-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
142 additions
and
15 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
src/main/java/com/nice/petudio/api/controller/member/dto/CreateMemberRequest.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,31 @@ | ||
package com.nice.petudio.api.controller.member.dto; | ||
|
||
import com.nice.petudio.domain.member.SocialType; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.ToString; | ||
|
||
@ToString | ||
@Getter | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
@Builder(access = AccessLevel.PRIVATE) | ||
public class CreateMemberRequest { | ||
|
||
private String socialId; | ||
private SocialType socialType; | ||
private String nickname; | ||
private String profileImageUrl; | ||
|
||
public static CreateMemberRequest of(String socialId, SocialType socialType, String nickname, String profileImageUrl) { | ||
return CreateMemberRequest.builder() | ||
.socialId(socialId) | ||
.socialType(socialType) | ||
.nickname(nickname) | ||
.profileImageUrl(profileImageUrl) | ||
.build(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/nice/petudio/api/controller/member/service/MemberService.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,20 @@ | ||
package com.nice.petudio.api.controller.member.service; | ||
|
||
import com.nice.petudio.api.controller.member.dto.CreateMemberRequest; | ||
import com.nice.petudio.domain.member.Member; | ||
import com.nice.petudio.domain.member.repository.MemberRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class MemberService { | ||
private final MemberRepository memberRepository; | ||
|
||
public Long registerMember(CreateMemberRequest request) { | ||
MemberServiceUtils.validateNotExistsMember(memberRepository, request.getSocialId(), request.getSocialType()); | ||
Member member = memberRepository.save( | ||
Member.newInstance(request.getSocialId(), request.getSocialType())); | ||
return member.getId(); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/nice/petudio/api/controller/member/service/MemberServiceUtils.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 com.nice.petudio.api.controller.member.service; | ||
|
||
import com.nice.petudio.domain.member.Member; | ||
import com.nice.petudio.domain.member.SocialType; | ||
import com.nice.petudio.domain.member.repository.MemberRepository; | ||
import com.nice.petudio.global.exception.ConflictException; | ||
import com.nice.petudio.global.exception.NotFoundException; | ||
import com.nice.petudio.global.exception.error.ErrorCode; | ||
import java.util.Optional; | ||
|
||
public class MemberServiceUtils { | ||
|
||
public static Member findMemberById(MemberRepository memberRepository, Long memberId) { | ||
return memberRepository.findById(memberId) | ||
.orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_MEMBER_EXCEPTION, | ||
String.format("존재하지 않는 memberId(%d) 입니다.", memberId))); | ||
} | ||
|
||
static void validateNotExistsMember(MemberRepository memberRepository, String socialId, | ||
SocialType socialType) { | ||
if (memberRepository.existsBySocialIdAndSocialType(socialId, socialType)) { | ||
throw new ConflictException(ErrorCode.CONFLICT_MEMBER_EXCEPTION, String.format("이미 존재하는 회원 소셜정보 (%s - %s) 입니다", socialId, socialType)); | ||
} | ||
} | ||
|
||
public static Member findMemberBySocialIdAndSocialType(MemberRepository memberRepository, String socialId, | ||
SocialType socialType) { | ||
Optional<Member> member = memberRepository.findMemberBySocialIdAndSocialType(socialId, socialType); | ||
return member.orElseThrow(() -> new NotFoundException( | ||
ErrorCode.NOT_FOUND_MEMBER_EXCEPTION, | ||
String.format("존재하지 않는 회원 소셜정보 (%s - %s) 입니다", socialType, socialId))); | ||
} | ||
} |
15 changes: 0 additions & 15 deletions
15
src/main/java/com/nice/petudio/api/member/service/MemberServiceUtils.java
This file was deleted.
Oops, something went wrong.
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
9 changes: 9 additions & 0 deletions
9
src/main/java/com/nice/petudio/domain/member/repository/MemberRepositoryCustom.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,4 +1,13 @@ | ||
package com.nice.petudio.domain.member.repository; | ||
|
||
import com.nice.petudio.domain.member.Member; | ||
import com.nice.petudio.domain.member.SocialType; | ||
import java.util.Optional; | ||
|
||
public interface MemberRepositoryCustom { | ||
boolean existsBySocialIdAndSocialType(String socialId, SocialType socialType); | ||
|
||
Optional<Member> findMemberById(Long id); | ||
|
||
Optional<Member> findMemberBySocialIdAndSocialType(String socialId, SocialType socialType); | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/com/nice/petudio/domain/member/repository/MemberRepositoryImpl.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,4 +1,44 @@ | ||
package com.nice.petudio.domain.member.repository; | ||
|
||
import static com.nice.petudio.domain.member.QMember.member; | ||
|
||
import com.nice.petudio.domain.member.Member; | ||
import com.nice.petudio.domain.member.SocialType; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import java.util.Optional; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public class MemberRepositoryImpl implements MemberRepositoryCustom { | ||
private final JPAQueryFactory queryFactory; | ||
|
||
@Override | ||
public boolean existsBySocialIdAndSocialType(String socialId, SocialType socialType) { | ||
return Optional.ofNullable(queryFactory.selectOne() | ||
.from(member) | ||
.where( | ||
member.socialInfo.socialId.eq(socialId), | ||
member.socialInfo.socialType.eq(socialType) | ||
) | ||
.fetchFirst()).isPresent(); | ||
} | ||
|
||
@Override | ||
public Optional<Member> findMemberById(Long id) { | ||
return Optional.ofNullable(queryFactory | ||
.selectFrom(member) | ||
.where(member.id.eq(id)) | ||
.fetchOne()); | ||
} | ||
|
||
@Override | ||
public Optional<Member> findMemberBySocialIdAndSocialType(String socialId, SocialType socialType) { | ||
return Optional.ofNullable(queryFactory | ||
.selectFrom(member) | ||
.where( | ||
member.socialInfo.socialId.eq(socialId), | ||
member.socialInfo.socialType.eq(socialType) | ||
) | ||
.fetchOne()); | ||
} | ||
} |