Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Add] checkBlankAndSpecial #35

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/com/easyvel/server/tag/TagController.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public List<PostDto> getUserTagPostList(@RequestParam String search,
}

@ApiOperation(value = "현재 인기있는 태그 목록", notes = "vol 파라미터에 받을 태그 수량을 입력")
@EasyvelTokenApiImplicitParams
@GetMapping("/hot-tag")
public TagList getHotTagList(@RequestParam(defaultValue = "10") int vol) throws IOException {
return tagService.getHotTagList(vol);
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/easyvel/server/tag/TagService.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

@Slf4j
@Service
Expand All @@ -43,13 +44,22 @@ public void addTag(String uid, String tagName) {
User user = getUserByUid(uid);
Tag tag = getElseMakeTag(tagName);

checkBlankAndSpecial(tagName);

if (containsTag(user, tag))
throw new IllegalArgumentException("이미 추가한 태그입니다.");

UserTag userTag = new UserTag(user, tag);
userTagRepository.save(userTag);
}

//Todo: 다른 곳에서도 필요할지도..? 이후 추가 적용하기
private void checkBlankAndSpecial(String tagName) {
String pattern = "^[0-9|a-z|A-Z|ㄱ-ㅎ|ㅏ-ㅣ|가-힣]*$";
if (!Pattern.matches(pattern, tagName))
throw new IllegalArgumentException("공백, 특수문자는 허용되지 않습니다.");
}

public void deleteTag(String uid, String tagName) {
User user = getUserByUid(uid);
Tag tag = getElseMakeTag(tagName);
Expand All @@ -69,6 +79,7 @@ public void deleteTag(String uid, String tagName) {
* @throws IOException
*/
public List<PostDto> getPostDtoListByTag(String uid, String tag) throws IOException {
//Todo: 없는 태그를 긁어오려할 경우 체크하는 로직 만들기
List<String> userSubscribeList = getSubscribeNameList(uid);
Elements postsElements = getTagPostsElements(tag);

Expand Down