Skip to content

Commit

Permalink
chore(UserActivityVO): 검증 로직 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
mikekks committed Dec 12, 2024
1 parent da2333c commit 7228013
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.sopt.makers.crew.main.entity.user.vo;

import static org.sopt.makers.crew.main.global.exception.ErrorStatus.*;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

Expand Down Expand Up @@ -27,7 +29,25 @@ public UserActivityVO(
@JsonProperty("part") String part,
@JsonProperty("generation") int generation) {

validateUserActivityVO(part, generation);
this.part = part;
this.generation = generation;
}

private void validateUserActivityVO(String part, int generation) {
// Part validation: Ensure it's not null, empty, or contain invalid characters.
if (part == null || part.trim().isEmpty()) {
throw new IllegalArgumentException(INVALID_INPUT_VALUE.getErrorCode() + part);
}

// Validate that part only contains letters (and optionally spaces)
if (!part.matches("^[a-zA-Z가-힣\s]+$")) {
throw new IllegalArgumentException(INVALID_INPUT_VALUE.getErrorCode() + part);
}

// Generation validation: Must be a positive integer
if (generation <= 0) {
throw new IllegalArgumentException(INVALID_INPUT_VALUE.getErrorCode() + generation);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public enum ErrorStatus {
*/
VALIDATION_EXCEPTION("CF-001"),
VALIDATION_REQUEST_MISSING_EXCEPTION("요청값이 입력되지 않았습니다."),
INVALID_INPUT_VALUE("요청값이 올바르지 않습니다."),
INVALID_INPUT_VALUE("요청값이 올바르지 않습니다. : "),
INVALID_INPUT_VALUE_FILTER("요청값 또는 토큰이 올바르지 않습니다."),
NOT_FOUND_MEETING("모임이 없습니다."),
NOT_FOUND_POST("존재하지 않는 게시글입니다."),
Expand Down

0 comments on commit 7228013

Please sign in to comment.