From de8b8d4665f3ffd568aa46a59cf28d00044753ab Mon Sep 17 00:00:00 2001 From: rachel3486 Date: Sat, 25 Feb 2023 20:26:27 +0900 Subject: [PATCH 1/5] style: Modify member oauth field name --- .../auth/service/OAuthKakaoServiceImpl.java | 10 +++++----- .../java/com/ftw/hometerview/member/domain/Member.java | 2 +- .../member/repository/MemberRepository.java | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/ftw/hometerview/auth/service/OAuthKakaoServiceImpl.java b/src/main/java/com/ftw/hometerview/auth/service/OAuthKakaoServiceImpl.java index bacef06..21d589c 100644 --- a/src/main/java/com/ftw/hometerview/auth/service/OAuthKakaoServiceImpl.java +++ b/src/main/java/com/ftw/hometerview/auth/service/OAuthKakaoServiceImpl.java @@ -39,15 +39,15 @@ public Map getMemberInfoByToken(LoginRequest loginRequest) { public LoginResponse login(LoginRequest loginRequest) { // Get user information using Kakao Token Map kakaoAttributes = getMemberInfoByToken(loginRequest); - String memberId = String.valueOf(kakaoAttributes.get("id")); + String oauthId = String.valueOf(kakaoAttributes.get("id")); Map properties = (Map) kakaoAttributes.get("properties"); String nickname = String.valueOf(properties.get("nickname")); - String accessToken = jwtTokenProvider.createAccessToken(memberId); + String accessToken = jwtTokenProvider.createAccessToken(oauthId); String refreshToken = jwtTokenProvider.createRefreshToken(); - // Check if requester are subscribed to the server through requester member ID - Optional member = memberRepository.findByMemberId(memberId); + // Check if requester are subscribed to the server through requester member oauth ID + Optional member = memberRepository.findByOauthId(oauthId); if (member.isPresent()) { ProviderType providerType = member.get().getProviderType(); @@ -58,7 +58,7 @@ public LoginResponse login(LoginRequest loginRequest) { memberRepository.save(member.get()); } else { memberRepository.save(Member.builder() - .memberId(memberId) + .oauthId(oauthId) .providerType(ProviderType.KAKAO) .refreshToken(refreshToken) .nickname(nickname) diff --git a/src/main/java/com/ftw/hometerview/member/domain/Member.java b/src/main/java/com/ftw/hometerview/member/domain/Member.java index 8606bf2..32fd841 100644 --- a/src/main/java/com/ftw/hometerview/member/domain/Member.java +++ b/src/main/java/com/ftw/hometerview/member/domain/Member.java @@ -19,7 +19,7 @@ public class Member extends AbstractDocument { @MongoId(FieldType.OBJECT_ID) String id; - String memberId; + String oauthId; String nickname; diff --git a/src/main/java/com/ftw/hometerview/member/repository/MemberRepository.java b/src/main/java/com/ftw/hometerview/member/repository/MemberRepository.java index 05a3da3..e10cccb 100644 --- a/src/main/java/com/ftw/hometerview/member/repository/MemberRepository.java +++ b/src/main/java/com/ftw/hometerview/member/repository/MemberRepository.java @@ -8,5 +8,5 @@ @Repository public interface MemberRepository extends MongoRepository { - Optional findByMemberId(String memberId); + Optional findByOauthId(String oauthId); } From 1a108ea441718afd9ff6fb2f0762e7ecd7b25347 Mon Sep 17 00:00:00 2001 From: rachel3486 Date: Sat, 25 Feb 2023 20:29:52 +0900 Subject: [PATCH 2/5] feat: Add memboer info API --- .../member/controller/MemberController.java | 25 ++++++++++++++++ .../member/controller/dto/MemberDto.java | 26 +++++++++++++++++ .../ftw/hometerview/member/domain/Member.java | 5 +++- .../member/service/MemberService.java | 22 ++++++++++++++ .../member/service/MemberServiceFacade.java | 29 +++++++++++++++++++ .../place/controller/dto/PlaceDto.java | 25 ++++++++++++++++ .../place/service/PlaceServiceFacade.java | 8 +++++ 7 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/ftw/hometerview/member/controller/MemberController.java create mode 100644 src/main/java/com/ftw/hometerview/member/controller/dto/MemberDto.java create mode 100644 src/main/java/com/ftw/hometerview/member/service/MemberService.java create mode 100644 src/main/java/com/ftw/hometerview/member/service/MemberServiceFacade.java diff --git a/src/main/java/com/ftw/hometerview/member/controller/MemberController.java b/src/main/java/com/ftw/hometerview/member/controller/MemberController.java new file mode 100644 index 0000000..bb0a261 --- /dev/null +++ b/src/main/java/com/ftw/hometerview/member/controller/MemberController.java @@ -0,0 +1,25 @@ +package com.ftw.hometerview.member.controller; + +import com.ftw.hometerview.core.domain.ResponseEntity; +import com.ftw.hometerview.core.interceptor.AuthUtil; +import com.ftw.hometerview.member.controller.dto.MemberDto; +import com.ftw.hometerview.member.service.MemberServiceFacade; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RequiredArgsConstructor +@RestController +@RequestMapping("api/v1/member") +public class MemberController { + + private final MemberServiceFacade memberService; + + @GetMapping("/my") + public ResponseEntity getLoginMemberInfo() { + var memberInfo = this.memberService.getMemberInfo(AuthUtil.getCurrentMemberId()); + return ResponseEntity.successResponse(memberInfo); + } + +} diff --git a/src/main/java/com/ftw/hometerview/member/controller/dto/MemberDto.java b/src/main/java/com/ftw/hometerview/member/controller/dto/MemberDto.java new file mode 100644 index 0000000..889f73b --- /dev/null +++ b/src/main/java/com/ftw/hometerview/member/controller/dto/MemberDto.java @@ -0,0 +1,26 @@ +package com.ftw.hometerview.member.controller.dto; + +import com.ftw.hometerview.member.domain.Member; +import com.ftw.hometerview.member.domain.Member.Certification; +import com.ftw.hometerview.place.controller.dto.PlaceDto.CompanyDetail; +import lombok.Builder; + +@Builder +public class MemberDto { + + String id; + String nickname; + Certification certification; + CompanyDetail companyDetail; + + + public static MemberDto of(Member member, CompanyDetail companyDetail) { + return MemberDto.builder() + .id(member.getId()) + .nickname(member.getNickname()) + .certification(member.getCertification()) + .companyDetail(companyDetail) + .build(); + } + +} diff --git a/src/main/java/com/ftw/hometerview/member/domain/Member.java b/src/main/java/com/ftw/hometerview/member/domain/Member.java index 32fd841..2719d95 100644 --- a/src/main/java/com/ftw/hometerview/member/domain/Member.java +++ b/src/main/java/com/ftw/hometerview/member/domain/Member.java @@ -27,9 +27,12 @@ public class Member extends AbstractDocument { Certification certification; + String companyId; + String refreshToken; - private class Certification { + public static class Certification { + String locationCode; // 지역 코드 Boolean isPostedReview; // 리뷰를 작성했는지에 대한 여부 } diff --git a/src/main/java/com/ftw/hometerview/member/service/MemberService.java b/src/main/java/com/ftw/hometerview/member/service/MemberService.java new file mode 100644 index 0000000..b788dcc --- /dev/null +++ b/src/main/java/com/ftw/hometerview/member/service/MemberService.java @@ -0,0 +1,22 @@ +package com.ftw.hometerview.member.service; + +import com.ftw.hometerview.core.domain.ResponseType; +import com.ftw.hometerview.core.exception.NotFoundException; +import com.ftw.hometerview.member.domain.Member; +import com.ftw.hometerview.member.repository.MemberRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@RequiredArgsConstructor +@Service +public class MemberService { + + private final MemberRepository memberRepository; + + public Member getMemberById(String memberId) { + return this.memberRepository.findById(memberId) + .orElseThrow(() -> new NotFoundException(ResponseType.MEMBER_NOT_EXIST_ID)); + + } + +} diff --git a/src/main/java/com/ftw/hometerview/member/service/MemberServiceFacade.java b/src/main/java/com/ftw/hometerview/member/service/MemberServiceFacade.java new file mode 100644 index 0000000..9302422 --- /dev/null +++ b/src/main/java/com/ftw/hometerview/member/service/MemberServiceFacade.java @@ -0,0 +1,29 @@ +package com.ftw.hometerview.member.service; + + +import com.ftw.hometerview.member.controller.dto.MemberDto; +import com.ftw.hometerview.member.domain.Member; +import com.ftw.hometerview.place.controller.dto.PlaceDto; +import com.ftw.hometerview.place.controller.dto.PlaceDto.CompanyDetail; +import com.ftw.hometerview.place.service.PlaceServiceFacade; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@RequiredArgsConstructor +@Service +public class MemberServiceFacade { + + private final PlaceServiceFacade placeService; + private final MemberService memberService; + + + public MemberDto getMemberInfo(String memberId) { + Member member = this.memberService.getMemberById(memberId); + PlaceDto.CompanyDetail companyDetail = new CompanyDetail(); + if (member.getCompanyId().isEmpty()) { + companyDetail = placeService.getCompanyDetail(member.getCompanyId()); + } + return MemberDto.of(member, companyDetail); + } + +} diff --git a/src/main/java/com/ftw/hometerview/place/controller/dto/PlaceDto.java b/src/main/java/com/ftw/hometerview/place/controller/dto/PlaceDto.java index c39034d..98073b0 100644 --- a/src/main/java/com/ftw/hometerview/place/controller/dto/PlaceDto.java +++ b/src/main/java/com/ftw/hometerview/place/controller/dto/PlaceDto.java @@ -1,11 +1,14 @@ package com.ftw.hometerview.place.controller.dto; import com.ftw.hometerview.place.controller.dto.CompanyDto.Meta; +import com.ftw.hometerview.place.domain.Company; +import com.ftw.hometerview.place.domain.Station; import java.util.Collections; import java.util.List; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; +import lombok.NoArgsConstructor; public class PlaceDto { @@ -25,4 +28,26 @@ public SearchResult(List companies) { } } + @Getter + @NoArgsConstructor + public static class CompanyDetail { + + String companyId; + String companyName; + String roadAddress; + String province; + String stationId; + String stationName; + + public CompanyDetail(Company company, Station station) { + this.companyId = company.getId(); + this.companyName = company.getName(); + this.roadAddress = company.getRoadAddress(); + this.province = company.getProvince(); + this.stationId = station.getId(); + this.stationName = station.getName(); + } + + } + } diff --git a/src/main/java/com/ftw/hometerview/place/service/PlaceServiceFacade.java b/src/main/java/com/ftw/hometerview/place/service/PlaceServiceFacade.java index 85b1663..5342233 100644 --- a/src/main/java/com/ftw/hometerview/place/service/PlaceServiceFacade.java +++ b/src/main/java/com/ftw/hometerview/place/service/PlaceServiceFacade.java @@ -39,4 +39,12 @@ public PlaceDto.SearchResult search(SearchType searchType, String keyword, Pagea // TODO:: Async 처리 적용 가능 여부(메서드 분리 필요 확인) } + public PlaceDto.CompanyDetail getCompanyDetail(String companyId) { + Company company = this.companyService.getCompanyById(companyId); + Station station = this.stationService.getByIds(List.of(company.getStationId())) + .getOrDefault(company.getStationId(), new Station()); + return new CompanyDetail(company, station); + + } + } From 47f0726a941afa3e06802747daba36013414bc9f Mon Sep 17 00:00:00 2001 From: rachel3486 Date: Thu, 2 Mar 2023 21:33:47 +0900 Subject: [PATCH 3/5] fix: Undefined methods --- .../java/com/ftw/hometerview/auth/service/AuthService.java | 2 +- .../com/ftw/hometerview/place/service/CompanyService.java | 5 +++++ .../ftw/hometerview/place/service/PlaceServiceFacade.java | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/ftw/hometerview/auth/service/AuthService.java b/src/main/java/com/ftw/hometerview/auth/service/AuthService.java index 47f17a7..dbcfed1 100644 --- a/src/main/java/com/ftw/hometerview/auth/service/AuthService.java +++ b/src/main/java/com/ftw/hometerview/auth/service/AuthService.java @@ -32,7 +32,7 @@ public void reissueAccessTokenToHeader(String memberId, String refreshToken, case EXPIRED -> throw new UnauthorizedException(ResponseType.AUTH_REQUIRE_LOGIN); } - Member member = memberRepository.findByMemberId(memberId).orElseThrow( + Member member = memberRepository.findByOauthId(memberId).orElseThrow( () -> new NotFoundException(ResponseType.MEMBER_NOT_EXIST_ID) ); diff --git a/src/main/java/com/ftw/hometerview/place/service/CompanyService.java b/src/main/java/com/ftw/hometerview/place/service/CompanyService.java index c15dfc8..e01b979 100644 --- a/src/main/java/com/ftw/hometerview/place/service/CompanyService.java +++ b/src/main/java/com/ftw/hometerview/place/service/CompanyService.java @@ -37,4 +37,9 @@ public List searchByKeyword(String keyword, Pageable pageable) return response; } + public Company getCompanyById(String companyId) { + return this.companyRepository.findById(companyId) + .orElseThrow(() -> new BadRequestException(ResponseType.REQUEST_NOT_VALID)); + } + } diff --git a/src/main/java/com/ftw/hometerview/place/service/PlaceServiceFacade.java b/src/main/java/com/ftw/hometerview/place/service/PlaceServiceFacade.java index 5342233..a11241a 100644 --- a/src/main/java/com/ftw/hometerview/place/service/PlaceServiceFacade.java +++ b/src/main/java/com/ftw/hometerview/place/service/PlaceServiceFacade.java @@ -42,7 +42,7 @@ public PlaceDto.SearchResult search(SearchType searchType, String keyword, Pagea public PlaceDto.CompanyDetail getCompanyDetail(String companyId) { Company company = this.companyService.getCompanyById(companyId); Station station = this.stationService.getByIds(List.of(company.getStationId())) - .getOrDefault(company.getStationId(), new Station()); + .getOrDefault(company.getStationId(), Station.EMPTY); return new CompanyDetail(company, station); } From 525154710e11fbf262f2c2294a52baeed2dfb9a6 Mon Sep 17 00:00:00 2001 From: rachel3486 Date: Thu, 2 Mar 2023 21:34:30 +0900 Subject: [PATCH 4/5] fix: Undefined methods --- src/main/java/com/ftw/hometerview/place/domain/Station.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/ftw/hometerview/place/domain/Station.java b/src/main/java/com/ftw/hometerview/place/domain/Station.java index 5565f54..b22efb2 100644 --- a/src/main/java/com/ftw/hometerview/place/domain/Station.java +++ b/src/main/java/com/ftw/hometerview/place/domain/Station.java @@ -37,4 +37,5 @@ public StationDto.Meta toMeta() { .build(); } + public static Station EMPTY = Station.builder().build(); } From d27eea7ae5a7c580bdd99c5ae8caee6290ead18d Mon Sep 17 00:00:00 2001 From: rachel3486 Date: Thu, 2 Mar 2023 21:36:01 +0900 Subject: [PATCH 5/5] fix: Undefined methods --- .../com/ftw/hometerview/place/service/PlaceServiceFacade.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/ftw/hometerview/place/service/PlaceServiceFacade.java b/src/main/java/com/ftw/hometerview/place/service/PlaceServiceFacade.java index a11241a..611141c 100644 --- a/src/main/java/com/ftw/hometerview/place/service/PlaceServiceFacade.java +++ b/src/main/java/com/ftw/hometerview/place/service/PlaceServiceFacade.java @@ -3,8 +3,10 @@ import com.ftw.hometerview.place.controller.dto.CompanyDto; import com.ftw.hometerview.place.controller.dto.PlaceDto; import com.ftw.hometerview.place.controller.dto.BuildingDto; +import com.ftw.hometerview.place.controller.dto.PlaceDto.CompanyDetail; import com.ftw.hometerview.place.controller.dto.PlaceDto.SearchResult; import com.ftw.hometerview.place.controller.dto.StationDto; +import com.ftw.hometerview.place.domain.Company; import com.ftw.hometerview.place.domain.SearchType; import com.ftw.hometerview.place.domain.Station; import java.util.List;