Skip to content

Commit

Permalink
refactor: 회의 진행 후 변경된 요구사항 반영 (#74)
Browse files Browse the repository at this point in the history
* refactor: 셀프 소개글 페이징 조회 관련 메서드 하나로 통합

* test: 셀프 소개글 api 수정으로 인한 테스트 수

* docs: 셀프 소개글 api 수정으로 인한 문서 수정

* refactor: 취미 페이징 조회 시 조회된 취미 id도 반환하도록 수

* test: 취미 페이징 api 수정으로 인한 테스트 수정

* refactor: 스타일 페이징 조회 시 조회된 스타일의 id 정보도 반환하도록 변

* test: 스타일 페이징 api 변경으로 인한 테스트 수정

* test: 페이징 조회 메서드에서 사용하는 변수명 변경

* refactor: nice 인증으로 진행하는 로그인 기능 개발 전 사용할 테스트용 로그인 구현

* refactor: MemberAuthService 어노테이션 순서 변경

* test: 공백 제거
  • Loading branch information
eom-tae-in authored Sep 25, 2024
1 parent 47bfd1d commit 308576b
Show file tree
Hide file tree
Showing 52 changed files with 493 additions and 498 deletions.
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 @@ -13,6 +14,7 @@
import org.springframework.transaction.annotation.Transactional;

@RequiredArgsConstructor
@Transactional
@Service
public class MemberAuthService {

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
) {

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

0 comments on commit 308576b

Please sign in to comment.