diff --git a/backend/src/main/java/com/team05/todolist/controller/CardController.java b/backend/src/main/java/com/team05/todolist/controller/CardController.java index f4d19a489..14e9e7aaf 100644 --- a/backend/src/main/java/com/team05/todolist/controller/CardController.java +++ b/backend/src/main/java/com/team05/todolist/controller/CardController.java @@ -3,6 +3,7 @@ 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 com.team05.todolist.service.CardService; import com.team05.todolist.service.LogService; import io.swagger.annotations.ApiOperation; @@ -32,12 +33,12 @@ public CardController(CardService cardService, LogService logService) { @ApiOperation("카드 등록") @PostMapping("/cards") - public ResponseEntity create(CardDTO cardDto) { - cardService.save(cardDto); + public ResponseEntity create(CardDTO cardDto) { + CardDTO newCardDto = cardService.save(cardDto); LogDTO log = logService.save(Event.CREATE, cardDto.getTitle(), cardDto.getSection()); - logger.debug("[card-title] {}, [log-information] {}({})", cardDto.getTitle(), log.getLogEventType(), log.getLogTime()); // card Id 추가 - return ResponseEntity.ok().body(log); + logger.debug("[card-{}] {}, [log-information] {}-{}({})", newCardDto.getCardId(), newCardDto.getTitle(), log.getSection(), log.getLogEventType(), log.getLogTime()); + return ResponseEntity.ok().body(new ResponseDTO(newCardDto, log)); } @PutMapping("/cards/{id}") 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 index e165089e3..101537ca7 100644 --- a/backend/src/main/java/com/team05/todolist/domain/dto/ResponseDTO.java +++ b/backend/src/main/java/com/team05/todolist/domain/dto/ResponseDTO.java @@ -1,5 +1,8 @@ package com.team05.todolist.domain.dto; +import lombok.Getter; + +@Getter public class ResponseDTO { private CardDTO card; diff --git a/backend/src/main/java/com/team05/todolist/repository/CardRepository.java b/backend/src/main/java/com/team05/todolist/repository/CardRepository.java index e8c9d2062..55c4fb2be 100644 --- a/backend/src/main/java/com/team05/todolist/repository/CardRepository.java +++ b/backend/src/main/java/com/team05/todolist/repository/CardRepository.java @@ -6,7 +6,7 @@ public interface CardRepository { - void save(Card card); + int save(Card card); void delete(int id); List findAll(); Optional findById(int id); diff --git a/backend/src/main/java/com/team05/todolist/repository/JdbcCardRepository.java b/backend/src/main/java/com/team05/todolist/repository/JdbcCardRepository.java index 045acc991..ec1c5dda0 100644 --- a/backend/src/main/java/com/team05/todolist/repository/JdbcCardRepository.java +++ b/backend/src/main/java/com/team05/todolist/repository/JdbcCardRepository.java @@ -28,17 +28,17 @@ public JdbcCardRepository(DataSource dataSource) { } @Override - public void save(Card card) { + public int save(Card card) { if (card.getId() != null) { jdbcTemplate.update( "UPDATE card SET order_index=?, title=?, content=?, section=? WHERE id=?", card.getOrder(), card.getTitle(), card. getContent(), card.getSectionType(), card.getId()); - return; + return card.getId(); } Map params = getSaveParams(card); - simpleJdbcInsert.executeAndReturnKey(params).intValue(); + return simpleJdbcInsert.executeAndReturnKey(params).intValue(); } private Map getSaveParams(Card card) { 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 fa31c9a61..e6c10b50e 100644 --- a/backend/src/main/java/com/team05/todolist/service/CardService.java +++ b/backend/src/main/java/com/team05/todolist/service/CardService.java @@ -18,12 +18,15 @@ public CardService(CardRepository cardRepository) { this.cardRepository = cardRepository; } - public void save(CardDTO cardDto) { + public CardDTO save(CardDTO cardDto) { Card card = new Card(cardDto.getOrder(), NON_DELETED, cardDto.getTitle(), cardDto.getContent(), cardDto.getSection()); - cardRepository.save(card); - + int newCardId = cardRepository.save(card); + CardDTO newCardDto = new CardDTO(card.getOrder(), card.getTitle(), card.getContent(), + card.getSectionType()); + newCardDto.setCardId(newCardId); + return newCardDto; }