Skip to content

Commit

Permalink
Merge branch 'staging' of https://github.com/Genti2024/GenTI-BE into …
Browse files Browse the repository at this point in the history
…feat/218-refactoring
  • Loading branch information
LeeJae-H committed Dec 5, 2024
2 parents 31c0af7 + c0fe0eb commit 462e48d
Show file tree
Hide file tree
Showing 15 changed files with 83 additions and 160 deletions.
28 changes: 23 additions & 5 deletions .github/workflows/cicd-ec2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,26 @@ jobs:
echo "${{ secrets.APPLICATION_STAGING }}" > ./application-staging.yml
shell: bash

# 아래 코드는 json이 큰따옴표 없이 저장됨
# - name: Create Google key.json file
# if: contains(github.ref, 'staging') || contains(github.ref, 'main-test')
# run: |
# cd ./genti-api/src/main/resources
# mkdir -p ./jsonkey
# echo "${{ secrets.GOOGLE_ACCOUNT_KEY }}" > ./jsonkey/key.json
# shell: bash

- name: Create jsonkey directory
if: contains(github.ref, 'staging') || contains(github.ref, 'main-test')
run: mkdir -p ./genti-api/src/main/resources/jsonkey

- name: Create Google key.json file
if: contains(github.ref, 'staging') || contains(github.ref, 'main-test')
run: |
cd ./genti-api/src/main/resources
mkdir -p ./jsonkey
echo "${{ secrets.GOOGLE_ACCOUNT_KEY }}" > ./jsonkey/key.json
shell: bash
id: create-json
uses: jsdaniell/create-json@1.1.2
with:
name: "./genti-api/src/main/resources/jsonkey/key.json"
json: ${{ secrets.GOOGLE_ACCOUNT_KEY }}

- name: make apple private key
run: |
Expand Down Expand Up @@ -187,6 +200,11 @@ jobs:
# Clean up the temporary directory
rm -rf temp_dir
- name: Upload key.json to S3
if: contains(github.ref, 'staging')
run: |
aws s3 cp ./genti-api/src/main/resources/jsonkey/key.json s3://$S3_BUCKET_NAME/jsonkey/key.json
- name: Upload docker-compose, appspec, afterInstall file to S3
if: contains(github.ref, 'staging')
run: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ public Page<PictureGenerateRequest> findAll(Pageable pageable) {
}

@Override
public Page<PictureGenerateResponse> findByPGRESStatusInAndMatchToAdminIs(
public Page<PictureGenerateResponse> findByPGRESStatusInAndMatchToAdminIsAndPaidIsNull(
List<PictureGenerateResponseStatus> statusList, boolean matchToAdmin, Pageable pageable) {
return pictureGenerateRequestRepository.findByPictureGenerateResponseStatusInAndMatchToAdminIs(statusList,
return pictureGenerateRequestRepository.findByPictureGenerateResponseStatusInAndMatchToAdminIsAndPaidIsNull(statusList,
matchToAdmin, pageable);
}

@Override
public Page<PictureGenerateRequest> findByMatchToAdminIs(boolean matchToAdmin, Pageable pageable) {
return pictureGenerateRequestRepository.findByMatchToAdminIs(matchToAdmin, pageable);
public Page<PictureGenerateRequest> findByMatchToAdminIsAndPaidIsNull(boolean matchToAdmin, Pageable pageable) {
return pictureGenerateRequestRepository.findByMatchToAdminIsAndPaidIsNull(matchToAdmin, pageable);

}

Expand All @@ -66,7 +66,7 @@ public Page<PictureGenerateRequest> findByMatchToAdminIsAndPaidIsNotNull(boolean

@Override
public Page<PictureGenerateRequest> findAllByRequester(User foundUser, Pageable pageable) {
return pictureGenerateRequestRepository.findAllByRequester(foundUser, pageable);
return pictureGenerateRequestRepository.findAllByRequesterAndPaidIsNull(foundUser, pageable);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,30 +54,4 @@ ResponseEntity<ApiResult<Page<PGREQAdminMatchedDetailFindByAdminResponseDto>>> g
@RequestParam(name = "email", required = false) @Email(message = "올바른 email 형식이 아닙니다.") String email,
@Parameter(description = "유료 사진생성요청 여부") @RequestParam(name = "paid", required = false) Boolean paid
);

@Operation(summary = "공급자->어드민(얼굴붙여야하는 요청)", description = "사진생성요청 전체를 매칭대상(어드민,공급자), 응답의 상태를 조건으로 조회하고 페이지네이션 조회합니다.")
@EnumResponses(value = {
@EnumResponse(ResponseCode.OK)
})
ResponseEntity<ApiResult<Page<PGREQCreatorSubmittedDetailFindByAdminResponseDto>>> getAllCreatorSubmittedPGREQ(
@Parameter(description = "페이지 번호 (0-based)", example = "0", required = true)
@RequestParam(name = "page", defaultValue = "0") @NotNull @Min(0) int page,
@Parameter(description = "페이지 당 요소 개수 >=1", example = "10", required = true)
@RequestParam(name = "size", defaultValue = "10") @NotNull @Min(1) int size,
@Parameter(description = "정렬 조건 - 기본값 생성일시", example = "createdAt", schema = @Schema(allowableValues = {"id",
"createdAt"}))
@RequestParam(name = "sortBy", defaultValue = "createdAt") String sortBy,
@Parameter(description = "정렬 방향 - 기본값 내림차순", example = "desc", schema = @Schema(allowableValues = {"acs",
"desc"}))
@RequestParam(name = "direction", defaultValue = "desc") String direction,
@Parameter(description = "현재 작업(사진생성응답)의 상태로 조회한다. ALL 조회 가능, EXPIRED는 MVP상 도메인로직엔 없지만 어드민페이지의 성격 상 필요하다고 생각하여 추가했습니다.",
examples = {@ExampleObject(name = "BEFORE_WORK", description = "작업 대기", value = "BEFORE_WORK"),
@ExampleObject(name = "IN_PROGRESS", description = "작업 중", value = "IN_PROGRESS"),
@ExampleObject(name = "COMPLETED", description = "작업 완료", value = "COMPLETED"),
@ExampleObject(name = "EXPIRED", description = "만료됨 (기존의 협의된 내용은 아니지만 어드민페이지에 필요하다고 생각했습니다. 추가 부탁드립니다.)", value = "EXPIRED"),
@ExampleObject(name = "ALL", description = "전체", value = "ALL")})
@RequestParam(name = "status", defaultValue = "ALL") @ValidEnum(value = PictureGenerateResponseStatusForAdmin.class, hasAllOption = true) String status,
@Parameter(description = "유저의 email")
@RequestParam(name = "email", required = false) @Email(message = "올바른 email 형식이 아닙니다.") String email
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,35 +79,6 @@ public ResponseEntity<ApiResult<Page<PGREQAdminMatchedDetailFindByAdminResponseD
}
}

@Logging(item = LogItem.PGREQ, action = LogAction.DELETE, requester = LogRequester.ADMIN)
@GetMapping("/creator-submitted")
public ResponseEntity<ApiResult<Page<PGREQCreatorSubmittedDetailFindByAdminResponseDto>>> getAllCreatorSubmittedPGREQ(
@Parameter(description = "페이지 번호 (0-based)", example = "0", required = true) @RequestParam(name = "page", defaultValue = "0") @NotNull @Min(0) int page,
@Parameter(description = "페이지 당 요소 개수 >=1", example = "10", required = true) @RequestParam(name = "size", defaultValue = "10") @NotNull @Min(1) int size,
@Parameter(description = "정렬 조건 - 기본값 생성일시", example = "createdAt", schema = @Schema(allowableValues = {"id",
"createdAt"})) @RequestParam(name = "sortBy", defaultValue = "createdAt") String sortBy,
@Parameter(description = "정렬 방향 - 기본값 내림차순", example = "desc", schema = @Schema(allowableValues = {"acs",
"desc"})) @RequestParam(name = "direction", defaultValue = "desc") String direction,
@Parameter(description = "현재 작업(사진생성응답)의 상태로 조회한다. ALL 조회 가능, EXPIRED는 MVP상 도메인로직엔 없지만 어드민페이지의 성격 상 필요하다고 생각하여 추가했습니다.", examples = {
@ExampleObject(name = "BEFORE_WORK", description = "작업 대기", value = "BEFORE_WORK"),
@ExampleObject(name = "IN_PROGRESS", description = "작업 중", value = "IN_PROGRESS"),
@ExampleObject(name = "COMPLETED", description = "작업 완료", value = "COMPLETED"),
@ExampleObject(name = "EXPIRED", description = "만료됨 (기존의 협의된 내용은 아니지만 어드민페이지에 필요하다고 생각했습니다. 추가 부탁드립니다.)", value = "EXPIRED"),
@ExampleObject(name = "ALL", description = "전체", value = "ALL")}) @RequestParam(name = "status", defaultValue = "ALL") @ValidEnum(value = PictureGenerateResponseStatusForAdmin.class, hasAllOption = true) String status,
@Parameter(description = "유저의 email") @RequestParam(name = "email", required = false) @Email(message = "올바른 email 형식이 아닙니다.") String email) {
Sort.Direction sortDirection = Sort.Direction.fromString(direction);
Pageable pageable = PageRequest.of(page, size, Sort.by(sortDirection, sortBy));
if (email != null) {
return success(pictureGenerateRequestUseCase.getAllCreatorSubmittedByRequesterEmail(email, pageable));
}
if ("ALL".equalsIgnoreCase(status)) {
return success(pictureGenerateRequestUseCase.getAllCreatorSubmitted(pageable));
} else {
return success(pictureGenerateRequestUseCase.getAllCreatorSubmittedByPGRESStatus(
PictureGenerateResponseStatusForAdmin.valueOf(status), pageable));
}
}

@Logging(item = LogItem.PGREQ, action = LogAction.VIEW, requester = LogRequester.ADMIN)
@DeleteMapping("/{pictureGenerateRequestId}")
public ResponseEntity<ApiResult<Boolean>> cancelRequest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public interface PictureGenerateRequestPort {

PictureGenerateRequest save(PictureGenerateRequest pictureGenerateRequest);

Page<PictureGenerateResponse> findByPGRESStatusInAndMatchToAdminIs(List<PictureGenerateResponseStatus> statusList,
Page<PictureGenerateResponse> findByPGRESStatusInAndMatchToAdminIsAndPaidIsNull(List<PictureGenerateResponseStatus> statusList,
boolean matchToAdmin, Pageable pageable);

Page<PictureGenerateRequest> findAll(Pageable pageable);

Page<PictureGenerateRequest> findByMatchToAdminIs(boolean matchToAdmin, Pageable pageable);
Page<PictureGenerateRequest> findByMatchToAdminIsAndPaidIsNull(boolean matchToAdmin, Pageable pageable);

Page<PictureGenerateRequest> findByMatchToAdminIsAndPaidIsNotNull(boolean matchToAdmin, Pageable pageable);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ public class PictureGenerateRequestService implements PictureGenerateRequestUseC

@Override
public Page<PGREQAdminMatchedDetailFindByAdminResponseDto> getAllAdminMatched(Pageable pageable) {
return pictureGenerateRequestPort.findByMatchToAdminIs(true, pageable)
return pictureGenerateRequestPort.findByMatchToAdminIsAndPaidIsNull(true, pageable)
.map(convertPGREQToAdminMatchedResponseDto());
}

@Override
public Page<PGREQAdminMatchedDetailFindByAdminResponseDto> getAllAdminMatchedByPGRESStatus(
PictureGenerateResponseStatusForAdmin statusForAdmin, Pageable pageable) {
return pictureGenerateRequestPort.findByPGRESStatusInAndMatchToAdminIs(
return pictureGenerateRequestPort.findByPGRESStatusInAndMatchToAdminIsAndPaidIsNull(
pgresStatusToPGRESStatusForAdminMapper.clientToDb(statusForAdmin), true, pageable)
.map(convertPGRESToAdminMatchedResponseDto());
}
Expand Down Expand Up @@ -106,20 +106,6 @@ public Page<PGREQAdminMatchedDetailFindByAdminResponseDto> getAllPaidAdminMatche
.map(convertPGREQToAdminMatchedResponseDto());
}

@Override
public Page<PGREQCreatorSubmittedDetailFindByAdminResponseDto> getAllCreatorSubmitted(Pageable pageable) {
return pictureGenerateRequestPort.findByMatchToAdminIs(false, pageable)
.map(convertPGREQToCreatorSubmittedResponseDto());
}

@Override
public Page<PGREQCreatorSubmittedDetailFindByAdminResponseDto> getAllCreatorSubmittedByPGRESStatus(
PictureGenerateResponseStatusForAdmin statusForAdmin, Pageable pageable) {
return pictureGenerateRequestPort.findByPGRESStatusInAndMatchToAdminIs(
pgresStatusToPGRESStatusForAdminMapper.clientToDb(statusForAdmin), false, pageable)
.map(convertPGRESToCreatorSubmittedResponseDto());
}

@Override
public Page<PGREQCreatorSubmittedDetailFindByAdminResponseDto> getAllCreatorSubmittedByRequesterEmail(String email,
Pageable pageable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

Expand All @@ -20,7 +21,7 @@ public class UserPurchaseController {
@PostMapping("/google/receipt-validation")
public ResponseEntity<GentiResponse.ApiResult<Boolean>> validateReceipt(
@AuthUser Long userId,
PurchaseRequestDto purchaseRequestDto) {
@RequestBody PurchaseRequestDto purchaseRequestDto) {
return GentiResponse.success(inAppPurchaseService.validateReceipt(userId, purchaseRequestDto));
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.gt.genti.purchase.dto.request;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED) // 있어야함
public class PurchaseRequestDto {
private String packageName; //인앱 상품이 판매된 애플리케이션의 패키지 이름
private String productId; //인앱 상품 SKU
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,67 +31,55 @@ public class InAppPurchaseService {

public Boolean validateReceipt(Long userId, PurchaseRequestDto purchaseRequestDto) {

// try {
// ================= Google Credential 생성 =================

JsonFactory JSON_FACTORY = GsonFactory.getDefaultInstance();

AndroidPublisher.Builder builder;
HttpTransport httpTransport;
try {
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
httpTransport = GoogleNetHttpTransport.newTrustedTransport();
} catch (IOException | GeneralSecurityException e1) {
throw ExpectedException.withLogging(ResponseCode.HttpMessageNotReadable, e1);
}

InputStream inputStream = new ClassPathResource(googleAccountFilePath).getInputStream();
GoogleCredentials credentials = GoogleCredentials
.fromStream(inputStream)
.createScoped(AndroidPublisherScopes.ANDROIDPUBLISHER);
builder = new AndroidPublisher.Builder(httpTransport, JSON_FACTORY, new HttpCredentialsAdapter(credentials));
} catch (IOException | GeneralSecurityException e){
throw ExpectedException.withLogging(ResponseCode.CashoutNotFound,
"---------------------------------------구매 에러 IOException, GeneralSecurityException 에러 1111111111: " + e + "-------------------------------------------------");
InputStream inputStream;
try {
inputStream = new ClassPathResource(googleAccountFilePath).getInputStream();
} catch (IOException e2) {
throw ExpectedException.withLogging(ResponseCode.HandlerNotFound, e2);
}

AndroidPublisher publisher;
GoogleCredentials credentials;
try {
// ======================== API 호출 ========================
publisher = builder.setApplicationName(googleApplicationPackageName).build();
AndroidPublisher.Purchases.Products.Get gas = publisher.purchases()
.products()
.get(
"packageName",
"productId",
"purchaseToken");
ProductPurchase purchase = gas.execute();
} catch (IOException e){
throw ExpectedException.withLogging(ResponseCode.HttpMessageNotReadable,
"---------------------------------------구매 에러 IOException 에러 2222222222: " + e + "-------------------------------------------------");
credentials = GoogleCredentials
.fromStream(inputStream)
.createScoped(AndroidPublisherScopes.ANDROIDPUBLISHER);
} catch (IOException e3) {
throw ExpectedException.withLogging(ResponseCode.AlreadyActivatedUser, e3);
}

builder = new AndroidPublisher.Builder(httpTransport, JSON_FACTORY, new HttpCredentialsAdapter(credentials));

AndroidPublisher publisher = builder.setApplicationName(purchaseRequestDto.getPackageName()).build();

try{
try {
AndroidPublisher.Purchases.Products.Get get = publisher.purchases().products()
.get(purchaseRequestDto.getPackageName(), purchaseRequestDto.getProductId(), purchaseRequestDto.getPurchaseToken()); //inapp 아이템의 구매 및 소모 상태 확인
.get(purchaseRequestDto.getPackageName(), purchaseRequestDto.getProductId(), purchaseRequestDto.getPurchaseToken());
ProductPurchase productPurchase = get.execute(); //검증 결과
System.out.println(productPurchase.toPrettyString());

// 인앱 상품의 소비 상태. 0 아직 소비 안됨(Yet to be consumed) / 1 소비됨(Consumed)
Integer consumptionState = productPurchase.getConsumptionState();

// 개발자가 지정한 임의 문자열 정보
String developerPayload = productPurchase.getDeveloperPayload();
// 상품이 구매된 시각. 타임스탬프 형태
Long purchaseTimeMillis = productPurchase.getPurchaseTimeMillis();

// 구매 상태. 0 구매완료 / 1 취소됨
Integer purchaseState = productPurchase.getPurchaseState();
if(purchaseState == 1){
if (purchaseState == 1) {
return false;
}

// 상품이 구매된 시각. 타임스탬프 형태
Long purchaseTimeMillis = productPurchase.getPurchaseTimeMillis();

return true;
} catch (IOException e) {
throw ExpectedException.withLogging(ResponseCode.FileTypeNotProvided,
"---------------------------------------구매 에러 IOException 에러 333333333333: " + e + "-------------------------------------------------");
} catch (IOException e5) {
throw ExpectedException.withLogging(ResponseCode.FileTypeNotProvided, e5);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ Page<PGREQAdminMatchedDetailFindByAdminResponseDto> getAllAdminMatchedByRequeste

Page<PGREQAdminMatchedDetailFindByAdminResponseDto> getAllPaidAdminMatchedByRequesterEmail(String email, Pageable pageable);

Page<PGREQCreatorSubmittedDetailFindByAdminResponseDto> getAllCreatorSubmitted(Pageable pageable);

Page<PGREQCreatorSubmittedDetailFindByAdminResponseDto> getAllCreatorSubmittedByPGRESStatus(
PictureGenerateResponseStatusForAdmin statusForAdmin, Pageable pageable);

Page<PGREQCreatorSubmittedDetailFindByAdminResponseDto> getAllCreatorSubmittedByRequesterEmail(String email,
Pageable pageable);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,6 @@ public ResponseEntity<ApiResult<UserFindResponseDto>> getUserInfo(
return GentiResponse.success(userService.getUserInfo(userId));
}

@PutMapping("/api/v1/users")
public ResponseEntity<ApiResult<UserFindResponseDto>> updateUserInfo(
@AuthUser Long userId,
@RequestBody @Valid UserInfoUpdateRequestDto userInfoUpdateRequestDto) {
return GentiResponse.success(userService.updateUserInfo(userId, userInfoUpdateRequestDto));
}

@PostMapping("/api/v1/users/signup")
@Logging(item = LogItem.USER, action = LogAction.SIGNUP, requester = LogRequester.ANONYMOUS)
public ResponseEntity<ApiResult<SignUpResponseDTO>> signUp(
Expand Down

This file was deleted.

Loading

0 comments on commit 462e48d

Please sign in to comment.