Skip to content

Commit

Permalink
refact : 변수명 리팩토링
Browse files Browse the repository at this point in the history
  • Loading branch information
redblackblossom committed Aug 10, 2024
1 parent 31f39a8 commit 9fbc4a1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,33 @@
import com.amazonaws.services.lambda.AWSLambda;
import com.amazonaws.services.lambda.model.InvocationType;
import com.amazonaws.services.lambda.model.InvokeRequest;
import com.amazonaws.services.lambda.model.InvokeResult;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.umc.naoman.domain.shareGroup.service.ShareGroupService;
import com.umc.naoman.global.error.BusinessException;
import com.umc.naoman.global.error.code.AwsLambdaErrorCode;
import lombok.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
public class FaceDetectionServiceImpl implements FaceDetectionService{
@Value("${spring.lambda.function.detect_face_photo}")
private String detectFacePhotoLambda;
@Value("${spring.lambda.function.join_share_group}")
private String detectFaceShareGroupLambda;
public class FaceDetectionServiceImpl implements FaceDetectionService {
@Value("${spring.lambda.function.detect_face_upload_photo}")
private String detectFaceUploadPhotoLambda;
@Value("${spring.lambda.function.detect_face_join_share_group}")
private String detectFaceJoinShareGroupLambda;
private final AWSLambda awsLambda;
private final ObjectMapper objectMapper = new ObjectMapper();
private final ShareGroupService shareGroupService;

@Getter
@AllArgsConstructor
private class DetectFacePhotoPayload {
private List<String> nameList;
private List<String> photoNameList;
private List<Long> memberIdList;
private Long shareGroupId;
}
Expand All @@ -47,39 +45,37 @@ public void detectFaceUploadPhoto(List<String> photoNameList, Long shareGroupId)
List<Long> memberIdList = shareGroupService.findProfileListByShareGroupId(shareGroupId).stream()
.map(profile -> profile.getMember().getId())
.collect(Collectors.toList());
DetectFacePhotoPayload payLoad = new DetectFacePhotoPayload(photoNameList,memberIdList,shareGroupId);
DetectFacePhotoPayload payLoad = new DetectFacePhotoPayload(photoNameList, memberIdList, shareGroupId);
String lambdaPayload = null;

try {
lambdaPayload = objectMapper.writeValueAsString(payLoad);
} catch (JsonProcessingException e) {
throw new BusinessException(AwsLambdaErrorCode.AWS_JsonProcessing_Exception,e);
throw new BusinessException(AwsLambdaErrorCode.AWS_JsonProcessing_Exception, e);
}
InvokeRequest invokeRequest = new InvokeRequest()
.withInvocationType(InvocationType.Event)
.withFunctionName(detectFacePhotoLambda)
.withInvocationType(InvocationType.Event) //비동기 호출
.withFunctionName(detectFaceUploadPhotoLambda)
.withPayload(lambdaPayload);

awsLambda.invoke(invokeRequest);
}

@Override
public void detectFaceJoinShareGroup(Long memberId, Long shareGroupId) {
DetectFaceShareGroupPayload payLoad = new DetectFaceShareGroupPayload(memberId,shareGroupId);
DetectFaceShareGroupPayload payLoad = new DetectFaceShareGroupPayload(memberId, shareGroupId);
String lambdaPayload = null;

try {
lambdaPayload = objectMapper.writeValueAsString(payLoad);
} catch (JsonProcessingException e) {
throw new BusinessException(AwsLambdaErrorCode.AWS_JsonProcessing_Exception,e);
throw new BusinessException(AwsLambdaErrorCode.AWS_JsonProcessing_Exception, e);
}
InvokeRequest invokeRequest = new InvokeRequest()
.withInvocationType(InvocationType.Event)
.withFunctionName(detectFaceShareGroupLambda)
.withInvocationType(InvocationType.Event) //비동기 호출
.withFunctionName(detectFaceJoinShareGroupLambda)
.withPayload(lambdaPayload);

awsLambda.invoke(invokeRequest);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.springframework.context.annotation.Primary;

@Configuration
public class S3Config {
public class AwsConfig {

@Value("${spring.cloud.aws.credentials.access-key}")
private String accessKey;
Expand Down

0 comments on commit 9fbc4a1

Please sign in to comment.