Skip to content

Commit

Permalink
chore: P4PU-188 added exception handler class (#6)
Browse files Browse the repository at this point in the history
* P4PU-188 added ArcExceptionHandler, custom exception and tests

* P4PU-188 removed ArcErrorDTO and custom exception, added openapi generator dependency and swagger

* P4PU-188 updated openapi generator config

* P4PU-188 cancelled modifies in application.yml

* P4PU-188 updated exception handler and swagger

* P4PU-188 updated swagger

* P4PU-188 updated swagger
  • Loading branch information
Giuseppe-LaManna authored Jun 4, 2024
1 parent c339e34 commit 2057543
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 4 deletions.
6 changes: 3 additions & 3 deletions .devops/code-review-pipelines.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pr:
- develop
- uat
- main
branches:
include:
- '*'

pool:
vmImage: ubuntu-22.04
Expand Down
29 changes: 29 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
jacoco
id("org.sonarqube") version "5.0.0.4638"
id("com.github.ben-manes.versions") version "0.51.0"
id ("org.openapi.generator") version "7.5.0"
}

group = "it.gov.pagopa"
Expand All @@ -26,6 +27,7 @@ repositories {

val springdocOpenApiVersion = "2.5.0"
val janinoVersion = "3.1.12"
val openApiToolsVersion = "0.2.6"

dependencies {
implementation("org.springframework.boot:spring-boot-starter")
Expand All @@ -34,6 +36,7 @@ dependencies {
implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:$springdocOpenApiVersion")
implementation("org.codehaus.janino:janino:$janinoVersion")
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310")
implementation("org.openapitools:jackson-databind-nullable:$openApiToolsVersion")
compileOnly("org.projectlombok:lombok")
annotationProcessor("org.projectlombok:lombok")

Expand Down Expand Up @@ -69,3 +72,29 @@ tasks {
}
}
}
configure<SourceSetContainer> {
named("main") {
java.srcDir("$projectDir/build/generated/src/main/java")
}
}

openApiGenerate {
generatorName.set("spring")
inputSpec.set("$rootDir/openapi/pagopa-arc-be.openapi.yaml")
outputDir.set("$projectDir/build/generated")
apiPackage.set("it.gov.pagopa.arc.controller.generated")
modelPackage.set("it.gov.pagopa.arc.model.generated")
configOptions.set(mapOf(
"dateLibrary" to "java8",
"requestMappingMode" to "api_interface",
"useSpringBoot3" to "true",
"interfaceOnly" to "true",
"useTags" to "true",
"generateConstructorWithAllArgs" to "false",
"generatedConstructorWithRequiredArgs" to "false",
"additionalModelTypeAnnotations" to "@lombok.Data @lombok.Builder @lombok.AllArgsConstructor @lombok.RequiredArgsConstructor"
))
typeMappings.set(mapOf(
"DateTime" to "java.time.ZonedDateTime"
))
}
107 changes: 107 additions & 0 deletions openapi/pagopa-arc-be.openapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
openapi: 3.0.1
info:
title: pagopa-arc-be
description: Api and Models
version: 0.0.1
servers:
- url: "http://localhost:8080/arc"
description: Generated server url
paths:
/transactions:
get:
tags:
- arc transactions
summary: "Retrieve the paged transaction list from arc"
operationId: getTransactionList
parameters:
- name: page
in: query
description: "Number of page required"
required: false
schema:
type: integer
format: int32
- name: size
in: query
description: "Number of items for page"
required: false
schema:
type: integer
format: int32
default: 10
- name: filter
in: query
description: "The field passed to filter the list of transactions"
required: false
schema:
type: string
example: payedByMe
responses:
'200':
description: "Obtained transaction list"
content:
application/json:
schema:
$ref: '#/components/schemas/TransactionsListDTO'
'401':
description: "Wrong or missing function key"
'429':
description: "Too many Requests"
'500':
description: "Service unavailable"
components:
schemas:
TransactionsListDTO:
type: object
properties:
transactions:
type: array
items:
$ref: '#/components/schemas/TransactionDTO'
currentPage:
type: integer
format: int32
itemsForPage:
type: integer
format: int32
totalItems:
type: integer
format: int32
totalPages:
type: integer
format: int32
TransactionDTO:
type: object
properties:
transactionId:
type: string
payeeName:
type: string
payeeTaxCode:
type: string
amount:
type: integer
format: int64
transactionDate:
type: string
format: date-time
example: "2024-05-31T13:07:25Z"
isCart:
type: boolean
payedByMe:
type: boolean
registeredToMe:
type: boolean
ErrorDTO:
type: object
required:
- error
properties:
error:
type: string
enum:
- generic_error
- invalid_request
error_description:
type: string
x-field-extra-annotation: "@com.fasterxml.jackson.annotation.JsonProperty(\"error_description\")"
13 changes: 13 additions & 0 deletions src/main/java/it/gov/pagopa/arc/exception/ExceptionHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package it.gov.pagopa.arc.exception;

import lombok.extern.slf4j.Slf4j;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
@Order(Ordered.HIGHEST_PRECEDENCE)
public class ExceptionHandler {

}
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ management:
web:
exposure.include: info, health

apiKey.bizEvents: ${BIZ_EVENTS_SERVICE_API_KEY:}
apiKey.biz-events: \${BIZ_EVENTS_SERVICE_API_KEY:}

0 comments on commit 2057543

Please sign in to comment.