Skip to content

Commit

Permalink
Merge branch 'develop' into feat/25
Browse files Browse the repository at this point in the history
  • Loading branch information
devholic22 authored May 18, 2024
2 parents d34bebd + c4c007f commit 4dcad34
Show file tree
Hide file tree
Showing 48 changed files with 1,009 additions and 206 deletions.
2 changes: 1 addition & 1 deletion src/docs/asciidoc/auth.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
:sectlinks:
:sectnums:

== Member
== Auth

=== 로그인

Expand Down
21 changes: 14 additions & 7 deletions src/docs/asciidoc/member.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
:sectlinks:
:sectnums:

== Info
== Member

=== 닉네임 중복 확인 (GET /api/members/nickname/existence)

Expand All @@ -18,35 +18,42 @@ include::{snippets}/member-controller-web-mvc-test/닉네임_중복_확인/http-
include::{snippets}/member-controller-web-mvc-test/닉네임_중복_확인/http-response.adoc[]


=== 회원 정보 초기화 (POST /api/members/{memberId})
=== 회원 정보 초기화 (POST /api/members)

==== 요청
include::{snippets}/member-controller-web-mvc-test/회원_정보_초기화/request-headers.adoc[]
include::{snippets}/member-controller-web-mvc-test/회원_정보_초기화/path-parameters.adoc[]
include::{snippets}/member-controller-web-mvc-test/회원_정보_초기화/request-fields.adoc[]
include::{snippets}/member-controller-web-mvc-test/회원_정보_초기화/http-request.adoc[]

==== 응답
include::{snippets}/member-controller-web-mvc-test/회원_정보_초기화/http-response.adoc[]


=== 회원 정보 수정 (PATCH /api/members/{memberId})
=== 회원 정보 조회(GET /api/members)
==== 요청
include::{snippets}/member-controller-web-mvc-test/회원_정보_조회/request-headers.adoc[]
include::{snippets}/member-controller-web-mvc-test/회원_정보_조회/http-request.adoc[]

==== 응답
include::{snippets}/member-controller-web-mvc-test/회원_정보_조회/response-body.adoc[]
include::{snippets}/member-controller-web-mvc-test/회원_정보_조회/http-response.adoc[]


=== 회원 정보 수정 (PATCH /api/members)

==== 요청
include::{snippets}/member-controller-web-mvc-test/회원_정보_수정/request-headers.adoc[]
include::{snippets}/member-controller-web-mvc-test/회원_정보_수정/path-parameters.adoc[]
include::{snippets}/member-controller-web-mvc-test/회원_정보_수정/request-fields.adoc[]
include::{snippets}/member-controller-web-mvc-test/회원_정보_수정/http-request.adoc[]

==== 응답
include::{snippets}/member-controller-web-mvc-test/회원_정보_수정/http-response.adoc[]


=== 회원 삭제 (DELETE /api/members/{memberId})
=== 회원 삭제 (DELETE /api/members)

==== 요청
include::{snippets}/member-controller-web-mvc-test/회원_삭제/request-headers.adoc[]
include::{snippets}/member-controller-web-mvc-test/회원_삭제/path-parameters.adoc[]
include::{snippets}/member-controller-web-mvc-test/회원_삭제/http-request.adoc[]

==== 응답
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.atwoz.member.application.member;

import com.atwoz.member.domain.member.MemberRepository;
import com.atwoz.member.exception.exceptions.member.MemberNicknameAlreadyExistedException;
import com.atwoz.member.infrastructure.member.dto.MemberResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@RequiredArgsConstructor
@Transactional(readOnly = true)
@Service
public class MemberQueryService {

private final MemberRepository memberRepository;

public void checkMemberExists(final String nickname) {
if (memberRepository.existsByNickname(nickname)) {
throw new MemberNicknameAlreadyExistedException();
}
}

public MemberResponse findMember(final Long memberId) {
return memberRepository.findMemberWithId(memberId);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.atwoz.member.application.member;

import com.atwoz.member.application.member.dto.MemberInitializeRequest;
import com.atwoz.member.application.member.dto.MemberNicknameRequest;
import com.atwoz.member.application.member.dto.MemberUpdateRequest;
import com.atwoz.member.domain.member.Member;
import com.atwoz.member.domain.member.MemberRepository;
Expand Down Expand Up @@ -30,17 +29,6 @@ public void create(final String phoneNumber) {
memberRepository.save(Member.createWithOAuth(phoneNumber));
}

@Transactional(readOnly = true)
public void checkMemberExists(final MemberNicknameRequest memberNicknameRequest) {
validateNicknameIsUnique(memberNicknameRequest.nickname());
}

private void validateNicknameIsUnique(final String nickname) {
if (memberRepository.existsByNickname(nickname)) {
throw new MemberNicknameAlreadyExistedException();
}
}

public void initializeMember(final Long memberId, final MemberInitializeRequest memberInitializeRequest) {
Member foundMember = findMemberById(memberId);
MemberProfileDto memberProfileDto = MemberProfileDto.createWith(
Expand All @@ -50,6 +38,12 @@ public void initializeMember(final Long memberId, final MemberInitializeRequest
foundMember.initializeWith(memberInitializeRequest.nickname(), foundRecommenderId, memberProfileDto);
}

private void validateNicknameIsUnique(final String nickname) {
if (memberRepository.existsByNickname(nickname)) {
throw new MemberNicknameAlreadyExistedException();
}
}

private Member findMemberById(final Long memberId) {
return memberRepository.findById(memberId)
.orElseThrow(MemberNotFoundException::new);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.atwoz.member.domain.member;

import com.atwoz.member.infrastructure.member.dto.MemberResponse;
import java.util.Optional;

public interface MemberRepository {
Expand All @@ -10,6 +11,8 @@ public interface MemberRepository {

Optional<Member> findByNickname(String nickname);

MemberResponse findMemberWithId(Long id);

Member save(Member member);

boolean existsByPhoneNumber(String phoneNumber);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,46 +1,47 @@
package com.atwoz.member.domain.member.profile.vo;
package com.atwoz.member.domain.member.profile;

import com.atwoz.member.domain.member.profile.vo.Hobby;
import com.atwoz.member.exception.exceptions.member.profile.HobbyDuplicateException;
import com.atwoz.member.exception.exceptions.member.profile.HobbySizeException;
import com.atwoz.member.exception.exceptions.member.profile.InvalidHobbyException;
import jakarta.persistence.CollectionTable;
import jakarta.persistence.ElementCollection;
import jakarta.persistence.Embeddable;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.OneToMany;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Embeddable
@EqualsAndHashCode(of = "id")
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor(access = AccessLevel.PUBLIC)
@Entity
public class MemberHobbies {

private static final int MIN_HOBBY_SIZE = 1;
private static final int MAX_HOBBY_SIZE = 3;

@ElementCollection
@CollectionTable(name = "HOBBIES", joinColumns = @JoinColumn(name = "profile_id"))
@Enumerated(EnumType.STRING)
private Set<Hobby> hobbies = new HashSet<>();
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

public MemberHobbies changeWith(final List<String> hobbyCodes) {
validateHobbyCodes(hobbyCodes);
Set<Hobby> uniqueHobbies = convertToUniqueHobbies(hobbyCodes);

if (isSameAsCurrentValue(uniqueHobbies)) {
return new MemberHobbies(this.hobbies);
}
@JoinColumn(name = "member_hobbies_id")
@OneToMany(cascade = {CascadeType.PERSIST, CascadeType.REMOVE}, orphanRemoval = true, fetch = FetchType.LAZY)
private Set<MemberHobby> hobbies = new HashSet<>();

return new MemberHobbies(uniqueHobbies);
public void change(final List<String> hobbyCodes) {
validateHobbyCodes(hobbyCodes);
changeHobbies(hobbyCodes);
}

private void validateHobbyCodes(final List<String> hobbyCodes) {
Expand Down Expand Up @@ -76,13 +77,16 @@ private boolean hasInvalidHobbyCode(final List<String> hobbyCodes) {
.anyMatch(hobbyCode -> !Hobby.isValidCode(hobbyCode));
}

private Set<Hobby> convertToUniqueHobbies(final List<String> hobbyCodes) {
return hobbyCodes.stream()
.map(Hobby::findByCode)
.collect(Collectors.toSet());
private void changeHobbies(final List<String> hobbyCodes) {
hobbies.removeIf(memberHobby -> !memberHobby.hasMatchingHobbyCodeOf(hobbyCodes));
hobbyCodes.stream()
.map(MemberHobby::createWith)
.filter(memberHobby -> !isAlreadyExist(memberHobby))
.forEach(memberHobby -> hobbies.add(memberHobby));
}

private boolean isSameAsCurrentValue(final Set<Hobby> uniqueHobbies) {
return uniqueHobbies.equals(this.hobbies);
private boolean isAlreadyExist(final MemberHobby memberHobby) {
return hobbies.stream()
.anyMatch(memberHobby::isSame);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.atwoz.member.domain.member.profile;

import com.atwoz.member.domain.member.profile.vo.Hobby;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import java.util.List;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Builder
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Entity
public class MemberHobby {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Enumerated(EnumType.STRING)
private Hobby hobby;

public static MemberHobby createWith(final String hobbyCode) {
return MemberHobby.builder()
.hobby(Hobby.findByCode(hobbyCode))
.build();
}

public boolean hasMatchingHobbyCodeOf(final List<String> hobbyCodes) {
return hobbyCodes.contains(hobby.getCode());
}

public boolean isSame(final MemberHobby memberHobby) {
return this.hobby.equals(memberHobby.hobby);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.atwoz.member.domain.member.profile;

import com.atwoz.member.domain.member.profile.vo.Style;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import java.util.List;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Builder
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Entity
public class MemberStyle {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Enumerated(EnumType.STRING)
private Style style;

public static MemberStyle createWith(final String styleCode) {
return MemberStyle.builder()
.style(Style.findByCode(styleCode))
.build();
}

public boolean hasMatchingStyleCodeOf(final List<String> styleCodes) {
return styleCodes.contains(style.getCode());
}

public boolean isSame(final MemberStyle memberStyle) {
return this.style.equals(memberStyle.style);
}
}
Loading

0 comments on commit 4dcad34

Please sign in to comment.