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 @@ -33,6 +33,15 @@ public RsData<MyHistoryPostListDto> getMyPosts(
MyHistoryPostListDto body = myHistoryService.getMyPosts(userId, lastCreatedAt, lastId, limit);
return RsData.successOf(body);
}

@GetMapping("/posts/{id}")
public RsData<com.back.domain.myhistory.dto.MyHistoryPostGoResponseDto> goFromPost(
@AuthenticationPrincipal(expression = "id") Long userId,
@PathVariable("id") Long postId
) {
var body = myHistoryService.getPostLinkFromMyPost(userId, postId);
return RsData.successOf(body);
}

@GetMapping("/comments")
public RsData<MyHistoryCommentListDto> getMyComments(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.back.domain.myhistory.dto;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class MyHistoryPostGoResponseDto {
private Long postId;
private String postApiUrl;
}

Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,10 @@ List<Post> findMyPostsAfter(@Param("userId") Long userId,
@Param("lastCreatedAt") LocalDateTime lastCreatedAt,
@Param("lastId") Long lastId,
Pageable pageable);

@Query("""
select p from Post p
where p.id = :id and p.user.id = :userId
""")
Post findByIdAndUserId(@Param("id") Long id, @Param("userId") Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,17 @@ public MyHistoryCommentGoResponseDto getPostLinkFromMyComment(Long userId, Long
String apiUrl = "/api/posts/" + postId;
return new MyHistoryCommentGoResponseDto(postId, apiUrl);
}

@Transactional(readOnly = true)
public MyHistoryPostGoResponseDto getPostLinkFromMyPost(Long userId, Long postId) {
Post p = myHistoryPostRepository.findByIdAndUserId(postId, userId);
if (p == null) {
throw new ServiceException(404, "게시글을 찾을 수 없습니다.");
}
if (p.getStatus() == PostStatus.DELETED) {
throw new ServiceException(410, "삭제된 게시글입니다.");
}
String apiUrl = "/api/posts/" + p.getId();
return new MyHistoryPostGoResponseDto(p.getId(), apiUrl);
}
}