From f7caebe4674ee38bb11b8f56dd2682fb995cbdb6 Mon Sep 17 00:00:00 2001 From: Tim <135014430+nagisa77@users.noreply.github.com> Date: Sat, 5 Jul 2025 18:11:40 +0800 Subject: [PATCH] Fix reserved word columns and update field names --- .../openisle/controller/CategoryController.java | 10 +++++----- .../com/openisle/controller/TagController.java | 10 +++++----- src/main/java/com/openisle/model/Category.java | 4 ++-- .../java/com/openisle/model/Notification.java | 2 +- src/main/java/com/openisle/model/Tag.java | 4 ++-- .../com/openisle/service/CategoryService.java | 10 +++++----- .../java/com/openisle/service/TagService.java | 10 +++++----- .../controller/CategoryControllerTest.java | 16 ++++++++-------- .../openisle/controller/PostControllerTest.java | 8 ++++---- .../openisle/controller/TagControllerTest.java | 16 ++++++++-------- .../integration/ComplexFlowIntegrationTest.java | 10 +++++----- .../integration/PublishModeIntegrationTest.java | 4 ++-- .../integration/SearchIntegrationTest.java | 4 ++-- 13 files changed, 54 insertions(+), 54 deletions(-) diff --git a/src/main/java/com/openisle/controller/CategoryController.java b/src/main/java/com/openisle/controller/CategoryController.java index ac1fa85dd..7e1dac930 100644 --- a/src/main/java/com/openisle/controller/CategoryController.java +++ b/src/main/java/com/openisle/controller/CategoryController.java @@ -19,13 +19,13 @@ public class CategoryController { @PostMapping public CategoryDto create(@RequestBody CategoryRequest req) { - Category c = categoryService.createCategory(req.getName(), req.getDescribe(), req.getIcon(), req.getSmallIcon()); + Category c = categoryService.createCategory(req.getName(), req.getDescription(), req.getIcon(), req.getSmallIcon()); return toDto(c); } @PutMapping("/{id}") public CategoryDto update(@PathVariable Long id, @RequestBody CategoryRequest req) { - Category c = categoryService.updateCategory(id, req.getName(), req.getDescribe(), req.getIcon(), req.getSmallIcon()); + Category c = categoryService.updateCategory(id, req.getName(), req.getDescription(), req.getIcon(), req.getSmallIcon()); return toDto(c); } @@ -67,14 +67,14 @@ public class CategoryController { dto.setName(c.getName()); dto.setIcon(c.getIcon()); dto.setSmallIcon(c.getSmallIcon()); - dto.setDescribe(c.getDescribe()); + dto.setDescription(c.getDescription()); return dto; } @Data private static class CategoryRequest { private String name; - private String describe; + private String description; private String icon; private String smallIcon; } @@ -83,7 +83,7 @@ public class CategoryController { private static class CategoryDto { private Long id; private String name; - private String describe; + private String description; private String icon; private String smallIcon; } diff --git a/src/main/java/com/openisle/controller/TagController.java b/src/main/java/com/openisle/controller/TagController.java index 33808bd8f..594fb6738 100644 --- a/src/main/java/com/openisle/controller/TagController.java +++ b/src/main/java/com/openisle/controller/TagController.java @@ -19,13 +19,13 @@ public class TagController { @PostMapping public TagDto create(@RequestBody TagRequest req) { - Tag tag = tagService.createTag(req.getName(), req.getDescribe(), req.getIcon(), req.getSmallIcon()); + Tag tag = tagService.createTag(req.getName(), req.getDescription(), req.getIcon(), req.getSmallIcon()); return toDto(tag); } @PutMapping("/{id}") public TagDto update(@PathVariable Long id, @RequestBody TagRequest req) { - Tag tag = tagService.updateTag(id, req.getName(), req.getDescribe(), req.getIcon(), req.getSmallIcon()); + Tag tag = tagService.updateTag(id, req.getName(), req.getDescription(), req.getIcon(), req.getSmallIcon()); return toDto(tag); } @@ -67,14 +67,14 @@ public class TagController { dto.setName(tag.getName()); dto.setIcon(tag.getIcon()); dto.setSmallIcon(tag.getSmallIcon()); - dto.setDescribe(tag.getDescribe()); + dto.setDescription(tag.getDescription()); return dto; } @Data private static class TagRequest { private String name; - private String describe; + private String description; private String icon; private String smallIcon; } @@ -83,7 +83,7 @@ public class TagController { private static class TagDto { private Long id; private String name; - private String describe; + private String description; private String icon; private String smallIcon; } diff --git a/src/main/java/com/openisle/model/Category.java b/src/main/java/com/openisle/model/Category.java index 4aea1f00e..f768bde33 100644 --- a/src/main/java/com/openisle/model/Category.java +++ b/src/main/java/com/openisle/model/Category.java @@ -24,6 +24,6 @@ public class Category { @Column private String smallIcon; - @Column(nullable = false) - private String describe; + @Column(name = "description", nullable = false) + private String description; } diff --git a/src/main/java/com/openisle/model/Notification.java b/src/main/java/com/openisle/model/Notification.java index 0529d3d0a..ab9f004d2 100644 --- a/src/main/java/com/openisle/model/Notification.java +++ b/src/main/java/com/openisle/model/Notification.java @@ -39,7 +39,7 @@ public class Notification { @Column private Boolean approved; - @Column(nullable = false) + @Column(name = "is_read", nullable = false) private boolean read = false; @Column(nullable = false) diff --git a/src/main/java/com/openisle/model/Tag.java b/src/main/java/com/openisle/model/Tag.java index cd1b3484d..b4b71a4eb 100644 --- a/src/main/java/com/openisle/model/Tag.java +++ b/src/main/java/com/openisle/model/Tag.java @@ -24,6 +24,6 @@ public class Tag { @Column private String smallIcon; - @Column(nullable = false) - private String describe; + @Column(name = "description", nullable = false) + private String description; } diff --git a/src/main/java/com/openisle/service/CategoryService.java b/src/main/java/com/openisle/service/CategoryService.java index 794251502..beb36c7b4 100644 --- a/src/main/java/com/openisle/service/CategoryService.java +++ b/src/main/java/com/openisle/service/CategoryService.java @@ -12,23 +12,23 @@ import java.util.List; public class CategoryService { private final CategoryRepository categoryRepository; - public Category createCategory(String name, String describe, String icon, String smallIcon) { + public Category createCategory(String name, String description, String icon, String smallIcon) { Category category = new Category(); category.setName(name); - category.setDescribe(describe); + category.setDescription(description); category.setIcon(icon); category.setSmallIcon(smallIcon); return categoryRepository.save(category); } - public Category updateCategory(Long id, String name, String describe, String icon, String smallIcon) { + public Category updateCategory(Long id, String name, String description, String icon, String smallIcon) { Category category = categoryRepository.findById(id) .orElseThrow(() -> new IllegalArgumentException("Category not found")); if (name != null) { category.setName(name); } - if (describe != null) { - category.setDescribe(describe); + if (description != null) { + category.setDescription(description); } if (icon != null) { category.setIcon(icon); diff --git a/src/main/java/com/openisle/service/TagService.java b/src/main/java/com/openisle/service/TagService.java index 614a0c430..f81c5319f 100644 --- a/src/main/java/com/openisle/service/TagService.java +++ b/src/main/java/com/openisle/service/TagService.java @@ -12,23 +12,23 @@ import java.util.List; public class TagService { private final TagRepository tagRepository; - public Tag createTag(String name, String describe, String icon, String smallIcon) { + public Tag createTag(String name, String description, String icon, String smallIcon) { Tag tag = new Tag(); tag.setName(name); - tag.setDescribe(describe); + tag.setDescription(description); tag.setIcon(icon); tag.setSmallIcon(smallIcon); return tagRepository.save(tag); } - public Tag updateTag(Long id, String name, String describe, String icon, String smallIcon) { + public Tag updateTag(Long id, String name, String description, String icon, String smallIcon) { Tag tag = tagRepository.findById(id) .orElseThrow(() -> new IllegalArgumentException("Tag not found")); if (name != null) { tag.setName(name); } - if (describe != null) { - tag.setDescribe(describe); + if (description != null) { + tag.setDescription(description); } if (icon != null) { tag.setIcon(icon); diff --git a/src/test/java/com/openisle/controller/CategoryControllerTest.java b/src/test/java/com/openisle/controller/CategoryControllerTest.java index f1fada7b8..45e217605 100644 --- a/src/test/java/com/openisle/controller/CategoryControllerTest.java +++ b/src/test/java/com/openisle/controller/CategoryControllerTest.java @@ -35,7 +35,7 @@ class CategoryControllerTest { Category c = new Category(); c.setId(1L); c.setName("tech"); - c.setDescribe("d"); + c.setDescription("d"); c.setIcon("i"); c.setSmallIcon("s1"); Mockito.when(categoryService.createCategory(eq("tech"), eq("d"), eq("i"), eq("s1"))).thenReturn(c); @@ -43,10 +43,10 @@ class CategoryControllerTest { mockMvc.perform(post("/api/categories") .contentType(MediaType.APPLICATION_JSON) - .content("{\"name\":\"tech\",\"describe\":\"d\",\"icon\":\"i\",\"smallIcon\":\"s1\"}")) + .content("{\"name\":\"tech\",\"description\":\"d\",\"icon\":\"i\",\"smallIcon\":\"s1\"}")) .andExpect(status().isOk()) .andExpect(jsonPath("$.name").value("tech")) - .andExpect(jsonPath("$.describe").value("d")) + .andExpect(jsonPath("$.description").value("d")) .andExpect(jsonPath("$.icon").value("i")) .andExpect(jsonPath("$.smallIcon").value("s1")); @@ -60,7 +60,7 @@ class CategoryControllerTest { Category c = new Category(); c.setId(2L); c.setName("life"); - c.setDescribe("d2"); + c.setDescription("d2"); c.setIcon("i2"); c.setSmallIcon("s2"); Mockito.when(categoryService.listCategories()).thenReturn(List.of(c)); @@ -68,7 +68,7 @@ class CategoryControllerTest { mockMvc.perform(get("/api/categories")) .andExpect(status().isOk()) .andExpect(jsonPath("$[0].name").value("life")) - .andExpect(jsonPath("$[0].describe").value("d2")) + .andExpect(jsonPath("$[0].description").value("d2")) .andExpect(jsonPath("$[0].icon").value("i2")) .andExpect(jsonPath("$[0].smallIcon").value("s2")); } @@ -78,18 +78,18 @@ class CategoryControllerTest { Category c = new Category(); c.setId(3L); c.setName("tech"); - c.setDescribe("d3"); + c.setDescription("d3"); c.setIcon("i3"); c.setSmallIcon("s3"); Mockito.when(categoryService.updateCategory(eq(3L), eq("tech"), eq("d3"), eq("i3"), eq("s3"))).thenReturn(c); mockMvc.perform(put("/api/categories/3") .contentType(MediaType.APPLICATION_JSON) - .content("{\"name\":\"tech\",\"describe\":\"d3\",\"icon\":\"i3\",\"smallIcon\":\"s3\"}")) + .content("{\"name\":\"tech\",\"description\":\"d3\",\"icon\":\"i3\",\"smallIcon\":\"s3\"}")) .andExpect(status().isOk()) .andExpect(jsonPath("$.id").value(3)) .andExpect(jsonPath("$.name").value("tech")) - .andExpect(jsonPath("$.describe").value("d3")) + .andExpect(jsonPath("$.description").value("d3")) .andExpect(jsonPath("$.icon").value("i3")) .andExpect(jsonPath("$.smallIcon").value("s3")); } diff --git a/src/test/java/com/openisle/controller/PostControllerTest.java b/src/test/java/com/openisle/controller/PostControllerTest.java index dcabd3a9b..d7ab4c76c 100644 --- a/src/test/java/com/openisle/controller/PostControllerTest.java +++ b/src/test/java/com/openisle/controller/PostControllerTest.java @@ -54,12 +54,12 @@ class PostControllerTest { Category cat = new Category(); cat.setId(1L); cat.setName("tech"); - cat.setDescribe("d"); + cat.setDescription("d"); cat.setIcon("i"); Tag tag = new Tag(); tag.setId(1L); tag.setName("java"); - tag.setDescribe("td"); + tag.setDescription("td"); tag.setIcon("ti"); Post post = new Post(); post.setId(1L); @@ -91,12 +91,12 @@ class PostControllerTest { Category cat = new Category(); cat.setId(1L); cat.setName("tech"); - cat.setDescribe("d"); + cat.setDescription("d"); cat.setIcon("i"); Tag tag = new Tag(); tag.setId(1L); tag.setName("java"); - tag.setDescribe("td"); + tag.setDescription("td"); tag.setIcon("ti"); Post post = new Post(); post.setId(2L); diff --git a/src/test/java/com/openisle/controller/TagControllerTest.java b/src/test/java/com/openisle/controller/TagControllerTest.java index 070aa86e0..6db997889 100644 --- a/src/test/java/com/openisle/controller/TagControllerTest.java +++ b/src/test/java/com/openisle/controller/TagControllerTest.java @@ -35,7 +35,7 @@ class TagControllerTest { Tag t = new Tag(); t.setId(1L); t.setName("java"); - t.setDescribe("d"); + t.setDescription("d"); t.setIcon("i"); t.setSmallIcon("s1"); Mockito.when(tagService.createTag(eq("java"), eq("d"), eq("i"), eq("s1"))).thenReturn(t); @@ -43,10 +43,10 @@ class TagControllerTest { mockMvc.perform(post("/api/tags") .contentType(MediaType.APPLICATION_JSON) - .content("{\"name\":\"java\",\"describe\":\"d\",\"icon\":\"i\",\"smallIcon\":\"s1\"}")) + .content("{\"name\":\"java\",\"description\":\"d\",\"icon\":\"i\",\"smallIcon\":\"s1\"}")) .andExpect(status().isOk()) .andExpect(jsonPath("$.name").value("java")) - .andExpect(jsonPath("$.describe").value("d")) + .andExpect(jsonPath("$.description").value("d")) .andExpect(jsonPath("$.icon").value("i")) .andExpect(jsonPath("$.smallIcon").value("s1")); @@ -60,7 +60,7 @@ class TagControllerTest { Tag t = new Tag(); t.setId(2L); t.setName("spring"); - t.setDescribe("d2"); + t.setDescription("d2"); t.setIcon("i2"); t.setSmallIcon("s2"); Mockito.when(tagService.listTags()).thenReturn(List.of(t)); @@ -69,7 +69,7 @@ class TagControllerTest { .andExpect(status().isOk()) .andExpect(status().isOk()) .andExpect(jsonPath("$[0].name").value("spring")) - .andExpect(jsonPath("$[0].describe").value("d2")) + .andExpect(jsonPath("$[0].description").value("d2")) .andExpect(jsonPath("$[0].icon").value("i2")) .andExpect(jsonPath("$[0].smallIcon").value("s2")); } @@ -79,18 +79,18 @@ class TagControllerTest { Tag t = new Tag(); t.setId(3L); t.setName("java"); - t.setDescribe("d3"); + t.setDescription("d3"); t.setIcon("i3"); t.setSmallIcon("s3"); Mockito.when(tagService.updateTag(eq(3L), eq("java"), eq("d3"), eq("i3"), eq("s3"))).thenReturn(t); mockMvc.perform(put("/api/tags/3") .contentType(MediaType.APPLICATION_JSON) - .content("{\"name\":\"java\",\"describe\":\"d3\",\"icon\":\"i3\",\"smallIcon\":\"s3\"}")) + .content("{\"name\":\"java\",\"description\":\"d3\",\"icon\":\"i3\",\"smallIcon\":\"s3\"}")) .andExpect(status().isOk()) .andExpect(jsonPath("$.id").value(3)) .andExpect(jsonPath("$.name").value("java")) - .andExpect(jsonPath("$.describe").value("d3")) + .andExpect(jsonPath("$.description").value("d3")) .andExpect(jsonPath("$.icon").value("i3")) .andExpect(jsonPath("$.smallIcon").value("s3")); } diff --git a/src/test/java/com/openisle/integration/ComplexFlowIntegrationTest.java b/src/test/java/com/openisle/integration/ComplexFlowIntegrationTest.java index 0d8c716f9..3feeae0a6 100644 --- a/src/test/java/com/openisle/integration/ComplexFlowIntegrationTest.java +++ b/src/test/java/com/openisle/integration/ComplexFlowIntegrationTest.java @@ -66,11 +66,11 @@ class ComplexFlowIntegrationTest { String adminToken = registerAndLoginAsAdmin("admin", "admin@example.com"); ResponseEntity catResp = postJson("/api/categories", - Map.of("name", "general", "describe", "d", "icon", "i"), adminToken); + Map.of("name", "general", "description", "d", "icon", "i"), adminToken); Long catId = ((Number)catResp.getBody().get("id")).longValue(); ResponseEntity tagResp = postJson("/api/tags", - Map.of("name", "java", "describe", "d", "icon", "i"), adminToken); + Map.of("name", "java", "description", "d", "icon", "i"), adminToken); Long tagId = ((Number)tagResp.getBody().get("id")).longValue(); ResponseEntity postResp = postJson("/api/posts", @@ -122,13 +122,13 @@ class ComplexFlowIntegrationTest { } if (catId == null) { - ResponseEntity catResp = postJson("/api/categories", - Map.of("name", "general", "describe", "d", "icon", "i"), adminToken); + ResponseEntity catResp = postJson("/api/categories", + Map.of("name", "general", "description", "d", "icon", "i"), adminToken); catId = ((Number)catResp.getBody().get("id")).longValue(); } ResponseEntity tagResp = postJson("/api/tags", - Map.of("name", "spring", "describe", "d", "icon", "i"), adminToken); + Map.of("name", "spring", "description", "d", "icon", "i"), adminToken); Long tagId = ((Number)tagResp.getBody().get("id")).longValue(); ResponseEntity postResp = postJson("/api/posts", diff --git a/src/test/java/com/openisle/integration/PublishModeIntegrationTest.java b/src/test/java/com/openisle/integration/PublishModeIntegrationTest.java index 97b9627a9..b2fe164a9 100644 --- a/src/test/java/com/openisle/integration/PublishModeIntegrationTest.java +++ b/src/test/java/com/openisle/integration/PublishModeIntegrationTest.java @@ -70,11 +70,11 @@ class PublishModeIntegrationTest { String adminToken = registerAndLoginAsAdmin("admin", "admin@example.com"); ResponseEntity catResp = postJson("/api/categories", - Map.of("name", "review", "describe", "d", "icon", "i"), adminToken); + Map.of("name", "review", "description", "d", "icon", "i"), adminToken); Long catId = ((Number)catResp.getBody().get("id")).longValue(); ResponseEntity tagResp = postJson("/api/tags", - Map.of("name", "t1", "describe", "d", "icon", "i"), adminToken); + Map.of("name", "t1", "description", "d", "icon", "i"), adminToken); Long tagId = ((Number)tagResp.getBody().get("id")).longValue(); ResponseEntity postResp = postJson("/api/posts", diff --git a/src/test/java/com/openisle/integration/SearchIntegrationTest.java b/src/test/java/com/openisle/integration/SearchIntegrationTest.java index 3843b46e1..681662b69 100644 --- a/src/test/java/com/openisle/integration/SearchIntegrationTest.java +++ b/src/test/java/com/openisle/integration/SearchIntegrationTest.java @@ -60,10 +60,10 @@ class SearchIntegrationTest { String admin = registerAndLoginAsAdmin("admin", "a@a.com"); String user = registerAndLogin("bob_nice", "b@b.com"); - ResponseEntity catResp = postJson("/api/categories", Map.of("name", "misc", "describe", "d", "icon", "i"), admin); + ResponseEntity catResp = postJson("/api/categories", Map.of("name", "misc", "description", "d", "icon", "i"), admin); Long catId = ((Number)catResp.getBody().get("id")).longValue(); - ResponseEntity tagResp = postJson("/api/tags", Map.of("name", "misc", "describe", "d", "icon", "i"), admin); + ResponseEntity tagResp = postJson("/api/tags", Map.of("name", "misc", "description", "d", "icon", "i"), admin); Long tagId = ((Number)tagResp.getBody().get("id")).longValue(); ResponseEntity postResp = postJson("/api/posts",