From 7abcc71a64d7a741ec3e731fa450131b0f79a078 Mon Sep 17 00:00:00 2001 From: jungeun Date: Tue, 6 Aug 2024 02:58:01 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20S3=20=EC=97=90=20=EC=9D=B4=EB=AF=B8?= =?UTF-8?q?=EC=A7=80=20=EC=97=85=EB=A1=9C=EB=93=9C=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 15 +++++++- build.gradle | 9 +++++ .../example/likelion12/config/S3Config.java | 35 +++++++++++++++++ .../likelion12/controller/CrewController.java | 4 +- .../controller/SocialringController.java | 8 ++-- .../likelion12/dto/crew/PostCrewRequest.java | 3 +- .../PatchSocialringModifyRequest.java | 3 +- .../dto/socialring/PostSocialringRequest.java | 7 +++- .../likelion12/service/CrewService.java | 9 +++-- .../likelion12/service/SocialringService.java | 27 +++++++------ .../example/likelion12/util/S3Uploader.java | 38 +++++++++++++++++++ src/main/resources/application.yml | 12 ++++++ 12 files changed, 145 insertions(+), 25 deletions(-) create mode 100644 src/main/java/com/example/likelion12/config/S3Config.java create mode 100644 src/main/java/com/example/likelion12/util/S3Uploader.java diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 9f10950..860c950 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -21,6 +21,11 @@ jobs: WAS_HOST: ${{ secrets.WAS_HOST }} JWT_SECRET: ${{ secrets.JWT_SECRET }} CLIENT_ID: ${{ secrets.CLIENT_ID }} + AWS_S3_BUCKET_NAME: ${{ secrets.AWS_S3_BUCKET_NAME }} + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_REGION: ap-northeast-2 + steps: - name: Checkout repository uses: actions/checkout@v3 @@ -62,6 +67,10 @@ jobs: --build-arg DB_PROD_PASSWD=${{ secrets.DB_PROD_PASSWD }} \ --build-arg JWT_SECRET=${{ secrets.JWT_SECRET }} \ --build-arg CLIENT_ID=${{ secrets.CLIENT_ID }} \ + --build-arg AWS_S3_BUCKET_NAME=${{ secrets.AWS_S3_BUCKET_NAME }} \ + --build-arg AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }} \ + --build-arg AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }} \ + --build-arg AWS_REGION=ap-northeast-2 \ -t likelion12/likelion12baby:latest . docker images docker push likelion12/likelion12baby:latest @@ -89,8 +98,12 @@ jobs: -e DB_PROD_PASSWD=${{ secrets.DB_PROD_PASSWD }} \ -e JWT_SECRET=${{ secrets.JWT_SECRET }} \ -e CLIENT_ID=${{ secrets.CLIENT_ID }} \ + -e AWS_S3_BUCKET_NAME=${{ secrets.AWS_S3_BUCKET_NAME }} \ + -e AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }} \ + -e AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }} \ + -e AWS_REGION=ap-northeast-2 \ -p 8080:8080 ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPO_NAME }} - sudo docker logs $(sudo docker ps -q --filter ancestor=${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPO_NAME }}) + sudo docker logs $(sudo docker ps -q —filter ancestor=${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPO_NAME }}) sudo docker image prune -f \ No newline at end of file diff --git a/build.gradle b/build.gradle index 4893871..1c1b598 100644 --- a/build.gradle +++ b/build.gradle @@ -40,6 +40,15 @@ dependencies { implementation 'org.json:json:20210307' implementation 'org.springframework.boot:spring-boot-starter-data-redis' implementation 'javax.servlet:javax.servlet-api:4.0.1' // 서블릿 API 추가 + + // AWS SDK + implementation platform('com.amazonaws:aws-java-sdk-bom:1.11.228') + implementation 'com.amazonaws:aws-java-sdk-s3' + // JAXB API + implementation 'javax.xml.bind:jaxb-api:2.3.1' + + // JAXB runtime dependencies + implementation 'org.glassfish.jaxb:jaxb-runtime:2.3.1' } tasks.named('test') { diff --git a/src/main/java/com/example/likelion12/config/S3Config.java b/src/main/java/com/example/likelion12/config/S3Config.java new file mode 100644 index 0000000..4bff75a --- /dev/null +++ b/src/main/java/com/example/likelion12/config/S3Config.java @@ -0,0 +1,35 @@ +package com.example.likelion12.config; + +import com.amazonaws.auth.AWSStaticCredentialsProvider; +import com.amazonaws.auth.BasicAWSCredentials; +import com.amazonaws.services.s3.AmazonS3; +import com.amazonaws.services.s3.AmazonS3ClientBuilder; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class S3Config { + + @Value("${spring.s3.bucket-name}") + private String bucketName; + + @Value("${spring.s3.access-key}") + private String accessKey; + + @Value("${spring.s3.secret-key}") + private String secretKey; + + @Value("${spring.s3.region}") + private String region; + + @Bean + public AmazonS3 amazonS3() { + BasicAWSCredentials awsCreds = new BasicAWSCredentials(accessKey, secretKey); + return AmazonS3ClientBuilder.standard() + .withRegion(region) + .withCredentials(new AWSStaticCredentialsProvider(awsCreds)) + .build(); + } +} + diff --git a/src/main/java/com/example/likelion12/controller/CrewController.java b/src/main/java/com/example/likelion12/controller/CrewController.java index a80b542..e59d2b4 100644 --- a/src/main/java/com/example/likelion12/controller/CrewController.java +++ b/src/main/java/com/example/likelion12/controller/CrewController.java @@ -8,6 +8,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; +import java.io.IOException; import java.util.List; @Slf4j @@ -24,11 +25,12 @@ public class CrewController { */ @PostMapping("") public BaseResponse createCrew(@RequestHeader("Authorization") String authorization, - @RequestBody PostCrewRequest postCrewRequest){ + @ModelAttribute PostCrewRequest postCrewRequest) throws IOException { log.info("[CrewController.createCrew]"); Long memberId = jwtProvider.extractIdFromHeader(authorization); return new BaseResponse<>(crewService.createCrew(memberId, postCrewRequest)); } + /** * 크루 조회 */ diff --git a/src/main/java/com/example/likelion12/controller/SocialringController.java b/src/main/java/com/example/likelion12/controller/SocialringController.java index dc86c1a..b0ce6f2 100644 --- a/src/main/java/com/example/likelion12/controller/SocialringController.java +++ b/src/main/java/com/example/likelion12/controller/SocialringController.java @@ -2,7 +2,6 @@ import com.example.likelion12.common.response.BaseResponse; import com.example.likelion12.common.response.status.BaseExceptionResponseStatus; -import com.example.likelion12.dto.crew.GetCrewInquiryResponse; import com.example.likelion12.dto.socialring.*; import com.example.likelion12.service.SocialringService; import com.example.likelion12.util.*; @@ -10,6 +9,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; +import java.io.IOException; import java.util.List; @Slf4j @@ -27,8 +27,7 @@ public class SocialringController { */ @PostMapping("") public BaseResponse createSocialring(@RequestHeader("Authorization") String authorization , - @RequestBody PostSocialringRequest postSocialringRequest) - { //헤더에서 소셜링 등록하는 멤버아이디 찾기 + @RequestBody PostSocialringRequest postSocialringRequest) throws IOException { //헤더에서 소셜링 등록하는 멤버아이디 찾기 Long memberId = jwtProvider.extractIdFromHeader(authorization); return new BaseResponse<>(socialringService.createSocialring(memberId,postSocialringRequest)); } @@ -38,8 +37,7 @@ public BaseResponse createSocialring(@RequestHeader("Aut */ @PatchMapping("") public BaseResponse modifySocialring(@RequestHeader("Authorization") String authorization, @RequestParam long socialringId, - @RequestBody PatchSocialringModifyRequest patchSocialringModifyRequest) - { + @RequestBody PatchSocialringModifyRequest patchSocialringModifyRequest) throws IOException { Long memberId = jwtProvider.extractIdFromHeader(authorization); socialringService.modifySocialring(memberId,socialringId,patchSocialringModifyRequest); return new BaseResponse<>(BaseExceptionResponseStatus.SUCCESS, null); diff --git a/src/main/java/com/example/likelion12/dto/crew/PostCrewRequest.java b/src/main/java/com/example/likelion12/dto/crew/PostCrewRequest.java index aa08e71..a1be689 100644 --- a/src/main/java/com/example/likelion12/dto/crew/PostCrewRequest.java +++ b/src/main/java/com/example/likelion12/dto/crew/PostCrewRequest.java @@ -4,6 +4,7 @@ import com.example.likelion12.domain.base.BaseLevel; import lombok.AllArgsConstructor; import lombok.Getter; +import org.springframework.web.multipart.MultipartFile; @Getter @AllArgsConstructor @@ -12,7 +13,7 @@ public class PostCrewRequest { * 크루 등록 request dto */ private String crewName; - private String crewImg; + private MultipartFile crewImg; private Long activityRegionId; private Long facilityId; private Long exerciseId; diff --git a/src/main/java/com/example/likelion12/dto/socialring/PatchSocialringModifyRequest.java b/src/main/java/com/example/likelion12/dto/socialring/PatchSocialringModifyRequest.java index 61ad652..2307319 100644 --- a/src/main/java/com/example/likelion12/dto/socialring/PatchSocialringModifyRequest.java +++ b/src/main/java/com/example/likelion12/dto/socialring/PatchSocialringModifyRequest.java @@ -4,6 +4,7 @@ import com.example.likelion12.domain.base.BaseLevel; import lombok.AllArgsConstructor; import lombok.Getter; +import org.springframework.web.multipart.MultipartFile; import java.time.LocalDate; @@ -14,7 +15,7 @@ public class PatchSocialringModifyRequest { * 소셜링 수정 request dto */ private String socialringName; - private String socialringImg; + private MultipartFile socialringImg; private String activityRegionName; private String facilityName; private String exerciseName; diff --git a/src/main/java/com/example/likelion12/dto/socialring/PostSocialringRequest.java b/src/main/java/com/example/likelion12/dto/socialring/PostSocialringRequest.java index 8cee371..aa2370a 100644 --- a/src/main/java/com/example/likelion12/dto/socialring/PostSocialringRequest.java +++ b/src/main/java/com/example/likelion12/dto/socialring/PostSocialringRequest.java @@ -3,18 +3,21 @@ import com.example.likelion12.domain.base.BaseGender; import com.example.likelion12.domain.base.BaseLevel; import lombok.AllArgsConstructor; +import lombok.Data; import lombok.Getter; +import org.springframework.web.multipart.MultipartFile; +import java.io.File; import java.time.LocalDate; -@Getter +@Data @AllArgsConstructor public class PostSocialringRequest { /** * 소셜링 등록 request dto */ private String socialringName; - private String socialringImg; + private MultipartFile socialringImg; private long activityRegionId; private long facilityId; private long exerciseId; diff --git a/src/main/java/com/example/likelion12/service/CrewService.java b/src/main/java/com/example/likelion12/service/CrewService.java index 0a98c98..948711e 100644 --- a/src/main/java/com/example/likelion12/service/CrewService.java +++ b/src/main/java/com/example/likelion12/service/CrewService.java @@ -1,7 +1,6 @@ package com.example.likelion12.service; import com.example.likelion12.common.exception.*; -import com.example.likelion12.common.response.BaseResponse; import com.example.likelion12.domain.*; import com.example.likelion12.domain.base.BaseGender; import com.example.likelion12.domain.base.BaseLevel; @@ -9,6 +8,7 @@ import com.example.likelion12.domain.base.BaseStatus; import com.example.likelion12.dto.crew.*; import com.example.likelion12.repository.*; +import com.example.likelion12.util.S3Uploader; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.Pageable; @@ -16,6 +16,7 @@ import org.springframework.transaction.annotation.Transactional; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -35,19 +36,19 @@ public class CrewService { private final MemberRepository memberRepository; private final MemberCrewService memberCrewService; private final MemberCrewRepository memberCrewRepository; + private final S3Uploader s3Uploader; /** * 크루 등록 */ @Transactional - public PostCrewResponse createCrew(Long memberId, PostCrewRequest postCrewRequest){ + public PostCrewResponse createCrew(Long memberId, PostCrewRequest postCrewRequest) throws IOException { log.info("[CrewService.createCrew]"); Member member = memberRepository.findByMemberIdAndStatus(memberId, BaseStatus.ACTIVE) .orElseThrow(()-> new MemberException(CANNOT_FOUND_MEMBER)); String crewName = postCrewRequest.getCrewName(); - String crewImg = postCrewRequest.getCrewImg(); Long activityRegionId = postCrewRequest.getActivityRegionId(); Long facilityId = postCrewRequest.getFacilityId(); Long exerciseId = postCrewRequest.getExerciseId(); @@ -67,6 +68,7 @@ public PostCrewResponse createCrew(Long memberId, PostCrewRequest postCrewReques Exercise exercise = exerciseRepository.findByExerciseIdAndStatus(exerciseId,BaseStatus.ACTIVE) .orElseThrow(()-> new ExerciseException(CANNOT_FOUND_EXERCISE)); + String crewImg = s3Uploader.uploadFileToS3(postCrewRequest.getCrewImg(),"crew/"); Crew crew = new Crew(crewName, crewImg, totalRecruits, crewCost,simpleComment,comment ,gender,level,activityRegion,facility, exercise, BaseStatus.ACTIVE); crewRepository.save(crew); @@ -75,6 +77,7 @@ public PostCrewResponse createCrew(Long memberId, PostCrewRequest postCrewReques return new PostCrewResponse(crew.getCrewId()); } + /** * 크루 조회 */ diff --git a/src/main/java/com/example/likelion12/service/SocialringService.java b/src/main/java/com/example/likelion12/service/SocialringService.java index 0c226e3..d7db826 100644 --- a/src/main/java/com/example/likelion12/service/SocialringService.java +++ b/src/main/java/com/example/likelion12/service/SocialringService.java @@ -8,12 +8,15 @@ import com.example.likelion12.domain.base.BaseStatus; import com.example.likelion12.dto.socialring.*; import com.example.likelion12.repository.*; +import com.example.likelion12.util.S3Uploader; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; +import java.io.IOException; import java.time.LocalDate; import java.util.ArrayList; import java.util.List; @@ -25,6 +28,7 @@ @Slf4j @Service @RequiredArgsConstructor +@Transactional(readOnly = true) public class SocialringService { private final SocialringRepository socialringRepository; private final MemberRepository memberRepository; @@ -33,18 +37,19 @@ public class SocialringService { private final MemberSocialringService memberSocialringService; private final ActivityRegionRepository activityRegionRepository; private final MemberSocialringRepository memberSocialringRepository; + private final S3Uploader s3Uploader; /** * 소셜링 등록 */ @Transactional - public PostSocialringResponse createSocialring(Long memberId, PostSocialringRequest postSocialringRequest) { + public PostSocialringResponse createSocialring(Long memberId, PostSocialringRequest postSocialringRequest) throws IOException { log.info("[SocialringService.createSocialring]"); Member member = memberRepository.findByMemberIdAndStatus(memberId, BaseStatus.ACTIVE) .orElseThrow(() -> new MemberException(CANNOT_FOUND_MEMBER)); String socialringName = postSocialringRequest.getSocialringName(); - String socialringImg = postSocialringRequest.getSocialringImg(); + MultipartFile socialringImg = postSocialringRequest.getSocialringImg(); long activityRegionId = postSocialringRequest.getActivityRegionId(); long facilityId = postSocialringRequest.getFacilityId(); long exerciseId = postSocialringRequest.getExerciseId(); @@ -63,7 +68,8 @@ public PostSocialringResponse createSocialring(Long memberId, PostSocialringRequ Exercise exercise = exerciseRepository.findByExerciseIdAndStatus(exerciseId, BaseStatus.ACTIVE) .orElseThrow(() -> new ExerciseException(CANNOT_FOUND_EXERCISE)); - Socialring socialring = new Socialring(socialringName, socialringImg, totalRecruits, socialringDate, socialringCost, comment, commentSimple, + String socialringImgUrl = s3Uploader.uploadFileToS3(socialringImg,"socialring/"); + Socialring socialring = new Socialring(socialringName, socialringImgUrl, totalRecruits, socialringDate, socialringCost, comment, commentSimple, gender, level, activityRegion, facility, exercise, BaseStatus.ACTIVE); socialringRepository.save(socialring); @@ -76,7 +82,7 @@ public PostSocialringResponse createSocialring(Long memberId, PostSocialringRequ * 소셜링 수정 */ @Transactional - public void modifySocialring(Long memberId, Long socialringId, PatchSocialringModifyRequest patchSocialringModifyRequest) { + public void modifySocialring(Long memberId, Long socialringId, PatchSocialringModifyRequest patchSocialringModifyRequest) throws IOException { log.info("[SocialringService.modifySocialring]"); //소셜링을 수정하고자 하는 멤버 @@ -96,8 +102,6 @@ public void modifySocialring(Long memberId, Long socialringId, PatchSocialringMo String newSocialringName = patchSocialringModifyRequest.getSocialringName() == null ? socialring.getSocialringName() : patchSocialringModifyRequest.getSocialringName(); - String newSocialringImg = patchSocialringModifyRequest.getSocialringImg() - == null ? socialring.getSocialringImg() : patchSocialringModifyRequest.getSocialringImg(); Integer newTotalRecruits = patchSocialringModifyRequest.getTotalRecruits() == null ? socialring.getTotalRecruits() : patchSocialringModifyRequest.getTotalRecruits(); LocalDate newSocialringDate = patchSocialringModifyRequest.getSocialringDate() @@ -116,10 +120,10 @@ public void modifySocialring(Long memberId, Long socialringId, PatchSocialringMo long newActivityRegionId = patchSocialringModifyRequest.getActivityRegionName() == null ? socialring.getActivityRegion().getActivityRegionId() : - //리퀘스트로 들어온값이 존재하는 값인지 네임으로 찾아서 아이디값 반환 후 아이디값 수정 - activityRegionRepository.findByActivityRegionNameAndStatus( - patchSocialringModifyRequest.getActivityRegionName(), BaseStatus.ACTIVE) - .orElseThrow(() -> new ActivityRegionException(CANNOT_FOUND_ACTIVITYREGION)).getActivityRegionId(); + //리퀘스트로 들어온값이 존재하는 값인지 네임으로 찾아서 아이디값 반환 후 아이디값 수정 + activityRegionRepository.findByActivityRegionNameAndStatus( + patchSocialringModifyRequest.getActivityRegionName(), BaseStatus.ACTIVE) + .orElseThrow(() -> new ActivityRegionException(CANNOT_FOUND_ACTIVITYREGION)).getActivityRegionId(); long newFacilityId = patchSocialringModifyRequest.getFacilityName() == null ? socialring.getFacility().getFacilityId() : facilityRepository.findByFacilityNameAndStatus( @@ -138,7 +142,8 @@ public void modifySocialring(Long memberId, Long socialringId, PatchSocialringMo Exercise exercise = exerciseRepository.findByExerciseIdAndStatus(newExerciseId, BaseStatus.ACTIVE) .orElseThrow(() -> new ExerciseException(CANNOT_FOUND_EXERCISE)); - + String newSocialringImg = patchSocialringModifyRequest.getSocialringImg() + == null ? socialring.getSocialringImg() : s3Uploader.uploadFileToS3(patchSocialringModifyRequest.getSocialringImg(),"socialring/"); //변경사항 업데이트 및 저장 socialring.UpdateSocialringInfo(newSocialringName, newSocialringImg, newTotalRecruits, newSocialringDate, newSocialringCost, newComment, newCommentSimple, newGender, newLevel, activityRegion, facility, exercise); diff --git a/src/main/java/com/example/likelion12/util/S3Uploader.java b/src/main/java/com/example/likelion12/util/S3Uploader.java new file mode 100644 index 0000000..757ed3a --- /dev/null +++ b/src/main/java/com/example/likelion12/util/S3Uploader.java @@ -0,0 +1,38 @@ +package com.example.likelion12.util; + +import com.amazonaws.services.s3.model.PutObjectRequest; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Component; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; +import java.io.InputStream; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; +import com.amazonaws.services.s3.AmazonS3; +@RequiredArgsConstructor +@Component +@Slf4j +public class S3Uploader { + + private final AmazonS3 amazonS3; + @Value("${spring.s3.bucket-name}") + private String bucketName; + @Value("${spring.s3.secret-key}") + private String secretKey; + + public String uploadFileToS3(MultipartFile file, String folder) throws IOException { + log.info("[S3Uploader.uploadFileToS3]"); + String fileName = folder + UUID.randomUUID().toString() + "_" + file.getOriginalFilename(); /** 템플릿 코드 : 고유한 아이디를 부여하는 코드라고 합니다! */ + try (InputStream inputStream = file.getInputStream()) { + amazonS3.putObject(new PutObjectRequest(bucketName, fileName, inputStream, null)); + } + String fileUrl = String.valueOf(amazonS3.getUrl(bucketName,secretKey)); + return fileUrl; + } + +} + diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 0f93bb8..678c7ab 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -2,6 +2,18 @@ spring: profiles: active: ${PROFILE} + servlet: + multipart: + enabled: true + max-file-size: 10MB + max-request-size: 10MB + + s3: + bucket-name: ${AWS_S3_BUCKET_NAME} + access-key: ${AWS_ACCESS_KEY_ID} + secret-key: ${AWS_SECRET_ACCESS_KEY} + region: ${AWS_REGION} + --- spring: config: From 9f40bc34a018c3b5a7e58ef1668a7679b9f5c603 Mon Sep 17 00:00:00 2001 From: jungeun Date: Tue, 6 Aug 2024 03:09:13 +0900 Subject: [PATCH 2/3] =?UTF-8?q?feat=20:=20Name=20=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B0=98=ED=99=98=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/likelion12/dto/crew/PostCrewRequest.java | 6 +++--- .../com/example/likelion12/service/CrewService.java | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/example/likelion12/dto/crew/PostCrewRequest.java b/src/main/java/com/example/likelion12/dto/crew/PostCrewRequest.java index a1be689..a2de836 100644 --- a/src/main/java/com/example/likelion12/dto/crew/PostCrewRequest.java +++ b/src/main/java/com/example/likelion12/dto/crew/PostCrewRequest.java @@ -14,9 +14,9 @@ public class PostCrewRequest { */ private String crewName; private MultipartFile crewImg; - private Long activityRegionId; - private Long facilityId; - private Long exerciseId; + private String activityRegionName; + private String facilityName; + private String exerciseName; private int totalRecruits; private int crewCost; private String simpleComment; diff --git a/src/main/java/com/example/likelion12/service/CrewService.java b/src/main/java/com/example/likelion12/service/CrewService.java index 948711e..7c89d29 100644 --- a/src/main/java/com/example/likelion12/service/CrewService.java +++ b/src/main/java/com/example/likelion12/service/CrewService.java @@ -49,9 +49,9 @@ public PostCrewResponse createCrew(Long memberId, PostCrewRequest postCrewReques .orElseThrow(()-> new MemberException(CANNOT_FOUND_MEMBER)); String crewName = postCrewRequest.getCrewName(); - Long activityRegionId = postCrewRequest.getActivityRegionId(); - Long facilityId = postCrewRequest.getFacilityId(); - Long exerciseId = postCrewRequest.getExerciseId(); + String activityRegionName = postCrewRequest.getActivityRegionName(); + String facilityName = postCrewRequest.getFacilityName(); + String exerciseName = postCrewRequest.getExerciseName(); int totalRecruits = postCrewRequest.getTotalRecruits(); int crewCost = postCrewRequest.getCrewCost(); String simpleComment = postCrewRequest.getSimpleComment(); @@ -59,13 +59,13 @@ public PostCrewResponse createCrew(Long memberId, PostCrewRequest postCrewReques BaseGender gender = postCrewRequest.getGender(); BaseLevel level = postCrewRequest.getLevel(); - ActivityRegion activityRegion = activityRegionRepository.findByActivityRegionIdAndStatus(activityRegionId, BaseStatus.ACTIVE) + ActivityRegion activityRegion = activityRegionRepository.findByActivityRegionNameAndStatus(activityRegionName, BaseStatus.ACTIVE) .orElseThrow(()-> new ActivityRegionException(CANNOT_FOUND_ACTIVITYREGION)); - Facility facility = facilityRepository.findByFacilityIdAndStatus(facilityId, BaseStatus.ACTIVE) + Facility facility = facilityRepository.findByFacilityNameAndStatus(facilityName, BaseStatus.ACTIVE) .orElseThrow(()-> new FacilityException(CANOOT_FOUND_FACILITY)); - Exercise exercise = exerciseRepository.findByExerciseIdAndStatus(exerciseId,BaseStatus.ACTIVE) + Exercise exercise = exerciseRepository.findByExerciseNameAndStatus(exerciseName,BaseStatus.ACTIVE) .orElseThrow(()-> new ExerciseException(CANNOT_FOUND_EXERCISE)); String crewImg = s3Uploader.uploadFileToS3(postCrewRequest.getCrewImg(),"crew/"); From df8cad60e5d2aa13b0af56505dddb53978a5d3cf Mon Sep 17 00:00:00 2001 From: jungeun Date: Tue, 6 Aug 2024 03:16:21 +0900 Subject: [PATCH 3/3] =?UTF-8?q?feat=20:=20=EC=82=AC=EC=A7=84=20=EC=97=85?= =?UTF-8?q?=EB=A1=9C=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/example/likelion12/util/S3Uploader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/example/likelion12/util/S3Uploader.java b/src/main/java/com/example/likelion12/util/S3Uploader.java index 757ed3a..86f1bcc 100644 --- a/src/main/java/com/example/likelion12/util/S3Uploader.java +++ b/src/main/java/com/example/likelion12/util/S3Uploader.java @@ -30,7 +30,7 @@ public String uploadFileToS3(MultipartFile file, String folder) throws IOExcepti try (InputStream inputStream = file.getInputStream()) { amazonS3.putObject(new PutObjectRequest(bucketName, fileName, inputStream, null)); } - String fileUrl = String.valueOf(amazonS3.getUrl(bucketName,secretKey)); + String fileUrl = String.valueOf(amazonS3.getUrl(bucketName,fileName)); return fileUrl; }