Fix reserved word columns and update field names

This commit is contained in:
Tim
2025-07-05 18:11:40 +08:00
parent cb5a4a6bfb
commit f7caebe467
13 changed files with 54 additions and 54 deletions

View File

@@ -19,13 +19,13 @@ public class CategoryController {
@PostMapping @PostMapping
public CategoryDto create(@RequestBody CategoryRequest req) { 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); return toDto(c);
} }
@PutMapping("/{id}") @PutMapping("/{id}")
public CategoryDto update(@PathVariable Long id, @RequestBody CategoryRequest req) { 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); return toDto(c);
} }
@@ -67,14 +67,14 @@ public class CategoryController {
dto.setName(c.getName()); dto.setName(c.getName());
dto.setIcon(c.getIcon()); dto.setIcon(c.getIcon());
dto.setSmallIcon(c.getSmallIcon()); dto.setSmallIcon(c.getSmallIcon());
dto.setDescribe(c.getDescribe()); dto.setDescription(c.getDescription());
return dto; return dto;
} }
@Data @Data
private static class CategoryRequest { private static class CategoryRequest {
private String name; private String name;
private String describe; private String description;
private String icon; private String icon;
private String smallIcon; private String smallIcon;
} }
@@ -83,7 +83,7 @@ public class CategoryController {
private static class CategoryDto { private static class CategoryDto {
private Long id; private Long id;
private String name; private String name;
private String describe; private String description;
private String icon; private String icon;
private String smallIcon; private String smallIcon;
} }

View File

@@ -19,13 +19,13 @@ public class TagController {
@PostMapping @PostMapping
public TagDto create(@RequestBody TagRequest req) { 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); return toDto(tag);
} }
@PutMapping("/{id}") @PutMapping("/{id}")
public TagDto update(@PathVariable Long id, @RequestBody TagRequest req) { 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); return toDto(tag);
} }
@@ -67,14 +67,14 @@ public class TagController {
dto.setName(tag.getName()); dto.setName(tag.getName());
dto.setIcon(tag.getIcon()); dto.setIcon(tag.getIcon());
dto.setSmallIcon(tag.getSmallIcon()); dto.setSmallIcon(tag.getSmallIcon());
dto.setDescribe(tag.getDescribe()); dto.setDescription(tag.getDescription());
return dto; return dto;
} }
@Data @Data
private static class TagRequest { private static class TagRequest {
private String name; private String name;
private String describe; private String description;
private String icon; private String icon;
private String smallIcon; private String smallIcon;
} }
@@ -83,7 +83,7 @@ public class TagController {
private static class TagDto { private static class TagDto {
private Long id; private Long id;
private String name; private String name;
private String describe; private String description;
private String icon; private String icon;
private String smallIcon; private String smallIcon;
} }

View File

@@ -24,6 +24,6 @@ public class Category {
@Column @Column
private String smallIcon; private String smallIcon;
@Column(nullable = false) @Column(name = "description", nullable = false)
private String describe; private String description;
} }

View File

@@ -39,7 +39,7 @@ public class Notification {
@Column @Column
private Boolean approved; private Boolean approved;
@Column(nullable = false) @Column(name = "is_read", nullable = false)
private boolean read = false; private boolean read = false;
@Column(nullable = false) @Column(nullable = false)

View File

@@ -24,6 +24,6 @@ public class Tag {
@Column @Column
private String smallIcon; private String smallIcon;
@Column(nullable = false) @Column(name = "description", nullable = false)
private String describe; private String description;
} }

View File

@@ -12,23 +12,23 @@ import java.util.List;
public class CategoryService { public class CategoryService {
private final CategoryRepository categoryRepository; 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 category = new Category();
category.setName(name); category.setName(name);
category.setDescribe(describe); category.setDescription(description);
category.setIcon(icon); category.setIcon(icon);
category.setSmallIcon(smallIcon); category.setSmallIcon(smallIcon);
return categoryRepository.save(category); 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) Category category = categoryRepository.findById(id)
.orElseThrow(() -> new IllegalArgumentException("Category not found")); .orElseThrow(() -> new IllegalArgumentException("Category not found"));
if (name != null) { if (name != null) {
category.setName(name); category.setName(name);
} }
if (describe != null) { if (description != null) {
category.setDescribe(describe); category.setDescription(description);
} }
if (icon != null) { if (icon != null) {
category.setIcon(icon); category.setIcon(icon);

View File

@@ -12,23 +12,23 @@ import java.util.List;
public class TagService { public class TagService {
private final TagRepository tagRepository; 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 tag = new Tag();
tag.setName(name); tag.setName(name);
tag.setDescribe(describe); tag.setDescription(description);
tag.setIcon(icon); tag.setIcon(icon);
tag.setSmallIcon(smallIcon); tag.setSmallIcon(smallIcon);
return tagRepository.save(tag); 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) Tag tag = tagRepository.findById(id)
.orElseThrow(() -> new IllegalArgumentException("Tag not found")); .orElseThrow(() -> new IllegalArgumentException("Tag not found"));
if (name != null) { if (name != null) {
tag.setName(name); tag.setName(name);
} }
if (describe != null) { if (description != null) {
tag.setDescribe(describe); tag.setDescription(description);
} }
if (icon != null) { if (icon != null) {
tag.setIcon(icon); tag.setIcon(icon);

View File

@@ -35,7 +35,7 @@ class CategoryControllerTest {
Category c = new Category(); Category c = new Category();
c.setId(1L); c.setId(1L);
c.setName("tech"); c.setName("tech");
c.setDescribe("d"); c.setDescription("d");
c.setIcon("i"); c.setIcon("i");
c.setSmallIcon("s1"); c.setSmallIcon("s1");
Mockito.when(categoryService.createCategory(eq("tech"), eq("d"), eq("i"), eq("s1"))).thenReturn(c); 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") mockMvc.perform(post("/api/categories")
.contentType(MediaType.APPLICATION_JSON) .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(status().isOk())
.andExpect(jsonPath("$.name").value("tech")) .andExpect(jsonPath("$.name").value("tech"))
.andExpect(jsonPath("$.describe").value("d")) .andExpect(jsonPath("$.description").value("d"))
.andExpect(jsonPath("$.icon").value("i")) .andExpect(jsonPath("$.icon").value("i"))
.andExpect(jsonPath("$.smallIcon").value("s1")); .andExpect(jsonPath("$.smallIcon").value("s1"));
@@ -60,7 +60,7 @@ class CategoryControllerTest {
Category c = new Category(); Category c = new Category();
c.setId(2L); c.setId(2L);
c.setName("life"); c.setName("life");
c.setDescribe("d2"); c.setDescription("d2");
c.setIcon("i2"); c.setIcon("i2");
c.setSmallIcon("s2"); c.setSmallIcon("s2");
Mockito.when(categoryService.listCategories()).thenReturn(List.of(c)); Mockito.when(categoryService.listCategories()).thenReturn(List.of(c));
@@ -68,7 +68,7 @@ class CategoryControllerTest {
mockMvc.perform(get("/api/categories")) mockMvc.perform(get("/api/categories"))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("$[0].name").value("life")) .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].icon").value("i2"))
.andExpect(jsonPath("$[0].smallIcon").value("s2")); .andExpect(jsonPath("$[0].smallIcon").value("s2"));
} }
@@ -78,18 +78,18 @@ class CategoryControllerTest {
Category c = new Category(); Category c = new Category();
c.setId(3L); c.setId(3L);
c.setName("tech"); c.setName("tech");
c.setDescribe("d3"); c.setDescription("d3");
c.setIcon("i3"); c.setIcon("i3");
c.setSmallIcon("s3"); c.setSmallIcon("s3");
Mockito.when(categoryService.updateCategory(eq(3L), eq("tech"), eq("d3"), eq("i3"), eq("s3"))).thenReturn(c); Mockito.when(categoryService.updateCategory(eq(3L), eq("tech"), eq("d3"), eq("i3"), eq("s3"))).thenReturn(c);
mockMvc.perform(put("/api/categories/3") mockMvc.perform(put("/api/categories/3")
.contentType(MediaType.APPLICATION_JSON) .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(status().isOk())
.andExpect(jsonPath("$.id").value(3)) .andExpect(jsonPath("$.id").value(3))
.andExpect(jsonPath("$.name").value("tech")) .andExpect(jsonPath("$.name").value("tech"))
.andExpect(jsonPath("$.describe").value("d3")) .andExpect(jsonPath("$.description").value("d3"))
.andExpect(jsonPath("$.icon").value("i3")) .andExpect(jsonPath("$.icon").value("i3"))
.andExpect(jsonPath("$.smallIcon").value("s3")); .andExpect(jsonPath("$.smallIcon").value("s3"));
} }

View File

@@ -54,12 +54,12 @@ class PostControllerTest {
Category cat = new Category(); Category cat = new Category();
cat.setId(1L); cat.setId(1L);
cat.setName("tech"); cat.setName("tech");
cat.setDescribe("d"); cat.setDescription("d");
cat.setIcon("i"); cat.setIcon("i");
Tag tag = new Tag(); Tag tag = new Tag();
tag.setId(1L); tag.setId(1L);
tag.setName("java"); tag.setName("java");
tag.setDescribe("td"); tag.setDescription("td");
tag.setIcon("ti"); tag.setIcon("ti");
Post post = new Post(); Post post = new Post();
post.setId(1L); post.setId(1L);
@@ -91,12 +91,12 @@ class PostControllerTest {
Category cat = new Category(); Category cat = new Category();
cat.setId(1L); cat.setId(1L);
cat.setName("tech"); cat.setName("tech");
cat.setDescribe("d"); cat.setDescription("d");
cat.setIcon("i"); cat.setIcon("i");
Tag tag = new Tag(); Tag tag = new Tag();
tag.setId(1L); tag.setId(1L);
tag.setName("java"); tag.setName("java");
tag.setDescribe("td"); tag.setDescription("td");
tag.setIcon("ti"); tag.setIcon("ti");
Post post = new Post(); Post post = new Post();
post.setId(2L); post.setId(2L);

View File

@@ -35,7 +35,7 @@ class TagControllerTest {
Tag t = new Tag(); Tag t = new Tag();
t.setId(1L); t.setId(1L);
t.setName("java"); t.setName("java");
t.setDescribe("d"); t.setDescription("d");
t.setIcon("i"); t.setIcon("i");
t.setSmallIcon("s1"); t.setSmallIcon("s1");
Mockito.when(tagService.createTag(eq("java"), eq("d"), eq("i"), eq("s1"))).thenReturn(t); 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") mockMvc.perform(post("/api/tags")
.contentType(MediaType.APPLICATION_JSON) .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(status().isOk())
.andExpect(jsonPath("$.name").value("java")) .andExpect(jsonPath("$.name").value("java"))
.andExpect(jsonPath("$.describe").value("d")) .andExpect(jsonPath("$.description").value("d"))
.andExpect(jsonPath("$.icon").value("i")) .andExpect(jsonPath("$.icon").value("i"))
.andExpect(jsonPath("$.smallIcon").value("s1")); .andExpect(jsonPath("$.smallIcon").value("s1"));
@@ -60,7 +60,7 @@ class TagControllerTest {
Tag t = new Tag(); Tag t = new Tag();
t.setId(2L); t.setId(2L);
t.setName("spring"); t.setName("spring");
t.setDescribe("d2"); t.setDescription("d2");
t.setIcon("i2"); t.setIcon("i2");
t.setSmallIcon("s2"); t.setSmallIcon("s2");
Mockito.when(tagService.listTags()).thenReturn(List.of(t)); Mockito.when(tagService.listTags()).thenReturn(List.of(t));
@@ -69,7 +69,7 @@ class TagControllerTest {
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("$[0].name").value("spring")) .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].icon").value("i2"))
.andExpect(jsonPath("$[0].smallIcon").value("s2")); .andExpect(jsonPath("$[0].smallIcon").value("s2"));
} }
@@ -79,18 +79,18 @@ class TagControllerTest {
Tag t = new Tag(); Tag t = new Tag();
t.setId(3L); t.setId(3L);
t.setName("java"); t.setName("java");
t.setDescribe("d3"); t.setDescription("d3");
t.setIcon("i3"); t.setIcon("i3");
t.setSmallIcon("s3"); t.setSmallIcon("s3");
Mockito.when(tagService.updateTag(eq(3L), eq("java"), eq("d3"), eq("i3"), eq("s3"))).thenReturn(t); Mockito.when(tagService.updateTag(eq(3L), eq("java"), eq("d3"), eq("i3"), eq("s3"))).thenReturn(t);
mockMvc.perform(put("/api/tags/3") mockMvc.perform(put("/api/tags/3")
.contentType(MediaType.APPLICATION_JSON) .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(status().isOk())
.andExpect(jsonPath("$.id").value(3)) .andExpect(jsonPath("$.id").value(3))
.andExpect(jsonPath("$.name").value("java")) .andExpect(jsonPath("$.name").value("java"))
.andExpect(jsonPath("$.describe").value("d3")) .andExpect(jsonPath("$.description").value("d3"))
.andExpect(jsonPath("$.icon").value("i3")) .andExpect(jsonPath("$.icon").value("i3"))
.andExpect(jsonPath("$.smallIcon").value("s3")); .andExpect(jsonPath("$.smallIcon").value("s3"));
} }

View File

@@ -66,11 +66,11 @@ class ComplexFlowIntegrationTest {
String adminToken = registerAndLoginAsAdmin("admin", "admin@example.com"); String adminToken = registerAndLoginAsAdmin("admin", "admin@example.com");
ResponseEntity<Map> catResp = postJson("/api/categories", ResponseEntity<Map> 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(); Long catId = ((Number)catResp.getBody().get("id")).longValue();
ResponseEntity<Map> tagResp = postJson("/api/tags", ResponseEntity<Map> 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(); Long tagId = ((Number)tagResp.getBody().get("id")).longValue();
ResponseEntity<Map> postResp = postJson("/api/posts", ResponseEntity<Map> postResp = postJson("/api/posts",
@@ -122,13 +122,13 @@ class ComplexFlowIntegrationTest {
} }
if (catId == null) { if (catId == null) {
ResponseEntity<Map> catResp = postJson("/api/categories", ResponseEntity<Map> catResp = postJson("/api/categories",
Map.of("name", "general", "describe", "d", "icon", "i"), adminToken); Map.of("name", "general", "description", "d", "icon", "i"), adminToken);
catId = ((Number)catResp.getBody().get("id")).longValue(); catId = ((Number)catResp.getBody().get("id")).longValue();
} }
ResponseEntity<Map> tagResp = postJson("/api/tags", ResponseEntity<Map> 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(); Long tagId = ((Number)tagResp.getBody().get("id")).longValue();
ResponseEntity<Map> postResp = postJson("/api/posts", ResponseEntity<Map> postResp = postJson("/api/posts",

View File

@@ -70,11 +70,11 @@ class PublishModeIntegrationTest {
String adminToken = registerAndLoginAsAdmin("admin", "admin@example.com"); String adminToken = registerAndLoginAsAdmin("admin", "admin@example.com");
ResponseEntity<Map> catResp = postJson("/api/categories", ResponseEntity<Map> 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(); Long catId = ((Number)catResp.getBody().get("id")).longValue();
ResponseEntity<Map> tagResp = postJson("/api/tags", ResponseEntity<Map> 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(); Long tagId = ((Number)tagResp.getBody().get("id")).longValue();
ResponseEntity<Map> postResp = postJson("/api/posts", ResponseEntity<Map> postResp = postJson("/api/posts",

View File

@@ -60,10 +60,10 @@ class SearchIntegrationTest {
String admin = registerAndLoginAsAdmin("admin", "a@a.com"); String admin = registerAndLoginAsAdmin("admin", "a@a.com");
String user = registerAndLogin("bob_nice", "b@b.com"); String user = registerAndLogin("bob_nice", "b@b.com");
ResponseEntity<Map> catResp = postJson("/api/categories", Map.of("name", "misc", "describe", "d", "icon", "i"), admin); ResponseEntity<Map> catResp = postJson("/api/categories", Map.of("name", "misc", "description", "d", "icon", "i"), admin);
Long catId = ((Number)catResp.getBody().get("id")).longValue(); Long catId = ((Number)catResp.getBody().get("id")).longValue();
ResponseEntity<Map> tagResp = postJson("/api/tags", Map.of("name", "misc", "describe", "d", "icon", "i"), admin); ResponseEntity<Map> tagResp = postJson("/api/tags", Map.of("name", "misc", "description", "d", "icon", "i"), admin);
Long tagId = ((Number)tagResp.getBody().get("id")).longValue(); Long tagId = ((Number)tagResp.getBody().get("id")).longValue();
ResponseEntity<Map> postResp = postJson("/api/posts", ResponseEntity<Map> postResp = postJson("/api/posts",