Merge pull request #105 from li-guohao/dev

feat: article subject list by star.
This commit is contained in:
xiaozzzi 2024-04-04 15:24:50 +08:00 committed by GitHub
commit a246b0f055
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 109 additions and 10 deletions

View File

@ -5,6 +5,8 @@ import cn.hutool.core.util.ObjUtil;
import com.blossom.backend.base.auth.AuthContext;
import com.blossom.backend.base.auth.annotation.AuthIgnore;
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.doc.DocService;
import com.blossom.backend.server.folder.pojo.*;
@ -44,15 +46,27 @@ public class FolderController {
if (userId == null) {
return R.ok(new ArrayList<>());
}
return R.ok(baseService.subjects(userId));
return R.ok(baseService.subjects(userId, null));
}
/**
* 查询专题列表
*/
@GetMapping("/subjects")
public R<List<FolderSubjectRes>> listSubject() {
return R.ok(baseService.subjects(AuthContext.getUserId()));
public R<List<FolderSubjectRes>> listSubject(@RequestParam("starStatus") Integer starStatus) {
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);
res.setTags(DocUtil.toTagList(entity.getTags()));
res.setType(entity.getType());
res.setStarStatus(entity.getStarStatus());
return R.ok(res);
}

View File

@ -23,11 +23,13 @@ import com.blossom.common.base.util.DateUtils;
import com.blossom.common.base.util.PrimaryKeyUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
@ -51,6 +53,8 @@ public class FolderService extends ServiceImpl<FolderMapper, FolderEntity> {
this.pictureService = pictureService;
}
/**
* 专题列表
* <p>1. 查询全部公开专题
@ -60,12 +64,14 @@ public class FolderService extends ServiceImpl<FolderMapper, FolderEntity> {
* <p>5. 通过文件夹ID获取到专题下的所有文章, 从而统计文章的总字数, 修改时间, 创建时间等.
* <p>6. 如果文章包含 TOC 标签, 则该文章为专题的目录, 专题的默认跳转会跳转至该目录
*/
public List<FolderSubjectRes> subjects(Long userId) {
// 1. 查询所有公开的专题
public List<FolderSubjectRes> subjects(Long userId, @Nullable Integer starStatus) {
// 1. 查询所有专题
FolderEntity where = new FolderEntity();
where.setTags(TagEnum.subject.name());
where.setOpenStatus(YesNo.YES.getValue());
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);
if (CollUtil.isEmpty(allOpenSubject)) {
return new ArrayList<>();
@ -196,6 +202,7 @@ public class FolderService extends ServiceImpl<FolderMapper, FolderEntity> {
public Long update(FolderEntity folder) {
XzException404.throwBy(folder.getId() == null, "ID不得为空");
XzException400.throwBy(folder.getId().equals(folder.getPid()), "上级文件夹不能是自己");
if (Objects.isNull(folder.getStarStatus())) {folder.setStarStatus(0);}
// 如果
if (StrUtil.isNotBlank(folder.getStorePath())) {
final FolderEntity oldFolder = selectById(folder.getId());
@ -214,6 +221,7 @@ public class FolderService extends ServiceImpl<FolderMapper, FolderEntity> {
}
}
folder.setStorePath(formatStorePath(folder.getStorePath()));
if (Objects.isNull(folder.getStarStatus())) { folder.setStarStatus(0);}
baseMapper.updById(folder);
return folder.getId();
}

View File

@ -44,6 +44,10 @@ public class FolderEntity extends AbstractPOJO implements Serializable {
* 标签
*/
private String tags;
/**
* star状态
*/
private Integer starStatus;
/**
* 开放状态
*/

View File

@ -16,6 +16,10 @@ import java.io.Serializable;
public class FolderQueryReq extends PageReq implements Serializable {
private static final long serialVersionUID = 1L;
/**
* star状态
*/
private Integer starStatus;
private String tags;

View File

@ -39,6 +39,10 @@ public class FolderRes extends AbstractPOJO implements Serializable {
* 标签
*/
private List<String> tags;
/**
* star状态
*/
private Integer starStatus;
/**
* 是否公开文件夹 [0:未公开1:公开]
*/

View File

@ -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;
}

View File

@ -33,6 +33,10 @@ public class FolderUpdReq extends AbstractPOJO implements Serializable {
private String name;
/** 图标 */
private String icon;
/**
* star状态
*/
private Integer starStatus;
/** 标签 */
private List<String> tags;
/** 排序 */

View File

@ -37,6 +37,7 @@ spring:
init:
mode: always
platform: mysql
continue-on-error: true
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫ mybatis ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

View File

@ -9,6 +9,7 @@
`name`,
icon,
tags,
star_status,
open_status,
sort,
cover,
@ -21,6 +22,7 @@
cre_time
from blossom_folder
<where>
<if test="starStatus != null ">and star_status = #{starStatus}</if>
<if test="openStatus != null ">and open_status = #{openStatus}</if>
<if test="type != null ">and type = #{type}</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="icon != null">icon = #{icon},</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="cover != null">cover = #{cover},</if>
<if test="color != null">color = #{color},</if>

View File

@ -638,4 +638,7 @@ CREATE TABLE IF NOT EXISTS `base_user_param`
UNIQUE KEY `unq_bup_userid_paramname` (`user_id`, `param_name`) COMMENT '用户参数唯一'
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4 COMMENT = '用户参数'
COLLATE = utf8mb4_bin;
COLLATE = utf8mb4_bin;
-- Code that might be wrong goes last
alter table blossom_folder add column star_status tinyint(1) NOT NULL DEFAULT 0 COMMENT '收藏 0:否,1:是';

View File

@ -274,6 +274,15 @@ export const articleStarApi = (data?: object): Promise<R<any>> => {
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
* @param params

View File

@ -69,7 +69,7 @@
<!-- 星标 -->
<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>
</div>
@ -239,6 +239,7 @@ import {
import { isNotBlank, isNull } from '@renderer/assets/utils/obj'
import { openExtenal, openNewIconWindow } from '@renderer/assets/utils/electron'
import Notify from '@renderer/scripts/notify'
import {folderStarApi} from "../../api/blossom";
//#region --------------------------------------------------< >--------------------------------------------------
const userStore = useUserStore()
@ -484,6 +485,12 @@ const star = (changeStarStatus: number) => {
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

View File

@ -56,7 +56,7 @@ let maxWords = 0
const subjects = ref<any>([])
const getSubjects = () => {
subjectsApi().then((resp) => {
subjectsApi({ starStatus: 1 }).then((resp) => {
subjects.value = resp.data
if (!isEmpty(resp.data)) {
maxWords = resp.data

View File

@ -26,7 +26,7 @@ import { subjectsApi } from '@/api/blossom'
onMounted(() => {
subjects.value = []
subjectsApi().then((resp) => {
subjectsApi({ starStatus: 1 }).then((resp) => {
subjects.value = resp.data
})
})