mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-28 09:00:48 +08:00
Compare commits
6 Commits
codex/fix-
...
feature/lo
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b64f9ef1f6 | ||
|
|
d26b96ebd1 | ||
|
|
13cc981421 | ||
|
|
efc8589ca0 | ||
|
|
940690889c | ||
|
|
d46420ef81 |
@@ -1,5 +1,6 @@
|
|||||||
package com.openisle.controller;
|
package com.openisle.controller;
|
||||||
|
|
||||||
|
import com.openisle.config.CachingConfig;
|
||||||
import com.openisle.dto.PostDetailDto;
|
import com.openisle.dto.PostDetailDto;
|
||||||
import com.openisle.dto.PostRequest;
|
import com.openisle.dto.PostRequest;
|
||||||
import com.openisle.dto.PostSummaryDto;
|
import com.openisle.dto.PostSummaryDto;
|
||||||
@@ -15,6 +16,7 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
|||||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
@@ -142,6 +144,10 @@ public class PostController {
|
|||||||
@Operation(summary = "List posts", description = "List posts by various filters")
|
@Operation(summary = "List posts", description = "List posts by various filters")
|
||||||
@ApiResponse(responseCode = "200", description = "List of posts",
|
@ApiResponse(responseCode = "200", description = "List of posts",
|
||||||
content = @Content(array = @ArraySchema(schema = @Schema(implementation = PostSummaryDto.class))))
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = PostSummaryDto.class))))
|
||||||
|
@Cacheable(
|
||||||
|
value = CachingConfig.POST_CACHE_NAME,
|
||||||
|
key = "new org.springframework.cache.interceptor.SimpleKey('default', #categoryId, #categoryIds, #tagId, #tagIds, #page, #pageSize)"
|
||||||
|
)
|
||||||
public List<PostSummaryDto> listPosts(@RequestParam(value = "categoryId", required = false) Long categoryId,
|
public List<PostSummaryDto> listPosts(@RequestParam(value = "categoryId", required = false) Long categoryId,
|
||||||
@RequestParam(value = "categoryIds", required = false) List<Long> categoryIds,
|
@RequestParam(value = "categoryIds", required = false) List<Long> categoryIds,
|
||||||
@RequestParam(value = "tagId", required = false) Long tagId,
|
@RequestParam(value = "tagId", required = false) Long tagId,
|
||||||
@@ -188,6 +194,10 @@ public class PostController {
|
|||||||
@Operation(summary = "Latest reply posts", description = "List posts by latest replies")
|
@Operation(summary = "Latest reply posts", description = "List posts by latest replies")
|
||||||
@ApiResponse(responseCode = "200", description = "Posts sorted by latest reply",
|
@ApiResponse(responseCode = "200", description = "Posts sorted by latest reply",
|
||||||
content = @Content(array = @ArraySchema(schema = @Schema(implementation = PostSummaryDto.class))))
|
content = @Content(array = @ArraySchema(schema = @Schema(implementation = PostSummaryDto.class))))
|
||||||
|
@Cacheable(
|
||||||
|
value = CachingConfig.POST_CACHE_NAME,
|
||||||
|
key = "new org.springframework.cache.interceptor.SimpleKey('latest_reply', #categoryId, #categoryIds, #tagIds, #page, #pageSize)"
|
||||||
|
)
|
||||||
public List<PostSummaryDto> latestReplyPosts(@RequestParam(value = "categoryId", required = false) Long categoryId,
|
public List<PostSummaryDto> latestReplyPosts(@RequestParam(value = "categoryId", required = false) Long categoryId,
|
||||||
@RequestParam(value = "categoryIds", required = false) List<Long> categoryIds,
|
@RequestParam(value = "categoryIds", required = false) List<Long> categoryIds,
|
||||||
@RequestParam(value = "tagId", required = false) Long tagId,
|
@RequestParam(value = "tagId", required = false) Long tagId,
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import org.springframework.stereotype.Component;
|
|||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/** Mapper responsible for converting posts into DTOs. */
|
/** Mapper responsible for converting posts into DTOs. */
|
||||||
@@ -99,6 +100,8 @@ public class PostMapper {
|
|||||||
l.setPointCost(lp.getPointCost());
|
l.setPointCost(lp.getPointCost());
|
||||||
l.setStartTime(lp.getStartTime());
|
l.setStartTime(lp.getStartTime());
|
||||||
l.setEndTime(lp.getEndTime());
|
l.setEndTime(lp.getEndTime());
|
||||||
|
l.setParticipants(lp.getParticipants().stream().map(userMapper::toAuthorDto).collect(Collectors.toList()));
|
||||||
|
l.setWinners(lp.getWinners().stream().map(userMapper::toAuthorDto).collect(Collectors.toList()));
|
||||||
dto.setLottery(l);
|
dto.setLottery(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,6 +110,7 @@ public class PostMapper {
|
|||||||
p.setOptions(pp.getOptions());
|
p.setOptions(pp.getOptions());
|
||||||
p.setVotes(pp.getVotes());
|
p.setVotes(pp.getVotes());
|
||||||
p.setEndTime(pp.getEndTime());
|
p.setEndTime(pp.getEndTime());
|
||||||
|
p.setParticipants(pp.getParticipants().stream().map(userMapper::toAuthorDto).collect(Collectors.toList()));
|
||||||
Map<Integer, List<AuthorDto>> optionParticipants = pollVoteRepository.findByPostId(pp.getId()).stream()
|
Map<Integer, List<AuthorDto>> optionParticipants = pollVoteRepository.findByPostId(pp.getId()).stream()
|
||||||
.collect(Collectors.groupingBy(PollVote::getOptionIndex,
|
.collect(Collectors.groupingBy(PollVote::getOptionIndex,
|
||||||
Collectors.mapping(v -> userMapper.toAuthorDto(v.getUser()), Collectors.toList())));
|
Collectors.mapping(v -> userMapper.toAuthorDto(v.getUser()), Collectors.toList())));
|
||||||
|
|||||||
@@ -323,6 +323,9 @@ public class PostService {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@CacheEvict(
|
||||||
|
value = CachingConfig.POST_CACHE_NAME, allEntries = true
|
||||||
|
)
|
||||||
public void joinLottery(Long postId, String username) {
|
public void joinLottery(Long postId, String username) {
|
||||||
LotteryPost post = lotteryPostRepository.findById(postId)
|
LotteryPost post = lotteryPostRepository.findById(postId)
|
||||||
.orElseThrow(() -> new com.openisle.exception.NotFoundException("Post not found"));
|
.orElseThrow(() -> new com.openisle.exception.NotFoundException("Post not found"));
|
||||||
@@ -339,6 +342,9 @@ public class PostService {
|
|||||||
.orElseThrow(() -> new com.openisle.exception.NotFoundException("Post not found"));
|
.orElseThrow(() -> new com.openisle.exception.NotFoundException("Post not found"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@CacheEvict(
|
||||||
|
value = CachingConfig.POST_CACHE_NAME, allEntries = true
|
||||||
|
)
|
||||||
@Transactional
|
@Transactional
|
||||||
public PollPost votePoll(Long postId, String username, java.util.List<Integer> optionIndices) {
|
public PollPost votePoll(Long postId, String username, java.util.List<Integer> optionIndices) {
|
||||||
PollPost post = pollPostRepository.findById(postId)
|
PollPost post = pollPostRepository.findById(postId)
|
||||||
@@ -376,6 +382,9 @@ public class PostService {
|
|||||||
return saved;
|
return saved;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@CacheEvict(
|
||||||
|
value = CachingConfig.POST_CACHE_NAME, allEntries = true
|
||||||
|
)
|
||||||
@Transactional
|
@Transactional
|
||||||
public void finalizePoll(Long postId) {
|
public void finalizePoll(Long postId) {
|
||||||
scheduledFinalizations.remove(postId);
|
scheduledFinalizations.remove(postId);
|
||||||
@@ -395,6 +404,9 @@ public class PostService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@CacheEvict(
|
||||||
|
value = CachingConfig.POST_CACHE_NAME, allEntries = true
|
||||||
|
)
|
||||||
@Transactional
|
@Transactional
|
||||||
public void finalizeLottery(Long postId) {
|
public void finalizeLottery(Long postId) {
|
||||||
log.info("start to finalizeLottery for {}", postId);
|
log.info("start to finalizeLottery for {}", postId);
|
||||||
@@ -508,10 +520,6 @@ public class PostService {
|
|||||||
return listPostsByLatestReply(null, null, page, pageSize);
|
return listPostsByLatestReply(null, null, page, pageSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Cacheable(
|
|
||||||
value = CachingConfig.POST_CACHE_NAME,
|
|
||||||
key = "new org.springframework.cache.interceptor.SimpleKey('latest_reply', #categoryIds, #tagIds, #page, #pageSize)"
|
|
||||||
)
|
|
||||||
public List<Post> listPostsByLatestReply(java.util.List<Long> categoryIds,
|
public List<Post> listPostsByLatestReply(java.util.List<Long> categoryIds,
|
||||||
java.util.List<Long> tagIds,
|
java.util.List<Long> tagIds,
|
||||||
Integer page,
|
Integer page,
|
||||||
@@ -647,10 +655,6 @@ public class PostService {
|
|||||||
* @param pageSize
|
* @param pageSize
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Cacheable(
|
|
||||||
value = CachingConfig.POST_CACHE_NAME,
|
|
||||||
key = "new org.springframework.cache.interceptor.SimpleKey('default', #ids, #tids, #page, #pageSize)"
|
|
||||||
)
|
|
||||||
public List<Post> defaultListPosts(List<Long> ids, List<Long> tids, Integer page, Integer pageSize){
|
public List<Post> defaultListPosts(List<Long> ids, List<Long> tids, Integer page, Integer pageSize){
|
||||||
boolean hasCategories = !CollectionUtils.isEmpty(ids);
|
boolean hasCategories = !CollectionUtils.isEmpty(ids);
|
||||||
boolean hasTags = !CollectionUtils.isEmpty(tids);
|
boolean hasTags = !CollectionUtils.isEmpty(tids);
|
||||||
|
|||||||
@@ -107,14 +107,52 @@ const likeCount = computed(() => counts.value['LIKE'] || 0)
|
|||||||
const userReacted = (type) =>
|
const userReacted = (type) =>
|
||||||
reactions.value.some((r) => r.type === type && r.user === authState.username)
|
reactions.value.some((r) => r.type === type && r.user === authState.username)
|
||||||
|
|
||||||
const displayedReactions = computed(() => {
|
const baseReactionOrder = computed(() => {
|
||||||
return Object.entries(counts.value)
|
if (reactionTypes.value.length) return [...reactionTypes.value]
|
||||||
.sort((a, b) => b[1] - a[1])
|
|
||||||
.slice(0, 3)
|
const order = []
|
||||||
.map(([type]) => ({ type }))
|
const seen = new Set()
|
||||||
|
for (const reaction of reactions.value) {
|
||||||
|
if (!seen.has(reaction.type)) {
|
||||||
|
seen.add(reaction.type)
|
||||||
|
order.push(reaction.type)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return order
|
||||||
})
|
})
|
||||||
|
|
||||||
const panelTypes = computed(() => reactionTypes.value.filter((t) => t !== 'LIKE'))
|
const sortedReactionTypes = computed(() => {
|
||||||
|
const baseOrder = [...baseReactionOrder.value]
|
||||||
|
for (const type of Object.keys(counts.value)) {
|
||||||
|
if (!baseOrder.includes(type)) baseOrder.push(type)
|
||||||
|
}
|
||||||
|
|
||||||
|
const withMetadata = baseOrder.map((type, index) => ({
|
||||||
|
type,
|
||||||
|
count: counts.value[type] || 0,
|
||||||
|
index,
|
||||||
|
}))
|
||||||
|
|
||||||
|
const nonZero = withMetadata
|
||||||
|
.filter((item) => item.count > 0)
|
||||||
|
.sort((a, b) => {
|
||||||
|
if (b.count !== a.count) return b.count - a.count
|
||||||
|
return a.index - b.index
|
||||||
|
})
|
||||||
|
|
||||||
|
const zero = withMetadata.filter((item) => item.count === 0)
|
||||||
|
|
||||||
|
return [...nonZero, ...zero].map((item) => item.type)
|
||||||
|
})
|
||||||
|
|
||||||
|
const displayedReactions = computed(() => {
|
||||||
|
return sortedReactionTypes.value
|
||||||
|
.filter((type) => counts.value[type] > 0)
|
||||||
|
.slice(0, 3)
|
||||||
|
.map((type) => ({ type }))
|
||||||
|
})
|
||||||
|
|
||||||
|
const panelTypes = computed(() => sortedReactionTypes.value.filter((t) => t !== 'LIKE'))
|
||||||
|
|
||||||
const panelVisible = ref(false)
|
const panelVisible = ref(false)
|
||||||
let hideTimer = null
|
let hideTimer = null
|
||||||
|
|||||||
@@ -122,7 +122,8 @@
|
|||||||
<l-hatch size="28" stroke="4" speed="3.5" color="var(--primary-color)"></l-hatch>
|
<l-hatch size="28" stroke="4" speed="3.5" color="var(--primary-color)"></l-hatch>
|
||||||
</div>
|
</div>
|
||||||
<div v-else class="comments-container">
|
<div v-else class="comments-container">
|
||||||
<BaseTimeline :items="timelineItems">
|
<BasePlaceholder v-if="timelineItems.length === 0" text="暂无评论" icon="inbox" />
|
||||||
|
<BaseTimeline v-else :items="timelineItems">
|
||||||
<template #item="{ item }">
|
<template #item="{ item }">
|
||||||
<CommentItem
|
<CommentItem
|
||||||
v-if="item.kind === 'comment'"
|
v-if="item.kind === 'comment'"
|
||||||
@@ -184,6 +185,7 @@ import { useRoute } from 'vue-router'
|
|||||||
import CommentItem from '~/components/CommentItem.vue'
|
import CommentItem from '~/components/CommentItem.vue'
|
||||||
import CommentEditor from '~/components/CommentEditor.vue'
|
import CommentEditor from '~/components/CommentEditor.vue'
|
||||||
import BaseTimeline from '~/components/BaseTimeline.vue'
|
import BaseTimeline from '~/components/BaseTimeline.vue'
|
||||||
|
import BasePlaceholder from '~/components/BasePlaceholder.vue'
|
||||||
import PostChangeLogItem from '~/components/PostChangeLogItem.vue'
|
import PostChangeLogItem from '~/components/PostChangeLogItem.vue'
|
||||||
import ArticleTags from '~/components/ArticleTags.vue'
|
import ArticleTags from '~/components/ArticleTags.vue'
|
||||||
import ArticleCategory from '~/components/ArticleCategory.vue'
|
import ArticleCategory from '~/components/ArticleCategory.vue'
|
||||||
@@ -813,9 +815,7 @@ const fetchCommentsAndChangeLog = async () => {
|
|||||||
|
|
||||||
for (const item of data) {
|
for (const item of data) {
|
||||||
const mappedPayload =
|
const mappedPayload =
|
||||||
item.kind === 'comment'
|
item.kind === 'comment' ? mapComment(item.payload) : mapChangeLog(item.payload)
|
||||||
? mapComment(item.payload)
|
|
||||||
: mapChangeLog(item.payload)
|
|
||||||
newTimelineItemList.push(mappedPayload)
|
newTimelineItemList.push(mappedPayload)
|
||||||
|
|
||||||
if (item.kind === 'comment') {
|
if (item.kind === 'comment') {
|
||||||
|
|||||||
Reference in New Issue
Block a user