From a71527540ec15a71dfc39c609c6daa7767296a30 Mon Sep 17 00:00:00 2001 From: test1 Date: Tue, 12 Nov 2024 02:21:27 +0900 Subject: [PATCH 1/2] =?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/2] =?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(),