From a71527540ec15a71dfc39c609c6daa7767296a30 Mon Sep 17 00:00:00 2001 From: test1 Date: Tue, 12 Nov 2024 02:21:27 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat=20:=20=ED=9A=8C=EC=82=AC=20=EA=B8=B0?= =?UTF-8?q?=EB=B3=B8=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=A0=80=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/UserInformationService.java | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/main/java/team18/team18_be/userInformation/service/UserInformationService.java b/src/main/java/team18/team18_be/userInformation/service/UserInformationService.java index 9fb1438..cee8892 100644 --- a/src/main/java/team18/team18_be/userInformation/service/UserInformationService.java +++ b/src/main/java/team18/team18_be/userInformation/service/UserInformationService.java @@ -1,11 +1,13 @@ package team18.team18_be.userInformation.service; +import java.io.IOException; import java.time.LocalDate; import java.util.Collections; import java.util.List; import java.util.NoSuchElementException; import java.util.stream.Collectors; import org.apache.commons.lang3.RandomStringUtils; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; import team18.team18_be.auth.entity.User; @@ -23,7 +25,9 @@ import team18.team18_be.userInformation.repository.CompanyRepository; import team18.team18_be.userInformation.repository.ForeignerInformationRepository; import team18.team18_be.userInformation.repository.SignRepository; - +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; @Service public class UserInformationService { @@ -33,7 +37,8 @@ public class UserInformationService { private final AuthRepository authRepository; private final GcsUploader gcsUploader; private final FileUtil fileUtil; - + @Value("${company.default-logo-url}") + private String defaultLogoUrl; public UserInformationService(ForeignerInformationRepository foreignerInformationRepository, CompanyRepository companyRepository, SignRepository signRepository, @@ -48,11 +53,18 @@ public UserInformationService(ForeignerInformationRepository foreignerInformatio } public Long createCompany(CompanyRequest companyRequest, MultipartFile logoImage, User user) { - byte[] imageFile = fileUtil.safelyGetBytes(logoImage) - .orElseThrow(() -> new IllegalArgumentException("multipart 파일을 읽지 못하였습니다.")); - String storedFileName = gcsUploader.upload(imageFile, "companyLogo", - user.getId().toString() + logoImage.getOriginalFilename()) - .orElseThrow(() -> new NoSuchElementException("파일 업로드에 실패했습니다.")); + byte[] imageFile =null; + String storedFileName = null; + + if (logoImage.isEmpty()){ + storedFileName=defaultLogoUrl; + }else { + imageFile = fileUtil.safelyGetBytes(logoImage) + .orElseThrow(() -> new IllegalArgumentException("multipart 파일을 읽지 못하였습니다.")); + storedFileName = gcsUploader.upload(imageFile, "companyLogo", + user.getId().toString()+"Real"+ logoImage.getOriginalFilename()) + .orElseThrow(() -> new NoSuchElementException("파일 업로드에 실패했습니다.")); + } Company company = new Company(companyRequest.name(), companyRequest.industryOccupation(), companyRequest.brand(), companyRequest.revenuePerYear(), storedFileName, user); Company savedCompany = companyRepository.save(company); @@ -72,7 +84,6 @@ private CompanyResponse createCompanyResponse(Company company) { return companyResponse; } - public Long fillInVisa(VisaRequest visaRequest, User user) { LocalDate visaGenerateDate = LocalDate.parse(visaRequest.visaGenerateDate()); LocalDate visaExpiryDate = visaGenerateDate.plusYears(10); From 09dfa0773d968117a560d0b08158f9b1063ebefb Mon Sep 17 00:00:00 2001 From: test1 Date: Tue, 12 Nov 2024 02:27:32 +0900 Subject: [PATCH 2/3] =?UTF-8?q?refactor=20:=20=EC=BD=94=EB=93=9C=EC=A0=95?= =?UTF-8?q?=EB=A0=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/UserInformationService.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/main/java/team18/team18_be/userInformation/service/UserInformationService.java b/src/main/java/team18/team18_be/userInformation/service/UserInformationService.java index cee8892..58959ef 100644 --- a/src/main/java/team18/team18_be/userInformation/service/UserInformationService.java +++ b/src/main/java/team18/team18_be/userInformation/service/UserInformationService.java @@ -1,6 +1,5 @@ package team18.team18_be.userInformation.service; -import java.io.IOException; import java.time.LocalDate; import java.util.Collections; import java.util.List; @@ -25,9 +24,7 @@ import team18.team18_be.userInformation.repository.CompanyRepository; import team18.team18_be.userInformation.repository.ForeignerInformationRepository; import team18.team18_be.userInformation.repository.SignRepository; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; + @Service public class UserInformationService { @@ -53,16 +50,16 @@ public UserInformationService(ForeignerInformationRepository foreignerInformatio } public Long createCompany(CompanyRequest companyRequest, MultipartFile logoImage, User user) { - byte[] imageFile =null; + byte[] imageFile = null; String storedFileName = null; - if (logoImage.isEmpty()){ - storedFileName=defaultLogoUrl; - }else { + if (logoImage.isEmpty()) { + storedFileName = defaultLogoUrl; + } else { imageFile = fileUtil.safelyGetBytes(logoImage) .orElseThrow(() -> new IllegalArgumentException("multipart 파일을 읽지 못하였습니다.")); storedFileName = gcsUploader.upload(imageFile, "companyLogo", - user.getId().toString()+"Real"+ logoImage.getOriginalFilename()) + user.getId().toString() + "Real" + logoImage.getOriginalFilename()) .orElseThrow(() -> new NoSuchElementException("파일 업로드에 실패했습니다.")); } Company company = new Company(companyRequest.name(), companyRequest.industryOccupation(), From 4c8ba75fa5b681622da23225d2f1efc6b92485c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=B0=EB=AF=BC=EC=88=98?= Date: Tue, 12 Nov 2024 02:39:45 +0900 Subject: [PATCH 3/3] =?UTF-8?q?feat:=20=EC=8A=AC=EB=9D=BC=EC=9D=B4?= =?UTF-8?q?=EB=8D=94=20=EB=B0=B0=EB=84=88=20API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../slider/controller/SliderController.java | 27 +++++++++++++ .../dto/response/SliderImageResponse.java | 7 ++++ .../slider/service/SliderService.java | 39 +++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 src/main/java/team18/team18_be/slider/controller/SliderController.java create mode 100644 src/main/java/team18/team18_be/slider/dto/response/SliderImageResponse.java create mode 100644 src/main/java/team18/team18_be/slider/service/SliderService.java diff --git a/src/main/java/team18/team18_be/slider/controller/SliderController.java b/src/main/java/team18/team18_be/slider/controller/SliderController.java new file mode 100644 index 0000000..ccb5d9a --- /dev/null +++ b/src/main/java/team18/team18_be/slider/controller/SliderController.java @@ -0,0 +1,27 @@ +package team18.team18_be.slider.controller; + +import io.swagger.v3.oas.annotations.tags.Tag; +import java.util.List; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import team18.team18_be.slider.dto.response.SliderImageResponse; +import team18.team18_be.slider.service.SliderService; + +@Tag(name = "슬라이더", description = "슬라이더 관련 API") +@RestController +@RequestMapping("/api/slides") +public class SliderController { + + private final SliderService sliderService; + + public SliderController(SliderService sliderService) { + this.sliderService = sliderService; + } + + @GetMapping + public ResponseEntity> getSliderBanner() { + return ResponseEntity.ok().body(sliderService.getSliderImageUrls()); + } +} diff --git a/src/main/java/team18/team18_be/slider/dto/response/SliderImageResponse.java b/src/main/java/team18/team18_be/slider/dto/response/SliderImageResponse.java new file mode 100644 index 0000000..de88f89 --- /dev/null +++ b/src/main/java/team18/team18_be/slider/dto/response/SliderImageResponse.java @@ -0,0 +1,7 @@ +package team18.team18_be.slider.dto.response; + +public record SliderImageResponse( + String imageUrl +) { + +} diff --git a/src/main/java/team18/team18_be/slider/service/SliderService.java b/src/main/java/team18/team18_be/slider/service/SliderService.java new file mode 100644 index 0000000..e67eb78 --- /dev/null +++ b/src/main/java/team18/team18_be/slider/service/SliderService.java @@ -0,0 +1,39 @@ +package team18.team18_be.slider.service; + +import com.google.cloud.storage.Blob; +import com.google.cloud.storage.Bucket; +import com.google.cloud.storage.Storage; +import java.util.ArrayList; +import java.util.List; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import team18.team18_be.slider.dto.response.SliderImageResponse; + +@Service +public class SliderService { + + public static final String IMAGE = "image/"; + private static final String DIRECTORY_IMAGES = "Slider"; + private final Storage storage; + @Value("${gcp.bucket.name}") + private String BUCKET_NAME; + + public SliderService(Storage storage) { + this.storage = storage; + } + + public List getSliderImageUrls() { + List imageUrls = new ArrayList<>(); + Bucket bucket = storage.get(BUCKET_NAME); + + for (Blob blob : bucket.list(Storage.BlobListOption.prefix(DIRECTORY_IMAGES)).iterateAll()) { + if (!blob.isDirectory() && blob.getContentType() != null && blob.getContentType().startsWith( + IMAGE)) { + String imageUrl = blob.getMediaLink(); + imageUrls.add(new SliderImageResponse(imageUrl)); + } + } + + return imageUrls; + } +}