mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-22 22:21:09 +08:00
Add update endpoints for tags and categories
This commit is contained in:
@@ -21,6 +21,12 @@ public class CategoryController {
|
||||
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());
|
||||
return toDto(c);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public void delete(@PathVariable Long id) {
|
||||
categoryService.deleteCategory(id);
|
||||
|
||||
@@ -21,6 +21,12 @@ public class TagController {
|
||||
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());
|
||||
return toDto(tag);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public void delete(@PathVariable Long id) {
|
||||
tagService.deleteTag(id);
|
||||
|
||||
@@ -20,6 +20,21 @@ public class CategoryService {
|
||||
return categoryRepository.save(category);
|
||||
}
|
||||
|
||||
public Category updateCategory(Long id, String name, String describe, String icon) {
|
||||
Category category = categoryRepository.findById(id)
|
||||
.orElseThrow(() -> new IllegalArgumentException("Category not found"));
|
||||
if (name != null) {
|
||||
category.setName(name);
|
||||
}
|
||||
if (describe != null) {
|
||||
category.setDescribe(describe);
|
||||
}
|
||||
if (icon != null) {
|
||||
category.setIcon(icon);
|
||||
}
|
||||
return categoryRepository.save(category);
|
||||
}
|
||||
|
||||
public void deleteCategory(Long id) {
|
||||
categoryRepository.deleteById(id);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,21 @@ public class TagService {
|
||||
return tagRepository.save(tag);
|
||||
}
|
||||
|
||||
public Tag updateTag(Long id, String name, String describe, String icon) {
|
||||
Tag tag = tagRepository.findById(id)
|
||||
.orElseThrow(() -> new IllegalArgumentException("Tag not found"));
|
||||
if (name != null) {
|
||||
tag.setName(name);
|
||||
}
|
||||
if (describe != null) {
|
||||
tag.setDescribe(describe);
|
||||
}
|
||||
if (icon != null) {
|
||||
tag.setIcon(icon);
|
||||
}
|
||||
return tagRepository.save(tag);
|
||||
}
|
||||
|
||||
public void deleteTag(Long id) {
|
||||
tagRepository.deleteById(id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user