Skip to content

Commit

Permalink
[BE-nathan] add: CardController 구현 및 ResponseDTO 생성
Browse files Browse the repository at this point in the history
- ResponseDTO에 Card, Log 정보를 ResponseEntity의 바디에 담음

Related to #8
  • Loading branch information
nathan29849 committed Apr 8, 2022
1 parent 66a5944 commit 9761dde
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@
import lombok.Setter;

@Getter
@Setter
public class CardDTO {

private Integer cardId;
private Integer orderIndex;
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;
}
}
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;
}
}

0 comments on commit 9761dde

Please sign in to comment.