-
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.
Merge pull request #144 from JNU-econovation/feat-cookie
닉네임 자리수 8글자 제한
- Loading branch information
Showing
7 changed files
with
118 additions
and
3 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
8 changes: 6 additions & 2 deletions
8
src/main/java/com/timcooki/jnuwiki/domain/member/DTO/request/JoinReqDTO.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,10 +1,14 @@ | ||
package com.timcooki.jnuwiki.domain.member.DTO.request; | ||
|
||
import com.timcooki.jnuwiki.domain.member.valid.Nickname; | ||
import lombok.Builder; | ||
@Builder | ||
|
||
public record JoinReqDTO( | ||
String email, | ||
String nickName, | ||
@Nickname String nickName, | ||
String password | ||
) { | ||
|
||
@Builder | ||
public JoinReqDTO{} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
src/main/java/com/timcooki/jnuwiki/domain/member/valid/Nickname.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,21 @@ | ||
package com.timcooki.jnuwiki.domain.member.valid; | ||
|
||
import javax.validation.Constraint; | ||
import javax.validation.Payload; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target(ElementType.FIELD) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Constraint(validatedBy = NicknameValidator.class) | ||
public @interface Nickname { | ||
|
||
String message() default "닉네임은 최대 8글자까지 가능합니다."; | ||
|
||
Class<?>[] groups() default {}; | ||
|
||
Class<? extends Payload>[] payload() default {}; | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/timcooki/jnuwiki/domain/member/valid/NicknameValidator.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,20 @@ | ||
package com.timcooki.jnuwiki.domain.member.valid; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import javax.validation.ConstraintValidator; | ||
import javax.validation.ConstraintValidatorContext; | ||
|
||
|
||
@Slf4j | ||
public class NicknameValidator implements ConstraintValidator<Nickname, String> { | ||
|
||
@Override | ||
public boolean isValid(String value, ConstraintValidatorContext context) { | ||
log.info("벨리데이션 진행중"); | ||
if (value == null) { | ||
return false; | ||
} | ||
return value.matches(".{1,8}"); | ||
} | ||
} |
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
57 changes: 57 additions & 0 deletions
57
src/test/java/com/timcooki/jnuwiki/domain/member/validation/NicknameValidatorTest.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 com.timcooki.jnuwiki.domain.member.validation; | ||
// | ||
// | ||
//import com.fasterxml.jackson.databind.ObjectMapper; | ||
//import com.timcooki.jnuwiki.domain.member.DTO.request.JoinReqDTO; | ||
//import org.junit.jupiter.api.DisplayName; | ||
//import org.junit.jupiter.api.Test; | ||
//import org.springframework.beans.factory.annotation.Autowired; | ||
//import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
//import org.springframework.boot.test.context.SpringBootTest; | ||
//import org.springframework.http.MediaType; | ||
//import org.springframework.test.web.servlet.MockMvc; | ||
//import org.springframework.test.web.servlet.ResultActions; | ||
//import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; | ||
//import java.nio.charset.Charset; | ||
// | ||
//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
// | ||
//@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK) | ||
//@AutoConfigureMockMvc | ||
//public class NicknameValidatorTest { | ||
// | ||
// @Autowired | ||
// protected MockMvc mockMvc; | ||
// | ||
// @Autowired | ||
// protected ObjectMapper om; | ||
// | ||
// @DisplayName("닉네임 자리수 실패 테스트") | ||
// @Test | ||
// public void nickname_8자리_테스트() throws Exception{ | ||
// // given | ||
// JoinReqDTO joinReqDTO = JoinReqDTO.builder() | ||
// .email("[email protected]") | ||
// .nickName("11asdfasdfsadfsa") | ||
// .password("asdfasdf") | ||
// .build(); | ||
// | ||
// | ||
// // when | ||
// ResultActions resultActions = mockMvc.perform( | ||
// MockMvcRequestBuilders | ||
// .post("/members/join") | ||
// .contentType(MediaType.APPLICATION_JSON) | ||
// .content(om.writeValueAsString(joinReqDTO)) | ||
// ); | ||
// | ||
// String responseBody = resultActions.andReturn().getResponse().getContentAsString(Charset.forName("UTF-8")); | ||
// System.out.println("테스트 : " + responseBody); | ||
// | ||
// // then | ||
// resultActions.andExpectAll( | ||
// status().is4xxClientError(), jsonPath("$.error.status").value("400")); | ||
// | ||
// } | ||
//} |