diff --git a/src/main/java/upbrella/be/store/controller/LockerController.java b/src/main/java/upbrella/be/store/controller/LockerController.java index 997c444f..e1133a7a 100644 --- a/src/main/java/upbrella/be/store/controller/LockerController.java +++ b/src/main/java/upbrella/be/store/controller/LockerController.java @@ -9,6 +9,8 @@ import upbrella.be.store.dto.response.AllLockerResponse; import upbrella.be.util.CustomResponse; +import javax.validation.Valid; + @RestController @RequiredArgsConstructor public class LockerController { @@ -30,7 +32,7 @@ public ResponseEntity> getLockers() { } @PostMapping("/admin/lockers") - public ResponseEntity> createLocker(@RequestBody CreateLockerRequest request) { + public ResponseEntity> createLocker(@RequestBody @Valid CreateLockerRequest request) { lockerService.createLocker(request); @@ -44,7 +46,7 @@ public ResponseEntity> createLocker(@RequestBody CreateLock } @PatchMapping("/admin/lockers/{lockerId}") - public ResponseEntity> updateLocker(@PathVariable Long lockerId, @RequestBody UpdateLockerRequest request) { + public ResponseEntity> updateLocker(@PathVariable Long lockerId, @RequestBody @Valid UpdateLockerRequest request) { lockerService.updateLocker(lockerId, request); diff --git a/src/main/java/upbrella/be/store/dto/request/CreateLockerRequest.java b/src/main/java/upbrella/be/store/dto/request/CreateLockerRequest.java index 6b20884f..0b609a97 100644 --- a/src/main/java/upbrella/be/store/dto/request/CreateLockerRequest.java +++ b/src/main/java/upbrella/be/store/dto/request/CreateLockerRequest.java @@ -5,6 +5,8 @@ import lombok.Getter; import lombok.NoArgsConstructor; +import javax.validation.constraints.Size; + @Getter @Builder @NoArgsConstructor @@ -12,5 +14,6 @@ public class CreateLockerRequest { private long storeId; + @Size(min = 32) private String secretKey; } diff --git a/src/main/java/upbrella/be/store/dto/request/UpdateLockerRequest.java b/src/main/java/upbrella/be/store/dto/request/UpdateLockerRequest.java index d090b4f2..9330aa58 100644 --- a/src/main/java/upbrella/be/store/dto/request/UpdateLockerRequest.java +++ b/src/main/java/upbrella/be/store/dto/request/UpdateLockerRequest.java @@ -5,6 +5,8 @@ import lombok.Getter; import lombok.NoArgsConstructor; +import javax.validation.constraints.Size; + @Getter @Builder @NoArgsConstructor @@ -12,5 +14,6 @@ public class UpdateLockerRequest { private long storeId; + @Size(min = 32) private String secretKey; } diff --git a/src/test/java/upbrella/be/store/controller/LockerControllerTest.java b/src/test/java/upbrella/be/store/controller/LockerControllerTest.java index 5ab96ffc..06d8bb05 100644 --- a/src/test/java/upbrella/be/store/controller/LockerControllerTest.java +++ b/src/test/java/upbrella/be/store/controller/LockerControllerTest.java @@ -76,7 +76,7 @@ void createLockerTest() throws Exception { // given CreateLockerRequest request = CreateLockerRequest.builder() .storeId(1L) - .secretKey("secretKey") + .secretKey("12345678901234567890123456789012") .build(); // then @@ -102,7 +102,7 @@ void updateLockerTest() throws Exception { // given UpdateLockerRequest request = UpdateLockerRequest.builder() .storeId(1L) - .secretKey("secretKey") + .secretKey("12345678901234567890123456789012") .build(); Long lockerId = 1L;