commit doble databse
This commit is contained in:
24
Dockerfile
24
Dockerfile
@@ -1,42 +1,26 @@
|
||||
FROM golang:1.23 AS builder
|
||||
# Install curl dan Tailwind dependencies
|
||||
RUN apt-get update && apt-get install -y curl ca-certificates
|
||||
FROM golang:1.23-alpine AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy go.mod dan go.sum untuk dependency management
|
||||
COPY go.mod go.sum ./
|
||||
|
||||
RUN go mod download
|
||||
RUN go mod tidy
|
||||
|
||||
# Copy seluruh project
|
||||
COPY . .
|
||||
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main ./cmd/api
|
||||
|
||||
# Install Tailwind CSS untuk generate output.css
|
||||
RUN go install github.com/a-h/templ/cmd/templ@latest && \
|
||||
templ generate && \
|
||||
curl -sL https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-linux-x64 -o tailwindcss && \
|
||||
chmod +x tailwindcss && \
|
||||
./tailwindcss -i cmd/web/assets/css/input.css -o cmd/web/assets/css/output.css
|
||||
# RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .
|
||||
|
||||
FROM alpine:latest
|
||||
|
||||
# Set timezone ke Asia/Jakarta
|
||||
ENV TZ=Asia/Jakarta
|
||||
|
||||
# Install dependensi runtime yang diperlukan
|
||||
RUN apk --no-cache add ca-certificates tzdata
|
||||
|
||||
WORKDIR /root/
|
||||
|
||||
# Copy binary yang sudah ter-build dari stage sebelumnya
|
||||
COPY --from=builder /app/main .
|
||||
COPY --from=builder /app/.env .
|
||||
|
||||
# Expose port aplikasi
|
||||
EXPOSE 8803
|
||||
|
||||
# Jalankan aplikasi
|
||||
EXPOSE 8080
|
||||
CMD ["./main"]
|
||||
@@ -7,9 +7,8 @@ import (
|
||||
"net/http"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"template_blueprint/internal/server"
|
||||
"time"
|
||||
)
|
||||
|
||||
func gracefulShutdown(apiServer *http.Server, done chan bool) {
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
@@ -1,30 +0,0 @@
|
||||
/*! tailwindcss v4.0.13 | MIT License | https://tailwindcss.com */
|
||||
.container {
|
||||
width: 100%;
|
||||
}
|
||||
.mx-auto {
|
||||
margin-inline: auto;
|
||||
}
|
||||
.block {
|
||||
display: block;
|
||||
}
|
||||
.h-screen {
|
||||
height: 100vh;
|
||||
}
|
||||
.resize {
|
||||
resize: both;
|
||||
}
|
||||
.border {
|
||||
border-style: var(--tw-border-style);
|
||||
border-width: 1px;
|
||||
}
|
||||
.transition {
|
||||
transition-property: color, background-color, border-color, outline-color, text-decoration-color, fill, stroke, --tw-gradient-from, --tw-gradient-via, --tw-gradient-to, opacity, box-shadow, transform, translate, scale, rotate, filter, -webkit-backdrop-filter, backdrop-filter;
|
||||
transition-timing-function: var(--tw-ease, ease);
|
||||
transition-duration: var(--tw-duration, 0s);
|
||||
}
|
||||
@property --tw-border-style {
|
||||
syntax: "*";
|
||||
inherits: false;
|
||||
initial-value: solid;
|
||||
}
|
||||
3476
cmd/web/assets/js/htmx.min.js
vendored
3476
cmd/web/assets/js/htmx.min.js
vendored
File diff suppressed because it is too large
Load Diff
@@ -1,18 +0,0 @@
|
||||
package web
|
||||
|
||||
templ Base() {
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" class="h-screen">
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<title>Go Blueprint Hello</title>
|
||||
<link href="assets/css/output.css" rel="stylesheet"/>
|
||||
<script src="assets/js/htmx.min.js"></script>
|
||||
</head>
|
||||
<body class="bg-gray-100">
|
||||
<main class="max-w-sm mx-auto p-4">
|
||||
{ children... }
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
package web
|
||||
|
||||
import "embed"
|
||||
|
||||
//go:embed "assets"
|
||||
var Files embed.FS
|
||||
@@ -1,21 +0,0 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func HelloWebHandler(w http.ResponseWriter, r *http.Request) {
|
||||
err := r.ParseForm()
|
||||
if err != nil {
|
||||
http.Error(w, "Bad Request", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
name := r.FormValue("name")
|
||||
component := HelloPost(name)
|
||||
err = component.Render(r.Context(), w)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
log.Fatalf("Error rendering in HelloWebHandler: %e", err)
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package web
|
||||
|
||||
templ HelloForm() {
|
||||
@Base() {
|
||||
<form hx-post="/hello" method="POST" hx-target="#hello-container">
|
||||
<input class="bg-gray-200 text-black p-2 border border-gray-400 rounded-lg"id="name" name="name" type="text"/>
|
||||
<button type="submit" class="bg-orange-500 hover:bg-orange-700 text-white py-2 px-4 rounded">Submit</button>
|
||||
</form>
|
||||
<div id="hello-container"></div>
|
||||
}
|
||||
}
|
||||
|
||||
templ HelloPost(name string) {
|
||||
<div class="bg-green-100 p-4 shadow-md rounded-lg mt-6">
|
||||
<p>Hello, { name }</p>
|
||||
</div>
|
||||
}
|
||||
@@ -3,14 +3,33 @@ services:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
container_name: api-keuangan
|
||||
restart: always
|
||||
ports:
|
||||
- 8803:8803
|
||||
- 8080:8080
|
||||
volumes:
|
||||
- .:/app
|
||||
- /etc/localtime:/etc/localtime:ro
|
||||
- /etc/timezone:/etc/timezone:ro
|
||||
environment:
|
||||
TZ: Asia/Jakarta
|
||||
MONGODB_DEV_HOST: 10.10.123.206
|
||||
MONGODB_DEV_PORT: 27017
|
||||
MONGODB_DEV_USER: admin
|
||||
MONGODB_DEV_PASS: stim*rs54
|
||||
MONGODB_DEV_MASTER: master
|
||||
MONGODB_DEV_LOCAL: local
|
||||
# TIMEZONE
|
||||
- TZ=Asia/Jakarta
|
||||
# DATABASE SIMRS V3.0
|
||||
- SIMRS_STAG_HOST=10.10.123.223
|
||||
- SIMRS_STAG_PORT=5432
|
||||
- SIMRS_STAG_NAME=simrs-stag
|
||||
- SIMRS_STAG_USER=simtest
|
||||
- SIMRS_STAG_PASS=12345
|
||||
# DATABASE SATU DATA
|
||||
- SATUDATA_HOST=10.10.123.165
|
||||
- SATUDATA_USER=stim
|
||||
- SATUDATA_PASS=stim*RS54
|
||||
- SATUDATA_NAME=satu_db
|
||||
- SATUDATA_PORT=5000
|
||||
# MONGODB DEV
|
||||
- MONGODB_DEV_HOST=10.10.123.206
|
||||
- MONGODB_DEV_PORT=27017
|
||||
- MONGODB_DEV_USER=admin
|
||||
- MONGODB_DEV_PASS=stim*rs54
|
||||
- MONGODB_DEV_MASTER=master
|
||||
- MONGODB_DEV_LOCAL=local
|
||||
27
docker-push.sh
Normal file
27
docker-push.sh
Normal file
@@ -0,0 +1,27 @@
|
||||
!/bin/bash
|
||||
|
||||
#get image name
|
||||
remote_url=$(git remote get-url origin)
|
||||
image=$(echo $remote_url | sed 's|https://||g; s|.git||g')
|
||||
|
||||
#get branch name
|
||||
branch_name=$(git rev-parse --abbrev-ref HEAD)
|
||||
clean_branch_name=${branch_name##*/}
|
||||
|
||||
#get timestamp for the tag
|
||||
timestamp=$(date +%Y%m%d%H%M%S)
|
||||
|
||||
tag=$image:$timestamp-$clean_branch_name
|
||||
latest=$image:latest-$clean_branch_name
|
||||
|
||||
#build image
|
||||
docker build -t $tag .
|
||||
docker tag $tag $latest
|
||||
|
||||
#push to dockerhub
|
||||
docker login git.rssa.top -u stim -p 4fde63b07906e7bfa6b3493d76d153a3981039b9
|
||||
docker push $tag
|
||||
docker push $latest
|
||||
|
||||
#remove dangling images
|
||||
docker system prune -f
|
||||
17
go.mod
17
go.mod
@@ -3,14 +3,16 @@ module template_blueprint
|
||||
go 1.23.1
|
||||
|
||||
require (
|
||||
github.com/a-h/templ v0.3.833
|
||||
github.com/coder/websocket v1.8.12
|
||||
github.com/gin-contrib/cors v1.7.4
|
||||
github.com/gin-gonic/gin v1.10.0
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/jackc/pgx/v5 v5.7.5
|
||||
github.com/joho/godotenv v1.5.1
|
||||
github.com/testcontainers/testcontainers-go/modules/mongodb v0.35.0
|
||||
go.mongodb.org/mongo-driver v1.17.3
|
||||
gorm.io/driver/postgres v1.5.11
|
||||
gorm.io/gorm v1.30.0
|
||||
)
|
||||
|
||||
require (
|
||||
@@ -42,6 +44,11 @@ require (
|
||||
github.com/goccy/go-json v0.10.5 // indirect
|
||||
github.com/gogo/protobuf v1.3.2 // indirect
|
||||
github.com/golang/snappy v0.0.4 // indirect
|
||||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
||||
github.com/jackc/puddle/v2 v2.2.2 // indirect
|
||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||
github.com/jinzhu/now v1.1.5 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/klauspost/compress v1.17.4 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.2.10 // indirect
|
||||
@@ -83,11 +90,11 @@ require (
|
||||
go.opentelemetry.io/otel/metric v1.24.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.24.0 // indirect
|
||||
golang.org/x/arch v0.15.0 // indirect
|
||||
golang.org/x/crypto v0.36.0 // indirect
|
||||
golang.org/x/crypto v0.38.0 // indirect
|
||||
golang.org/x/net v0.37.0 // indirect
|
||||
golang.org/x/sync v0.12.0 // indirect
|
||||
golang.org/x/sys v0.31.0 // indirect
|
||||
golang.org/x/text v0.23.0 // indirect
|
||||
golang.org/x/sync v0.14.0 // indirect
|
||||
golang.org/x/sys v0.33.0 // indirect
|
||||
golang.org/x/text v0.25.0 // indirect
|
||||
google.golang.org/protobuf v1.36.5 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
||||
38
go.sum
38
go.sum
@@ -6,8 +6,6 @@ github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOEl
|
||||
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
|
||||
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
|
||||
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
|
||||
github.com/a-h/templ v0.3.833 h1:L/KOk/0VvVTBegtE0fp2RJQiBm7/52Zxv5fqlEHiQUU=
|
||||
github.com/a-h/templ v0.3.833/go.mod h1:cAu4AiZhtJfBjMY0HASlyzvkrtjnHWPeEsyGK2YYmfk=
|
||||
github.com/bytedance/sonic v1.12.10 h1:uVCQr6oS5669E9ZVW0HyksTLfNS7Q/9hV6IVS4nEMsI=
|
||||
github.com/bytedance/sonic v1.12.10/go.mod h1:uVvFidNmlt9+wa31S1urfwwthTWteBgG0hWuoKAXTx8=
|
||||
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
|
||||
@@ -81,6 +79,18 @@ 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/grpc-ecosystem/grpc-gateway/v2 v2.16.0 h1:YBftPWNWd4WwGqtY2yeZL2ef8rHAxPBD8KFhJpmcqms=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0/go.mod h1:YN5jB8ie0yfIUg6VvR9Kz84aCaG7AsGZnLjhHbUqwPg=
|
||||
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-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
|
||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
|
||||
github.com/jackc/pgx/v5 v5.7.5 h1:JHGfMnQY+IEtGM63d+NGMjoRpysB2JBwDr5fsngwmJs=
|
||||
github.com/jackc/pgx/v5 v5.7.5/go.mod h1:aruU7o91Tc2q2cFp5h4uP3f6ztExVpyVv88Xl/8Vl8M=
|
||||
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
|
||||
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
|
||||
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/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
@@ -208,8 +218,8 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34=
|
||||
golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=
|
||||
golang.org/x/crypto v0.38.0 h1:jt+WWG8IZlBnVbomuhg2Mdq0+BBQaHbtqHEFEigjUV8=
|
||||
golang.org/x/crypto v0.38.0/go.mod h1:MvrbAqul58NNYPKnOra203SB9vpuZW0e+RRZV+Ggqjw=
|
||||
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
@@ -225,8 +235,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
|
||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/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.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw=
|
||||
golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
|
||||
golang.org/x/sync v0.14.0 h1:woo0S4Yywslg6hp4eUFjTVOyKt0RookbpAHG4c1HmhQ=
|
||||
golang.org/x/sync v0.14.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-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
@@ -242,18 +252,18 @@ 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.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
|
||||
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
|
||||
golang.org/x/sys v0.33.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.30.0 h1:PQ39fJZ+mfadBm0y5WlL4vlM7Sx1Hgf13sMIY2+QS9Y=
|
||||
golang.org/x/term v0.30.0/go.mod h1:NYYFdzHoI5wRh/h5tDMdMqCqPJZEuNqVR5xJLd/n67g=
|
||||
golang.org/x/term v0.32.0 h1:DR4lr0TjUs3epypdhTOkMmuF5CDFJ/8pOnbzMZPQ7bg=
|
||||
golang.org/x/term v0.32.0/go.mod h1:uZG1FhGx848Sqfsq4/DlJr3xGGsYMu/L5GW4abiaEPQ=
|
||||
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.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
|
||||
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
|
||||
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
|
||||
golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4=
|
||||
golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA=
|
||||
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 h1:vVKdlvoWBphwdxWKrFZEuM0kGgGLxUOYcY4U/2Vjg44=
|
||||
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
@@ -280,6 +290,10 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EV
|
||||
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.11 h1:ubBVAfbKEUld/twyKZ0IYn9rSQh448EdelLYk9Mv314=
|
||||
gorm.io/driver/postgres v1.5.11/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI=
|
||||
gorm.io/gorm v1.30.0 h1:qbT5aPv1UH8gI99OsRlvDToLxW5zR7FzS9acZDOZcgs=
|
||||
gorm.io/gorm v1.30.0/go.mod h1:8Z33v652h4//uMA76KjeDH8mJXPm1QNCYrMeatR0DOE=
|
||||
gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU=
|
||||
gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU=
|
||||
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
|
||||
|
||||
@@ -3,38 +3,100 @@ package database
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"go.mongodb.org/mongo-driver/mongo/readpref"
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
_ "github.com/jackc/pgx/v5/stdlib"
|
||||
_ "github.com/joho/godotenv/autoload"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
"go.mongodb.org/mongo-driver/mongo/readpref"
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/gorm"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Service represents a service that interacts with a database.
|
||||
type Service interface {
|
||||
Health() map[string]string
|
||||
GetDB() *mongo.Database
|
||||
Close() error
|
||||
GetDB(database string) *gorm.DB
|
||||
GetMongoDB() *mongo.Database
|
||||
}
|
||||
|
||||
type service struct {
|
||||
simrsDB *gorm.DB
|
||||
satuDataDB *gorm.DB
|
||||
client *mongo.Client
|
||||
db *mongo.Database
|
||||
mongoDB *mongo.Database
|
||||
}
|
||||
|
||||
var (
|
||||
host = os.Getenv("MONGODB_DEV_HOST")
|
||||
port = os.Getenv("MONGODB_DEV_PORT")
|
||||
user = os.Getenv("MONGODB_DEV_USER")
|
||||
pass = os.Getenv("MONGODB_DEV_PASS")
|
||||
hostSimrs = os.Getenv("SIMRS_STAG_HOST")
|
||||
userNameSimrs = os.Getenv("SIMRS_STAG_USER")
|
||||
passwordSimrs = os.Getenv("SIMRS_STAG_PASS")
|
||||
dbNameSimrs = os.Getenv("SIMRS_STAG_NAME")
|
||||
portSimrs = os.Getenv("SIMRS_STAG_PORT")
|
||||
|
||||
hostSatudata = os.Getenv("SATUDATA_HOST")
|
||||
userNameSatudata = os.Getenv("SATUDATA_USER")
|
||||
passwordSatudata = os.Getenv("SATUDATA_PASS")
|
||||
dbNameSatudata = os.Getenv("SATUDATA_NAME")
|
||||
portSatudata = os.Getenv("SATUDATA_PORT")
|
||||
|
||||
hostMongo = os.Getenv("MONGODB_DEV_HOST")
|
||||
portMongo = os.Getenv("MONGODB_DEV_PORT")
|
||||
userMongo = os.Getenv("MONGODB_DEV_USER")
|
||||
passMongo = os.Getenv("MONGODB_DEV_PASS")
|
||||
dbInstance *service
|
||||
)
|
||||
|
||||
func New(database string) Service {
|
||||
func New(database ...string) Service {
|
||||
mongoDBName := os.Getenv("MONGODB_DEV_MASTER")
|
||||
if len(database) > 0 {
|
||||
mongoDBName = database[0]
|
||||
}
|
||||
if dbInstance != nil {
|
||||
if database != nil {
|
||||
mongoURI := fmt.Sprintf("mongodb://%s:%s@%s:%s/%s?authSource=admin",
|
||||
user, pass, host, port, database)
|
||||
userMongo, passMongo, hostMongo, portMongo, mongoDBName)
|
||||
log.Println("Connecting to MongoDB...")
|
||||
log.Println(mongoURI)
|
||||
clientOptions := options.Client().ApplyURI(mongoURI)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
client, err := mongo.Connect(ctx, clientOptions)
|
||||
if err == nil {
|
||||
log.Println("Connected to MongoDB")
|
||||
}
|
||||
if err = client.Ping(ctx, readpref.Primary()); err != nil {
|
||||
log.Println("Failed to connect to MongoDB!!!")
|
||||
log.Fatalf("Failed to connect to database: %v", err)
|
||||
}
|
||||
dbInstance.mongoDB = client.Database(mongoDBName)
|
||||
}
|
||||
return dbInstance
|
||||
}
|
||||
simrs := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%s sslmode=disable TimeZone=Asia/Jakarta", hostSimrs, userNameSimrs, passwordSimrs, dbNameSimrs, portSimrs)
|
||||
|
||||
SimrsDB, err := gorm.Open(postgres.Open(simrs), &gorm.Config{})
|
||||
if err != nil {
|
||||
log.Fatal("Failed to connect to SIM database: ", err)
|
||||
} else {
|
||||
log.Println("Successfully connected to the database")
|
||||
}
|
||||
satudata := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%s sslmode=disable TimeZone=Asia/Jakarta", hostSatudata, userNameSatudata, passwordSatudata, dbNameSatudata, portSatudata)
|
||||
|
||||
SatudataDB, err := gorm.Open(postgres.Open(satudata), &gorm.Config{})
|
||||
if err != nil {
|
||||
log.Fatal("Failed to connect to SIM database: ", err)
|
||||
} else {
|
||||
log.Println("Successfully connected to the database")
|
||||
}
|
||||
mongoURI := fmt.Sprintf("mongodb://%s:%s@%s:%s/%s?authSource=admin",
|
||||
userMongo, passMongo, hostMongo, portMongo, database)
|
||||
var client *mongo.Client
|
||||
var err error
|
||||
log.Println("Connecting to MongoDB...")
|
||||
log.Println(mongoURI)
|
||||
clientOptions := options.Client().ApplyURI(mongoURI)
|
||||
@@ -63,31 +125,104 @@ func New(database string) Service {
|
||||
}
|
||||
|
||||
log.Println("Successfully connected to MongoDB!")
|
||||
|
||||
return &service{
|
||||
client: client,
|
||||
db: client.Database(database),
|
||||
dbInstance = &service{
|
||||
simrsDB: SimrsDB,
|
||||
satuDataDB: SatudataDB,
|
||||
mongoDB: client.Database(mongoDBName),
|
||||
}
|
||||
return dbInstance
|
||||
}
|
||||
|
||||
// Health checks the health of the database connection by pinging the database.
|
||||
// It returns a map with keys indicating various health statistics.
|
||||
func (s *service) Health() map[string]string {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
status := map[string]string{
|
||||
"status": "up",
|
||||
"message": "MongoDB connection is healthy",
|
||||
stats := make(map[string]string)
|
||||
|
||||
// Ping the database using GORM
|
||||
db, err := s.simrsDB.DB() // Retrieve the underlying sql.DB instance from GORM
|
||||
if err != nil {
|
||||
stats["status"] = "down"
|
||||
stats["error"] = fmt.Sprintf("failed to get sql.DB from GORM: %v", err)
|
||||
log.Fatalf("failed to get sql.DB from GORM: %v", err) // Log the error and terminate the program
|
||||
return stats
|
||||
}
|
||||
|
||||
if err := s.client.Ping(ctx, nil); err != nil {
|
||||
status["status"] = "down"
|
||||
status["error"] = err.Error()
|
||||
status["message"] = "Connection to MongoDB failed"
|
||||
err = db.PingContext(ctx)
|
||||
if err != nil {
|
||||
stats["status"] = "down"
|
||||
stats["error"] = fmt.Sprintf("db down: %v", err)
|
||||
log.Fatalf("db down: %v", err) // Log the error and terminate the program
|
||||
return stats
|
||||
}
|
||||
|
||||
return status
|
||||
// Database is up, add more statistics
|
||||
stats["status"] = "up"
|
||||
stats["message"] = "It's healthy"
|
||||
|
||||
// Get database stats
|
||||
dbStats := db.Stats()
|
||||
stats["open_connections"] = strconv.Itoa(dbStats.OpenConnections)
|
||||
stats["in_use"] = strconv.Itoa(dbStats.InUse)
|
||||
stats["idle"] = strconv.Itoa(dbStats.Idle)
|
||||
stats["wait_count"] = strconv.FormatInt(dbStats.WaitCount, 10)
|
||||
stats["wait_duration"] = dbStats.WaitDuration.String()
|
||||
stats["max_idle_closed"] = strconv.FormatInt(dbStats.MaxIdleClosed, 10)
|
||||
stats["max_lifetime_closed"] = strconv.FormatInt(dbStats.MaxLifetimeClosed, 10)
|
||||
|
||||
// Evaluate stats to provide a health message
|
||||
if dbStats.OpenConnections > 40 { // Assuming 50 is the max for this example
|
||||
stats["message"] = "The database is experiencing heavy load."
|
||||
}
|
||||
|
||||
func (s *service) GetDB() *mongo.Database {
|
||||
return s.db
|
||||
if dbStats.WaitCount > 1000 {
|
||||
stats["message"] = "The database has a high number of wait events, indicating potential bottlenecks."
|
||||
}
|
||||
|
||||
if dbStats.MaxIdleClosed > int64(dbStats.OpenConnections)/2 {
|
||||
stats["message"] = "Many idle connections are being closed, consider revising the connection pool settings."
|
||||
}
|
||||
|
||||
if dbStats.MaxLifetimeClosed > int64(dbStats.OpenConnections)/2 {
|
||||
stats["message"] = "Many connections are being closed due to max lifetime, consider increasing max lifetime or revising the connection usage pattern."
|
||||
}
|
||||
|
||||
return stats
|
||||
}
|
||||
|
||||
// Close closes the database connection.
|
||||
// It logs a message indicating the disconnection from the specific database.
|
||||
// If the connection is successfully closed, it returns nil.
|
||||
// If an error occurs while closing the connection, it returns the error.
|
||||
func (s *service) Close() error {
|
||||
db, err := s.simrsDB.DB() // Retrieve the underlying sql.DB instance from GORM
|
||||
if err != nil {
|
||||
log.Printf("Failed to retrieve sql.DB from GORM: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
err = db.Close()
|
||||
if err != nil {
|
||||
log.Printf("Error closing the database connection: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
log.Printf("Disconnected from database successfully")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *service) GetDB(database string) *gorm.DB {
|
||||
if strings.ToLower(database) == "simrs" {
|
||||
return s.simrsDB
|
||||
} else if strings.ToLower(database) == "satudata" {
|
||||
return s.satuDataDB
|
||||
}
|
||||
log.Println("Database tidak ditemukan")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *service) GetMongoDB() *mongo.Database {
|
||||
return s.mongoDB
|
||||
}
|
||||
|
||||
@@ -1,22 +1,14 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"github.com/a-h/templ"
|
||||
"io/fs"
|
||||
"template_blueprint/cmd/web"
|
||||
|
||||
"github.com/coder/websocket"
|
||||
|
||||
"github.com/gin-contrib/cors"
|
||||
patientHandler "template_blueprint/pkg/handlers/patient"
|
||||
"github.com/gin-gonic/gin"
|
||||
"log"
|
||||
"net/http"
|
||||
LoginHandler "template_blueprint/pkg/handlers/login"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (s *Server) RegisterRoutes() http.Handler {
|
||||
@@ -26,23 +18,13 @@ func (s *Server) RegisterRoutes() http.Handler {
|
||||
|
||||
r.GET("/websocket", s.websocketHandler)
|
||||
|
||||
staticFiles, _ := fs.Sub(web.Files, "assets")
|
||||
r.StaticFS("/assets", http.FS(staticFiles))
|
||||
|
||||
r.GET("/web", func(c *gin.Context) {
|
||||
templ.Handler(web.HelloForm()).ServeHTTP(c.Writer, c.Request)
|
||||
})
|
||||
|
||||
r.POST("/hello", func(c *gin.Context) {
|
||||
web.HelloWebHandler(c.Writer, c.Request)
|
||||
})
|
||||
|
||||
api := r.Group("/api")
|
||||
patient := api.Group("/patient")
|
||||
login := api.Group("/login")
|
||||
{
|
||||
patient.POST("/insertpatient", patientHandler.InsertPatient)
|
||||
patient.GET("/getallpatient", patientHandler.GetAllPatient)
|
||||
login.GET("/get", LoginHandler.Getlogin)
|
||||
login.GET("/:id", LoginHandler.GetloginbyID)
|
||||
}
|
||||
|
||||
r.Use(cors.New(cors.Config{
|
||||
AllowOrigins: []string{"*"}, // or specific domains like "http://example.com"
|
||||
AllowMethods: []string{"GET", "POST", "PUT", "DELETE"},
|
||||
|
||||
@@ -5,9 +5,9 @@ import (
|
||||
)
|
||||
|
||||
type DatabaseService struct {
|
||||
DB *mongo.Database
|
||||
DBMongo *mongo.Database
|
||||
}
|
||||
|
||||
func NewDatabaseService(db *mongo.Database) *DatabaseService {
|
||||
return &DatabaseService{DB: db}
|
||||
func NewDatabaseServiceMongo(db *mongo.Database) *DatabaseService {
|
||||
return &DatabaseService{DBMongo: db}
|
||||
}
|
||||
|
||||
52
pkg/database/mongo/login.go
Normal file
52
pkg/database/mongo/login.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package mongo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"log"
|
||||
loginHandler "template_blueprint/pkg/models/login"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (s *DatabaseService) Getlogin() ([]*loginHandler.Menu, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
datalogin, err := s.DBMongo.Collection("role_menu_ex").Find(ctx, bson.D{})
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
var login []*loginHandler.Menu
|
||||
err = datalogin.All(ctx, &login)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return nil, err
|
||||
}
|
||||
return login, nil
|
||||
}
|
||||
|
||||
func (s *DatabaseService) GetByid(id string) (*loginHandler.Menu, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
objectID, err := primitive.ObjectIDFromHex(id)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid ID format: %v", err)
|
||||
}
|
||||
filter := bson.M{
|
||||
"_id": objectID,
|
||||
}
|
||||
|
||||
var result loginHandler.Menu
|
||||
err = s.DBMongo.Collection("role_menu_ex").FindOne(ctx, filter).Decode(&result)
|
||||
if err != nil {
|
||||
if err == mongo.ErrNoDocuments {
|
||||
return nil, fmt.Errorf("ID %s tidak ditemukan", id)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package mongo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"template_blueprint/pkg/models/master_data"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (s *DatabaseService) InsertDataMaster(req master_data.ReqInsertData) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
_, err := s.DB.Collection(req.Table).InsertOne(ctx, master_data.ReqInsertDataMaster{
|
||||
ID: req.ID,
|
||||
System: req.System,
|
||||
Code: req.Code,
|
||||
Display: req.Display,
|
||||
})
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package mongo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"log"
|
||||
"template_blueprint/pkg/models/local"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (s *DatabaseService) GetDataLog() ([]*local.StartUpLog, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
dataLog, err := s.DB.Collection("startup_log").Find(ctx, bson.M{})
|
||||
if err != nil {
|
||||
log.Println("MASUK SINI")
|
||||
log.Println(err)
|
||||
return nil, err
|
||||
}
|
||||
log.Println("Data", dataLog.Current)
|
||||
var logs []*local.StartUpLog
|
||||
errDecode := dataLog.All(ctx, &logs)
|
||||
if errDecode != nil {
|
||||
log.Println(errDecode)
|
||||
return nil, errDecode
|
||||
}
|
||||
log.Println("LOGS :", logs)
|
||||
return logs, nil
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package mongo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"log"
|
||||
"template_blueprint/pkg/models/patient"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (s *DatabaseService) InsertPatient(req *patient.Patient) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
_, err := s.DB.Collection("patient").InsertOne(ctx, req)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *DatabaseService) GetAllDataPatient() ([]*patient.Patient, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
dataUser, err := s.DB.Collection("patient").Find(ctx, bson.D{})
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
var users []*patient.Patient
|
||||
err = dataUser.All(ctx, &users)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return nil, err
|
||||
}
|
||||
return users, nil
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
package mongo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"log"
|
||||
"template_blueprint/pkg/models/user"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (s *DatabaseService) InsertUser(req user.ReqInsertUser) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
_, err := s.DB.Collection("user").InsertOne(ctx, user.ReqInsertUser{
|
||||
ID: req.ID,
|
||||
Name: req.Name,
|
||||
Age: req.Age,
|
||||
Address: req.Address,
|
||||
Gender: req.Gender,
|
||||
Religion: req.Religion,
|
||||
})
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *DatabaseService) GetAllDataUser() ([]*user.User, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
dataUser, err := s.DB.Collection("user").Find(ctx, bson.D{})
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
var users []*user.User
|
||||
err = dataUser.All(ctx, &users)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return nil, err
|
||||
}
|
||||
return users, nil
|
||||
}
|
||||
|
||||
func (s *DatabaseService) GetUserById(id string) (*user.User, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
dataUser := s.DB.Collection("user").FindOne(ctx, bson.D{{Key: "_id", Value: id}})
|
||||
var user *user.User
|
||||
err := dataUser.Decode(&user)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return nil, err
|
||||
}
|
||||
return user, nil
|
||||
}
|
||||
|
||||
func (s *DatabaseService) UpdateUser(reqUpdate *user.ReqUpdateUser) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
log.Println(reqUpdate.ID)
|
||||
filter := bson.M{"_id": reqUpdate.ID}
|
||||
update := bson.M{"$set": bson.M{
|
||||
"name": reqUpdate.Name,
|
||||
"age": reqUpdate.Age,
|
||||
"address": reqUpdate.Address,
|
||||
"gender": reqUpdate.Gender,
|
||||
"religion": reqUpdate.Religion,
|
||||
}}
|
||||
updatedData, err := s.DB.Collection("user").UpdateOne(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return err
|
||||
}
|
||||
log.Println(updatedData)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *DatabaseService) DeleteUserById(id string) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
_, err := s.DB.Collection("user").DeleteOne(ctx, bson.D{{Key: "_id", Value: id}})
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
57
pkg/handlers/login/login.go
Normal file
57
pkg/handlers/login/login.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package login
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"os"
|
||||
"template_blueprint/internal/database"
|
||||
"template_blueprint/pkg/database/mongo"
|
||||
)
|
||||
|
||||
func Getlogin(c *gin.Context) {
|
||||
local := os.Getenv("MONGODB_DEV_MASTER")
|
||||
db := database.New(local).GetMongoDB()
|
||||
if db == nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"message": "Database connection failed"})
|
||||
return
|
||||
}
|
||||
|
||||
mongoDB := mongo.NewDatabaseServiceMongo(db)
|
||||
dataEncounter, errSelect := mongoDB.Getlogin()
|
||||
if errSelect != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"message": errSelect.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"data": dataEncounter,
|
||||
"message": "login Sukses Ter-ambil ",
|
||||
})
|
||||
}
|
||||
|
||||
func GetloginbyID(c *gin.Context) {
|
||||
local := os.Getenv("MONGODB_DEV_MASTER")
|
||||
db := database.New(local).GetMongoDB()
|
||||
if db == nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"message": "Database connection failed"})
|
||||
return
|
||||
}
|
||||
|
||||
id := c.Param("id")
|
||||
|
||||
if id == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"message": "Parameter 'id' dibutuhkan"})
|
||||
return
|
||||
}
|
||||
|
||||
mongoDB := mongo.NewDatabaseServiceMongo(db)
|
||||
dataID, err := mongoDB.GetByid(id)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"message": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"data": dataID,
|
||||
"message": "ID berhasil di cari",
|
||||
})
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package master_data
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
"net/http"
|
||||
"os"
|
||||
"template_blueprint/internal/database"
|
||||
"template_blueprint/pkg/database/mongo"
|
||||
"template_blueprint/pkg/models/master_data"
|
||||
)
|
||||
|
||||
func InsertDataMaster(c *gin.Context) {
|
||||
master := os.Getenv("BLUEPRINT_DB_MASTER")
|
||||
var ReqInsertData master_data.ReqInsertData
|
||||
errBind := c.Bind(&ReqInsertData)
|
||||
if errBind != nil {
|
||||
c.JSON(400, gin.H{
|
||||
"code": 400,
|
||||
})
|
||||
}
|
||||
db := database.New(master).GetDB()
|
||||
mongoDB := mongo.NewDatabaseService(db)
|
||||
ReqInsertData.ID = uuid.New().String()
|
||||
errInsert := mongoDB.InsertDataMaster(ReqInsertData)
|
||||
if errInsert != nil {
|
||||
c.JSON(400, gin.H{
|
||||
"message": "Failed Insert User",
|
||||
})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Successfully Inserted User"})
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package mongo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"template_blueprint/internal/database"
|
||||
"template_blueprint/pkg/database/mongo"
|
||||
"template_blueprint/pkg/models/local"
|
||||
"time"
|
||||
)
|
||||
|
||||
func GetDataLog(c *gin.Context) {
|
||||
locals := os.Getenv("BLUEPRINT_DB_LOCAL")
|
||||
db := database.New(locals).GetDB()
|
||||
if db == nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"message": "Database connection failed"})
|
||||
return
|
||||
}
|
||||
mongoDB := mongo.NewDatabaseService(db)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
cursor, err := mongoDB.DB.Collection("startup_log").Find(ctx, bson.M{})
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"message": "Database query failed"})
|
||||
return
|
||||
}
|
||||
|
||||
var dataLog []*local.StartUpLog
|
||||
errDecode := cursor.All(ctx, &dataLog)
|
||||
if errDecode != nil {
|
||||
log.Println(errDecode)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"message": "Database query failed"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, dataLog)
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
package patient
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"os"
|
||||
"template_blueprint/internal/database"
|
||||
"template_blueprint/pkg/database/mongo"
|
||||
"template_blueprint/pkg/models/patient"
|
||||
"time"
|
||||
)
|
||||
|
||||
func InsertPatient(c *gin.Context) {
|
||||
local := os.Getenv("MONGODB_DEV_LOCAL")
|
||||
db := database.New(local).GetDB()
|
||||
if db == nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"message": "Database connection failed"})
|
||||
return
|
||||
}
|
||||
mongoDB := mongo.NewDatabaseService(db)
|
||||
var req *patient.Patient
|
||||
err := c.Bind(&req)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"message": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
dateCreated := time.Now().Format("2006-01-02 15:04:05")
|
||||
req.ResourceType = "Patient"
|
||||
req.CreatedAt = dateCreated
|
||||
|
||||
errInsert := mongoDB.InsertPatient(req)
|
||||
if errInsert != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"message": errInsert.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Patient successfully inserted"})
|
||||
}
|
||||
|
||||
func GetAllPatient(c *gin.Context) {
|
||||
local := os.Getenv("MONGODB_DEV_LOCAL")
|
||||
db := database.New(local).GetDB()
|
||||
if db == nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"message": "Database connection failed"})
|
||||
return
|
||||
}
|
||||
mongoDB := mongo.NewDatabaseService(db)
|
||||
dataPatient, errSelect := mongoDB.GetAllDataPatient()
|
||||
if errSelect != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"message": errSelect.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, dataPatient)
|
||||
}
|
||||
@@ -1,168 +0,0 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"template_blueprint/internal/database"
|
||||
"template_blueprint/pkg/database/mongo"
|
||||
"template_blueprint/pkg/models/user"
|
||||
)
|
||||
|
||||
// InsertUser godoc
|
||||
// @Summary Insert a new user
|
||||
// @Description Adds a new user to the database
|
||||
// @Tags users
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param request body user.ReqInsertUser true "User Data"
|
||||
// @Success 200 {object} map[string]string "Successfully Inserted User"
|
||||
// @Failure 400 {object} map[string]string "Bad Request"
|
||||
// @Failure 500 {object} map[string]string "Database connection failed"
|
||||
// @Router /api/localinsertuser [post]
|
||||
func InsertUser(c *gin.Context) {
|
||||
local := os.Getenv("BLUEPRINT_DB_LOCAL")
|
||||
db := database.New(local).GetDB()
|
||||
if db == nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"message": "Database connection failed"})
|
||||
return
|
||||
}
|
||||
mongoDB := mongo.NewDatabaseService(db)
|
||||
var reqInsert user.ReqInsertUser
|
||||
|
||||
errBind := c.Bind(&reqInsert)
|
||||
if errBind != nil {
|
||||
c.JSON(400, gin.H{
|
||||
"message": errBind.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
id := uuid.New().String()
|
||||
reqInsert.ID = id
|
||||
errInsert := mongoDB.InsertUser(reqInsert)
|
||||
if errInsert != nil {
|
||||
c.JSON(400, gin.H{
|
||||
"message": errInsert.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Successfully Inserted User"})
|
||||
}
|
||||
|
||||
// GetAllUser godoc
|
||||
// @Summary Get all users
|
||||
// @Description Retrieves all users from the database
|
||||
// @Tags users
|
||||
// @Produce json
|
||||
// @Success 200 {array} user.User "List of users"
|
||||
// @Failure 500 {object} map[string]string "Database connection failed"
|
||||
// @Router /api/local/getalluser [get]
|
||||
func GetAllUser(c *gin.Context) {
|
||||
local := os.Getenv("BLUEPRINT_DB_LOCAL")
|
||||
db := database.New(local).GetDB()
|
||||
if db == nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"message": "Database connection failed"})
|
||||
return
|
||||
}
|
||||
mongoDB := mongo.NewDatabaseService(db)
|
||||
dataUser, errSelect := mongoDB.GetAllDataUser()
|
||||
if errSelect != nil {
|
||||
c.JSON(400, gin.H{
|
||||
"message": errSelect.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, dataUser)
|
||||
}
|
||||
|
||||
// GetUserByID godoc
|
||||
// @Summary Get user by ID
|
||||
// @Description Retrieves a user by their ID
|
||||
// @Tags users
|
||||
// @Produce json
|
||||
// @Param id path string true "User ID"
|
||||
// @Success 200 {object} user.User "User data"
|
||||
// @Failure 400 {object} map[string]string "Bad Request"
|
||||
// @Router /api/local/getuser/{id} [get]
|
||||
func GetUserByID(c *gin.Context) {
|
||||
local := os.Getenv("BLUEPRINT_DB_LOCAL")
|
||||
db := database.New(local).GetDB()
|
||||
if db == nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"message": "Database connection failed"})
|
||||
return
|
||||
}
|
||||
id := c.Param("id")
|
||||
log.Println("ID", id)
|
||||
mongoDB := mongo.NewDatabaseService(db)
|
||||
dataUser, errSelect := mongoDB.GetUserById(id)
|
||||
if errSelect != nil {
|
||||
c.JSON(400, gin.H{
|
||||
"message": errSelect.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, dataUser)
|
||||
}
|
||||
|
||||
// UpdateUser godoc
|
||||
// @Summary Update a user
|
||||
// @Description Updates user information
|
||||
// @Tags users
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param request body user.User true "User Data"
|
||||
// @Success 200 {object} map[string]string "Successfully Updated User"
|
||||
// @Failure 400 {object} map[string]string "Bad Request"
|
||||
// @Failure 500 {object} map[string]string "Database connection failed"
|
||||
// @Router /users [put]
|
||||
func UpdateUser(c *gin.Context) {
|
||||
local := os.Getenv("BLUEPRINT_DB_LOCAL")
|
||||
db := database.New(local).GetDB()
|
||||
if db == nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"message": "Database connection failed"})
|
||||
return
|
||||
}
|
||||
mongoDB := mongo.NewDatabaseService(db)
|
||||
var reqUpdate *user.ReqUpdateUser
|
||||
errBind := c.Bind(&reqUpdate)
|
||||
if errBind != nil {
|
||||
c.JSON(400, gin.H{
|
||||
"message": errBind.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
log.Println("REQ UPDATE", reqUpdate)
|
||||
errUpdate := mongoDB.UpdateUser(reqUpdate)
|
||||
if errUpdate != nil {
|
||||
c.JSON(400, gin.H{
|
||||
"message": errUpdate.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Successfully Updated User"})
|
||||
}
|
||||
|
||||
func DeleteUser(c *gin.Context) {
|
||||
local := os.Getenv("BLUEPRINT_DB_LOCAL")
|
||||
db := database.New(local).GetDB()
|
||||
if db == nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"message": "Database connection failed"})
|
||||
return
|
||||
}
|
||||
mongoDB := mongo.NewDatabaseService(db)
|
||||
var reqDelete *user.ReqDeleteUser
|
||||
errBind := c.Bind(&reqDelete)
|
||||
if errBind != nil {
|
||||
c.JSON(400, gin.H{})
|
||||
return
|
||||
}
|
||||
log.Println("REQ DELETE", reqDelete)
|
||||
errDelete := mongoDB.DeleteUserById(reqDelete.ID)
|
||||
if errDelete != nil {
|
||||
c.JSON(400, gin.H{"message": "Failed to Delete User"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Successfully Deleted User"})
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
package encounter
|
||||
@@ -1,72 +0,0 @@
|
||||
package local
|
||||
|
||||
type StartUpLog struct {
|
||||
ID string `bson:"_id"`
|
||||
HostName string `bson:"hostname"`
|
||||
StartTime string `bson:"start_time"`
|
||||
StartTimeLocal string `bson:"start_time_local"`
|
||||
CmdLine CmdLine `bson:"cmdline"`
|
||||
Pid int `bson:"pid"`
|
||||
BuildInfo BuildInfo `bson:"buildinfo"`
|
||||
}
|
||||
|
||||
type CmdLine struct {
|
||||
Net Net `bson:"net"`
|
||||
ProcessManagement ProcessManagement `bson:"processManagement"`
|
||||
SystemLog SystemLog `bson:"systemLog"`
|
||||
}
|
||||
|
||||
type Net struct {
|
||||
BindIP string `bson:"bindIp"`
|
||||
Port int `bson:"port"`
|
||||
Tls TLS `bson:"tls"`
|
||||
}
|
||||
|
||||
type TLS struct {
|
||||
Mode string `bson:"mode"`
|
||||
}
|
||||
|
||||
type ProcessManagement struct {
|
||||
Fork bool `bson:"fork"`
|
||||
PidFilePath string `bson:"pidFilePath"`
|
||||
}
|
||||
|
||||
type SystemLog struct {
|
||||
Destination string `bson:"destination"`
|
||||
LogAppend bool `bson:"logAppend"`
|
||||
Path string `bson:"path"`
|
||||
}
|
||||
|
||||
type BuildInfo struct {
|
||||
Version string `bson:"version"`
|
||||
GitVersion string `bson:"gitVersion"`
|
||||
Modules []string `bson:"modules"`
|
||||
Allocator string `bson:"allocator"`
|
||||
JavaScriptEngine string `bson:"javaScriptEngine"`
|
||||
SysInfo string `bson:"sysInfo"`
|
||||
VersionArray []int `bson:"versionArray"`
|
||||
OpenSSL OpenSSL `bson:"openssl"`
|
||||
BuildEnvironment BuildEnvironment `bson:"buildEnvironment"`
|
||||
Bits int `bson:"bits"`
|
||||
Debug bool `bson:"debug"`
|
||||
MaxBsonObjectSize int `bson:"maxBsonObjectSize"`
|
||||
StorageEngines []string `bson:"storageEngines"`
|
||||
}
|
||||
|
||||
type OpenSSL struct {
|
||||
Running string `bson:"running"`
|
||||
Compiled string `bson:"compiled"`
|
||||
}
|
||||
|
||||
type BuildEnvironment struct {
|
||||
DistMod string `bson:"distmod"`
|
||||
Distarch string `bson:"distarch"`
|
||||
CC string `bson:"cc"`
|
||||
CCFlags string `bson:"ccflags"`
|
||||
CXX string `bson:"cxx"`
|
||||
CXXFlags string `bson:"cxxflags"`
|
||||
LinkFlags string `bson:"linkflags"`
|
||||
TargetArch string `bson:"target_arch"`
|
||||
TargetOS string `bson:"target_os"`
|
||||
CPPDefines string `bson:"cppdefines"`
|
||||
}
|
||||
23
pkg/models/login/login.go
Normal file
23
pkg/models/login/login.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package login
|
||||
|
||||
import "go.mongodb.org/mongo-driver/bson/primitive"
|
||||
|
||||
type Menu struct {
|
||||
ID primitive.ObjectID `bson:"_id" json:"_id"`
|
||||
Items []MenuItem `bson:"items" json:"items"`
|
||||
}
|
||||
|
||||
type MenuItem struct {
|
||||
Header string `bson:"header,omitempty" json:"header,omitempty"`
|
||||
Title string `bson:"title,omitempty" json:"title,omitempty"`
|
||||
Icon string `bson:"icon,omitempty" json:"icon,omitempty"`
|
||||
To string `bson:"to,omitempty" json:"to,omitempty"`
|
||||
Children []SubItem `bson:"children,omitempty" json:"children,omitempty"`
|
||||
}
|
||||
|
||||
type SubItem struct {
|
||||
Title string `bson:"title,omitempty" json:"title,omitempty"`
|
||||
To string `bson:"to,omitempty" json:"to,omitempty"`
|
||||
Chip string `bson:"chip,omitempty" json:"chip,omitempty"`
|
||||
External bool `bson:"external,omitempty" json:"external,omitempty"`
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package master_data
|
||||
|
||||
type ReqInsertData struct {
|
||||
ID string `bson:"_id"`
|
||||
Table string `bson:"table"`
|
||||
System string `bson:"system"`
|
||||
Code string `bson:"code"`
|
||||
Display string `bson:"display"`
|
||||
}
|
||||
|
||||
type ReqInsertDataMaster struct {
|
||||
ID string `bson:"_id"`
|
||||
System string `bson:"system"`
|
||||
Code string `bson:"code"`
|
||||
Display string `bson:"display"`
|
||||
}
|
||||
@@ -1,167 +0,0 @@
|
||||
package patient
|
||||
|
||||
type Coding struct {
|
||||
System string `bson:"system,omitempty"`
|
||||
Version string `bson:"version,omitempty"`
|
||||
Code string `bson:"code,omitempty"`
|
||||
Display string `bson:"display,omitempty"`
|
||||
UserSelected bool `bson:"userSelected,omitempty"`
|
||||
}
|
||||
|
||||
type Identifier struct {
|
||||
Use string `bson:"use,omitempty"`
|
||||
Type CodeableConcept `bson:"type,omitempty"`
|
||||
System string `bson:"system,omitempty"`
|
||||
Value string `bson:"value,omitempty"`
|
||||
Period Period `bson:"period,omitempty"`
|
||||
Assigner struct{} `bson:"assigner,omitempty"`
|
||||
}
|
||||
|
||||
type CodeableConcept struct {
|
||||
Coding []Coding `bson:"coding,omitempty"`
|
||||
Text string `bson:"text,omitempty"`
|
||||
}
|
||||
|
||||
type Period struct {
|
||||
Start string `bson:"start,omitempty"`
|
||||
End string `bson:"end,omitempty"`
|
||||
}
|
||||
|
||||
type ContactPoint struct {
|
||||
System string `bson:"system,omitempty"`
|
||||
Value string `bson:"value,omitempty"`
|
||||
Use string `bson:"use,omitempty"`
|
||||
Rank int `bson:"rank,omitempty"`
|
||||
Period Period `bson:"period,omitempty"`
|
||||
}
|
||||
|
||||
type HumanName struct {
|
||||
Use string `bson:"use,omitempty"`
|
||||
Text string `bson:"text,omitempty"`
|
||||
Family string `bson:"family,omitempty"`
|
||||
Given []string `bson:"given,omitempty"`
|
||||
Prefix []string `bson:"prefix,omitempty"`
|
||||
Suffix []string `bson:"suffix,omitempty"`
|
||||
Period Period `bson:"period,omitempty"`
|
||||
}
|
||||
|
||||
type Address struct {
|
||||
Use string `bson:"use,omitempty"`
|
||||
Type string `bson:"type,omitempty"`
|
||||
Text string `bson:"text,omitempty"`
|
||||
Line []string `bson:"line,omitempty"`
|
||||
City string `bson:"city,omitempty"`
|
||||
District string `bson:"district,omitempty"`
|
||||
State string `bson:"state,omitempty"`
|
||||
PostalCode string `bson:"postalCode,omitempty"`
|
||||
Country string `bson:"country,omitempty"`
|
||||
Period Period `bson:"period,omitempty"`
|
||||
}
|
||||
|
||||
type Organization struct {
|
||||
Reference string `bson:"reference,omitempty"`
|
||||
}
|
||||
|
||||
type Contact struct {
|
||||
Relationship []CodeableConcept `bson:"relationship,omitempty"`
|
||||
Name []HumanName `bson:"name,omitempty"`
|
||||
Telecom []ContactPoint `bson:"telecom,omitempty"`
|
||||
Address Address `bson:"address,omitempty"`
|
||||
Organization Organization `bson:"organization,omitempty"`
|
||||
Gender string `bson:"gender,omitempty"`
|
||||
Period Period `bson:"period,omitempty"`
|
||||
}
|
||||
|
||||
type Communication struct {
|
||||
Language CodeableConcept `bson:"language,omitempty"`
|
||||
Preferred bool `bson:"preferred,omitempty"`
|
||||
}
|
||||
|
||||
type ReqInsertCommunication struct {
|
||||
Language Coding `bson:"language,omitempty"`
|
||||
Preferred bool `bson:"preferred,omitempty"`
|
||||
}
|
||||
|
||||
type Link struct {
|
||||
RelatePerson []RelatePerson `bson:"relatePerson,omitempty"`
|
||||
}
|
||||
|
||||
type RelatePerson struct {
|
||||
Identifier []Identifier `bson:"identifier,omitempty"`
|
||||
Active bool `bson:"active"`
|
||||
Patient string `bson:"patient"`
|
||||
Relationship CodeableConcept `bson:"relationship"`
|
||||
Name []HumanName `bson:"name,omitempty"`
|
||||
Telecom []ContactPoint `bson:"telecom,omitempty"`
|
||||
Gender string `bson:"gender,omitempty"`
|
||||
BirthDate string `bson:"birthDate,omitempty"`
|
||||
Address []Address `bson:"address,omitempty"`
|
||||
Photo string `bson:"photo,omitempty"`
|
||||
Period Period `bson:"period,omitempty"`
|
||||
Communication []Communication `bson:"communication,omitempty"`
|
||||
Preferred bool `bson:"preferred"`
|
||||
}
|
||||
|
||||
type Deceased struct {
|
||||
DeceasedBoolean bool `bson:"deceasedBoolean,omitempty"`
|
||||
DeceasedDateTime string `bson:"deceasedDateTime,omitempty"`
|
||||
}
|
||||
|
||||
type MultipleBirth struct {
|
||||
MultipleBirthBoolean bool `bson:"multipleBirthBoolean,omitempty"`
|
||||
MultipleBirthInteger int `bson:"multipleBirthInteger,omitempty"`
|
||||
}
|
||||
|
||||
type Patient struct {
|
||||
ResourceType string `bson:"resourceType"`
|
||||
ID string `bson:"_id"`
|
||||
Identifier []Identifier `bson:"identifier,omitempty"`
|
||||
Active bool `bson:"active"`
|
||||
Name []HumanName `bson:"name,omitempty"`
|
||||
Telecom []ContactPoint `bson:"telecom,omitempty"`
|
||||
Gender string `bson:"gender,omitempty"`
|
||||
BirthPlace string `bson:"birthPlace,omitempty"`
|
||||
BirthDate string `bson:"birthDate,omitempty"`
|
||||
Address []Address `bson:"address,omitempty"`
|
||||
MaritalStatus CodeableConcept `bson:"maritalStatus,omitempty"`
|
||||
Job CodeableConcept `bson:"job,omitempty"`
|
||||
Religion CodeableConcept `bson:"religion,omitempty"`
|
||||
Tribe CodeableConcept `bson:"tribe,omitempty"`
|
||||
Link Link `bson:"link,omitempty"`
|
||||
Communication []Communication `bson:"communication,omitempty"`
|
||||
Disability bool `bson:"disability,omitempty"`
|
||||
National string `bson:"national,omitempty"`
|
||||
Deceased Deceased `bson:"deceased,omitempty"`
|
||||
MultipleBirth MultipleBirth `bson:"multipleBirth,omitempty"`
|
||||
CreatedAt string `bson:"createdAt"`
|
||||
UpdatedAt string `bson:"updatedAt"`
|
||||
}
|
||||
|
||||
type ReqInsertIdentifier struct {
|
||||
Use string `bson:"use,omitempty"`
|
||||
Type Coding `bson:"type,omitempty"`
|
||||
System string `bson:"system,omitempty"`
|
||||
Value string `bson:"value,omitempty"`
|
||||
Period Period `bson:"period,omitempty"`
|
||||
}
|
||||
|
||||
type ReqInsertPatient struct {
|
||||
Identifier []ReqInsertIdentifier `bson:"identifier,omitempty"`
|
||||
Active bool `bson:"active"`
|
||||
Name []HumanName `bson:"name,omitempty"`
|
||||
Telecom []ContactPoint `bson:"telecom,omitempty"`
|
||||
Gender string `bson:"gender,omitempty"`
|
||||
BirthPlace string `bson:"birthPlace,omitempty"`
|
||||
BirthDate string `bson:"birthDate,omitempty"`
|
||||
Address []Address `bson:"address,omitempty"`
|
||||
MaritalStatus []CodeableConcept `bson:"maritalStatus,omitempty"`
|
||||
Job []CodeableConcept `bson:"job,omitempty"`
|
||||
Religion []CodeableConcept `bson:"religion,omitempty"`
|
||||
Tribe []CodeableConcept `bson:"tribe,omitempty"`
|
||||
Link Link `bson:"link,omitempty"`
|
||||
Communication []Communication `bson:"communication,omitempty"`
|
||||
Disability bool `bson:"disability,omitempty"`
|
||||
National string `bson:"national,omitempty"`
|
||||
Deceased Deceased `bson:"deceased,omitempty"`
|
||||
MultipleBirth MultipleBirth `bson:"multipleBirth,omitempty"`
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package user
|
||||
|
||||
type User struct {
|
||||
ID string `bson:"_id"`
|
||||
Name string `bson:"name"`
|
||||
Age int `bson:"age"`
|
||||
Address string `bson:"address"`
|
||||
Gender string `bson:"gender"`
|
||||
Religion string `bson:"religion"`
|
||||
}
|
||||
|
||||
type ReqInsertUser struct {
|
||||
ID string `bson:"_id"`
|
||||
Name string `bson:"name"`
|
||||
Age int `bson:"age"`
|
||||
Address string `bson:"address"`
|
||||
Gender string `bson:"gender"`
|
||||
Religion string `bson:"religion"`
|
||||
}
|
||||
|
||||
// USING INSERT AND UPDATE
|
||||
type ReqUpdateUser struct {
|
||||
ID string `json:"_id"`
|
||||
Name string `json:"name"`
|
||||
Age int `json:"age"`
|
||||
Address string `json:"address"`
|
||||
Gender string `json:"gender"`
|
||||
Religion string `json:"religion"`
|
||||
}
|
||||
|
||||
type ReqDeleteUser struct {
|
||||
ID string `json:"_id"`
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
module.exports = {
|
||||
content: [
|
||||
"./cmd/web/**/*.html", "./cmd/web/**/*.templ",
|
||||
],
|
||||
theme: {
|
||||
extend: {},
|
||||
},
|
||||
plugins: [],
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user