mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-19 05:21:15 +08:00
feat: relocate remaining dtos
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
package com.openisle.controller;
|
||||
|
||||
import com.openisle.dto.MilkTeaInfoDto;
|
||||
import com.openisle.dto.MilkTeaRedeemRequest;
|
||||
import com.openisle.model.Activity;
|
||||
import com.openisle.model.ActivityType;
|
||||
import com.openisle.model.User;
|
||||
import com.openisle.service.ActivityService;
|
||||
import com.openisle.service.UserService;
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -25,20 +26,20 @@ public class ActivityController {
|
||||
}
|
||||
|
||||
@GetMapping("/milk-tea")
|
||||
public MilkTeaInfo milkTea() {
|
||||
public MilkTeaInfoDto milkTea() {
|
||||
Activity a = activityService.getByType(ActivityType.MILK_TEA);
|
||||
long count = activityService.countParticipants(a);
|
||||
if (!a.isEnded() && count >= 50) {
|
||||
activityService.end(a);
|
||||
}
|
||||
MilkTeaInfo info = new MilkTeaInfo();
|
||||
MilkTeaInfoDto info = new MilkTeaInfoDto();
|
||||
info.setRedeemCount(count);
|
||||
info.setEnded(a.isEnded());
|
||||
return info;
|
||||
}
|
||||
|
||||
@PostMapping("/milk-tea/redeem")
|
||||
public java.util.Map<String, String> redeemMilkTea(@RequestBody RedeemRequest req, Authentication auth) {
|
||||
public java.util.Map<String, String> redeemMilkTea(@RequestBody MilkTeaRedeemRequest req, Authentication auth) {
|
||||
User user = userService.findByIdentifier(auth.getName()).orElseThrow();
|
||||
Activity a = activityService.getByType(ActivityType.MILK_TEA);
|
||||
boolean first = activityService.redeem(a, user, req.getContact());
|
||||
@@ -47,15 +48,4 @@ public class ActivityController {
|
||||
}
|
||||
return java.util.Map.of("message", "updated");
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class MilkTeaInfo {
|
||||
private long redeemCount;
|
||||
private boolean ended;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class RedeemRequest {
|
||||
private String contact;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
package com.openisle.controller;
|
||||
|
||||
import com.openisle.model.PasswordStrength;
|
||||
import com.openisle.model.PublishMode;
|
||||
import com.openisle.dto.ConfigDto;
|
||||
import com.openisle.service.AiUsageService;
|
||||
import com.openisle.service.PasswordValidator;
|
||||
import com.openisle.service.PostService;
|
||||
import com.openisle.service.AiUsageService;
|
||||
import com.openisle.service.RegisterModeService;
|
||||
import com.openisle.model.RegisterMode;
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -47,11 +44,4 @@ public class AdminConfigController {
|
||||
return getConfig();
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class ConfigDto {
|
||||
private PublishMode publishMode;
|
||||
private PasswordStrength passwordStrength;
|
||||
private Integer aiFormatLimit;
|
||||
private RegisterMode registerMode;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package com.openisle.controller;
|
||||
|
||||
import com.openisle.model.Post;
|
||||
import com.openisle.dto.PostSummaryDto;
|
||||
import com.openisle.mapper.PostMapper;
|
||||
import com.openisle.service.PostService;
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -18,77 +17,32 @@ import java.util.stream.Collectors;
|
||||
@RequiredArgsConstructor
|
||||
public class AdminPostController {
|
||||
private final PostService postService;
|
||||
private final PostMapper postMapper;
|
||||
|
||||
@GetMapping("/pending")
|
||||
public List<PostDto> pendingPosts() {
|
||||
public List<PostSummaryDto> pendingPosts() {
|
||||
return postService.listPendingPosts().stream()
|
||||
.map(this::toDto)
|
||||
.map(postMapper::toSummaryDto)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@PostMapping("/{id}/approve")
|
||||
public PostDto approve(@PathVariable Long id) {
|
||||
return toDto(postService.approvePost(id));
|
||||
public PostSummaryDto approve(@PathVariable Long id) {
|
||||
return postMapper.toSummaryDto(postService.approvePost(id));
|
||||
}
|
||||
|
||||
@PostMapping("/{id}/reject")
|
||||
public PostDto reject(@PathVariable Long id) {
|
||||
return toDto(postService.rejectPost(id));
|
||||
public PostSummaryDto reject(@PathVariable Long id) {
|
||||
return postMapper.toSummaryDto(postService.rejectPost(id));
|
||||
}
|
||||
|
||||
@PostMapping("/{id}/pin")
|
||||
public PostDto pin(@PathVariable Long id) {
|
||||
return toDto(postService.pinPost(id));
|
||||
public PostSummaryDto pin(@PathVariable Long id) {
|
||||
return postMapper.toSummaryDto(postService.pinPost(id));
|
||||
}
|
||||
|
||||
@PostMapping("/{id}/unpin")
|
||||
public PostDto unpin(@PathVariable Long id) {
|
||||
return toDto(postService.unpinPost(id));
|
||||
}
|
||||
|
||||
private PostDto toDto(Post post) {
|
||||
PostDto dto = new PostDto();
|
||||
dto.setId(post.getId());
|
||||
dto.setTitle(post.getTitle());
|
||||
dto.setContent(post.getContent());
|
||||
dto.setCreatedAt(post.getCreatedAt());
|
||||
dto.setAuthor(post.getAuthor().getUsername());
|
||||
dto.setCategory(toCategoryDto(post.getCategory()));
|
||||
dto.setViews(post.getViews());
|
||||
dto.setStatus(post.getStatus());
|
||||
dto.setPinnedAt(post.getPinnedAt());
|
||||
return dto;
|
||||
}
|
||||
|
||||
private CategoryDto toCategoryDto(com.openisle.model.Category c) {
|
||||
CategoryDto dto = new CategoryDto();
|
||||
dto.setId(c.getId());
|
||||
dto.setName(c.getName());
|
||||
dto.setDescription(c.getDescription());
|
||||
dto.setIcon(c.getIcon());
|
||||
dto.setSmallIcon(c.getSmallIcon());
|
||||
return dto;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class PostDto {
|
||||
private Long id;
|
||||
private String title;
|
||||
private String content;
|
||||
private LocalDateTime createdAt;
|
||||
private String author;
|
||||
private CategoryDto category;
|
||||
private long views;
|
||||
private com.openisle.model.PostStatus status;
|
||||
private LocalDateTime pinnedAt;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class CategoryDto {
|
||||
private Long id;
|
||||
private String name;
|
||||
private String description;
|
||||
private String icon;
|
||||
private String smallIcon;
|
||||
public PostSummaryDto unpin(@PathVariable Long id) {
|
||||
return postMapper.toSummaryDto(postService.unpinPost(id));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.openisle.controller;
|
||||
|
||||
import com.openisle.dto.TagDto;
|
||||
import com.openisle.model.Tag;
|
||||
import com.openisle.service.TagService;
|
||||
import com.openisle.service.PostService;
|
||||
import lombok.Data;
|
||||
import com.openisle.service.TagService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -38,17 +38,8 @@ public class AdminTagController {
|
||||
dto.setDescription(tag.getDescription());
|
||||
dto.setIcon(tag.getIcon());
|
||||
dto.setSmallIcon(tag.getSmallIcon());
|
||||
dto.setCreatedAt(tag.getCreatedAt());
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,17 @@
|
||||
package com.openisle.controller;
|
||||
|
||||
import com.openisle.model.User;
|
||||
import com.openisle.service.EmailSender;
|
||||
import com.openisle.service.JwtService;
|
||||
import com.openisle.service.UserService;
|
||||
import com.openisle.service.CaptchaService;
|
||||
import com.openisle.service.GoogleAuthService;
|
||||
import com.openisle.service.GithubAuthService;
|
||||
import com.openisle.service.DiscordAuthService;
|
||||
import com.openisle.service.TwitterAuthService;
|
||||
import com.openisle.service.RegisterModeService;
|
||||
import com.openisle.service.NotificationService;
|
||||
import com.openisle.model.RegisterMode;
|
||||
import com.openisle.repository.UserRepository;
|
||||
import com.openisle.dto.*;
|
||||
import com.openisle.exception.FieldException;
|
||||
import lombok.Data;
|
||||
import com.openisle.model.RegisterMode;
|
||||
import com.openisle.model.User;
|
||||
import com.openisle.repository.UserRepository;
|
||||
import com.openisle.service.*;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -307,71 +299,5 @@ public class AuthController {
|
||||
}
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class RegisterRequest {
|
||||
private String username;
|
||||
private String email;
|
||||
private String password;
|
||||
private String captcha;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class LoginRequest {
|
||||
private String username;
|
||||
private String password;
|
||||
private String captcha;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class GoogleLoginRequest {
|
||||
private String idToken;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class GithubLoginRequest {
|
||||
private String code;
|
||||
private String redirectUri;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class DiscordLoginRequest {
|
||||
private String code;
|
||||
private String redirectUri;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class TwitterLoginRequest {
|
||||
private String code;
|
||||
private String redirectUri;
|
||||
private String codeVerifier;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class VerifyRequest {
|
||||
private String username;
|
||||
private String code;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class MakeReasonRequest {
|
||||
private String token;
|
||||
private String reason;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class ForgotPasswordRequest {
|
||||
private String email;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class VerifyForgotRequest {
|
||||
private String email;
|
||||
private String code;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class ResetPasswordRequest {
|
||||
private String token;
|
||||
private String password;
|
||||
}
|
||||
// DTO classes moved to com.openisle.dto package
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package com.openisle.controller;
|
||||
|
||||
import com.openisle.dto.CategoryDto;
|
||||
import com.openisle.dto.CategoryRequest;
|
||||
import com.openisle.dto.PostSummaryDto;
|
||||
import com.openisle.mapper.PostMapper;
|
||||
import com.openisle.model.Category;
|
||||
import com.openisle.service.CategoryService;
|
||||
import com.openisle.service.PostService;
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -16,6 +19,7 @@ import java.util.stream.Collectors;
|
||||
public class CategoryController {
|
||||
private final CategoryService categoryService;
|
||||
private final PostService postService;
|
||||
private final PostMapper postMapper;
|
||||
|
||||
@PostMapping
|
||||
public CategoryDto create(@RequestBody CategoryRequest req) {
|
||||
@@ -57,12 +61,7 @@ public class CategoryController {
|
||||
@RequestParam(value = "pageSize", required = false) Integer pageSize) {
|
||||
return postService.listPostsByCategories(java.util.List.of(id), page, pageSize)
|
||||
.stream()
|
||||
.map(p -> {
|
||||
PostSummaryDto dto = new PostSummaryDto();
|
||||
dto.setId(p.getId());
|
||||
dto.setTitle(p.getTitle());
|
||||
return dto;
|
||||
})
|
||||
.map(postMapper::toSummaryDto)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@@ -76,28 +75,4 @@ public class CategoryController {
|
||||
dto.setCount(count);
|
||||
return dto;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class CategoryRequest {
|
||||
private String name;
|
||||
private String description;
|
||||
private String icon;
|
||||
private String smallIcon;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class CategoryDto {
|
||||
private Long id;
|
||||
private String name;
|
||||
private String description;
|
||||
private String icon;
|
||||
private String smallIcon;
|
||||
private Long count;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class PostSummaryDto {
|
||||
private Long id;
|
||||
private String title;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
package com.openisle.controller;
|
||||
|
||||
import com.openisle.dto.AuthorDto;
|
||||
import com.openisle.dto.CommentDto;
|
||||
import com.openisle.dto.CommentRequest;
|
||||
import com.openisle.dto.ReactionDto;
|
||||
import com.openisle.model.Comment;
|
||||
import com.openisle.service.CommentService;
|
||||
import com.openisle.model.CommentSort;
|
||||
import com.openisle.service.CaptchaService;
|
||||
import com.openisle.service.CommentService;
|
||||
import com.openisle.service.LevelService;
|
||||
import com.openisle.service.ReactionService;
|
||||
import com.openisle.model.CommentSort;
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -102,43 +105,15 @@ public class CommentController {
|
||||
dto.setId(comment.getId());
|
||||
dto.setContent(comment.getContent());
|
||||
dto.setCreatedAt(comment.getCreatedAt());
|
||||
dto.setAuthor(toAuthorDto(comment.getAuthor()));
|
||||
AuthorDto author = new AuthorDto();
|
||||
author.setId(comment.getAuthor().getId());
|
||||
author.setUsername(comment.getAuthor().getUsername());
|
||||
author.setAvatar(comment.getAuthor().getAvatar());
|
||||
dto.setAuthor(author);
|
||||
dto.setReward(0);
|
||||
return dto;
|
||||
}
|
||||
|
||||
private AuthorDto toAuthorDto(com.openisle.model.User user) {
|
||||
AuthorDto dto = new AuthorDto();
|
||||
dto.setId(user.getId());
|
||||
dto.setUsername(user.getUsername());
|
||||
dto.setAvatar(user.getAvatar());
|
||||
return dto;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class CommentRequest {
|
||||
private String content;
|
||||
private String captcha;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class CommentDto {
|
||||
private Long id;
|
||||
private String content;
|
||||
private LocalDateTime createdAt;
|
||||
private AuthorDto author;
|
||||
private List<CommentDto> replies;
|
||||
private List<ReactionDto> reactions;
|
||||
private int reward;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class AuthorDto {
|
||||
private Long id;
|
||||
private String username;
|
||||
private String avatar;
|
||||
}
|
||||
|
||||
private ReactionDto toReactionDto(com.openisle.model.Reaction reaction) {
|
||||
ReactionDto dto = new ReactionDto();
|
||||
dto.setId(reaction.getId());
|
||||
@@ -153,14 +128,4 @@ public class CommentController {
|
||||
dto.setReward(0);
|
||||
return dto;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class ReactionDto {
|
||||
private Long id;
|
||||
private com.openisle.model.ReactionType type;
|
||||
private String user;
|
||||
private Long postId;
|
||||
private Long commentId;
|
||||
private int reward;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package com.openisle.controller;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import com.openisle.dto.SiteConfigDto;
|
||||
import com.openisle.service.RegisterModeService;
|
||||
import com.openisle.model.RegisterMode;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@@ -34,8 +33,8 @@ public class ConfigController {
|
||||
private final RegisterModeService registerModeService;
|
||||
|
||||
@GetMapping("/config")
|
||||
public ConfigResponse getConfig() {
|
||||
ConfigResponse resp = new ConfigResponse();
|
||||
public SiteConfigDto getConfig() {
|
||||
SiteConfigDto resp = new SiteConfigDto();
|
||||
resp.setCaptchaEnabled(captchaEnabled);
|
||||
resp.setRegisterCaptchaEnabled(registerCaptchaEnabled);
|
||||
resp.setLoginCaptchaEnabled(loginCaptchaEnabled);
|
||||
@@ -45,15 +44,4 @@ public class ConfigController {
|
||||
resp.setRegisterMode(registerModeService.getRegisterMode());
|
||||
return resp;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class ConfigResponse {
|
||||
private boolean captchaEnabled;
|
||||
private boolean registerCaptchaEnabled;
|
||||
private boolean loginCaptchaEnabled;
|
||||
private boolean postCaptchaEnabled;
|
||||
private boolean commentCaptchaEnabled;
|
||||
private int aiFormatLimit;
|
||||
private RegisterMode registerMode;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package com.openisle.controller;
|
||||
|
||||
import com.openisle.dto.DraftDto;
|
||||
import com.openisle.dto.DraftRequest;
|
||||
import com.openisle.model.Draft;
|
||||
import com.openisle.service.DraftService;
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@@ -48,20 +48,4 @@ public class DraftController {
|
||||
return dto;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class DraftRequest {
|
||||
private String title;
|
||||
private String content;
|
||||
private Long categoryId;
|
||||
private List<Long> tagIds;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class DraftDto {
|
||||
private Long id;
|
||||
private String title;
|
||||
private String content;
|
||||
private Long categoryId;
|
||||
private List<Long> tagIds;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
package com.openisle.controller;
|
||||
|
||||
import com.openisle.model.Notification;
|
||||
import com.openisle.model.NotificationType;
|
||||
import com.openisle.model.ReactionType;
|
||||
import com.openisle.dto.AuthorDto;
|
||||
import com.openisle.dto.CommentDto;
|
||||
import com.openisle.dto.NotificationDto;
|
||||
import com.openisle.dto.NotificationMarkReadRequest;
|
||||
import com.openisle.dto.NotificationUnreadCountDto;
|
||||
import com.openisle.dto.PostSummaryDto;
|
||||
import com.openisle.model.Comment;
|
||||
import com.openisle.model.Post;
|
||||
import com.openisle.model.Notification;
|
||||
import com.openisle.service.NotificationService;
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -31,15 +33,15 @@ public class NotificationController {
|
||||
}
|
||||
|
||||
@GetMapping("/unread-count")
|
||||
public UnreadCount unreadCount(Authentication auth) {
|
||||
public NotificationUnreadCountDto unreadCount(Authentication auth) {
|
||||
long count = notificationService.countUnread(auth.getName());
|
||||
UnreadCount uc = new UnreadCount();
|
||||
NotificationUnreadCountDto uc = new NotificationUnreadCountDto();
|
||||
uc.setCount(count);
|
||||
return uc;
|
||||
}
|
||||
|
||||
@PostMapping("/read")
|
||||
public void markRead(@RequestBody MarkReadRequest req, Authentication auth) {
|
||||
public void markRead(@RequestBody NotificationMarkReadRequest req, Authentication auth) {
|
||||
notificationService.markRead(auth.getName(), req.getIds());
|
||||
}
|
||||
|
||||
@@ -48,7 +50,10 @@ public class NotificationController {
|
||||
dto.setId(n.getId());
|
||||
dto.setType(n.getType());
|
||||
if (n.getPost() != null) {
|
||||
dto.setPost(toPostDto(n.getPost()));
|
||||
PostSummaryDto postDto = new PostSummaryDto();
|
||||
postDto.setId(n.getPost().getId());
|
||||
postDto.setTitle(n.getPost().getTitle());
|
||||
dto.setPost(postDto);
|
||||
}
|
||||
if (n.getComment() != null) {
|
||||
dto.setComment(toCommentDto(n.getComment()));
|
||||
@@ -58,7 +63,11 @@ public class NotificationController {
|
||||
}
|
||||
}
|
||||
if (n.getFromUser() != null) {
|
||||
dto.setFromUser(toAuthorDto(n.getFromUser()));
|
||||
AuthorDto author = new AuthorDto();
|
||||
author.setId(n.getFromUser().getId());
|
||||
author.setUsername(n.getFromUser().getUsername());
|
||||
author.setAvatar(n.getFromUser().getAvatar());
|
||||
dto.setFromUser(author);
|
||||
}
|
||||
if (n.getReactionType() != null) {
|
||||
dto.setReactionType(n.getReactionType());
|
||||
@@ -70,73 +79,16 @@ public class NotificationController {
|
||||
return dto;
|
||||
}
|
||||
|
||||
private PostDto toPostDto(Post post) {
|
||||
PostDto dto = new PostDto();
|
||||
dto.setId(post.getId());
|
||||
dto.setTitle(post.getTitle());
|
||||
return dto;
|
||||
}
|
||||
|
||||
private CommentDto toCommentDto(Comment comment) {
|
||||
CommentDto dto = new CommentDto();
|
||||
dto.setId(comment.getId());
|
||||
dto.setContent(comment.getContent());
|
||||
dto.setCreatedAt(comment.getCreatedAt());
|
||||
dto.setAuthor(toAuthorDto(comment.getAuthor()));
|
||||
AuthorDto author = new AuthorDto();
|
||||
author.setId(comment.getAuthor().getId());
|
||||
author.setUsername(comment.getAuthor().getUsername());
|
||||
author.setAvatar(comment.getAuthor().getAvatar());
|
||||
dto.setAuthor(author);
|
||||
return dto;
|
||||
}
|
||||
|
||||
private AuthorDto toAuthorDto(com.openisle.model.User user) {
|
||||
AuthorDto dto = new AuthorDto();
|
||||
dto.setId(user.getId());
|
||||
dto.setUsername(user.getUsername());
|
||||
dto.setAvatar(user.getAvatar());
|
||||
return dto;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class MarkReadRequest {
|
||||
private List<Long> ids;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class NotificationDto {
|
||||
private Long id;
|
||||
private NotificationType type;
|
||||
private PostDto post;
|
||||
private CommentDto comment;
|
||||
private CommentDto parentComment;
|
||||
private AuthorDto fromUser;
|
||||
private ReactionType reactionType;
|
||||
private String content;
|
||||
private Boolean approved;
|
||||
private boolean read;
|
||||
private LocalDateTime createdAt;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class PostDto {
|
||||
private Long id;
|
||||
private String title;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class CommentDto {
|
||||
private Long id;
|
||||
private String content;
|
||||
private LocalDateTime createdAt;
|
||||
private AuthorDto author;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class AuthorDto {
|
||||
private Long id;
|
||||
private String username;
|
||||
private String avatar;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class UnreadCount {
|
||||
private long count;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package com.openisle.controller;
|
||||
|
||||
import com.openisle.dto.PushPublicKeyDto;
|
||||
import com.openisle.dto.PushSubscriptionRequest;
|
||||
import com.openisle.service.PushSubscriptionService;
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.security.core.Authentication;
|
||||
@@ -16,26 +17,14 @@ public class PushSubscriptionController {
|
||||
private String publicKey;
|
||||
|
||||
@GetMapping("/public-key")
|
||||
public PublicKeyResponse getPublicKey() {
|
||||
PublicKeyResponse r = new PublicKeyResponse();
|
||||
public PushPublicKeyDto getPublicKey() {
|
||||
PushPublicKeyDto r = new PushPublicKeyDto();
|
||||
r.setKey(publicKey);
|
||||
return r;
|
||||
}
|
||||
|
||||
@PostMapping("/subscribe")
|
||||
public void subscribe(@RequestBody SubscriptionRequest req, Authentication auth) {
|
||||
public void subscribe(@RequestBody PushSubscriptionRequest req, Authentication auth) {
|
||||
pushSubscriptionService.saveSubscription(auth.getName(), req.getEndpoint(), req.getP256dh(), req.getAuth());
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class PublicKeyResponse {
|
||||
private String key;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class SubscriptionRequest {
|
||||
private String endpoint;
|
||||
private String p256dh;
|
||||
private String auth;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package com.openisle.controller;
|
||||
|
||||
import com.openisle.dto.ReactionDto;
|
||||
import com.openisle.dto.ReactionRequest;
|
||||
import com.openisle.model.Reaction;
|
||||
import com.openisle.model.ReactionType;
|
||||
import com.openisle.service.ReactionService;
|
||||
import com.openisle.service.LevelService;
|
||||
import com.openisle.service.ReactionService;
|
||||
import jakarta.transaction.Transactional;
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.core.Authentication;
|
||||
@@ -66,19 +67,4 @@ public class ReactionController {
|
||||
dto.setReward(0);
|
||||
return dto;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class ReactionRequest {
|
||||
private ReactionType type;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class ReactionDto {
|
||||
private Long id;
|
||||
private ReactionType type;
|
||||
private String user;
|
||||
private Long postId;
|
||||
private Long commentId;
|
||||
private int reward;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package com.openisle.controller;
|
||||
|
||||
import com.openisle.dto.PostSummaryDto;
|
||||
import com.openisle.dto.SearchResultDto;
|
||||
import com.openisle.dto.UserDto;
|
||||
import com.openisle.model.Post;
|
||||
import com.openisle.model.Comment;
|
||||
import com.openisle.model.User;
|
||||
import com.openisle.service.SearchService;
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -28,21 +29,21 @@ public class SearchController {
|
||||
}
|
||||
|
||||
@GetMapping("/posts")
|
||||
public List<PostDto> searchPosts(@RequestParam String keyword) {
|
||||
public List<PostSummaryDto> searchPosts(@RequestParam String keyword) {
|
||||
return searchService.searchPosts(keyword).stream()
|
||||
.map(this::toPostDto)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@GetMapping("/posts/content")
|
||||
public List<PostDto> searchPostsByContent(@RequestParam String keyword) {
|
||||
public List<PostSummaryDto> searchPostsByContent(@RequestParam String keyword) {
|
||||
return searchService.searchPostsByContent(keyword).stream()
|
||||
.map(this::toPostDto)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@GetMapping("/posts/title")
|
||||
public List<PostDto> searchPostsByTitle(@RequestParam String keyword) {
|
||||
public List<PostSummaryDto> searchPostsByTitle(@RequestParam String keyword) {
|
||||
return searchService.searchPostsByTitle(keyword).stream()
|
||||
.map(this::toPostDto)
|
||||
.collect(Collectors.toList());
|
||||
@@ -72,33 +73,10 @@ public class SearchController {
|
||||
return dto;
|
||||
}
|
||||
|
||||
private PostDto toPostDto(Post post) {
|
||||
PostDto dto = new PostDto();
|
||||
private PostSummaryDto toPostDto(Post post) {
|
||||
PostSummaryDto dto = new PostSummaryDto();
|
||||
dto.setId(post.getId());
|
||||
dto.setTitle(post.getTitle());
|
||||
return dto;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class UserDto {
|
||||
private Long id;
|
||||
private String username;
|
||||
private String avatar;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class PostDto {
|
||||
private Long id;
|
||||
private String title;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class SearchResultDto {
|
||||
private String type;
|
||||
private Long id;
|
||||
private String text;
|
||||
private String subText;
|
||||
private String extra;
|
||||
private Long postId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
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.dto.PostSummaryDto;
|
||||
import com.openisle.dto.TagDto;
|
||||
import com.openisle.dto.TagRequest;
|
||||
import com.openisle.mapper.PostMapper;
|
||||
import com.openisle.model.PublishMode;
|
||||
import com.openisle.model.Role;
|
||||
import lombok.Data;
|
||||
import com.openisle.model.Tag;
|
||||
import com.openisle.repository.UserRepository;
|
||||
import com.openisle.service.PostService;
|
||||
import com.openisle.service.TagService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -20,6 +23,7 @@ public class TagController {
|
||||
private final TagService tagService;
|
||||
private final PostService postService;
|
||||
private final UserRepository userRepository;
|
||||
private final PostMapper postMapper;
|
||||
|
||||
@PostMapping
|
||||
public TagDto create(@RequestBody TagRequest req, org.springframework.security.core.Authentication auth) {
|
||||
@@ -79,12 +83,7 @@ public class TagController {
|
||||
@RequestParam(value = "pageSize", required = false) Integer pageSize) {
|
||||
return postService.listPostsByTags(java.util.List.of(id), page, pageSize)
|
||||
.stream()
|
||||
.map(p -> {
|
||||
PostSummaryDto dto = new PostSummaryDto();
|
||||
dto.setId(p.getId());
|
||||
dto.setTitle(p.getTitle());
|
||||
return dto;
|
||||
})
|
||||
.map(postMapper::toSummaryDto)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@@ -95,31 +94,8 @@ public class TagController {
|
||||
dto.setIcon(tag.getIcon());
|
||||
dto.setSmallIcon(tag.getSmallIcon());
|
||||
dto.setDescription(tag.getDescription());
|
||||
dto.setCreatedAt(tag.getCreatedAt());
|
||||
dto.setCount(count);
|
||||
return dto;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class TagRequest {
|
||||
private String name;
|
||||
private String description;
|
||||
private String icon;
|
||||
private String smallIcon;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class TagDto {
|
||||
private Long id;
|
||||
private String name;
|
||||
private String description;
|
||||
private String icon;
|
||||
private String smallIcon;
|
||||
private Long count;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class PostSummaryDto {
|
||||
private Long id;
|
||||
private String title;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
package com.openisle.controller;
|
||||
|
||||
import com.openisle.dto.CommentInfoDto;
|
||||
import com.openisle.dto.ParentCommentDto;
|
||||
import com.openisle.dto.PostMetaDto;
|
||||
import com.openisle.dto.TagDto;
|
||||
import com.openisle.dto.UpdateProfileDto;
|
||||
import com.openisle.dto.UserAggregateDto;
|
||||
import com.openisle.dto.UserDto;
|
||||
import com.openisle.exception.NotFoundException;
|
||||
import com.openisle.model.User;
|
||||
import com.openisle.service.*;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.core.Authentication;
|
||||
@@ -139,13 +145,13 @@ public class UserController {
|
||||
}
|
||||
|
||||
@GetMapping("/{identifier}/hot-tags")
|
||||
public java.util.List<TagInfoDto> hotTags(@PathVariable("identifier") String identifier,
|
||||
@RequestParam(value = "limit", required = false) Integer limit) {
|
||||
public java.util.List<TagDto> hotTags(@PathVariable("identifier") String identifier,
|
||||
@RequestParam(value = "limit", required = false) Integer limit) {
|
||||
int l = limit != null ? limit : 10;
|
||||
User user = userService.findByIdentifier(identifier).orElseThrow();
|
||||
return tagService.getTagsByUser(user.getUsername()).stream()
|
||||
.map(t -> {
|
||||
TagInfoDto dto = new TagInfoDto();
|
||||
TagDto dto = new TagDto();
|
||||
dto.setId(t.getId());
|
||||
dto.setName(t.getName());
|
||||
dto.setDescription(t.getDescription());
|
||||
@@ -161,13 +167,13 @@ public class UserController {
|
||||
}
|
||||
|
||||
@GetMapping("/{identifier}/tags")
|
||||
public java.util.List<TagInfoDto> userTags(@PathVariable("identifier") String identifier,
|
||||
@RequestParam(value = "limit", required = false) Integer limit) {
|
||||
public java.util.List<TagDto> userTags(@PathVariable("identifier") String identifier,
|
||||
@RequestParam(value = "limit", required = false) Integer limit) {
|
||||
int l = limit != null ? limit : defaultTagsLimit;
|
||||
User user = userService.findByIdentifier(identifier).orElseThrow();
|
||||
return tagService.getRecentTagsByUser(user.getUsername(), l).stream()
|
||||
.map(t -> {
|
||||
TagInfoDto dto = new TagInfoDto();
|
||||
TagDto dto = new TagDto();
|
||||
dto.setId(t.getId());
|
||||
dto.setName(t.getName());
|
||||
dto.setDescription(t.getDescription());
|
||||
@@ -294,78 +300,4 @@ public class UserController {
|
||||
}
|
||||
return dto;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class UserDto {
|
||||
private Long id;
|
||||
private String username;
|
||||
private String email;
|
||||
private String avatar;
|
||||
private String role;
|
||||
private String introduction;
|
||||
private long followers;
|
||||
private long following;
|
||||
private java.time.LocalDateTime createdAt;
|
||||
private java.time.LocalDateTime lastPostTime;
|
||||
private java.time.LocalDateTime lastCommentTime;
|
||||
private long totalViews;
|
||||
private long visitedDays;
|
||||
private long readPosts;
|
||||
private long likesSent;
|
||||
private long likesReceived;
|
||||
private boolean subscribed;
|
||||
private int experience;
|
||||
private int currentLevel;
|
||||
private int nextLevelExp;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class PostMetaDto {
|
||||
private Long id;
|
||||
private String title;
|
||||
private String snippet;
|
||||
private java.time.LocalDateTime createdAt;
|
||||
private String category;
|
||||
private long views;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class CommentInfoDto {
|
||||
private Long id;
|
||||
private String content;
|
||||
private java.time.LocalDateTime createdAt;
|
||||
private PostMetaDto post;
|
||||
private ParentCommentDto parentComment;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class TagInfoDto {
|
||||
private Long id;
|
||||
private String name;
|
||||
private String description;
|
||||
private String icon;
|
||||
private String smallIcon;
|
||||
private java.time.LocalDateTime createdAt;
|
||||
private Long count;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class ParentCommentDto {
|
||||
private Long id;
|
||||
private String author;
|
||||
private String content;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class UpdateProfileDto {
|
||||
private String username;
|
||||
private String introduction;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class UserAggregateDto {
|
||||
private UserDto user;
|
||||
private java.util.List<PostMetaDto> posts;
|
||||
private java.util.List<CommentInfoDto> replies;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user