Skip to content

Commit

Permalink
Merge pull request #73 from Mile-Writings/feat/#71
Browse files Browse the repository at this point in the history
#71 [feat] GET - 임시저장글 조회
  • Loading branch information
parkheeddong authored Jan 11, 2024
2 parents f71020f + c46a999 commit 57e5ae9
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.mile.post.service.dto.CommentListResponse;
import com.mile.post.service.dto.PostGetResponse;
import com.mile.post.service.dto.PostPutRequest;
import com.mile.post.service.dto.TemporaryPostGetResponse;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -116,6 +117,15 @@ public SuccessResponse deletePost(
}

@Override
@GetMapping("/temporary/{postId}")
public SuccessResponse<TemporaryPostGetResponse> getTemporaryPost(
@PathVariable final Long postId,
final Principal principal
) {
return SuccessResponse.of(SuccessMessage.TEMPORARY_POST_GET_SUCCESS,
postService.getTemporaryPost(postId, Long.valueOf(principal.getName())));
}

@GetMapping("/{postId}")
public SuccessResponse<PostGetResponse> getPost(
@PathVariable final Long postId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.mile.post.service.dto.CommentListResponse;
import com.mile.post.service.dto.PostGetResponse;
import com.mile.post.service.dto.PostPutRequest;
import com.mile.post.service.dto.TemporaryPostGetResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
Expand Down Expand Up @@ -163,6 +164,21 @@ SuccessResponse deletePost(
final Principal principal
);

@Operation(summary = "임시저장글 조회")
@ApiResponses(
value = {
@ApiResponse(responseCode = "200", description = "임시저장글 조회가 완료되었습니다."),
@ApiResponse(responseCode = "404", description = "해당 글은 존재하지 않습니다.",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "500", description = "서버 내부 오류입니다.",
content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
}
)
SuccessResponse<TemporaryPostGetResponse> getTemporaryPost(
@PathVariable final Long postId,
final Principal principal
);

@Operation(summary = "글 조회")
@ApiResponses(
value = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public enum ErrorMessage {
INVALID_BUCKET_PREFIX(HttpStatus.BAD_REQUEST.value(), "유효하지 않는 S3 버킷 디렉터리 이름입니다."),
VALIDATION_REQUEST_MISSING_EXCEPTION(HttpStatus.BAD_REQUEST.value(), "요청 값이 유효하지 않습니다."),
BEARER_LOST_ERROR(HttpStatus.BAD_REQUEST.value(), "토큰의 요청에 Bearer이 담겨 있지 않습니다."),
POST_NOT_TEMPORARY_ERROR(HttpStatus.BAD_REQUEST.value(), "해당 글은 임시저장글이 아닙니다."),

IMAGE_EXTENSION_INVALID_ERROR(HttpStatus.BAD_REQUEST.value(), "이미지 확장자는 jpg, png, webp만 가능합니다."),
IMAGE_SIZE_INVALID_ERROR(HttpStatus.BAD_REQUEST.value(), "이미지 사이즈는 5MB를 넘을 수 없습니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public enum SuccessMessage {
POST_DELETE_SUCCESS(HttpStatus.OK.value(), "글 삭제가 완료되었습니다."),
CATEGORY_LIST_SEARCH_SUCCESS(HttpStatus.OK.value(), "카테고리 리스트 조회가 완료되었습니다."),
MOIM_TOPIC_GET_SUCCESS(HttpStatus.OK.value(), "글감 조회가 완료되었습니다."),
TEMPORARY_POST_GET_SUCCESS(HttpStatus.OK.value(), "임시저장글 조회가 완료되었습니다."),
MOIM_TOP_2_POST_GET_SUCCESS(HttpStatus.OK.value(), "궁금해요 상위 2개의 글이 조회 완료되었습니다."),
POST_GET_SUCCESS(HttpStatus.OK.value(), "글 조회가 완료되었습니다."),
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.mile.curious.serivce.CuriousService;
import com.mile.curious.serivce.dto.CuriousInfoResponse;
import com.mile.exception.message.ErrorMessage;
import com.mile.exception.model.BadRequestException;
import com.mile.exception.model.NotFoundException;
import com.mile.moim.domain.Moim;
import com.mile.post.domain.Post;
Expand All @@ -13,11 +14,11 @@
import com.mile.post.service.dto.CommentListResponse;
import com.mile.post.service.dto.PostGetResponse;
import com.mile.post.service.dto.PostPutRequest;
import com.mile.post.service.dto.TemporaryPostGetResponse;
import com.mile.post.service.dto.WriterAuthenticateResponse;
import com.mile.topic.domain.Topic;
import com.mile.topic.serivce.TopicService;
import com.mile.user.service.UserService;
import com.mile.writerName.domain.WriterName;
import com.mile.writerName.serivce.WriterNameService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -160,6 +161,24 @@ private void deleteS3File(
}

@Transactional(readOnly = true)
public TemporaryPostGetResponse getTemporaryPost(
final Long postId,
final Long userId
) {
Post post = findById(postId);
postAuthenticateService.authenticateUserWithPost(post, userId);
isPostTemporary(post);
return TemporaryPostGetResponse.of(post);
}

private void isPostTemporary(
final Post post
) {
if (!post.isTemporary()) {
throw new BadRequestException(ErrorMessage.POST_NOT_TEMPORARY_ERROR);
}
}

public PostGetResponse getPost(
final Long postId
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.mile.post.service.dto;

import com.mile.moim.domain.Moim;
import com.mile.post.domain.Post;
import com.mile.utils.DateUtil;


public record TemporaryPostGetResponse(
TemporaryPostTopicGetResponse topic,
String title,
String content,
String imageUrl,
boolean anonymous
) {
public static TemporaryPostGetResponse of(Post post) {

return new TemporaryPostGetResponse(
TemporaryPostTopicGetResponse.of(post.getTopic()),
post.getTitle(),
post.getContent(),
post.getImageUrl(),
post.isAnonymous()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.mile.post.service.dto;

import com.mile.topic.domain.Topic;

public record TemporaryPostTopicGetResponse(Long topicId, String topicContent) {
public static TemporaryPostTopicGetResponse of(Topic topic) {
return new TemporaryPostTopicGetResponse(topic.getId(), topic.getContent());
}
}

0 comments on commit 57e5ae9

Please sign in to comment.