Skip to content

Commit 83d5cf7

Browse files
Merge pull request #116 from pknu-wap/feature/seojin/#107
Feature/seojin/#107
2 parents 6a16f2b + 26ea97f commit 83d5cf7

8 files changed

Lines changed: 335 additions & 12 deletions

File tree

src/main/java/com/example/trace/gpt/service/PostVerificationServiceImpl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,15 @@ public VerificationDto verifyDailyMission(SubmitDailyMissionDto submitDto,DailyM
7272
VerificationDto result = verifyMissionTextOnly(requestContent, assignedContent);
7373
if (!result.isTextResult()) {
7474
String failureReason = result.getFailureReason();
75+
log.info("실패 이유 : {}",failureReason);
7576
throw new GptException(GptErrorCode.WRONG_CONTENT, failureReason);
7677
}
7778
return result;
7879
} else {
7980
VerificationDto result = verifyMissionTextAndImages(requestContent, assignedContent, images);
8081
if (!result.isTextResult() || !result.isImageResult()) {
8182
String failureReason = result.getFailureReason();
83+
log.info("실패 이유 : {}",failureReason);
8284
throw new GptException(GptErrorCode.WRONG_CONTENT, failureReason);
8385
}
8486
return result;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,4 +175,5 @@ public ResponseEntity<CursorResponse<PostFeedDto>> searchPosts(
175175

176176
return ResponseEntity.ok(response);
177177
}
178+
178179
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,24 @@ List<PostFeedDto> findPostsWithCursorAndSearch(
3838
String providerId
3939
);
4040

41+
List<PostFeedDto> findUserPosts(
42+
String providerId,
43+
LocalDateTime cursorDateTime,
44+
Long cursorId,
45+
int size
46+
);
47+
48+
List<PostFeedDto> findUserCommentedPosts(
49+
String providerId,
50+
LocalDateTime cursorDateTime,
51+
Long cursorId,
52+
int size
53+
);
54+
55+
List<PostFeedDto> findUserEmotedPosts(
56+
String providerId,
57+
LocalDateTime cursorDateTime,
58+
Long cursorId,
59+
int size
60+
);
4161
}

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

Lines changed: 145 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,20 @@ private BooleanExpression postTypeEq(PostType postType) {
4141
}
4242

4343
StringExpression imageUrlExpr = Expressions.cases()
44-
.when(post.images.isEmpty())
45-
.then("")
44+
.when(post.images.isEmpty()).then("")
4645
.otherwise(
4746
JPAExpressions
4847
.select(postImage.imageUrl)
4948
.from(postImage)
50-
.where(postImage.post.eq(post))
51-
.orderBy(postImage.id.asc())
52-
.limit(1)
49+
.where(
50+
postImage.post.eq(post)
51+
.and(postImage.id.eq(
52+
JPAExpressions
53+
.select(postImage.id.min())
54+
.from(postImage)
55+
.where(postImage.post.eq(post))
56+
))
57+
)
5358
);
5459
Expression<Long> totalEmotionCount = JPAExpressions
5560
.select(emotion.count())
@@ -142,7 +147,7 @@ public List<PostFeedDto> findPostsWithCursor(
142147
post.user.providerId,
143148
post.user.nickname,
144149
post.user.profileImageUrl,
145-
imageUrlExpr, // 서브쿼리 사용
150+
imageUrlExpr,
146151
post.viewCount,
147152
post.commentList.size().longValue(),
148153
post.createdAt,
@@ -154,10 +159,9 @@ public List<PostFeedDto> findPostsWithCursor(
154159
.from(post)
155160
.leftJoin(post.user)
156161
.leftJoin(post.verification) // verification 조인 추가
157-
.leftJoin(post.images, postImage).on(postImage.order.eq(1))
158162
.where(
159163
postTypeEq(postType),
160-
postCursorCondition(cursorDateTime, cursorId) // 커서 조건
164+
postCursorCondition(cursorDateTime, cursorId)
161165
)
162166
.orderBy(post.createdAt.desc(), post.id.desc())
163167
.limit(size + 1)
@@ -198,7 +202,6 @@ public List<PostFeedDto> findPostsWithCursorAndSearch(
198202
.from(post)
199203
.leftJoin(post.user)
200204
.leftJoin(post.verification)
201-
.leftJoin(post.images, postImage).on(postImage.order.eq(1))
202205
.where(
203206
postTypeEq(postType),
204207
postCursorCondition(cursorDateTime, cursorId),
@@ -277,5 +280,138 @@ public List<CommentDto> findComments(
277280
return allComments;
278281
}
279282

283+
@Override
284+
public List<PostFeedDto> findUserPosts(
285+
String providerId,
286+
LocalDateTime cursorDateTime,
287+
Long cursorId,
288+
int size) {
289+
290+
return queryFactory
291+
.select(Projections.constructor(PostFeedDto.class,
292+
post.id.as("postId"),
293+
post.postType,
294+
post.title,
295+
post.content,
296+
post.user.providerId,
297+
post.user.nickname,
298+
post.user.profileImageUrl,
299+
imageUrlExpr,
300+
post.viewCount,
301+
post.commentList.size().longValue(),
302+
post.createdAt,
303+
post.updatedAt,
304+
isVerifiedExpr,
305+
isOwnerExpr(providerId),
306+
totalEmotionCount
307+
))
308+
.from(post)
309+
.leftJoin(post.user)
310+
.leftJoin(post.verification)
311+
.where(
312+
post.user.providerId.eq(providerId),
313+
postCursorCondition(cursorDateTime, cursorId)
314+
)
315+
.orderBy(post.createdAt.desc(), post.id.desc())
316+
.limit(size + 1)
317+
.fetch();
318+
}
319+
320+
@Override
321+
public List<PostFeedDto> findUserCommentedPosts(
322+
String providerId,
323+
LocalDateTime cursorDateTime,
324+
Long cursorId,
325+
int size) {
326+
327+
Expression<Long> totalEmotionCount = JPAExpressions
328+
.select(emotion.count())
329+
.from(emotion)
330+
.where(emotion.post.eq(post));
331+
332+
return queryFactory
333+
.select(Projections.constructor(PostFeedDto.class,
334+
post.id.as("postId"),
335+
post.postType,
336+
post.title,
337+
post.content,
338+
post.user.providerId,
339+
post.user.nickname,
340+
post.user.profileImageUrl,
341+
imageUrlExpr,
342+
post.viewCount,
343+
post.commentList.size().longValue(),
344+
post.createdAt,
345+
post.updatedAt,
346+
isVerifiedExpr,
347+
isOwnerExpr(providerId),
348+
totalEmotionCount
349+
))
350+
.from(post)
351+
.leftJoin(post.user)
352+
.leftJoin(post.verification)
353+
.where(
354+
post.id.in(
355+
JPAExpressions
356+
.select(comment.post.id)
357+
.from(comment)
358+
.where(
359+
comment.user.providerId.eq(providerId),
360+
comment.isDeleted.eq(false)
361+
)
362+
),
363+
postCursorCondition(cursorDateTime, cursorId)
364+
)
365+
.orderBy(post.createdAt.desc(), post.id.desc())
366+
.limit(size + 1)
367+
.fetch();
368+
}
369+
370+
@Override
371+
public List<PostFeedDto> findUserEmotedPosts(
372+
String providerId,
373+
LocalDateTime cursorDateTime,
374+
Long cursorId,
375+
int size) {
376+
377+
Expression<Long> totalEmotionCount = JPAExpressions
378+
.select(emotion.count())
379+
.from(emotion)
380+
.where(emotion.post.eq(post));
381+
382+
return queryFactory
383+
.select(Projections.constructor(PostFeedDto.class,
384+
post.id.as("postId"),
385+
post.postType,
386+
post.title,
387+
post.content,
388+
post.user.providerId,
389+
post.user.nickname,
390+
post.user.profileImageUrl,
391+
imageUrlExpr,
392+
post.viewCount,
393+
post.commentList.size().longValue(),
394+
post.createdAt,
395+
post.updatedAt,
396+
isVerifiedExpr,
397+
isOwnerExpr(providerId),
398+
totalEmotionCount
399+
))
400+
.from(post)
401+
.leftJoin(post.user)
402+
.leftJoin(post.verification)
403+
.where(
404+
post.id.in(
405+
JPAExpressions
406+
.select(emotion.post.id)
407+
.from(emotion)
408+
.where(emotion.user.providerId.eq(providerId))
409+
),
410+
postCursorCondition(cursorDateTime, cursorId)
411+
)
412+
.orderBy(post.createdAt.desc(), post.id.desc())
413+
.limit(size + 1)
414+
.fetch();
415+
}
280416

281417
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import com.example.trace.post.dto.post.PostCreateDto;
99
import com.example.trace.post.dto.post.PostDto;
1010
import com.example.trace.user.User;
11-
11+
import java.util.List;
1212

1313
public interface PostService {
1414

@@ -24,4 +24,10 @@ public interface PostService {
2424

2525
CursorResponse<PostFeedDto> searchPostsWithCursor(PostCursorRequest request, String providerId);
2626

27+
CursorResponse<PostFeedDto> getMyPostsWithCursor(PostCursorRequest request, String providerId);
28+
29+
CursorResponse<PostFeedDto> getUserCommentedPostsWithCursor(PostCursorRequest request, String providerId);
30+
31+
CursorResponse<PostFeedDto> getUserEmotedPostsWithCursor(PostCursorRequest request, String providerId);
32+
2733
}

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

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,129 @@ private void validateKeyword(String keyword) {
298298
}
299299
}
300300

301+
@Transactional(readOnly = true)
302+
public CursorResponse<PostFeedDto> getUserCommentedPostsWithCursor(PostCursorRequest request, String providerId) {
303+
// 커서 요청 처리
304+
int size = request.getSize() != null ? request.getSize() : 10;
305+
306+
// 게시글 조회
307+
List<PostFeedDto> posts;
308+
if (request.getCursorDateTime() == null || request.getCursorId() == null) {
309+
// 첫 페이지 조회
310+
posts = postRepository.findUserCommentedPosts(providerId, null, null, size + 1);
311+
} else {
312+
// 다음 페이지 조회
313+
posts = postRepository.findUserCommentedPosts(
314+
providerId, request.getCursorDateTime(), request.getCursorId(), size + 1);
315+
}
316+
317+
// 다음 페이지 여부 확인
318+
boolean hasNext = false;
319+
if (posts.size() > size) {
320+
hasNext = true;
321+
posts = posts.subList(0, size);
322+
}
323+
324+
// 커서 메타데이터 생성
325+
CursorResponse.CursorMeta nextCursor = null;
326+
if (!posts.isEmpty() && hasNext) {
327+
PostFeedDto lastPost = posts.get(posts.size() - 1);
328+
nextCursor = CursorResponse.CursorMeta.builder()
329+
.dateTime(lastPost.getCreatedAt())
330+
.id(lastPost.getPostId())
331+
.build();
332+
}
333+
334+
// 응답 생성
335+
return CursorResponse.<PostFeedDto>builder()
336+
.content(posts)
337+
.hasNext(hasNext)
338+
.cursor(nextCursor)
339+
.build();
340+
}
341+
342+
@Override
343+
@Transactional(readOnly = true)
344+
public CursorResponse<PostFeedDto> getMyPostsWithCursor(PostCursorRequest request, String providerId) {
345+
// 커서 요청 처리
346+
int size = request.getSize() != null ? request.getSize() : 10;
347+
348+
// 게시글 조회
349+
List<PostFeedDto> posts;
350+
if (request.getCursorDateTime() == null || request.getCursorId() == null) {
351+
// 첫 페이지 조회
352+
posts = postRepository.findUserPosts(providerId, null, null, size + 1);
353+
} else {
354+
// 다음 페이지 조회
355+
posts = postRepository.findUserPosts(
356+
providerId, request.getCursorDateTime(), request.getCursorId(), size + 1);
357+
}
358+
359+
// 다음 페이지 여부 확인
360+
boolean hasNext = false;
361+
if (posts.size() > size) {
362+
hasNext = true;
363+
posts = posts.subList(0, size);
364+
}
301365

366+
// 커서 메타데이터 생성
367+
CursorResponse.CursorMeta nextCursor = null;
368+
if (!posts.isEmpty() && hasNext) {
369+
PostFeedDto lastPost = posts.get(posts.size() - 1);
370+
nextCursor = CursorResponse.CursorMeta.builder()
371+
.dateTime(lastPost.getCreatedAt())
372+
.id(lastPost.getPostId())
373+
.build();
374+
}
375+
376+
// 응답 생성
377+
return CursorResponse.<PostFeedDto>builder()
378+
.content(posts)
379+
.hasNext(hasNext)
380+
.cursor(nextCursor)
381+
.build();
382+
}
383+
384+
@Override
385+
@Transactional(readOnly = true)
386+
public CursorResponse<PostFeedDto> getUserEmotedPostsWithCursor(PostCursorRequest request, String providerId) {
387+
// 커서 요청 처리
388+
int size = request.getSize() != null ? request.getSize() : 10;
389+
390+
// 게시글 조회
391+
List<PostFeedDto> posts;
392+
if (request.getCursorDateTime() == null || request.getCursorId() == null) {
393+
// 첫 페이지 조회
394+
posts = postRepository.findUserEmotedPosts(providerId, null, null, size + 1);
395+
} else {
396+
// 다음 페이지 조회
397+
posts = postRepository.findUserEmotedPosts(
398+
providerId, request.getCursorDateTime(), request.getCursorId(), size + 1);
399+
}
400+
401+
// 다음 페이지 여부 확인
402+
boolean hasNext = false;
403+
if (posts.size() > size) {
404+
hasNext = true;
405+
posts = posts.subList(0, size);
406+
}
407+
408+
// 커서 메타데이터 생성
409+
CursorResponse.CursorMeta nextCursor = null;
410+
if (!posts.isEmpty() && hasNext) {
411+
PostFeedDto lastPost = posts.get(posts.size() - 1);
412+
nextCursor = CursorResponse.CursorMeta.builder()
413+
.dateTime(lastPost.getCreatedAt())
414+
.id(lastPost.getPostId())
415+
.build();
416+
}
417+
418+
// 응답 생성
419+
return CursorResponse.<PostFeedDto>builder()
420+
.content(posts)
421+
.hasNext(hasNext)
422+
.cursor(nextCursor)
423+
.build();
424+
}
302425

303426
}

0 commit comments

Comments
 (0)