Skip to content

Commit

Permalink
[BE-pio] feat: 전체조회시 카드를 order순으로 정렬
Browse files Browse the repository at this point in the history
- CardDTO에 Comparable을 구현.
- ClassifiedCardsDTO의 sort메서드를 통해 정렬.

Related to #16
  • Loading branch information
NB993 committed Apr 13, 2022
1 parent 322f04d commit 2dd1664
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@ApiModel(value="CardDTO : 카드 정보를 가지고 있는 모델")
@Getter
public class CardDTO {
public class CardDTO implements Comparable<CardDTO> {

@ApiModelProperty(hidden = true)
private Integer cardId;
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -21,4 +22,11 @@ public ClassifiedCardsDTO() {
public List<CardDTO> 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"));
};

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -93,10 +94,12 @@ public CardDTO delete(int id) {

public ClassifiedCardsDTO findCards() {
List<Card> cards = cardRepository.findAll();
return classifyBySection(cards);
ClassifiedCardsDTO classifiedCardsDTO = classifyBySection(cards);
classifiedCardsDTO.sort();
return classifiedCardsDTO;
}

private ClassifiedCardsDTO classifyBySection(List<Card> cards) {
private ClassifiedCardsDTO classifyBySection(List<Card> cards) {
ClassifiedCardsDTO classifiedCards = new ClassifiedCardsDTO();
List<CardDTO> sectionCards;
CardDTO cardDto;
Expand Down

0 comments on commit 2dd1664

Please sign in to comment.