Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend/feat/moved-govtdata-table-to-clickhouse #495

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/mobility-core/mobility-core.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ library
Kernel.External.Verification
Kernel.External.Verification.GovtData.Client
Kernel.External.Verification.GovtData.Storage.Beam
Kernel.External.Verification.GovtData.Storage.ClickHouse
Kernel.External.Verification.GovtData.Storage.Query
Kernel.External.Verification.GovtData.Types
Kernel.External.Verification.Idfy.Auth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,20 @@ module Kernel.External.Verification.GovtData.Client
)
where

import Kernel.Beam.Lib.UtilsTH
import Kernel.External.Verification.GovtData.Storage.Beam as BeamGRC
import qualified Kernel.External.Verification.GovtData.Storage.Query as QGD
import qualified Kernel.External.Verification.GovtData.Storage.ClickHouse as QGC
import Kernel.External.Verification.Interface.Types
import qualified Kernel.External.Verification.Types as VT
import Kernel.Prelude
import Kernel.Types.Common
import Kernel.Storage.ClickhouseV2 as CH
import Kernel.Types.Error
import Kernel.Utils.Common

verifyRC ::
(HasSchemaName BeamGRC.GovtDataRCT, MonadFlow m, EsqDBFlow m r, CacheFlow m r) =>
(CH.HasClickhouseEnv CH.APP_SERVICE_CLICKHOUSE m) =>
VerifyRCReq ->
m VerifyRCResp
verifyRC req = do
res <- QGD.findByRCNumber req.rcNumber >>= fromMaybeM (InternalError "rcNumber is not found in GovtData.")
res <- QGC.findByRCNumber req.rcNumber >>= fromMaybeM (InternalError "rcNumber is not found in GovtData.")
pure $
SyncResp
VT.RCVerificationResponse
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TemplateHaskell #-}
{-
Copyright 2022-23, Juspay India Pvt Ltd

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License

as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is

distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS

FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero

General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
-}
{-# OPTIONS_GHC -Wno-orphans #-}

module Kernel.External.Verification.GovtData.Storage.ClickHouse where

import Kernel.Prelude
import Kernel.Storage.ClickhouseV2 as CH hiding (toDate)
import qualified Kernel.Storage.ClickhouseV2.UtilsTH as TH

data GovtDataT f = GovtDataT
{ id :: C f Text,
merchantOperatingCityId :: C f Text,
ownerSerialNumber :: C f (Maybe Text),
registrationNumber :: C f (Maybe Text),
manufacturerModel :: C f (Maybe Text),
permitValidityFrom :: C f (Maybe Text),
permitValidityUpto :: C f (Maybe Text),
manufacturer :: C f (Maybe Text),
bodyType :: C f (Maybe Text),
numberOfCylinder :: C f (Maybe Int),
fuelType :: C f (Maybe Text),
seatingCapacity :: C f (Maybe Int),
fromDate :: C f (Maybe Text),
toDate :: C f (Maybe Text),
createdAt :: C f UTCTime
}
deriving (Generic)

deriving instance Show GovtData

govtDataTTable :: GovtDataT (FieldModification GovtDataT)
govtDataTTable =
GovtDataT
{ id = "id",
merchantOperatingCityId = "merchant_operating_city_id",
ownerSerialNumber = "owner_serial_number",
registrationNumber = "registration_number",
manufacturerModel = "manufacturer_model",
permitValidityFrom = "permit_validity_from",
permitValidityUpto = "permit_validity_upto",
manufacturer = "manufacturer",
bodyType = "body_type",
numberOfCylinder = "number_of_cylinder",
fuelType = "fuel_type",
seatingCapacity = "seating_capacity",
fromDate = "from_date",
toDate = "to_date",
createdAt = "created_at"
}

type GovtData = GovtDataT Identity

$(TH.mkClickhouseInstances ''GovtDataT)

findByRCNumber ::
CH.HasClickhouseEnv CH.APP_SERVICE_CLICKHOUSE m =>
Text ->
m (Maybe (GovtDataT Identity))
findByRCNumber rcNumber = do
govtData <-
CH.findAll $
CH.select $
CH.filter_
( \govtData _ ->
govtData.registrationNumber CH.==. (Just rcNumber)
)
(CH.all_ @CH.APP_SERVICE_CLICKHOUSE govtDataTTable)
return $ listToMaybe govtData
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,15 @@ module Kernel.External.Verification.Interface
where

import EulerHS.Prelude
import Kernel.Beam.Lib.UtilsTH
import qualified Kernel.External.Verification.GovtData.Client as GovtData
import Kernel.External.Verification.GovtData.Storage.Beam as BeamGRC
import Kernel.External.Verification.GovtData.Types as Reexport
import Kernel.External.Verification.Idfy.Config as Reexport
import qualified Kernel.External.Verification.Interface.Idfy as Idfy
import qualified Kernel.External.Verification.Interface.InternalScripts as IS
import qualified Kernel.External.Verification.Interface.SafetyPortal as SafetyPortal
import Kernel.External.Verification.Interface.Types as Reexport
import Kernel.External.Verification.InternalScripts.Types
import Kernel.External.Verification.SafetyPortal.Types
import Kernel.External.Verification.Types as Reexport
import qualified Kernel.Storage.ClickhouseV2 as CH
import Kernel.Tools.Metrics.CoreMetrics.Types
import Kernel.Types.Common
import Kernel.Types.Error
Expand All @@ -57,7 +54,7 @@ verifyDLAsync serviceConfig req = case serviceConfig of
verifyRC ::
( EncFlow m r,
CoreMetrics m,
HasSchemaName BeamGRC.GovtDataRCT,
CH.HasClickhouseEnv CH.APP_SERVICE_CLICKHOUSE m,
MonadFlow m,
EsqDBFlow m r,
CacheFlow m r
Expand All @@ -84,7 +81,7 @@ verifyRC verificationProvidersPriorityList idfyServiceConfig req = do
verifyRC' ::
( EncFlow m r,
CoreMetrics m,
HasSchemaName BeamGRC.GovtDataRCT,
CH.HasClickhouseEnv CH.APP_SERVICE_CLICKHOUSE m,
MonadFlow m,
EsqDBFlow m r,
CacheFlow m r
Expand Down