Merge pull request #929 from nagisa77/codex/add-user-avatar-return-in-changelog

feat: expand post change log details
This commit is contained in:
Tim
2025-09-08 13:54:51 +08:00
committed by GitHub
9 changed files with 80 additions and 4 deletions

View File

@@ -11,6 +11,7 @@ import java.time.LocalDateTime;
public class PostChangeLogDto { public class PostChangeLogDto {
private Long id; private Long id;
private String username; private String username;
private String userAvatar;
private PostChangeType type; private PostChangeType type;
private LocalDateTime time; private LocalDateTime time;
private String oldTitle; private String oldTitle;

View File

@@ -9,7 +9,10 @@ public class PostChangeLogMapper {
public PostChangeLogDto toDto(PostChangeLog log) { public PostChangeLogDto toDto(PostChangeLog log) {
PostChangeLogDto dto = new PostChangeLogDto(); PostChangeLogDto dto = new PostChangeLogDto();
dto.setId(log.getId()); dto.setId(log.getId());
dto.setUsername(log.getUser().getUsername()); if (log.getUser() != null) {
dto.setUsername(log.getUser().getUsername());
dto.setUserAvatar(log.getUser().getAvatar());
}
dto.setType(log.getType()); dto.setType(log.getType());
dto.setTime(log.getCreatedAt()); dto.setTime(log.getCreatedAt());
if (log instanceof PostTitleChangeLog t) { if (log instanceof PostTitleChangeLog t) {

View File

@@ -23,7 +23,7 @@ public abstract class PostChangeLog {
@JoinColumn(name = "post_id") @JoinColumn(name = "post_id")
private Post post; private Post post;
@ManyToOne(fetch = FetchType.LAZY, optional = false) @ManyToOne(fetch = FetchType.LAZY, optional = true)
@JoinColumn(name = "user_id") @JoinColumn(name = "user_id")
private User user; private User user;

View File

@@ -7,5 +7,7 @@ public enum PostChangeType {
TAG, TAG,
CLOSED, CLOSED,
PINNED, PINNED,
FEATURED FEATURED,
VOTE_RESULT,
LOTTERY_RESULT
} }

View File

@@ -0,0 +1,16 @@
package com.openisle.model;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Getter
@Setter
@NoArgsConstructor
@Entity
@Table(name = "post_lottery_result_change_logs")
public class PostLotteryResultChangeLog extends PostChangeLog {
}

View File

@@ -0,0 +1,16 @@
package com.openisle.model;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Getter
@Setter
@NoArgsConstructor
@Entity
@Table(name = "post_vote_result_change_logs")
public class PostVoteResultChangeLog extends PostChangeLog {
}

View File

@@ -86,6 +86,20 @@ public class PostChangeLogService {
logRepository.save(log); logRepository.save(log);
} }
public void recordVoteResult(Post post) {
PostVoteResultChangeLog log = new PostVoteResultChangeLog();
log.setPost(post);
log.setType(PostChangeType.VOTE_RESULT);
logRepository.save(log);
}
public void recordLotteryResult(Post post) {
PostLotteryResultChangeLog log = new PostLotteryResultChangeLog();
log.setPost(post);
log.setType(PostChangeType.LOTTERY_RESULT);
logRepository.save(log);
}
public List<PostChangeLog> listLogs(Long postId) { public List<PostChangeLog> listLogs(Long postId) {
Post post = postRepository.findById(postId) Post post = postRepository.findById(postId)
.orElseThrow(() -> new com.openisle.exception.NotFoundException("Post not found")); .orElseThrow(() -> new com.openisle.exception.NotFoundException("Post not found"));

View File

@@ -1,7 +1,13 @@
<template> <template>
<div :id="`change-log-${log.id}`" class="change-log-container"> <div :id="`change-log-${log.id}`" class="change-log-container">
<div class="change-log-text"> <div class="change-log-text">
<span class="change-log-user">{{ log.username }}</span> <BaseImage
v-if="log.userAvatar"
class="change-log-avatar"
:src="log.userAvatar"
alt="avatar"
/>
<span v-if="log.username" class="change-log-user">{{ log.username }}</span>
<span v-if="log.type === 'CONTENT'">变更了文章内容</span> <span v-if="log.type === 'CONTENT'">变更了文章内容</span>
<span v-else-if="log.type === 'TITLE'">变更了文章标题</span> <span v-else-if="log.type === 'TITLE'">变更了文章标题</span>
<span v-else-if="log.type === 'CATEGORY'">变更了文章分类</span> <span v-else-if="log.type === 'CATEGORY'">变更了文章分类</span>
@@ -18,6 +24,8 @@
<template v-if="log.newFeatured">将文章设为精选</template> <template v-if="log.newFeatured">将文章设为精选</template>
<template v-else>取消精选文章</template> <template v-else>取消精选文章</template>
</span> </span>
<span v-else-if="log.type === 'VOTE_RESULT'">投票已出结果</span>
<span v-else-if="log.type === 'LOTTERY_RESULT'">抽奖已开奖</span>
</div> </div>
<div class="change-log-time">{{ log.time }}</div> <div class="change-log-time">{{ log.time }}</div>
<div <div
@@ -34,6 +42,7 @@ import { html } from 'diff2html'
import { createTwoFilesPatch } from 'diff' import { createTwoFilesPatch } from 'diff'
import { useIsMobile } from '~/utils/screen' import { useIsMobile } from '~/utils/screen'
import 'diff2html/bundles/css/diff2html.min.css' import 'diff2html/bundles/css/diff2html.min.css'
import BaseImage from '~/components/BaseImage.vue'
const props = defineProps({ const props = defineProps({
log: Object, log: Object,
title: String, title: String,
@@ -76,10 +85,20 @@ const diffHtml = computed(() => {
opacity: 0.7; opacity: 0.7;
font-size: 14px; font-size: 14px;
} }
.change-log-text {
display: flex;
align-items: center;
}
.change-log-user { .change-log-user {
font-weight: bold; font-weight: bold;
margin-right: 4px; margin-right: 4px;
} }
.change-log-avatar {
width: 20px;
height: 20px;
border-radius: 50%;
margin-right: 4px;
}
.change-log-time { .change-log-time {
font-size: 12px; font-size: 12px;
opacity: 0.6; opacity: 0.6;

View File

@@ -363,6 +363,10 @@ const changeLogIcon = (l) => {
} else { } else {
return 'dislike' return 'dislike'
} }
} else if (l.type === 'VOTE_RESULT') {
return 'check-one'
} else if (l.type === 'LOTTERY_RESULT') {
return 'gift'
} else { } else {
return 'info' return 'info'
} }
@@ -371,6 +375,7 @@ const changeLogIcon = (l) => {
const mapChangeLog = (l) => ({ const mapChangeLog = (l) => ({
id: l.id, id: l.id,
username: l.username, username: l.username,
userAvatar: l.userAvatar,
type: l.type, type: l.type,
createdAt: l.time, createdAt: l.time,
time: TimeManager.format(l.time), time: TimeManager.format(l.time),