-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into CHK-3301-add-postman-collection
- Loading branch information
Showing
20 changed files
with
617 additions
and
95 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
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
27 changes: 27 additions & 0 deletions
27
src/main/kotlin/it/pagopa/ecommerce/users/config/mongo/MongoConfig.kt
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,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(), | ||
) | ||
) | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...main/kotlin/it/pagopa/ecommerce/users/config/mongo/converters/OffsetDateTimeConverters.kt
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,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() | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/kotlin/it/pagopa/ecommerce/users/config/mongo/converters/UUIDConverters.kt
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,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() | ||
} |
34 changes: 22 additions & 12 deletions
34
src/main/kotlin/it/pagopa/ecommerce/users/controllers/v1/LastUsageController.kt
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 |
---|---|---|
@@ -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() } | ||
} | ||
} |
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
Oops, something went wrong.