Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,18 @@ Response<PostSliceResponse> getPostSlice(



@Operation(summary = "내 게시물 조회", description = "사용자 나의 게시물 목록을 조회합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200",
description = "게시물 목록 조회 성공",
content = @Content(schema = @Schema(implementation = PostListResponse.class)))
})
@GetMapping
Response<PostListResponse> getMyPost(
@Valid @ModelAttribute PostListRequest request,
@UserPrincipal User user);



@Operation(summary = "게시물 수정", description = "기존 게시물을 수정합니다.")
@ApiResponses(value = {
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/backend/airo/api/post/PostController.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@Validated
Expand Down Expand Up @@ -101,6 +103,18 @@ public Response<PostSliceResponse> getPostSlice(
}


@Override
@GetMapping("/my")
public Response<PostListResponse> getMyPost(
@Valid @ModelAttribute PostListRequest request,
@UserPrincipal User user) {

PostListResponse response = postUseCase.getMyPostList(request, user.getId());

return Response.success(response);
}



// ===== 게시물 수정 =====
@Override
Expand Down
47 changes: 9 additions & 38 deletions src/main/java/backend/airo/api/post/dto/PostCreateRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import backend.airo.api.image.dto.ImageCreateRequest;
import backend.airo.domain.post.enums.*;
import backend.airo.domain.post.vo.Location;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
import jakarta.validation.constraints.*;
Expand All @@ -25,9 +26,10 @@ public record PostCreateRequest(
@NotNull(message = "게시물 상태는 필수입니다") // @NotBlank → @NotNull
PostStatus status,

@Schema(description = "누구와 태그", example = "FRIEND")
@NotNull(message = "withWhoTag는 필수입니다") // @NotBlank → @NotNull
PostWithWhoTag withWhoTag,
@Schema(description = "사업장 이름", example = "부산 맛집")
@Size(max = 100, message = "사업장 이름은 100자를 초과할 수 없습니다") // 길이 제한 추가 권장
@NotNull(message = "상호명은 필수입니다")
String businessName,

@Schema(description = "목적 태그", example = "HEALING")
@NotNull(message = "forWhatTag는 필수입니다") // 필수라면 @NotNull 추가
Expand All @@ -48,6 +50,10 @@ public record PostCreateRequest(
@PastOrPresent(message = "여행 날짜는 현재 또는 과거여야 합니다")
LocalDate travelDate,

@Schema(description = "위치 정보", example = "{ \"latitude\": 35.1796, \"longitude\": 129.0756 }")
@Valid // Location 객체 검증을 위해 추가
Location location,

@Schema(description = "주소", example = "부산시 해운대구")
@Size(max = 500, message = "주소는 500자를 초과할 수 없습니다") // 길이 제한 추가 권장
String address,
Expand All @@ -61,40 +67,5 @@ public record PostCreateRequest(
Boolean isFeatured
) {

public static PostCreateRequest forDraft(String title, String content) {
return new PostCreateRequest(
title, content, PostStatus.DRAFT,
null, null, null, null, null, null,
List.of(), false
);
}

public static PostCreateRequest forPublish(String title, String content,
PostWithWhoTag withWhoTag, PostForWhatTag forWhatTag,
PostCategory category) {
return new PostCreateRequest(
title, content, PostStatus.PUBLISHED,
withWhoTag, forWhatTag, null, category, null, null,
List.of(), false
);
}

public boolean canPublish() {
return status == PostStatus.PUBLISHED
&& title != null && !title.trim().isEmpty()
&& content != null && !content.trim().isEmpty()
&& withWhoTag != null
&& emotionTags != null
&& category != null;
}

public boolean hasImages() {
return images != null && !images.isEmpty();
}

public boolean hasEmotionTags() {
return emotionTags != null && !emotionTags.isEmpty();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ public record PostDetailResponse(
@Schema(description = "게시물 요약", example = "부산에서의 즐거운 여행...")
String summary,

@Schema(description = "사업장 이름", example = "짱구 분식")
String businessName,

@Schema(description = "게시물 상태", example = "PUBLISHED")
PostStatus status,

@Schema(description = "누구와 태그", example = "FRIEND")
PostWithWhoTag withWhoTag,

@Schema(description = "목적 태그", example = "HEALING")
PostForWhatTag forWhatTag,

Expand Down Expand Up @@ -79,8 +79,8 @@ public static PostDetailResponse toResponse(Post post,
post.getTitle(),
post.getContent(),
post.getSummary(),
post.getBusinessName(),
post.getStatus(),
post.getWithWhoTag(),
post.getForWhatTag(),
post.getEmotionTags(),
post.getTravelDate(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ public record PostUpdateRequest(
@Schema(description = "게시물 상태", example = "PUBLISHED")
PostStatus status,

@Schema(description = "누구와 태그", example = "FRIEND")
PostWithWhoTag withWhoTag,

@Schema(description = "목적 태그", example = "HEALING")
PostForWhatTag forWhatTag,
Expand Down Expand Up @@ -50,8 +48,7 @@ public record PostUpdateRequest(
) {

public boolean hasChanges() {
return title != null || content != null || status != null ||
withWhoTag != null || forWhatTag != null || emotionTags != null ||
return title != null || content != null || status != null || forWhatTag != null || emotionTags != null ||
travelDate != null || location != null || address != null || isFeatured != null;
}

Expand All @@ -61,7 +58,7 @@ public boolean isStatusChange() {

public boolean isMetadataOnly() {
return title == null && content == null &&
(withWhoTag != null || forWhatTag != null || emotionTags != null ||
(forWhatTag != null || emotionTags != null ||
location != null || address != null || isFeatured != null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class PostCacheUseCase {
private final DeletePostCommandService deletePostCommandService;
private final UpsertPointCommand upsertPointCommand;
private final CreatePointHistoryCommand createPointHistoryCommand;

private final GetPostListQueryService getPostListQueryService;
private final GetPostQueryService getPostQueryService;
private final GetUserQuery getUserQueryService;
private final GetImageQueryService getImageQueryService;
Expand Down Expand Up @@ -160,6 +160,11 @@ public void deletePost(Long postId, Long requesterId) {
}


public PostListResponse getMyPostList(PostListRequest request, Long userId) {
Page<Post> posts = getPostListQueryService.handleMyPosts(request, userId);
PostListResponse postListResponse = PostListResponse.fromDomain(posts);
return postListResponse;
}

// private method

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ public Post createPost(PostCreateRequest request, Long userId) {
}





public PostDetailResponse getPostDetail(Long postId, Long requesterId) {
log.debug("게시물 조회: id={}, requesterId={}", postId, requesterId);
Post post = getPostQueryService.handle(postId);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/backend/airo/cache/post/dto/PostCacheDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public class PostCacheDto {
private String title;
private String content;
private String summary;
private String businessName;
private PostStatus status;
private PostWithWhoTag withWhoTag;
private PostForWhatTag forWhatTag;
private PostCategory category;
private LocalDate travelDate;
Expand All @@ -44,8 +44,8 @@ public static PostCacheDto from(Post post) {
post.getTitle(),
post.getContent(),
post.getSummary(),
post.getBusinessName(),
post.getStatus(),
post.getWithWhoTag(),
post.getForWhatTag(),
post.getCategory(),
post.getTravelDate(),
Expand All @@ -64,7 +64,7 @@ public static PostCacheDto from(Post post) {
public Post toPost() {
return new Post(
id, userId, title, content, summary,
status, withWhoTag, forWhatTag,
businessName,status, forWhatTag,
emotionTags, category, travelDate, location,
address, viewCount, likeCount, commentCount,
isFeatured, publishedAt
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/backend/airo/domain/post/Post.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public class Post {
private String title;
private String content;
private String summary;
private String businessName;
private PostStatus status;
private PostWithWhoTag withWhoTag;
private PostForWhatTag forWhatTag;
private List<PostEmotionTag> emotionTags;
private PostCategory category;
Expand All @@ -37,8 +37,8 @@ public class Post {
private Boolean isFeatured = false;
private LocalDateTime publishedAt;

public Post(Long id, Long userId, String title, String content, String summary,
PostStatus status, PostWithWhoTag withWhoTag, PostForWhatTag forWhatTag,
public Post(Long id, Long userId, String title, String content, String summary, String businessName,
PostStatus status, PostForWhatTag forWhatTag,
List<PostEmotionTag> emotionTags, PostCategory category, LocalDate travelDate, Location location,
String address, Integer viewCount, Integer likeCount, Integer commentCount,
Boolean isFeatured, LocalDateTime publishedAt) {
Expand All @@ -47,8 +47,8 @@ public Post(Long id, Long userId, String title, String content, String summary,
this.title = title;
this.content = content;
this.summary = summary;
this.businessName = businessName;
this.status = status;
this.withWhoTag = withWhoTag;
this.forWhatTag = forWhatTag;
this.emotionTags = emotionTags;
this.category = category;
Expand Down Expand Up @@ -78,8 +78,8 @@ public static Post createForTest(
title,
content,
null, // summary
"gootshp",
PostStatus.PUBLISHED,
PostWithWhoTag.ALLONE,
PostForWhatTag.HEALING,
emotionTags,
category,
Expand All @@ -101,13 +101,13 @@ public static Post createPost(PostCreateRequest request, Long userId) {
request.title(),
request.content(),
null, // AI로 생성될 요약
request.businessName(),
request.status(),
request.withWhoTag(),
request.forWhatTag(),
request.emotionTags(),
request.category(),
request.travelDate(),
null, // 발행일은 별도 로직으로 처리
request.location(),
request.address(),
0, // 초기 조회수
0, // 초기 좋아요 수
Expand All @@ -124,8 +124,8 @@ public static Post updatePostFromCommand(Post existingPost, PostUpdateRequest re
request.title() != null ? request.title() : existingPost.getTitle(),
request.content() != null ? request.content() : existingPost.getContent(),
existingPost.getSummary(),
existingPost.getBusinessName(),
request.status() != null ? request.status() : existingPost.getStatus(),
request.withWhoTag() != null ? request.withWhoTag() : existingPost.getWithWhoTag(),
request.forWhatTag() != null ? request.forWhatTag() : existingPost.getForWhatTag(),
request.emotionTags() != null ? request.emotionTags() : existingPost.getEmotionTags(),
existingPost.getCategory(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ public Page<Post> handle(PostListRequest request) {
return retrievePosts(request.sortBy(), pageable, request.status());
}

public Page<Post> handleMyPosts(PostListRequest request, Long userId) {
Pageable pageable = buildPageable(request);
return postRepository.findByUserId(userId, pageable);
}


public Slice<Post> handleSlice(PostSliceRequest request) {
log.debug("무한스크롤 게시물 조회: lastPostId={}, size={}",
request.lastPostId(), request.size());
Expand All @@ -32,6 +38,7 @@ public Slice<Post> handleSlice(PostSliceRequest request) {
}



private Pageable buildPageable(PostListRequest request) {
Sort sort = determineSort(request.sortBy());
return PageRequest.of(request.page(), request.size(), sort);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,9 @@ Page<Post> findByStatus(
Long findMaxPostId();

boolean existsByIdLessThan(Long postId);

Page<Post> findByUserId(
Long userId,
Pageable pageable
);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package backend.airo.domain.user.repository;

import backend.airo.domain.AggregateSupport;
import backend.airo.domain.post.Post;
import backend.airo.domain.user.User;
import backend.airo.domain.user.enums.ProviderType;
import backend.airo.persistence.post.entity.PostEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import java.util.Optional;

Expand All @@ -15,4 +19,6 @@ public interface UserRepository extends AggregateSupport<User, Long> {

// User와 연관된 모든 데이터를 함께 삭제
void deleteUserWithRelatedData(Long userId);


}
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,20 @@ public boolean existsByIdLessThan(Long id) {
return postJpaRepository.existsByIdLessThan(id);
}



@Override
public Page<Post> findByUserId(Long userId, Pageable pageable) {
log.debug("사용자 ID로 게시물 조회: userId={}, 페이지: {}", userId, pageable);
Page<PostEntity> entities = postJpaRepository.findByUserId(userId, pageable);
return entities.map(PostEntity::toDomain);
}






// ===== Private Helper Methods =====

private PostEntity updateExistingEntity(Post post) {
Expand All @@ -205,4 +219,7 @@ private PostEntity updateExistingEntity(Post post) {

return PostEntity.toEntity(post);
}



}
Loading