-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from YAPP-Github/feature/MAFOO-101
[MAFOO-101] feat: 사진 순서 관련 API 기능 추가
- Loading branch information
Showing
10 changed files
with
166 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...e/src/main/java/kr/mafoo/photo/controller/dto/request/PhotoUpdateDisplayIndexRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package kr.mafoo.photo.controller.dto.request; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.NotNull; | ||
|
||
@Schema(description = "사진 인덱스 수정 요청") | ||
public record PhotoUpdateDisplayIndexRequest( | ||
@NotNull | ||
@Schema(description = "사진 표시 인덱스", example = "photo_display_index") | ||
Integer newDisplayIndex | ||
) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
photo-service/src/main/java/kr/mafoo/photo/exception/PhotoDisplayIndexIsSameException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package kr.mafoo.photo.exception; | ||
|
||
public class PhotoDisplayIndexIsSameException extends DomainException { | ||
public PhotoDisplayIndexIsSameException() { | ||
super(ErrorCode.PHOTO_DISPLAY_INDEX_IS_SAME); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
photo-service/src/main/java/kr/mafoo/photo/exception/PhotoDisplayIndexNotValidException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package kr.mafoo.photo.exception; | ||
|
||
public class PhotoDisplayIndexNotValidException extends DomainException { | ||
public PhotoDisplayIndexNotValidException() { | ||
super(ErrorCode.PHOTO_DISPLAY_INDEX_NOT_VALID); | ||
} | ||
} |
17 changes: 16 additions & 1 deletion
17
photo-service/src/main/java/kr/mafoo/photo/repository/PhotoRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,24 @@ | ||
package kr.mafoo.photo.repository; | ||
|
||
import kr.mafoo.photo.domain.PhotoEntity; | ||
import org.springframework.data.r2dbc.repository.Modifying; | ||
import org.springframework.data.r2dbc.repository.Query; | ||
import org.springframework.data.r2dbc.repository.R2dbcRepository; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
public interface PhotoRepository extends R2dbcRepository<PhotoEntity, String> { | ||
Flux<PhotoEntity> findAllByAlbumId(String ownerAlbumId); | ||
Flux<PhotoEntity> findAllByAlbumIdOrderByDisplayIndexDesc(String ownerAlbumId); | ||
|
||
@Modifying | ||
@Query("UPDATE photo SET display_index = display_index - 1 WHERE album_id = :albumId AND display_index > :startIndex") | ||
Mono<Void> popDisplayIndexGreaterThan(String albumId, int startIndex); | ||
|
||
@Modifying | ||
@Query("UPDATE photo SET display_index = display_index - 1 WHERE album_id = :albumId AND display_index BETWEEN :startIndex AND :endIndex") | ||
Mono<Void> popDisplayIndexBetween(String albumId, int startIndex, int endIndex); | ||
|
||
@Modifying | ||
@Query("UPDATE photo SET display_index = display_index + 1 WHERE album_id = :albumId AND display_index BETWEEN :startIndex AND :endIndex") | ||
Mono<Void> pushDisplayIndexBetween(String albumId, int startIndex, int endIndex); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
photo-service/src/main/resources/db/migration/V7__addDisplayIndexColumnInPhotoTable.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
ALTER TABLE `photo` | ||
ADD `display_index` INTEGER COMMENT '표시순' AFTER `album_id`; | ||
|
||
CREATE INDEX `idx_photo_display_index` ON `photo`(`display_index`); | ||
|
||
WITH RankedPhotos AS ( | ||
SELECT | ||
id, | ||
owner_member_id, | ||
album_id, | ||
CASE | ||
WHEN album_id IS NOT NULL THEN ROW_NUMBER() OVER (PARTITION BY owner_member_id, album_id ORDER BY created_at) - 1 | ||
ELSE NULL | ||
END AS new_index | ||
FROM photo | ||
) | ||
UPDATE photo | ||
JOIN RankedPhotos | ||
ON photo.id = RankedPhotos.id | ||
SET photo.display_index = RankedPhotos.new_index; |