-
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 #59 from YAPP-Github/feature/MAFOO-93
[MAFOO-93] feat: 앨범 순서 관련 API 및 기능 추가
- Loading branch information
Showing
9 changed files
with
115 additions
and
4 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
14 changes: 14 additions & 0 deletions
14
...e/src/main/java/kr/mafoo/photo/controller/dto/request/AlbumUpdateDisplayIndexRequest.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,14 @@ | ||
package kr.mafoo.photo.controller.dto.request; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.Min; | ||
import jakarta.validation.constraints.NotNull; | ||
|
||
@Schema(description = "앨범 수정 요청") | ||
public record AlbumUpdateDisplayIndexRequest( | ||
@NotNull | ||
@Min(0) | ||
@Schema(description = "대상 인덱스", example = "1") | ||
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
7 changes: 7 additions & 0 deletions
7
photo-service/src/main/java/kr/mafoo/photo/exception/AlbumIndexIsSameException.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 AlbumIndexIsSameException extends DomainException { | ||
public AlbumIndexIsSameException() { | ||
super(ErrorCode.ALBUM_DISPLAY_INDEX_IS_SAME); | ||
} | ||
} |
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
19 changes: 18 additions & 1 deletion
19
photo-service/src/main/java/kr/mafoo/photo/repository/AlbumRepository.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,26 @@ | ||
package kr.mafoo.photo.repository; | ||
|
||
import kr.mafoo.photo.domain.AlbumEntity; | ||
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 AlbumRepository extends R2dbcRepository<AlbumEntity, String> { | ||
Flux<AlbumEntity> findAllByOwnerMemberId(String ownerMemberId); | ||
Flux<AlbumEntity> findAllByOwnerMemberIdOrderByDisplayIndex(String ownerMemberId); | ||
|
||
@Modifying | ||
@Query("UPDATE album SET display_index = display_index + 1 WHERE owner_member_id = :ownerMemberId") | ||
Mono<Void> pushDisplayIndex(String ownerMemberId); | ||
|
||
@Modifying | ||
@Query("UPDATE album SET display_index = display_index + 1 WHERE owner_member_id = :ownerMemberId " + | ||
"AND display_index BETWEEN :startIndex AND :lastIndex") | ||
Mono<Void> pushDisplayIndexBetween(String ownerMemberId, Integer startIndex, Integer lastIndex); | ||
|
||
@Modifying | ||
@Query("UPDATE album SET display_index = display_index -1 WHERE owner_member_id = :ownerMemberId " + | ||
"AND display_index BETWEEN :startIndex AND :lastIndex") | ||
Mono<Void> popDisplayIndexBetween(String ownerMemberId, Integer startIndex, Integer lastIndex); | ||
} |
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
15 changes: 15 additions & 0 deletions
15
photo-service/src/main/resources/db/migration/V6__addDisplayIndexColumnInAlbumTable.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,15 @@ | ||
ALTER TABLE `album` | ||
ADD `display_index` INTEGER NOT NULL DEFAULT 0 COMMENT '표시순' after `owner_member_id`; | ||
CREATE INDEX `idx_album_display_index` ON `album`(`display_index`); | ||
|
||
WITH RankedAlbums AS ( | ||
SELECT | ||
id, | ||
owner_member_id, | ||
ROW_NUMBER() OVER (PARTITION BY owner_member_id ORDER BY created_at DESC) - 1 AS new_index | ||
FROM album | ||
) | ||
UPDATE album | ||
JOIN RankedAlbums | ||
ON album.id = RankedAlbums.id | ||
SET album.display_index = RankedAlbums.new_index; |