Skip to content

Commit

Permalink
feat: list contact type codes (#330)
Browse files Browse the repository at this point in the history
* feat: list contact type codes

* fix test

* Updated code to use ClientNameCodeDto

* fix: fixing action param name

* ci: adding test on main branch

this is to update the coverage info for main branch on each sonar project and use it as a base for branch comparison.

* chore: renaming endpoint and swagger data

* feat(fe:autocomplete): adding useFetch function (#331)

* feat(fe:autocomplete): adding useFetch function

* feat(fe:autocomplete): adding autocomplete component

* feat(fe:autocomplete): adding component and fetch

- added component FormAutoComplete
- hardcoded fetch for required field (for now)
- added fetch example on FormSections

* fix: changing country endpoint name

* chore: adding content type response

* chore: changing response format to match format

changed dto to use a simpler one.

* fix: fixing small client configuration issue

* chore: fixing swagger

* chore: updating response to be uniform

changing response to activeClientType endpoint to be the same dto used in other endpoints

* chore: updating schema info

---------

Co-authored-by: Paulo Gomes da Cruz Junior <[email protected]>
  • Loading branch information
brunoMarchiEncora and Paulo Gomes da Cruz Junior authored Feb 14, 2023
1 parent 831d507 commit 9d8fd2f
Show file tree
Hide file tree
Showing 11 changed files with 340 additions and 30 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/merge-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,64 @@ concurrency:
cancel-in-progress: true

jobs:
tests-backend:
name: Backend Unit Tests
runs-on: ubuntu-22.04
steps:
- uses: bcgov-nr/[email protected]
with:
commands: |
mvn -B verify -P all-tests checkstyle:checkstyle -Dcheckstyle.skip=false --file pom.xml
dir: backend
java-cache: maven
java-distribution: temurin
java-version: "17"
sonar_args: >
-Dsonar.organization=bcgov-sonarcloud
-Dsonar.projectKey=forest-client-backend
sonar_project_token: ${{ secrets.SONAR_TOKEN_BACKEND }}

tests-legacy:
name: Legacy Unit Tests
runs-on: ubuntu-22.04
steps:
- uses: bcgov-nr/[email protected]
with:
commands: |
mvn -B verify -P all-tests checkstyle:checkstyle -Dcheckstyle.skip=false --file pom.xml
dir: legacy
java-cache: maven
java-distribution: temurin
java-version: "17"
sonar_args: >
-Dsonar.organization=bcgov-sonarcloud
-Dsonar.projectKey=forest-client-legacy
sonar_project_token: ${{ secrets.SONAR_TOKEN_LEGACY }}

tests-frontend:
name: Frontend Unit Tests
runs-on: ubuntu-22.04
steps:
- uses: bcgov-nr/[email protected]
with:
commands: |
npm ci
npm run test
dir: frontend
sonar_args: >
-Dsonar.exclusions=**/coverage/**,**/examples/**,**/pages/**
-Dsonar.organization=bcgov-sonarcloud
-Dsonar.projectKey=forest-client-frontend
-Dsonar.tests=src/tests
sonar_project_token: ${{ secrets.SONAR_TOKEN_FRONTEND }}

codeql:
name: Semantic Code Analysis
runs-on: ubuntu-22.04
needs:
- tests-backend
- tests-legacy
- tests-frontend
permissions:
actions: read
contents: read
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-open.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
# Current changelog
${{ steps.changelog.outputs.clean_changelog }}
comment_includes: "# Current changelog"
comment_tag: "# Current changelog"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

pr-greeting:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
package ca.bc.gov.app.dto.client;

public record ClientNameCodeDto(String code, String name) {
import io.swagger.v3.oas.annotations.media.Schema;

@Schema(
description = "A simple name and code object",
title = "NameCode",
example = """
{
"code": "00000002",
"name": "BAXTER"
}"""
)
public record ClientNameCodeDto(

@Schema(description = "The code for that specific object", example = "00000002")
String code,

@Schema(description = "The name information for that specific object", example = "BAXTER")
String name
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package ca.bc.gov.app.entity.client;

import ca.bc.gov.app.ApplicationConstant;
import jakarta.validation.constraints.NotNull;
import java.time.LocalDate;
import java.time.LocalDateTime;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.With;
import org.springframework.data.annotation.Id;
import org.springframework.data.relational.core.mapping.Column;
import org.springframework.data.relational.core.mapping.Table;

@Table(name = "contact_type_code", schema = ApplicationConstant.POSTGRES_ATTRIBUTE_SCHEMA)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@With
public class ContactTypeCodeEntity {
@Id
@Column("contact_type_code")
private String contactTypeCode;

@NotNull
@Column("description")
private String description;

@NotNull
@Column("effective_date")
private LocalDate effectiveAt;

@NotNull
@Column("expiry_date")
private LocalDate expiredAt;

@Column("create_timestamp")
private LocalDateTime createdAt;

@Column("update_timestamp")
private LocalDateTime updatedAt;

@Column("create_user")
private String createdBy;

@Column("update_user")
private String updatedBy;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static org.springdoc.core.fn.builders.apiresponse.Builder.responseBuilder;
import static org.springdoc.core.fn.builders.content.Builder.contentBuilder;
import static org.springdoc.core.fn.builders.exampleobject.Builder.exampleOjectBuilder;
import static org.springdoc.core.fn.builders.header.Builder.headerBuilder;
import static org.springdoc.core.fn.builders.requestbody.Builder.requestBodyBuilder;
import static org.springdoc.core.fn.builders.schema.Builder.schemaBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static org.springdoc.core.fn.builders.schema.Builder.schemaBuilder;

import ca.bc.gov.app.dto.client.ClientCodeTypeDto;
import ca.bc.gov.app.dto.client.ClientNameCodeDto;
import ca.bc.gov.app.handlers.BaseHandler;
import ca.bc.gov.app.service.client.ClientService;
import ca.bc.gov.app.util.HandlerUtil;
Expand Down Expand Up @@ -38,7 +39,7 @@ public Mono<ServerResponse> handle(ServerRequest serverRequest) {
.body(
clientService
.findActiveClientTypeCodes(LocalDate.now()),
ClientCodeTypeDto.class
ClientNameCodeDto.class
)
.doOnError(ResponseStatusException.class, HandlerUtil.handleStatusResponse())
.doOnError(HandlerUtil.handleError());
Expand All @@ -63,8 +64,8 @@ public Consumer<Builder> documentation(String tag) {
arraySchemaBuilder()
.schema(
schemaBuilder()
.name("ClientCodeType")
.implementation(ClientCodeTypeDto.class)
.name("NameCode")
.implementation(ClientNameCodeDto.class)
)
)
.mediaType(MediaType.APPLICATION_JSON_VALUE)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package ca.bc.gov.app.handlers.client;

import static org.springdoc.core.fn.builders.apiresponse.Builder.responseBuilder;
import static org.springdoc.core.fn.builders.arrayschema.Builder.arraySchemaBuilder;
import static org.springdoc.core.fn.builders.content.Builder.contentBuilder;
import static org.springdoc.core.fn.builders.parameter.Builder.parameterBuilder;
import static org.springdoc.core.fn.builders.requestbody.Builder.requestBodyBuilder;
import static org.springdoc.core.fn.builders.schema.Builder.schemaBuilder;

import ca.bc.gov.app.dto.client.ClientNameCodeDto;
import ca.bc.gov.app.handlers.BaseHandler;
import ca.bc.gov.app.service.client.ClientService;
import ca.bc.gov.app.util.HandlerUtil;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import java.util.function.Consumer;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.core.fn.builders.operation.Builder;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.reactive.function.server.ServerResponse;
import org.springframework.web.server.ResponseStatusException;
import reactor.core.publisher.Mono;

@Component
@Slf4j
@RequiredArgsConstructor
public class ContactTypeCodeHandler implements BaseHandler {

private final ClientService clientService;


@Override
public Mono<ServerResponse> handle(ServerRequest serverRequest) {
return
ServerResponse
.ok()
.body(
clientService
.listClientContactTypeCodes(
serverRequest
.queryParam("page")
.map(Integer::parseInt)
.orElse(0),
serverRequest
.queryParam("size")
.map(Integer::parseInt)
.orElse(5)
),
ContactTypeCodeHandler.class
)
.doOnError(ResponseStatusException.class, HandlerUtil.handleStatusResponse())
.doOnError(HandlerUtil.handleError());
}

@Override
public Consumer<Builder> documentation(String tag) {
return ops -> ops
.tag(tag)
.description("List contact type codes")
.beanClass(ContactTypeCodeHandler.class)
.beanMethod("handle")
.operationId("handle")
.requestBody(requestBodyBuilder())
.parameter(
parameterBuilder()
.in(ParameterIn.QUERY)
.name("page")
.description("""
0 index page number, for example:
0 for the first page, 4 for the fifth page.
Defaults to 0 (first page)""")
.allowEmptyValue(true)
.schema(schemaBuilder().implementation(String.class))
.example("4")
)
.parameter(
parameterBuilder()
.in(ParameterIn.QUERY)
.name("size")
.description("Amount of entries per page,default to 5")
.allowEmptyValue(true)
.schema(schemaBuilder().implementation(String.class))
.example("5")
)
.response(
responseBuilder()
.responseCode("200")
.description("OK - List a page of contact type codes")
.content(
contentBuilder()
.array(
arraySchemaBuilder()
.schema(
schemaBuilder()
.name("NameCode")
.implementation(ClientNameCodeDto.class)
)
)
.mediaType(MediaType.APPLICATION_JSON_VALUE)
)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ca.bc.gov.app.repository.client;

import ca.bc.gov.app.entity.client.ContactTypeCodeEntity;
import org.springframework.data.domain.Pageable;
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
import org.springframework.data.repository.reactive.ReactiveSortingRepository;
import org.springframework.stereotype.Repository;
import reactor.core.publisher.Flux;

@Repository
public interface ContactTypeCodeRepository
extends ReactiveCrudRepository<ContactTypeCodeEntity, String>,
ReactiveSortingRepository<ContactTypeCodeEntity, String> {

Flux<ContactTypeCodeEntity> findBy(Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import static org.springdoc.webflux.core.fn.SpringdocRouteBuilder.route;
import static org.springframework.web.reactive.function.server.RequestPredicates.accept;

import ca.bc.gov.app.handlers.client.ClientProvinceCodeHandler;
import ca.bc.gov.app.handlers.client.ClientCountryCodeHandler;
import ca.bc.gov.app.handlers.client.ClientProvinceCodeHandler;
import ca.bc.gov.app.handlers.client.ClientTypeCodeHandler;
import ca.bc.gov.app.handlers.client.ContactTypeCodeHandler;
import ca.bc.gov.app.routes.BaseRouter;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
Expand All @@ -21,6 +22,8 @@ public class ClientRouter implements BaseRouter {
private final ClientTypeCodeHandler clientHandler;
private final ClientCountryCodeHandler countryCodeHandler;

private final ContactTypeCodeHandler contactTypeCodeHandler;

@Override
public String basePath() {
return "/clients";
Expand Down Expand Up @@ -57,7 +60,12 @@ public RouterFunction<ServerResponse> routerRoute() {
provinceCodeHandler::handle,
provinceCodeHandler.documentation(routeTagName())
)
.GET(
"/activeContactTypeCodes",
accept(MediaType.ALL),
contactTypeCodeHandler::handle,
contactTypeCodeHandler.documentation(routeTagName())
)
.build();
}

}
Loading

0 comments on commit 9d8fd2f

Please sign in to comment.