diff --git a/src/main/java/com/beotkkot/qtudy/dto/request/comments/CommentsRequestDto.java b/src/main/java/com/beotkkot/qtudy/dto/request/comments/CommentsRequestDto.java new file mode 100644 index 0000000..2adfb7b --- /dev/null +++ b/src/main/java/com/beotkkot/qtudy/dto/request/comments/CommentsRequestDto.java @@ -0,0 +1,30 @@ +package com.beotkkot.qtudy.dto.request.comments; + +import com.beotkkot.qtudy.domain.comments.Comments; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.text.SimpleDateFormat; +import java.time.Instant; +import java.util.Date; + +@NoArgsConstructor +@Getter +public class CommentsRequestDto { + private String content; + private Long userUid; + + public Comments toEntity(Long postId) { + Date now = Date.from(Instant.now()); + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + String writeDatetime = simpleDateFormat.format(now); + + return Comments.builder() + .userUid(userUid) + .postId(postId) + .content(content) + .createdAt(writeDatetime) + .build(); + } + +} diff --git a/src/main/java/com/beotkkot/qtudy/dto/response/comments/CommentsResponseDto.java b/src/main/java/com/beotkkot/qtudy/dto/response/comments/CommentsResponseDto.java new file mode 100644 index 0000000..0dce2c4 --- /dev/null +++ b/src/main/java/com/beotkkot/qtudy/dto/response/comments/CommentsResponseDto.java @@ -0,0 +1,35 @@ +package com.beotkkot.qtudy.dto.response.comments; + +import com.beotkkot.qtudy.common.ResponseCode; +import com.beotkkot.qtudy.common.ResponseMessage; +import com.beotkkot.qtudy.dto.response.ResponseDto; +import lombok.Getter; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +@Getter +public class CommentsResponseDto extends ResponseDto{ + public CommentsResponseDto() { + super(ResponseCode.SUCCESS, ResponseMessage.SUCCESS); + } + + public static ResponseEntity success() { + CommentsResponseDto result = new CommentsResponseDto(); + return ResponseEntity.status(HttpStatus.OK).body(result); + } + + public static ResponseEntity notExistedPost(){ + ResponseDto result = new ResponseDto(ResponseCode.NOT_EXISTED_POST, ResponseMessage.NOT_EXISTED_POST); + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(result); + } + + public static ResponseEntity notExistedUser() { + ResponseDto result = new ResponseDto(ResponseCode.NOT_EXISTED_USER, ResponseMessage.NOT_EXISTED_USER); + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(result); + } + + public static ResponseEntity notExistedComment() { + ResponseDto result = new ResponseDto(ResponseCode.NOT_EXISTED_COMMENT, ResponseMessage.NOT_EXISTED_COMMENT); + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(result); + } +} diff --git a/src/main/java/com/beotkkot/qtudy/dto/response/comments/GetCommentsAllResponseDto.java b/src/main/java/com/beotkkot/qtudy/dto/response/comments/GetCommentsAllResponseDto.java new file mode 100644 index 0000000..3ba9845 --- /dev/null +++ b/src/main/java/com/beotkkot/qtudy/dto/response/comments/GetCommentsAllResponseDto.java @@ -0,0 +1,37 @@ +package com.beotkkot.qtudy.dto.response.comments; + +import com.beotkkot.qtudy.common.ResponseCode; +import com.beotkkot.qtudy.common.ResponseMessage; +import com.beotkkot.qtudy.dto.object.CommentListItem; +import com.beotkkot.qtudy.dto.response.ResponseDto; +import lombok.Getter; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import java.util.List; + + +@Getter +public class GetCommentsAllResponseDto extends ResponseDto { + private int page; + private List commentList; + + public GetCommentsAllResponseDto(List commentListItem, int page) { + super(ResponseCode.SUCCESS, ResponseMessage.SUCCESS); + this.page = page; + this.commentList = commentListItem; + } + + public static ResponseEntity success(List commentListItem, int page) { + GetCommentsAllResponseDto result = new GetCommentsAllResponseDto(commentListItem, page); + return ResponseEntity.status(HttpStatus.OK).body(result); + } + + public static ResponseEntity notExistedPost(){ + ResponseDto result = new ResponseDto(ResponseCode.NOT_EXISTED_POST, ResponseMessage.NOT_EXISTED_POST); + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(result); + } +} + + +