Skip to content

Commit

Permalink
feat: Add Comments dto (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahyun0326 committed Mar 19, 2024
1 parent d374810 commit d120794
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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();
}

}
Original file line number Diff line number Diff line change
@@ -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<CommentsResponseDto> success() {
CommentsResponseDto result = new CommentsResponseDto();
return ResponseEntity.status(HttpStatus.OK).body(result);
}

public static ResponseEntity<ResponseDto> notExistedPost(){
ResponseDto result = new ResponseDto(ResponseCode.NOT_EXISTED_POST, ResponseMessage.NOT_EXISTED_POST);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(result);
}

public static ResponseEntity<ResponseDto> notExistedUser() {
ResponseDto result = new ResponseDto(ResponseCode.NOT_EXISTED_USER, ResponseMessage.NOT_EXISTED_USER);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(result);
}

public static ResponseEntity<? super CommentsResponseDto> notExistedComment() {
ResponseDto result = new ResponseDto(ResponseCode.NOT_EXISTED_COMMENT, ResponseMessage.NOT_EXISTED_COMMENT);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(result);
}
}
Original file line number Diff line number Diff line change
@@ -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<CommentListItem> commentList;

public GetCommentsAllResponseDto(List<CommentListItem> commentListItem, int page) {
super(ResponseCode.SUCCESS, ResponseMessage.SUCCESS);
this.page = page;
this.commentList = commentListItem;
}

public static ResponseEntity<GetCommentsAllResponseDto> success(List<CommentListItem> commentListItem, int page) {
GetCommentsAllResponseDto result = new GetCommentsAllResponseDto(commentListItem, page);
return ResponseEntity.status(HttpStatus.OK).body(result);
}

public static ResponseEntity<ResponseDto> notExistedPost(){
ResponseDto result = new ResponseDto(ResponseCode.NOT_EXISTED_POST, ResponseMessage.NOT_EXISTED_POST);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(result);
}
}



0 comments on commit d120794

Please sign in to comment.