-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
server/src/main/java/com/yogit/server/board/controller/CommenrController.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,40 @@ | ||
package com.yogit.server.board.controller; | ||
|
||
import com.yogit.server.board.dto.request.comment.CreateCommentReq; | ||
import com.yogit.server.board.dto.response.comment.CommentRes; | ||
import com.yogit.server.board.service.comment.CommentService; | ||
import com.yogit.server.global.dto.ApplicationResponse; | ||
import io.swagger.annotations.ApiOperation; | ||
import io.swagger.annotations.ApiResponse; | ||
import io.swagger.annotations.ApiResponses; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Slf4j | ||
@RestController | ||
@RequiredArgsConstructor // private final DI의존주입 | ||
@RequestMapping("/comments") | ||
public class CommenrController { | ||
|
||
private final CommentService commentService; | ||
/** | ||
* 코멘트 등록 | ||
* @author 토마스 | ||
*/ | ||
@ApiOperation(value = "코멘트 등록", notes = "코멘트 내용을 입력해 등록 요청.") | ||
@ApiResponses({ | ||
@ApiResponse(code= 201, message = "요청에 성공하였습니다."), | ||
@ApiResponse(code= 404, message = "존재하지 않는 유저입니다."), | ||
@ApiResponse(code= 404, message = "존재하지 않는 클립보드입니다."), | ||
@ApiResponse(code = 4000 , message = "서버 오류입니다.") | ||
}) | ||
@PostMapping("") | ||
public ApplicationResponse<CommentRes> createComment(@RequestBody @Validated CreateCommentReq createCommentReq){ | ||
return commentService.createComment(createCommentReq); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
server/src/main/java/com/yogit/server/board/dto/request/comment/CreateCommentReq.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,26 @@ | ||
package com.yogit.server.board.dto.request.comment; | ||
|
||
import io.swagger.annotations.ApiModelProperty; | ||
import io.swagger.annotations.ApiParam; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.validation.constraints.NotBlank; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
public class CreateCommentReq { | ||
|
||
@ApiModelProperty(example = "1") | ||
@ApiParam(value = "유저 ID", required = true) | ||
private Long userId; | ||
|
||
@ApiModelProperty(example = "1") | ||
@ApiParam(value = "ClipBoard ID", required = true) | ||
private Long clipBoardId; | ||
|
||
@ApiModelProperty(example = "경복궁역 몇 번 출구인가요?") | ||
@ApiParam(value = "클립보드 상세 내용", required = true) | ||
@NotBlank | ||
private String content; | ||
} |
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
10 changes: 10 additions & 0 deletions
10
server/src/main/java/com/yogit/server/board/service/comment/CommentService.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,10 @@ | ||
package com.yogit.server.board.service.comment; | ||
|
||
import com.yogit.server.board.dto.request.comment.CreateCommentReq; | ||
import com.yogit.server.board.dto.response.comment.CommentRes; | ||
import com.yogit.server.global.dto.ApplicationResponse; | ||
|
||
public interface CommentService { | ||
|
||
ApplicationResponse<CommentRes> createComment(CreateCommentReq createCommentReq); | ||
} |
46 changes: 46 additions & 0 deletions
46
server/src/main/java/com/yogit/server/board/service/comment/CommentServiceImpl.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,46 @@ | ||
package com.yogit.server.board.service.comment; | ||
|
||
import com.yogit.server.board.dto.request.comment.CreateCommentReq; | ||
import com.yogit.server.board.dto.response.comment.CommentRes; | ||
import com.yogit.server.board.entity.ClipBoard; | ||
import com.yogit.server.board.entity.Comment; | ||
import com.yogit.server.board.exception.clipboard.NotFoundClipBoardException; | ||
import com.yogit.server.board.repository.ClipBoardRepository; | ||
import com.yogit.server.board.repository.CommentRepository; | ||
import com.yogit.server.global.dto.ApplicationResponse; | ||
import com.yogit.server.user.entity.User; | ||
import com.yogit.server.user.exception.NotFoundUserException; | ||
import com.yogit.server.user.repository.UserRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class CommentServiceImpl implements CommentService{ | ||
|
||
private final CommentRepository commentRepository; | ||
private final UserRepository userRepository; | ||
private final ClipBoardRepository clipBoardRepository; | ||
|
||
|
||
|
||
@Transactional(readOnly = false) | ||
@Override | ||
public ApplicationResponse<CommentRes> createComment(CreateCommentReq dto){ | ||
|
||
User user = userRepository.findById(dto.getUserId()) | ||
.orElseThrow(() -> new NotFoundUserException()); | ||
|
||
ClipBoard clipBoard = clipBoardRepository.findClipBoardById(dto.getClipBoardId()) | ||
.orElseThrow(() -> new NotFoundClipBoardException()); | ||
|
||
Comment comment = new Comment(dto, user, clipBoard); | ||
Comment savedComment = commentRepository.save(comment); | ||
CommentRes commentRes = CommentRes.toDto(savedComment); | ||
return ApplicationResponse.create("코멘트 생성을 성공했습니다.", commentRes); | ||
} | ||
|
||
|
||
} |