Skip to content

Commit

Permalink
feat: refactoring rest-api (#53)
Browse files Browse the repository at this point in the history
* feat: refactoring rest-api

* tests: sonar issues
  • Loading branch information
andrejpetras authored Jul 23, 2024
1 parent 7d1d3b2 commit 577fc8e
Show file tree
Hide file tree
Showing 19 changed files with 329 additions and 227 deletions.
2 changes: 2 additions & 0 deletions docs/modules/onecx-help-svc/pages/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ include::onecx-help-svc-attributes.adoc[opts=optional]

include::docs.adoc[opts=optional]

=== Configuration
include::onecx-help-svc.adoc[opts=optional]

include::onecx-help-svc-docs.adoc[opts=optional]
44 changes: 22 additions & 22 deletions docs/modules/onecx-help-svc/pages/onecx-help-svc-extensions.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ h| Version

| https://onecx.github.io/docs/onecx-quarkus/current/onecx-quarkus/onecx-core.html[Link]
|
| 0.22.0
| 0.24.0

| onecx-tenant

| https://onecx.github.io/docs/onecx-quarkus/current/onecx-quarkus/onecx-tenant.html[Link]
| https://github.com/onecx/onecx-quarkus/blob/0.22.0/docs/modules/onecx-quarkus/pages/includes/onecx-tenant.adoc[Link]
| 0.22.0
| https://github.com/onecx/onecx-quarkus/blob/0.24.0/docs/modules/onecx-quarkus/pages/includes/onecx-tenant.adoc[Link]
| 0.24.0

| quarkus-oidc

Expand All @@ -29,50 +29,50 @@ h| Version
| tkit-quarkus-rest-context
| https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-rest-context.html[Link]
| https://github.com/1000kit/tkit-quarkus/blob/2.27.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-rest-context.adoc[Link]
| 2.27.0
| https://github.com/1000kit/tkit-quarkus/blob/2.28.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-rest-context.adoc[Link]
| 2.28.0
| tkit-quarkus-jpa-tenant
| https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-jpa-tenant.html[Link]
| https://github.com/1000kit/tkit-quarkus/blob/2.27.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-jpa-tenant.adoc[Link]
| 2.27.0
| https://github.com/1000kit/tkit-quarkus/blob/2.28.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-jpa-tenant.adoc[Link]
| 2.28.0
| tkit-quarkus-data-import
| https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-data-import.html[Link]
| https://github.com/1000kit/tkit-quarkus/blob/2.27.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-data-import.adoc[Link]
| 2.27.0
| https://github.com/1000kit/tkit-quarkus/blob/2.28.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-data-import.adoc[Link]
| 2.28.0
| tkit-quarkus-jpa
| https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-jpa.html[Link]
| https://github.com/1000kit/tkit-quarkus/blob/2.27.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-jpa.adoc[Link]
| 2.27.0
| https://github.com/1000kit/tkit-quarkus/blob/2.28.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-jpa.adoc[Link]
| 2.28.0
| tkit-quarkus-log-cdi
| https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-log-cdi.html[Link]
| https://github.com/1000kit/tkit-quarkus/blob/2.27.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-cdi.adoc[Link]
| 2.27.0
| https://github.com/1000kit/tkit-quarkus/blob/2.28.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-cdi.adoc[Link]
| 2.28.0
| tkit-quarkus-log-rs
| https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-log-rs.html[Link]
| https://github.com/1000kit/tkit-quarkus/blob/2.27.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-rs.adoc[Link]
| 2.27.0
| https://github.com/1000kit/tkit-quarkus/blob/2.28.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-rs.adoc[Link]
| 2.28.0
| tkit-quarkus-log-json
| https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-log-json.html[Link]
| https://github.com/1000kit/tkit-quarkus/blob/2.27.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-json.adoc[Link]
| 2.27.0
| https://github.com/1000kit/tkit-quarkus/blob/2.28.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-log-json.adoc[Link]
| 2.28.0
| tkit-quarkus-rest
| https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-rest.html[Link]
| https://github.com/1000kit/tkit-quarkus/blob/2.27.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-rest.adoc[Link]
| 2.27.0
| https://github.com/1000kit/tkit-quarkus/blob/2.28.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-rest.adoc[Link]
| 2.28.0
| quarkus-arc
Expand Down Expand Up @@ -143,8 +143,8 @@ h| Version
| tkit-quarkus-security
| https://1000kit.github.io/tkit-quarkus/current/tkit-quarkus/tkit-quarkus-security.html[Link]
| https://github.com/1000kit/tkit-quarkus/blob/2.27.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-security.adoc[Link]
| 2.27.0
| https://github.com/1000kit/tkit-quarkus/blob/2.28.0/docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-security.adoc[Link]
| 2.28.0
| quarkus-container-image-docker
Expand All @@ -157,7 +157,7 @@ h| Version
|
|
| 0.22.0
| 0.24.0
| quarkus-smallrye-context-propagation
Expand Down
63 changes: 63 additions & 0 deletions docs/modules/onecx-help-svc/pages/onecx-help-svc.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@

:summaryTableId: onecx-help-svc
[.configuration-legend]
icon:lock[title=Fixed at build time] Configuration property fixed at build time - All other configuration properties are overridable at runtime
[.configuration-reference.searchable, cols="80,.^10,.^10"]
|===

h|[[onecx-help-svc_configuration]]link:#onecx-help-svc_configuration[Configuration property]

h|Type
h|Default

a| [[onecx-help-svc_onecx-help-default-enabled]]`link:#onecx-help-svc_onecx-help-default-enabled[onecx.help.default.enabled]`


[.description]
--
Enable or disable default help

ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++ONECX_HELP_DEFAULT_ENABLED+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++ONECX_HELP_DEFAULT_ENABLED+++`
endif::add-copy-button-to-env-var[]
--|boolean
|`false`


a| [[onecx-help-svc_onecx-help-default-url]]`link:#onecx-help-svc_onecx-help-default-url[onecx.help.default.url]`


[.description]
--
Default help URL

ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++ONECX_HELP_DEFAULT_URL+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++ONECX_HELP_DEFAULT_URL+++`
endif::add-copy-button-to-env-var[]
--|string
|`https://github.com/onecx`


a| [[onecx-help-svc_onecx-help-product-item-id]]`link:#onecx-help-svc_onecx-help-product-item-id[onecx.help.product-item-id]`


[.description]
--
Default help URL

ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++ONECX_HELP_PRODUCT_ITEM_ID+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++ONECX_HELP_PRODUCT_ITEM_ID+++`
endif::add-copy-button-to-env-var[]
--|string
|`PRODUCT_BASE_DOC_URL`

|===
12 changes: 0 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -220,18 +220,6 @@
<modelNameSuffix>DTO</modelNameSuffix>
</configuration>
</execution>
<execution>
<id>v1</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>src/main/openapi/onecx-help-v1-openapi.yaml</inputSpec>
<apiPackage>gen.org.tkit.onecx.help.rs.v1</apiPackage>
<modelPackage>gen.org.tkit.onecx.help.rs.v1.model</modelPackage>
<modelNameSuffix>DTOV1</modelNameSuffix>
</configuration>
</execution>
<execution>
<id>di-help-v1</id>
<goals>
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/org/tkit/onecx/help/domain/config/HelpConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.tkit.onecx.help.domain.config;

import io.quarkus.runtime.annotations.ConfigDocFilename;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithDefault;
import io.smallrye.config.WithName;

@ConfigDocFilename("onecx-help-svc.adoc")
@ConfigRoot(phase = ConfigPhase.RUN_TIME)
@ConfigMapping(prefix = "onecx.help")
public interface HelpConfig {

/**
* Enable or disable default help
*/
@WithName("default.enabled")
@WithDefault("false")
boolean defaultHelpEnabled();

/**
* Default help URL
*/
@WithName("default.url")
@WithDefault("https://github.com/onecx")
String defaultHelpUrl();

/**
* Default help URL
*/
@WithName("product-item-id")
@WithDefault("PRODUCT_BASE_DOC_URL")
String productItemId();
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import org.jboss.resteasy.reactive.RestResponse;
import org.jboss.resteasy.reactive.server.ServerExceptionMapper;
import org.tkit.onecx.help.domain.config.HelpConfig;
import org.tkit.onecx.help.domain.daos.HelpDAO;
import org.tkit.onecx.help.rs.internal.mappers.ExceptionMapper;
import org.tkit.onecx.help.rs.internal.mappers.HelpMapper;
Expand Down Expand Up @@ -41,6 +42,9 @@ public class HelpsRestController implements HelpsInternalApi {
@Context
UriInfo uriInfo;

@Inject
HelpConfig config;

@Override
@Transactional
public Response createNewHelp(CreateHelpDTO createHelpDTO) {
Expand Down Expand Up @@ -96,6 +100,25 @@ public Response updateHelp(String id, UpdateHelpDTO updateHelpDTO) {
return Response.noContent().build();
}

@Override
public Response getHelpByProductNameItemId(String productName, String helpItemId) {
var help = dao.findByProductNameAndItemId(productName, helpItemId);
if (help != null) {
return Response.ok(mapper.map(help)).build();
}

help = dao.findByProductNameAndItemId(productName, config.productItemId());
if (help != null) {
return Response.ok(mapper.map(help)).build();
}

if (config.defaultHelpEnabled()) {
return Response.ok(mapper.createDefault(productName, helpItemId, config.defaultHelpUrl())).build();
}

return Response.status(Response.Status.NOT_FOUND).build();
}

@ServerExceptionMapper
public RestResponse<ProblemDetailResponseDTO> exception(ConstraintException ex) {
return exceptionMapper.exception(ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ public interface HelpMapper {

HelpDTO map(Help help);

@Mapping(target = "id", ignore = true)
@Mapping(target = "creationDate", ignore = true)
@Mapping(target = "creationUser", ignore = true)
@Mapping(target = "modificationDate", ignore = true)
@Mapping(target = "modificationUser", ignore = true)
@Mapping(target = "modificationCount", ignore = true)
@Mapping(target = "context", ignore = true)
@Mapping(target = "resourceUrl", ignore = true)
HelpDTO createDefault(String productName, String itemId, String baseUrl);

@Mapping(target = "id", ignore = true)
@Mapping(target = "creationDate", ignore = true)
@Mapping(target = "creationUser", ignore = true)
Expand Down

This file was deleted.

This file was deleted.

30 changes: 30 additions & 0 deletions src/main/openapi/onecx-help-internal-openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,36 @@ servers:
tags:
- name: helpsInternal
paths:
/internal/helps/{productName}/{helpItemId}:
get:
security:
- oauth2: [ ocx-hp:all, ocx-hp:read ]
tags:
- helpsInternal
description: search help item by product name and item id
operationId: getHelpByProductNameItemId
parameters:
- name: productName
in: path
required: true
description: product name
schema:
type: string
- name: helpItemId
in: path
required: true
description: help item ID
schema:
type: string
responses:
200:
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/Help'
404:
description: Help not found
/internal/helps:
post:
security:
Expand Down
Loading

0 comments on commit 577fc8e

Please sign in to comment.