Merge pull request #6 from dikstub-rssa/feat/atlas-migration-orm

Feat/atlas migration orm
This commit is contained in:
Munawwirul Jamal
2025-08-29 11:08:08 +07:00
committed by GitHub
34 changed files with 1316 additions and 123 deletions
+1
View File
@@ -27,6 +27,7 @@ go.work.sum
# env file
.env
config.yml
cmd/migration/atlas.hcl
# Editor/IDE
# .idea/
+7 -7
View File
@@ -7,12 +7,12 @@
"mode": "auto",
"program": "${workspaceFolder}/cmd/main-api"
},
// {
// "name": "Launch Package excel migrator",
// "type": "go",
// "request": "launch",
// "mode": "auto",
// "program": "${workspaceFolder}/cmd/excelmigrator"
// }
{
"name": "Launch Package migratioon",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/migration"
}
]
}
+6
View File
@@ -15,6 +15,12 @@ dbCfg:
maxIdleConns: 5
maxIdleTime: 100
ssDbCfg:
dsn:
maxOpenConns: 5
maxIdleConns: 5
maxIdleTime: 100
loggerCfg:
hideTime:
hideLevel:
+22
View File
@@ -0,0 +1,22 @@
data "external_schema" "gorm" {
program = [
"go",
"run",
"-mod=mod",
".",
]
}
env "gorm" {
src = data.external_schema.gorm.url
dev = "postgres://moko:password@localhost:5432/simrs_vx3?sslmode=disable"
migration {
dir = "file://migrations"
}
url = "postgres://moko:password@localhost:5432/simrs_vx1?sslmode=disable"
format {
migrate {
diff = "{{ sql . \" \" }}"
}
}
}
+22
View File
@@ -0,0 +1,22 @@
data "external_schema" "gorm" {
program = [
"go",
"run",
"-mod=mod",
".",
]
}
env "gorm" {
src = data.external_schema.gorm.url
dev = "" // dsn db to check the diff
migration {
dir = "file://migrations"
}
url = "" // dsn db to apply
format {
migrate {
diff = "{{ sql . \" \" }}"
}
}
}
+22 -12
View File
@@ -1,35 +1,45 @@
module simrs-vx
go 1.23.0
go 1.24
toolchain go1.23.11
toolchain go1.24.6
require (
github.com/karincake/apem v0.0.16-g
ariga.io/atlas-provider-gorm v0.5.6
github.com/karincake/apem v0.0.16-h
github.com/karincake/dodol v0.0.1
github.com/karincake/getuk v0.1.0
github.com/karincake/lepet v0.0.1
golang.org/x/crypto v0.40.0
gopkg.in/yaml.v3 v3.0.1
gorm.io/driver/postgres v1.5.7
gorm.io/gorm v1.25.10
golang.org/x/crypto v0.41.0
gorm.io/driver/postgres v1.5.11
gorm.io/gorm v1.25.12
)
require (
ariga.io/atlas v0.36.2-0.20250806044935-5bb51a0a956e // indirect
github.com/go-redis/redis v6.15.9+incompatible // indirect
github.com/go-sql-driver/mysql v1.7.0 // indirect
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
github.com/golang-sql/sqlexp v0.1.0 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgx/v5 v5.4.3 // indirect
github.com/jackc/pgx/v5 v5.5.5 // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-sqlite3 v1.14.28 // indirect
github.com/microsoft/go-mssqldb v1.7.2 // indirect
github.com/nxadm/tail v1.4.11 // indirect
github.com/rs/zerolog v1.33.0 // indirect
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 // indirect
golang.org/x/net v0.42.0 // indirect
golang.org/x/sys v0.34.0 // indirect
golang.org/x/text v0.27.0 // indirect
golang.org/x/sync v0.16.0 // indirect
golang.org/x/sys v0.35.0 // indirect
golang.org/x/text v0.28.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/driver/mysql v1.5.7 // indirect
gorm.io/driver/sqlite v1.5.7 // indirect
gorm.io/driver/sqlserver v1.5.4 // indirect
)
+162 -16
View File
@@ -1,27 +1,74 @@
ariga.io/atlas v0.36.2-0.20250806044935-5bb51a0a956e h1:7upp27oOT/fmM5Dz3z9k8cmYwKJ2NAzuTqfT/rEP+50=
ariga.io/atlas v0.36.2-0.20250806044935-5bb51a0a956e/go.mod h1:Ex5l1xHsnWQUc3wYnrJ9gD7RUEzG76P7ZRQp8wNr0wc=
ariga.io/atlas-provider-gorm v0.5.6 h1:poMRZgIRvx/qIFtartefgOjCfgNIPBCdrVfkb5pIBQc=
ariga.io/atlas-provider-gorm v0.5.6/go.mod h1:9UmIoNjSAB6CHOrshEmR6sXUmqpLpIGWffBQigjQYDs=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.7.0/go.mod h1:bjGvMhVMb+EEm3VRNQawDMUyMMjo+S5ewNjflkep/0Q=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.7.1/go.mod h1:bjGvMhVMb+EEm3VRNQawDMUyMMjo+S5ewNjflkep/0Q=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.1 h1:lGlwhPtrX6EVml1hO0ivjkUxsSyl4dsiw9qcA1k/3IQ=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.1/go.mod h1:RKUqNu35KJYcVG/fqTRqmuXJZYNhYkBrnC/hX7yGbTA=
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.3.1/go.mod h1:uE9zaUfEQT/nbQjVi2IblCG9iaLtZsuYZ8ne+PuQ02M=
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.5.1 h1:sO0/P7g68FrryJzljemN+6GTssUXdANk6aJ7T1ZxnsQ=
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.5.1/go.mod h1:h8hyGFDsU5HMivxiS2iYFZsgDbU9OnnJ163x5UGVKYo=
github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0/go.mod h1:okt5dMMTOFjX/aovMlrjvvXoPMBVSPzk9185BT0+eZM=
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.1 h1:6oNBlSdi1QqM1PNW7FPA6xOGA5UNsXnkaYZz9vdPGhA=
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.1/go.mod h1:s4kgfzA0covAXNicZHDMN58jExvcng2mC/DepXiF1EI=
github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azkeys v1.0.1 h1:MyVTgWR8qd/Jw1Le0NZebGBUCLbtak3bJ3z1OlqZBpw=
github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azkeys v1.0.1/go.mod h1:GpPjLhVR9dnUoJMyHWSPy71xY9/lcmpzIPZXmF0FCVY=
github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/internal v1.0.0 h1:D3occbWoio4EBLkbkevetNMAVX197GkzbUMtqjGWn80=
github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/internal v1.0.0/go.mod h1:bTSOgj05NGRuHHhQwAdPnYr9TOdNmKlZTgGLL6nyAdI=
github.com/AzureAD/microsoft-authentication-library-for-go v1.1.1/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI=
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.1 h1:DzHpqpoJVaCgOUdVHxE8QB52S6NiVdDQvGlny1qvPqA=
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.1/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dnaeon/go-vcr v1.1.0/go.mod h1:M7tiix8f0r6mKKJ3Yq/kqU1OYf3MnfmBWVbPx/yU9ko=
github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
github.com/go-redis/redis v6.15.9+incompatible h1:K0pv1D7EQUjfyoMql+r/jZqCLizCGKFlFgcHWWmHQjg=
github.com/go-redis/redis v6.15.9+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc=
github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
github.com/golang-jwt/jwt/v5 v5.2.0 h1:d/ix8ftRUorsN+5eMIlF4T6J8CAt9rch3My2winC1Jw=
github.com/golang-jwt/jwt/v5 v5.2.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 h1:au07oEsX2xN0ktxqI+Sida1w446QrXBRJ0nee3SNZlA=
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
github.com/golang-sql/sqlexp v0.1.0 h1:ZCD6MBpcuOVfGVqsEmY5/4FtYiKz6tSyUv9LPEDei6A=
github.com/golang-sql/sqlexp v0.1.0/go.mod h1:J4ad9Vo8ZCWQ2GMrC4UCQy1JpCbwU9m3EOqtpKwwwHI=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
github.com/jackc/pgx/v5 v5.4.3 h1:cxFyXhxlvAifxnkKKdlxv8XqUf59tDlYjnV5YYfsJJY=
github.com/jackc/pgx/v5 v5.4.3/go.mod h1:Ig06C2Vu0t5qXC60W8sqIthScaEnFvojjj9dSljmHRA=
github.com/jackc/pgx/v5 v5.5.5 h1:amBjrZVmksIdNjxGW/IiIMzxMKZFelXbUoPNb+8sjQw=
github.com/jackc/pgx/v5 v5.5.5/go.mod h1:ez9gk+OAat140fv9ErkZDYFWmXLfV+++K0uAOiwgm1A=
github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk=
github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/jcmturner/aescts/v2 v2.0.0/go.mod h1:AiaICIRyfYg35RUkr8yESTqvSy7csK90qZ5xfvvsoNs=
github.com/jcmturner/dnsutils/v2 v2.0.0/go.mod h1:b0TnjGOvI/n42bZa+hmXL+kFJZsFT7G4t3HTlQ184QM=
github.com/jcmturner/gofork v1.7.6/go.mod h1:1622LH6i/EZqLloHfE7IeZ0uEJwMSUyQ/nDd82IeqRo=
github.com/jcmturner/goidentity/v6 v6.0.1/go.mod h1:X1YW3bgtvwAXju7V3LCIMpY0Gbxyjn/mY9zx4tFonSg=
github.com/jcmturner/gokrb5/v8 v8.4.4/go.mod h1:1btQEpgT6k+unzCwX1KdWMEwPPkkgBtP+F6aCACiMrs=
github.com/jcmturner/rpc/v2 v2.0.3/go.mod h1:VUJYCIDm3PVOEHw8sgt091/20OJjskO/YJki3ELg/Hc=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/karincake/apem v0.0.16-g h1:jPIr/YiaJhVSftdA1PyB2tlDiQtFeTVZohO1qf0qpw0=
github.com/karincake/apem v0.0.16-g/go.mod h1:cQP2sJfDrLRIiwWoaLWw/z8uAya+DWu/FpmYeinMQXM=
github.com/karincake/apem v0.0.16-h h1:rfO444oDG4cWFf0PjUshA+0U8KI/u067Va273WeJhpU=
github.com/karincake/apem v0.0.16-h/go.mod h1:cQP2sJfDrLRIiwWoaLWw/z8uAya+DWu/FpmYeinMQXM=
github.com/karincake/dodol v0.0.1 h1:jUXmJh1r0Ei4fmHPZ6IUkoplW/V9d27L63JEl6zudL0=
github.com/karincake/dodol v0.0.1/go.mod h1:2f1NcvkvY0J3GMUkwILNDYVvRUpz0W3lpPp/Ha/Ld24=
github.com/karincake/getuk v0.1.0 h1:jcIsASrr0UDE528GN7Ua6n9UFyRgUypsWh8Or8wzCO0=
@@ -32,17 +79,28 @@ github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-sqlite3 v1.14.28 h1:ThEiQrnbtumT+QMknw63Befp/ce/nUPgBPMlRFEum7A=
github.com/mattn/go-sqlite3 v1.14.28/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/microsoft/go-mssqldb v1.7.2 h1:CHkFJiObW7ItKTJfHo1QX7QBBD1iV+mn1eOyRP3b/PA=
github.com/microsoft/go-mssqldb v1.7.2/go.mod h1:kOvZKUdrhhFQmxLZqbwUV0rHkNkZpthMITIb2Ko1IoA=
github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8=
github.com/montanaflynn/stats v0.7.0/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
github.com/nxadm/tail v1.4.11 h1:8feyoE3OzPrcshW5/MJ4sGESc5cqmGkGCWlco4l0bqY=
github.com/nxadm/tail v1.4.11/go.mod h1:OTaG3NK980DZzxbRq6lEuzgU+mug70nY11sMd4JXXHc=
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
github.com/onsi/gomega v1.33.1 h1:dsYjIxxSR755MDmKVsaFQTE22ChNBcuuTWgkUDSubOk=
github.com/onsi/gomega v1.33.1/go.mod h1:U4R44UsT+9eLIaYRB2a5qajjtQYn0hauxvRm16AVYg0=
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI=
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ=
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
@@ -52,33 +110,121 @@ github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
golang.org/x/crypto v0.40.0 h1:r4x+VvoG5Fm+eJcxMaY8CQM7Lb0l1lsmjGBQ6s8BfKM=
golang.org/x/crypto v0.40.0/go.mod h1:Qr1vMER5WyS2dfPHAlsOj01wgLbsyWtFn/aY+5+ZdxY=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio=
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
golang.org/x/crypto v0.41.0 h1:WKYxWedPGCTVVl5+WHSSrOBT0O8lx32+zxmHxijgXp4=
golang.org/x/crypto v0.41.0/go.mod h1:pO5AFd7FA68rFak7rOAGVuygIISepHftHnr8dr6+sUc=
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 h1:yixxcjnhBmY0nkL253HFVIm0JsFHwrHdT3Yh6szTnfY=
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8/go.mod h1:jj3sYF3dwk5D+ghuXyeI3r5MFf+NT2An6/9dOA95KSI=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.13.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
golang.org/x/net v0.42.0 h1:jzkYrhi3YQWD6MLBJcsklgQsoAcw89EcZbJw8Z614hs=
golang.org/x/net v0.42.0/go.mod h1:FF1RA5d3u7nAYA4z2TkclSCKh68eSXtiFwcWQpPXdt8=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA=
golang.org/x/sys v0.34.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/text v0.27.0 h1:4fGWRpyh641NLlecmyl4LOe6yDdfaYNrGb2zdfo4JV4=
golang.org/x/text v0.27.0/go.mod h1:1D28KMCvyooCX9hBiosv5Tz/+YLxj0j7XhWjpSUF7CU=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o=
golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU=
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/postgres v1.5.7 h1:8ptbNJTDbEmhdr62uReG5BGkdQyeasu/FZHxI0IMGnM=
gorm.io/driver/postgres v1.5.7/go.mod h1:3e019WlBaYI5o5LIdNV+LyxCMNtLOQETBXL2h4chKpA=
gorm.io/gorm v1.25.10 h1:dQpO+33KalOA+aFYGlK+EfxcI5MbO7EP2yYygwh9h+s=
gorm.io/gorm v1.25.10/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
gorm.io/driver/mysql v1.5.7 h1:MndhOPYOfEp2rHKgkZIhJ16eVUIRf2HmzgoPmh7FCWo=
gorm.io/driver/mysql v1.5.7/go.mod h1:sEtPWMiqiN1N1cMXoXmBbd8C6/l+TESwriotuRRpkDM=
gorm.io/driver/postgres v1.5.11 h1:ubBVAfbKEUld/twyKZ0IYn9rSQh448EdelLYk9Mv314=
gorm.io/driver/postgres v1.5.11/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI=
gorm.io/driver/sqlite v1.5.7 h1:8NvsrhP0ifM7LX9G4zPB97NwovUakUxc+2V2uuf3Z1I=
gorm.io/driver/sqlite v1.5.7/go.mod h1:U+J8craQU6Fzkcvu8oLeAQmi50TkwPEhHDEjQZXDah4=
gorm.io/driver/sqlserver v1.5.4 h1:xA+Y1KDNspv79q43bPyjDMUgHoYHLhXYmdFcYPobg8g=
gorm.io/driver/sqlserver v1.5.4/go.mod h1:+frZ/qYmuna11zHPlh5oc2O6ZA/lS88Keb0XSH1Zh/g=
gorm.io/gorm v1.25.7-0.20240204074919-46816ad31dde/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8=
gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ=
+2 -2
View File
@@ -1,6 +1,6 @@
package single
type Createdto struct {
type CreateDto struct {
Code string `json:"code"`
Name string `json:"name"`
Description string `json:"description"`
@@ -23,7 +23,7 @@ type ReadDetailDto struct {
type Updatedto struct {
Id uint `json:"id"`
Createdto
CreateDto
}
type Deletedto struct {
+7 -4
View File
@@ -1,14 +1,17 @@
package core
import "gorm.io/gorm"
import (
"time"
"gorm.io/gorm"
)
type Base struct {
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
CreatedAt time.Time `json:"createdAt" gorm:"type:timestamptz"`
UpdatedAt string `json:"updatedAt" gorm:"type:timestamptz"`
DeteledAt gorm.DeletedAt `json:"deletedAt,omitempty"`
}
//
type Main struct {
Id uint `json:"id" gorm:"primaryKey"` // depends on the system architecture
Base
+38
View File
@@ -0,0 +1,38 @@
package user
import erc "simrs-vx/internal/domain/references/common"
type CreateDto struct {
Name string `json:"name"`
Password string `json:"password"`
Status_Code erc.StatusCode `json:"status_code"`
}
type ReadListDto struct {
Name string `json:"name"`
Status_Code erc.StatusCode `json:"status_code"`
Page int `json:"page"`
PageSize int `json:"page_size"`
NoPagination int `json:"no_pagination"`
}
type ReadDetailDto struct {
Id uint `json:"id"`
Name string `json:"name"`
}
type Updatedto struct {
Id uint `json:"id"`
CreateDto
}
type Deletedto struct {
Id uint `json:"id"`
}
type MetaDto struct {
PageNumber int `json:"page_number"`
PageSize int `json:"page_size"`
Count int64 `json:"count"`
}
@@ -0,0 +1,14 @@
package user
import (
ecore "simrs-vx/internal/domain/base-entities/core"
erc "simrs-vx/internal/domain/references/common"
)
type User struct {
ecore.Main // adjust this according to the needs
Name string `json:"name" gorm:"not null;size:25"`
Password string `json:"password" gorm:"not null;size:255"`
Status_Code erc.StatusCode `json:"status_code" gorm:"not null;size:10"`
FailedLoginCount uint8 `json:"failedLoginCount" gorm:"type:smallint"`
}
@@ -0,0 +1,40 @@
package common
type (
YaTidakCode byte
SudahBelumCode byte
AktifSimpelCode byte
AktifAdvanceCode byte
TersediaCode byte
StatusCode string
)
const (
TTTidak YaTidakCode = iota
TTYa
)
const (
BSBelum SudahBelumCode = iota
BSSudah
)
const (
ASCInaktif AktifSimpelCode = iota
ASCAktif
)
const (
AACBaru AktifAdvanceCode = iota
AACAktif
AACBlokir
AACHapus
)
const (
TCTidakTersedia TersediaCode = iota
TCTersedia
)
const (
SCActive StatusCode = "active"
SCInactive StatusCode = "inactive"
)
@@ -0,0 +1,26 @@
package digitalsignature
type (
RMEType string
SignType string
)
const (
// modules
RMETypePrescription RMEType = "prescription"
RMETypeExamination RMEType = "examination"
RMETypeRadiology RMEType = "radiology"
RMETypeSick RMEType = "sick"
RMETypeReferral RMEType = "referral"
RMETypeEndOfLife RMEType = "endoflife"
RMETypeChangeDpjp RMEType = "changedpjp"
// employee
SignTypeEmployee SignType = "employee"
// doctor
SignTypeDoctor SignType = "doctor"
// patient
SignTypePatient SignType = "patient"
)
@@ -0,0 +1,44 @@
package examination
type (
ExaminationStatus string
ExaminationClass string
EmergencyClass string
InpatientClass string
)
const (
ExaminationStatusNew ExaminationStatus = "new"
ExaminationStatusNurse ExaminationStatus = "nurse assessment"
ExaminationStatusDoctor ExaminationStatus = "doctor assessment"
ExaminationStatusDone ExaminationStatus = "done"
ExaminationStatusCancel ExaminationStatus = "canceled"
)
const (
IGD EmergencyClass = "igd"
Ponek EmergencyClass = "ponek"
)
const (
ECAmbulatory ExaminationClass = "ambulatory"
ECInpatient ExaminationClass = "inpatient"
ECEmergency ExaminationClass = "emergency"
ECRadiology ExaminationClass = "radiology"
)
func (ec ExaminationClass) Code() string {
switch ec {
case ECAmbulatory:
return "AMB"
case ECInpatient:
return "IMP"
case ECEmergency:
return "EMER"
default:
return "UNKNOWN"
}
}
const (
ICU InpatientClass = "ICU"
NonICU InpatientClass = "non ICU"
)
@@ -0,0 +1,67 @@
package finance
type (
PaymentMethodCode string
TaxCode string
PaymentStatusCode string
ServiceType string
)
const (
PMCCash PaymentMethodCode = "cash"
PMCBPJS PaymentMethodCode = "bpjs"
PMCInsurance PaymentMethodCode = "insurance"
PMCMembership PaymentMethodCode = "membership"
PMCDebit PaymentMethodCode = "debit"
PMCCredit PaymentMethodCode = "credit"
PMCOther PaymentMethodCode = "other"
)
const (
TCCountry TaxCode = "country"
)
const (
PaymentStatusNew PaymentStatusCode = "new"
PaymentStatusUnpaid PaymentStatusCode = "unpaid"
PaymentStatusPaid PaymentStatusCode = "paid"
PaymentStatusCancel PaymentStatusCode = "cancel"
PaymentStatusFailed PaymentStatusCode = "failed"
)
func GetTaxeCodes() map[TaxCode]float32 {
return map[TaxCode]float32{
TCCountry: 0.11,
}
}
var NonInsurancePaymentMethods = map[PaymentMethodCode]bool{
PMCCash: true,
PMCDebit: true,
PMCCredit: true,
}
func (p PaymentMethodCode) IsInsurance() bool {
switch p {
case PMCCash, PMCDebit, PMCCredit, PMCBPJS:
return true
default:
return false
}
}
const (
STInpatient = "Rawat Inap"
STAmbulatory = "Rawat Jalan"
STEmergency = "IGD"
STPonek = "PONEK"
STLab = "Laboratorium"
STRadiology = "Radiologi"
)
const (
AdminEmergencyFee = "Biaya Administrasi IGD"
DoctorEmergencyFee = "Biaya Dokter IGD"
AdminPediatricInternalFee = "Biaya Administrasi Poli Anak/Penyakit Dalam"
AdminGeneralPolyFee = "Biaya Administrasi Poli"
)
@@ -0,0 +1,46 @@
package organization
type (
PositionCode string
QueuePositionCode string
)
const (
PosReg PositionCode = "reg"
PosDoctor PositionCode = "doc"
PosNurse PositionCode = "nur" // DEPRECATED
PosAmbulatory PositionCode = "amb" // rawat jalan
PosEmergency PositionCode = "emg" // gawat darurat
PosNEC PositionCode = "eon" // ponek, cEONc
PosInpatient PositionCode = "inp" // rawat inap
PosICU PositionCode = "icu"
PosVK PositionCode = "vlk"
PosNeonatus PositionCode = "neo"
PosMidwife PositionCode = "mwf"
PosNutrition PositionCode = "nut"
PosAnesthesia PositionCode = "ans"
PosSurgery PositionCode = "sur"
PosPharmacy PositionCode = "pha"
PosRadiology PositionCode = "rad"
PosLab PositionCode = "lab"
PosFinance PositionCode = "fin"
PosHRD PositionCode = "hrd"
PosOperator PositionCode = "opr"
PosAdmin PositionCode = "adm"
PosSystem PositionCode = "sys"
)
const (
CQPCRegistration QueuePositionCode = "reg"
CQPCPayment QueuePositionCode = "pay"
CQPCExamination QueuePositionCode = "exa"
CQPCMedicine QueuePositionCode = "med"
CQPCProcedure QueuePositionCode = "pro"
CQPCFinish QueuePositionCode = "fin"
CQPCRegSkip QueuePositionCode = "reg-ski"
CQPCPaySkip QueuePositionCode = "pay-ski"
CQPCExaSkip QueuePositionCode = "exa-ski"
CQPCMedSkip QueuePositionCode = "med-ski"
CQPCReschedule QueuePositionCode = "rse"
)
@@ -0,0 +1,85 @@
package patient
type (
ConsciousLevelCode string
StatusCode string
PaymentMethodCode string
EndAssessmentCode string
VisitTypeJknCode uint8
)
const (
CLCAlert ConsciousLevelCode = "alert"
CLCVoice ConsciousLevelCode = "voice"
CLCPain ConsciousLevelCode = "pain"
CLCUnresponsive ConsciousLevelCode = "unresponsive"
CLCAnxious ConsciousLevelCode = "anxious"
CLCAcuteConfusional ConsciousLevelCode = "acute-confuncional"
PMCCash PaymentMethodCode = "cash"
PMCDebit PaymentMethodCode = "debit"
PMCCredit PaymentMethodCode = "credit"
PMCBpjs PaymentMethodCode = "bpjs"
PMCMembership PaymentMethodCode = "membership"
PMCInsurance PaymentMethodCode = "insurance"
SCDraft StatusCode = "draft"
SCActive StatusCode = "active"
SCInactive StatusCode = "inactive"
SCBlocked StatusCode = "blocked"
SCDead StatusCode = "dead"
EACHomeRecom EndAssessmentCode = "home recommendation"
EACHomeReq EndAssessmentCode = "home request"
EACOtherPoly EndAssessmentCode = "others poly"
EACRefInt EndAssessmentCode = "referral internal"
EACRefExt EndAssessmentCode = "referral external"
EACDecease EndAssessmentCode = "decease"
VTJCReference VisitTypeJknCode = 1
VTJCInternalReference VisitTypeJknCode = 2
VTJCControl VisitTypeJknCode = 3
VTJCExternalReference VisitTypeJknCode = 4
)
func GetStatusCodes() map[StatusCode]string {
return map[StatusCode]string{
SCDraft: "Draft",
SCActive: "Aktif",
SCInactive: "Tidak Aktif",
SCBlocked: "Diblokir",
SCDead: "Meninggal",
}
}
func GetConsciousLevelCodes() map[ConsciousLevelCode]string {
return map[ConsciousLevelCode]string{
CLCAlert: "Sadar Baik / Alert",
CLCVoice: "Berespon dengan kata-kata / Voice",
CLCPain: "Hanya beresponse jika dirangsang nyeri / pain",
CLCUnresponsive: "Pasien tidak sadar / unresponsive",
CLCAnxious: "Gelisah atau bingung",
CLCAcuteConfusional: "Acute Confusional States",
}
}
func GetPaymentMethodCodes() map[PaymentMethodCode]string {
return map[PaymentMethodCode]string{
PMCCash: "cash",
PMCDebit: "debit",
PMCCredit: "credit",
PMCBpjs: "bpjs",
PMCMembership: "membership",
PMCInsurance: "insurance"}
}
func GetEndAssessments() map[EndAssessmentCode]string {
return map[EndAssessmentCode]string{
EACHomeRecom: "home-recommendation",
EACHomeReq: "home-request",
EACOtherPoly: "other-poly",
EACRefInt: "referral-internal",
EACRefExt: "referral-external",
EACDecease: "decease",
}
}
+252
View File
@@ -0,0 +1,252 @@
package person
type (
GenderCode string
BloodTypeCode string
MaritalStatusCode string
ReligionCode string
EducationCode string
ProfessionCode string
AgeGroupCode string
AgeGroupForMedicineCode string
RelativeCode string
)
const (
GCMale GenderCode = "male"
GCFemale GenderCode = "female"
GCOther GenderCode = "other"
GCUnknown GenderCode = "unknown"
)
const (
BTCAPositive BloodTypeCode = "A+"
BTCANegative BloodTypeCode = "A-"
BTCBPositive BloodTypeCode = "B+"
BTCBNegative BloodTypeCode = "B-"
BTCABPositive BloodTypeCode = "AB+"
BTCABNegative BloodTypeCode = "AB-"
BTCOPositive BloodTypeCode = "O+"
BTCONegative BloodTypeCode = "O-"
)
const (
MSCBelumKawin MaritalStatusCode = "S"
MSCKawin MaritalStatusCode = "M"
MSCCeraiHidup MaritalStatusCode = "D"
MSCCeraiMati MaritalStatusCode = "W"
)
const (
RCIslam ReligionCode = "islam"
RCProtestan ReligionCode = "protestan"
RCKatolik ReligionCode = "katolik"
RCHindu ReligionCode = "hindu"
RCBudha ReligionCode = "budha"
RCKonghucu ReligionCode = "konghucu"
RCPenghayat ReligionCode = "penghayat"
)
const (
ECTidakSekolah EducationCode = "TS"
ECTK EducationCode = "TK"
ECSD EducationCode = "SD"
ECSLTP EducationCode = "SMP"
ECSLTA EducationCode = "SMA"
ECD1 EducationCode = "D1"
ECD2 EducationCode = "D2"
ECD3 EducationCode = "D3"
ECD4 EducationCode = "D4"
ECS1 EducationCode = "S1"
ECS2 EducationCode = "S2"
ECS3 EducationCode = "S3"
)
const (
PCTidakBekerja ProfessionCode = "-"
PCPns ProfessionCode = "pns"
PCTniPolri ProfessionCode = "tni-polri"
PCBumn ProfessionCode = "bumn"
PCWiraswasta ProfessionCode = "wiraswasta"
PCLainlain ProfessionCode = "lainnya"
)
const (
AGCEUnknown AgeGroupCode = "unkown"
AGCLTE5 AgeGroupCode = "LT5"
AGCEU19 AgeGroupCode = "UE19"
AGCEU29 AgeGroupCode = "UE29"
AGCEU39 AgeGroupCode = "UE39"
AGCEU49 AgeGroupCode = "UE49"
AGCEU59 AgeGroupCode = "UE50"
AGCGE60 AgeGroupCode = "E60"
)
const (
AGMCNew AgeGroupForMedicineCode = "new-born"
AGMCInfant AgeGroupForMedicineCode = "infant"
AGMCToddler AgeGroupForMedicineCode = "toddler"
AGMCKid AgeGroupForMedicineCode = "kid"
AGMCAdult AgeGroupForMedicineCode = "adult"
)
const (
RCMSuami RelativeCode = "suami"
RCMIstri RelativeCode = "istri"
RCMAnak RelativeCode = "anak"
RCMMenantu RelativeCode = "menantu"
RCMCucu RelativeCode = "cucu"
RCMOrangTua RelativeCode = "orang-tua"
RCMMertua RelativeCode = "mertua"
RCMAdik RelativeCode = "adik"
RCMKeponakan RelativeCode = "keponakan"
RCMKakak RelativeCode = "kakak"
RCMPaman RelativeCode = "paman"
RCMBibi RelativeCode = "bibi"
RCMPamanKakek RelativeCode = "kakek"
RCMPamanNenek RelativeCode = "nenek"
)
func GetGenderCodes() map[GenderCode]string {
return map[GenderCode]string{
GCMale: "Laki-laki",
GCFemale: "Perempuan",
GCOther: "Lainnya",
GCUnknown: "Tidak diketahui",
}
}
func GetBloodTypeCodes() map[BloodTypeCode]string {
return map[BloodTypeCode]string{
BTCAPositive: "A Positive",
BTCANegative: "A Negative",
BTCABPositive: "AB Positive",
BTCABNegative: "AB Negative",
BTCBPositive: "B Positive",
BTCBNegative: "B Negative",
BTCOPositive: "O Positive",
BTCONegative: "O Negative",
}
}
func GetMaritalStatusCodes() map[MaritalStatusCode]string {
return map[MaritalStatusCode]string{
MSCBelumKawin: "Belum Kawin",
MSCKawin: "Kawin",
MSCCeraiHidup: "Cerai Hidup",
MSCCeraiMati: "Cerai Mati",
}
}
func GetReligionCodes() map[ReligionCode]string {
return map[ReligionCode]string{
RCIslam: "Islam",
RCProtestan: "Kristen (Protestan)",
RCKatolik: "Katolik",
RCHindu: "Hindu",
RCBudha: "Budha",
RCKonghucu: "Konghucu",
RCPenghayat: "Penghayat",
}
}
func GetEducationCodes() map[EducationCode]string {
return map[EducationCode]string{
ECTidakSekolah: "Tidak Sekolah",
ECTK: "TK",
ECSD: "SD",
ECSLTP: "SMP sederajat",
ECSLTA: "SMP sederajat",
ECD1: "D1 sederajat",
ECD2: "D2 sederajat",
ECD3: "D3 sederajat",
ECD4: "D4 sederajat",
ECS1: "S1",
ECS2: "S3",
ECS3: "S3",
}
}
func GetProfessions() map[ProfessionCode]string {
return map[ProfessionCode]string{
PCTidakBekerja: "Tidak Bekerja",
PCPns: "PNS",
PCTniPolri: "TNI/POLRI",
PCBumn: "BUMN",
PCWiraswasta: "Pegawai Swasta / Wirausaha",
PCLainlain: "Lain-lain",
}
}
func GetAgeGroupCodes() map[AgeGroupCode]string {
return map[AgeGroupCode]string{
AGCEUnknown: "unknown",
AGCLTE5: "<=5",
AGCEU19: "6-19",
AGCEU29: "20-29",
AGCEU39: "30-39",
AGCEU49: "40-49",
AGCEU59: "50-59",
AGCGE60: ">=60",
}
}
func GetAgeGroupForMedicineCodes() map[AgeGroupForMedicineCode]string {
return map[AgeGroupForMedicineCode]string{
AGMCNew: "new-born",
AGMCInfant: "infant",
AGMCToddler: "toddler",
AGMCKid: "kid",
AGMCAdult: "adult",
}
}
func GetRelativeCodes() map[RelativeCode]string {
return map[RelativeCode]string{
RCMSuami: "Suami",
RCMIstri: "Istri",
RCMAnak: "Anak",
RCMMenantu: "Menantu",
RCMCucu: "Cucu",
RCMOrangTua: "Orang Tua",
RCMMertua: "Mertua",
RCMAdik: "Adik",
RCMKeponakan: "Keponakan",
RCMKakak: "Kakak",
RCMPaman: "Paman",
RCMBibi: "Bibi",
RCMPamanKakek: "Kakek",
RCMPamanNenek: "Nenek",
}
}
func (obj GenderCode) String() string {
return GetGenderCodes()[obj]
}
func (obj BloodTypeCode) String() string {
return GetBloodTypeCodes()[obj]
}
func (obj MaritalStatusCode) String() string {
return GetMaritalStatusCodes()[obj]
}
func (obj ReligionCode) String() string {
return GetReligionCodes()[obj]
}
func (obj EducationCode) String() string {
return GetEducationCodes()[obj]
}
func (obj ProfessionCode) String() string {
return GetProfessions()[obj]
}
func (obj AgeGroupCode) String() string {
return GetAgeGroupCodes()[obj]
}
func (obj RelativeCode) String() string {
return GetRelativeCodes()[obj]
}
@@ -0,0 +1,3 @@
package queue
const QueueName = "SABBI-QUEUE-"
+31
View File
@@ -0,0 +1,31 @@
package xtime
type (
DayCode byte
)
const (
DCMinggu DayCode = iota
DCSenin
DCSelasa
DCRabu
DCKamis
DCJumat
DCSabtu
)
func GetDayCodes() map[DayCode]string {
return map[DayCode]string{
DCMinggu: "Minggu",
DCSenin: "Senin",
DCSelasa: "Selasa",
DCRabu: "Rabu",
DCKamis: "Kamis",
DCJumat: "Jumat",
DCSabtu: "Sabtu",
}
}
func (obj DayCode) String() string {
return GetDayCodes()[obj]
}
@@ -0,0 +1,19 @@
package gormsetting
import (
dg "github.com/karincake/apem/db-gorm-pg"
// "gorm.io/gorm"
"gorm.io/gorm"
"gorm.io/gorm/schema"
)
func Adjust() {
dg.GormConfig = &gorm.Config{
// Logger: logger.Default.LogMode(logger.Error),
NamingStrategy: schema.NamingStrategy{
SingularTable: true,
NoLowerCase: true,
},
}
}
+36
View File
@@ -0,0 +1,36 @@
package ssdb
import (
"log"
a "github.com/karincake/apem"
lo "github.com/karincake/apem/loggero"
"gorm.io/driver/postgres"
"gorm.io/gorm"
"gorm.io/gorm/schema"
)
func Init() {
SetConfig()
NewInstance()
}
func SetConfig() {
a.ParseSingleCfg(&Cfg)
}
func NewInstance() {
// create database connection
db, err := gorm.Open(postgres.Open(Cfg.Dsn), &gorm.Config{
NamingStrategy: schema.NamingStrategy{
SingularTable: true,
NoLowerCase: true,
},
})
if err != nil {
log.Fatal(err)
}
SSDb = db
lo.I.Println("Instantiation for satu-sehat database-connetion using db-gorm-pg, status: DONE!!")
}
+13
View File
@@ -0,0 +1,13 @@
package ssdb
import "gorm.io/gorm"
type SsDbCfg struct {
Dsn string
MaxOpenConns int `yaml:"maxOpenConns"`
MaxIdleConns int `yaml:"maxIdleConns"`
MaxIdleTime int `yaml:"maxIdleTime"`
}
var Cfg SsDbCfg = SsDbCfg{}
var SSDb *gorm.DB
@@ -3,7 +3,14 @@ package handler
import (
"net/http"
///// PKG
/******************** external ********************/
a "github.com/karincake/apem"
/******************** infra ********************/
gs "simrs-vx/internal/infra/gorm-setting"
ssdb "simrs-vx/internal/infra/ss-db"
/******************** pkg ********************/
handlerlogger "simrs-vx/pkg/middleware/handler-logger"
///// Internal
@@ -13,7 +20,8 @@ import (
// One place route to relatively easier to manage, ESPECIALLY in tracking
func SetRoutes() http.Handler {
/////
// a.RegisterExtCall(gs.Adjust)
a.RegisterExtCall(gs.Adjust)
a.RegisterExtCall(ssdb.Init)
r := http.NewServeMux()
+53 -73
View File
@@ -1,93 +1,73 @@
package migration
import (
"flag"
"fmt"
"log"
"io"
"os"
"reflect"
"os/exec"
eu "simrs-vx/internal/domain/main-entities/user"
"gopkg.in/yaml.v3"
"gorm.io/driver/postgres"
"ariga.io/atlas-provider-gorm/gormschema"
"gorm.io/gorm"
"gorm.io/gorm/schema"
)
type DbConf struct {
Dsn string
Dialect string
type Config struct {
DbCfg DbConf `yaml:"dbCfg"`
}
// Migrate all tables at once, one time only for exam purpose
func Migrate() {
// use default config file location or use flat
cfgFile := "./config.yml"
flag.StringVar(&cfgFile, "config-file", "./config.yml", "Configuration path (default=./config.yaml)")
flag.Parse()
type DbConf struct {
DSN string `yaml:"dsn"`
MaxOpenConns int `yaml:"maxOpenConns"`
MaxIdleConns int `yaml:"maxIdleConns"`
MaxIdleTime int `yaml:"maxIdleTime"`
}
// read the config file
yamlFile, err := os.ReadFile(cfgFile)
if err != nil {
log.Fatalf("%v", err)
}
// parse into config struct
var dbConf DbConf
err = yaml.Unmarshal(yamlFile, &dbConf)
if err != nil {
log.Fatal(err)
}
log.Print("config is loaded successfully")
// create database connection
db, err := gorm.Open(postgres.Open(dbConf.Dsn), &gorm.Config{
func Loader() {
gormCfg := &gorm.Config{
NamingStrategy: schema.NamingStrategy{
SingularTable: true,
NoLowerCase: true,
},
})
}
stmts, err := gormschema.New("postgres", gormschema.WithConfig(gormCfg)).Load(GetEntities()...)
if err != nil {
log.Fatal(err)
fmt.Fprintf(os.Stderr, "failed to load gorm schema: %v\n", err)
os.Exit(1)
}
log.Print("database-connection is established successfully")
// migrate all the tables
modelList := []any{
// &single.Single{}}, // example
}
argsWithProg := os.Args
if len(argsWithProg) > 1 {
if argsWithProg[1] == "gradually" {
for _, v := range modelList {
name := ""
if t := reflect.TypeOf(v); t.Kind() == reflect.Ptr {
name = "*" + t.Elem().Name()
} else {
name = t.Name()
}
fmt.Println("Migrating ", name)
db.AutoMigrate(v)
}
} else {
for _, v := range modelList {
name := ""
if t := reflect.TypeOf(v); t.Kind() == reflect.Ptr {
name = "*" + t.Elem().Name()
} else {
name = t.Name()
}
if name == argsWithProg[1] {
fmt.Println("Migrating ", name)
db.AutoMigrate(v)
}
}
}
} else {
fmt.Println("Migrating all tables")
db.AutoMigrate(modelList...)
}
log.Printf("migration is complete")
_, _ = io.WriteString(os.Stdout, stmts)
}
func GetEntities() []any {
return []any{
&eu.User{},
}
}
func runAtlas(args ...string) error {
cmd := exec.Command("atlas", args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}
func logMsg(msg string) {
fmt.Fprintln(os.Stderr, msg)
}
func Migrate() {
Loader()
logMsg("Running atlas migrate diff...")
if err := runAtlas("migrate", "diff", "--env", "gorm"); err != nil {
logMsg(fmt.Sprintf("Failed to run diff: %v", err))
return
}
logMsg("Running atlas migrate apply...")
if err := runAtlas("migrate", "apply", "--env", "gorm"); err != nil {
logMsg(fmt.Sprintf("Failed to run apply: %v", err))
return
}
logMsg("Migration complete")
}
@@ -23,7 +23,7 @@ const source = "crud"
func Create(input e.Createdto) (*d.Data, error) {
data := e.Single{}
setData(&data, &input)
setData(input, &data)
event := pl.Event{
Feature: "Create",
@@ -47,7 +47,7 @@ func Create(input e.Createdto) (*d.Data, error) {
event.ErrInfo = pl.ErrorInfo{
Code: "MW_PRE_FAILED", // TODO: add to lang json
Detail: fmt.Sprintf("Pre-middleware %s failed", mwName),
Raw: mwErr,
Raw: err,
}
return pl.SetLogError(event, data)
}
@@ -59,7 +59,8 @@ func Create(input e.Createdto) (*d.Data, error) {
event.Action = "DBCreate"
event.Status = "started"
pl.SetLogInfo(event, data)
if result, err := CreateData(&data, tx).Error; err != nil {
result, err := CreateData(&data, tx)
if err != nil {
event.Status = "failed"
event.ErrInfo = pl.ErrorInfo{
Code: "data-create-fail",
@@ -83,7 +84,7 @@ func Create(input e.Createdto) (*d.Data, error) {
event.ErrInfo = pl.ErrorInfo{
Code: "MW_POST_FAILED", // TODO: add to lang json
Detail: fmt.Sprintf("Post-middleware %s failed", mwName),
Raw: mwErr,
Raw: err,
}
return pl.SetLogError(event, data)
}
@@ -5,7 +5,7 @@ Any functions that are used internally by the use-case
package crud
import (
e "simrs-vx/internal/domain/main-entities/single"
e "simrs-vx/internal/domain/_template/single"
)
func setData(src e.Createdto, dst *e.Single) {
@@ -16,7 +16,7 @@ func CreateData(input *e.Single, dbx ...*gorm.DB) (*e.Single, error) {
tx = dg.I
}
if err := tx.Create(&data).Error; err != nil {
if err := tx.Create(&input).Error; err != nil {
return nil, err
}
@@ -14,7 +14,7 @@ import (
e "simrs-vx/internal/domain/main-entities/single"
)
type createMw func(input *e.Createdto, data *e.Single, tx *gorm.DB) error
type createMw func(input *e.CreateDto, data *e.Single, tx *gorm.DB) error
type readListMw func(input *e.ReadListDto, data *e.Single, tx *gorm.DB) error
type readDetailMw func(input *e.ReadDetailDto, data *e.Single, tx *gorm.DB) error
type updateMw func(input *e.ReadDetailDto, data *e.Single, tx *gorm.DB) error
@@ -0,0 +1,106 @@
package user
import (
"fmt"
e "simrs-vx/internal/domain/main-entities/user"
dg "github.com/karincake/apem/db-gorm-pg"
d "github.com/karincake/dodol"
pl "simrs-vx/pkg/logger"
"gorm.io/gorm"
)
const source = "user"
func Create(input e.CreateDto) (*d.Data, error) {
data := e.User{}
setData(input, &data)
event := pl.Event{
Feature: "Create",
Source: source,
}
// Start log
event.Action = "Create"
event.Status = "started"
pl.SetLogInfo(event, input)
err := dg.I.Transaction(func(tx *gorm.DB) error {
for i := range createPreMw {
mwName := fmt.Sprintf("createPreMw[%d]", i)
event.Action = mwName
event.Status = "started"
pl.SetLogInfo(event, data)
if err := createPreMw[i](&input, &data, tx); err != nil {
event.Status = "failed"
event.ErrInfo = pl.ErrorInfo{
Code: "MW_PRE_FAILED", // TODO: add to lang json
Detail: fmt.Sprintf("Pre-middleware %s failed", mwName),
Raw: err,
}
return pl.SetLogError(event, data)
}
event.Status = "completed"
pl.SetLogInfo(event, nil)
}
event.Action = "DBCreate"
event.Status = "started"
pl.SetLogInfo(event, data)
_, err := CreateData(&data, tx)
if err != nil {
event.Status = "failed"
event.ErrInfo = pl.ErrorInfo{
Code: "data-create-fail",
Detail: "Database insert failed",
Raw: err,
}
return pl.SetLogError(event, data)
}
event.Status = "completed"
pl.SetLogInfo(event, nil)
for i := range createPostMw {
mwName := fmt.Sprintf("createPostMw[%d]", i)
event.Action = mwName
event.Status = "started"
pl.SetLogInfo(event, input)
if err := createPostMw[i](&input, &data, tx); err != nil {
event.Status = "failed"
event.ErrInfo = pl.ErrorInfo{
Code: "MW_POST_FAILED", // TODO: add to lang json
Detail: fmt.Sprintf("Post-middleware %s failed", mwName),
Raw: err,
}
return pl.SetLogError(event, data)
}
}
event.Status = "completed"
pl.SetLogInfo(event, nil)
return nil
})
if err != nil {
return nil, err
}
return &d.Data{
Meta: d.II{
"source": source,
"type": "list",
"status": "created",
},
Data: data,
}, nil
}
@@ -0,0 +1,24 @@
/*
DESCRIPTION:
Any functions that are used internally by the use-case
*/
package user
import (
e "simrs-vx/internal/domain/main-entities/user"
p "simrs-vx/pkg/password"
)
func setData(src e.CreateDto, dst *e.User) error {
pass, err := p.Hash(src.Password)
if err != nil {
return err
}
dst.Name = src.Name
dst.Password = pass
dst.Status_Code = src.Status_Code
return nil
}
+101
View File
@@ -0,0 +1,101 @@
package user
import (
e "simrs-vx/internal/domain/main-entities/user"
dg "github.com/karincake/apem/db-gorm-pg"
gh "github.com/karincake/getuk"
"gorm.io/gorm"
)
func CreateData(input *e.User, dbx ...*gorm.DB) (*e.User, error) {
var tx *gorm.DB
if len(dbx) > 0 {
tx = dbx[0]
} else {
tx = dg.I
}
if err := tx.Create(&input).Error; err != nil {
return nil, err
}
return input, nil
}
func ReadListData(input e.ReadListDto, dbx ...*gorm.DB) ([]e.User, *e.MetaDto, error) {
data := []e.User{}
pagination := gh.Pagination{}
count := int64(0)
meta := e.MetaDto{}
var tx *gorm.DB
if len(dbx) > 0 {
tx = dbx[0]
} else {
tx = dg.I
}
tx = tx.
Model(&e.User{}).
// Joins("Patient"). // if needed
// Preload("Patient"). // if needed
Scopes(gh.Filter(input)).
Count(&count).
Scopes(gh.Paginate(input, &pagination)).
Order("CreatedAt DESC")
if err := tx.Find(&data).Error; err != nil {
if err == gorm.ErrRecordNotFound {
return nil, &meta, nil
}
return nil, nil, err
}
meta.Count = count
meta.PageNumber = pagination.PageNumber
meta.PageSize = pagination.PageSize
return data, &meta, nil
}
func ReadDetailData(input e.ReadDetailDto, dbx ...*gorm.DB) (*e.User, error) {
data := e.User{}
var tx *gorm.DB
if len(dbx) > 0 {
tx = dbx[0]
} else {
tx = dg.I
}
if err := tx.First(&data, input.Id).Error; err != nil {
if err == gorm.ErrRecordNotFound {
return nil, nil
}
return nil, err
}
return &data, nil
}
func UpdateData(input e.User, dbx ...*gorm.DB) error {
var tx *gorm.DB
if len(dbx) > 0 {
tx = dbx[0]
} else {
tx = dg.I
}
return tx.Save(&input).Error
}
func DeleteData(input *e.User, dbx ...*gorm.DB) error {
var tx *gorm.DB
if len(dbx) > 0 {
tx = dbx[0]
} else {
tx = dg.I
}
return tx.Delete(input).Error
}
@@ -0,0 +1,32 @@
/*
DESCRIPTION:
A sample, part of the package that contains type, constants, and/or variables.
In this sample it also provides type and variable regarding the needs of the
middleware to separate from main use-case which has the basic CRUD
functionality. The purpose of this is to make the code more maintainable.
*/
package user
import (
"gorm.io/gorm"
e "simrs-vx/internal/domain/main-entities/user"
)
type createMw func(input *e.CreateDto, data *e.User, tx *gorm.DB) error
type readListMw func(input *e.ReadListDto, data *e.User, tx *gorm.DB) error
type readDetailMw func(input *e.ReadDetailDto, data *e.User, tx *gorm.DB) error
type updateMw func(input *e.ReadDetailDto, data *e.User, tx *gorm.DB) error
type deleteMw func(input *e.ReadDetailDto, data *e.User, tx *gorm.DB) error
var createPreMw []createMw // preprocess middleware
var createPostMw []createMw // postprocess middleware
var readListPreMw []readListMw // ..
var readListPostMw []readListMw // ..
var readDetailPreMw []readDetailMw
var readDetailPostMw []readDetailMw
var udpatePreMw []readDetailMw
var udpatePostMw []readDetailMw
var deletePreMw []readDetailMw
var deletePostMw []readDetailMw
+17
View File
@@ -0,0 +1,17 @@
package password
import (
"golang.org/x/crypto/bcrypt"
)
var Cost = 10 // can be set by consumer
func Hash(password string) (string, error) {
bytes, err := bcrypt.GenerateFromPassword([]byte(password), Cost)
return string(bytes), err
}
func Check(password, hash string) bool {
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
return err == nil
}