forked from codesquad-members-2022/todo-list
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BE-nathan] add: CardController 구현 및 ResponseDTO 생성
- ResponseDTO에 Card, Log 정보를 ResponseEntity의 바디에 담음 Related to #8
- Loading branch information
1 parent
66a5944
commit 9761dde
Showing
3 changed files
with
55 additions
and
3 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
backend/src/main/java/com/team05/todolist/controller/CardController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.team05.todolist.controller; | ||
|
||
import com.team05.todolist.domain.Card; | ||
import com.team05.todolist.domain.Event; | ||
import com.team05.todolist.domain.dto.CardDTO; | ||
import com.team05.todolist.domain.dto.LogDTO; | ||
import com.team05.todolist.domain.dto.ResponseDTO; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
@Controller | ||
@RequestMapping("/api") | ||
public class CardController { | ||
|
||
private final CardService cardService; | ||
private final LogService logService; | ||
private Logger logger = LoggerFactory.getLogger(CardController.class); | ||
|
||
public CardController(CardService cardService, LogService logService) { | ||
this.cardService = cardService; | ||
this.logService = logService; | ||
} | ||
|
||
@PostMapping("/cards") | ||
public ResponseEntity<ResponseDTO> create(CardDTO cardDto) { | ||
CardDTO card = cardService.save(cardDto); | ||
LogDTO log = logService.save(Event.CREATE, cardDto); | ||
ResponseDTO responseDTO = new ResponseDTO(card, log); | ||
logger.debug("card-{}: {}, log: {}({})", card.getCardId(), card.getTitle(), | ||
log.getLogEvent(), log.getLogTime()); | ||
return ResponseEntity.ok().body(responseDTO); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
backend/src/main/java/com/team05/todolist/domain/dto/ResponseDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.team05.todolist.domain.dto; | ||
|
||
public class ResponseDTO { | ||
|
||
private CardDTO card; | ||
private LogDTO log; | ||
|
||
public ResponseDTO(CardDTO cardDto, LogDTO logDto) { | ||
this.card = cardDto; | ||
this.log = logDto; | ||
} | ||
} |