diff --git a/pom.xml b/pom.xml
index 9a7fd03..d299956 100644
--- a/pom.xml
+++ b/pom.xml
@@ -106,6 +106,12 @@
6.5.0
+
+ org.hibernate.validator
+ hibernate-validator
+
+
+
diff --git a/src/main/java/net/tokishu/note/config/SecurityConfig.java b/src/main/java/net/tokishu/note/config/SecurityConfig.java
index b97758c..2872177 100644
--- a/src/main/java/net/tokishu/note/config/SecurityConfig.java
+++ b/src/main/java/net/tokishu/note/config/SecurityConfig.java
@@ -31,7 +31,7 @@ public class SecurityConfig {
)
.authorizeHttpRequests(auth -> auth
.requestMatchers(new AntPathRequestMatcher("/api/auth/**")).permitAll()
- .requestMatchers(new AntPathRequestMatcher("/h2-console/**")).permitAll()
+ .requestMatchers(new AntPathRequestMatcher("/api/notes/*")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/error")).permitAll()
.anyRequest().authenticated()
)
diff --git a/src/main/java/net/tokishu/note/controller/AuthController.java b/src/main/java/net/tokishu/note/controller/AuthController.java
index ecf7d1f..596a74d 100644
--- a/src/main/java/net/tokishu/note/controller/AuthController.java
+++ b/src/main/java/net/tokishu/note/controller/AuthController.java
@@ -14,12 +14,14 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
+import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
@RestController
@RequiredArgsConstructor
+@Validated
@RequestMapping("/auth")
public class AuthController {
@@ -38,7 +40,6 @@ public class AuthController {
return ResponseEntity.ok(response);
}
-
@PostMapping("/new-root")
public ResponseEntity newRoot() {
RootResponse response = authService.registerRoot();
diff --git a/src/main/java/net/tokishu/note/controller/NotesController.java b/src/main/java/net/tokishu/note/controller/NotesController.java
index 9847864..8aed389 100644
--- a/src/main/java/net/tokishu/note/controller/NotesController.java
+++ b/src/main/java/net/tokishu/note/controller/NotesController.java
@@ -1,11 +1,13 @@
package net.tokishu.note.controller;
+import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import net.tokishu.note.dto.request.NoteRequest;
import net.tokishu.note.dto.response.NoteResponse;
import net.tokishu.note.service.NoteService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
+import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@@ -14,6 +16,7 @@ import java.util.UUID;
@RequiredArgsConstructor
@RestController
+@Validated
@RequestMapping("/notes")
public class NotesController {
@@ -24,19 +27,19 @@ public class NotesController {
return ResponseEntity.ok(noteService.getAll());
}
- @GetMapping("/{uuid}")
- public NoteResponse find(@PathVariable UUID uuid){
- return noteService.find(uuid);
+ @GetMapping("/{idOrCode}")
+ public NoteResponse find(@PathVariable String idOrCode) {
+ return noteService.findByIdOrPublicLink(idOrCode);
}
@PostMapping()
- public ResponseEntity