-
Notifications
You must be signed in to change notification settings - Fork 1
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 #122 from Team-SilverTown/feature
🦾 개발 서버 배포
- Loading branch information
Showing
62 changed files
with
1,740 additions
and
262 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
27 changes: 27 additions & 0 deletions
27
src/main/java/team/silvertown/masil/common/scroll/OrderType.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 team.silvertown.masil.common.scroll; | ||
|
||
import io.micrometer.common.util.StringUtils; | ||
import java.util.Arrays; | ||
import java.util.Objects; | ||
import team.silvertown.masil.common.exception.BadRequestException; | ||
import team.silvertown.masil.common.scroll.dto.ScrollErrorCode; | ||
|
||
public enum OrderType { | ||
LATEST, | ||
MOST_POPULAR; | ||
|
||
public static OrderType get(String order) { | ||
if (StringUtils.isBlank(order)) { | ||
return LATEST; | ||
} | ||
|
||
return Arrays.stream(OrderType.values()) | ||
.filter(orderType -> order.equals(orderType.name())) | ||
.findFirst() | ||
.orElseThrow(() -> new BadRequestException(ScrollErrorCode.INVALID_ORDER_TYPE)); | ||
} | ||
|
||
public static boolean isMostPopular(OrderType orderType) { | ||
return Objects.isNull(orderType) || orderType == MOST_POPULAR; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/team/silvertown/masil/common/scroll/dto/NormalListRequest.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 team.silvertown.masil.common.scroll.dto; | ||
|
||
import java.util.Objects; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public final class NormalListRequest { | ||
|
||
private final String depth1; | ||
private final String depth2; | ||
private final String depth3; | ||
private final ScrollRequest scrollRequest; | ||
|
||
@Builder | ||
private NormalListRequest( | ||
String depth1, | ||
String depth2, | ||
String depth3, | ||
String order, | ||
String cursor, | ||
int size | ||
) { | ||
this.depth1 = depth1; | ||
this.depth2 = depth2; | ||
this.depth3 = depth3; | ||
this.scrollRequest = new ScrollRequest(order, cursor, size); | ||
} | ||
|
||
public int getSize() { | ||
return this.scrollRequest.getSize(); | ||
} | ||
|
||
public boolean isBasedOnAddress() { | ||
return Objects.nonNull(depth1) && Objects.nonNull(depth2) && Objects.nonNull(depth3); | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/team/silvertown/masil/common/scroll/dto/ScrollErrorCode.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,15 @@ | ||
package team.silvertown.masil.common.scroll.dto; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import team.silvertown.masil.common.exception.ErrorCode; | ||
|
||
@RequiredArgsConstructor | ||
@Getter | ||
public enum ScrollErrorCode implements ErrorCode { | ||
INVALID_ORDER_TYPE(20311000, "올바르지 않은 정렬 기준입니다"), | ||
INVALID_CURSOR_FORMAT(20311001, "정렬 기준에 맞지 않은 커서 형식입니다"); | ||
|
||
private final int code; | ||
private final String message; | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/team/silvertown/masil/common/scroll/dto/ScrollRequest.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 team.silvertown.masil.common.scroll.dto; | ||
|
||
import lombok.Getter; | ||
import team.silvertown.masil.common.scroll.OrderType; | ||
import team.silvertown.masil.common.validator.ScrollValidator; | ||
|
||
@Getter | ||
public final class ScrollRequest { | ||
|
||
private final OrderType order; | ||
private final String cursor; | ||
private final int size; | ||
|
||
public ScrollRequest( | ||
String order, | ||
String cursor, | ||
int size | ||
) { | ||
OrderType orderType = OrderType.get(order); | ||
|
||
ScrollValidator.validateCursorFormat(cursor, orderType); | ||
|
||
this.order = orderType; | ||
this.cursor = cursor; | ||
this.size = size; | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...masil/common/response/ScrollResponse.java → ...sil/common/scroll/dto/ScrollResponse.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
30 changes: 30 additions & 0 deletions
30
src/main/java/team/silvertown/masil/common/validator/ScrollValidator.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,30 @@ | ||
package team.silvertown.masil.common.validator; | ||
|
||
import io.micrometer.common.util.StringUtils; | ||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
import team.silvertown.masil.common.exception.BadRequestException; | ||
import team.silvertown.masil.common.scroll.OrderType; | ||
import team.silvertown.masil.common.scroll.dto.ScrollErrorCode; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public final class ScrollValidator extends Validator { | ||
|
||
private static final int ID_CURSOR_LENGTH = 16; | ||
private static final String INITIAL_CURSUR = "0"; | ||
|
||
public static void validateCursorFormat(String cursor, OrderType order) { | ||
if (StringUtils.isBlank(cursor) || cursor.equals(INITIAL_CURSUR)) { | ||
return; | ||
} | ||
|
||
if (OrderType.isMostPopular(order)) { | ||
throwIf(cursor.length() != ID_CURSOR_LENGTH, | ||
() -> new BadRequestException(ScrollErrorCode.INVALID_CURSOR_FORMAT)); | ||
return; | ||
} | ||
|
||
notOver(cursor.length(), ID_CURSOR_LENGTH, ScrollErrorCode.INVALID_CURSOR_FORMAT); | ||
} | ||
|
||
} |
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
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
17 changes: 17 additions & 0 deletions
17
src/main/java/team/silvertown/masil/image/validator/ImageFileServiceValidator.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,17 @@ | ||
package team.silvertown.masil.image.validator; | ||
|
||
import org.springframework.web.multipart.MultipartFile; | ||
import team.silvertown.masil.common.exception.BadRequestException; | ||
import team.silvertown.masil.common.validator.Validator; | ||
import team.silvertown.masil.image.exception.ImageErrorCode; | ||
|
||
public class ImageFileServiceValidator extends Validator { | ||
|
||
public static void validateImgFile(MultipartFile file) { | ||
throwIf(file.isEmpty(), () -> new BadRequestException(ImageErrorCode.FILE_IS_EMPTY)); | ||
String contentType = file.getContentType(); | ||
throwIf(!ImageFileType.isImage(contentType), | ||
() -> new BadRequestException(ImageErrorCode.NOT_SUPPORTED_CONTENT)); | ||
} | ||
|
||
} |
Oops, something went wrong.