Skip to content

Commit

Permalink
refactor: add return value
Browse files Browse the repository at this point in the history
- fix add unique constraint on tables
  • Loading branch information
aiaiaiai1 committed Nov 24, 2024
1 parent 5797aea commit 8910994
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import gymmi.photoboard.response.PhotoFeedDetailResponse;
import gymmi.photoboard.response.PhotoFeedResponse;
import gymmi.photoboard.service.PhotoFeedService;
import gymmi.response.IdResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
Expand All @@ -20,12 +21,12 @@ public class PhotoBoardController {
private final PhotoFeedService photoFeedService;

@PostMapping("/photos")
public ResponseEntity<Void> createPhotoFeed(
public ResponseEntity<IdResponse> createPhotoFeed(
@Logined User user,
@Validated @RequestBody CreatePhotoFeedRequest request
) {
photoFeedService.createPhotoFeed(user, request);
return ResponseEntity.ok().build();
Long id = photoFeedService.createPhotoFeed(user, request);
return ResponseEntity.ok().body(new IdResponse(id));
}

@GetMapping("/photos/{photoId}")
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/gymmi/photoboard/service/PhotoFeedService.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ public class PhotoFeedService {
private final ThumbsUpRepository thumbsUpRepository;

@Transactional
public void createPhotoFeed(User loginedUser, CreatePhotoFeedRequest request) {
public Long createPhotoFeed(User loginedUser, CreatePhotoFeedRequest request) {
PhotoFeed photoFeed = new PhotoFeed(loginedUser, request.getComment());
PhotoFeedImage photoFeedImage = new PhotoFeedImage(photoFeed, request.getFilename());
s3Service.checkObjectExist(PhotoFeedImage.IMAGE_USE, photoFeedImage.getFilename());
photoFeedRepository.save(photoFeed);
PhotoFeed savedPhotoFeed = photoFeedRepository.save(photoFeed);
photoFeedImageRepository.save(photoFeedImage);
return savedPhotoFeed.getId();
}

@Transactional(readOnly = true)
Expand Down

0 comments on commit 8910994

Please sign in to comment.