mirror of
https://github.com/blossom-editor/blossom
synced 2024-11-17 14:39:21 +08:00
feat: article subject list by star.
This commit is contained in:
parent
5de8435536
commit
34f2c34f68
@ -5,6 +5,8 @@ import cn.hutool.core.util.ObjUtil;
|
|||||||
import com.blossom.backend.base.auth.AuthContext;
|
import com.blossom.backend.base.auth.AuthContext;
|
||||||
import com.blossom.backend.base.auth.annotation.AuthIgnore;
|
import com.blossom.backend.base.auth.annotation.AuthIgnore;
|
||||||
import com.blossom.backend.config.BlConstants;
|
import com.blossom.backend.config.BlConstants;
|
||||||
|
import com.blossom.backend.server.article.draft.pojo.ArticleEntity;
|
||||||
|
import com.blossom.backend.server.article.draft.pojo.ArticleStarReq;
|
||||||
import com.blossom.backend.server.article.draft.pojo.ArticleUpdTagReq;
|
import com.blossom.backend.server.article.draft.pojo.ArticleUpdTagReq;
|
||||||
import com.blossom.backend.server.doc.DocService;
|
import com.blossom.backend.server.doc.DocService;
|
||||||
import com.blossom.backend.server.folder.pojo.*;
|
import com.blossom.backend.server.folder.pojo.*;
|
||||||
@ -44,15 +46,27 @@ public class FolderController {
|
|||||||
if (userId == null) {
|
if (userId == null) {
|
||||||
return R.ok(new ArrayList<>());
|
return R.ok(new ArrayList<>());
|
||||||
}
|
}
|
||||||
return R.ok(baseService.subjects(userId));
|
return R.ok(baseService.subjects(userId, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询专题列表
|
* 查询专题列表
|
||||||
*/
|
*/
|
||||||
@GetMapping("/subjects")
|
@GetMapping("/subjects")
|
||||||
public R<List<FolderSubjectRes>> listSubject() {
|
public R<List<FolderSubjectRes>> listSubject(@RequestParam("starStatus") Integer starStatus) {
|
||||||
return R.ok(baseService.subjects(AuthContext.getUserId()));
|
return R.ok(baseService.subjects(AuthContext.getUserId(), starStatus));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 星标目录
|
||||||
|
*
|
||||||
|
* @param req 目录对象
|
||||||
|
*/
|
||||||
|
@PostMapping("/star")
|
||||||
|
public R<Long> star(@Validated @RequestBody FolderStarReq req) {
|
||||||
|
FolderEntity folder = req.to(FolderEntity.class);
|
||||||
|
folder.setUserId(AuthContext.getUserId());
|
||||||
|
return R.ok(baseService.update(folder));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -68,6 +82,7 @@ public class FolderController {
|
|||||||
FolderRes res = entity.to(FolderRes.class);
|
FolderRes res = entity.to(FolderRes.class);
|
||||||
res.setTags(DocUtil.toTagList(entity.getTags()));
|
res.setTags(DocUtil.toTagList(entity.getTags()));
|
||||||
res.setType(entity.getType());
|
res.setType(entity.getType());
|
||||||
|
res.setStarStatus(entity.getStarStatus());
|
||||||
return R.ok(res);
|
return R.ok(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,11 +23,13 @@ import com.blossom.common.base.util.DateUtils;
|
|||||||
import com.blossom.common.base.util.PrimaryKeyUtil;
|
import com.blossom.common.base.util.PrimaryKeyUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -51,6 +53,8 @@ public class FolderService extends ServiceImpl<FolderMapper, FolderEntity> {
|
|||||||
this.pictureService = pictureService;
|
this.pictureService = pictureService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 专题列表
|
* 专题列表
|
||||||
* <p>1. 查询全部公开专题
|
* <p>1. 查询全部公开专题
|
||||||
@ -60,12 +64,14 @@ public class FolderService extends ServiceImpl<FolderMapper, FolderEntity> {
|
|||||||
* <p>5. 通过文件夹ID获取到专题下的所有文章, 从而统计文章的总字数, 修改时间, 创建时间等.
|
* <p>5. 通过文件夹ID获取到专题下的所有文章, 从而统计文章的总字数, 修改时间, 创建时间等.
|
||||||
* <p>6. 如果文章包含 TOC 标签, 则该文章为专题的目录, 专题的默认跳转会跳转至该目录
|
* <p>6. 如果文章包含 TOC 标签, 则该文章为专题的目录, 专题的默认跳转会跳转至该目录
|
||||||
*/
|
*/
|
||||||
public List<FolderSubjectRes> subjects(Long userId) {
|
public List<FolderSubjectRes> subjects(Long userId, @Nullable Integer starStatus) {
|
||||||
// 1. 查询所有公开的专题
|
// 1. 查询所有专题
|
||||||
FolderEntity where = new FolderEntity();
|
FolderEntity where = new FolderEntity();
|
||||||
where.setTags(TagEnum.subject.name());
|
where.setTags(TagEnum.subject.name());
|
||||||
where.setOpenStatus(YesNo.YES.getValue());
|
|
||||||
where.setUserId(userId);
|
where.setUserId(userId);
|
||||||
|
if (Objects.nonNull(starStatus) &&
|
||||||
|
(starStatus.equals(1) || starStatus.equals(0))) { where.setStarStatus(starStatus); }
|
||||||
|
else {where.setStarStatus(0);}
|
||||||
List<FolderEntity> allOpenSubject = baseMapper.listAll(where);
|
List<FolderEntity> allOpenSubject = baseMapper.listAll(where);
|
||||||
if (CollUtil.isEmpty(allOpenSubject)) {
|
if (CollUtil.isEmpty(allOpenSubject)) {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
@ -196,6 +202,7 @@ public class FolderService extends ServiceImpl<FolderMapper, FolderEntity> {
|
|||||||
public Long update(FolderEntity folder) {
|
public Long update(FolderEntity folder) {
|
||||||
XzException404.throwBy(folder.getId() == null, "ID不得为空");
|
XzException404.throwBy(folder.getId() == null, "ID不得为空");
|
||||||
XzException400.throwBy(folder.getId().equals(folder.getPid()), "上级文件夹不能是自己");
|
XzException400.throwBy(folder.getId().equals(folder.getPid()), "上级文件夹不能是自己");
|
||||||
|
if (Objects.isNull(folder.getStarStatus())) {folder.setStarStatus(0);}
|
||||||
// 如果
|
// 如果
|
||||||
if (StrUtil.isNotBlank(folder.getStorePath())) {
|
if (StrUtil.isNotBlank(folder.getStorePath())) {
|
||||||
final FolderEntity oldFolder = selectById(folder.getId());
|
final FolderEntity oldFolder = selectById(folder.getId());
|
||||||
@ -214,6 +221,7 @@ public class FolderService extends ServiceImpl<FolderMapper, FolderEntity> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
folder.setStorePath(formatStorePath(folder.getStorePath()));
|
folder.setStorePath(formatStorePath(folder.getStorePath()));
|
||||||
|
if (Objects.isNull(folder.getStarStatus())) { folder.setStarStatus(0);}
|
||||||
baseMapper.updById(folder);
|
baseMapper.updById(folder);
|
||||||
return folder.getId();
|
return folder.getId();
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,10 @@ public class FolderEntity extends AbstractPOJO implements Serializable {
|
|||||||
* 标签
|
* 标签
|
||||||
*/
|
*/
|
||||||
private String tags;
|
private String tags;
|
||||||
|
/**
|
||||||
|
* star状态
|
||||||
|
*/
|
||||||
|
private Integer starStatus;
|
||||||
/**
|
/**
|
||||||
* 开放状态
|
* 开放状态
|
||||||
*/
|
*/
|
||||||
|
@ -16,6 +16,10 @@ import java.io.Serializable;
|
|||||||
public class FolderQueryReq extends PageReq implements Serializable {
|
public class FolderQueryReq extends PageReq implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
/**
|
||||||
|
* star状态
|
||||||
|
*/
|
||||||
|
private Integer starStatus;
|
||||||
|
|
||||||
private String tags;
|
private String tags;
|
||||||
|
|
||||||
|
@ -39,6 +39,10 @@ public class FolderRes extends AbstractPOJO implements Serializable {
|
|||||||
* 标签
|
* 标签
|
||||||
*/
|
*/
|
||||||
private List<String> tags;
|
private List<String> tags;
|
||||||
|
/**
|
||||||
|
* star状态
|
||||||
|
*/
|
||||||
|
private Integer starStatus;
|
||||||
/**
|
/**
|
||||||
* 是否公开文件夹 [0:未公开,1:公开]
|
* 是否公开文件夹 [0:未公开,1:公开]
|
||||||
*/
|
*/
|
||||||
|
@ -0,0 +1,37 @@
|
|||||||
|
package com.blossom.backend.server.folder.pojo;
|
||||||
|
|
||||||
|
|
||||||
|
import com.blossom.common.base.enums.YesNo;
|
||||||
|
import com.blossom.common.base.pojo.AbstractPOJO;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import javax.validation.constraints.Max;
|
||||||
|
import javax.validation.constraints.Min;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文章 star
|
||||||
|
*
|
||||||
|
* @author xzzz
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class FolderStarReq extends AbstractPOJO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 目录ID
|
||||||
|
*/
|
||||||
|
@Min(value = 0, message = "[目录ID] 不能小于0")
|
||||||
|
@NotNull(message = "[目录ID] 为必填项")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* star 状态 {@link YesNo}
|
||||||
|
* @see YesNo
|
||||||
|
*/
|
||||||
|
@Min(value = 0, message = "[star 状态] 不能小于0")
|
||||||
|
@Max(value = 1, message = "[star 状态] 不能大于1")
|
||||||
|
@NotNull(message = "[star 状态] 为必填项")
|
||||||
|
private Integer starStatus;
|
||||||
|
}
|
@ -33,6 +33,10 @@ public class FolderUpdReq extends AbstractPOJO implements Serializable {
|
|||||||
private String name;
|
private String name;
|
||||||
/** 图标 */
|
/** 图标 */
|
||||||
private String icon;
|
private String icon;
|
||||||
|
/**
|
||||||
|
* star状态
|
||||||
|
*/
|
||||||
|
private Integer starStatus;
|
||||||
/** 标签 */
|
/** 标签 */
|
||||||
private List<String> tags;
|
private List<String> tags;
|
||||||
/** 排序 */
|
/** 排序 */
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
`name`,
|
`name`,
|
||||||
icon,
|
icon,
|
||||||
tags,
|
tags,
|
||||||
|
star_status,
|
||||||
open_status,
|
open_status,
|
||||||
sort,
|
sort,
|
||||||
cover,
|
cover,
|
||||||
@ -21,6 +22,7 @@
|
|||||||
cre_time
|
cre_time
|
||||||
from blossom_folder
|
from blossom_folder
|
||||||
<where>
|
<where>
|
||||||
|
<if test="starStatus != null ">and star_status = #{starStatus}</if>
|
||||||
<if test="openStatus != null ">and open_status = #{openStatus}</if>
|
<if test="openStatus != null ">and open_status = #{openStatus}</if>
|
||||||
<if test="type != null ">and type = #{type}</if>
|
<if test="type != null ">and type = #{type}</if>
|
||||||
<if test="tags != null and tags != ''">and tags like concat('%',#{tags},'%')</if>
|
<if test="tags != null and tags != ''">and tags like concat('%',#{tags},'%')</if>
|
||||||
@ -62,6 +64,7 @@
|
|||||||
<if test="name != null">`name` = #{name},</if>
|
<if test="name != null">`name` = #{name},</if>
|
||||||
<if test="icon != null">icon = #{icon},</if>
|
<if test="icon != null">icon = #{icon},</if>
|
||||||
<if test="tags != null">tags = #{tags},</if>
|
<if test="tags != null">tags = #{tags},</if>
|
||||||
|
<if test="starStatus != null">star_status = #{starStatus},</if>
|
||||||
<if test="sort != null">sort = #{sort},</if>
|
<if test="sort != null">sort = #{sort},</if>
|
||||||
<if test="cover != null">cover = #{cover},</if>
|
<if test="cover != null">cover = #{cover},</if>
|
||||||
<if test="color != null">color = #{color},</if>
|
<if test="color != null">color = #{color},</if>
|
||||||
|
@ -435,6 +435,7 @@ CREATE TABLE IF NOT EXISTS `blossom_folder`
|
|||||||
`name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL DEFAULT '' COMMENT '文件夹名称',
|
`name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL DEFAULT '' COMMENT '文件夹名称',
|
||||||
`icon` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL DEFAULT '' COMMENT '图标',
|
`icon` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL DEFAULT '' COMMENT '图标',
|
||||||
`tags` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL DEFAULT '' COMMENT '标签',
|
`tags` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL DEFAULT '' COMMENT '标签',
|
||||||
|
`star_status` tinyint(1) NOT NULL DEFAULT 0 COMMENT '收藏 0:否,1:是',
|
||||||
`open_status` tinyint(1) NOT NULL DEFAULT 0 COMMENT '开放状态',
|
`open_status` tinyint(1) NOT NULL DEFAULT 0 COMMENT '开放状态',
|
||||||
`sort` int UNSIGNED NOT NULL DEFAULT 1 COMMENT '排序',
|
`sort` int UNSIGNED NOT NULL DEFAULT 1 COMMENT '排序',
|
||||||
`cover` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL DEFAULT '' COMMENT '封面图片',
|
`cover` varchar(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL DEFAULT '' COMMENT '封面图片',
|
||||||
|
@ -274,6 +274,15 @@ export const articleStarApi = (data?: object): Promise<R<any>> => {
|
|||||||
return rq.post<R<any>>('/article/star', data)
|
return rq.post<R<any>>('/article/star', data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* star 或取消 star
|
||||||
|
* @param data
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export const folderStarApi = (data?: object): Promise<R<any>> => {
|
||||||
|
return rq.post<R<any>>('/folder/star', data)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 下载文章 markdown
|
* 下载文章 markdown
|
||||||
* @param params
|
* @param params
|
||||||
|
@ -69,7 +69,7 @@
|
|||||||
|
|
||||||
<!-- 星标 -->
|
<!-- 星标 -->
|
||||||
<div class="stat-star">
|
<div class="stat-star">
|
||||||
<div v-if="!curIsStar" :class="['iconbl bl-star-line', curDocDialogType == 'add' || curIsFolder ? 'disabled' : '']" @click="star(1)"></div>
|
<div v-if="!curIsStar" :class="['iconbl bl-star-line', curDocDialogType == 'add']" @click="star(1)"></div>
|
||||||
<div v-else class="iconbl bl-star-fill" @click="star(0)"></div>
|
<div v-else class="iconbl bl-star-fill" @click="star(0)"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -239,6 +239,7 @@ import {
|
|||||||
import { isNotBlank, isNull } from '@renderer/assets/utils/obj'
|
import { isNotBlank, isNull } from '@renderer/assets/utils/obj'
|
||||||
import { openExtenal, openNewIconWindow } from '@renderer/assets/utils/electron'
|
import { openExtenal, openNewIconWindow } from '@renderer/assets/utils/electron'
|
||||||
import Notify from '@renderer/scripts/notify'
|
import Notify from '@renderer/scripts/notify'
|
||||||
|
import {folderStarApi} from "../../api/blossom";
|
||||||
|
|
||||||
//#region --------------------------------------------------< 基本信息 >--------------------------------------------------
|
//#region --------------------------------------------------< 基本信息 >--------------------------------------------------
|
||||||
const userStore = useUserStore()
|
const userStore = useUserStore()
|
||||||
@ -484,6 +485,12 @@ const star = (changeStarStatus: number) => {
|
|||||||
Notify.success(docForm.value.starStatus === 0 ? '取消 Star 成功' : 'Star 成功')
|
Notify.success(docForm.value.starStatus === 0 ? '取消 Star 成功' : 'Star 成功')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
if (curIsFolder.value) {
|
||||||
|
docForm.value.starStatus = changeStarStatus
|
||||||
|
folderStarApi({ id: docForm.value.id, starStatus: docForm.value.starStatus }).then(() => {
|
||||||
|
Notify.success(docForm.value.starStatus === 0 ? '取消 Star 成功' : 'Star 成功')
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//#endregion
|
//#endregion
|
||||||
|
@ -56,7 +56,7 @@ let maxWords = 0
|
|||||||
const subjects = ref<any>([])
|
const subjects = ref<any>([])
|
||||||
|
|
||||||
const getSubjects = () => {
|
const getSubjects = () => {
|
||||||
subjectsApi().then((resp) => {
|
subjectsApi({ starStatus: 1 }).then((resp) => {
|
||||||
subjects.value = resp.data
|
subjects.value = resp.data
|
||||||
if (!isEmpty(resp.data)) {
|
if (!isEmpty(resp.data)) {
|
||||||
maxWords = resp.data
|
maxWords = resp.data
|
||||||
|
@ -26,7 +26,7 @@ import { subjectsApi } from '@/api/blossom'
|
|||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
subjects.value = []
|
subjects.value = []
|
||||||
subjectsApi().then((resp) => {
|
subjectsApi({ starStatus: 1 }).then((resp) => {
|
||||||
subjects.value = resp.data
|
subjects.value = resp.data
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user