-
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 #77 from YAPP-Github/feature/MAFOO-180
[MAFOO-180] feat: 공유 앨범 상세 조회 API를 구현했어요
- Loading branch information
Showing
14 changed files
with
267 additions
and
48 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
photo-service/src/main/java/kr/mafoo/photo/api/SharedAlbumApi.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,35 @@ | ||
package kr.mafoo.photo.api; | ||
|
||
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.annotation.ULID; | ||
import kr.mafoo.photo.controller.dto.response.SharedAlbumResponse; | ||
import org.springframework.http.server.reactive.ServerHttpRequest; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import reactor.core.publisher.Mono; | ||
|
||
@Validated | ||
@Tag(name = "공유 앨범 관련 API", description = "공유 앨범 상세 조회 API") | ||
@RequestMapping("/v1/shared-albums") | ||
public interface SharedAlbumApi { | ||
@Operation(summary = "공유 앨범 상세 조회", description = "공유 앨범의 상세 정보를 조회합니다.") | ||
@GetMapping("/{albumId}") | ||
Mono<SharedAlbumResponse> getSharedAlbumOwnerAndMemberList( | ||
@RequestMemberId | ||
String memberId, | ||
|
||
@ULID | ||
@Parameter(description = "앨범 ID", example = "test_album_id") | ||
@PathVariable | ||
String albumId, | ||
|
||
// Authorization Header를 받아올 목적 | ||
ServerHttpRequest serverHttpRequest | ||
); | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
photo-service/src/main/java/kr/mafoo/photo/controller/SharedAlbumController.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,29 @@ | ||
package kr.mafoo.photo.controller; | ||
|
||
import kr.mafoo.photo.api.SharedAlbumApi; | ||
import kr.mafoo.photo.controller.dto.response.SharedAlbumResponse; | ||
import kr.mafoo.photo.service.SharedAlbumService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.server.reactive.ServerHttpRequest; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import reactor.core.publisher.Mono; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
public class SharedAlbumController implements SharedAlbumApi { | ||
|
||
private final SharedAlbumService sharedAlbumService; | ||
|
||
@Override | ||
public Mono<SharedAlbumResponse> getSharedAlbumOwnerAndMemberList( | ||
String memberId, | ||
String albumId, | ||
ServerHttpRequest serverHttpRequest | ||
) { | ||
String authorizationToken = serverHttpRequest.getHeaders().getFirst("Authorization"); | ||
|
||
return sharedAlbumService.findSharedAlbumOwnerAndMemberList(albumId, memberId, authorizationToken) | ||
.flatMap(SharedAlbumResponse::fromDto); | ||
} | ||
|
||
} |
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
52 changes: 52 additions & 0 deletions
52
photo-service/src/main/java/kr/mafoo/photo/controller/dto/response/SharedAlbumResponse.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,52 @@ | ||
package kr.mafoo.photo.controller.dto.response; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import java.util.List; | ||
import kr.mafoo.photo.domain.enums.AlbumType; | ||
import kr.mafoo.photo.service.dto.SharedAlbumDto; | ||
import reactor.core.publisher.Mono; | ||
|
||
@Schema(description = "공유 앨범 응답") | ||
public record SharedAlbumResponse( | ||
@Schema(description = "앨범 ID", example = "test_album_id") | ||
String albumId, | ||
|
||
@Schema(description = "앨범 이름", example = "야뿌들") | ||
String name, | ||
|
||
@Schema(description = "앨범 종류", example = "HEART") | ||
AlbumType type, | ||
|
||
@Schema(description = "공유 앨범 소유자 ID", example = "test_member_id") | ||
String ownerMemberId, | ||
|
||
@Schema(description = "공유 앨범 소유자 이름", example = "시금치파슷하") | ||
String ownerName, | ||
|
||
@Schema(description = "공유 앨범 소유자 프로필 이미지 URL", example = "https://mafoo.kr/profile.jpg") | ||
String ownerProfileImageUrl, | ||
|
||
@Schema(description = "공유 앨범 소유자 식별 번호", example = "0000") | ||
String ownerSerialNumber, | ||
|
||
@Schema(description = "공유 앨범 사용자 정보 목록") | ||
List<SharedMemberDetailResponse> sharedMembers | ||
) { | ||
public static Mono<SharedAlbumResponse> fromDto( | ||
SharedAlbumDto dto | ||
) { | ||
return dto.sharedMemberDtoFlux() | ||
.map(SharedMemberDetailResponse::fromDto) | ||
.collectList() | ||
.map(sharedMemberList -> new SharedAlbumResponse( | ||
dto.albumId(), | ||
dto.name(), | ||
dto.type(), | ||
dto.ownerMemberId(), | ||
dto.ownerName(), | ||
dto.ownerProfileImageUrl(), | ||
dto.ownerSerialNumber(), | ||
sharedMemberList | ||
)); | ||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
photo-service/src/main/java/kr/mafoo/photo/domain/enums/ShareStatus.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,8 +1,8 @@ | ||
package kr.mafoo.photo.domain.enums; | ||
|
||
public enum ShareStatus { | ||
PENDING, | ||
ACCEPTED, | ||
PENDING, | ||
REJECTED | ||
} | ||
|
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
42 changes: 42 additions & 0 deletions
42
photo-service/src/main/java/kr/mafoo/photo/service/SharedAlbumService.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,42 @@ | ||
package kr.mafoo.photo.service; | ||
|
||
import static kr.mafoo.photo.domain.enums.PermissionLevel.VIEW_ACCESS; | ||
|
||
import java.util.Comparator; | ||
import kr.mafoo.photo.service.dto.SharedAlbumDto; | ||
import kr.mafoo.photo.service.dto.SharedMemberDto; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class SharedAlbumService { | ||
|
||
private final SharedMemberQuery sharedMemberQuery; | ||
|
||
private final AlbumPermissionVerifier albumPermissionVerifier; | ||
private final MemberService memberService; | ||
|
||
@Transactional(readOnly = true) | ||
public Mono<SharedAlbumDto> findSharedAlbumOwnerAndMemberList(String albumId, String requestMemberId, String token) { | ||
return albumPermissionVerifier.verifyOwnershipOrAccessPermission(albumId, requestMemberId, VIEW_ACCESS) | ||
.flatMap(album -> memberService.getMemberInfoById(album.getOwnerMemberId(), token) | ||
.flatMap(ownerMember -> Mono.just(SharedAlbumDto.fromSharedAlbum( | ||
album, | ||
ownerMember, | ||
findSharedAlbumMemberDetail(albumId, token) | ||
))) | ||
); | ||
} | ||
|
||
private Flux<SharedMemberDto> findSharedAlbumMemberDetail(String albumId, String token) { | ||
return sharedMemberQuery.findAllByAlbumIdWhereStatusNotRejected(albumId) | ||
.concatMap(sharedMember -> memberService.getMemberInfoById(sharedMember.getMemberId(), token) | ||
.flatMap(memberInfo -> Mono.just(SharedMemberDto.fromSharedMember(sharedMember, memberInfo))) | ||
).sort(Comparator.comparing(SharedMemberDto::shareStatus)); | ||
} | ||
} | ||
|
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
33 changes: 33 additions & 0 deletions
33
photo-service/src/main/java/kr/mafoo/photo/service/dto/SharedAlbumDto.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,33 @@ | ||
package kr.mafoo.photo.service.dto; | ||
|
||
import kr.mafoo.photo.domain.AlbumEntity; | ||
import kr.mafoo.photo.domain.enums.AlbumType; | ||
import reactor.core.publisher.Flux; | ||
|
||
public record SharedAlbumDto( | ||
String albumId, | ||
String name, | ||
AlbumType type, | ||
String ownerMemberId, | ||
String ownerName, | ||
String ownerProfileImageUrl, | ||
String ownerSerialNumber, | ||
Flux<SharedMemberDto> sharedMemberDtoFlux | ||
) { | ||
public static SharedAlbumDto fromSharedAlbum( | ||
AlbumEntity albumEntity, | ||
MemberDto ownerMemberDto, | ||
Flux<SharedMemberDto> sharedMemberDtoFlux | ||
) { | ||
return new SharedAlbumDto( | ||
albumEntity.getAlbumId(), | ||
albumEntity.getName(), | ||
albumEntity.getType(), | ||
ownerMemberDto.memberId(), | ||
ownerMemberDto.name(), | ||
ownerMemberDto.profileImageUrl(), | ||
ownerMemberDto.serialNumber(), | ||
sharedMemberDtoFlux | ||
); | ||
} | ||
} |
30 changes: 0 additions & 30 deletions
30
photo-service/src/main/java/kr/mafoo/photo/service/dto/SharedMemberDetailDto.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.