Skip to content

Commit

Permalink
optimize: 提供给插件的内部接口 (#686)
Browse files Browse the repository at this point in the history
* feat: 添加TagOperate以支持插件对标签的查询和新增

* feat: 出于安全性考虑插件的内部接口移除所有的删除方法

* build: upgrade to v0.16.0
  • Loading branch information
chivehao authored Oct 14, 2024
1 parent a8afdba commit 319e692
Show file tree
Hide file tree
Showing 19 changed files with 66 additions and 72 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

更新日志文档,版本顺序从新到旧,最新版本在最前(上)面。

# 0.15.11
# 0.16.0

## 新特性

- Console支持管理和加载全局header和footer配置

## 插件支持

- 添加`MetaOperate`以支持插件调用三方元数据插件条目查寻
- 添加`MetaOperate`以支持插件调用三方元数据插件条目查询
- 添加`TagOperate`以支持插件对标签的查询和新增
- 出于安全性考虑插件的内部接口移除所有的删除方法

# 0.15.10

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,13 @@ public interface AttachmentOperate extends AllowPluginOperate {

Mono<PagingWrap<Attachment>> listByCondition(AttachmentSearchCondition searchCondition);

Mono<Void> removeById(Long attachmentId);

Mono<Attachment> upload(AttachmentUploadCondition uploadCondition);

Mono<Attachment> findById(Long attachmentId);

Mono<Attachment> findByTypeAndParentIdAndName(AttachmentType type, @Nullable Long parentId,
String name);

Mono<Void> removeByTypeAndParentIdAndName(
AttachmentType type, @Nullable Long parentId, String name);


Mono<Attachment> createDirectory(@Nullable Long parentId, @NotBlank String name);

Mono<Boolean> existsByParentIdAndName(@Nullable Long parentId, String name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ public interface AttachmentReferenceOperate extends AllowPluginOperate {
Flux<AttachmentReference> findAllByTypeAndAttachmentId(
AttachmentReferenceType type, Long attachmentId);

Mono<Void> removeById(Long attachmentRefId);

Mono<Void> removeByTypeAndAttachmentIdAndReferenceId(
AttachmentReferenceType type, Long attachmentId, Long referenceId);

Mono<Void> matchingAttachmentsAndSubjectEpisodes(Long subjectId, Long[] attachmentIds);

Mono<Void> matchingAttachmentsAndSubjectEpisodes(Long subjectId, Long[] attachmentIds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
public interface EpisodeCollectionOperate extends CollectionOperate {
Mono<EpisodeCollection> create(Long userId, Long episodeId);

Mono<EpisodeCollection> remove(Long userId, Long episodeId);

Mono<EpisodeCollection> findByUserIdAndEpisodeId(Long userId, Long episodeId);

Mono<Void> updateEpisodeCollectionProgress(Long userId, Long episodeId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ public interface SubjectCollectionOperate extends CollectionOperate {
Mono<Void> collect(Long userId, Long subjectId,
CollectionType type, Boolean isPrivate);

Mono<Void> unCollect(Long userId, Long subjectId);

Mono<SubjectCollection> findCollection(Long userId, Long subjectId);

Mono<PagingWrap<SubjectCollection>> findCollections(Long userId, Integer page,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public interface SubjectOperate extends AllowPluginOperate {

Mono<Void> update(Subject subject);

Mono<Void> removeById(Long id);

Mono<Subject> syncByPlatform(@Nullable Long subjectId, SubjectSyncPlatform platform,
String platformId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ public interface SubjectRelationOperate extends AllowPluginOperate {

Mono<SubjectRelation> createSubjectRelation(SubjectRelation subjectRelation);

Mono<SubjectRelation> removeSubjectRelation(SubjectRelation subjectRelation);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ public interface SubjectSyncPlatformOperate extends AllowPluginOperate {

Mono<SubjectSync> save(SubjectSync subjectSync);

Mono<Void> remove(SubjectSync subjectSync);

Flux<SubjectSync> findSubjectSyncsBySubjectId(long subjectId);

Mono<SubjectSync> findSubjectSyncBySubjectIdAndPlatform(long subjectId,
Expand Down
14 changes: 14 additions & 0 deletions api/src/main/java/run/ikaros/api/core/tag/TagOperate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package run.ikaros.api.core.tag;

import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import run.ikaros.api.plugin.AllowPluginOperate;
import run.ikaros.api.store.enums.TagType;

public interface TagOperate extends AllowPluginOperate {
Flux<Tag> findAll(TagType type, Long masterId, Long userId, String name);

Flux<SubjectTag> findSubjectTags(Long subjectId);

Mono<Tag> create(Tag tag);
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=0.15.11
version=0.16.0
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ public Mono<PagingWrap<Attachment>> listByCondition(AttachmentSearchCondition se
return service.listByCondition(searchCondition);
}

@Override
public Mono<Void> removeById(Long attachmentId) {
return service.removeById(attachmentId);
}

@Override
public Mono<Attachment> upload(AttachmentUploadCondition uploadCondition) {
return service.upload(uploadCondition);
Expand All @@ -52,12 +47,6 @@ public Mono<Attachment> findByTypeAndParentIdAndName(AttachmentType type,
return service.findByTypeAndParentIdAndName(type, parentId, name);
}

@Override
public Mono<Void> removeByTypeAndParentIdAndName(AttachmentType type, @Nullable Long parentId,
String name) {
return service.removeByTypeAndParentIdAndName(type, parentId, name);
}

@Override
public Mono<Attachment> createDirectory(@Nullable Long parentId, String name) {
return service.createDirectory(parentId, name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,6 @@ public Flux<AttachmentReference> findAllByTypeAndAttachmentId(AttachmentReferenc
return service.findAllByTypeAndAttachmentId(type, attachmentId);
}

@Override
public Mono<Void> removeById(Long attachmentRefId) {
return service.removeById(attachmentRefId);
}

@Override
public Mono<Void> removeByTypeAndAttachmentIdAndReferenceId(AttachmentReferenceType type,
Long attachmentId,
Long referenceId) {
return service.removeByTypeAndAttachmentIdAndReferenceId(type, attachmentId, referenceId);
}

@Override
public Mono<Void> matchingAttachmentsAndSubjectEpisodes(Long subjectId, Long[] attachmentIds) {
return service.matchingAttachmentsAndSubjectEpisodes(subjectId, attachmentIds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ public Mono<EpisodeCollection> create(Long userId, Long episodeId) {
return service.create(userId, episodeId);
}

@Override
public Mono<EpisodeCollection> remove(Long userId, Long episodeId) {
return service.remove(userId, episodeId);
}

@Override
public Mono<EpisodeCollection> findByUserIdAndEpisodeId(Long userId, Long episodeId) {
return service.findByUserIdAndEpisodeId(userId, episodeId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ public Mono<Void> collect(Long userId, Long subjectId, CollectionType type, Bool
return service.collect(userId, subjectId, type, isPrivate);
}

@Override
public Mono<Void> unCollect(Long userId, Long subjectId) {
return service.unCollect(userId, subjectId);
}

@Override
public Mono<SubjectCollection> findCollection(Long userId, Long subjectId) {
return service.findCollection(userId, subjectId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ public Mono<Void> update(Subject subject) {
return subjectService.update(subject);
}

@Override
public Mono<Void> removeById(Long id) {
return subjectService.deleteById(id);
}

@Override
public Mono<Subject> syncByPlatform(@Nullable Long subjectId, SubjectSyncPlatform platform,
String platformId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,4 @@ public Mono<SubjectRelation> createSubjectRelation(SubjectRelation subjectRelati
return subjectRelationService.createSubjectRelation(subjectRelation);
}

@Override
public Mono<SubjectRelation> removeSubjectRelation(SubjectRelation subjectRelation) {
return subjectRelationService.removeSubjectRelation(subjectRelation);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ public Mono<SubjectSync> save(SubjectSync subjectSync) {
return service.save(subjectSync);
}

@Override
public Mono<Void> remove(SubjectSync subjectSync) {
return service.remove(subjectSync);
}

@Override
public Flux<SubjectSync> findSubjectSyncsBySubjectId(long subjectId) {
return service.findSubjectSyncsBySubjectId(subjectId);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package run.ikaros.server.core.tag;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import run.ikaros.api.core.tag.SubjectTag;
import run.ikaros.api.core.tag.Tag;
import run.ikaros.api.core.tag.TagOperate;
import run.ikaros.api.store.enums.TagType;

@Slf4j
@Service
public class DefaultTagOperator implements TagOperate {
private final TagService tagService;

public DefaultTagOperator(TagService tagService) {
this.tagService = tagService;
}

@Override
public Flux<Tag> findAll(TagType type, Long masterId, Long userId, String name) {
return tagService.findAll(type, masterId, userId, name);
}

@Override
public Flux<SubjectTag> findSubjectTags(Long subjectId) {
return tagService.findSubjectTags(subjectId);
}

@Override
public Mono<Tag> create(Tag tag) {
return tagService.create(tag);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import run.ikaros.api.infra.exception.NotFoundException;
import run.ikaros.api.infra.utils.StringUtils;
import run.ikaros.api.store.enums.TagType;
import run.ikaros.server.core.user.UserService;
import run.ikaros.server.store.entity.TagEntity;
import run.ikaros.server.store.repository.TagRepository;

Expand All @@ -25,10 +26,17 @@
public class DefaultTagService implements TagService {
private final TagRepository tagRepository;
private final R2dbcEntityTemplate r2dbcEntityTemplate;
private final UserService userService;

public DefaultTagService(TagRepository tagRepository, R2dbcEntityTemplate r2dbcEntityTemplate) {
/**
* Construct.
*/
public DefaultTagService(TagRepository tagRepository,
R2dbcEntityTemplate r2dbcEntityTemplate,
UserService userService) {
this.tagRepository = tagRepository;
this.r2dbcEntityTemplate = r2dbcEntityTemplate;
this.userService = userService;
}

@Override
Expand Down Expand Up @@ -76,8 +84,9 @@ public Mono<Tag> create(Tag tag) {
Assert.notNull(tag.getType(), "'type' must not null.");
Assert.isTrue(tag.getMasterId() >= 0, "'masterId' must >=0.");
Assert.hasText(tag.getName(), "'name' must has text.");
return Mono.just(tag)
.flatMap(tag1 -> copyProperties(tag1, new TagEntity()))
return userService.getUserIdFromSecurityContext()
.map(tag::setUserId)
.flatMap(t -> copyProperties(t, new TagEntity()))
.flatMap(tagRepository::save)
.flatMap(tagEntity -> copyProperties(tagEntity, tag));
}
Expand Down

0 comments on commit 319e692

Please sign in to comment.