-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Victor N. Skurikhin
committed
May 24, 2024
1 parent
f572dde
commit e5dba66
Showing
14 changed files
with
427 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
api-gateway/src/main/java/su/svn/daybook3/api/gateway/models/dto/NewJsonRecord.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* This file was last modified at 2024-05-24 11:40 by Victor N. Skurikhin. | ||
* This is free and unencumbered software released into the public domain. | ||
* For more information, please refer to <http://unlicense.org> | ||
* NewJsonRecord.java | ||
* $Id$ | ||
*/ | ||
|
||
package su.svn.daybook3.api.gateway.models.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonPropertyOrder; | ||
import lombok.Builder; | ||
|
||
import java.io.Serializable; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
|
||
@JsonPropertyOrder({"visible", "flags"}) | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
public record NewJsonRecord( | ||
@JsonProperty UUID parentId, | ||
@JsonProperty Map<String, String> values, | ||
@JsonProperty boolean visible, | ||
@JsonProperty int flags) implements Serializable { | ||
@Builder | ||
public NewJsonRecord { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
api-gateway/src/main/java/su/svn/daybook3/api/gateway/models/dto/UpdateJsonRecord.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* This file was last modified at 2024-05-24 11:59 by Victor N. Skurikhin. | ||
* This is free and unencumbered software released into the public domain. | ||
* For more information, please refer to <http://unlicense.org> | ||
* UpdateJsonRecord.java | ||
* $Id$ | ||
*/ | ||
|
||
package su.svn.daybook3.api.gateway.models.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.Builder; | ||
import su.svn.daybook3.api.gateway.models.UUIDIdentification; | ||
|
||
import java.io.Serializable; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
|
||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
public record UpdateJsonRecord( | ||
@JsonProperty UUID id, | ||
@JsonProperty Map<String, String> values, | ||
@JsonProperty boolean visible, | ||
@JsonProperty int flags) | ||
implements UUIDIdentification, Serializable { | ||
@Builder | ||
public UpdateJsonRecord { | ||
} | ||
} |
136 changes: 136 additions & 0 deletions
136
api-gateway/src/main/java/su/svn/daybook3/api/gateway/resources/JsonRecordResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
/* | ||
* This file was last modified at 2024-05-24 12:02 by Victor N. Skurikhin. | ||
* This is free and unencumbered software released into the public domain. | ||
* For more information, please refer to <http://unlicense.org> | ||
* JsonRecordResource.java | ||
* $Id$ | ||
*/ | ||
|
||
package su.svn.daybook3.api.gateway.resources; | ||
|
||
import io.smallrye.mutiny.Uni; | ||
import jakarta.annotation.security.RolesAllowed; | ||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.Consumes; | ||
import jakarta.ws.rs.DELETE; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.PUT; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.QueryParam; | ||
import jakarta.ws.rs.core.MediaType; | ||
import jakarta.ws.rs.core.Response; | ||
import org.eclipse.microprofile.openapi.annotations.Operation; | ||
import org.eclipse.microprofile.openapi.annotations.security.SecurityRequirement; | ||
import org.jboss.resteasy.reactive.RestResponse; | ||
import org.jboss.resteasy.reactive.server.ServerExceptionMapper; | ||
import su.svn.daybook3.api.gateway.annotations.PrincipalLogging; | ||
import su.svn.daybook3.api.gateway.domain.enums.ResourcePath; | ||
import su.svn.daybook3.api.gateway.domain.messages.Request; | ||
import su.svn.daybook3.api.gateway.models.dto.NewJsonRecord; | ||
import su.svn.daybook3.api.gateway.models.dto.UpdateJsonRecord; | ||
import su.svn.daybook3.api.gateway.models.pagination.PageRequest; | ||
import su.svn.daybook3.api.gateway.services.mappers.JsonRecordMapper; | ||
import su.svn.daybook3.api.gateway.services.models.JsonRecordService; | ||
|
||
import java.util.UUID; | ||
|
||
@PrincipalLogging | ||
@Path(ResourcePath.JSON_RECORD) | ||
public class JsonRecordResource | ||
extends AbstractResource { | ||
|
||
@Inject | ||
JsonRecordMapper mapper; | ||
|
||
@Inject | ||
JsonRecordService service; | ||
|
||
@Operation(summary = "Get JSON record") | ||
@GET | ||
@Path(ResourcePath.ID) | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public Uni<Response> get(UUID id) { | ||
|
||
var request = new Request<>(id, authContext.getPrincipal()); | ||
|
||
return service.get(request) | ||
.map(this::createResponseBuilder) | ||
.map(Response.ResponseBuilder::build); | ||
} | ||
|
||
@Operation(summary = "Get page with list of JSON record") | ||
@GET | ||
@Path(ResourcePath.PAGE) | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public Uni<Response> page(@QueryParam("page") int page, @QueryParam("limit") short limit) { | ||
|
||
var pageRequest = new PageRequest(page, limit); | ||
var request = new Request<>(pageRequest, authContext.getPrincipal()); | ||
|
||
return service.getPage(request) | ||
.map(this::createPageResponseBuilder) | ||
.map(Response.ResponseBuilder::build); | ||
} | ||
|
||
@Operation(summary = "Create JSON record") | ||
@POST | ||
@Path(ResourcePath.NONE) | ||
@RolesAllowed("ADMIN") | ||
@SecurityRequirement(name = "day-book") | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public Uni<Response> post(NewJsonRecord entry) { | ||
|
||
var record = mapper.toResource(entry) | ||
.toBuilder() | ||
.userName("root") | ||
.build(); | ||
var request = new Request<>(record, authContext.getPrincipal()); | ||
|
||
return service.add(request) | ||
.map(this::createResponseBuilder) | ||
.map(Response.ResponseBuilder::build); | ||
} | ||
|
||
@Operation(summary = "Update JSON record") | ||
@PUT | ||
@Path(ResourcePath.NONE) | ||
@RolesAllowed("ADMIN") | ||
@SecurityRequirement(name = "day-book") | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public Uni<Response> put(UpdateJsonRecord entry) { | ||
|
||
var record = mapper.toResource(entry) | ||
.toBuilder() | ||
.userName("root") | ||
.build(); | ||
var request = new Request<>(record, authContext.getPrincipal()); | ||
|
||
return service.put(request) | ||
.map(this::createResponseBuilder) | ||
.map(Response.ResponseBuilder::build); | ||
} | ||
|
||
@Operation(summary = "Delete JSON record") | ||
@DELETE | ||
@Path(ResourcePath.ID) | ||
@RolesAllowed("ADMIN") | ||
@SecurityRequirement(name = "day-book") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public Uni<Response> delete(UUID id) { | ||
|
||
var request = new Request<>(id, authContext.getPrincipal()); | ||
|
||
return service.delete(request) | ||
.map(this::createResponseBuilder) | ||
.map(Response.ResponseBuilder::build); | ||
} | ||
|
||
@ServerExceptionMapper | ||
public RestResponse<String> exception(Throwable x) { | ||
return exceptionMapper(x); | ||
} | ||
} |
Oops, something went wrong.