Skip to content

Commit

Permalink
fix: create subject tag (#762)
Browse files Browse the repository at this point in the history
  • Loading branch information
chivehao authored Jan 8, 2025
1 parent 6a938a9 commit 6c036b7
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions server/src/main/java/run/ikaros/server/core/tag/TagEndpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import static org.springdoc.core.fn.builders.requestbody.Builder.requestBodyBuilder;

import io.swagger.v3.oas.annotations.enums.ParameterIn;
import java.security.Principal;
import java.util.Optional;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.webflux.core.fn.SpringdocRouteBuilder;
import org.springframework.security.authentication.AuthenticationCredentialsNotFoundException;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import org.springframework.web.reactive.function.server.RouterFunction;
Expand Down Expand Up @@ -151,10 +151,11 @@ private Mono<ServerResponse> listAttachmentTagsByAttachmentId(ServerRequest requ

private Mono<ServerResponse> create(ServerRequest request) {
return request.bodyToMono(Tag.class)
.flatMap(tag -> userService.getUserIdFromSecurityContext()
.map(tag::setUserId)
.onErrorResume(AuthenticationCredentialsNotFoundException.class,
e -> Mono.just(tag)))
.flatMap(tag -> request.principal()
.map(Principal::getName)
.flatMap(userService::getUserByUsername)
.map(user -> user.entity().getId())
.map(tag::setUserId))
.flatMap(tagService::create)
.flatMap(tag -> ServerResponse.ok().bodyValue(tag));
}
Expand Down

0 comments on commit 6c036b7

Please sign in to comment.