From 2dd16646789a2ce2741c32c776971395433d6e35 Mon Sep 17 00:00:00 2001 From: Jaehong Choe Date: Wed, 13 Apr 2022 14:44:30 +0900 Subject: [PATCH] =?UTF-8?q?[BE-pio]=20feat:=20=EC=A0=84=EC=B2=B4=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=EC=8B=9C=20=EC=B9=B4=EB=93=9C=EB=A5=BC=20order?= =?UTF-8?q?=EC=88=9C=EC=9C=BC=EB=A1=9C=20=EC=A0=95=EB=A0=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - CardDTO에 Comparable을 구현. - ClassifiedCardsDTO의 sort메서드를 통해 정렬. Related to #16 --- .../main/java/com/team05/todolist/domain/dto/CardDTO.java | 7 ++++++- .../team05/todolist/domain/dto/ClassifiedCardsDTO.java | 8 ++++++++ .../java/com/team05/todolist/service/CardService.java | 7 +++++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/backend/src/main/java/com/team05/todolist/domain/dto/CardDTO.java b/backend/src/main/java/com/team05/todolist/domain/dto/CardDTO.java index e4b9b5d52..bd847dba0 100644 --- a/backend/src/main/java/com/team05/todolist/domain/dto/CardDTO.java +++ b/backend/src/main/java/com/team05/todolist/domain/dto/CardDTO.java @@ -6,7 +6,7 @@ @ApiModel(value="CardDTO : 카드 정보를 가지고 있는 모델") @Getter -public class CardDTO { +public class CardDTO implements Comparable { @ApiModelProperty(hidden = true) private Integer cardId; @@ -32,4 +32,9 @@ public CardDTO(Integer order, String title, String content, String section) { public void setCardId(Integer cardId) { this.cardId = cardId; } + + @Override + public int compareTo(CardDTO o) { + return this.order - o.order; + } } diff --git a/backend/src/main/java/com/team05/todolist/domain/dto/ClassifiedCardsDTO.java b/backend/src/main/java/com/team05/todolist/domain/dto/ClassifiedCardsDTO.java index d1e929709..33c9d3d9c 100644 --- a/backend/src/main/java/com/team05/todolist/domain/dto/ClassifiedCardsDTO.java +++ b/backend/src/main/java/com/team05/todolist/domain/dto/ClassifiedCardsDTO.java @@ -1,6 +1,7 @@ package com.team05.todolist.domain.dto; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -21,4 +22,11 @@ public ClassifiedCardsDTO() { public List get(String section) { return classifiedCards.get(section); } + + public void sort() { + Collections.sort(classifiedCards.get("todo")); + Collections.sort(classifiedCards.get("doing")); + Collections.sort(classifiedCards.get("done")); + }; + } diff --git a/backend/src/main/java/com/team05/todolist/service/CardService.java b/backend/src/main/java/com/team05/todolist/service/CardService.java index 34834de6a..18ab805dc 100644 --- a/backend/src/main/java/com/team05/todolist/service/CardService.java +++ b/backend/src/main/java/com/team05/todolist/service/CardService.java @@ -6,6 +6,7 @@ import com.team05.todolist.domain.dto.ClassifiedCardsDTO; import com.team05.todolist.domain.dto.MoveCardDTO; import com.team05.todolist.repository.CardRepository; +import java.util.Collections; import java.util.List; import java.util.NoSuchElementException; import java.util.Optional; @@ -93,10 +94,12 @@ public CardDTO delete(int id) { public ClassifiedCardsDTO findCards() { List cards = cardRepository.findAll(); - return classifyBySection(cards); + ClassifiedCardsDTO classifiedCardsDTO = classifyBySection(cards); + classifiedCardsDTO.sort(); + return classifiedCardsDTO; } - private ClassifiedCardsDTO classifyBySection(List cards) { + private ClassifiedCardsDTO classifyBySection(List cards) { ClassifiedCardsDTO classifiedCards = new ClassifiedCardsDTO(); List sectionCards; CardDTO cardDto;