Skip to content

Commit

Permalink
feat: 체류 만료일 불러온 후 worker 정보 업데이트 api 개발
Browse files Browse the repository at this point in the history
  • Loading branch information
dgjinsu committed Nov 10, 2024
1 parent 469bd45 commit acc1bdb
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
import jikgong.domain.member.dto.info.WorkerInfoRequest;
import jikgong.domain.member.dto.info.WorkerInfoResponse;
import jikgong.domain.member.service.MemberInfoService;
import jikgong.domain.member.service.StayExpirationService;
import jikgong.global.annotation.AuthenticatedRequired;
import jikgong.global.annotation.CompanyRoleRequired;
import jikgong.global.annotation.WorkerRoleRequired;
import jikgong.global.codef.service.StayExpirationService;
import jikgong.global.common.Response;
import jikgong.global.security.principal.PrincipalDetails;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -120,8 +120,10 @@ public ResponseEntity<Response> updateTemporaryPassword(@RequestBody AuthCodeFor
@Operation(summary = "체류 만료일 정보 불러오기", description = "codef api를 활용하여 체류 만료일 정보 저장")
@PostMapping("/api/member-info/visaExpiryDate")
@WorkerRoleRequired
public ResponseEntity<Response> updateVisaExpiryDate(@RequestBody StayExpirationRequest request)
public ResponseEntity<Response> updateVisaExpiryDate(@AuthenticationPrincipal PrincipalDetails principalDetails,
@RequestBody StayExpirationRequest request)
throws JsonProcessingException {
memberInfoService.updateStayExpiration(principalDetails.getMember().getId(), request);
return ResponseEntity.ok(new Response(stayExpirationService.checkStayExpiration(request), "개발 미완성"));
}

Expand Down
21 changes: 12 additions & 9 deletions src/main/java/jikgong/domain/member/entity/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@
import jikgong.domain.history.entity.History;
import jikgong.domain.location.entity.Location;
import jikgong.domain.member.dto.info.CompanyInfoRequest;
import jikgong.domain.member.dto.info.WorkerInfoRequest;
import jikgong.domain.member.dto.info.StayExpirationResponse;
import jikgong.domain.visaimage.entity.VisaImage;
import jikgong.domain.workexperience.entity.WorkExperience;
import jikgong.global.exception.ErrorCode;
import jikgong.global.exception.JikgongException;
import jikgong.global.utils.DateConverter;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
Expand Down Expand Up @@ -102,9 +105,6 @@ public void updateDeviceToken(String deviceToken) {
this.deviceToken = deviceToken;
}

public void updateWorkerInfo(WorkerInfoRequest request) {
this.workerInfo.updateWorkerInfo(request);
}

public void updateCompanyInfo(CompanyInfoRequest request) {
this.companyInfo.updateWorkerInfo(request);
Expand All @@ -114,11 +114,14 @@ public void updatePassword(String newPassword) {
this.password = newPassword;
}

private void updateVisaExpiryDate(LocalDate visaExpiryDate) {
this.workerInfo.updateVisaExpiryDate(visaExpiryDate);
}
public void updateVisaExpiryDate(StayExpirationResponse stayExpirationResponse) {
// 국내에 체류중인 외국인이 아닐 경우
if ("0".equals(stayExpirationResponse.getData().getResAuthenticity())) {
throw new JikgongException(ErrorCode.MEMBER_NOT_STAY_WITH_IN_THE_COUNTRY);
}

public void updateVisaImage(VisaImage visaImage) {
this.visaImage = visaImage;
LocalDate visaExpiryDate = DateConverter.convertToLocalDate(
stayExpirationResponse.getData().getResExpirationDate());
this.workerInfo.updateVisaExpiryDate(visaExpiryDate);
}
}
22 changes: 22 additions & 0 deletions src/main/java/jikgong/domain/member/service/MemberInfoService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package jikgong.domain.member.service;

import com.fasterxml.jackson.core.JsonProcessingException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
Expand All @@ -15,6 +16,8 @@
import jikgong.domain.member.dto.info.PasswordFindRequest;
import jikgong.domain.member.dto.info.PasswordFindResponse;
import jikgong.domain.member.dto.info.PasswordUpdateRequest;
import jikgong.domain.member.dto.info.StayExpirationRequest;
import jikgong.domain.member.dto.info.StayExpirationResponse;
import jikgong.domain.member.dto.info.WorkerInfoRequest;
import jikgong.domain.member.dto.info.WorkerInfoResponse;
import jikgong.domain.member.entity.Member;
Expand Down Expand Up @@ -44,6 +47,7 @@ public class MemberInfoService {
private final PasswordEncoder encoder;
private final RedisTemplate<String, String> redisTemplate;
private final SmsService smsService;
private final StayExpirationService stayExpirationService;

/**
* 노동자: 회원 정보 조회
Expand Down Expand Up @@ -224,4 +228,22 @@ public LoginIdFindResponse findLoginId(AuthCodeForFindRequest request) {
// 로그인 아이디 반환
return LoginIdFindResponse.from(member);
}

/**
* 체류 만료일 조회 api 호출
* 체류 만료일 정보 업데이트
*/
public void updateStayExpiration(Long workerId, StayExpirationRequest request) throws JsonProcessingException {
// codef api 호출
StayExpirationResponse stayExpirationResponse = stayExpirationService.checkStayExpiration(request);

if (!"CF-00000".equals(stayExpirationResponse.getResult().getCode())) {
throw new JikgongException(ErrorCode.CODEF_UNKNOWN_ERROR);
}

Member member = memberRepository.findById(workerId)
.orElseThrow(() -> new JikgongException(ErrorCode.MEMBER_NOT_FOUND));

member.updateVisaExpiryDate(stayExpirationResponse);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package jikgong.global.codef.service;
package jikgong.domain.member.service;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down

0 comments on commit acc1bdb

Please sign in to comment.