Skip to content

Commit

Permalink
feat: 添加对于附件标签的服务端支持 (#708)
Browse files Browse the repository at this point in the history
  • Loading branch information
chivehao authored Oct 19, 2024
1 parent b10fdaa commit ffb000a
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

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

# 0.17.4

## 新特性

- 添加对于附件标签的服务端支持

# 0.17.3

## 新特性
Expand Down
22 changes: 22 additions & 0 deletions api/src/main/java/run/ikaros/api/core/tag/AttachmentTag.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package run.ikaros.api.core.tag;

import java.time.LocalDateTime;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;


@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class AttachmentTag {
private Long id;
private Long attachmentId;
private String name;
private Long userId;
private LocalDateTime createTime;
}
11 changes: 10 additions & 1 deletion api/src/main/java/run/ikaros/api/store/enums/TagType.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,14 @@

public enum TagType {
SUBJECT,
EPISODE
EPISODE,
/**
* Attachment Tag.
* <ul>
* <li>
* subject:000
* </li>
* </ul>
*/
ATTACHMENT
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=0.17.3
version=0.17.4
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.springframework.util.Assert;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import run.ikaros.api.core.tag.AttachmentTag;
import run.ikaros.api.core.tag.SubjectTag;
import run.ikaros.api.core.tag.Tag;
import run.ikaros.api.infra.exception.NotFoundException;
Expand Down Expand Up @@ -74,6 +75,19 @@ public Flux<SubjectTag> findSubjectTags(Long subjectId) {
.build());
}

@Override
public Flux<AttachmentTag> findAttachmentTags(Long attachmentId) {
Assert.isTrue(attachmentId >= 0, "'attachmentId' must >=0.");
return findAll(TagType.ATTACHMENT, attachmentId, null, null)
.map(tag -> AttachmentTag.builder()
.id(tag.getId())
.attachmentId(tag.getMasterId())
.userId(tag.getUserId())
.name(tag.getName())
.createTime(tag.getCreateTime())
.build());
}

@Override
public Mono<Tag> create(Tag tag) {
Assert.isNull(tag.getId(), "'tag id' must is null.");
Expand Down
22 changes: 21 additions & 1 deletion server/src/main/java/run/ikaros/server/core/tag/TagEndpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Mono;
import run.ikaros.api.constant.OpenApiConst;
import run.ikaros.api.core.tag.AttachmentTag;
import run.ikaros.api.core.tag.SubjectTag;
import run.ikaros.api.core.tag.Tag;
import run.ikaros.api.infra.utils.StringUtils;
Expand Down Expand Up @@ -63,6 +64,14 @@ public RouterFunction<ServerResponse> endpoint() {
.in(ParameterIn.PATH).implementation(Long.class))
.response(responseBuilder().implementationArray(SubjectTag.class)))

.GET("/tags/attachment/attachmentId/{attachmentId}",
this::listAttachmentTagsByAttachmentId,
builder -> builder.operationId("ListAttachmentTagsByAttachmentId")
.tag(tag).description("List attachment tags by attachment id.")
.parameter(parameterBuilder().name("attachmentId").required(true)
.in(ParameterIn.PATH).implementation(Long.class))
.response(responseBuilder().implementationArray(AttachmentTag.class)))

.POST("/tag", this::create,
builder -> builder.operationId("CreateTag")
.tag(tag).description("Create tag")
Expand Down Expand Up @@ -121,14 +130,25 @@ private Mono<ServerResponse> listByCondition(ServerRequest request) {

private Mono<ServerResponse> listSubjectTagsBySubjectId(ServerRequest request) {
String subjectIdS = request.pathVariable("subjectId");
Assert.hasText(subjectIdS, "'subjectId' mus has value.");
Assert.hasText(subjectIdS, "'subjectId' must has value.");
Long subjectId = Long.parseLong(subjectIdS);
return tagService.findSubjectTags(subjectId)
.collectList()
.flatMap(subjectTags -> ServerResponse.ok()
.bodyValue(subjectTags));
}


private Mono<ServerResponse> listAttachmentTagsByAttachmentId(ServerRequest request) {
String attachmentIdS = request.pathVariable("attachmentId");
Assert.hasText(attachmentIdS, "'attachmentId' must has value.");
Long attachmentId = Long.parseLong(attachmentIdS);
return tagService.findAttachmentTags(attachmentId)
.collectList()
.flatMap(attachmentTags -> ServerResponse.ok()
.bodyValue(attachmentTags));
}

private Mono<ServerResponse> create(ServerRequest request) {
return request.bodyToMono(Tag.class)
.flatMap(tag -> request.principal()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import run.ikaros.api.core.tag.AttachmentTag;
import run.ikaros.api.core.tag.SubjectTag;
import run.ikaros.api.core.tag.Tag;
import run.ikaros.api.store.enums.TagType;
Expand All @@ -11,6 +12,8 @@ public interface TagService {

Flux<SubjectTag> findSubjectTags(Long subjectId);

Flux<AttachmentTag> findAttachmentTags(Long attachmentId);

Mono<Tag> create(Tag tag);

Mono<Void> remove(TagType type, Long masterId, String name);
Expand Down

0 comments on commit ffb000a

Please sign in to comment.