Skip to content

Commit

Permalink
style: Modify member oauth field name
Browse files Browse the repository at this point in the history
  • Loading branch information
im-gnar committed Feb 25, 2023
1 parent b19e0d0 commit cd5d883
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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<MemberDto> getLoginMemberInfo() {
var memberInfo = this.memberService.getMemberInfo(AuthUtil.getCurrentMemberId());
return ResponseEntity.successResponse(memberInfo);
}

}
Original file line number Diff line number Diff line change
@@ -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();
}

}
5 changes: 4 additions & 1 deletion src/main/java/com/ftw/hometerview/member/domain/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -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; // 리뷰를 작성했는지에 대한 여부
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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));

}

}
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -25,4 +28,26 @@ public SearchResult(List<Meta> 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();
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}

}

0 comments on commit cd5d883

Please sign in to comment.