Skip to content

Commit 22698bf

Browse files
committed
feat: 내가 '좋아요'한 게시글 링크 기능 추가
- 사용자가 '좋아요'를 누른 게시글의 링크를 반환하는 `getPostLinkFromMyLikedPost` 메서드 추가 - `MyHistoryLikedPostRepository`를 사용하여 특정 게시글에 대한 사용자의 '좋아요' 기록을 조회 - '좋아요' 기록이 없거나 게시글이 삭제된 경우 예외 처리
1 parent dd80e12 commit 22698bf

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/main/java/com/back/domain/myhistory/service/MyHistoryService.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public MyHistoryLikedPostListDto getMyLikedPosts(Long userId, LocalDateTime last
139139
if (hasNext) rows = rows.subList(0, safeLimit);
140140

141141
List<MyHistoryLikedPostItemDto> items = new ArrayList<>();
142-
for (com.back.domain.post.post.entity.PostLike pl : rows) items.add(MyHistoryLikedPostItemDto.from(pl));
142+
for (com.back.domain.post.post.entity.PostLike postLike : rows) items.add(MyHistoryLikedPostItemDto.from(postLike));
143143

144144
LocalDateTime nextCreatedAt = null;
145145
Long nextId = null;
@@ -151,4 +151,22 @@ public MyHistoryLikedPostListDto getMyLikedPosts(Long userId, LocalDateTime last
151151

152152
return new MyHistoryLikedPostListDto(items, hasNext, nextCreatedAt, nextId);
153153
}
154+
155+
@Transactional(readOnly = true)
156+
public MyHistoryPostGoResponseDto getPostLinkFromMyLikedPost(Long userId, Long postId) {
157+
com.back.domain.post.post.entity.PostLike postLike = myHistoryLikedPostRepository.findByPostIdAndUserIdLike(
158+
postId,
159+
userId,
160+
com.back.domain.post.post.enums.PostLikeStatus.LIKE
161+
);
162+
if (postLike == null) {
163+
throw new ServiceException(404, "좋아요한 게시글을 찾을 수 없습니다.");
164+
}
165+
Post post = postLike.getPost();
166+
if (post.getStatus() == PostStatus.DELETED) {
167+
throw new ServiceException(410, "삭제된 게시글입니다.");
168+
}
169+
String apiUrl = "/api/posts/" + post.getId();
170+
return new MyHistoryPostGoResponseDto(post.getId(), apiUrl);
171+
}
154172
}

0 commit comments

Comments
 (0)