From 1a108ea441718afd9ff6fb2f0762e7ecd7b25347 Mon Sep 17 00:00:00 2001 From: rachel3486 Date: Sat, 25 Feb 2023 20:29:52 +0900 Subject: [PATCH] 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); + + } + }