Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: 회의 진행 후 변경된 요구사항 반영 #74

Merged
merged 11 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions src/docs/asciidoc/selfIntro.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,6 @@ include::{snippets}/self-intro-controller-web-mvc-test/셀프_소개글_저장/r
==== 응답
include::{snippets}/self-intro-controller-web-mvc-test/셀프_소개글_저장/http-response.adoc[]


=== 셀프 소개글 페이징 조회 (GET /api/members/self-intros)

==== 요청
include::{snippets}/self-intro-controller-web-mvc-test/셀프_소개글_페이징_조회/http-request.adoc[]
include::{snippets}/self-intro-controller-web-mvc-test/셀프_소개글_페이징_조회/request-headers.adoc[]
include::{snippets}/self-intro-controller-web-mvc-test/셀프_소개글_페이징_조회/request-parts.adoc[]

==== 응답
include::{snippets}/self-intro-controller-web-mvc-test/셀프_소개글_페이징_조회/http-response.adoc[]
include::{snippets}/self-intro-controller-web-mvc-test/셀프_소개글_페이징_조회/response-fields.adoc[]


=== 셀프 소개글 페이징 조회 (필터 적용) (Get /api/members/self-intros/filter)

==== 요청
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.atwoz.alert.application.event.AlertTokenCreatedEvent;
import com.atwoz.global.event.Events;
import com.atwoz.member.application.auth.dto.LoginRequest;
import com.atwoz.member.application.auth.dto.TestLoginRequest;
import com.atwoz.member.domain.auth.MemberTokenProvider;
import com.atwoz.member.domain.member.Member;
import com.atwoz.member.domain.member.MemberRepository;
Expand All @@ -14,6 +15,7 @@

@RequiredArgsConstructor
@Service
@Transactional
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저희 그동안 Service를 가장 아래로 하고 그 위에 Transactional을 붙이기로 했던 것 같습니다 :)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네 수정하겠습니다!

public class MemberAuthService {

private static final String DEFAULT_PHONE_NUMBER = "01011111111";
Expand All @@ -25,7 +27,6 @@ public class MemberAuthService {
/**
* OAuth 인증방식과 PASS 인증 방식에 차이가 존재해서 회의 후 메서드 변경을 진행할 예정
*/
@Transactional
public String login(final LoginRequest request, final OAuthProviderRequest provider) {
String accessToken = oAuthRequester.getAccessToken(request.code(), provider);
MemberInfoResponse memberInfoResponse = oAuthRequester.getMemberInfo(accessToken, provider);
Expand All @@ -36,4 +37,12 @@ public String login(final LoginRequest request, final OAuthProviderRequest provi

return memberTokenProvider.createAccessToken(createdMember.getId());
}

//TODO: test를 위해 임시로 구현한 메서드입니다. 나중에 삭제해야합니다.
public String testLogin(final TestLoginRequest request) {
Member member = Member.createWithOAuth(request.phoneNumber());
memberRepository.save(member);

return memberTokenProvider.createAccessToken(member.getId());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.atwoz.member.application.auth.dto;

//TODO 잠깐 테스트 용도로 로그인을 허용하기 위해 만든 dto입니다. 나중에 삭제해야합니다.
public record TestLoginRequest(
String phoneNumber
) {
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.atwoz.member.application.member.profile.hobby;

import com.atwoz.global.application.BaseQueryService;
import com.atwoz.member.application.member.profile.hobby.dto.HobbyResponses;
import com.atwoz.member.application.member.profile.hobby.dto.HobbyPagingResponses;
import com.atwoz.member.domain.member.profile.Hobby;
import com.atwoz.member.domain.member.profile.HobbyRepository;
import com.atwoz.member.exception.exceptions.member.profile.hobby.HobbyNotFoundException;
import com.atwoz.member.infrastructure.member.profile.hobby.dto.HobbyResponse;
import com.atwoz.member.infrastructure.member.profile.hobby.dto.HobbyPagingResponse;
import com.atwoz.member.infrastructure.member.profile.hobby.dto.HobbySingleResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand All @@ -15,24 +16,24 @@
@RequiredArgsConstructor
@Service
@Transactional(readOnly = true)
public class HobbyQueryService extends BaseQueryService<HobbyResponse> {
public class HobbyQueryService extends BaseQueryService<HobbyPagingResponse> {

private final HobbyRepository hobbyRepository;

public HobbyResponse findHobby(final Long hobbyId) {
public HobbySingleResponse findHobby(final Long hobbyId) {
Hobby foundHobby = findMemberHobbyById(hobbyId);
return HobbyResponse.from(foundHobby);
return HobbySingleResponse.from(foundHobby);
}

private Hobby findMemberHobbyById(final Long hobbyId) {
return hobbyRepository.findHobbyById(hobbyId)
.orElseThrow(HobbyNotFoundException::new);
}

public HobbyResponses findHobbiesWithPaging(final Pageable pageable) {
Page<HobbyResponse> hobbyResponses = hobbyRepository.findHobbiesWithPaging(pageable);
public HobbyPagingResponses findHobbiesWithPaging(final Pageable pageable) {
Page<HobbyPagingResponse> hobbyResponses = hobbyRepository.findHobbiesWithPaging(pageable);
int nextPage = getNextPage(pageable.getPageNumber(), hobbyResponses);

return HobbyResponses.of(hobbyResponses, pageable, nextPage);
return HobbyPagingResponses.of(hobbyResponses, pageable, nextPage);
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.atwoz.member.application.member.profile.hobby.dto;

import com.atwoz.member.infrastructure.member.profile.hobby.dto.HobbyResponse;
import com.atwoz.member.infrastructure.member.profile.hobby.dto.HobbyPagingResponse;
import java.util.List;
import lombok.Builder;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

@Builder
public record HobbyResponses(
List<HobbyResponse> hobbyResponses,
public record HobbyPagingResponses(
List<HobbyPagingResponse> hobbyPagingResponses,
int nowPage,
int nextPage,
int totalPages,
Expand All @@ -18,13 +18,13 @@ public record HobbyResponses(
private static final int NEXT_PAGE = 1;
private static final int NO_MORE_PAGE = -1;

public static HobbyResponses of(
final Page<HobbyResponse> hobbyResponses,
public static HobbyPagingResponses of(
final Page<HobbyPagingResponse> hobbyResponses,
final Pageable pageable,
final int nextPage
) {
return HobbyResponses.builder()
.hobbyResponses(hobbyResponses.getContent())
return HobbyPagingResponses.builder()
.hobbyPagingResponses(hobbyResponses.getContent())
.nowPage(pageable.getPageNumber())
.nextPage(nextPage)
.totalPages(hobbyResponses.getTotalPages())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.atwoz.member.application.member.profile.style;

import com.atwoz.global.application.BaseQueryService;
import com.atwoz.member.application.member.profile.style.dto.StyleResponses;
import com.atwoz.member.application.member.profile.style.dto.StylePagingResponses;
import com.atwoz.member.domain.member.profile.Style;
import com.atwoz.member.domain.member.profile.StyleRepository;
import com.atwoz.member.exception.exceptions.member.profile.style.StyleNotFoundException;
import com.atwoz.member.infrastructure.member.profile.style.dto.StyleResponse;
import com.atwoz.member.infrastructure.member.profile.style.dto.StylePagingResponse;
import com.atwoz.member.infrastructure.member.profile.style.dto.StyleSingleResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand All @@ -15,23 +16,23 @@
@RequiredArgsConstructor
@Service
@Transactional(readOnly = true)
public class StyleQueryService extends BaseQueryService<StyleResponse> {
public class StyleQueryService extends BaseQueryService<StylePagingResponse> {

private final StyleRepository styleRepository;

public StyleResponse findStyle(final Long styleId) {
public StyleSingleResponse findStyle(final Long styleId) {
Style foundStyle = findStyleById(styleId);
return StyleResponse.from(foundStyle);
return StyleSingleResponse.from(foundStyle);
}

private Style findStyleById(final Long styleId) {
return styleRepository.findStyleById(styleId)
.orElseThrow(StyleNotFoundException::new);
}

public StyleResponses findStylesWithPaging(final Pageable pageable) {
Page<StyleResponse> styleResponses = styleRepository.findStylesWithPaging(pageable);
public StylePagingResponses findStylesWithPaging(final Pageable pageable) {
Page<StylePagingResponse> styleResponses = styleRepository.findStylesWithPaging(pageable);
int nextPage = getNextPage(pageable.getPageNumber(), styleResponses);
return StyleResponses.of(styleResponses, pageable, nextPage);
return StylePagingResponses.of(styleResponses, pageable, nextPage);
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.atwoz.member.application.member.profile.style.dto;

import com.atwoz.member.infrastructure.member.profile.style.dto.StyleResponse;
import com.atwoz.member.infrastructure.member.profile.style.dto.StylePagingResponse;
import java.util.List;
import lombok.Builder;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

@Builder
public record StyleResponses(
List<StyleResponse> styleResponses,
public record StylePagingResponses(
List<StylePagingResponse> stylePagingResponses,
int nowPage,
int nextPage,
int totalPages,
Expand All @@ -18,13 +18,13 @@ public record StyleResponses(
private static final int NEXT_PAGE = 1;
private static final int NO_MORE_PAGE = -1;

public static StyleResponses of(
final Page<StyleResponse> styleResponses,
public static StylePagingResponses of(
final Page<StylePagingResponse> styleResponses,
final Pageable pageable,
final int nextPage
) {
return StyleResponses.builder()
.styleResponses(styleResponses.getContent())
return StylePagingResponses.builder()
.stylePagingResponses(styleResponses.getContent())
.nowPage(pageable.getPageNumber())
.nextPage(nextPage)
.totalPages(styleResponses.getTotalPages())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ public class SelfIntroQueryService extends BaseQueryService<SelfIntroResponse> {

private final SelfIntroRepository selfIntroRepository;

public SelfIntroResponses findAllSelfIntrosWithPaging(final Pageable pageable) {
Page<SelfIntroResponse> selfIntroResponses = selfIntroRepository.findAllSelfIntrosWithPaging(pageable);
int nextPage = getNextPage(pageable.getPageNumber(), selfIntroResponses);
return SelfIntroResponses.of(selfIntroResponses, pageable, nextPage);
}

public SelfIntroResponses findAllSelfIntrosWithPagingAndFiltering(
final Pageable pageable,
final SelfIntroFilterRequest selfIntroFilterRequest,
Expand All @@ -34,7 +28,7 @@ public SelfIntroResponses findAllSelfIntrosWithPagingAndFiltering(
selfIntroFilterRequest.minAge(),
selfIntroFilterRequest.maxAge(),
selfIntroFilterRequest.isOnlyOppositeGender(),
selfIntroFilterRequest.getCities(),
selfIntroFilterRequest.cities(),
memberId
);
int nextPage = getNextPage(pageable.getPageNumber(), selfIntroResponses);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
package com.atwoz.member.application.selfintro.dto;

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import java.util.Collections;
import java.util.List;

public record SelfIntroFilterRequest(

@NotNull(message = "최소 나이를 입력해주세요")
Integer minAge,

@NotNull(message = "최대 나이를 입력해주세요")
Integer maxAge,

@NotNull(message = "성별을 선택해주세요")
Boolean isOnlyOppositeGender,

@Valid
@NotEmpty(message = "선호 지역을 하나 이상 입력해주세요.")
List<CityRequest> cityRequests
List<String> cities
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

혹시 validator를 쓰지 않고 자체 검증만 하시게 된 이유가 있으실까요?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

필터 기능을 사용할 수도 사용하지 않을수도 있기 때문에 validator로 빈 값에 대한 테스트를 하게 되면 필터를 사용하지 않는 요청이 에러로 나가게 됩니다. 필터를 적용한 페이징 기능과 기존의 페이징 기능을 합쳐서 필터를 사용하지 않는 페이징 요청을 처리하기 위해서 dto에서 유효하지 않는 요청에 대해서만 빈 리스트를 넘겨주는 방식으로 구현했습니다.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

필요에 따라 쓸 수도 있고 쓰지 않을 수도 있기 때문이었군요 이해했습니다 :)

) {

public List<String> getCities() {
return cityRequests.stream()
.map(CityRequest::city)
.toList();
public SelfIntroFilterRequest(
final Integer minAge,
final Integer maxAge,
final Boolean isOnlyOppositeGender,
final List<String> cities
) {
this.minAge = minAge;
this.maxAge = maxAge;
this.isOnlyOppositeGender = isOnlyOppositeGender;
this.cities = ensureCities(cities);
}

private List<String> ensureCities(final List<String> cities) {
if (isInvalidCase(cities)) {
return Collections.emptyList();
}
return cities;
}

private boolean isInvalidCase(final List<String> cities) {
return cities == null ||
cities.stream()
.allMatch(city -> city == null || city.isBlank());
}
}
8 changes: 5 additions & 3 deletions src/main/java/com/atwoz/member/domain/member/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@ public static Member createWithPass(final String gender,
.build();
}

public void initializeWith(final String nickname,
final Long recommenderId,
final InternalProfileInitializeRequest internalProfileInitializeRequest) {
public void initializeWith(
final String nickname,
final Long recommenderId,
final InternalProfileInitializeRequest internalProfileInitializeRequest
) {
this.nickname = nickname;
initializeRecommenderId(recommenderId);
memberProfile.initialize(internalProfileInitializeRequest);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.atwoz.member.domain.member.profile;

import com.atwoz.member.infrastructure.member.profile.hobby.dto.HobbyResponse;
import com.atwoz.member.infrastructure.member.profile.hobby.dto.HobbyPagingResponse;
import java.util.Optional;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand All @@ -15,7 +15,7 @@ public interface HobbyRepository {

Optional<Hobby> findHobbyByCode(String hobbyCode);

Page<HobbyResponse> findHobbiesWithPaging(Pageable pageable);
Page<HobbyPagingResponse> findHobbiesWithPaging(Pageable pageable);

void deleteById(Long hobbyId);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.atwoz.member.domain.member.profile;

import com.atwoz.member.infrastructure.member.profile.style.dto.StyleResponse;
import com.atwoz.member.infrastructure.member.profile.style.dto.StylePagingResponse;
import java.util.Optional;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand All @@ -15,7 +15,7 @@ public interface StyleRepository {

Optional<Style> findStyleByCode(String styleCode);

Page<StyleResponse> findStylesWithPaging(Pageable pageable);
Page<StylePagingResponse> findStylesWithPaging(Pageable pageable);

void deleteStyleById(Long styleId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ public interface SelfIntroRepository {

void deleteById(Long id);

Page<SelfIntroResponse> findAllSelfIntrosWithPaging(Pageable pageable);

Page<SelfIntroResponse> findAllSelfIntrosWithPagingAndFiltering(
Pageable pageable,
int minAge,
int maxAge,
boolean isOnlyOppositeGender,
Integer minAge,
Integer maxAge,
Boolean isOnlyOppositeGender,
List<String> cities,
Long memberId
);
Expand Down
Loading
Loading