Skip to content

Commit

Permalink
Merge branch 'main' into CHK-3301-add-postman-collection
Browse files Browse the repository at this point in the history
  • Loading branch information
pietro-tota authored Oct 7, 2024
2 parents 1e14f28 + 45ff345 commit 2ec4c3f
Show file tree
Hide file tree
Showing 20 changed files with 617 additions and 95 deletions.
4 changes: 3 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

group = "it.pagopa.ecommerce.users"

version = "0.0.4"
version = "0.1.0"

description = "pagopa-ecommerce-user-stats-service"

Expand Down Expand Up @@ -33,6 +33,7 @@ object Dependencies {
const val jacksonDatabindNullableVersion = "0.2.6"

const val ioSwaggerAnnotationVersion = "2.2.23"
const val mockitoKotlinVersion = "5.4.0"
}

dependencyManagement {
Expand Down Expand Up @@ -83,6 +84,7 @@ dependencies {
// Kotlin dependencies
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
testImplementation("org.mockito.kotlin:mockito-kotlin:${Dependencies.mockitoKotlinVersion}")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
}

Expand Down
10 changes: 4 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ services:
ports:
- "8080:8080"
depends_on:
- mongo
- pagopa-ecommerce-user-stats-service-mongo
networks:
- pagopa-ecommerce-user-stats-net

mongo-express:
pagopa-ecommerce-user-stats-service-mongo-express:
container_name: pagopa-ecommerce-user-stats-service-mongo-express
image: mongo-express@sha256:1b23d7976f0210dbec74045c209e52fbb26d29b2e873d6c6fa3d3f0ae32c2a64
env_file: ./docker/config/mongo/mongo-express.env
Expand All @@ -24,9 +24,9 @@ services:
networks:
- pagopa-ecommerce-user-stats-net
depends_on:
- mongo
- pagopa-ecommerce-user-stats-service-mongo

mongo:
pagopa-ecommerce-user-stats-service-mongo:
container_name: pagopa-ecommerce-user-stats-service-mongo
image: mongo@sha256:7b225d4ae2df7cf98812f27f5d0d98054efaf9bfd4cc79c7e3e0bed1c1d3bf45
env_file: ./docker/config/mongo/mongodb.env
Expand All @@ -40,8 +40,6 @@ services:
volumes:
- ./docker/config/mongo/mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro



networks:
pagopa-ecommerce-user-stats-net:
driver: bridge
Expand Down
1 change: 1 addition & 0 deletions gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ org.junit.platform:junit-platform-commons:1.10.3=testCompileClasspath,testImplem
org.junit.platform:junit-platform-engine:1.10.3=testRuntimeClasspath
org.junit:junit-bom:5.10.3=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.latencyutils:LatencyUtils:2.0.3=productionRuntimeClasspath,runtimeClasspath,testRuntimeClasspath
org.mockito.kotlin:mockito-kotlin:5.4.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.mockito:mockito-core:5.11.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.mockito:mockito-junit-jupiter:5.11.0=testCompileClasspath,testImplementationDependenciesMetadata,testRuntimeClasspath
org.mongodb:bson-record-codec:5.0.1=productionRuntimeClasspath,runtimeClasspath,testRuntimeClasspath
Expand Down
61 changes: 61 additions & 0 deletions gradle/verification-metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2579,6 +2579,14 @@
<sha256 value="4d27a66f31c78fe5543495b332485de5feab0a25802adc8641300f2026d6ac02" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.apiguardian" name="apiguardian-api" version="1.1.0">
<artifact name="apiguardian-api-1.1.0.jar">
<sha1 value="fc9dff4bb36d627bdc553de77e1f17efd790876c" origin="Taken from maven"/>
</artifact>
<artifact name="apiguardian-api-1.1.0.pom">
<sha1 value="41f951c2aff248588037007e8f915467b9971a6f" origin="Taken from maven"/>
</artifact>
</component>
<component group="org.apiguardian" name="apiguardian-api" version="1.1.2">
<artifact name="apiguardian-api-1.1.2.jar">
<sha256 value="b509448ac506d607319f182537f0b35d71007582ec741832a1f111e5b5b70b38" origin="Generated by Gradle"/>
Expand Down Expand Up @@ -3638,6 +3646,11 @@
<sha256 value="10937d44c425984cb8739225d34712e1a3145641ca93ac3f7ef186fa25f6babc" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.junit" name="junit-bom" version="5.6.3">
<artifact name="junit-bom-5.6.3.module">
<sha1 value="eb2f653fbc0e59f868d504eddfe6239d13eeb507" origin="Taken from maven"/>
</artifact>
</component>
<component group="org.junit" name="junit-bom" version="5.7.1">
<artifact name="junit-bom-5.7.1.module">
<sha256 value="9854e3894d64b2485207e0046bca07b3d42d169e782f4fa8c9ce229a78faee04" origin="Generated by Gradle"/>
Expand Down Expand Up @@ -3708,6 +3721,14 @@
<sha256 value="734a1c68c34c5adf3bd2f5bca4bf498cbb4f49c489d7c24d80cf0e2102be6f14" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.junit.jupiter" name="junit-jupiter-api" version="5.6.3">
<artifact name="junit-jupiter-api-5.6.3.jar">
<sha1 value="73ea5e2b7f112616315d3e2325a98e6e93c2813a" origin="Taken from maven"/>
</artifact>
<artifact name="junit-jupiter-api-5.6.3.module">
<sha1 value="aed0f8af5832cff330bd7cf13309b655c720ff86" origin="Taken from maven"/>
</artifact>
</component>
<component group="org.junit.jupiter" name="junit-jupiter-engine" version="5.10.3">
<artifact name="junit-jupiter-engine-5.10.3.jar">
<sha256 value="bbd3ce8dc11e9925071ef9691d68af1ab6e712faa6851f7c5275bc8aafc88673" origin="Generated by Gradle"/>
Expand All @@ -3719,6 +3740,14 @@
<sha256 value="83ef0fd68b60bf6bc79a78feb11882c625c482ef69d62bfe2d117040a6448144" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.junit.jupiter" name="junit-jupiter-engine" version="5.6.3">
<artifact name="junit-jupiter-engine-5.6.3.jar">
<sha1 value="234f250d1608684c4436d72214e7530f23cb8a03" origin="Taken from maven"/>
</artifact>
<artifact name="junit-jupiter-engine-5.6.3.module">
<sha1 value="427537bc608bfedb9385075bc3208440be0169c5" origin="Taken from maven"/>
</artifact>
</component>
<component group="org.junit.jupiter" name="junit-jupiter-params" version="5.10.3">
<artifact name="junit-jupiter-params-5.10.3.jar">
<sha256 value="7c3ed8cefb12496b76c53c3da986ea8f0bf3f426781869475551ae3a506c1ad8" origin="Generated by Gradle"/>
Expand All @@ -3741,6 +3770,14 @@
<sha256 value="7597572c59f1975262f8d8fcf88ec6783376854bf08ce8a93d99dbdc89ee43f9" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.junit.platform" name="junit-platform-commons" version="1.6.3">
<artifact name="junit-platform-commons-1.6.3.jar">
<sha1 value="7ce526bbb9e6202e8a30140a50bfff644fddd10e" origin="Taken from maven"/>
</artifact>
<artifact name="junit-platform-commons-1.6.3.module">
<sha1 value="1303c9a7198e44c37e7409c4609d212da9d71a77" origin="Taken from maven"/>
</artifact>
</component>
<component group="org.junit.platform" name="junit-platform-engine" version="1.10.3">
<artifact name="junit-platform-engine-1.10.3.jar">
<sha256 value="df7c32bf75cf47c4c8ddd1942091027947a7d765d30b731fe00830115fafa133" origin="Generated by Gradle"/>
Expand All @@ -3752,6 +3789,14 @@
<sha256 value="6f9b99bca0c17ddc19f51bc037e3b17cab0fc7e6f1da70387a30ab4e05207228" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.junit.platform" name="junit-platform-engine" version="1.6.3">
<artifact name="junit-platform-engine-1.6.3.jar">
<sha1 value="a926b9bbc7fe67c5795ee1f00cc1b618b313e5ce" origin="Taken from maven"/>
</artifact>
<artifact name="junit-platform-engine-1.6.3.module">
<sha1 value="80cfb28eebf275405e87108c491749f825cdd202" origin="Taken from maven"/>
</artifact>
</component>
<component group="org.jvnet.staxex" name="stax-ex" version="2.1.0">
<artifact name="stax-ex-2.1.0.jar">
<sha256 value="9f786ab52392106a53491bd1ddd8bd9028c95bb280e30387b70d498a8647cf35" origin="Generated by Gradle"/>
Expand Down Expand Up @@ -3807,6 +3852,14 @@
<sha256 value="6e69977a948bbe44d09f750f5e8b368b7545c32e4978982bb3496e8894042e5e" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.mockito.kotlin" name="mockito-kotlin" version="5.4.0">
<artifact name="mockito-kotlin-5.4.0.jar">
<sha256 value="c97a3c0ad362d9352a135323767fd3dad64796f26339399b129fe19d7e30356a" origin="Generated by Gradle"/>
</artifact>
<artifact name="mockito-kotlin-5.4.0.pom">
<sha256 value="9de847e498eaf9790e448d8e6732137f8a9a8f173c2143c6283ea663f47fd8bb" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.mongodb" name="bson" version="5.0.1">
<artifact name="bson-5.0.1.jar">
<sha256 value="76231b6b9572f6d32b125ca891ccfdf9ee6f0ebbc96d4ff1d6f0eab841063ad6" origin="Generated by Gradle"/>
Expand Down Expand Up @@ -3910,6 +3963,14 @@
<sha256 value="86845083aa61e989fe5fb36b6bcd49497977945dd8132e81a32003de6a2f7765" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="org.opentest4j" name="opentest4j" version="1.2.0">
<artifact name="opentest4j-1.2.0.jar">
<sha1 value="28c11eb91f9b6d8e200631d46e20a7f407f2a046" origin="Taken from maven"/>
</artifact>
<artifact name="opentest4j-1.2.0.pom">
<sha1 value="b5c66f49b69c36797c1fb7f4ec57776f261303ad" origin="Taken from maven"/>
</artifact>
</component>
<component group="org.opentest4j" name="opentest4j" version="1.3.0">
<artifact name="opentest4j-1.3.0.jar">
<sha256 value="48e2df636cab6563ced64dcdff8abb2355627cb236ef0bf37598682ddf742f1b" origin="Generated by Gradle"/>
Expand Down
4 changes: 2 additions & 2 deletions helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ apiVersion: v2
name: wallet
description: Microservice that handles user stats
type: application
version: 0.0.4
appVersion: 0.0.4
version: 0.1.0
appVersion: 0.1.0
dependencies:
- name: microservice-chart
version: 2.8.0
Expand Down
2 changes: 1 addition & 1 deletion helm/values-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ microservice-chart:
envConfig: {}
image:
repository: pagopadcommonacr.azurecr.io/pagopaecommerceuserstatsservice
tag: "0.0.4"
tag: "0.1.0"
pullPolicy: Always
livenessProbe:
handlerType: httpGet
Expand Down
2 changes: 1 addition & 1 deletion helm/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ microservice-chart:
envConfig: {}
image:
repository: pagopapcommonacr.azurecr.io/pagopaecommerceuserstatsservice
tag: "0.0.4"
tag: "0.1.0"
pullPolicy: Always
livenessProbe:
handlerType: httpGet
Expand Down
2 changes: 1 addition & 1 deletion helm/values-uat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ microservice-chart:
envConfig: {}
image:
repository: pagopaucommonacr.azurecr.io/pagopaecommerceuserstatsservice
tag: "0.0.4"
tag: "0.1.0"
pullPolicy: Always
livenessProbe:
handlerType: httpGet
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package it.pagopa.ecommerce.users.config.mongo

import it.pagopa.ecommerce.users.config.mongo.converters.OffsetDateTimeReadingConverter
import it.pagopa.ecommerce.users.config.mongo.converters.OffsetDateTimeWritingConverter
import it.pagopa.ecommerce.users.config.mongo.converters.UUIDReadingConverter
import it.pagopa.ecommerce.users.config.mongo.converters.UUIDWritingConverter
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.data.mongodb.core.convert.MongoCustomConversions

/** Mongo configuration */
@Configuration
class MongoConfig {

/** Register custom conversion implementation */
@Bean
fun mongoCustomConversions(): MongoCustomConversions {
return MongoCustomConversions(
listOf(
OffsetDateTimeReadingConverter(),
OffsetDateTimeWritingConverter(),
UUIDReadingConverter(),
UUIDWritingConverter(),
)
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package it.pagopa.ecommerce.users.config.mongo.converters

import java.time.OffsetDateTime
import org.springframework.core.convert.converter.Converter
import org.springframework.data.convert.ReadingConverter
import org.springframework.data.convert.WritingConverter

@ReadingConverter
class OffsetDateTimeReadingConverter : Converter<String, OffsetDateTime> {
override fun convert(source: String): OffsetDateTime = OffsetDateTime.parse(source)
}

@WritingConverter
class OffsetDateTimeWritingConverter : Converter<OffsetDateTime, String> {

override fun convert(source: OffsetDateTime): String = source.toString()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package it.pagopa.ecommerce.users.config.mongo.converters

import java.util.*
import org.springframework.core.convert.converter.Converter
import org.springframework.data.convert.ReadingConverter
import org.springframework.data.convert.WritingConverter

@ReadingConverter
class UUIDReadingConverter : Converter<String, UUID> {
override fun convert(source: String): UUID = UUID.fromString(source)
}

@WritingConverter
class UUIDWritingConverter : Converter<UUID, String> {
override fun convert(source: UUID): String = source.toString()
}
Original file line number Diff line number Diff line change
@@ -1,36 +1,46 @@
package it.pagopa.ecommerce.users.controllers.v1

import it.pagopa.ecommerce.users.services.UserStatisticsService
import it.pagopa.generated.ecommerce.users.api.UserApi
import it.pagopa.generated.ecommerce.users.model.UserLastPaymentMethodData
import it.pagopa.generated.ecommerce.users.model.WalletLastUsageData
import java.time.OffsetDateTime
import java.util.*
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.server.ServerWebExchange
import reactor.core.publisher.Mono

@RestController("LastUsageControllerV1")
class LastUsageController : UserApi {
class LastUsageController(@Autowired private val userStatisticsService: UserStatisticsService) :
UserApi {

override fun getLastPaymentMethodUsed(
xUserId: UUID,
exchange: ServerWebExchange
): Mono<ResponseEntity<UserLastPaymentMethodData>> =
Mono.just(
ResponseEntity.ok(
WalletLastUsageData()
.date(OffsetDateTime.now())
.walletId(UUID.randomUUID())
.type("wallet")
)
)
userStatisticsService.findUserLastMethodById(xUserId.toString()).map {
ResponseEntity.ok(it)
}

/*
* @formatter:off
*
* Warning kotlin:S6508 - "Unit" should be used instead of "Void"
* Suppressed because controller interface is generated from openapi descriptor as java code which use Void as return type.
* User stats interfaces are generated as java code because kotlin generation generate broken code
*
* @formatter:on
*/
@SuppressWarnings("kotlin:S6508")
override fun saveLastPaymentMethodUsed(
xUserId: UUID,
userLastPaymentMethodDataDto: Mono<UserLastPaymentMethodData>,
exchange: ServerWebExchange
): Mono<ResponseEntity<Void>> =
userLastPaymentMethodDataDto.flatMap {
Mono.error(NotImplementedError("SAVE NOT IMPLEMENTED YET!"))
userStatisticsService
.saveUserLastUsedMethodInfo(userId = xUserId, userLastPaymentMethodData = it)
.map { ResponseEntity.status(HttpStatus.CREATED).build() }
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package it.pagopa.ecommerce.users.documents

import java.time.Instant
import java.time.OffsetDateTime
import java.util.*

data class LastUsage(
Expand All @@ -9,7 +9,7 @@ data class LastUsage(
/** The id of the method used to pay */
val instrumentId: UUID,
/** The date of the last usage */
val date: Instant
val date: OffsetDateTime
) {

/** Payment type enumeration */
Expand Down
Loading

0 comments on commit 2ec4c3f

Please sign in to comment.