Skip to content

Commit 24d1e4b

Browse files
Merge pull request #119 from pknu-wap/revert-118-feature/seojin/#107
Revert "feat : 마이페이지 게시글 조회"
2 parents 9a45779 + 157b125 commit 24d1e4b

11 files changed

Lines changed: 152 additions & 106 deletions

File tree

src/main/java/com/example/trace/global/errorcode/UserErrorCode.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
@RequiredArgsConstructor
99
public enum UserErrorCode implements ErrorCode{
1010
USER_NOT_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 사용자입니다."),
11-
ALREADY_IN_USE_NICKNAME(HttpStatus.BAD_REQUEST, "닉네임이 중복됩니다."),
12-
INVALID_NICKNAME_LENGTH(HttpStatus.BAD_REQUEST, "닉네임은 2-12자 이내여야 합니다."),
13-
INVALID_NICKNAME_FORMAT(HttpStatus.BAD_REQUEST, "닉네임은 공백만으로 이루어질 수 없습니다.");
11+
ALREADY_IN_USE_NICKNAME(HttpStatus.BAD_REQUEST,"닉네임이 중복됩니다.")
1412

13+
;
1514
private final HttpStatus httpStatus;
1615
private final String message;
1716
}

src/main/java/com/example/trace/post/controller/PostController.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import com.example.trace.gpt.service.PostVerificationService;
55
import com.example.trace.post.domain.PostType;
66
import com.example.trace.post.dto.cursor.CursorResponse;
7-
import com.example.trace.user.dto.UserPostCursorRequest;
7+
import com.example.trace.post.dto.cursor.PostCursorRequest;
88
import com.example.trace.post.dto.post.PostFeedDto;
99
import com.example.trace.user.User;
1010
import com.example.trace.auth.dto.PrincipalDetails;
@@ -30,6 +30,7 @@
3030

3131
import java.util.List;
3232

33+
3334
@RestController
3435
@RequestMapping("/posts")
3536
@RequiredArgsConstructor
@@ -101,6 +102,7 @@ public ResponseEntity<PostDto> createPostWithVerification(
101102
return ResponseEntity.status(HttpStatus.CREATED).body(postDto);
102103
}
103104

105+
104106
@GetMapping("/{id}")
105107
@Operation(summary = "게시글 조회", description = "게시글을 조회합니다.")
106108
@ApiResponse(
@@ -123,7 +125,7 @@ public ResponseEntity<PostDto> getPost(
123125
@PostMapping("/feed")
124126
@Operation(summary = "게시글 커서 기반 페이징 조회", description = "커서 기반 페이징으로 게시글을 조회합니다.")
125127
public ResponseEntity<CursorResponse<PostFeedDto>> getAllPosts(
126-
@RequestBody UserPostCursorRequest request,
128+
@RequestBody PostCursorRequest request,
127129
@AuthenticationPrincipal PrincipalDetails principalDetails) {
128130
String providerId = principalDetails.getUser().getProviderId();
129131
CursorResponse<PostFeedDto> response = postService.getAllPostsWithCursor(
@@ -132,6 +134,7 @@ public ResponseEntity<CursorResponse<PostFeedDto>> getAllPosts(
132134
return ResponseEntity.ok(response);
133135
}
134136

137+
135138
@PutMapping("/{id}")
136139
@Operation(summary = "게시글 수정", description = "게시글을 수정합니다.")
137140
public ResponseEntity<PostDto> updatePost(
@@ -143,6 +146,9 @@ public ResponseEntity<PostDto> updatePost(
143146
return ResponseEntity.ok(updatedPost);
144147
}
145148

149+
150+
151+
146152
@DeleteMapping("/{id}")
147153
@Operation(summary = "게시글 삭제", description = "게시글을 삭제합니다.")
148154
@ApiResponse(
@@ -161,10 +167,12 @@ public ResponseEntity<Void> deletePost(
161167
@PostMapping("/search")
162168
@Operation(summary = "게시글 검색 (커서 기반 페이징)", description = "키워드로 게시글을 검색하고 커서 기반 페이징으로 조회합니다.")
163169
public ResponseEntity<CursorResponse<PostFeedDto>> searchPosts(
164-
@RequestBody UserPostCursorRequest request,
170+
@RequestBody PostCursorRequest request,
165171
@AuthenticationPrincipal PrincipalDetails principalDetails) {
172+
166173
String providerId = principalDetails.getUser().getProviderId();
167174
CursorResponse<PostFeedDto> response = postService.searchPostsWithCursor(request, providerId);
175+
168176
return ResponseEntity.ok(response);
169177
}
170178

src/main/java/com/example/trace/user/dto/UserPostCursorRequest.java renamed to src/main/java/com/example/trace/post/dto/cursor/PostCursorRequest.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
package com.example.trace.user.dto;
1+
package com.example.trace.post.dto.cursor;
22

3+
import com.example.trace.post.domain.PostType;
34
import com.example.trace.post.domain.cursor.SearchType;
45
import io.swagger.v3.oas.annotations.media.Schema;
6+
import jakarta.validation.constraints.Size;
57
import lombok.AllArgsConstructor;
68
import lombok.Builder;
79
import lombok.Data;
@@ -13,15 +15,15 @@
1315
@NoArgsConstructor
1416
@AllArgsConstructor
1517
@Schema(description = "게시글 커서 요청 DTO")
16-
public class UserPostCursorRequest {
18+
public class PostCursorRequest {
1719
@Schema(description = "커서 날짜 및 시간(첫 요청일 시, null)", example = "null")
1820
private LocalDateTime cursorDateTime;
1921
@Schema(description = "커서 ID(첫 요청일 시, null)", example = "null")
2022
private Long cursorId;
2123
@Schema(description = "페이지 크기", example = "10")
2224
private Integer size = 10; // 기본 페이지 크기
23-
@Schema(description = "마이페이지 탭 타입", example = "WRITTEN_POSTS")
24-
private MyPageTab myPageTab;
25+
@Schema(description = "게시글 타입", example = "MISSION")
26+
private PostType postType; // 필터링을 위한 게시글 타입 (선택적)
2527

2628
// 검색을 위한 필드
2729
@Schema(description = "검색 키워드", example = "")
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
package com.example.trace.post.repository;
22

3+
34
import com.example.trace.post.domain.Post;
5+
import com.example.trace.post.domain.PostType;
6+
import com.example.trace.post.dto.post.PostFeedDto;
47
import org.springframework.data.jpa.repository.JpaRepository;
58
import org.springframework.stereotype.Repository;
69

710
import java.time.LocalDateTime;
811
import java.util.List;
912
import java.util.Optional;
10-
import com.example.trace.post.dto.post.PostFeedDto;
13+
1114

1215
@Repository
1316
public interface PostRepository extends JpaRepository<Post, Long>, PostRepositoryCustom {
1417
Optional<Post> findById(Long postId);
15-
1618
List<PostFeedDto> findPostsWithCursor(
1719
LocalDateTime cursorDateTime,
1820
Long cursorId,
1921
int size,
22+
PostType postType,
2023
String providerId);
24+
25+
2126
}

src/main/java/com/example/trace/post/repository/PostRepositoryCustom.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.example.trace.post.repository;
22

3+
import com.example.trace.post.domain.PostType;
34
import com.example.trace.post.domain.cursor.SearchType;
45
import com.example.trace.post.dto.comment.CommentDto;
56
import com.example.trace.post.dto.post.PostFeedDto;
@@ -12,6 +13,7 @@ List<PostFeedDto> findPostsWithCursor(
1213
LocalDateTime cursorDateTime,
1314
Long cursorId,
1415
int size,
16+
PostType postType,
1517
String providerId
1618
);
1719

@@ -30,6 +32,7 @@ List<PostFeedDto> findPostsWithCursorAndSearch(
3032
LocalDateTime cursorDateTime,
3133
Long cursorId,
3234
int size,
35+
PostType postType,
3336
String keyword,
3437
SearchType searchType,
3538
String providerId

src/main/java/com/example/trace/post/repository/PostRepositoryCustomImpl.java

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ private BooleanExpression postTypeEq(PostType postType) {
4242

4343
StringExpression imageUrlExpr = Expressions.cases()
4444
.when(post.images.isEmpty()).then("")
45-
4645
.otherwise(
4746
JPAExpressions
4847
.select(postImage.imageUrl)
@@ -126,10 +125,18 @@ public List<PostFeedDto> findPostsWithCursor(
126125
LocalDateTime cursorDateTime,
127126
Long cursorId,
128127
int size,
128+
PostType postType,
129129
String providerId) {
130130

131-
BooleanExpression isOwner = (providerId != null) ? post.user.providerId.eq(providerId) : null;
132-
Expression<Long> totalEmotionCount = emotion.count();
131+
// Q클래스 정의
132+
QPost post = QPost.post;
133+
QPostImage postImage = new QPostImage("postImage");
134+
135+
Expression<Long> totalEmotionCount = JPAExpressions
136+
.select(emotion.count())
137+
.from(emotion)
138+
.where(emotion.post.eq(post));
139+
133140

134141
return queryFactory
135142
.select(Projections.constructor(PostFeedDto.class,
@@ -151,18 +158,13 @@ public List<PostFeedDto> findPostsWithCursor(
151158
))
152159
.from(post)
153160
.leftJoin(post.user)
154-
.leftJoin(post.verification)
155-
.leftJoin(post.images, postImage).on(postImage.order.eq(1))
156-
.leftJoin(emotion).on(emotion.post.eq(post))
161+
.leftJoin(post.verification) // verification 조인 추가
157162
.where(
163+
postTypeEq(postType),
158164
postCursorCondition(cursorDateTime, cursorId)
159165
)
160-
.groupBy(post.id, post.postType, post.title, post.content, post.user.providerId,
161-
post.user.nickname, post.user.profileImageUrl, imageUrlExpr, post.viewCount,
162-
post.commentList.size(), post.createdAt, post.updatedAt, isVerifiedExpr,
163-
isOwnerExpr(providerId))
164166
.orderBy(post.createdAt.desc(), post.id.desc())
165-
.limit(size)
167+
.limit(size + 1)
166168
.fetch();
167169
}
168170

@@ -171,12 +173,13 @@ public List<PostFeedDto> findPostsWithCursorAndSearch(
171173
LocalDateTime cursorDateTime,
172174
Long cursorId,
173175
int size,
176+
PostType postType,
174177
String keyword,
175178
SearchType searchType,
176179
String providerId) {
177180

178-
BooleanExpression isOwner = (providerId != null) ? post.user.providerId.eq(providerId) : null;
179-
Expression<Long> totalEmotionCount = emotion.count();
181+
QPost post = QPost.post;
182+
QPostImage postImage = new QPostImage("postImage");
180183

181184
return queryFactory
182185
.select(Projections.constructor(PostFeedDto.class,
@@ -199,18 +202,13 @@ public List<PostFeedDto> findPostsWithCursorAndSearch(
199202
.from(post)
200203
.leftJoin(post.user)
201204
.leftJoin(post.verification)
202-
.leftJoin(post.images, postImage).on(postImage.order.eq(1))
203-
.leftJoin(emotion).on(emotion.post.eq(post))
204205
.where(
205-
searchCondition(keyword, searchType),
206-
postCursorCondition(cursorDateTime, cursorId)
206+
postTypeEq(postType),
207+
postCursorCondition(cursorDateTime, cursorId),
208+
searchCondition(keyword, searchType) // 새로 추가할 검색 조건
207209
)
208-
.groupBy(post.id, post.postType, post.title, post.content, post.user.providerId,
209-
post.user.nickname, post.user.profileImageUrl, imageUrlExpr, post.viewCount,
210-
post.commentList.size(), post.createdAt, post.updatedAt, isVerifiedExpr,
211-
isOwnerExpr(providerId))
212210
.orderBy(post.createdAt.desc(), post.id.desc())
213-
.limit(size)
211+
.limit(size + 1)
214212
.fetch();
215213
}
216214

src/main/java/com/example/trace/post/service/PostService.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.example.trace.gpt.dto.VerificationDto;
44
import com.example.trace.post.dto.cursor.CursorResponse;
5-
import com.example.trace.user.dto.UserPostCursorRequest;
5+
import com.example.trace.post.dto.cursor.PostCursorRequest;
66
import com.example.trace.post.dto.post.PostFeedDto;
77
import com.example.trace.post.dto.post.PostUpdateDto;
88
import com.example.trace.post.dto.post.PostCreateDto;
@@ -18,12 +18,15 @@ public interface PostService {
1818
PostDto getPostById(Long id, User user);
1919

2020
PostDto updatePost(Long id, PostUpdateDto postUpdateDto,String providerId);
21-
22-
CursorResponse<PostFeedDto> getAllPostsWithCursor(UserPostCursorRequest request, String requesterId);
23-
21+
CursorResponse<PostFeedDto> getAllPostsWithCursor(PostCursorRequest request, String requesterId);
2422
void deletePost(Long id, String providerId);
2523

26-
CursorResponse<PostFeedDto> searchPostsWithCursor(UserPostCursorRequest request, String providerId);
24+
CursorResponse<PostFeedDto> searchPostsWithCursor(PostCursorRequest request, String providerId);
25+
26+
CursorResponse<PostFeedDto> getMyPostsWithCursor(PostCursorRequest request, String providerId);
27+
28+
CursorResponse<PostFeedDto> getUserCommentedPostsWithCursor(PostCursorRequest request, String providerId);
29+
30+
CursorResponse<PostFeedDto> getUserEmotedPostsWithCursor(PostCursorRequest request, String providerId);
2731

28-
CursorResponse<PostFeedDto> getMyPagePostsWithCursor(UserPostCursorRequest request, String providerId);
2932
}

0 commit comments

Comments
 (0)