-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
41 changed files
with
926 additions
and
32 deletions.
There are no files selected for viewing
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
3 changes: 2 additions & 1 deletion
3
...ion/src/main/java/org/depromeet/spot/application/common/config/SpotApplicationConfig.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 |
---|---|---|
@@ -1,12 +1,13 @@ | ||
package org.depromeet.spot.application.common.config; | ||
|
||
import org.depromeet.spot.jpa.config.JpaConfig; | ||
import org.depromeet.spot.ncp.NcpConfig; | ||
import org.depromeet.spot.usecase.config.UsecaseConfig; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Import; | ||
|
||
@ComponentScan(basePackages = {"org.depromeet.spot.application"}) | ||
@Configuration | ||
@Import(value = {UsecaseConfig.class, JpaConfig.class}) | ||
@Import(value = {UsecaseConfig.class, JpaConfig.class, NcpConfig.class}) | ||
public class SpotApplicationConfig {} |
50 changes: 50 additions & 0 deletions
50
application/src/main/java/org/depromeet/spot/application/media/MediaController.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,50 @@ | ||
package org.depromeet.spot.application.media; | ||
|
||
import jakarta.validation.Valid; | ||
|
||
import org.depromeet.spot.application.media.dto.request.CreatePresignedUrlRequest; | ||
import org.depromeet.spot.application.media.dto.response.MediaUrlResponse; | ||
import org.depromeet.spot.usecase.port.out.media.CreatePresignedUrlPort; | ||
import org.depromeet.spot.usecase.port.out.media.CreatePresignedUrlPort.PresignedUrlRequest; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1") | ||
@Tag(name = "미디어 (이미지, 영상)") | ||
public class MediaController { | ||
|
||
private final CreatePresignedUrlPort createPresignedUrlPort; | ||
|
||
@ResponseStatus(HttpStatus.CREATED) | ||
@PostMapping(value = "/members/{memberId}/reviews/images") | ||
@Operation(summary = "리뷰 이미지 업로드 url을 생성합니다.") | ||
public MediaUrlResponse createReviewImageUploadUrl( | ||
@PathVariable Long memberId, @RequestBody @Valid CreatePresignedUrlRequest request) { | ||
PresignedUrlRequest command = | ||
new PresignedUrlRequest(request.fileExtension(), request.property()); | ||
String presignedUrl = createPresignedUrlPort.forReview(memberId, command); | ||
return new MediaUrlResponse(presignedUrl); | ||
} | ||
|
||
@ResponseStatus(HttpStatus.CREATED) | ||
@PostMapping(value = "/stadiums/images") | ||
@Operation(summary = "공연장 이미지 업로드 url을 생성합니다.") | ||
public MediaUrlResponse createStadiumSeatUploadUrl( | ||
@RequestBody @Valid CreatePresignedUrlRequest request) { | ||
PresignedUrlRequest command = | ||
new PresignedUrlRequest(request.fileExtension(), request.property()); | ||
String presignedUrl = createPresignedUrlPort.forStadiumSeat(command); | ||
return new MediaUrlResponse(presignedUrl); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...main/java/org/depromeet/spot/application/media/dto/request/CreatePresignedUrlRequest.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,5 @@ | ||
package org.depromeet.spot.application.media.dto.request; | ||
|
||
import org.depromeet.spot.domain.media.MediaProperty; | ||
|
||
public record CreatePresignedUrlRequest(String fileExtension, MediaProperty property) {} |
3 changes: 3 additions & 0 deletions
3
...ion/src/main/java/org/depromeet/spot/application/media/dto/response/MediaUrlResponse.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,3 @@ | ||
package org.depromeet.spot.application.media.dto.response; | ||
|
||
public record MediaUrlResponse(String presignedUrl) {} |
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
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
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
26 changes: 26 additions & 0 deletions
26
common/src/main/java/org/depromeet/spot/common/exception/media/MediaErrorCode.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,26 @@ | ||
package org.depromeet.spot.common.exception.media; | ||
|
||
import org.depromeet.spot.common.exception.ErrorCode; | ||
import org.springframework.http.HttpStatus; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum MediaErrorCode implements ErrorCode { | ||
INVALID_EXTENSION(HttpStatus.BAD_REQUEST, "ME001", "허용하지 않는 확장자입니다."), | ||
INVALID_STADIUM_MEDIA(HttpStatus.BAD_REQUEST, "ME002", "경기장과 관련된 미디어 파일이 아닙니다."), | ||
INVALID_REVIEW_MEDIA(HttpStatus.BAD_REQUEST, "ME003", "리뷰와 관련된 미디어 파일이 아닙니다."), | ||
INVALID_MEDIA(HttpStatus.INTERNAL_SERVER_ERROR, "ME004", "잘못된 미디어 형식입니다."), | ||
; | ||
|
||
private final HttpStatus status; | ||
private final String code; | ||
private String message; | ||
|
||
public MediaErrorCode appended(final String s) { | ||
message = message + " {" + s + "}"; | ||
return this; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
common/src/main/java/org/depromeet/spot/common/exception/media/MediaException.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,38 @@ | ||
package org.depromeet.spot.common.exception.media; | ||
|
||
import org.depromeet.spot.common.exception.BusinessException; | ||
|
||
public abstract class MediaException extends BusinessException { | ||
|
||
protected MediaException(MediaErrorCode errorCode) { | ||
super(errorCode); | ||
} | ||
|
||
public static class InvalidExtensionException extends MediaException { | ||
public InvalidExtensionException() { | ||
super(MediaErrorCode.INVALID_EXTENSION); | ||
} | ||
|
||
public InvalidExtensionException(final String s) { | ||
super(MediaErrorCode.INVALID_EXTENSION.appended(s)); | ||
} | ||
} | ||
|
||
public static class InvalidStadiumMediaException extends MediaException { | ||
public InvalidStadiumMediaException() { | ||
super(MediaErrorCode.INVALID_STADIUM_MEDIA); | ||
} | ||
} | ||
|
||
public static class InvalidReviewMediaException extends MediaException { | ||
public InvalidReviewMediaException() { | ||
super(MediaErrorCode.INVALID_REVIEW_MEDIA); | ||
} | ||
} | ||
|
||
public static class InvalidMediaException extends MediaException { | ||
public InvalidMediaException() { | ||
super(MediaErrorCode.INVALID_MEDIA); | ||
} | ||
} | ||
} |
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
28 changes: 28 additions & 0 deletions
28
domain/src/main/java/org/depromeet/spot/domain/media/Media.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,28 @@ | ||
package org.depromeet.spot.domain.media; | ||
|
||
import org.depromeet.spot.common.exception.media.MediaException.InvalidMediaException; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class Media { | ||
|
||
private final String url; | ||
private final String fileName; | ||
|
||
public Media(final String url, final String fileName) { | ||
checkIsValidMedia(url, fileName); | ||
this.url = url; | ||
this.fileName = fileName; | ||
} | ||
|
||
private void checkIsValidMedia(final String url, final String fileName) { | ||
if (isBlankOrNull(url) || isBlankOrNull(fileName)) { | ||
throw new InvalidMediaException(); | ||
} | ||
} | ||
|
||
private boolean isBlankOrNull(final String str) { | ||
return str == null || str.isBlank(); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
domain/src/main/java/org/depromeet/spot/domain/media/MediaProperty.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 org.depromeet.spot.domain.media; | ||
|
||
public enum MediaProperty { | ||
REVIEW, | ||
STADIUM, | ||
; | ||
} |
40 changes: 40 additions & 0 deletions
40
domain/src/main/java/org/depromeet/spot/domain/media/extension/ImageExtension.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,40 @@ | ||
package org.depromeet.spot.domain.media.extension; | ||
|
||
import java.util.Arrays; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
import org.depromeet.spot.common.exception.media.MediaException.InvalidExtensionException; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public enum ImageExtension { | ||
JPG("jpg"), | ||
JPEG("jpeg"), | ||
PNG("png"), | ||
; | ||
|
||
private final String value; | ||
|
||
private static final Map<String, ImageExtension> cachedImageExtension = | ||
Arrays.stream(ImageExtension.values()) | ||
.collect( | ||
Collectors.toMap(extension -> extension.value, extension -> extension)); | ||
|
||
ImageExtension(final String value) { | ||
this.value = value; | ||
} | ||
|
||
public static boolean isValid(final String reqExtension) { | ||
return cachedImageExtension.containsKey(reqExtension); | ||
} | ||
|
||
public static ImageExtension from(final String reqExtension) { | ||
ImageExtension extension = cachedImageExtension.get(reqExtension); | ||
if (extension == null) { | ||
throw new InvalidExtensionException(reqExtension); | ||
} | ||
return extension; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...in/src/main/java/org/depromeet/spot/domain/media/extension/StadiumSeatMediaExtension.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,38 @@ | ||
package org.depromeet.spot.domain.media.extension; | ||
|
||
import java.util.Arrays; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
import org.depromeet.spot.common.exception.media.MediaException.InvalidExtensionException; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public enum StadiumSeatMediaExtension { | ||
SVG("svg"), | ||
; | ||
|
||
private final String value; | ||
|
||
private static final Map<String, StadiumSeatMediaExtension> cachedStadiumMedia = | ||
Arrays.stream(StadiumSeatMediaExtension.values()) | ||
.collect( | ||
Collectors.toMap(extension -> extension.value, extension -> extension)); | ||
|
||
StadiumSeatMediaExtension(final String value) { | ||
this.value = value; | ||
} | ||
|
||
public static boolean isValid(final String reqExtension) { | ||
return cachedStadiumMedia.containsKey(reqExtension); | ||
} | ||
|
||
public static StadiumSeatMediaExtension from(final String reqExtension) { | ||
StadiumSeatMediaExtension extension = cachedStadiumMedia.get(reqExtension); | ||
if (extension == null) { | ||
throw new InvalidExtensionException(reqExtension); | ||
} | ||
return extension; | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
domain/src/test/java/org/depromeet/spot/domain/media/MediaTest.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,57 @@ | ||
package org.depromeet.spot.domain.media; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; | ||
|
||
import org.depromeet.spot.common.exception.media.MediaException.InvalidMediaException; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class MediaTest { | ||
|
||
@Test | ||
public void url이_공백이면_미디어를_생성할_수_없다() { | ||
// given | ||
final String url = ""; | ||
final String fileName = "file"; | ||
|
||
// when | ||
// then | ||
assertThatThrownBy(() -> new Media(url, fileName)) | ||
.isInstanceOf(InvalidMediaException.class); | ||
} | ||
|
||
@Test | ||
public void url이_null이면_미디어를_생성할_수_없다() { | ||
// given | ||
final String url = null; | ||
final String fileName = "file"; | ||
|
||
// when | ||
// then | ||
assertThatThrownBy(() -> new Media(url, fileName)) | ||
.isInstanceOf(InvalidMediaException.class); | ||
} | ||
|
||
@Test | ||
public void fileName이_공백이면_미디어를_생성할_수_없다() { | ||
// given | ||
final String url = "url"; | ||
final String fileName = ""; | ||
|
||
// when | ||
// then | ||
assertThatThrownBy(() -> new Media(url, fileName)) | ||
.isInstanceOf(InvalidMediaException.class); | ||
} | ||
|
||
@Test | ||
public void fileName이_null이면_미디어를_생성할_수_없다() { | ||
// given | ||
final String url = "url"; | ||
final String fileName = ""; | ||
|
||
// when | ||
// then | ||
assertThatThrownBy(() -> new Media(url, fileName)) | ||
.isInstanceOf(InvalidMediaException.class); | ||
} | ||
} |
Oops, something went wrong.