Skip to content

Commit

Permalink
feat : 회사 기본이미지 저장
Browse files Browse the repository at this point in the history
  • Loading branch information
test1 committed Nov 11, 2024
1 parent 82cdcd2 commit a715275
Showing 1 changed file with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {

Expand All @@ -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,
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit a715275

Please sign in to comment.