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

Feat/my company #43

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ public Map<String, Object> getMemberInfoByToken(LoginRequest loginRequest) {
public LoginResponse login(LoginRequest loginRequest) {
// Get user information using Kakao Token
Map<String, Object> kakaoAttributes = getMemberInfoByToken(loginRequest);
String memberId = String.valueOf(kakaoAttributes.get("id"));
String oauthId = String.valueOf(kakaoAttributes.get("id"));
Map<String, Object> properties = (Map<String, Object>) 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> member = memberRepository.findByMemberId(memberId);
// Check if requester are subscribed to the server through requester member oauth ID
Optional<Member> member = memberRepository.findByOauthId(oauthId);
if (member.isPresent()) {
ProviderType providerType = member.get().getProviderType();

Expand All @@ -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)
Expand Down
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();
}

}
7 changes: 5 additions & 2 deletions src/main/java/com/ftw/hometerview/member/domain/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,20 @@ public class Member extends AbstractDocument {
@MongoId(FieldType.OBJECT_ID)
String id;

String memberId;
String oauthId;

String nickname;

ProviderType providerType;

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
Expand Up @@ -8,5 +8,5 @@
@Repository
public interface MemberRepository extends MongoRepository<Member, String> {

Optional<Member> findByMemberId(String memberId);
Optional<Member> findByOauthId(String oauthId);
}
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 @@ -37,4 +37,5 @@ public StationDto.Meta toMeta() {
.build();
}

public static Station EMPTY = Station.builder().build();
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,9 @@ public List<CompanyDto.Meta> searchByKeyword(String keyword, Pageable pageable)
return response;
}

public Company getCompanyById(String companyId) {
return this.companyRepository.findById(companyId)
.orElseThrow(() -> new BadRequestException(ResponseType.REQUEST_NOT_VALID));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -39,4 +41,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(), Station.EMPTY);
return new CompanyDetail(company, station);

}

}