Skip to content

Commit

Permalink
Update: jwt exception 코드 및 공급자 관련 api 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
BYEONGRYEOL committed May 15, 2024
1 parent 1ab717c commit bf8344e
Show file tree
Hide file tree
Showing 31 changed files with 408 additions and 94 deletions.
50 changes: 50 additions & 0 deletions src/main/java/com/gt/genti/adapter/in/web/CreatorController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.gt.genti.adapter.in.web;

import static com.gt.genti.other.util.ApiUtils.*;

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.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.gt.genti.dto.CreatorInfoResponseDto;
import com.gt.genti.dto.UpdateAccountInfoRequestDto;
import com.gt.genti.dto.UpdateCreatorStatusRequestDto;
import com.gt.genti.dto.UpdateCreatorStatusResponseDto;
import com.gt.genti.dto.UserInfoResponseDto;
import com.gt.genti.other.annotation.ToBeUpdated;
import com.gt.genti.other.aop.annotation.CheckUserIsQuit;
import com.gt.genti.other.auth.UserDetailsImpl;
import com.gt.genti.service.CreatorService;

import lombok.RequiredArgsConstructor;

@RestController
@RequestMapping("/api/creators")
@RequiredArgsConstructor
public class CreatorController {
private final CreatorService creatorService;

@GetMapping("")
public ResponseEntity<ApiResult<CreatorInfoResponseDto>> getCreatorInfo(
@AuthenticationPrincipal UserDetailsImpl userDetails) {
return success(creatorService.getCreatorInfo(userDetails.getId()));
}

@PostMapping("/account")
public ResponseEntity<ApiResult<Boolean>> updateAccountInfo(
@AuthenticationPrincipal UserDetailsImpl userDetails,
@RequestBody UpdateAccountInfoRequestDto updateAccountInfoRequestDto) {
return success(creatorService.updateAccountInfo(userDetails.getId(), updateAccountInfoRequestDto));
}
@PostMapping("/status")
public ResponseEntity<ApiResult<UpdateCreatorStatusResponseDto>> updateCreatorStatus(
@AuthenticationPrincipal UserDetailsImpl userDetails,
@RequestBody UpdateCreatorStatusRequestDto updateCreatorStatusRequestDto) {
return success(creatorService.updateCreatorStatus(userDetails.getId(), updateCreatorStatusRequestDto));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public ResponseEntity<ApiResult<TestJwtResponseDto>> getTestJwt(@PathParam(value
if (tempRole == null) {
throw new RuntimeException();
}
Map<UserRole, String> userIdMapper = Map.of(UserRole.USER, "3", UserRole.ADMIN, "1", UserRole.CREATOR, "4");
Map<UserRole, String> userIdMapper = Map.of(UserRole.USER, "2", UserRole.ADMIN, "1", UserRole.CREATOR, "4");
String userId = userIdMapper.get(tempRole);
Map<String, Object> tempClaim = Map.of("auth", tempRole.getStringValue(), "sub", userId);
String accessToken = jwtTokenProvider.generateToken(tempClaim, 1000000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import com.gt.genti.adapter.usecase.PictureGenerateRequestUseCase;
import com.gt.genti.domain.enums.PictureGenerateRequestStatus;
import com.gt.genti.dto.PictureGenerateRequestBriefResponseDto;
import com.gt.genti.dto.PictureGenerateRequestDetailResponseDto;
import com.gt.genti.dto.PictureGenerateRequestModifyDto;
import com.gt.genti.dto.PictureGenerateRequestRequestDto;
Expand All @@ -35,14 +36,14 @@ public class PictureGenerateRequestController {
@GetMapping("")
public ResponseEntity<ApiResult<List<PictureGenerateRequestDetailResponseDto>>> getMyPictureGenerateRequest(
@AuthenticationPrincipal UserDetailsImpl userDetails,
@PathParam(value = "status")PictureGenerateRequestStatus status
@PathParam(value = "status") PictureGenerateRequestStatus status
) {
return success(
pictureGenerateRequestUseCase.getPictureGenerateRequest(userDetails.getId(), status));
}

@CheckUserIsQuit
@GetMapping("/recent")
@GetMapping("/active")
public ResponseEntity<ApiResult<PictureGenerateRequestDetailResponseDto>> getMyRecentPictureGenerateRequest(
@AuthenticationPrincipal UserDetailsImpl userDetails
) {
Expand Down Expand Up @@ -77,4 +78,11 @@ public ResponseEntity<ApiResult<Boolean>> modifyPictureGenerateRequest(
pictureGenerateRequestModifyDto));
}

@GetMapping("/all")
public ResponseEntity<ApiResult<List<PictureGenerateRequestBriefResponseDto>>> getAllMyRequests(
@AuthenticationPrincipal UserDetailsImpl userDetails
) {
return success(pictureGenerateRequestUseCase.getAllMyPictureGenerateRequests(userDetails.getId()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@

import org.springframework.transaction.annotation.Transactional;

import com.gt.genti.domain.User;
import com.gt.genti.domain.enums.PictureGenerateRequestStatus;
import com.gt.genti.dto.PictureGenerateRequestBriefResponseDto;
import com.gt.genti.dto.PictureGenerateRequestDetailResponseDto;
import com.gt.genti.dto.PictureGenerateRequestModifyDto;
import com.gt.genti.dto.PictureGenerateRequestRequestDto;
import com.gt.genti.dto.PictureGenerateRequestSimplifiedResponseDto;

public interface PictureGenerateRequestUseCase {
public List<PictureGenerateRequestDetailResponseDto> getPictureGenerateRequest(Long userId,
PictureGenerateRequestStatus status);

public PictureGenerateRequestDetailResponseDto getPictureGenerateRequest(Long userId);

public PictureGenerateRequestDetailResponseDto getPictureGenerateRequestById(Long id);

public List<PictureGenerateRequestSimplifiedResponseDto> getAllMyPictureGenerateRequests(User requester);
public List<PictureGenerateRequestBriefResponseDto> getAllMyPictureGenerateRequests(Long userId);

@Transactional
public Boolean createPictureGenerateRequest(Long requesterId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
import com.gt.genti.application.port.in.PictureGenerateRequestPort;
import com.gt.genti.command.CreatePicturePoseCommand;
import com.gt.genti.domain.Creator;
import com.gt.genti.domain.PictureCompleted;
import com.gt.genti.domain.PictureGenerateRequest;
import com.gt.genti.domain.PicturePose;
import com.gt.genti.domain.PictureUserFace;
import com.gt.genti.domain.User;
import com.gt.genti.domain.enums.PictureGenerateRequestStatus;
import com.gt.genti.dto.PictureGenerateRequestBriefResponseDto;
import com.gt.genti.dto.PictureGenerateRequestDetailResponseDto;
import com.gt.genti.dto.PictureGenerateRequestModifyDto;
import com.gt.genti.dto.PictureGenerateRequestRequestDto;
import com.gt.genti.dto.PictureGenerateRequestSimplifiedResponseDto;
import com.gt.genti.error.ErrorCode;
import com.gt.genti.error.ExpectedException;
import com.gt.genti.external.openai.dto.PromptAdvancementRequestDto;
Expand Down Expand Up @@ -77,9 +78,25 @@ public PictureGenerateRequestDetailResponseDto getPictureGenerateRequestById(Lon
// edited at 2024-04-13
// author 서병렬
@Override
public List<PictureGenerateRequestSimplifiedResponseDto> getAllMyPictureGenerateRequests(User requester) {
// return pictureGenerateRequestPersistenceAdapter.findAllByRequester(requester).stream().map(entity -> );
return null;
public List<PictureGenerateRequestBriefResponseDto> getAllMyPictureGenerateRequests(Long userId) {
User foundUser = userRepository.findById(userId)
.orElseThrow(() -> new ExpectedException(ErrorCode.UserNotFound));
return pictureGenerateRequestPort.findAllByRequester(foundUser)
.stream()
.map(entity -> PictureGenerateRequestBriefResponseDto.builder()
.shotCoverage(entity.getShotCoverage())
.cameraAngle(entity.getCameraAngle())
.requestId(entity.getId())
.prompt(entity.getPrompt())
.status(entity.getPictureGenerateRequestStatus())
.urlList(entity.getResponseList()
.stream()
.flatMap(pictureGenerateResponse -> pictureGenerateResponse.getCompletedPictureList().stream().map(
PictureCompleted::getUrl))
.toList())
.build()

).toList();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public PictureGenerateRequestBriefResponseDto getPictureGenerateRequestBrief(Lon
.orElseThrow(() -> new ExpectedException(ErrorCode.CreatorNotFound));
Optional<PictureGenerateRequest> foundPGR;
switch (status) {
case BEFORE_WORK ->
case IN_PROGRESS ->
foundPGR = pictureGenerateRequestRepository.findByCreatorAndRequestStatusIsBeforeWorkOrderByCreatedAtAsc(
foundCreator);
case ASSIGNING ->
Expand All @@ -52,8 +52,8 @@ public PictureGenerateRequestBriefResponseDto getPictureGenerateRequestBrief(Lon
(pictureGenerateRequest) ->
PictureGenerateRequestBriefResponseDto.builder()
.requestId(pictureGenerateRequest.getId())
.cameraAngle(pictureGenerateRequest.getCameraAngle().getStringValue())
.shotCoverage(pictureGenerateRequest.getShotCoverage().getStringValue())
.cameraAngle(pictureGenerateRequest.getCameraAngle())
.shotCoverage(pictureGenerateRequest.getShotCoverage())
.prompt(pictureGenerateRequest.getPrompt())
.build()
).orElseThrow(() -> new ExpectedException(ErrorCode.PictureGenerateRequestNotFound));
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/gt/genti/domain/Creator.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import java.util.List;

import com.gt.genti.domain.common.BaseTimeEntity;
import com.gt.genti.domain.enums.BankType;
import com.gt.genti.domain.enums.converter.BankTypeConverter;

import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
Expand All @@ -17,6 +20,7 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Table(name = "creator")
@Entity
Expand All @@ -28,6 +32,7 @@ public class Creator extends BaseTimeEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
Long id;

@Setter
@Column(name = "workable", nullable = false)
Boolean workable;

Expand All @@ -38,8 +43,21 @@ public class Creator extends BaseTimeEntity {
@OneToMany(mappedBy = "creator")
List<PictureGenerateRequest> pictureGenerateRequest;

@Convert(converter = BankTypeConverter.class)
@Column(name = "bank_type")
BankType bankType;


@Column(name = "account_number")
String accountNumber;

@Builder
public Creator(Boolean workable) {
this.workable = workable;
}

public void updateAccountInfo(BankType bankType, String accountNumber){
this.bankType = bankType;
this.accountNumber = accountNumber;
}
}
5 changes: 3 additions & 2 deletions src/main/java/com/gt/genti/domain/PictureGenerateRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public PictureGenerateRequest(User requester, PictureGenerateRequestRequestDto p
this.prompt = pictureGenerateRequestRequestDto.getPrompt();
this.promptAdvanced = promptAdvanced;
this.picturePose = picturePose;
this.pictureGenerateRequestStatus = PictureGenerateRequestStatus.BEFORE_WORK;
this.pictureGenerateRequestStatus = PictureGenerateRequestStatus.ASSIGNING;
this.cameraAngle = pictureGenerateRequestRequestDto.getCameraAngle();
this.shotCoverage = pictureGenerateRequestRequestDto.getShotCoverage();
this.userFacePictureList = userFacePictureList;
Expand All @@ -104,10 +104,11 @@ public void modify(PictureGenerateRequestModifyDto pictureGenerateRequestModifyD
}

public void assign(Creator creator) {
if (this.pictureGenerateRequestStatus != PictureGenerateRequestStatus.BEFORE_WORK) {
if (this.pictureGenerateRequestStatus != PictureGenerateRequestStatus.ASSIGNING) {
log.error(" 이미 진행중인 작업에 대해 비 정상적인 매칭");
return;
}
this.creator = creator;
this.pictureGenerateRequestStatus = PictureGenerateRequestStatus.IN_PROGRESS;
}
}
31 changes: 31 additions & 0 deletions src/main/java/com/gt/genti/domain/enums/BankType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.gt.genti.domain.enums;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum BankType implements ConvertableEnum {
KB("국민은행"),
SHINHAN("신한은행"),
HANA("하나은행"),
WOORI("우리은행"),
IBK("기업은행"),
SC("SC제일은행"),
CITY("씨티은행"),
NH("농협은행"),
SH("수협은행"),

K("케이뱅크"),
KAKAOBANK("카카오뱅크"),
TOSS("토스뱅크"),

DAEGU("대구은행"),
BUSAN("부산은행"),
KYONGNAM("경남은행"),
KWANGJU("광주은행"),
JEONBUK("전북은행"),
JEJU("제주은행"),
NONE("NONE");
private final String stringValue;
}
2 changes: 1 addition & 1 deletion src/main/java/com/gt/genti/domain/enums/OauthType.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public enum OauthType implements com.gt.genti.domain.enums.ConvertableEnum {
GOOGLE("GOOGLE"),
KAKAO("KAKAO"),
APPLE("APPLE"),
NULL("NULL");
NONE("NONE");

private final String stringValue;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
@RequiredArgsConstructor
public enum PictureGenerateRequestStatus implements ConvertableEnum {
ASSIGNING("ASSIGNING"),
BEFORE_WORK("BEFORE_WORK"),
IN_PROGRESS("IN_PROGRESS"),
CANCELED("CANCELED"),
REPORTED("REPORTED"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.gt.genti.domain.enums.converter;

import com.gt.genti.domain.enums.BankType;
import com.gt.genti.domain.enums.CameraAngle;

import jakarta.persistence.Converter;

@Converter
public class BankTypeConverter extends DefaultStringAttributeConverter<BankType> {

public BankTypeConverter() {
super(BankType.class);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@

@Slf4j
public class EnumUtil {
public static final String NULL = "NONE";

private static <E extends Enum<E> & ConvertableEnum> E convertNullToEnum(Class<E> enumType) {
for (E enumValue : enumType.getEnumConstants()) {
if (enumValue.name().equals("NULL")) {
if (enumValue.name().equals(NULL)) {
return enumValue;
}
}
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/com/gt/genti/dto/CreatorInfoResponseDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.gt.genti.dto;

import com.gt.genti.domain.enums.BankType;

import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class CreatorInfoResponseDto {
Boolean workable;
BankType bankType;
String accountNumber;

@Builder
public CreatorInfoResponseDto(Boolean workable, BankType bankType, String accountNumber) {
this.workable = workable;
this.bankType = bankType;
this.accountNumber = accountNumber;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package com.gt.genti.dto;

import java.util.List;

import com.gt.genti.domain.PictureGenerateRequest;
import com.gt.genti.domain.enums.CameraAngle;
import com.gt.genti.domain.enums.PictureGenerateRequestStatus;
import com.gt.genti.domain.enums.ShotCoverage;

import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -9,15 +16,19 @@
public class PictureGenerateRequestBriefResponseDto {
Long requestId;
String prompt;
String cameraAngle;
String shotCoverage;
CameraAngle cameraAngle;
ShotCoverage shotCoverage;
List<String> urlList;
PictureGenerateRequestStatus status;

@Builder
public PictureGenerateRequestBriefResponseDto(Long requestId, String prompt, String cameraAngle,
String shotCoverage) {
public PictureGenerateRequestBriefResponseDto(Long requestId, String prompt, CameraAngle cameraAngle,
ShotCoverage shotCoverage, List<String> urlList, PictureGenerateRequestStatus status) {
this.requestId = requestId;
this.prompt = prompt;
this.cameraAngle = cameraAngle;
this.shotCoverage = shotCoverage;
this.urlList = urlList;
this.status = status;
}
}
Loading

0 comments on commit bf8344e

Please sign in to comment.