Skip to content

Commit

Permalink
Merge pull request #51 from Na-o-man/feature/#47/get-inviteCode-api
Browse files Browse the repository at this point in the history
[FEAT] 내 공유 그룹 초대 코드 조회 API 구현
  • Loading branch information
h-ye-ryoung authored Aug 2, 2024
2 parents 44d7d6d + 7197037 commit 8f7f0a0
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ public ResultResponse<ShareGroupResponse.PagedShareGroupInfo> getMyShareGroupLis
shareGroupConverter.toPagedShareGroupInfo(shareGroupList));
}

@GetMapping("/{shareGroupId}/invite")
@Operation(summary = "공유그룹 초대 코드 조회 API", description = "공유그룹의 초대 코드를 조회하는 API입니다.")
@Parameters(value = {
@Parameter(name = "shareGroupId", description = "조회할 공유그룹 id를 입력해 주세요.")
})
public ResultResponse<ShareGroupResponse.InviteInfo> getInviteCode(@PathVariable Long shareGroupId,
@LoginMember Member member) {
ShareGroup shareGroup = shareGroupService.getInviteInfo(shareGroupId, member);
return ResultResponse.of(ShareGroupResultCode.GET_INVITE_CODE,
shareGroupConverter.toInviteInfo(shareGroup));
}

@PostMapping("/join")
@Operation(summary = "공유그룹 참여 API", description = "특정 공유그룹에 참여하는 API입니다.")
public ResultResponse<ShareGroupResponse.ShareGroupId> joinShareGroup(@Valid @RequestBody ShareGroupRequest.JoinShareGroupRequest request,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

@Component
public class ShareGroupConverter {
private static final String BASE_URL = "https://na0man/invite/"; //baseUrl 상수
private static final String BASE_URL = "https://naoman/invite/"; //baseUrl 상수

public ShareGroup toEntity(ShareGroupRequest.createShareGroupRequest request) {
return ShareGroup.builder()
Expand Down Expand Up @@ -42,6 +42,15 @@ public ShareGroupResponse.ShareGroupId toShareGroupId(ShareGroup shareGroup) {
.build();
}

// 내 공유 그룹의 inviteCode를 반환하는 DTO
public ShareGroupResponse.InviteInfo toInviteInfo(ShareGroup shareGroup) {
return ShareGroupResponse.InviteInfo.builder()
.shareGroupId(shareGroup.getId())
.inviteCode(shareGroup.getInviteCode())
.inviteUrl(BASE_URL + shareGroup.getInviteCode())
.build();
}

// 조회 시, 디테일한 그룹 정보를 반환하는 DTO
public ShareGroupDetailInfo toShareGroupDetailInfo(ShareGroup shareGroup, List<Profile> profiles) {
List<ShareGroupResponse.ProfileInfo> profileInfoList = profiles.stream()
Expand Down Expand Up @@ -85,6 +94,4 @@ public PagedShareGroupInfo toPagedShareGroupInfo(Page<ShareGroup> shareGroupList
.isLast(shareGroupList.isLast())
.build();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,4 @@ public static class JoinShareGroupRequest {
@NotNull(message = "프로필 ID를 입력해야 합니다.")
private Long profileId;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,13 @@ public static class ProfileInfo {
private Long memberId;
}


@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class InviteInfo {
private Long shareGroupId;
private String inviteCode;
private String inviteUrl;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ public interface ProfileRepository extends JpaRepository<Profile, Long> {
List<Profile> findByShareGroupId(Long shareGroupId);
Optional<Profile> findByShareGroupIdAndMemberId(Long shareGroupId, Long memberId);
List<Profile> findByMemberId(Long memberId);
boolean existsByShareGroupIdAndMemberId(Long shareGroupId, Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ public interface ShareGroupService {
Profile findProfile(Long shareGroupId, Long memberID);
Page<ShareGroup> getMyShareGroupList(Member member, Pageable pageable);
ShareGroup deleteShareGroup(Long shareGroupId, Member member);
ShareGroup getInviteInfo(Long shareGroupId, Member member);
boolean doesProfileExist(Long shareGroupId, Long memberId);
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package com.umc.naoman.domain.shareGroup.service;

import com.umc.naoman.domain.member.entity.Member;
import com.umc.naoman.domain.member.repository.MemberRepository;
import com.umc.naoman.domain.shareGroup.converter.ShareGroupConverter;
import com.umc.naoman.domain.shareGroup.dto.ShareGroupRequest;
import com.umc.naoman.domain.shareGroup.dto.ShareGroupResponse;
import com.umc.naoman.domain.shareGroup.dto.ShareGroupResponse.PagedShareGroupInfo;
import com.umc.naoman.domain.shareGroup.entity.Profile;
import com.umc.naoman.domain.shareGroup.entity.Role;
import com.umc.naoman.domain.shareGroup.entity.ShareGroup;
Expand All @@ -31,7 +28,6 @@ public class ShareGroupServiceImpl implements ShareGroupService {

private final ShareGroupRepository shareGroupRepository;
private final ProfileRepository profileRepository;
private final MemberRepository memberRepository;
private final ShareGroupConverter shareGroupConverter;

@Transactional
Expand Down Expand Up @@ -69,10 +65,13 @@ public ShareGroup createShareGroup(ShareGroupRequest.createShareGroupRequest req
@Transactional
@Override
public ShareGroup joinShareGroup(Long shareGroupId, Long profileId, Member member) {

ShareGroup shareGroup = findShareGroup(shareGroupId);

//repo에서 Profile 객체 꺼내오기
if (doesProfileExist(shareGroupId, member.getId())) {
throw new BusinessException(ShareGroupErrorCode.ALREADY_JOINED);
}

// --- repo에서 Profile 객체 꺼내오기 ---
Profile profile = findProfile(profileId);

//공유그룹에 해당 profile이 존재하지 않으면
Expand All @@ -99,6 +98,16 @@ public Page<ShareGroup> getMyShareGroupList(Member member, Pageable pageable) {
return shareGroupRepository.findByIdIn(shareGroupIdList, pageable);
}

@Override
public ShareGroup getInviteInfo(Long shareGroupId, Member member) {
ShareGroup shareGroup = findShareGroup(shareGroupId); //해당 공유그룹 엔티티

// 사용자가 해당 공유그룹에 속하는지 검증해야 함
findProfile(shareGroupId, member.getId());

return shareGroup;
}

@Transactional
@Override
public ShareGroup deleteShareGroup(Long shareGroupId, Member member) {
Expand Down Expand Up @@ -145,4 +154,9 @@ public Profile findProfile(Long shareGroupId, Long memberId) {
.orElseThrow(() -> new BusinessException(ShareGroupErrorCode.PROFILE_NOT_FOUND));
}

@Override
public boolean doesProfileExist(Long shareGroupId, Long memberId) {
return profileRepository.existsByShareGroupIdAndMemberId(shareGroupId, memberId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public enum ShareGroupErrorCode implements ErrorCode {
INVALID_PROFILE_FOR_GROUP(400, "EG007", "해당 프로필은 이 공유 그룹에 속하지 않습니다."),

UNAUTHORIZED_DELETE(403, "EG008", "공유 그룹을 삭제할 권한이 없습니다."),
ALREADY_JOINED(400, "EG009", "이미 해당 공유 그룹에 참여하였습니다.");
;

private final int status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public enum ShareGroupResultCode implements ResultCode {
SHARE_GROUP_INFO(200, "SG002", "공유 그룹을 성공적으로 조회했습니다."),
JOIN_SHARE_GROUP(200, "SG003", "성공적으로 공유 그룹에 참여했습니다." ),
SHARE_GROUP_INFO_LIST(200, "SG004", "내가 참여한 공유 그룹 목록을 성공적으로 조회하였습니다."),
DELETE_SHARE_GROUP(200, "SG005", "성공적으로 공유 그룹을 삭제했습니다.")
DELETE_SHARE_GROUP(200, "SG005", "성공적으로 공유 그룹을 삭제했습니다."),
GET_INVITE_CODE(200, "SG006", "성공적으로 초대 코드를 조회하였습니다.")
;
private final int status;
private final String code;
Expand Down

0 comments on commit 8f7f0a0

Please sign in to comment.