Skip to content

Commit

Permalink
feat: 로그인한 노동자의 비자 사진 조회 API 개발
Browse files Browse the repository at this point in the history
  • Loading branch information
dgjinsu committed Sep 13, 2024
1 parent 47fde9f commit 3e623b9
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
package jikgong.domain.visaimage.controller;

import io.swagger.v3.oas.annotations.Operation;
import jikgong.domain.visaimage.dto.VisaImageResponse;
import jikgong.domain.visaimage.service.VisaImageService;
import jikgong.global.annotation.WorkerRoleRequired;
import jikgong.global.common.Response;
import jikgong.global.security.principal.PrincipalDetails;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
public class VisaImageController {

private final VisaImageService visaImageService;

@Operation(summary = "노동자: 비자 이미지 조회")
@GetMapping("/api/visa-image")
@WorkerRoleRequired
public ResponseEntity<Response> findMyVisaImage(@AuthenticationPrincipal PrincipalDetails principalDetails) {
VisaImageResponse visaImageResponse = visaImageService.findMyVisaImage(principalDetails.getMember().getId());
return ResponseEntity.ok(new Response(visaImageResponse, "비자 이미지 조회 완료"));
}
}
18 changes: 18 additions & 0 deletions src/main/java/jikgong/domain/visaimage/dto/VisaImageResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package jikgong.domain.visaimage.dto;

import jikgong.domain.visaimage.entity.VisaImage;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class VisaImageResponse {

private String s3Url;

public static VisaImageResponse from(VisaImage visaImage) {
return VisaImageResponse.builder()
.s3Url(visaImage.getS3Url())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package jikgong.domain.visaimage.service;

import jikgong.domain.member.entity.Member;
import jikgong.domain.member.repository.MemberRepository;
import jikgong.domain.visaimage.dto.VisaImageResponse;
import jikgong.domain.visaimage.entity.VisaImage;
import jikgong.domain.visaimage.repository.VisaImageRepository;
import jikgong.global.exception.ErrorCode;
import jikgong.global.exception.JikgongException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
@Transactional
@Slf4j
public class VisaImageService {

private final VisaImageRepository visaImageRepository;
private final MemberRepository memberRepository;


/**
* 로그인한 노동자의 비자 사진 조회
*/
public VisaImageResponse findMyVisaImage(Long workerId) {
Member member = memberRepository.findById(workerId)
.orElseThrow(() -> new JikgongException(ErrorCode.MEMBER_NOT_FOUND));

VisaImage visaImage = member.getVisaImage();

if (visaImage == null) {
throw new JikgongException(ErrorCode.VISA_IMAGE_NOT_FOUND);
}

return VisaImageResponse.from(visaImage);
}
}
7 changes: 6 additions & 1 deletion src/main/java/jikgong/global/exception/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,12 @@ public enum ErrorCode {
SMS_FORBIDDEN(HttpStatus.FORBIDDEN, "SMS-004", "접근이 금지되었습니다."),
SMS_NOT_FOUND(HttpStatus.NOT_FOUND, "SMS-005", "요청한 리소스를 찾을 수 없습니다."),
SMS_TOO_MANY_REQUESTS(HttpStatus.TOO_MANY_REQUESTS, "SMS-006", "요청이 너무 많습니다. 나중에 다시 시도하세요."),
SMS_INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "SMS-007", "서버 내부 오류가 발생했습니다.");
SMS_INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "SMS-007", "서버 내부 오류가 발생했습니다."),

/**
* 비자 사진
*/
VISA_IMAGE_NOT_FOUND(HttpStatus.NOT_FOUND, "VISA-001", "비자 사진 정보가 없습니다.");

private final HttpStatus status;
private final String code;
Expand Down

0 comments on commit 3e623b9

Please sign in to comment.