-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: validate 로직 분리 - TagValidator 추가
- Loading branch information
Showing
2 changed files
with
37 additions
and
18 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
32 changes: 32 additions & 0 deletions
32
backend/src/main/java/kernel360/techpick/feature/tag/validator/TagValidator.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,32 @@ | ||
package kernel360.techpick.feature.tag.validator; | ||
|
||
import java.util.Objects; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import kernel360.techpick.core.exception.feature.tag.ApiTagException; | ||
import kernel360.techpick.core.model.tag.Tag; | ||
import kernel360.techpick.feature.tag.model.provider.TagProvider; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class TagValidator { | ||
|
||
private final TagProvider tagProvider; | ||
|
||
public void validateTagAccess(Long userId, Tag tag) throws ApiTagException { | ||
|
||
if (tag == null || !Objects.equals(userId, tag.getUser().getId())) { | ||
throw ApiTagException.UNAUTHORIZED_TAG_ACCESS(); | ||
} | ||
} | ||
|
||
public void validateTagNameExists(Long userId, String name) throws ApiTagException { | ||
|
||
if (tagProvider.existsByUserIdAndName(userId, name)) { | ||
throw ApiTagException.TAG_ALREADY_EXIST(); | ||
} | ||
} | ||
} | ||
|