diff --git a/backend/src/main/java/com/team05/todolist/controller/CardController.java b/backend/src/main/java/com/team05/todolist/controller/CardController.java new file mode 100644 index 000000000..cd14fd400 --- /dev/null +++ b/backend/src/main/java/com/team05/todolist/controller/CardController.java @@ -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 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); + } +} 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 c2134f8a8..75dd45463 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 @@ -4,7 +4,6 @@ import lombok.Setter; @Getter -@Setter public class CardDTO { private Integer cardId; @@ -12,10 +11,13 @@ public class CardDTO { private String title; private String content; - public CardDTO(Integer cardId, Integer orderIndex, String title, String content) { - this.cardId = cardId; + public CardDTO(Integer orderIndex, String title, String content) { this.orderIndex = orderIndex; this.title = title; this.content = content; } + + public void setCardId(Integer cardId) { + this.cardId = cardId; + } } diff --git a/backend/src/main/java/com/team05/todolist/domain/dto/ResponseDTO.java b/backend/src/main/java/com/team05/todolist/domain/dto/ResponseDTO.java new file mode 100644 index 000000000..e165089e3 --- /dev/null +++ b/backend/src/main/java/com/team05/todolist/domain/dto/ResponseDTO.java @@ -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; + } +}