Skip to content

Commit

Permalink
Merge pull request #147 from kakao-tech-campus-2nd-step3/Develop
Browse files Browse the repository at this point in the history
[Master] ์Šฌ๋ผ์ด๋” API ๋ฐ ํšŒ์‚ฌ ๊ธฐ๋ณธ ์ด๋ฏธ์ง€ ์ €์žฅ
  • Loading branch information
minsu-cnu authored Nov 11, 2024
2 parents a723b8b + dac33ce commit 79ae857
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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<List<SliderImageResponse>> getSliderBanner() {
return ResponseEntity.ok().body(sliderService.getSliderImageUrls());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package team18.team18_be.slider.dto.response;

public record SliderImageResponse(
String imageUrl
) {

}
39 changes: 39 additions & 0 deletions src/main/java/team18/team18_be/slider/service/SliderService.java
Original file line number Diff line number Diff line change
@@ -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<SliderImageResponse> getSliderImageUrls() {
List<SliderImageResponse> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
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 Down Expand Up @@ -33,7 +34,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 +50,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 +81,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 79ae857

Please sign in to comment.