Skip to content

Commit f552d22

Browse files
authored
Merge pull request #194 from sally4405/dev-be
[team-08][BE] todo-list 2주차 #4
2 parents 2c2d973 + 3b27df2 commit f552d22

File tree

13 files changed

+102
-136
lines changed

13 files changed

+102
-136
lines changed
Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,18 @@
11
package todolist.controller;
22

3-
import org.springframework.beans.factory.annotation.Autowired;
43
import org.springframework.web.bind.annotation.*;
5-
import todolist.domain.event.Action;
64
import todolist.dto.card.RequestCardDto;
75
import todolist.dto.card.ResponseCardDto;
86
import todolist.dto.card.ResponseCardsDto;
9-
import todolist.dto.event.RequestEventDto;
107
import todolist.service.CardService;
11-
import todolist.service.EventService;
128

139
@RestController
1410
public class CardController {
1511

1612
private final CardService cardService;
17-
private final EventService eventService;
1813

19-
@Autowired
20-
public CardController(CardService cardService, EventService eventService) {
14+
public CardController(CardService cardService) {
2115
this.cardService = cardService;
22-
this.eventService = eventService;
2316
}
2417

2518
@GetMapping("/todos")
@@ -29,26 +22,16 @@ public ResponseCardsDto getTodo() {
2922

3023
@PostMapping("/todo")
3124
public ResponseCardDto add(@RequestBody RequestCardDto requestCardDto) {
32-
ResponseCardDto responseCardDto = cardService.addCard(requestCardDto);
33-
eventService.addEvent(new RequestEventDto(responseCardDto), Action.ADD);
34-
return responseCardDto;
25+
return cardService.addCard(requestCardDto);
3526
}
3627

3728
@PutMapping("/todo/{id}")
3829
public void update(@PathVariable Long id, @RequestBody RequestCardDto requestCardDto) {
39-
String prevSection = cardService.getPrevSection(id);
40-
ResponseCardDto responseCardDto = cardService.updateCard(id, requestCardDto);
41-
42-
if (prevSection.equals(responseCardDto.getSection())) {
43-
eventService.addEvent(new RequestEventDto(responseCardDto), Action.UPDATE);
44-
} else {
45-
eventService.addEvent(new RequestEventDto(prevSection, responseCardDto), Action.MOVE);
46-
}
30+
cardService.updateCard(id, requestCardDto);
4731
}
4832

4933
@DeleteMapping("/todo/{id}")
5034
public void delete(@PathVariable Long id) {
51-
ResponseCardDto responseCardDto = cardService.deleteCard(id);
52-
eventService.addEvent(new RequestEventDto(responseCardDto), Action.REMOVE);
35+
cardService.deleteCard(id);
5336
}
5437
}
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package todolist.controller;
22

3-
import org.springframework.beans.factory.annotation.Autowired;
43
import org.springframework.web.bind.annotation.GetMapping;
54
import org.springframework.web.bind.annotation.RestController;
65
import todolist.domain.event.Event;
7-
import todolist.dto.event.ResponseEventDto;
86
import todolist.service.EventService;
97

108
import java.util.List;
@@ -14,13 +12,12 @@ public class EventController {
1412

1513
private final EventService eventService;
1614

17-
@Autowired
1815
public EventController(EventService eventService) {
1916
this.eventService = eventService;
2017
}
2118

2219
@GetMapping("/events")
23-
public List<ResponseEventDto> getEvents() {
20+
public List<Event> getEvents() {
2421
return eventService.getEventList();
2522
}
2623
}

be/src/main/java/todolist/domain/card/Card.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ public ResponseCardDto toResponseCardDto() {
3333
return responseCardDto;
3434
}
3535

36+
public boolean isSectionUpdated(String prevSection) {
37+
return prevSection == section;
38+
}
39+
3640
@Override
3741
public String toString() {
3842
return "Card{" +
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package todolist.domain.card;
2+
3+
import java.util.*;
4+
5+
public enum Section {
6+
TODO("해야할 일"),
7+
DOING("하고 있는 일"),
8+
DONE("완료된 일");
9+
10+
11+
private String sectionTitle;
12+
13+
Section(String sectionTitle) {
14+
this.sectionTitle = sectionTitle;
15+
}
16+
17+
public String getSectionTitle() {
18+
return sectionTitle;
19+
}
20+
21+
public static Map<String, List<Card>> categorizeCards(List<Card> cardlist) {
22+
23+
Map<String, List<Card>> result = new HashMap<>() {{
24+
put(TODO.sectionTitle, new ArrayList<>());
25+
put(DOING.sectionTitle, new ArrayList<>());
26+
put(DONE.sectionTitle, new ArrayList<>());
27+
}};
28+
29+
for (Card card : cardlist) {
30+
String section = card.getSection();
31+
List<Card> responseSection = result.get(findSection(section).sectionTitle);
32+
responseSection.add(card);
33+
}
34+
return result;
35+
}
36+
37+
private static Section findSection(String sectionTitle) {
38+
return Arrays.stream(Section.values())
39+
.filter(s -> s.getSectionTitle().equals(sectionTitle))
40+
.findFirst()
41+
.orElseThrow(() -> new IllegalArgumentException());
42+
}
43+
}

be/src/main/java/todolist/domain/event/Action.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
import java.util.function.BiFunction;
66

77
public enum Action {
8-
ADD((dto, action) -> new Event(dto.getTitle(), dto.getCurrentSection(), action)),
9-
MOVE((dto, action) -> new Event(dto.getTitle(),dto.getPrevSection(), dto.getCurrentSection(), action)),
10-
UPDATE((dto, action) -> new Event(dto.getTitle(), dto.getCurrentSection(), action)),
11-
REMOVE((dto, action) -> new Event(dto.getTitle(), dto.getCurrentSection(), action));
8+
ADD((dto, action) -> new Event(dto, action)),
9+
MOVE((dto, action) -> new Event(dto, action)),
10+
UPDATE((dto, action) -> new Event(dto, action)),
11+
REMOVE((dto, action) -> new Event(dto, action));
1212

1313

1414
private BiFunction<RequestEventDto, Action, Event> eventFunction;

be/src/main/java/todolist/domain/event/Event.java

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package todolist.domain.event;
22

3-
import todolist.dto.event.ResponseEventDto;
3+
import todolist.dto.event.RequestEventDto;
44

55
import java.time.LocalDateTime;
66

@@ -12,13 +12,8 @@ public class Event {
1212
private Action action;
1313
private LocalDateTime createdAt;
1414

15-
16-
public Event(String cardTitle, String currentSection, Action action) {
17-
this(cardTitle, "", currentSection, action);
18-
}
19-
20-
public Event(String cardTitle, String prevSection, String currentSection, Action action) {
21-
this(-1L, cardTitle, prevSection, currentSection, action, null);
15+
public Event(RequestEventDto dto, Action action) {
16+
this(-1L, dto.getTitle(), dto.getPrevSection(), dto.getCurrentSection(), action, null);
2217
}
2318

2419
public Event(Long id, String cardTitle, String prevSection, String currentSection, Action action, LocalDateTime createdAt) {
@@ -49,9 +44,4 @@ public String getCurrentSection() {
4944
public Action getAction() {
5045
return action;
5146
}
52-
53-
public ResponseEventDto toResponseEventDto() {
54-
return new ResponseEventDto(id, cardTitle, prevSection, currentSection, action, createdAt);
55-
}
56-
5747
}

be/src/main/java/todolist/dto/card/RequestCardDto.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package todolist.dto.card;
22

3-
import lombok.Getter;
4-
import lombok.Setter;
53
import todolist.domain.card.Card;
64

75
public class RequestCardDto {

be/src/main/java/todolist/dto/card/ResponseCardsDto.java

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,19 @@
22

33
import todolist.domain.card.Card;
44

5-
import java.util.ArrayList;
6-
import java.util.HashMap;
75
import java.util.List;
86
import java.util.Map;
97

108
public class ResponseCardsDto {
119

12-
private Map<String, List<ResponseCardDto>> cards;
10+
private Map<String, List<Card>> cards;
1311

14-
public ResponseCardsDto() {
15-
cards = new HashMap<>();
16-
cards.put("해야할 일", new ArrayList<>());
17-
cards.put("하고 있는 일", new ArrayList<>());
18-
cards.put("완료된 일", new ArrayList<>());
12+
public ResponseCardsDto(Map<String, List<Card>> cards) {
13+
this.cards = cards;
1914
}
2015

21-
public Map<String, List<ResponseCardDto>> getCards() {
16+
public Map<String, List<Card>> getCards() {
2217
return cards;
2318
}
2419

25-
public void categorizeCards(List<Card> cardlist) {
26-
for (Card card : cardlist) {
27-
String section = card.getSection();
28-
List<ResponseCardDto> responseSection = cards.get(section);
29-
responseSection.add(card.toResponseCardDto());
30-
}
31-
}
3220
}

be/src/main/java/todolist/dto/event/RequestEventDto.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
package todolist.dto.event;
22

3-
import todolist.dto.card.ResponseCardDto;
3+
import todolist.domain.card.Card;
44

55
public class RequestEventDto {
66
private String title;
77
private String prevSection;
88
private String currentSection;
99

1010

11-
public RequestEventDto(ResponseCardDto responseCardDto) {
12-
this("", responseCardDto);
11+
public RequestEventDto(Card card) {
12+
this("", card);
1313
}
1414

15-
public RequestEventDto(String prevSection, ResponseCardDto responseCardDto) {
16-
this.title = responseCardDto.getTitle();
15+
public RequestEventDto(String prevSection, Card card) {
16+
this.title = card.getTitle();
1717
this.prevSection = prevSection;
18-
this.currentSection = responseCardDto.getSection();
18+
this.currentSection = card.getSection();
1919
}
2020

2121
public String getTitle() {

be/src/main/java/todolist/dto/event/ResponseEventDto.java

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)