Skip to content

Commit

Permalink
refactor: add field to response
Browse files Browse the repository at this point in the history
  • Loading branch information
aiaiaiai1 committed Nov 26, 2024
1 parent 35091c9 commit 302fbf8
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ public ResponseEntity<IdResponse> createPhotoFeed(

@GetMapping("/photos/{photoId}")
public ResponseEntity<PhotoFeedDetailResponse> seePhotoFeed(
@Logined User user,
@PathVariable(name = "photoId") Long photoFeedId
) {
PhotoFeedDetailResponse response = photoFeedService.getPhotoFeed(photoFeedId);
PhotoFeedDetailResponse response = photoFeedService.getPhotoFeed(user, photoFeedId);
return ResponseEntity.ok().body(response);
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/gymmi/photoboard/domain/entity/PhotoFeed.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,8 @@ public void checkWriter(User user) {
throw new NotHavePermissionException(ErrorCode.NOT_PHOTO_FEED_WRITER);
}
}

public boolean isWriter(User user) {
return this.user.equals(user);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@ public class PhotoFeedDetailResponse {
private final LocalDateTime createdAt;
private final Boolean isModified;
private final String nickname;
private final Boolean isMine;
private final Boolean hasMyThumbsUp;

public PhotoFeedDetailResponse(PhotoFeed photoFeed, String photoImageUrl) {
public PhotoFeedDetailResponse(PhotoFeed photoFeed, String photoImageUrl, boolean isMine, boolean hasMyThumbsUp) {
this.profileImageUrl = photoFeed.getUser().getProfileImageName();
this.photoImageUrl = photoImageUrl;
this.comment = photoFeed.getComment();
this.thumpsUpCount = photoFeed.getThumpsUpCount();
this.createdAt = photoFeed.getCreatedAt();
this.isModified = photoFeed.isModified();
this.nickname = photoFeed.getUser().getNickname();
this.isMine = isMine;
this.hasMyThumbsUp = hasMyThumbsUp;
}

}

8 changes: 5 additions & 3 deletions src/main/java/gymmi/photoboard/service/PhotoFeedService.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ public Long createPhotoFeed(User loginedUser, CreatePhotoFeedRequest request) {
}

@Transactional(readOnly = true)
public PhotoFeedDetailResponse getPhotoFeed(Long photoFeedId) {
public PhotoFeedDetailResponse getPhotoFeed(User loginedUser, Long photoFeedId) {
PhotoFeed photoFeed = photoFeedRepository.getByPhotoFeedId(photoFeedId);
PhotoFeedImage photoFeedImage = photoFeedImageRepository.getByPhotoFeedId(photoFeedId);

String photoImagePresignedUrl = s3Service.getPresignedUrl(PhotoFeedImage.IMAGE_USE, photoFeedImage.getFilename());
return new PhotoFeedDetailResponse(photoFeed, photoImagePresignedUrl);
if (thumbsUpRepository.findByUserId(loginedUser.getId()).isEmpty()) {
return new PhotoFeedDetailResponse(photoFeed, photoImagePresignedUrl, photoFeed.isWriter(loginedUser), false);
}
return new PhotoFeedDetailResponse(photoFeed, photoImagePresignedUrl, photoFeed.isWriter(loginedUser), true);
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class PhotoFeedServiceTest extends IntegrationTest {
PhotoFeedImage photoFeedImage = persister.persistPhotoFeedImage(photoFeed);

// when
PhotoFeedDetailResponse result = photoFeedService.getPhotoFeed(photoFeed.getId());
PhotoFeedDetailResponse result = photoFeedService.getPhotoFeed(user, photoFeed.getId());

// then
assertThat(result.getIsModified()).isFalse();
Expand All @@ -73,6 +73,8 @@ class PhotoFeedServiceTest extends IntegrationTest {
assertThat(result.getProfileImageUrl()).isEqualTo(user.getProfileImageName());
assertThat(result.getComment()).isEqualTo(photoFeed.getComment());
assertThat(result.getNickname()).isEqualTo(user.getNickname());
assertThat(result.getIsMine()).isEqualTo(true);
assertThat(result.getHasMyThumbsUp()).isEqualTo(false);
}

@Test
Expand Down

0 comments on commit 302fbf8

Please sign in to comment.