Skip to content

Commit

Permalink
feat: implement getMemberByKeywordForSharedAlbum in member service
Browse files Browse the repository at this point in the history
  • Loading branch information
gmkim20713 committed Nov 22, 2024
1 parent 75f7498 commit 412eae1
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package kr.mafoo.user.controller.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import kr.mafoo.user.service.dto.MemberDetailDto;

@Schema(description = "사용자의 정보 응답")
public record MemberDetailResponse(
@Schema(description = "사용자 ID", example = "test")
String memberId,

@Schema(description = "사용자 이름", example = "송영민")
String name,

@Schema(description = "프로필 이미지 URL", example = "https://mafoo.kr/profile.jpg")
String profileImageUrl,

@Schema(description = "식별 번호", example = "0000")
String serialNumber,

@Schema(description = "공유 사용자 ID", example = "test_shared_member_id")
String sharedMemberId,

@Schema(description = "공유 상태", example = "PENDING")
String shareStatus,

@Schema(description = "권한 단계", example = "FULL_ACCESS")
String permissionLevel
) {
public static MemberDetailResponse fromDto(
MemberDetailDto dto
) {
return new MemberDetailResponse(
dto.memberId(),
dto.name(),
dto.profileImageUrl(),
dto.serialNumber(),
dto.sharedMemberId(),
dto.shareStatus(),
dto.permissionLevel()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import kr.mafoo.user.exception.MemberNotFoundException;
import kr.mafoo.user.repository.MemberRepository;
import kr.mafoo.user.repository.SocialMemberRepository;
import kr.mafoo.user.service.dto.MemberDetailDto;
import kr.mafoo.user.util.IdGenerator;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -19,6 +20,7 @@ public class MemberService {
private final MemberRepository memberRepository;
private final SocialMemberRepository socialMemberRepository;
private final SlackService slackService;
private final SharedMemberService sharedMemberService;

@Transactional
public Mono<Void> quitMemberByMemberId(String memberId) {
Expand All @@ -27,10 +29,13 @@ public Mono<Void> quitMemberByMemberId(String memberId) {
.then(memberRepository.deleteMemberById(memberId));
}

public Flux<MemberEntity> getMemberByKeyword(String keyword) {
public Flux<MemberDetailDto> getMemberByKeywordForSharedAlbum(String keyword, String albumId, String token) {
return memberRepository
.findAllByNameContaining(keyword)
.switchIfEmpty(Mono.error(new MemberNotFoundException()));
.switchIfEmpty(Mono.error(new MemberNotFoundException()))
.concatMap(member -> sharedMemberService.getSharedMemberInfoByAlbumId(albumId, member.getId(), token)
.flatMap(sharedMemberDto -> Mono.just(MemberDetailDto.fromSharedMember(member, sharedMemberDto)))
);
}

public Mono<MemberEntity> getMemberByMemberId(String memberId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package kr.mafoo.user.service.dto;

import kr.mafoo.user.domain.MemberEntity;

public record MemberDetailDto(
String memberId,
String name,
String profileImageUrl,
String serialNumber,
String sharedMemberId,
String shareStatus,
String permissionLevel
) {
public static MemberDetailDto fromSharedMember(
MemberEntity memberEntity,
SharedMemberDto sharedMemberDto
) {
return new MemberDetailDto(
memberEntity.getId(),
memberEntity.getName(),
memberEntity.getProfileImageUrl(),
String.format("%04d", memberEntity.getSerialNumber()),
sharedMemberDto.sharedMemberId(),
sharedMemberDto.shareStatus(),
sharedMemberDto.permissionLevel()
);
}
}

0 comments on commit 412eae1

Please sign in to comment.