From 2906ce2ab369559ee576d65b2b7b3500a6386f95 Mon Sep 17 00:00:00 2001 From: Amir Rajabi Date: Sat, 2 Aug 2025 15:35:47 +0330 Subject: [PATCH 1/2] hot fix --- .../co/nilin/opex/profile/app/service/ProfileManagement.kt | 4 ++-- .../profile/core/data/profile/CompleteProfileRequest.kt | 2 +- .../profile/core/data/profile/CompleteProfileResponse.kt | 6 +++--- .../co/nilin/opex/profile/core/data/profile/Profile.kt | 2 +- .../co/nilin/opex/profile/ports/auth/impl/AuthProxyImpl.kt | 6 +++--- .../opex/profile/ports/postgres/imp/ProfileManagementImp.kt | 2 +- .../nilin/opex/profile/ports/postgres/model/base/Profile.kt | 3 ++- 7 files changed, 13 insertions(+), 12 deletions(-) diff --git a/profile/profile-app/src/main/kotlin/co/nilin/opex/profile/app/service/ProfileManagement.kt b/profile/profile-app/src/main/kotlin/co/nilin/opex/profile/app/service/ProfileManagement.kt index 2a6ae4383..ddd05ef44 100644 --- a/profile/profile-app/src/main/kotlin/co/nilin/opex/profile/app/service/ProfileManagement.kt +++ b/profile/profile-app/src/main/kotlin/co/nilin/opex/profile/app/service/ProfileManagement.kt @@ -156,7 +156,7 @@ class ProfileManagement( ) ) if (verifyResponse.result) { - authProxy.updateEmail(userId, email) //TODO rollback in error ? + authProxy.updateEmail(userId, email) profilePersister.updateEmail(userId, email) } else throw OpexError.InvalidOTP.exception() } @@ -173,7 +173,7 @@ class ProfileManagement( throw OpexError.ProfileAlreadyCompleted.exception() } - val isIranian = request.nationality == NationalityType.IRANIAN.name + val isIranian = request.nationality == NationalityType.IRANIAN var useMobileIdentity = false var usePersonalIdentity = false diff --git a/profile/profile-core/src/main/kotlin/co/nilin/opex/profile/core/data/profile/CompleteProfileRequest.kt b/profile/profile-core/src/main/kotlin/co/nilin/opex/profile/core/data/profile/CompleteProfileRequest.kt index c1c8ec304..111f615e6 100644 --- a/profile/profile-core/src/main/kotlin/co/nilin/opex/profile/core/data/profile/CompleteProfileRequest.kt +++ b/profile/profile-core/src/main/kotlin/co/nilin/opex/profile/core/data/profile/CompleteProfileRequest.kt @@ -8,7 +8,7 @@ data class CompleteProfileRequest( var address: String? = null, var telephone: String? = null, var postalCode: String? = null, - var nationality: String, + var nationality: NationalityType, var identifier: String, var gender: Gender, var birthDate: LocalDateTime, diff --git a/profile/profile-core/src/main/kotlin/co/nilin/opex/profile/core/data/profile/CompleteProfileResponse.kt b/profile/profile-core/src/main/kotlin/co/nilin/opex/profile/core/data/profile/CompleteProfileResponse.kt index fe86ecfd2..ea0f43089 100644 --- a/profile/profile-core/src/main/kotlin/co/nilin/opex/profile/core/data/profile/CompleteProfileResponse.kt +++ b/profile/profile-core/src/main/kotlin/co/nilin/opex/profile/core/data/profile/CompleteProfileResponse.kt @@ -13,12 +13,12 @@ open class CompleteProfileResponse( var mobile: String? = null, var telephone: String? = null, var postalCode: String? = null, - var nationality: String? = null, + var nationality: NationalityType? = null, var identifier: String? = null, var gender: Gender? = null, var birthDate: LocalDateTime? = null, var status: UserStatus? = null, var kycLevel: KycLevel? = null, - var mobileIdentityMatch : Boolean? = false, - var personalIdentityMatch : Boolean? = false + var mobileIdentityMatch: Boolean? = false, + var personalIdentityMatch: Boolean? = false ) diff --git a/profile/profile-core/src/main/kotlin/co/nilin/opex/profile/core/data/profile/Profile.kt b/profile/profile-core/src/main/kotlin/co/nilin/opex/profile/core/data/profile/Profile.kt index 2ed002b01..d37eae120 100644 --- a/profile/profile-core/src/main/kotlin/co/nilin/opex/profile/core/data/profile/Profile.kt +++ b/profile/profile-core/src/main/kotlin/co/nilin/opex/profile/core/data/profile/Profile.kt @@ -15,7 +15,7 @@ data class Profile( var mobile: String? = null, var telephone: String? = null, var postalCode: String? = null, - var nationality: String? = null, + var nationality: NationalityType? = null, var identifier: String? = null, var gender: Gender? = null, var birthDate: LocalDateTime? = null, diff --git a/profile/profile-ports/profile-auth-proxy/src/main/kotlin/co/nilin/opex/profile/ports/auth/impl/AuthProxyImpl.kt b/profile/profile-ports/profile-auth-proxy/src/main/kotlin/co/nilin/opex/profile/ports/auth/impl/AuthProxyImpl.kt index 6fc55c460..094bbef80 100644 --- a/profile/profile-ports/profile-auth-proxy/src/main/kotlin/co/nilin/opex/profile/ports/auth/impl/AuthProxyImpl.kt +++ b/profile/profile-ports/profile-auth-proxy/src/main/kotlin/co/nilin/opex/profile/ports/auth/impl/AuthProxyImpl.kt @@ -14,7 +14,7 @@ class AuthProxyImpl(private val webClient: WebClient) : AuthProxy { private lateinit var baseUrl: String override suspend fun updateEmail(userId: String, email: String) { - webClient.put().uri("$baseUrl/v1/user/email") + webClient.put().uri("$baseUrl/v1/user/update/email") .contentType(MediaType.APPLICATION_JSON) .bodyValue(mapOf("userId" to userId, "email" to email)) .retrieve() @@ -22,7 +22,7 @@ class AuthProxyImpl(private val webClient: WebClient) : AuthProxy { } override suspend fun updateMobile(userId: String, mobile: String) { - webClient.put().uri("$baseUrl/v1/user/mobile") + webClient.put().uri("$baseUrl/v1/user/update/mobile") .contentType(MediaType.APPLICATION_JSON) .bodyValue(mapOf("userId" to userId, "mobile" to mobile)) .retrieve() @@ -30,7 +30,7 @@ class AuthProxyImpl(private val webClient: WebClient) : AuthProxy { } override suspend fun updateName(userId: String, firstName: String, lastName: String) { - webClient.put().uri("$baseUrl/v1/user/name") + webClient.put().uri("$baseUrl/v1/user/update/name") .contentType(MediaType.APPLICATION_JSON) .bodyValue(mapOf("userId" to userId, "firstName" to firstName, "lastName" to lastName)) .retrieve() diff --git a/profile/profile-ports/profile-postgres/src/main/kotlin/co/nilin/opex/profile/ports/postgres/imp/ProfileManagementImp.kt b/profile/profile-ports/profile-postgres/src/main/kotlin/co/nilin/opex/profile/ports/postgres/imp/ProfileManagementImp.kt index d53205490..ddcca340b 100644 --- a/profile/profile-ports/profile-postgres/src/main/kotlin/co/nilin/opex/profile/ports/postgres/imp/ProfileManagementImp.kt +++ b/profile/profile-ports/profile-postgres/src/main/kotlin/co/nilin/opex/profile/ports/postgres/imp/ProfileManagementImp.kt @@ -100,7 +100,7 @@ class ProfileManagementImp( return profileRepository.save(newProfileModel) .map { saved -> val response = convertProfileModelToCompleteProfileResponse(saved) - if (saved.nationality == NationalityType.IRANIAN.name) { + if (saved.nationality == NationalityType.IRANIAN) { response.kycLevel = KycLevel.Level2 } response diff --git a/profile/profile-ports/profile-postgres/src/main/kotlin/co/nilin/opex/profile/ports/postgres/model/base/Profile.kt b/profile/profile-ports/profile-postgres/src/main/kotlin/co/nilin/opex/profile/ports/postgres/model/base/Profile.kt index 641e3aa92..9d898d8a4 100644 --- a/profile/profile-ports/profile-postgres/src/main/kotlin/co/nilin/opex/profile/ports/postgres/model/base/Profile.kt +++ b/profile/profile-ports/profile-postgres/src/main/kotlin/co/nilin/opex/profile/ports/postgres/model/base/Profile.kt @@ -2,6 +2,7 @@ package co.nilin.opex.profile.ports.postgres.model.base import co.nilin.opex.profile.core.data.profile.Gender import co.nilin.opex.profile.core.data.kyc.KycLevel +import co.nilin.opex.profile.core.data.profile.NationalityType import co.nilin.opex.profile.core.data.profile.UserStatus import java.time.LocalDateTime @@ -14,7 +15,7 @@ open class Profile { var mobile: String? = null var telephone: String? = null var postalCode: String? = null - var nationality: String? = null + var nationality: NationalityType? = null var identifier: String? = null var gender: Gender? = null lateinit var birthDate: LocalDateTime From bee8853aa513955720bf0d2dd62d1c0354b5415e Mon Sep 17 00:00:00 2001 From: Amir Rajabi Date: Sat, 2 Aug 2025 18:27:29 +0330 Subject: [PATCH 2/2] Refactor comparative inquiry and profile model updates --- .../kotlin/co/nilin/opex/common/OpexError.kt | 7 ++-- .../profile/app/service/ProfileManagement.kt | 17 +++++----- .../core/data/profile}/ComparativeResponse.kt | 2 +- .../data/profile/CompleteProfileRequest.kt | 4 +-- .../opex/profile/core/spi/InquiryProxy.kt | 5 +-- .../ports/inquiry/imp/InquiryProxyImp.kt | 10 +++--- .../ports/inquiry/utils/DateConvertor.kt | 16 ++++----- .../postgres/imp/ProfileManagementImp.kt | 18 ++++------ .../profile/ports/postgres/utils/Convertor.kt | 33 +++++++++++++++++++ .../ports/postgres/utils/Extensions.kt | 18 ++++++++++ .../src/main/resources/schema.sql | 15 +++++++-- 11 files changed, 100 insertions(+), 45 deletions(-) rename profile/{profile-ports/profile-inquiry-proxy/src/main/kotlin/co/nilin/opex/profile/ports/inquiry/data => profile-core/src/main/kotlin/co/nilin/opex/profile/core/data/profile}/ComparativeResponse.kt (71%) create mode 100644 profile/profile-ports/profile-postgres/src/main/kotlin/co/nilin/opex/profile/ports/postgres/utils/Extensions.kt diff --git a/common/src/main/kotlin/co/nilin/opex/common/OpexError.kt b/common/src/main/kotlin/co/nilin/opex/common/OpexError.kt index 2cdb53fd9..dc87d979c 100644 --- a/common/src/main/kotlin/co/nilin/opex/common/OpexError.kt +++ b/common/src/main/kotlin/co/nilin/opex/common/OpexError.kt @@ -157,11 +157,12 @@ enum class OpexError(val code: Int, val message: String?, val status: HttpStatus MobileAlreadySet(13014, "Mobile already set", HttpStatus.BAD_REQUEST), EmailAlreadySet(13015, "Email already set", HttpStatus.BAD_REQUEST), ProfileAlreadyCompleted(13016, "Profile already completed", HttpStatus.BAD_REQUEST), - ComparativeVerificationFailed(13017, "Comparative Verification Failed", HttpStatus.BAD_REQUEST), - ProfileApprovalRequestNotfound(13018, "Profile approval request not found", HttpStatus.NOT_FOUND), - InvalidProfileApprovalRequestStatus(13018, "Invalid profile approval request status", HttpStatus.BAD_REQUEST), + FirstNameIsNotSimilarEnough(13017, "The first name is not similar enough.", HttpStatus.BAD_REQUEST), + LastNameIsNotSimilarEnough(13018, "The last name is not similar enough.", HttpStatus.BAD_REQUEST), ShahkarInquiryUnavailable(13019,"Shahkar inquiry unavailable" , HttpStatus.SERVICE_UNAVAILABLE), ComparativeInquiryUnavailable(13020,"Comparative inquiry unavailable" , HttpStatus.SERVICE_UNAVAILABLE), + ProfileApprovalRequestNotfound(13021, "Profile approval request not found", HttpStatus.NOT_FOUND), + InvalidProfileApprovalRequestStatus(13022, "Invalid profile approval request status", HttpStatus.BAD_REQUEST), ; override fun code() = this.code diff --git a/profile/profile-app/src/main/kotlin/co/nilin/opex/profile/app/service/ProfileManagement.kt b/profile/profile-app/src/main/kotlin/co/nilin/opex/profile/app/service/ProfileManagement.kt index ddd05ef44..b2902b383 100644 --- a/profile/profile-app/src/main/kotlin/co/nilin/opex/profile/app/service/ProfileManagement.kt +++ b/profile/profile-app/src/main/kotlin/co/nilin/opex/profile/app/service/ProfileManagement.kt @@ -223,15 +223,16 @@ class ProfileManagement( identifier: String, firstName: String, lastName: String, - birthDate: LocalDateTime + birthDate: Long ) { - if (!inquiryProxy.getComparativeInquiryResult( - identifier, - birthDate, - firstName, - lastName - ) - ) throw OpexError.ComparativeVerificationFailed.exception() + val comparativeInquiryResult = inquiryProxy.getComparativeInquiryResult( + identifier, + birthDate, + firstName, + lastName + ) + if (comparativeInquiryResult.firstNameSimilarityPercentage < 95) throw OpexError.FirstNameIsNotSimilarEnough.exception() + if (comparativeInquiryResult.lastNameSimilarityPercentage < 95) throw OpexError.LastNameIsNotSimilarEnough.exception() } private suspend fun saveProfileApprovalRequest(profileId: Long) { diff --git a/profile/profile-ports/profile-inquiry-proxy/src/main/kotlin/co/nilin/opex/profile/ports/inquiry/data/ComparativeResponse.kt b/profile/profile-core/src/main/kotlin/co/nilin/opex/profile/core/data/profile/ComparativeResponse.kt similarity index 71% rename from profile/profile-ports/profile-inquiry-proxy/src/main/kotlin/co/nilin/opex/profile/ports/inquiry/data/ComparativeResponse.kt rename to profile/profile-core/src/main/kotlin/co/nilin/opex/profile/core/data/profile/ComparativeResponse.kt index 83d59c061..3cddbd05c 100644 --- a/profile/profile-ports/profile-inquiry-proxy/src/main/kotlin/co/nilin/opex/profile/ports/inquiry/data/ComparativeResponse.kt +++ b/profile/profile-core/src/main/kotlin/co/nilin/opex/profile/core/data/profile/ComparativeResponse.kt @@ -1,4 +1,4 @@ -package co.nilin.opex.profile.ports.inquiry.data +package co.nilin.opex.profile.core.data.profile data class ComparativeResponse( val firstNameSimilarityPercentage: Int, diff --git a/profile/profile-core/src/main/kotlin/co/nilin/opex/profile/core/data/profile/CompleteProfileRequest.kt b/profile/profile-core/src/main/kotlin/co/nilin/opex/profile/core/data/profile/CompleteProfileRequest.kt index 111f615e6..397155d15 100644 --- a/profile/profile-core/src/main/kotlin/co/nilin/opex/profile/core/data/profile/CompleteProfileRequest.kt +++ b/profile/profile-core/src/main/kotlin/co/nilin/opex/profile/core/data/profile/CompleteProfileRequest.kt @@ -1,7 +1,5 @@ package co.nilin.opex.profile.core.data.profile -import java.time.LocalDateTime - data class CompleteProfileRequest( var firstName: String, var lastName: String, @@ -11,5 +9,5 @@ data class CompleteProfileRequest( var nationality: NationalityType, var identifier: String, var gender: Gender, - var birthDate: LocalDateTime, + var birthDate: Long, ) diff --git a/profile/profile-core/src/main/kotlin/co/nilin/opex/profile/core/spi/InquiryProxy.kt b/profile/profile-core/src/main/kotlin/co/nilin/opex/profile/core/spi/InquiryProxy.kt index 7e383359d..2b2118ac0 100644 --- a/profile/profile-core/src/main/kotlin/co/nilin/opex/profile/core/spi/InquiryProxy.kt +++ b/profile/profile-core/src/main/kotlin/co/nilin/opex/profile/core/spi/InquiryProxy.kt @@ -1,5 +1,6 @@ package co.nilin.opex.profile.core.spi +import co.nilin.opex.profile.core.data.profile.ComparativeResponse import java.time.LocalDateTime interface InquiryProxy { @@ -7,8 +8,8 @@ interface InquiryProxy { suspend fun getComparativeInquiryResult( identifier: String, - birthDate: LocalDateTime, + birthDate: Long, firstName: String, lastName: String - ): Boolean + ): ComparativeResponse } \ No newline at end of file diff --git a/profile/profile-ports/profile-inquiry-proxy/src/main/kotlin/co/nilin/opex/profile/ports/inquiry/imp/InquiryProxyImp.kt b/profile/profile-ports/profile-inquiry-proxy/src/main/kotlin/co/nilin/opex/profile/ports/inquiry/imp/InquiryProxyImp.kt index 0a19aa352..4d1135a4e 100644 --- a/profile/profile-ports/profile-inquiry-proxy/src/main/kotlin/co/nilin/opex/profile/ports/inquiry/imp/InquiryProxyImp.kt +++ b/profile/profile-ports/profile-inquiry-proxy/src/main/kotlin/co/nilin/opex/profile/ports/inquiry/imp/InquiryProxyImp.kt @@ -1,8 +1,8 @@ package co.nilin.opex.profile.ports.inquiry.imp import co.nilin.opex.common.OpexError +import co.nilin.opex.profile.core.data.profile.ComparativeResponse import co.nilin.opex.profile.core.spi.InquiryProxy -import co.nilin.opex.profile.ports.inquiry.data.ComparativeResponse import co.nilin.opex.profile.ports.inquiry.data.ShahkarResponse import co.nilin.opex.profile.ports.inquiry.utils.TokenProvider import co.nilin.opex.profile.ports.inquiry.utils.toPersianDateFormatted @@ -41,13 +41,13 @@ class InquiryProxyImp( override suspend fun getComparativeInquiryResult( identifier: String, - birthDate: LocalDateTime, + birthDate: Long, firstName: String, lastName: String - ): Boolean { + ): ComparativeResponse { val birthDateFormatted = birthDate.toPersianDateFormatted() - val response = webClient.get() + return webClient.get() .uri("$baseUrl/v1/services/identity/similarity") { it.queryParam("nationalCode", identifier) it.queryParam("birthDate", birthDateFormatted) @@ -60,7 +60,5 @@ class InquiryProxyImp( .retrieve() .onStatus({ t -> t.isError }, { throw OpexError.ComparativeInquiryUnavailable.exception() }) .awaitBody() - - return (response.firstNameSimilarityPercentage >= 95 && response.lastNameSimilarityPercentage >= 95) } } \ No newline at end of file diff --git a/profile/profile-ports/profile-inquiry-proxy/src/main/kotlin/co/nilin/opex/profile/ports/inquiry/utils/DateConvertor.kt b/profile/profile-ports/profile-inquiry-proxy/src/main/kotlin/co/nilin/opex/profile/ports/inquiry/utils/DateConvertor.kt index 26d4f8211..8b1fe8191 100644 --- a/profile/profile-ports/profile-inquiry-proxy/src/main/kotlin/co/nilin/opex/profile/ports/inquiry/utils/DateConvertor.kt +++ b/profile/profile-ports/profile-inquiry-proxy/src/main/kotlin/co/nilin/opex/profile/ports/inquiry/utils/DateConvertor.kt @@ -1,20 +1,20 @@ package co.nilin.opex.profile.ports.inquiry.utils import com.ibm.icu.util.Calendar +import com.ibm.icu.util.TimeZone import com.ibm.icu.util.ULocale -import java.time.LocalDateTime -import java.time.ZoneId import java.util.* -fun LocalDateTime.toPersianDateFormatted(): String { - val instant = this.atZone(ZoneId.systemDefault()).toInstant() - val date = Date.from(instant) - val calendar = Calendar.getInstance(ULocale("fa_IR@calendar=persian")) - calendar.time = date +fun Long.toPersianDateFormatted(): String { + val date = Date(this) + val calendar = Calendar.getInstance(ULocale("fa_IR@calendar=persian")).apply { + timeZone = TimeZone.getTimeZone("Asia/Tehran") + time = date + } val year = calendar.get(Calendar.YEAR) val month = calendar.get(Calendar.MONTH) + 1 val day = calendar.get(Calendar.DAY_OF_MONTH) return String.format("%04d%02d%02d", year, month, day) -} \ No newline at end of file +} diff --git a/profile/profile-ports/profile-postgres/src/main/kotlin/co/nilin/opex/profile/ports/postgres/imp/ProfileManagementImp.kt b/profile/profile-ports/profile-postgres/src/main/kotlin/co/nilin/opex/profile/ports/postgres/imp/ProfileManagementImp.kt index ddcca340b..26827bdf9 100644 --- a/profile/profile-ports/profile-postgres/src/main/kotlin/co/nilin/opex/profile/ports/postgres/imp/ProfileManagementImp.kt +++ b/profile/profile-ports/profile-postgres/src/main/kotlin/co/nilin/opex/profile/ports/postgres/imp/ProfileManagementImp.kt @@ -17,6 +17,7 @@ import co.nilin.opex.profile.ports.postgres.convertor.convertProfileModelToCompl import co.nilin.opex.profile.ports.postgres.dao.ProfileHistoryRepository import co.nilin.opex.profile.ports.postgres.dao.ProfileRepository import co.nilin.opex.profile.ports.postgres.model.entity.ProfileModel +import co.nilin.opex.profile.ports.postgres.utils.toProfileModel import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.toList @@ -84,18 +85,11 @@ class ProfileManagementImp( val existingProfile = profileRepository.findByUserId(id)?.awaitFirstOrNull() ?: throw OpexError.ProfileNotfound.exception() - var newProfileModel = data.convert(ProfileModel::class.java) - newProfileModel.email = existingProfile.email - newProfileModel.mobile = existingProfile.mobile - newProfileModel.id = existingProfile.id - newProfileModel.userId = existingProfile.userId - newProfileModel.status = existingProfile.status - newProfileModel.createDate = existingProfile.createDate - newProfileModel.creator = existingProfile.creator - newProfileModel.kycLevel = existingProfile.kycLevel - newProfileModel.lastUpdateDate = LocalDateTime.now() - newProfileModel.mobileIdentityMatch = mobileIdentityMatch - newProfileModel.personalIdentityMatch = personalIdentityMatch + val newProfileModel = data.toProfileModel( + existing = existingProfile, + mobileMatch = mobileIdentityMatch, + personalMatch = personalIdentityMatch + ) return profileRepository.save(newProfileModel) .map { saved -> diff --git a/profile/profile-ports/profile-postgres/src/main/kotlin/co/nilin/opex/profile/ports/postgres/utils/Convertor.kt b/profile/profile-ports/profile-postgres/src/main/kotlin/co/nilin/opex/profile/ports/postgres/utils/Convertor.kt index e7d99d76a..13d844690 100644 --- a/profile/profile-ports/profile-postgres/src/main/kotlin/co/nilin/opex/profile/ports/postgres/utils/Convertor.kt +++ b/profile/profile-ports/profile-postgres/src/main/kotlin/co/nilin/opex/profile/ports/postgres/utils/Convertor.kt @@ -1,8 +1,41 @@ package co.nilin.opex.profile.ports.postgres.utils +import co.nilin.opex.profile.core.data.profile.CompleteProfileRequest +import co.nilin.opex.profile.ports.postgres.model.entity.ProfileModel import com.google.gson.Gson import reactor.core.publisher.Mono +import java.time.LocalDateTime fun Any.convert(classOfT: Class): T = Gson().fromJson(Gson().toJson(this), classOfT) fun Mono.convert(classOfT: Class): Mono = Mono.just(Gson().fromJson(Gson().toJson(this), classOfT)) + +fun CompleteProfileRequest.toProfileModel( + existing: ProfileModel, + mobileMatch: Boolean, + personalMatch: Boolean +): ProfileModel { + return ProfileModel(id = existing.id).apply { + userId = existing.userId + email = existing.email + mobile = existing.mobile + status = existing.status + createDate = existing.createDate + creator = existing.creator + kycLevel = existing.kycLevel + lastUpdateDate = LocalDateTime.now() + + firstName = this@toProfileModel.firstName + lastName = this@toProfileModel.lastName + address = this@toProfileModel.address + telephone = this@toProfileModel.telephone + postalCode = this@toProfileModel.postalCode + nationality = this@toProfileModel.nationality + identifier = this@toProfileModel.identifier + gender = this@toProfileModel.gender + birthDate = this@toProfileModel.birthDate.asLocalDateTime() + + mobileIdentityMatch = mobileMatch + personalIdentityMatch = personalMatch + } +} diff --git a/profile/profile-ports/profile-postgres/src/main/kotlin/co/nilin/opex/profile/ports/postgres/utils/Extensions.kt b/profile/profile-ports/profile-postgres/src/main/kotlin/co/nilin/opex/profile/ports/postgres/utils/Extensions.kt new file mode 100644 index 000000000..6806c6f99 --- /dev/null +++ b/profile/profile-ports/profile-postgres/src/main/kotlin/co/nilin/opex/profile/ports/postgres/utils/Extensions.kt @@ -0,0 +1,18 @@ +package co.nilin.opex.profile.ports.postgres.utils + + +import java.time.LocalDateTime +import java.time.ZoneId +import java.util.* + +fun LocalDateTime.asDate(): Date { + return Date.from(atZone(ZoneId.systemDefault()).toInstant()) +} + +fun Date.asLocalDateTime(): LocalDateTime { + return LocalDateTime.ofInstant(toInstant(), ZoneId.systemDefault()) +} + +fun Long.asLocalDateTime(): LocalDateTime { + return LocalDateTime.ofInstant(Date(this).toInstant(), ZoneId.systemDefault()) +} \ No newline at end of file diff --git a/profile/profile-ports/profile-postgres/src/main/resources/schema.sql b/profile/profile-ports/profile-postgres/src/main/resources/schema.sql index dd44fa5c6..3d651f59d 100644 --- a/profile/profile-ports/profile-postgres/src/main/resources/schema.sql +++ b/profile/profile-ports/profile-postgres/src/main/resources/schema.sql @@ -25,7 +25,7 @@ CREATE TABLE IF NOT EXISTS profile CREATE TABLE IF NOT EXISTS profile_history ( id SERIAL PRIMARY KEY, - email VARCHAR(100) NOT NULL, + email VARCHAR(100), last_name VARCHAR(256), user_id VARCHAR(100) NOT NULL, create_date TIMESTAMP, @@ -261,4 +261,15 @@ CREATE TABLE IF NOT EXISTS profile_approval_request updater VARCHAR(100), description VARCHAR(255), UNIQUE (profile_id, status) -); \ No newline at end of file +); + +DO +$$ + BEGIN + IF EXISTS (SELECT 1 + FROM information_schema.columns + WHERE table_name = 'profile_history' AND column_name = 'email') THEN ALTER TABLE profile_history + ALTER COLUMN email DROP NOT NULL; + END IF; + END +$$; \ No newline at end of file