From 578ca96118fa352a2373e4fba5c42fe1dbbf991e Mon Sep 17 00:00:00 2001 From: Gyoungmin Kim Date: Tue, 2 Jul 2024 19:52:18 +0900 Subject: [PATCH 1/6] feat: add db migration v2 (#11) * feat: create photo table --- .../main/resources/db/migration/V2__createPhotoTable.sql | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 photo-service/src/main/resources/db/migration/V2__createPhotoTable.sql diff --git a/photo-service/src/main/resources/db/migration/V2__createPhotoTable.sql b/photo-service/src/main/resources/db/migration/V2__createPhotoTable.sql new file mode 100644 index 0000000..ab53314 --- /dev/null +++ b/photo-service/src/main/resources/db/migration/V2__createPhotoTable.sql @@ -0,0 +1,9 @@ +CREATE TABLE photo( + `id` CHAR(26) PRIMARY KEY NOT NULL COMMENT '사진아이디', + `url` VARCHAR(255) NOT NULL COMMENT '사진url', + `owner_member_id` CHAR(26) NOT NULL COMMENT '사진소유자아이디', + `owner_album_id` CHAR(26) NULL COMMENT '사진소유앨범아이디', + `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + INDEX `photo_idx1` (`owner_member_id`) +); From fb4bb3fa4181fe7005fffb6df5409f4f823d8b58 Mon Sep 17 00:00:00 2001 From: Gyoungmin Kim Date: Tue, 2 Jul 2024 19:53:19 +0900 Subject: [PATCH 2/6] feat: add photo domain entity (#11) * feat: create PhotoEntity * feat: create PhotoRepository * feat: create fromEntity in PhotoResponse --- .../dto/response/PhotoResponse.java | 10 +++ .../kr/mafoo/photo/domain/PhotoEntity.java | 75 +++++++++++++++++++ .../photo/repository/PhotoRepository.java | 7 ++ 3 files changed, 92 insertions(+) create mode 100644 photo-service/src/main/java/kr/mafoo/photo/domain/PhotoEntity.java create mode 100644 photo-service/src/main/java/kr/mafoo/photo/repository/PhotoRepository.java diff --git a/photo-service/src/main/java/kr/mafoo/photo/controller/dto/response/PhotoResponse.java b/photo-service/src/main/java/kr/mafoo/photo/controller/dto/response/PhotoResponse.java index 298bedf..c284b9c 100644 --- a/photo-service/src/main/java/kr/mafoo/photo/controller/dto/response/PhotoResponse.java +++ b/photo-service/src/main/java/kr/mafoo/photo/controller/dto/response/PhotoResponse.java @@ -1,6 +1,7 @@ package kr.mafoo.photo.controller.dto.response; import io.swagger.v3.oas.annotations.media.Schema; +import kr.mafoo.photo.domain.PhotoEntity; @Schema(description = "사진 응답") public record PhotoResponse( @@ -13,4 +14,13 @@ public record PhotoResponse( @Schema(description = "앨범 ID", example = "test_album_id") String albumId ) { + public static PhotoResponse fromEntity( + PhotoEntity entity + ) { + return new PhotoResponse( + entity.getPhotoId(), + entity.getPhotoUrl(), + entity.getOwnerAlbumId() + ); + } } diff --git a/photo-service/src/main/java/kr/mafoo/photo/domain/PhotoEntity.java b/photo-service/src/main/java/kr/mafoo/photo/domain/PhotoEntity.java new file mode 100644 index 0000000..8ebe5af --- /dev/null +++ b/photo-service/src/main/java/kr/mafoo/photo/domain/PhotoEntity.java @@ -0,0 +1,75 @@ +package kr.mafoo.photo.domain; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.Id; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.annotation.Transient; +import org.springframework.data.domain.Persistable; +import org.springframework.data.relational.core.mapping.Column; +import org.springframework.data.relational.core.mapping.Table; + +import java.time.LocalDateTime; + +@Getter +@NoArgsConstructor +@Table("photo") +public class PhotoEntity implements Persistable { + @Id + @Column("id") + private String photoId; + + @Column("url") + private String photoUrl; + + @Column("owner_member_id") + private String ownerMemberId; + + @Column("owner_album_id") + private String ownerAlbumId; + + @CreatedDate + @Column("created_at") + private LocalDateTime createdAt; + + @LastModifiedDate + @Column("updated_at") + private LocalDateTime updatedAt; + + @Transient + private boolean isNew = false; + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null || getClass() != obj.getClass()) return false; + + PhotoEntity that = (PhotoEntity) obj; + return photoId.equals(that.photoId); + } + + @Override + public int hashCode() { + return photoId.hashCode(); + } + + @Override + public String getId() { + return photoId; + } + + public PhotoEntity updateOwnerAlbumId(String albumId) { + this.ownerAlbumId = albumId; + return this; + } + + public static PhotoEntity newPhoto(String photoId, String photoUrl, String ownerMemberId) { + PhotoEntity photo = new PhotoEntity(); + photo.photoId = photoId; + photo.photoUrl = photoUrl; + photo.ownerMemberId = ownerMemberId; + photo.isNew = true; + return photo; + } +} diff --git a/photo-service/src/main/java/kr/mafoo/photo/repository/PhotoRepository.java b/photo-service/src/main/java/kr/mafoo/photo/repository/PhotoRepository.java new file mode 100644 index 0000000..aaeb94e --- /dev/null +++ b/photo-service/src/main/java/kr/mafoo/photo/repository/PhotoRepository.java @@ -0,0 +1,7 @@ +package kr.mafoo.photo.repository; + +import kr.mafoo.photo.domain.PhotoEntity; +import org.springframework.data.r2dbc.repository.R2dbcRepository; + +public interface PhotoRepository extends R2dbcRepository { +} \ No newline at end of file From 370bec9624c26912f899e9d4792f63fc676aff40 Mon Sep 17 00:00:00 2001 From: Gyoungmin Kim Date: Tue, 2 Jul 2024 19:53:59 +0900 Subject: [PATCH 3/6] feat: add photo domain exception (#11) * feat: create PhotoNotFoundException --- .../src/main/java/kr/mafoo/photo/exception/ErrorCode.java | 1 + .../kr/mafoo/photo/exception/PhotoNotFoundException.java | 7 +++++++ 2 files changed, 8 insertions(+) create mode 100644 photo-service/src/main/java/kr/mafoo/photo/exception/PhotoNotFoundException.java diff --git a/photo-service/src/main/java/kr/mafoo/photo/exception/ErrorCode.java b/photo-service/src/main/java/kr/mafoo/photo/exception/ErrorCode.java index 8852dac..5c9d304 100644 --- a/photo-service/src/main/java/kr/mafoo/photo/exception/ErrorCode.java +++ b/photo-service/src/main/java/kr/mafoo/photo/exception/ErrorCode.java @@ -7,6 +7,7 @@ @RequiredArgsConstructor public enum ErrorCode { ALBUM_NOT_FOUND("AE0001", "앨범을 찾을 수 없습니다"), + PHOTO_NOT_FOUND("PE0001", "사진을 찾을 수 없습니다"), ; private final String code; diff --git a/photo-service/src/main/java/kr/mafoo/photo/exception/PhotoNotFoundException.java b/photo-service/src/main/java/kr/mafoo/photo/exception/PhotoNotFoundException.java new file mode 100644 index 0000000..3fb32dd --- /dev/null +++ b/photo-service/src/main/java/kr/mafoo/photo/exception/PhotoNotFoundException.java @@ -0,0 +1,7 @@ +package kr.mafoo.photo.exception; + +public class PhotoNotFoundException extends DomainException { + public PhotoNotFoundException() { + super(ErrorCode.PHOTO_NOT_FOUND); + } +} From 40c80f60810d841efae254a212b9f5b9224b1dd8 Mon Sep 17 00:00:00 2001 From: Gyoungmin Kim Date: Tue, 2 Jul 2024 20:04:12 +0900 Subject: [PATCH 4/6] feat: implement photo api (#11) --- .../java/kr/mafoo/photo/api/PhotoApi.java | 21 ++++-- .../photo/controller/PhotoController.java | 32 +++++---- ...st.java => PhotoUpdateAlbumIdRequest.java} | 2 +- .../photo/repository/PhotoRepository.java | 2 + .../kr/mafoo/photo/service/PhotoService.java | 71 +++++++++++++++++++ 5 files changed, 111 insertions(+), 17 deletions(-) rename photo-service/src/main/java/kr/mafoo/photo/controller/dto/request/{PhotoAlbumUpdateRequest.java => PhotoUpdateAlbumIdRequest.java} (86%) create mode 100644 photo-service/src/main/java/kr/mafoo/photo/service/PhotoService.java diff --git a/photo-service/src/main/java/kr/mafoo/photo/api/PhotoApi.java b/photo-service/src/main/java/kr/mafoo/photo/api/PhotoApi.java index 9f8018c..84915f1 100644 --- a/photo-service/src/main/java/kr/mafoo/photo/api/PhotoApi.java +++ b/photo-service/src/main/java/kr/mafoo/photo/api/PhotoApi.java @@ -3,8 +3,9 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; +import kr.mafoo.photo.annotation.RequestMemberId; import kr.mafoo.photo.controller.dto.request.PhotoCreateRequest; -import kr.mafoo.photo.controller.dto.request.PhotoAlbumUpdateRequest; +import kr.mafoo.photo.controller.dto.request.PhotoUpdateAlbumIdRequest; import kr.mafoo.photo.controller.dto.response.PhotoResponse; import org.springframework.web.bind.annotation.*; import reactor.core.publisher.Flux; @@ -15,15 +16,21 @@ public interface PhotoApi { @Operation(summary = "사진 조회", description = "사진 목록을 조회합니다.") @GetMapping - Flux getAlbumPhotos( + Flux getPhotos( + @RequestMemberId + String memberId, + @Parameter(description = "앨범 ID", example = "test_album_id") - @RequestParam(required = false) + @RequestParam String albumId ); @Operation(summary = "사진 생성", description = "사진을 생성합니다.") @PostMapping Mono createPhoto( + @RequestMemberId + String memberId, + @RequestBody PhotoCreateRequest request ); @@ -31,17 +38,23 @@ Mono createPhoto( @Operation(summary = "사진 앨범 수정", description = "사진을 다른 앨범으로 이동시킵니다.") @PatchMapping("/{photoId}/album") Mono updatePhotoAlbum( + @RequestMemberId + String memberId, + @Parameter(description = "사진 ID", example = "test_photo_id") @PathVariable String photoId, @RequestBody - PhotoAlbumUpdateRequest request + PhotoUpdateAlbumIdRequest request ); @Operation(summary = "사진 삭제", description = "사진을 삭제합니다.") @DeleteMapping("{photoId}") Mono deletePhoto( + @RequestMemberId + String memberId, + @Parameter(description = "사진 ID", example = "test_photo_id") @PathVariable String photoId diff --git a/photo-service/src/main/java/kr/mafoo/photo/controller/PhotoController.java b/photo-service/src/main/java/kr/mafoo/photo/controller/PhotoController.java index 735052b..85d1f53 100644 --- a/photo-service/src/main/java/kr/mafoo/photo/controller/PhotoController.java +++ b/photo-service/src/main/java/kr/mafoo/photo/controller/PhotoController.java @@ -2,28 +2,33 @@ import kr.mafoo.photo.api.PhotoApi; import kr.mafoo.photo.controller.dto.request.PhotoCreateRequest; -import kr.mafoo.photo.controller.dto.request.PhotoAlbumUpdateRequest; +import kr.mafoo.photo.controller.dto.request.PhotoUpdateAlbumIdRequest; import kr.mafoo.photo.controller.dto.response.PhotoResponse; +import kr.mafoo.photo.service.PhotoService; +import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.RestController; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; +@RequiredArgsConstructor @RestController public class PhotoController implements PhotoApi { + private final PhotoService photoService; + @Override - public Flux getAlbumPhotos( + public Flux getPhotos( + String memberId, String albumId ){ - return Flux.just( - new PhotoResponse("test_photo_id_a", "test_album_id_a", "photo_url"), - new PhotoResponse("test_photo_id_b", "test_album_id_a", "photo_url"), - new PhotoResponse("test_photo_id_c", "test_album_id_a", "photo_url") - ); + return photoService + .findAllByOwnerAlbumId(albumId, memberId) + .map(PhotoResponse::fromEntity); } @Override public Mono createPhoto( + String memberId, PhotoCreateRequest request ){ return Mono.just( @@ -33,18 +38,21 @@ public Mono createPhoto( @Override public Mono updatePhotoAlbum( + String memberId, String photoId, - PhotoAlbumUpdateRequest request + PhotoUpdateAlbumIdRequest request ){ - return Mono.just( - new PhotoResponse("test_photo_id", "photo_url", "test_album_id") - ); + return photoService + .updatePhotoOwnerAlbumId(photoId, request.albumId(), memberId) + .map(PhotoResponse::fromEntity); } @Override public Mono deletePhoto( + String memberId, String photoId ){ - return Mono.empty(); + return photoService + .deletePhotoById(photoId, memberId); } } diff --git a/photo-service/src/main/java/kr/mafoo/photo/controller/dto/request/PhotoAlbumUpdateRequest.java b/photo-service/src/main/java/kr/mafoo/photo/controller/dto/request/PhotoUpdateAlbumIdRequest.java similarity index 86% rename from photo-service/src/main/java/kr/mafoo/photo/controller/dto/request/PhotoAlbumUpdateRequest.java rename to photo-service/src/main/java/kr/mafoo/photo/controller/dto/request/PhotoUpdateAlbumIdRequest.java index c35cc71..b4bb1b6 100644 --- a/photo-service/src/main/java/kr/mafoo/photo/controller/dto/request/PhotoAlbumUpdateRequest.java +++ b/photo-service/src/main/java/kr/mafoo/photo/controller/dto/request/PhotoUpdateAlbumIdRequest.java @@ -3,7 +3,7 @@ import io.swagger.v3.oas.annotations.media.Schema; @Schema(description = "사진 앨범 수정 요청") -public record PhotoAlbumUpdateRequest( +public record PhotoUpdateAlbumIdRequest( @Schema(description = "앨범 ID", example = "test_album_id") String albumId ) { diff --git a/photo-service/src/main/java/kr/mafoo/photo/repository/PhotoRepository.java b/photo-service/src/main/java/kr/mafoo/photo/repository/PhotoRepository.java index aaeb94e..b104858 100644 --- a/photo-service/src/main/java/kr/mafoo/photo/repository/PhotoRepository.java +++ b/photo-service/src/main/java/kr/mafoo/photo/repository/PhotoRepository.java @@ -2,6 +2,8 @@ import kr.mafoo.photo.domain.PhotoEntity; import org.springframework.data.r2dbc.repository.R2dbcRepository; +import reactor.core.publisher.Flux; public interface PhotoRepository extends R2dbcRepository { + Flux findAllByOwnerAlbumId(String ownerAlbumId); } \ No newline at end of file diff --git a/photo-service/src/main/java/kr/mafoo/photo/service/PhotoService.java b/photo-service/src/main/java/kr/mafoo/photo/service/PhotoService.java new file mode 100644 index 0000000..636c0f3 --- /dev/null +++ b/photo-service/src/main/java/kr/mafoo/photo/service/PhotoService.java @@ -0,0 +1,71 @@ +package kr.mafoo.photo.service; + +import kr.mafoo.photo.domain.PhotoEntity; +import kr.mafoo.photo.exception.AlbumNotFoundException; +import kr.mafoo.photo.exception.PhotoNotFoundException; +import kr.mafoo.photo.repository.AlbumRepository; +import kr.mafoo.photo.repository.PhotoRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +@RequiredArgsConstructor +@Service +public class PhotoService { + private final PhotoRepository photoRepository; + private final AlbumRepository albumRepository; + + public Flux findAllByOwnerAlbumId(String ownerAlbumId, String requestMemberId) { + return albumRepository + .findById(ownerAlbumId) + .switchIfEmpty(Mono.error(new AlbumNotFoundException())) + .flatMapMany(albumEntity -> { + if(!albumEntity.getOwnerMemberId().equals(requestMemberId)) { + // 내 앨범이 아니면 그냥 없는 앨범 처리 + return Mono.error(new AlbumNotFoundException()); + } else { + return photoRepository.findAllByOwnerAlbumId(ownerAlbumId); + } + }); + } + + public Mono deletePhotoById(String photoId, String requestMemberId) { + return photoRepository + .findById(photoId) + .switchIfEmpty(Mono.error(new PhotoNotFoundException())) + .flatMap(photoEntity -> { + if(!photoEntity.getOwnerMemberId().equals(requestMemberId)) { + // 내 사진이 아니면 그냥 없는 사진 처리 + return Mono.error(new PhotoNotFoundException()); + } else { + return photoRepository.deleteById(photoId); + } + }); + } + + public Mono updatePhotoOwnerAlbumId(String photoId, String ownerAlbumId, String requestMemberId) { + return photoRepository + .findById(photoId) + .switchIfEmpty(Mono.error(new PhotoNotFoundException())) + .flatMap(photoEntity -> { + if(!photoEntity.getOwnerMemberId().equals(requestMemberId)) { + // 내 사진이 아니면 그냥 없는 사진 처리 + return Mono.error(new PhotoNotFoundException()); + } else { + return albumRepository + .findById(ownerAlbumId) + .switchIfEmpty(Mono.error(new AlbumNotFoundException())) + .flatMap(albumEntity -> { + if(!albumEntity.getOwnerMemberId().equals(requestMemberId)) { + // 내 앨범이 아니면 그냥 없는 앨범 처리 + return Mono.error(new AlbumNotFoundException()); + } else { + return photoRepository.save(photoEntity.updateOwnerAlbumId(ownerAlbumId)); + } + }); + } + }); + } + +} From b9496334d62f92924d667b06207727795c68acf1 Mon Sep 17 00:00:00 2001 From: Gyoungmin Kim Date: Wed, 3 Jul 2024 00:15:18 +0900 Subject: [PATCH 5/6] refactor: change photo table column owner_album_id to album_id (#11) --- .../kr/mafoo/photo/controller/PhotoController.java | 4 ++-- .../photo/controller/dto/response/PhotoResponse.java | 2 +- .../main/java/kr/mafoo/photo/domain/PhotoEntity.java | 8 ++++---- .../kr/mafoo/photo/repository/PhotoRepository.java | 2 +- .../java/kr/mafoo/photo/service/PhotoService.java | 12 ++++++------ 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/photo-service/src/main/java/kr/mafoo/photo/controller/PhotoController.java b/photo-service/src/main/java/kr/mafoo/photo/controller/PhotoController.java index 85d1f53..79dad1c 100644 --- a/photo-service/src/main/java/kr/mafoo/photo/controller/PhotoController.java +++ b/photo-service/src/main/java/kr/mafoo/photo/controller/PhotoController.java @@ -22,7 +22,7 @@ public Flux getPhotos( String albumId ){ return photoService - .findAllByOwnerAlbumId(albumId, memberId) + .findAllByAlbumId(albumId, memberId) .map(PhotoResponse::fromEntity); } @@ -43,7 +43,7 @@ public Mono updatePhotoAlbum( PhotoUpdateAlbumIdRequest request ){ return photoService - .updatePhotoOwnerAlbumId(photoId, request.albumId(), memberId) + .updatePhotoAlbumId(photoId, request.albumId(), memberId) .map(PhotoResponse::fromEntity); } diff --git a/photo-service/src/main/java/kr/mafoo/photo/controller/dto/response/PhotoResponse.java b/photo-service/src/main/java/kr/mafoo/photo/controller/dto/response/PhotoResponse.java index c284b9c..a70a1fa 100644 --- a/photo-service/src/main/java/kr/mafoo/photo/controller/dto/response/PhotoResponse.java +++ b/photo-service/src/main/java/kr/mafoo/photo/controller/dto/response/PhotoResponse.java @@ -20,7 +20,7 @@ public static PhotoResponse fromEntity( return new PhotoResponse( entity.getPhotoId(), entity.getPhotoUrl(), - entity.getOwnerAlbumId() + entity.getAlbumId() ); } } diff --git a/photo-service/src/main/java/kr/mafoo/photo/domain/PhotoEntity.java b/photo-service/src/main/java/kr/mafoo/photo/domain/PhotoEntity.java index 8ebe5af..c33fed8 100644 --- a/photo-service/src/main/java/kr/mafoo/photo/domain/PhotoEntity.java +++ b/photo-service/src/main/java/kr/mafoo/photo/domain/PhotoEntity.java @@ -26,8 +26,8 @@ public class PhotoEntity implements Persistable { @Column("owner_member_id") private String ownerMemberId; - @Column("owner_album_id") - private String ownerAlbumId; + @Column("album_id") + private String albumId; @CreatedDate @Column("created_at") @@ -59,8 +59,8 @@ public String getId() { return photoId; } - public PhotoEntity updateOwnerAlbumId(String albumId) { - this.ownerAlbumId = albumId; + public PhotoEntity updateAlbumId(String albumId) { + this.albumId = albumId; return this; } diff --git a/photo-service/src/main/java/kr/mafoo/photo/repository/PhotoRepository.java b/photo-service/src/main/java/kr/mafoo/photo/repository/PhotoRepository.java index b104858..1af61d4 100644 --- a/photo-service/src/main/java/kr/mafoo/photo/repository/PhotoRepository.java +++ b/photo-service/src/main/java/kr/mafoo/photo/repository/PhotoRepository.java @@ -5,5 +5,5 @@ import reactor.core.publisher.Flux; public interface PhotoRepository extends R2dbcRepository { - Flux findAllByOwnerAlbumId(String ownerAlbumId); + Flux findAllByAlbumId(String ownerAlbumId); } \ No newline at end of file diff --git a/photo-service/src/main/java/kr/mafoo/photo/service/PhotoService.java b/photo-service/src/main/java/kr/mafoo/photo/service/PhotoService.java index 636c0f3..b9d4939 100644 --- a/photo-service/src/main/java/kr/mafoo/photo/service/PhotoService.java +++ b/photo-service/src/main/java/kr/mafoo/photo/service/PhotoService.java @@ -16,16 +16,16 @@ public class PhotoService { private final PhotoRepository photoRepository; private final AlbumRepository albumRepository; - public Flux findAllByOwnerAlbumId(String ownerAlbumId, String requestMemberId) { + public Flux findAllByAlbumId(String albumId, String requestMemberId) { return albumRepository - .findById(ownerAlbumId) + .findById(albumId) .switchIfEmpty(Mono.error(new AlbumNotFoundException())) .flatMapMany(albumEntity -> { if(!albumEntity.getOwnerMemberId().equals(requestMemberId)) { // 내 앨범이 아니면 그냥 없는 앨범 처리 return Mono.error(new AlbumNotFoundException()); } else { - return photoRepository.findAllByOwnerAlbumId(ownerAlbumId); + return photoRepository.findAllByAlbumId(albumId); } }); } @@ -44,7 +44,7 @@ public Mono deletePhotoById(String photoId, String requestMemberId) { }); } - public Mono updatePhotoOwnerAlbumId(String photoId, String ownerAlbumId, String requestMemberId) { + public Mono updatePhotoAlbumId(String photoId, String albumId, String requestMemberId) { return photoRepository .findById(photoId) .switchIfEmpty(Mono.error(new PhotoNotFoundException())) @@ -54,14 +54,14 @@ public Mono updatePhotoOwnerAlbumId(String photoId, String ownerAlb return Mono.error(new PhotoNotFoundException()); } else { return albumRepository - .findById(ownerAlbumId) + .findById(albumId) .switchIfEmpty(Mono.error(new AlbumNotFoundException())) .flatMap(albumEntity -> { if(!albumEntity.getOwnerMemberId().equals(requestMemberId)) { // 내 앨범이 아니면 그냥 없는 앨범 처리 return Mono.error(new AlbumNotFoundException()); } else { - return photoRepository.save(photoEntity.updateOwnerAlbumId(ownerAlbumId)); + return photoRepository.save(photoEntity.updateAlbumId(albumId)); } }); } From cf7e5444215b1919df66882cfa5e673a622bab4c Mon Sep 17 00:00:00 2001 From: Gyoungmin Kim Date: Wed, 3 Jul 2024 00:16:27 +0900 Subject: [PATCH 6/6] refactor: create photo table index for album_id (#11) --- .../src/main/resources/db/migration/V2__createPhotoTable.sql | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/photo-service/src/main/resources/db/migration/V2__createPhotoTable.sql b/photo-service/src/main/resources/db/migration/V2__createPhotoTable.sql index ab53314..2681c0e 100644 --- a/photo-service/src/main/resources/db/migration/V2__createPhotoTable.sql +++ b/photo-service/src/main/resources/db/migration/V2__createPhotoTable.sql @@ -2,8 +2,9 @@ CREATE TABLE photo( `id` CHAR(26) PRIMARY KEY NOT NULL COMMENT '사진아이디', `url` VARCHAR(255) NOT NULL COMMENT '사진url', `owner_member_id` CHAR(26) NOT NULL COMMENT '사진소유자아이디', - `owner_album_id` CHAR(26) NULL COMMENT '사진소유앨범아이디', + `album_id` CHAR(26) NULL COMMENT '사진앨범아이디', `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - INDEX `photo_idx1` (`owner_member_id`) + INDEX `photo_idx1` (`owner_member_id`), + INDEX `photo_idx2` (`album_id`) );