mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-25 23:50:51 +08:00
Add post and tag review workflow
This commit is contained in:
@@ -45,6 +45,7 @@ public class AdminPostController {
|
||||
dto.setAuthor(post.getAuthor().getUsername());
|
||||
dto.setCategory(toCategoryDto(post.getCategory()));
|
||||
dto.setViews(post.getViews());
|
||||
dto.setStatus(post.getStatus());
|
||||
return dto;
|
||||
}
|
||||
|
||||
@@ -67,6 +68,7 @@ public class AdminPostController {
|
||||
private String author;
|
||||
private CategoryDto category;
|
||||
private long views;
|
||||
private com.openisle.model.PostStatus status;
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.openisle.controller;
|
||||
|
||||
import com.openisle.model.Tag;
|
||||
import com.openisle.service.TagService;
|
||||
import com.openisle.service.PostService;
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/admin/tags")
|
||||
@RequiredArgsConstructor
|
||||
public class AdminTagController {
|
||||
private final TagService tagService;
|
||||
private final PostService postService;
|
||||
|
||||
@GetMapping("/pending")
|
||||
public List<TagDto> pendingTags() {
|
||||
return tagService.listPendingTags().stream()
|
||||
.map(t -> toDto(t, postService.countPostsByTag(t.getId())))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@PostMapping("/{id}/approve")
|
||||
public TagDto approve(@PathVariable Long id) {
|
||||
Tag tag = tagService.approveTag(id);
|
||||
long count = postService.countPostsByTag(tag.getId());
|
||||
return toDto(tag, count);
|
||||
}
|
||||
|
||||
private TagDto toDto(Tag tag, long count) {
|
||||
TagDto dto = new TagDto();
|
||||
dto.setId(tag.getId());
|
||||
dto.setName(tag.getName());
|
||||
dto.setDescription(tag.getDescription());
|
||||
dto.setIcon(tag.getIcon());
|
||||
dto.setSmallIcon(tag.getSmallIcon());
|
||||
dto.setCount(count);
|
||||
return dto;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class TagDto {
|
||||
private Long id;
|
||||
private String name;
|
||||
private String description;
|
||||
private String icon;
|
||||
private String smallIcon;
|
||||
private Long count;
|
||||
}
|
||||
}
|
||||
@@ -117,6 +117,7 @@ public class PostController {
|
||||
dto.setCategory(toCategoryDto(post.getCategory()));
|
||||
dto.setTags(post.getTags().stream().map(this::toTagDto).collect(Collectors.toList()));
|
||||
dto.setViews(post.getViews());
|
||||
dto.setStatus(post.getStatus());
|
||||
|
||||
List<ReactionDto> reactions = reactionService.getReactionsForPost(post.getId())
|
||||
.stream()
|
||||
@@ -232,6 +233,7 @@ public class PostController {
|
||||
private CategoryDto category;
|
||||
private java.util.List<TagDto> tags;
|
||||
private long views;
|
||||
private com.openisle.model.PostStatus status;
|
||||
private List<CommentDto> comments;
|
||||
private List<ReactionDto> reactions;
|
||||
private java.util.List<AuthorDto> participants;
|
||||
|
||||
@@ -3,6 +3,9 @@ package com.openisle.controller;
|
||||
import com.openisle.model.Tag;
|
||||
import com.openisle.service.TagService;
|
||||
import com.openisle.service.PostService;
|
||||
import com.openisle.repository.UserRepository;
|
||||
import com.openisle.model.PublishMode;
|
||||
import com.openisle.model.Role;
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -16,10 +19,18 @@ import java.util.stream.Collectors;
|
||||
public class TagController {
|
||||
private final TagService tagService;
|
||||
private final PostService postService;
|
||||
private final UserRepository userRepository;
|
||||
|
||||
@PostMapping
|
||||
public TagDto create(@RequestBody TagRequest req) {
|
||||
Tag tag = tagService.createTag(req.getName(), req.getDescription(), req.getIcon(), req.getSmallIcon());
|
||||
public TagDto create(@RequestBody TagRequest req, org.springframework.security.core.Authentication auth) {
|
||||
boolean approved = true;
|
||||
if (postService.getPublishMode() == PublishMode.REVIEW && auth != null) {
|
||||
com.openisle.model.User user = userRepository.findByUsername(auth.getName()).orElseThrow();
|
||||
if (user.getRole() != Role.ADMIN) {
|
||||
approved = false;
|
||||
}
|
||||
}
|
||||
Tag tag = tagService.createTag(req.getName(), req.getDescription(), req.getIcon(), req.getSmallIcon(), approved);
|
||||
long count = postService.countPostsByTag(tag.getId());
|
||||
return toDto(tag, count);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user