-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
src/main/java/jikgong/domain/visaimage/controller/VisaImageController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
18
src/main/java/jikgong/domain/visaimage/dto/VisaImageResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/jikgong/domain/visaimage/service/VisaImageService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters