mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-04-21 11:27:27 +08:00
Merge pull request #90 from nagisa77/codex/return-full-object-for-tags-and-categories
This commit is contained in:
@@ -43,11 +43,21 @@ public class AdminPostController {
|
|||||||
dto.setContent(post.getContent());
|
dto.setContent(post.getContent());
|
||||||
dto.setCreatedAt(post.getCreatedAt());
|
dto.setCreatedAt(post.getCreatedAt());
|
||||||
dto.setAuthor(post.getAuthor().getUsername());
|
dto.setAuthor(post.getAuthor().getUsername());
|
||||||
dto.setCategory(post.getCategory().getName());
|
dto.setCategory(toCategoryDto(post.getCategory()));
|
||||||
dto.setViews(post.getViews());
|
dto.setViews(post.getViews());
|
||||||
return dto;
|
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
|
@Data
|
||||||
private static class PostDto {
|
private static class PostDto {
|
||||||
private Long id;
|
private Long id;
|
||||||
@@ -55,7 +65,16 @@ public class AdminPostController {
|
|||||||
private String content;
|
private String content;
|
||||||
private LocalDateTime createdAt;
|
private LocalDateTime createdAt;
|
||||||
private String author;
|
private String author;
|
||||||
private String category;
|
private CategoryDto category;
|
||||||
private long views;
|
private long views;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
private static class CategoryDto {
|
||||||
|
private Long id;
|
||||||
|
private String name;
|
||||||
|
private String description;
|
||||||
|
private String icon;
|
||||||
|
private String smallIcon;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,8 +84,8 @@ public class PostController {
|
|||||||
dto.setContent(post.getContent());
|
dto.setContent(post.getContent());
|
||||||
dto.setCreatedAt(post.getCreatedAt());
|
dto.setCreatedAt(post.getCreatedAt());
|
||||||
dto.setAuthor(post.getAuthor().getUsername());
|
dto.setAuthor(post.getAuthor().getUsername());
|
||||||
dto.setCategory(post.getCategory().getName());
|
dto.setCategory(toCategoryDto(post.getCategory()));
|
||||||
dto.setTags(post.getTags().stream().map(com.openisle.model.Tag::getName).collect(Collectors.toList()));
|
dto.setTags(post.getTags().stream().map(this::toTagDto).collect(Collectors.toList()));
|
||||||
dto.setViews(post.getViews());
|
dto.setViews(post.getViews());
|
||||||
|
|
||||||
List<ReactionDto> reactions = reactionService.getReactionsForPost(post.getId())
|
List<ReactionDto> reactions = reactionService.getReactionsForPost(post.getId())
|
||||||
@@ -142,6 +142,26 @@ public class PostController {
|
|||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private CategoryDto toCategoryDto(com.openisle.model.Category category) {
|
||||||
|
CategoryDto dto = new CategoryDto();
|
||||||
|
dto.setId(category.getId());
|
||||||
|
dto.setName(category.getName());
|
||||||
|
dto.setDescription(category.getDescription());
|
||||||
|
dto.setIcon(category.getIcon());
|
||||||
|
dto.setSmallIcon(category.getSmallIcon());
|
||||||
|
return dto;
|
||||||
|
}
|
||||||
|
|
||||||
|
private TagDto toTagDto(com.openisle.model.Tag tag) {
|
||||||
|
TagDto dto = new TagDto();
|
||||||
|
dto.setId(tag.getId());
|
||||||
|
dto.setName(tag.getName());
|
||||||
|
dto.setDescription(tag.getDescription());
|
||||||
|
dto.setIcon(tag.getIcon());
|
||||||
|
dto.setSmallIcon(tag.getSmallIcon());
|
||||||
|
return dto;
|
||||||
|
}
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
private static class PostRequest {
|
private static class PostRequest {
|
||||||
private Long categoryId;
|
private Long categoryId;
|
||||||
@@ -158,13 +178,31 @@ public class PostController {
|
|||||||
private String content;
|
private String content;
|
||||||
private LocalDateTime createdAt;
|
private LocalDateTime createdAt;
|
||||||
private String author;
|
private String author;
|
||||||
private String category;
|
private CategoryDto category;
|
||||||
private java.util.List<String> tags;
|
private java.util.List<TagDto> tags;
|
||||||
private long views;
|
private long views;
|
||||||
private List<CommentDto> comments;
|
private List<CommentDto> comments;
|
||||||
private List<ReactionDto> reactions;
|
private List<ReactionDto> reactions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
private static class CategoryDto {
|
||||||
|
private Long id;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
private static class CommentDto {
|
private static class CommentDto {
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|||||||
Reference in New Issue
Block a user