diff --git a/src/docs/asciidoc/auth.adoc b/src/docs/asciidoc/auth.adoc new file mode 100644 index 00000000..cdd8024b --- /dev/null +++ b/src/docs/asciidoc/auth.adoc @@ -0,0 +1,25 @@ +:toc: left +:source-highlighter: highlightjs +:sectlinks: +:toclevels: 2 +:sectlinks: +:sectnums: + +== Member + +=== 로그인 + +==== 요청 (POST api/auth/login) + +include::{snippets}/auth-controller-web-mvc-test/do_signup/http-request.adoc[] +include::{snippets}/auth-controller-web-mvc-test/do_signup/request-fields.adoc[] + + +==== 응답 +include::{snippets}/auth-controller-web-mvc-test/do_signup/http-response.adoc[] +include::{snippets}/auth-controller-web-mvc-test/do_signup/request-fields.adoc[] + + + + + diff --git a/src/docs/asciidoc/index.adoc b/src/docs/asciidoc/index.adoc index aa206863..a84f99be 100644 --- a/src/docs/asciidoc/index.adoc +++ b/src/docs/asciidoc/index.adoc @@ -5,7 +5,7 @@ :sectlinks: == atwoz Server API -* link:member.adoc[회원 API] -* link:info.adoc[회원 정보 API] +* link:auth.adoc[회원 API] +* link:member.adoc[회원 정보 API] * link:mission.adoc[미션 API] * link:membermissions.adoc[회원 미션 API] diff --git a/src/docs/asciidoc/info.adoc b/src/docs/asciidoc/info.adoc deleted file mode 100644 index 67e1e934..00000000 --- a/src/docs/asciidoc/info.adoc +++ /dev/null @@ -1,37 +0,0 @@ -:toc: left -:source-highlighter: highlightjs -:sectlinks: -:toclevels: 2 -:sectlinks: -:sectnums: - -== Info - -=== 회원 정보 작성 - -==== 요청 -include::{snippets}/info-controller-web-mvc-test/write_info/http-request.adoc[] -include::{snippets}/info-controller-web-mvc-test/write_info/request-headers.adoc[] -include::{snippets}/info-controller-web-mvc-test/write_info/request-fields.adoc[] - -==== 응답 -include::{snippets}/info-controller-web-mvc-test/write_info/http-response.adoc[] - -=== 회원 정보 수정 - -==== 요청 -include::{snippets}/info-controller-web-mvc-test/update_info/http-request.adoc[] -include::{snippets}/info-controller-web-mvc-test/update_info/request-headers.adoc[] -include::{snippets}/info-controller-web-mvc-test/update_info/request-fields.adoc[] - -==== 응답 -include::{snippets}/info-controller-web-mvc-test/update_info/http-response.adoc[] - -=== 회원 정보 조회 - -==== 요청 -include::{snippets}/info-controller-web-mvc-test/search_info/http-request.adoc[] -include::{snippets}/info-controller-web-mvc-test/search_info/request-headers.adoc[] -==== 응답 -include::{snippets}/info-controller-web-mvc-test/search_info/http-response.adoc[] -include::{snippets}/info-controller-web-mvc-test/search_info/response-fields.adoc[] diff --git a/src/docs/asciidoc/member.adoc b/src/docs/asciidoc/member.adoc index 18d6c3d1..a1bcf005 100644 --- a/src/docs/asciidoc/member.adoc +++ b/src/docs/asciidoc/member.adoc @@ -5,21 +5,49 @@ :sectlinks: :sectnums: -== Member +== Info -=== 로그인 +=== 닉네임 중복 확인 (GET /api/members/nickname/existence) ==== 요청 +include::{snippets}/member-controller-web-mvc-test/닉네임_중복_확인/request-headers.adoc[] +include::{snippets}/member-controller-web-mvc-test/닉네임_중복_확인/request-fields.adoc[] +include::{snippets}/member-controller-web-mvc-test/닉네임_중복_확인/http-request.adoc[] -include::{snippets}/auth-controller-web-mvc-test/do_signup/http-request.adoc[] -include::{snippets}/auth-controller-web-mvc-test/do_signup/request-fields.adoc[] +==== 응답 +include::{snippets}/member-controller-web-mvc-test/닉네임_중복_확인/http-response.adoc[] + + +=== 회원 정보 초기화 (POST /api/members/{memberId}) +==== 요청 +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}/auth-controller-web-mvc-test/do_signup/http-response.adoc[] -include::{snippets}/auth-controller-web-mvc-test/do_signup/request-fields.adoc[] +include::{snippets}/member-controller-web-mvc-test/회원_정보_초기화/http-response.adoc[] +=== 회원 정보 수정 (PATCH /api/members/{memberId}) +==== 요청 +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}) + +==== 요청 +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[] + +==== 응답 +include::{snippets}/member-controller-web-mvc-test/회원_삭제/http-response.adoc[] diff --git a/src/main/java/com/atwoz/global/domain/BaseEntity.java b/src/main/java/com/atwoz/global/domain/BaseEntity.java index 4b83c3f9..7c117ecf 100644 --- a/src/main/java/com/atwoz/global/domain/BaseEntity.java +++ b/src/main/java/com/atwoz/global/domain/BaseEntity.java @@ -3,6 +3,7 @@ import jakarta.persistence.Column; import jakarta.persistence.EntityListeners; import jakarta.persistence.MappedSuperclass; +import java.time.LocalDateTime; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; @@ -11,8 +12,6 @@ import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; -import java.time.LocalDateTime; - @Getter @SuperBuilder @MappedSuperclass diff --git a/src/main/java/com/atwoz/global/domain/SoftDeleteBaseEntity.java b/src/main/java/com/atwoz/global/domain/SoftDeleteBaseEntity.java new file mode 100644 index 00000000..ff60bc14 --- /dev/null +++ b/src/main/java/com/atwoz/global/domain/SoftDeleteBaseEntity.java @@ -0,0 +1,19 @@ +package com.atwoz.global.domain; + +import jakarta.persistence.EntityListeners; +import jakarta.persistence.MappedSuperclass; +import java.time.LocalDateTime; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +@Getter +@MappedSuperclass +@NoArgsConstructor +@AllArgsConstructor +@EntityListeners(AuditingEntityListener.class) +public abstract class SoftDeleteBaseEntity extends BaseEntity { + + private LocalDateTime deletedAt; +} diff --git a/src/main/java/com/atwoz/member/application/auth/AuthService.java b/src/main/java/com/atwoz/member/application/auth/AuthService.java index 2c61a67a..4183b5a4 100644 --- a/src/main/java/com/atwoz/member/application/auth/AuthService.java +++ b/src/main/java/com/atwoz/member/application/auth/AuthService.java @@ -14,6 +14,8 @@ @Service public class AuthService { + private static final String DEFAULT_PHONE_NUMBER = "01011111111"; + private final TokenProvider tokenProvider; private final OAuthRequester oAuthRequester; @@ -21,8 +23,12 @@ public class AuthService { public String login(final LoginRequest request, final OAuthProviderRequest provider) { String accessToken = oAuthRequester.getAccessToken(request.code(), provider); MemberInfoResponse memberInfoResponse = oAuthRequester.getMemberInfo(accessToken, provider); - Events.raise(new ValidatedLoginEvent(memberInfoResponse.email(), memberInfoResponse.name())); - return tokenProvider.createTokenWith(memberInfoResponse.email()); + /** + * OAuth 인증방식과 PASS 인증 방식에 차이가 존재해서 회의 후 메서드 변경을 진행할 예정 + */ + Events.raise(new ValidatedLoginEvent(DEFAULT_PHONE_NUMBER)); + + return tokenProvider.createTokenWithPhoneNumber(DEFAULT_PHONE_NUMBER); } } diff --git a/src/main/java/com/atwoz/member/application/auth/OAuthRequester.java b/src/main/java/com/atwoz/member/application/auth/OAuthRequester.java index 2aef158e..d551e763 100644 --- a/src/main/java/com/atwoz/member/application/auth/OAuthRequester.java +++ b/src/main/java/com/atwoz/member/application/auth/OAuthRequester.java @@ -5,7 +5,7 @@ public interface OAuthRequester { - String getAccessToken(final String code, final OAuthProviderRequest provider); + String getAccessToken(String code, OAuthProviderRequest provider); - MemberInfoResponse getMemberInfo(final String accessToken, final OAuthProviderRequest oAuthProviderRequest); + MemberInfoResponse getMemberInfo(String accessToken, OAuthProviderRequest oAuthProviderRequest); } diff --git a/src/main/java/com/atwoz/member/application/auth/event/ValidatedLoginEvent.java b/src/main/java/com/atwoz/member/application/auth/event/ValidatedLoginEvent.java index b3c8023a..eae01c4f 100644 --- a/src/main/java/com/atwoz/member/application/auth/event/ValidatedLoginEvent.java +++ b/src/main/java/com/atwoz/member/application/auth/event/ValidatedLoginEvent.java @@ -8,6 +8,5 @@ @RequiredArgsConstructor public class ValidatedLoginEvent extends Event { - private final String email; - private final String nickname; + private final String phoneNumber; } diff --git a/src/main/java/com/atwoz/member/application/info/InfoService.java b/src/main/java/com/atwoz/member/application/info/InfoService.java deleted file mode 100644 index 917d4159..00000000 --- a/src/main/java/com/atwoz/member/application/info/InfoService.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.atwoz.member.application.info; - -import com.atwoz.global.event.Events; -import com.atwoz.member.application.info.hobby.event.HobbyUpdatedEvent; -import com.atwoz.member.application.info.hobby.event.HobbyWroteEvent; -import com.atwoz.member.application.info.option.event.OptionUpdatedEvent; -import com.atwoz.member.application.info.option.event.OptionWroteEvent; -import com.atwoz.member.application.info.profile.event.ProfileUpdatedEvent; -import com.atwoz.member.application.info.profile.event.ProfileWroteEvent; -import com.atwoz.member.application.info.style.event.StyleUpdatedEvent; -import com.atwoz.member.application.info.style.event.StyleWroteEvent; -import com.atwoz.member.application.info.hobby.dto.HobbyUpdateRequest; -import com.atwoz.member.application.info.hobby.dto.HobbyWriteRequest; -import com.atwoz.member.application.info.dto.InfoUpdateRequest; -import com.atwoz.member.application.info.dto.InfoWriteRequest; -import com.atwoz.member.application.info.style.dto.StyleUpdateRequest; -import com.atwoz.member.application.info.style.dto.StyleWriteRequest; -import com.atwoz.member.domain.info.InfoRepository; -import com.atwoz.member.exception.exceptions.info.InfoNotFoundException; -import com.atwoz.member.infrastructure.info.dto.InfoSearchResponse; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import java.util.List; - -@RequiredArgsConstructor -@Transactional(readOnly = true) -@Service -public class InfoService { - - private final InfoRepository infoRepository; - - @Transactional - public void writeInfo(final Long memberId, final InfoWriteRequest request) { - List hobbyCodes = extractHobbyNamesFromInfoWriteRequest(request.hobbies()); - List styleCodes = extractStyleNamesFromInfoWriteRequest(request.styles()); - - Events.raise(new ProfileWroteEvent(memberId, request.profile())); - Events.raise(new OptionWroteEvent(memberId, request.option())); - - Events.raise(new HobbyWroteEvent(memberId, hobbyCodes)); - Events.raise(new StyleWroteEvent(memberId, styleCodes)); - } - - private List extractHobbyNamesFromInfoWriteRequest(final List hobbies) { - return hobbies.stream() - .map(HobbyWriteRequest::hobby) - .toList(); - } - - private List extractStyleNamesFromInfoWriteRequest(final List styles) { - return styles.stream() - .map(StyleWriteRequest::style) - .toList(); - } - - @Transactional - public void updateInfo(final Long memberId, final InfoUpdateRequest request) { - List hobbyCodes = extractHobbyNamesFromInfoUpdateRequest(request.hobbies()); - List styleCodes = extractStyleNamesFromInfoUpdateRequest(request.styles()); - - Events.raise(new ProfileUpdatedEvent(memberId, request.profile())); - Events.raise(new OptionUpdatedEvent(memberId, request.option())); - - Events.raise(new HobbyUpdatedEvent(memberId, hobbyCodes)); - Events.raise(new StyleUpdatedEvent(memberId, styleCodes)); - } - - private List extractHobbyNamesFromInfoUpdateRequest(final List hobbies) { - return hobbies.stream() - .map(HobbyUpdateRequest::hobby) - .toList(); - } - - private List extractStyleNamesFromInfoUpdateRequest(final List styles) { - return styles.stream() - .map(StyleUpdateRequest::style) - .toList(); - } - - public InfoSearchResponse findInfo(final Long memberId) { - return infoRepository.findByMemberId(memberId) - .orElseThrow(InfoNotFoundException::new); - } -} diff --git a/src/main/java/com/atwoz/member/application/info/dto/InfoUpdateRequest.java b/src/main/java/com/atwoz/member/application/info/dto/InfoUpdateRequest.java deleted file mode 100644 index 445a18e8..00000000 --- a/src/main/java/com/atwoz/member/application/info/dto/InfoUpdateRequest.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.atwoz.member.application.info.dto; - -import com.atwoz.member.application.info.hobby.dto.HobbyUpdateRequest; -import com.atwoz.member.application.info.option.dto.OptionUpdateRequest; -import com.atwoz.member.application.info.profile.dto.ProfileUpdateRequest; -import com.atwoz.member.application.info.style.dto.StyleUpdateRequest; -import jakarta.validation.Valid; -import jakarta.validation.constraints.NotNull; -import java.util.List; - -public record InfoUpdateRequest( - @Valid - @NotNull(message = "profile 요청이 있어야 합니다.") - ProfileUpdateRequest profile, - - @Valid - @NotNull(message = "option 요청이 있어야 합니다.") - OptionUpdateRequest option, - - @Valid - @NotNull(message = "취미 요청이 있어야 합니다.") - List hobbies, - - @Valid - @NotNull(message = "스타일 요청이 있어야 합니다.") - List styles -) { -} diff --git a/src/main/java/com/atwoz/member/application/info/dto/InfoWriteRequest.java b/src/main/java/com/atwoz/member/application/info/dto/InfoWriteRequest.java deleted file mode 100644 index 1912a2a1..00000000 --- a/src/main/java/com/atwoz/member/application/info/dto/InfoWriteRequest.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.atwoz.member.application.info.dto; - -import com.atwoz.member.application.info.hobby.dto.HobbyWriteRequest; -import com.atwoz.member.application.info.option.dto.OptionWriteRequest; -import com.atwoz.member.application.info.profile.dto.ProfileWriteRequest; -import com.atwoz.member.application.info.style.dto.StyleWriteRequest; -import jakarta.validation.Valid; -import jakarta.validation.constraints.NotNull; -import java.util.List; - -public record InfoWriteRequest( - @Valid - @NotNull(message = "profile 요청이 있어야 합니다.") - ProfileWriteRequest profile, - - @Valid - @NotNull(message = "option 요청이 있어야 합니다.") - OptionWriteRequest option, - - @Valid - @NotNull(message = "취미 요청이 있어야 합니다.") - List hobbies, - - @Valid - @NotNull(message = "스타일 요청이 있어야 합니다.") - List styles -) { -} diff --git a/src/main/java/com/atwoz/member/application/info/hobby/HobbyEventHandler.java b/src/main/java/com/atwoz/member/application/info/hobby/HobbyEventHandler.java deleted file mode 100644 index 66827c4d..00000000 --- a/src/main/java/com/atwoz/member/application/info/hobby/HobbyEventHandler.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.atwoz.member.application.info.hobby; - -import com.atwoz.member.application.info.hobby.event.HobbyUpdatedEvent; -import com.atwoz.member.application.info.hobby.event.HobbyWroteEvent; -import lombok.RequiredArgsConstructor; -import org.springframework.context.event.EventListener; -import org.springframework.stereotype.Component; -import java.util.List; - -@RequiredArgsConstructor -@Component -public class HobbyEventHandler { - - private final MemberHobbyService memberHobbyService; - - @EventListener - public void writeHobbies(final HobbyWroteEvent event) { - Long memberId = event.getMemberId(); - List hobbyCodes = event.getHobbyCodes(); - - memberHobbyService.saveMemberHobbies(memberId, hobbyCodes); - } - - @EventListener - public void updateHobbies(final HobbyUpdatedEvent event) { - Long memberId = event.getMemberId(); - List hobbyCodes = event.getHobbyCodes(); - - memberHobbyService.updateMemberHobbies(memberId, hobbyCodes); - } -} diff --git a/src/main/java/com/atwoz/member/application/info/hobby/MemberHobbyService.java b/src/main/java/com/atwoz/member/application/info/hobby/MemberHobbyService.java deleted file mode 100644 index 63dcb9d6..00000000 --- a/src/main/java/com/atwoz/member/application/info/hobby/MemberHobbyService.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.atwoz.member.application.info.hobby; - -import com.atwoz.member.domain.info.hobby.Hobby; -import com.atwoz.member.domain.info.hobby.MemberHobby; -import com.atwoz.member.domain.info.hobby.MemberHobbyRepository; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import java.util.List; - -@RequiredArgsConstructor -@Transactional(readOnly = true) -@Service -public class MemberHobbyService { - - private final MemberHobbyRepository memberHobbyRepository; - - @Transactional - public void saveMemberHobbies(final Long memberId, final List hobbyCodes) { - saveMemberHobbiesByHobbyCodes(memberId, hobbyCodes); - } - - private void saveMemberHobbiesByHobbyCodes(final Long memberId, final List hobbyCodes) { - List memberHobbies = Hobby.findAllByCodes(hobbyCodes) - .stream() - .map(hobby -> new MemberHobby(memberId, hobby)) - .toList(); - - memberHobbyRepository.saveAll(memberHobbies); - } - - @Transactional - public void updateMemberHobbies(final Long memberId, final List hobbyCodes) { - memberHobbyRepository.deleteHobbiesByMemberId(memberId); - - saveMemberHobbiesByHobbyCodes(memberId, hobbyCodes); - } -} diff --git a/src/main/java/com/atwoz/member/application/info/hobby/dto/HobbyUpdateRequest.java b/src/main/java/com/atwoz/member/application/info/hobby/dto/HobbyUpdateRequest.java deleted file mode 100644 index 3160431d..00000000 --- a/src/main/java/com/atwoz/member/application/info/hobby/dto/HobbyUpdateRequest.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.atwoz.member.application.info.hobby.dto; - -import jakarta.validation.constraints.NotBlank; - -public record HobbyUpdateRequest( - @NotBlank(message = "취미가 작성되어야 합니다.") - String hobby -) { -} diff --git a/src/main/java/com/atwoz/member/application/info/hobby/dto/HobbyWriteRequest.java b/src/main/java/com/atwoz/member/application/info/hobby/dto/HobbyWriteRequest.java deleted file mode 100644 index b7a05385..00000000 --- a/src/main/java/com/atwoz/member/application/info/hobby/dto/HobbyWriteRequest.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.atwoz.member.application.info.hobby.dto; - -import jakarta.validation.constraints.NotBlank; - -public record HobbyWriteRequest( - @NotBlank(message = "취미가 작성되어야 합니다.") - String hobby -) { -} diff --git a/src/main/java/com/atwoz/member/application/info/hobby/event/HobbyUpdatedEvent.java b/src/main/java/com/atwoz/member/application/info/hobby/event/HobbyUpdatedEvent.java deleted file mode 100644 index 5d21f9a0..00000000 --- a/src/main/java/com/atwoz/member/application/info/hobby/event/HobbyUpdatedEvent.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.atwoz.member.application.info.hobby.event; - -import com.atwoz.global.event.Event; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import java.util.List; - -@Getter -@RequiredArgsConstructor -public class HobbyUpdatedEvent extends Event { - - private final Long memberId; - private final List hobbyCodes; -} diff --git a/src/main/java/com/atwoz/member/application/info/hobby/event/HobbyWroteEvent.java b/src/main/java/com/atwoz/member/application/info/hobby/event/HobbyWroteEvent.java deleted file mode 100644 index 99c70fb5..00000000 --- a/src/main/java/com/atwoz/member/application/info/hobby/event/HobbyWroteEvent.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.atwoz.member.application.info.hobby.event; - -import com.atwoz.global.event.Event; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import java.util.List; - -@Getter -@RequiredArgsConstructor -public class HobbyWroteEvent extends Event { - - private final Long memberId; - private final List hobbyCodes; -} diff --git a/src/main/java/com/atwoz/member/application/info/option/OptionEventHandler.java b/src/main/java/com/atwoz/member/application/info/option/OptionEventHandler.java deleted file mode 100644 index 6e2f7a64..00000000 --- a/src/main/java/com/atwoz/member/application/info/option/OptionEventHandler.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.atwoz.member.application.info.option; - -import com.atwoz.member.application.info.option.event.OptionUpdatedEvent; -import com.atwoz.member.application.info.option.event.OptionWroteEvent; -import com.atwoz.member.application.info.option.dto.OptionUpdateRequest; -import com.atwoz.member.application.info.option.dto.OptionWriteRequest; -import lombok.RequiredArgsConstructor; -import org.springframework.context.event.EventListener; -import org.springframework.stereotype.Component; - -@RequiredArgsConstructor -@Component -public class OptionEventHandler { - - private final OptionService optionService; - - @EventListener - public void writeOption(final OptionWroteEvent event) { - Long memberId = event.getMemberId(); - OptionWriteRequest request = event.getRequest(); - - optionService.writeOption(memberId, request); - } - - @EventListener - public void updateOption(final OptionUpdatedEvent event) { - Long memberId = event.getMemberId(); - OptionUpdateRequest request = event.getRequest(); - - optionService.updateOption(memberId, request); - } -} diff --git a/src/main/java/com/atwoz/member/application/info/option/OptionService.java b/src/main/java/com/atwoz/member/application/info/option/OptionService.java deleted file mode 100644 index dac012d5..00000000 --- a/src/main/java/com/atwoz/member/application/info/option/OptionService.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.atwoz.member.application.info.option; - -import com.atwoz.member.application.info.option.dto.OptionUpdateRequest; -import com.atwoz.member.application.info.option.dto.OptionWriteRequest; -import com.atwoz.member.domain.info.option.Option; -import com.atwoz.member.domain.info.option.OptionRepository; -import com.atwoz.member.domain.info.option.dto.InnerOptionUpdateRequest; -import com.atwoz.member.domain.info.option.dto.InnerOptionWriteRequest; -import com.atwoz.member.exception.exceptions.info.option.OptionNotFoundException; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -@RequiredArgsConstructor -@Transactional(readOnly = true) -@Service -public class OptionService { - - private final OptionRepository optionRepository; - - @Transactional - public void writeOption(final Long memberId, final OptionWriteRequest request) { - InnerOptionWriteRequest optionWriteRequest = InnerOptionWriteRequest.of(memberId, request); - Option newOption = Option.createFrom(optionWriteRequest); - if (!optionRepository.isExistMemberOption(memberId)) { - optionRepository.save(newOption); - } - } - - @Transactional - public void updateOption(final Long memberId, final OptionUpdateRequest request) { - InnerOptionUpdateRequest optionUpdateRequest = InnerOptionUpdateRequest.from(request); - Option existOption = findByMemberId(memberId); - existOption.updateContentsFrom(optionUpdateRequest); - } - - private Option findByMemberId(final Long memberId) { - return optionRepository.findByMemberId(memberId) - .orElseThrow(OptionNotFoundException::new); - } -} diff --git a/src/main/java/com/atwoz/member/application/info/option/dto/OptionUpdateRequest.java b/src/main/java/com/atwoz/member/application/info/option/dto/OptionUpdateRequest.java deleted file mode 100644 index 8ada9c0e..00000000 --- a/src/main/java/com/atwoz/member/application/info/option/dto/OptionUpdateRequest.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.atwoz.member.application.info.option.dto; - -import jakarta.validation.constraints.NotBlank; - -public record OptionUpdateRequest( - @NotBlank(message = "음주가 작성되어야 합니다.") - String drink, - - @NotBlank(message = "최종학력이 작성되어야 합니다.") - String graduate, - - @NotBlank(message = "종교가 작성되어야 합니다.") - String religion, - - @NotBlank(message = "흡연이 작성되어야 합니다.") - String smoke, - - @NotBlank(message = "MBTI가 작성되어야 합니다.") - String mbti -) { -} diff --git a/src/main/java/com/atwoz/member/application/info/option/dto/OptionWriteRequest.java b/src/main/java/com/atwoz/member/application/info/option/dto/OptionWriteRequest.java deleted file mode 100644 index 7e0efff1..00000000 --- a/src/main/java/com/atwoz/member/application/info/option/dto/OptionWriteRequest.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.atwoz.member.application.info.option.dto; - -import jakarta.validation.constraints.NotBlank; - -public record OptionWriteRequest( - @NotBlank(message = "음주가 작성되어야 합니다.") - String drink, - - @NotBlank(message = "최종학력이 작성되어야 합니다.") - String graduate, - - @NotBlank(message = "종교가 작성되어야 합니다.") - String religion, - - @NotBlank(message = "흡연이 작성되어야 합니다.") - String smoke, - - @NotBlank(message = "MBTI가 작성되어야 합니다.") - String mbti -) { -} diff --git a/src/main/java/com/atwoz/member/application/info/option/event/OptionUpdatedEvent.java b/src/main/java/com/atwoz/member/application/info/option/event/OptionUpdatedEvent.java deleted file mode 100644 index b737c5e5..00000000 --- a/src/main/java/com/atwoz/member/application/info/option/event/OptionUpdatedEvent.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.atwoz.member.application.info.option.event; - -import com.atwoz.global.event.Event; -import com.atwoz.member.application.info.option.dto.OptionUpdateRequest; -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -@Getter -@RequiredArgsConstructor -public class OptionUpdatedEvent extends Event { - - private final Long memberId; - private final OptionUpdateRequest request; -} diff --git a/src/main/java/com/atwoz/member/application/info/option/event/OptionWroteEvent.java b/src/main/java/com/atwoz/member/application/info/option/event/OptionWroteEvent.java deleted file mode 100644 index 52a19435..00000000 --- a/src/main/java/com/atwoz/member/application/info/option/event/OptionWroteEvent.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.atwoz.member.application.info.option.event; - -import com.atwoz.global.event.Event; -import com.atwoz.member.application.info.option.dto.OptionWriteRequest; -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -@Getter -@RequiredArgsConstructor -public class OptionWroteEvent extends Event { - - private final Long memberId; - private final OptionWriteRequest request; -} diff --git a/src/main/java/com/atwoz/member/application/info/profile/ProfileEventHandler.java b/src/main/java/com/atwoz/member/application/info/profile/ProfileEventHandler.java deleted file mode 100644 index 7468e369..00000000 --- a/src/main/java/com/atwoz/member/application/info/profile/ProfileEventHandler.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.atwoz.member.application.info.profile; - -import com.atwoz.member.application.info.profile.event.ProfileUpdatedEvent; -import com.atwoz.member.application.info.profile.event.ProfileWroteEvent; -import com.atwoz.member.application.info.profile.dto.ProfileUpdateRequest; -import com.atwoz.member.application.info.profile.dto.ProfileWriteRequest; -import lombok.RequiredArgsConstructor; -import org.springframework.context.event.EventListener; -import org.springframework.stereotype.Component; - -@RequiredArgsConstructor -@Component -public class ProfileEventHandler { - - private final ProfileService profileService; - - @EventListener - public void writeProfile(final ProfileWroteEvent event) { - Long memberId = event.getMemberId(); - ProfileWriteRequest request = event.getRequest(); - - profileService.writeProfile(memberId, request); - } - - @EventListener - public void updateProfile(final ProfileUpdatedEvent event) { - Long memberId = event.getMemberId(); - ProfileUpdateRequest request = event.getRequest(); - - profileService.updateProfile(memberId, request); - } -} diff --git a/src/main/java/com/atwoz/member/application/info/profile/ProfileService.java b/src/main/java/com/atwoz/member/application/info/profile/ProfileService.java deleted file mode 100644 index 23b67915..00000000 --- a/src/main/java/com/atwoz/member/application/info/profile/ProfileService.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.atwoz.member.application.info.profile; - -import com.atwoz.member.application.info.profile.dto.ProfileUpdateRequest; -import com.atwoz.member.application.info.profile.dto.ProfileWriteRequest; -import com.atwoz.member.domain.info.profile.dto.InnerProfileUpdateRequest; -import com.atwoz.member.domain.info.profile.Profile; -import com.atwoz.member.domain.info.profile.ProfileRepository; -import com.atwoz.member.domain.info.profile.body.YearManager; -import com.atwoz.member.domain.info.profile.dto.InnerProfileWriteRequest; -import com.atwoz.member.exception.exceptions.info.profile.ProfileNotFoundException; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -@RequiredArgsConstructor -@Transactional(readOnly = true) -@Service -public class ProfileService { - - private final ProfileRepository profileRepository; - private final YearManager yearManager; - - @Transactional - public void writeProfile(final Long memberId, final ProfileWriteRequest request) { - InnerProfileWriteRequest profileWriteRequest = InnerProfileWriteRequest.of(memberId, yearManager, request); - Profile newProfile = Profile.createFrom(profileWriteRequest); - if (!profileRepository.isExistMemberProfile(memberId)) { - profileRepository.save(newProfile); - } - } - - @Transactional - public void updateProfile(final Long memberId, final ProfileUpdateRequest request) { - InnerProfileUpdateRequest profileUpdateRequest = InnerProfileUpdateRequest.of(memberId, yearManager, request); - Profile existProfile = findByMemberId(memberId); - existProfile.updateContentsFrom(profileUpdateRequest); - } - - private Profile findByMemberId(final Long memberId) { - return profileRepository.findByMemberId(memberId) - .orElseThrow(ProfileNotFoundException::new); - } -} diff --git a/src/main/java/com/atwoz/member/application/info/profile/body/dto/BodyUpdateRequest.java b/src/main/java/com/atwoz/member/application/info/profile/body/dto/BodyUpdateRequest.java deleted file mode 100644 index f365ae58..00000000 --- a/src/main/java/com/atwoz/member/application/info/profile/body/dto/BodyUpdateRequest.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.atwoz.member.application.info.profile.body.dto; - -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.NotNull; - -public record BodyUpdateRequest( - @NotNull(message = "출생년도가 작성되어야 합니다.") - Integer birthYear, - - @NotNull(message = "키가 작성되어야 합니다.") - Integer height, - - @NotBlank(message = "성별이 작성되어야 합니다.") - String gender -) { -} diff --git a/src/main/java/com/atwoz/member/application/info/profile/body/dto/BodyWriteRequest.java b/src/main/java/com/atwoz/member/application/info/profile/body/dto/BodyWriteRequest.java deleted file mode 100644 index 62c7d8f3..00000000 --- a/src/main/java/com/atwoz/member/application/info/profile/body/dto/BodyWriteRequest.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.atwoz.member.application.info.profile.body.dto; - -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.NotNull; - -public record BodyWriteRequest( - @NotNull(message = "출생년도가 작성되어야 합니다.") - Integer birthYear, - - @NotNull(message = "키가 작성되어야 합니다.") - Integer height, - - @NotBlank(message = "성별이 작성되어야 합니다.") - String gender -) { -} diff --git a/src/main/java/com/atwoz/member/application/info/profile/dto/ProfileUpdateRequest.java b/src/main/java/com/atwoz/member/application/info/profile/dto/ProfileUpdateRequest.java deleted file mode 100644 index 04e7a0e4..00000000 --- a/src/main/java/com/atwoz/member/application/info/profile/dto/ProfileUpdateRequest.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.atwoz.member.application.info.profile.dto; - -import com.atwoz.member.application.info.profile.body.dto.BodyUpdateRequest; -import com.atwoz.member.application.info.profile.location.dto.LocationUpdateRequest; -import com.atwoz.member.application.info.profile.position.dto.PositionUpdateRequest; -import jakarta.validation.Valid; -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.NotNull; - -public record ProfileUpdateRequest( - @Valid - @NotNull(message = "신체 정보가 작성되어야 합니다.") - BodyUpdateRequest body, - - @Valid - @NotNull(message = "위치가 작성되어야 합니다.") - LocationUpdateRequest location, - - @Valid - @NotNull(message = "위도-경도가 작성되어야 합니다.") - PositionUpdateRequest position, - - @NotBlank(message = "직업이 작성되어야 합니다.") - String job -) { -} diff --git a/src/main/java/com/atwoz/member/application/info/profile/dto/ProfileWriteRequest.java b/src/main/java/com/atwoz/member/application/info/profile/dto/ProfileWriteRequest.java deleted file mode 100644 index dd03b21d..00000000 --- a/src/main/java/com/atwoz/member/application/info/profile/dto/ProfileWriteRequest.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.atwoz.member.application.info.profile.dto; - -import com.atwoz.member.application.info.profile.body.dto.BodyWriteRequest; -import com.atwoz.member.application.info.profile.location.dto.LocationWriteRequest; -import com.atwoz.member.application.info.profile.position.dto.PositionWriteRequest; -import jakarta.validation.Valid; -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.NotNull; - -public record ProfileWriteRequest( - @Valid - @NotNull(message = "신체 정보가 작성되어야 합니다.") - BodyWriteRequest body, - - @Valid - @NotNull(message = "위치가 작성되어야 합니다.") - LocationWriteRequest location, - - @Valid - @NotNull(message = "위도-경도가 작성되어야 합니다.") - PositionWriteRequest position, - - @NotBlank(message = "직업이 작성되어야 합니다.") - String job -) { -} diff --git a/src/main/java/com/atwoz/member/application/info/profile/event/ProfileUpdatedEvent.java b/src/main/java/com/atwoz/member/application/info/profile/event/ProfileUpdatedEvent.java deleted file mode 100644 index da5a2325..00000000 --- a/src/main/java/com/atwoz/member/application/info/profile/event/ProfileUpdatedEvent.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.atwoz.member.application.info.profile.event; - -import com.atwoz.global.event.Event; -import com.atwoz.member.application.info.profile.dto.ProfileUpdateRequest; -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -@Getter -@RequiredArgsConstructor -public class ProfileUpdatedEvent extends Event { - - private final Long memberId; - private final ProfileUpdateRequest request; -} diff --git a/src/main/java/com/atwoz/member/application/info/profile/event/ProfileWroteEvent.java b/src/main/java/com/atwoz/member/application/info/profile/event/ProfileWroteEvent.java deleted file mode 100644 index 6d83d96d..00000000 --- a/src/main/java/com/atwoz/member/application/info/profile/event/ProfileWroteEvent.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.atwoz.member.application.info.profile.event; - -import com.atwoz.global.event.Event; -import com.atwoz.member.application.info.profile.dto.ProfileWriteRequest; -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -@Getter -@RequiredArgsConstructor -public class ProfileWroteEvent extends Event { - - private final Long memberId; - private final ProfileWriteRequest request; -} diff --git a/src/main/java/com/atwoz/member/application/info/profile/location/dto/LocationUpdateRequest.java b/src/main/java/com/atwoz/member/application/info/profile/location/dto/LocationUpdateRequest.java deleted file mode 100644 index 47ec55f9..00000000 --- a/src/main/java/com/atwoz/member/application/info/profile/location/dto/LocationUpdateRequest.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.atwoz.member.application.info.profile.location.dto; - -import jakarta.validation.constraints.NotBlank; - -public record LocationUpdateRequest( - @NotBlank(message = "시/도가 작성되어야 합니다.") - String city, - - @NotBlank(message = "구/군이 작성되어야 합니다.") - String sector -) { -} diff --git a/src/main/java/com/atwoz/member/application/info/profile/location/dto/LocationWriteRequest.java b/src/main/java/com/atwoz/member/application/info/profile/location/dto/LocationWriteRequest.java deleted file mode 100644 index cae511bd..00000000 --- a/src/main/java/com/atwoz/member/application/info/profile/location/dto/LocationWriteRequest.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.atwoz.member.application.info.profile.location.dto; - -import jakarta.validation.constraints.NotBlank; - -public record LocationWriteRequest( - @NotBlank(message = "시/도가 작성되어야 합니다.") - String city, - - @NotBlank(message = "구/군이 작성되어야 합니다.") - String sector -) { -} diff --git a/src/main/java/com/atwoz/member/application/info/profile/position/dto/PositionUpdateRequest.java b/src/main/java/com/atwoz/member/application/info/profile/position/dto/PositionUpdateRequest.java deleted file mode 100644 index 442900ab..00000000 --- a/src/main/java/com/atwoz/member/application/info/profile/position/dto/PositionUpdateRequest.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.atwoz.member.application.info.profile.position.dto; - -import jakarta.validation.constraints.NotNull; -import java.math.BigDecimal; - -public record PositionUpdateRequest( - @NotNull(message = "위도가 있어야 합니다.") - BigDecimal latitude, - - @NotNull(message = "경도가 있어야 합니다.") - BigDecimal longitude -) { -} diff --git a/src/main/java/com/atwoz/member/application/info/profile/position/dto/PositionWriteRequest.java b/src/main/java/com/atwoz/member/application/info/profile/position/dto/PositionWriteRequest.java deleted file mode 100644 index 0a6ae9ba..00000000 --- a/src/main/java/com/atwoz/member/application/info/profile/position/dto/PositionWriteRequest.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.atwoz.member.application.info.profile.position.dto; - -import jakarta.validation.constraints.NotNull; -import java.math.BigDecimal; - -public record PositionWriteRequest( - @NotNull(message = "위도가 있어야 합니다.") - BigDecimal latitude, - - @NotNull(message = "경도가 있어야 합니다.") - BigDecimal longitude -) { -} diff --git a/src/main/java/com/atwoz/member/application/info/style/MemberStyleService.java b/src/main/java/com/atwoz/member/application/info/style/MemberStyleService.java deleted file mode 100644 index 189abad4..00000000 --- a/src/main/java/com/atwoz/member/application/info/style/MemberStyleService.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.atwoz.member.application.info.style; - -import com.atwoz.member.domain.info.style.MemberStyle; -import com.atwoz.member.domain.info.style.Style; -import com.atwoz.member.domain.info.style.MemberStyleRepository; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import java.util.List; - -@RequiredArgsConstructor -@Transactional(readOnly = true) -@Service -public class MemberStyleService { - - private final MemberStyleRepository memberStyleRepository; - - @Transactional - public void saveMemberStyles(final Long memberId, final List styleCodes) { - saveMemberStylesByStyleCodes(memberId, styleCodes); - } - - private void saveMemberStylesByStyleCodes(final Long memberId, final List styleCodes) { - List memberStyles = Style.findAllByCodes(styleCodes) - .stream() - .map(style -> new MemberStyle(memberId, style)) - .toList(); - - memberStyleRepository.saveAll(memberStyles); - } - - @Transactional - public void updateMemberStyles(final Long memberId, final List styleCodes) { - memberStyleRepository.deleteStylesByMemberId(memberId); - - saveMemberStylesByStyleCodes(memberId, styleCodes); - } -} diff --git a/src/main/java/com/atwoz/member/application/info/style/StyleEventHandler.java b/src/main/java/com/atwoz/member/application/info/style/StyleEventHandler.java deleted file mode 100644 index 6af662df..00000000 --- a/src/main/java/com/atwoz/member/application/info/style/StyleEventHandler.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.atwoz.member.application.info.style; - -import com.atwoz.member.application.info.style.event.StyleUpdatedEvent; -import com.atwoz.member.application.info.style.event.StyleWroteEvent; -import lombok.RequiredArgsConstructor; -import org.springframework.context.event.EventListener; -import org.springframework.stereotype.Component; -import java.util.List; - -@RequiredArgsConstructor -@Component -public class StyleEventHandler { - - private final MemberStyleService memberStyleService; - - @EventListener - public void writeHobbies(final StyleWroteEvent event) { - Long memberId = event.getMemberId(); - List styleCodes = event.getStyleCodes(); - - memberStyleService.saveMemberStyles(memberId, styleCodes); - } - - @EventListener - public void updateHobbies(final StyleUpdatedEvent event) { - Long memberId = event.getMemberId(); - List styleCodes = event.getStyleCodes(); - - memberStyleService.updateMemberStyles(memberId, styleCodes); - } -} diff --git a/src/main/java/com/atwoz/member/application/info/style/dto/StyleUpdateRequest.java b/src/main/java/com/atwoz/member/application/info/style/dto/StyleUpdateRequest.java deleted file mode 100644 index 4e72fb63..00000000 --- a/src/main/java/com/atwoz/member/application/info/style/dto/StyleUpdateRequest.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.atwoz.member.application.info.style.dto; - -import jakarta.validation.constraints.NotBlank; - -public record StyleUpdateRequest( - @NotBlank(message = "스타일이 작성되어야 합니다.") - String style -) { -} diff --git a/src/main/java/com/atwoz/member/application/info/style/dto/StyleWriteRequest.java b/src/main/java/com/atwoz/member/application/info/style/dto/StyleWriteRequest.java deleted file mode 100644 index 4efce8a9..00000000 --- a/src/main/java/com/atwoz/member/application/info/style/dto/StyleWriteRequest.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.atwoz.member.application.info.style.dto; - -import jakarta.validation.constraints.NotBlank; - -public record StyleWriteRequest( - @NotBlank(message = "스타일이 작성되어야 합니다.") - String style -) { -} diff --git a/src/main/java/com/atwoz/member/application/info/style/event/StyleUpdatedEvent.java b/src/main/java/com/atwoz/member/application/info/style/event/StyleUpdatedEvent.java deleted file mode 100644 index 51d2d30c..00000000 --- a/src/main/java/com/atwoz/member/application/info/style/event/StyleUpdatedEvent.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.atwoz.member.application.info.style.event; - -import com.atwoz.global.event.Event; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import java.util.List; - -@Getter -@RequiredArgsConstructor -public class StyleUpdatedEvent extends Event { - - private final Long memberId; - private final List styleCodes; -} diff --git a/src/main/java/com/atwoz/member/application/info/style/event/StyleWroteEvent.java b/src/main/java/com/atwoz/member/application/info/style/event/StyleWroteEvent.java deleted file mode 100644 index 82fcb9a9..00000000 --- a/src/main/java/com/atwoz/member/application/info/style/event/StyleWroteEvent.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.atwoz.member.application.info.style.event; - -import com.atwoz.global.event.Event; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import java.util.List; - -@Getter -@RequiredArgsConstructor -public class StyleWroteEvent extends Event { - - private final Long memberId; - private final List styleCodes; -} diff --git a/src/main/java/com/atwoz/member/application/member/MemberEventHandler.java b/src/main/java/com/atwoz/member/application/member/MemberEventHandler.java index 8aabd68e..e80307b9 100644 --- a/src/main/java/com/atwoz/member/application/member/MemberEventHandler.java +++ b/src/main/java/com/atwoz/member/application/member/MemberEventHandler.java @@ -13,6 +13,7 @@ public class MemberEventHandler { @EventListener public void registerIfNotMemberExist(final ValidatedLoginEvent event) { - memberService.create(event.getEmail(), event.getNickname()); + memberService.create(event.getPhoneNumber()); } } + diff --git a/src/main/java/com/atwoz/member/application/member/MemberService.java b/src/main/java/com/atwoz/member/application/member/MemberService.java index 3e1115ea..1095750d 100644 --- a/src/main/java/com/atwoz/member/application/member/MemberService.java +++ b/src/main/java/com/atwoz/member/application/member/MemberService.java @@ -1,21 +1,92 @@ 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; +import com.atwoz.member.domain.member.dto.MemberProfileDto; +import com.atwoz.member.domain.member.profile.physical.YearManager; +import com.atwoz.member.exception.exceptions.member.MemberAlreadyExistedException; +import com.atwoz.member.exception.exceptions.member.MemberNicknameAlreadyExistedException; +import com.atwoz.member.exception.exceptions.member.MemberNotFoundException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @RequiredArgsConstructor @Service +@Transactional public class MemberService { private final MemberRepository memberRepository; + private final YearManager yearManager; - @Transactional - public void create(final String email, final String nickname) { - if (!memberRepository.existsByEmail(email)) { - memberRepository.save(Member.createWithOAuthLogin(email, nickname)); + public void create(final String phoneNumber) { + if (memberRepository.existsByPhoneNumber(phoneNumber)) { + throw new MemberAlreadyExistedException(); + } + + 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( + memberInitializeRequest.profileInitializeRequest(), yearManager); + validateNicknameIsUnique(memberInitializeRequest.nickname()); + Long foundRecommenderId = findRecommenderIdByNicknameOrNull(memberInitializeRequest.recommender()); + foundMember.initializeWith(memberInitializeRequest.nickname(), foundRecommenderId, memberProfileDto); + } + + private Member findMemberById(final Long memberId) { + return memberRepository.findById(memberId) + .orElseThrow(MemberNotFoundException::new); + } + + private Long findRecommenderIdByNicknameOrNull(final String nickname) { + if (nickname == null || nickname.isBlank()) { + return null; + } + + return memberRepository.findByNickname(nickname) + .orElseThrow(MemberNotFoundException::new) + .getId(); + } + + public void updateMember(final Long memberId, final MemberUpdateRequest memberUpdateRequest) { + Member foundMember = findMemberById(memberId); + MemberProfileDto memberProfileDto = MemberProfileDto.createWith(memberUpdateRequest.profileUpdateRequest(), + yearManager); + validateUpdateNickname(memberUpdateRequest.nickname(), foundMember); + foundMember.updateWith(memberUpdateRequest.nickname(), memberProfileDto); + } + + private void validateUpdateNickname(final String nickname, final Member foundMember) { + if (!nickname.equals(foundMember.getNickname())) { + validateNicknameIsUnique(nickname); + } + } + + public void deleteMember(final Long memberId) { + checkMemberExists(memberId); + memberRepository.deleteById(memberId); + } + + private void checkMemberExists(final Long memberId) { + if (!memberRepository.existsById(memberId)) { + throw new MemberNotFoundException(); } } } diff --git a/src/main/java/com/atwoz/member/application/member/dto/HobbiesRequest.java b/src/main/java/com/atwoz/member/application/member/dto/HobbiesRequest.java new file mode 100644 index 00000000..6bbdcb45 --- /dev/null +++ b/src/main/java/com/atwoz/member/application/member/dto/HobbiesRequest.java @@ -0,0 +1,10 @@ +package com.atwoz.member.application.member.dto; + +import jakarta.validation.constraints.NotEmpty; +import java.util.List; + +public record HobbiesRequest( + @NotEmpty(message = "취미 정보를 입력해주세요.") + List hobbies +) { +} diff --git a/src/main/java/com/atwoz/member/application/member/dto/MemberInitializeRequest.java b/src/main/java/com/atwoz/member/application/member/dto/MemberInitializeRequest.java new file mode 100644 index 00000000..433f731a --- /dev/null +++ b/src/main/java/com/atwoz/member/application/member/dto/MemberInitializeRequest.java @@ -0,0 +1,18 @@ +package com.atwoz.member.application.member.dto; + +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; + +public record MemberInitializeRequest( + @Valid + @NotNull(message = "프로필 정보를 입력해주세요") + ProfileInitializeRequest profileInitializeRequest, + + @NotBlank(message = "닉네입을 입력해주세요.") + String nickname, + + String recommender +) { +} + diff --git a/src/main/java/com/atwoz/member/application/member/dto/MemberNicknameRequest.java b/src/main/java/com/atwoz/member/application/member/dto/MemberNicknameRequest.java new file mode 100644 index 00000000..169f4c24 --- /dev/null +++ b/src/main/java/com/atwoz/member/application/member/dto/MemberNicknameRequest.java @@ -0,0 +1,9 @@ +package com.atwoz.member.application.member.dto; + +import jakarta.validation.constraints.NotBlank; + +public record MemberNicknameRequest( + @NotBlank(message = "닉네임을 입력해주세요.") + String nickname +){ +} diff --git a/src/main/java/com/atwoz/member/application/member/dto/MemberUpdateRequest.java b/src/main/java/com/atwoz/member/application/member/dto/MemberUpdateRequest.java new file mode 100644 index 00000000..1e041359 --- /dev/null +++ b/src/main/java/com/atwoz/member/application/member/dto/MemberUpdateRequest.java @@ -0,0 +1,15 @@ +package com.atwoz.member.application.member.dto; + +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; + +public record MemberUpdateRequest( + @Valid + @NotNull(message = "프로필 정보를 입력해주세요.") + ProfileUpdateRequest profileUpdateRequest, + + @NotBlank(message = "닉네입을 입력해주세요.") + String nickname +) { +} diff --git a/src/main/java/com/atwoz/member/application/member/dto/ProfileInitializeRequest.java b/src/main/java/com/atwoz/member/application/member/dto/ProfileInitializeRequest.java new file mode 100644 index 00000000..02992e3e --- /dev/null +++ b/src/main/java/com/atwoz/member/application/member/dto/ProfileInitializeRequest.java @@ -0,0 +1,46 @@ +package com.atwoz.member.application.member.dto; + +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; + +public record ProfileInitializeRequest( + @NotNull(message = "출생년도를 작성해주세요.") + Integer birthYear, + + @NotNull(message = "키를 입력해주세요.") + Integer height, + + @NotBlank(message = "거주하고 있는 광역시/도를 입력해주세요.") + String city, + + @NotBlank(message = "거주하고 있는 시/군/자치구 입력해주세요.") + String sector, + + @NotBlank(message = "직업을 입력해주세요.") + String job, + + @NotBlank(message = "최종학력 정보를 입력해주세요.") + String graduate, + + @NotBlank(message = "음주 정보를 입력해주세요.") + String drink, + + @NotBlank(message = "흡연을 입력해주세요.") + String smoke, + + @NotBlank(message = "종교 정보를 입력해주세요.") + String religion, + + @NotBlank(message = "mbti를 입력해주세요.") + String mbti, + + @Valid + @NotNull(message = "취미 정보를 입력해주세요.") + HobbiesRequest hobbiesRequest, + + @Valid + @NotNull(message = "스타일 정보를 입력해주세요.") + StylesRequest stylesRequest +) { +} diff --git a/src/main/java/com/atwoz/member/application/member/dto/ProfileUpdateRequest.java b/src/main/java/com/atwoz/member/application/member/dto/ProfileUpdateRequest.java new file mode 100644 index 00000000..079d68c6 --- /dev/null +++ b/src/main/java/com/atwoz/member/application/member/dto/ProfileUpdateRequest.java @@ -0,0 +1,46 @@ +package com.atwoz.member.application.member.dto; + +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; + +public record ProfileUpdateRequest( + @NotNull(message = "출생년도를 작성해주세요.") + Integer birthYear, + + @NotNull(message = "키를 입력해주세요.") + Integer height, + + @NotBlank(message = "거주하고 있는 광역시/도를 입력해주세요.") + String city, + + @NotBlank(message = "거주하고 있는 시/군/자치구 입력해주세요.") + String sector, + + @NotBlank(message = "직업을 입력해주세요.") + String job, + + @NotBlank(message = "최종학력 정보를 입력해주세요.") + String graduate, + + @NotBlank(message = "음주 정보를 입력해주세요.") + String drink, + + @NotBlank(message = "흡연을 입력해주세요.") + String smoke, + + @NotBlank(message = "종교 정보를 입력해주세요.") + String religion, + + @NotBlank(message = "mbti를 입력해주세요.") + String mbti, + + @Valid + @NotNull(message = "취미 정보를 입력해주세요.") + HobbiesRequest hobbiesRequest, + + @Valid + @NotNull(message = "스타일 정보를 입력해주세요") + StylesRequest stylesRequest +) { +} diff --git a/src/main/java/com/atwoz/member/application/member/dto/StylesRequest.java b/src/main/java/com/atwoz/member/application/member/dto/StylesRequest.java new file mode 100644 index 00000000..0a17876d --- /dev/null +++ b/src/main/java/com/atwoz/member/application/member/dto/StylesRequest.java @@ -0,0 +1,10 @@ +package com.atwoz.member.application.member.dto; + +import jakarta.validation.constraints.NotEmpty; +import java.util.List; + +public record StylesRequest( + @NotEmpty(message = "스타일 정보를 입력해주세요.") + List styles +) { +} diff --git a/src/main/java/com/atwoz/member/config/AuthConfig.java b/src/main/java/com/atwoz/member/config/AuthConfig.java index 7dd45024..57ee1756 100644 --- a/src/main/java/com/atwoz/member/config/AuthConfig.java +++ b/src/main/java/com/atwoz/member/config/AuthConfig.java @@ -3,7 +3,9 @@ import com.atwoz.member.ui.auth.interceptor.LoginValidCheckerInterceptor; import com.atwoz.member.ui.auth.interceptor.ParseMemberIdFromTokenInterceptor; import com.atwoz.member.ui.auth.interceptor.PathMatcherInterceptor; +import com.atwoz.member.ui.auth.interceptor.TokenRegenerateInterceptor; import com.atwoz.member.ui.auth.support.resolver.AuthArgumentResolver; +import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Configuration; import org.springframework.web.method.support.HandlerMethodArgumentResolver; @@ -11,7 +13,6 @@ import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; -import java.util.List; import static com.atwoz.member.ui.auth.interceptor.HttpMethod.DELETE; import static com.atwoz.member.ui.auth.interceptor.HttpMethod.GET; import static com.atwoz.member.ui.auth.interceptor.HttpMethod.OPTIONS; @@ -25,11 +26,13 @@ public class AuthConfig implements WebMvcConfigurer { private final AuthArgumentResolver authArgumentResolver; private final ParseMemberIdFromTokenInterceptor parseMemberIdFromTokenInterceptor; private final LoginValidCheckerInterceptor loginValidCheckerInterceptor; + private final TokenRegenerateInterceptor tokenRegenerateInterceptor; @Override - public void addInterceptors(InterceptorRegistry registry) { + public void addInterceptors(final InterceptorRegistry registry) { registry.addInterceptor(parseMemberIdFromTokenInterceptor()); registry.addInterceptor(loginValidCheckerInterceptor()); + registry.addInterceptor(tokenRegenerateInterceptor()); } private HandlerInterceptor parseMemberIdFromTokenInterceptor() { @@ -40,13 +43,19 @@ private HandlerInterceptor parseMemberIdFromTokenInterceptor() { } /** - * @AuthMember를 통해서 인증이 필요한 경우에 해당 메서드에 URI를 추가해주면 된다. - * 추가를 해야지 인증,인가 가능 + * @AuthMember를 통해서 인증이 필요한 경우에 해당 메서드에 URI를 추가해주면 된다. 추가를 해야지 인증,인가 가능 */ private HandlerInterceptor loginValidCheckerInterceptor() { return new PathMatcherInterceptor(loginValidCheckerInterceptor) .excludePathPattern("/**", OPTIONS) - .excludePathPattern("/api/missions/**", GET, POST, PATCH, DELETE); + .excludePathPattern("/api/missions/**", GET, POST, PATCH, DELETE) + .addPathPatterns("/api/members/**", GET, POST, PATCH, DELETE); + } + + private HandlerInterceptor tokenRegenerateInterceptor() { + return new PathMatcherInterceptor(tokenRegenerateInterceptor) + .excludePathPattern("/**", OPTIONS) + .addPathPatterns("/api/auth/login", POST); } @Override diff --git a/src/main/java/com/atwoz/member/domain/auth/JsonMapper.java b/src/main/java/com/atwoz/member/domain/auth/JsonMapper.java index d9e69e2d..d7280e0b 100644 --- a/src/main/java/com/atwoz/member/domain/auth/JsonMapper.java +++ b/src/main/java/com/atwoz/member/domain/auth/JsonMapper.java @@ -5,8 +5,10 @@ public interface JsonMapper { - String getValueByKey(final String json, final String key); + String getValueByKey(String json, String key); - MemberInfoResponse extractMemberInfoFrom(final String memberInfoResponse, - final MemberInfoKeyWordRequest memberInfoKeyWordRequest); + MemberInfoResponse extractMemberInfoFrom(String memberInfoResponse, + MemberInfoKeyWordRequest memberInfoKeyWordRequest); + + byte[] convertObjectToJsonByteArray(Object object); } diff --git a/src/main/java/com/atwoz/member/domain/auth/OAuthConnectionManager.java b/src/main/java/com/atwoz/member/domain/auth/OAuthConnectionManager.java index 343def15..e7baa81d 100644 --- a/src/main/java/com/atwoz/member/domain/auth/OAuthConnectionManager.java +++ b/src/main/java/com/atwoz/member/domain/auth/OAuthConnectionManager.java @@ -4,7 +4,7 @@ public interface OAuthConnectionManager { - String getAccessTokenResponse (final OAuthProviderRequest oAuthProviderRequest, final String code); + String getAccessTokenResponse (OAuthProviderRequest oAuthProviderRequest, String code); - String getMemberInfoResponse(final String accessToken, final String userInfoUrl); + String getMemberInfoResponse(String accessToken, String userInfoUrl); } diff --git a/src/main/java/com/atwoz/member/domain/auth/TokenProvider.java b/src/main/java/com/atwoz/member/domain/auth/TokenProvider.java index e91a2b2c..e5e27192 100644 --- a/src/main/java/com/atwoz/member/domain/auth/TokenProvider.java +++ b/src/main/java/com/atwoz/member/domain/auth/TokenProvider.java @@ -2,7 +2,9 @@ public interface TokenProvider { - String createTokenWith(final String email); + String createTokenWithId(Long id); - String extract(final String token); + String createTokenWithPhoneNumber(String phoneNumber); + + T extract(String token, String claimName, Class classType); } diff --git a/src/main/java/com/atwoz/member/domain/info/InfoRepository.java b/src/main/java/com/atwoz/member/domain/info/InfoRepository.java deleted file mode 100644 index 66e6a47e..00000000 --- a/src/main/java/com/atwoz/member/domain/info/InfoRepository.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.atwoz.member.domain.info; - -import com.atwoz.member.infrastructure.info.dto.InfoSearchResponse; -import java.util.Optional; - -public interface InfoRepository { - - Optional findByMemberId(final Long memberId); -} diff --git a/src/main/java/com/atwoz/member/domain/info/hobby/MemberHobby.java b/src/main/java/com/atwoz/member/domain/info/hobby/MemberHobby.java deleted file mode 100644 index ff1e387f..00000000 --- a/src/main/java/com/atwoz/member/domain/info/hobby/MemberHobby.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.atwoz.member.domain.info.hobby; - -import jakarta.persistence.Column; -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 jakarta.persistence.Table; -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Getter -@EqualsAndHashCode(exclude = "id") -@Table(name = "member_hobbies") -@AllArgsConstructor(access = AccessLevel.PRIVATE) -@NoArgsConstructor(access = AccessLevel.PROTECTED) -@Builder -@Entity -public class MemberHobby { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @Column(nullable = false) - private Long memberId; - - @Column(nullable = false) - @Enumerated(value = EnumType.STRING) - private Hobby hobby; - - public MemberHobby(final Long memberId, final Hobby hobby) { - this.memberId = memberId; - this.hobby = hobby; - } -} diff --git a/src/main/java/com/atwoz/member/domain/info/hobby/MemberHobbyRepository.java b/src/main/java/com/atwoz/member/domain/info/hobby/MemberHobbyRepository.java deleted file mode 100644 index 195ad6e9..00000000 --- a/src/main/java/com/atwoz/member/domain/info/hobby/MemberHobbyRepository.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.atwoz.member.domain.info.hobby; - -import java.util.List; - -public interface MemberHobbyRepository { - - void save(final MemberHobby memberHobby); - void saveAll(final List memberHobbies); - void deleteHobbiesByMemberId(final Long memberId); - List findAllByMemberId(final Long memberId); -} diff --git a/src/main/java/com/atwoz/member/domain/info/option/Option.java b/src/main/java/com/atwoz/member/domain/info/option/Option.java deleted file mode 100644 index 7e6f0e78..00000000 --- a/src/main/java/com/atwoz/member/domain/info/option/Option.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.atwoz.member.domain.info.option; - -import com.atwoz.member.domain.info.option.dto.InnerOptionUpdateRequest; -import com.atwoz.member.domain.info.option.dto.InnerOptionWriteRequest; -import jakarta.persistence.Column; -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 jakarta.persistence.Table; -import lombok.AccessLevel; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Getter -@EqualsAndHashCode(exclude = "id") -@Table(name = "member_option") -@NoArgsConstructor(access = AccessLevel.PROTECTED) -@Entity -public class Option { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @Column(nullable = false) - private Long memberId; - - @Column(nullable = false) - @Enumerated(value = EnumType.STRING) - private Smoke smoke; - - @Column(nullable = false) - @Enumerated(value = EnumType.STRING) - private Religion religion; - - @Column(nullable = false) - @Enumerated(value = EnumType.STRING) - private Drink drink; - - @Column(nullable = false) - @Enumerated(value = EnumType.STRING) - private Mbti mbti; - - @Column(nullable = false) - @Enumerated(value = EnumType.STRING) - private Graduate graduate; - - public Option(final Long memberId, - final Smoke smoke, - final Religion religion, - final Drink drink, - final Mbti mbti, - final Graduate graduate) { - this.memberId = memberId; - this.smoke = smoke; - this.religion = religion; - this.drink = drink; - this.mbti = mbti; - this.graduate = graduate; - } - - public static Option createFrom(final InnerOptionWriteRequest request) { - return new Option( - request.memberId(), - Smoke.findByName(request.smokeName()), - Religion.findByName(request.religionName()), - Drink.findByName(request.drinkName()), - Mbti.findByName(request.mbtiName()), - Graduate.findByName(request.graduateName()) - ); - } - - public void updateContentsFrom(final InnerOptionUpdateRequest request) { - this.smoke = Smoke.findByName(request.smokeName()); - this.religion = Religion.findByName(request.religionName()); - this.drink = Drink.findByName(request.drinkName()); - this.mbti = Mbti.findByName(request.mbtiName()); - this.graduate = Graduate.findByName(request.graduateName()); - } -} diff --git a/src/main/java/com/atwoz/member/domain/info/option/OptionRepository.java b/src/main/java/com/atwoz/member/domain/info/option/OptionRepository.java deleted file mode 100644 index 6d337de8..00000000 --- a/src/main/java/com/atwoz/member/domain/info/option/OptionRepository.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.atwoz.member.domain.info.option; - -import java.util.Optional; - -public interface OptionRepository { - - void save(final Option option); - Optional