-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #147 from kakao-tech-campus-2nd-step3/Develop
[Master] ์ฌ๋ผ์ด๋ API ๋ฐ ํ์ฌ ๊ธฐ๋ณธ ์ด๋ฏธ์ง ์ ์ฅ
- Loading branch information
Showing
4 changed files
with
88 additions
and
7 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
src/main/java/team18/team18_be/slider/controller/SliderController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/team18/team18_be/slider/dto/response/SliderImageResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
39
src/main/java/team18/team18_be/slider/service/SliderService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters