From a0fdf0240f543243deb6248719031f118fb64f59 Mon Sep 17 00:00:00 2001 From: mirza Date: Fri, 7 Mar 2025 11:11:44 +0700 Subject: [PATCH] fix code crud user and insert master data for fhir --- .env | 2 +- cmd/api/main.go | 4 +- docker-compose.yml | 7 +- docs/docs.go | 251 ++++++++++++++++++++++++ docs/swagger.json | 224 +++++++++++++++++++++ docs/swagger.yaml | 145 ++++++++++++++ go.mod | 16 ++ go.sum | 63 +++++- internal/database/database.go | 11 +- internal/server/routes.go | 23 ++- internal/server/server.go | 6 - pkg/database/mongo/master_data.go | 24 +++ pkg/database/mongo/user.go | 32 ++- pkg/handlers/master_data/master_data.go | 33 ++++ pkg/handlers/mongo/mongo.go | 25 ++- pkg/handlers/user/user.go | 78 +++++++- pkg/models/master_data/master_data.go | 16 ++ pkg/models/user/user.go | 34 +++- 18 files changed, 940 insertions(+), 54 deletions(-) create mode 100644 docs/docs.go create mode 100644 docs/swagger.json create mode 100644 docs/swagger.yaml create mode 100644 pkg/database/mongo/master_data.go create mode 100644 pkg/handlers/master_data/master_data.go create mode 100644 pkg/models/master_data/master_data.go diff --git a/.env b/.env index d2b62f6..63a912e 100644 --- a/.env +++ b/.env @@ -2,7 +2,7 @@ PORT=8801 APP_ENV=local -BLUEPRINT_DB_HOST=mongodb +BLUEPRINT_DB_HOST=host.docker.internal BLUEPRINT_DB_PORT=27017 BLUEPRINT_DB_USER=admin BLUEPRINT_DB_PASS=password diff --git a/cmd/api/main.go b/cmd/api/main.go index 7ea7143..7887467 100644 --- a/cmd/api/main.go +++ b/cmd/api/main.go @@ -4,12 +4,12 @@ import ( "context" "fmt" "log" + _ "mongotest/docs" + "mongotest/internal/server" "net/http" "os/signal" "syscall" "time" - - "mongotest/internal/server" ) func gracefulShutdown(apiServer *http.Server, done chan bool) { diff --git a/docker-compose.yml b/docker-compose.yml index 42cc16b..3e367ec 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,11 +9,12 @@ services: - 8801:8801 environment: TZ: Asia/Jakarta - BLUEPRINT_DB_HOST: host.docker.internal + BLUEPRINT_DB_HOST: 10.10.123.206 BLUEPRINT_DB_PORT: 27017 BLUEPRINT_DB_USER: admin - BLUEPRINT_DB_PASS: password - BLUEPRINT_DB_NAME: local + BLUEPRINT_DB_PASS: 12345 + BLUEPRINT_DB_MASTER: master + BLUEPRINT_DB_LOCAL: local networks: app-network: diff --git a/docs/docs.go b/docs/docs.go new file mode 100644 index 0000000..542b7d6 --- /dev/null +++ b/docs/docs.go @@ -0,0 +1,251 @@ +// Package docs Code generated by swaggo/swag. DO NOT EDIT +package docs + +import "github.com/swaggo/swag" + +const docTemplate = `{ + "schemes": {{ marshal .Schemes }}, + "swagger": "2.0", + "info": { + "description": "{{escape .Description}}", + "title": "{{.Title}}", + "contact": {}, + "version": "{{.Version}}" + }, + "host": "{{.Host}}", + "basePath": "{{.BasePath}}", + "paths": { + "/api/local/getalluser": { + "get": { + "description": "Retrieves all users from the database", + "produces": [ + "application/json" + ], + "tags": [ + "users" + ], + "summary": "Get all users", + "responses": { + "200": { + "description": "List of users", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/user.User" + } + } + }, + "500": { + "description": "Database connection failed", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + } + }, + "/api/local/getuser/{id}": { + "get": { + "description": "Retrieves a user by their ID", + "produces": [ + "application/json" + ], + "tags": [ + "users" + ], + "summary": "Get user by ID", + "parameters": [ + { + "type": "string", + "description": "User ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "User data", + "schema": { + "$ref": "#/definitions/user.User" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + } + }, + "/api/localinsertuser": { + "post": { + "description": "Adds a new user to the database", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "users" + ], + "summary": "Insert a new user", + "parameters": [ + { + "description": "User Data", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/user.ReqInsertUser" + } + } + ], + "responses": { + "200": { + "description": "Successfully Inserted User", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Database connection failed", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + } + }, + "/users": { + "put": { + "description": "Updates user information", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "users" + ], + "summary": "Update a user", + "parameters": [ + { + "description": "User Data", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/user.User" + } + } + ], + "responses": { + "200": { + "description": "Successfully Updated User", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Database connection failed", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + } + } + }, + "definitions": { + "user.ReqInsertUser": { + "type": "object", + "properties": { + "address": { + "type": "string" + }, + "age": { + "type": "integer" + }, + "id": { + "type": "string" + }, + "name": { + "type": "string" + } + } + }, + "user.User": { + "type": "object", + "properties": { + "address": { + "type": "string" + }, + "age": { + "type": "integer" + }, + "id": { + "type": "string" + }, + "name": { + "type": "string" + } + } + } + } +}` + +// SwaggerInfo holds exported Swagger Info so clients can modify it +var SwaggerInfo = &swag.Spec{ + Version: "", + Host: "", + BasePath: "", + Schemes: []string{}, + Title: "", + Description: "", + InfoInstanceName: "swagger", + SwaggerTemplate: docTemplate, +} + +func init() { + swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo) +} diff --git a/docs/swagger.json b/docs/swagger.json new file mode 100644 index 0000000..8e64cf8 --- /dev/null +++ b/docs/swagger.json @@ -0,0 +1,224 @@ +{ + "swagger": "2.0", + "info": { + "contact": {} + }, + "paths": { + "/api/local/getalluser": { + "get": { + "description": "Retrieves all users from the database", + "produces": [ + "application/json" + ], + "tags": [ + "users" + ], + "summary": "Get all users", + "responses": { + "200": { + "description": "List of users", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/user.User" + } + } + }, + "500": { + "description": "Database connection failed", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + } + }, + "/api/local/getuser/{id}": { + "get": { + "description": "Retrieves a user by their ID", + "produces": [ + "application/json" + ], + "tags": [ + "users" + ], + "summary": "Get user by ID", + "parameters": [ + { + "type": "string", + "description": "User ID", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "User data", + "schema": { + "$ref": "#/definitions/user.User" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + } + }, + "/api/localinsertuser": { + "post": { + "description": "Adds a new user to the database", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "users" + ], + "summary": "Insert a new user", + "parameters": [ + { + "description": "User Data", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/user.ReqInsertUser" + } + } + ], + "responses": { + "200": { + "description": "Successfully Inserted User", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Database connection failed", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + } + }, + "/users": { + "put": { + "description": "Updates user information", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "users" + ], + "summary": "Update a user", + "parameters": [ + { + "description": "User Data", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/user.User" + } + } + ], + "responses": { + "200": { + "description": "Successfully Updated User", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "500": { + "description": "Database connection failed", + "schema": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + } + } + } + }, + "definitions": { + "user.ReqInsertUser": { + "type": "object", + "properties": { + "address": { + "type": "string" + }, + "age": { + "type": "integer" + }, + "id": { + "type": "string" + }, + "name": { + "type": "string" + } + } + }, + "user.User": { + "type": "object", + "properties": { + "address": { + "type": "string" + }, + "age": { + "type": "integer" + }, + "id": { + "type": "string" + }, + "name": { + "type": "string" + } + } + } + } +} \ No newline at end of file diff --git a/docs/swagger.yaml b/docs/swagger.yaml new file mode 100644 index 0000000..c099ee2 --- /dev/null +++ b/docs/swagger.yaml @@ -0,0 +1,145 @@ +definitions: + user.ReqInsertUser: + properties: + address: + type: string + age: + type: integer + id: + type: string + name: + type: string + type: object + user.User: + properties: + address: + type: string + age: + type: integer + id: + type: string + name: + type: string + type: object +info: + contact: {} +paths: + /api/local/getalluser: + get: + description: Retrieves all users from the database + produces: + - application/json + responses: + "200": + description: List of users + schema: + items: + $ref: '#/definitions/user.User' + type: array + "500": + description: Database connection failed + schema: + additionalProperties: + type: string + type: object + summary: Get all users + tags: + - users + /api/local/getuser/{id}: + get: + description: Retrieves a user by their ID + parameters: + - description: User ID + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "200": + description: User data + schema: + $ref: '#/definitions/user.User' + "400": + description: Bad Request + schema: + additionalProperties: + type: string + type: object + summary: Get user by ID + tags: + - users + /api/localinsertuser: + post: + consumes: + - application/json + description: Adds a new user to the database + parameters: + - description: User Data + in: body + name: request + required: true + schema: + $ref: '#/definitions/user.ReqInsertUser' + produces: + - application/json + responses: + "200": + description: Successfully Inserted User + schema: + additionalProperties: + type: string + type: object + "400": + description: Bad Request + schema: + additionalProperties: + type: string + type: object + "500": + description: Database connection failed + schema: + additionalProperties: + type: string + type: object + summary: Insert a new user + tags: + - users + /users: + put: + consumes: + - application/json + description: Updates user information + parameters: + - description: User Data + in: body + name: request + required: true + schema: + $ref: '#/definitions/user.User' + produces: + - application/json + responses: + "200": + description: Successfully Updated User + schema: + additionalProperties: + type: string + type: object + "400": + description: Bad Request + schema: + additionalProperties: + type: string + type: object + "500": + description: Database connection failed + schema: + additionalProperties: + type: string + type: object + summary: Update a user + tags: + - users +swagger: "2.0" diff --git a/go.mod b/go.mod index e64bfe1..0fb9946 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,8 @@ require ( github.com/gin-gonic/gin v1.10.0 github.com/google/uuid v1.6.0 github.com/joho/godotenv v1.5.1 + github.com/swaggo/files v1.0.1 + github.com/swaggo/gin-swagger v1.6.0 github.com/testcontainers/testcontainers-go/modules/mongodb v0.35.0 go.mongodb.org/mongo-driver v1.17.2 ) @@ -14,7 +16,10 @@ require ( require ( dario.cat/mergo v1.0.0 // indirect github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect + github.com/KyleBanks/depth v1.2.1 // indirect github.com/Microsoft/go-winio v0.6.2 // indirect + github.com/PuerkitoBio/purell v1.1.1 // indirect + github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect github.com/bytedance/sonic v1.12.8 // indirect github.com/bytedance/sonic/loader v0.2.3 // indirect github.com/cenkalti/backoff/v4 v4.2.1 // indirect @@ -34,18 +39,25 @@ require ( github.com/go-logr/logr v1.4.1 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/go-ole/go-ole v1.2.6 // indirect + github.com/go-openapi/jsonpointer v0.19.5 // indirect + github.com/go-openapi/jsonreference v0.19.6 // indirect + github.com/go-openapi/spec v0.20.4 // indirect + github.com/go-openapi/swag v0.19.15 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.25.0 // indirect 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/josharian/intern v1.0.0 // 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.9 // indirect + github.com/kr/pretty v0.3.1 // indirect github.com/leodido/go-urn v1.4.0 // indirect github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect github.com/magiconair/properties v1.8.7 // indirect + github.com/mailru/easyjson v0.7.6 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/moby/docker-image-spec v1.3.1 // indirect github.com/moby/patternmatcher v0.6.0 // indirect @@ -62,10 +74,12 @@ require ( github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect + github.com/rogpeppe/go-internal v1.11.0 // indirect github.com/shirou/gopsutil/v3 v3.23.12 // indirect github.com/shoenig/go-m1cpu v0.1.6 // indirect github.com/sirupsen/logrus v1.9.3 // indirect github.com/stretchr/testify v1.10.0 // indirect + github.com/swaggo/swag v1.8.12 // indirect github.com/testcontainers/testcontainers-go v0.35.0 // indirect github.com/tklauser/go-sysconf v0.3.12 // indirect github.com/tklauser/numcpus v0.6.1 // indirect @@ -86,6 +100,8 @@ require ( golang.org/x/sync v0.11.0 // indirect golang.org/x/sys v0.30.0 // indirect golang.org/x/text v0.22.0 // indirect + golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect google.golang.org/protobuf v1.36.5 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index d0f3c90..acceb6a 100644 --- a/go.sum +++ b/go.sum @@ -4,8 +4,14 @@ github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 h1:bvDV9 github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8= github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8= github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= +github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc= +github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE= github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= +github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI= +github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= +github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M= +github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= github.com/bytedance/sonic v1.12.8 h1:4xYRVRlXIgvSZ4e8iVTlMF5szgpXd4AfvuWgA8I8lgs= github.com/bytedance/sonic v1.12.8/go.mod h1:uVvFidNmlt9+wa31S1urfwwthTWteBgG0hWuoKAXTx8= github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= @@ -24,6 +30,7 @@ github.com/containerd/platforms v0.2.1 h1:zvwtM3rz2YHPQsF2CHYM8+KtB5dvhISiXh5ZpS github.com/containerd/platforms v0.2.1/go.mod h1:XHCb+2/hzowdiut9rkudds9bE5yJ7npe7dG/wG+uFPw= github.com/cpuguy83/dockercfg v0.3.2 h1:DlJTyZGBDlXqUZ2Dk2Q3xHs/FtnooJJVaad2S9GKorA= github.com/cpuguy83/dockercfg v0.3.2/go.mod h1:sugsbF4//dDlL/i+S+rtpIWp+5h0BHJHfjj5/jFyUJc= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY= github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -43,6 +50,8 @@ github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3G github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8= github.com/gin-contrib/cors v1.7.3 h1:hV+a5xp8hwJoTw7OY+a70FsL8JkVVFTXw9EcfrYUdns= github.com/gin-contrib/cors v1.7.3/go.mod h1:M3bcKZhxzsvI+rlRSkkxHyljJt1ESd93COUvemZ79j4= +github.com/gin-contrib/gzip v0.0.6 h1:NjcunTcGAj5CO1gn4N8jHOSIeRFHIbn51z6K+xaN4d4= +github.com/gin-contrib/gzip v0.0.6/go.mod h1:QOJlmV2xmayAjkNS2Y8NQsMneuRShOU/kjovCXNuzzk= github.com/gin-contrib/sse v1.0.0 h1:y3bT1mUWUxDpW4JLQg/HnTqV4rozuW4tC9eFKTxYI9E= github.com/gin-contrib/sse v1.0.0/go.mod h1:zNuFdwarAygJBht0NTKiSi3jRf6RbqeILZ9Sp6Slhe0= github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU= @@ -54,6 +63,16 @@ github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= +github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= +github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY= +github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= +github.com/go-openapi/jsonreference v0.19.6 h1:UBIxjkht+AWIgYzCDSv2GN+E/togfwXUJFRTWhl2Jjs= +github.com/go-openapi/jsonreference v0.19.6/go.mod h1:diGHMEHg2IqXZGKxqyvWdfWU/aim5Dprw5bqpKkTvns= +github.com/go-openapi/spec v0.20.4 h1:O8hJrt0UMnhHcluhIdUgCLRWyM2x7QkBXRvOs7m+O1M= +github.com/go-openapi/spec v0.20.4/go.mod h1:faYFR1CvsJZ0mNsmsphTMSoRrNV3TEDoAM7FOEWeq8I= +github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= +github.com/go-openapi/swag v0.19.15 h1:D2NRCBzS9/pEY3gP9Nl8aDqGUcPFrwG2p+CNFrLyrCM= +github.com/go-openapi/swag v0.19.15/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= @@ -79,6 +98,8 @@ github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 h1:YBftPWNWd4WwGqtY2yeZL2ef8rH github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0/go.mod h1:YN5jB8ie0yfIUg6VvR9Kz84aCaG7AsGZnLjhHbUqwPg= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= +github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= +github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= @@ -89,8 +110,11 @@ github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa02 github.com/klauspost/cpuid/v2 v2.2.9 h1:66ze0taIn2H33fBvCkXuv9BmCwDfafmiIVpKV9kKGuY= github.com/klauspost/cpuid/v2 v2.2.9/go.mod h1:rqkxqrZ1EhYM9G+hXH7YdowN5R5RGN6NK4QwQ3WMXF8= github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= -github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= -github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= @@ -99,6 +123,10 @@ github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I= github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= +github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +github.com/mailru/easyjson v0.7.6 h1:8yTIVnZgCoiM1TgqoeTl+LfU5Jg6/xL3QhGQnimLYnA= +github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0= @@ -120,20 +148,23 @@ github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8 github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow= github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug= github.com/opencontainers/image-spec v1.1.0/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM= github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M= github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= 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= github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw= github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= -github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XFkP+Eg= -github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= +github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= +github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= github.com/shirou/gopsutil/v3 v3.23.12 h1:z90NtUkp3bMtmICZKpC4+WaknU1eXtp5vtbQ11DgpE4= github.com/shirou/gopsutil/v3 v3.23.12/go.mod h1:1FrWgea594Jp7qmjHUUPlJDTPgcsb9mGnXDxavtikzM= github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM= @@ -148,6 +179,7 @@ github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpE github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 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= @@ -155,6 +187,12 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o 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/swaggo/files v1.0.1 h1:J1bVJ4XHZNq0I46UU90611i9/YzdrF7x92oX1ig5IdE= +github.com/swaggo/files v1.0.1/go.mod h1:0qXmMNH6sXNf+73t65aKeB+ApmgxdnkQzVTAj2uaMUg= +github.com/swaggo/gin-swagger v1.6.0 h1:y8sxvQ3E20/RCyrXeFfg60r6H0Z+SwpTjMYsMm+zy8M= +github.com/swaggo/gin-swagger v1.6.0/go.mod h1:BG00cCEy294xtVpyIAHG6+e2Qzj/xKlRdOqDkvq0uzo= +github.com/swaggo/swag v1.8.12 h1:pctzkNPu0AlQP2royqX3apjKCQonAnf7KGoxeO4y64w= +github.com/swaggo/swag v1.8.12/go.mod h1:lNfm6Gg+oAq3zRJQNEMBE66LIJKM44mxFqhEEgy2its= github.com/testcontainers/testcontainers-go v0.35.0 h1:uADsZpTKFAtp8SLK+hMwSaa+X+JiERHtd4sQAFmXeMo= github.com/testcontainers/testcontainers-go v0.35.0/go.mod h1:oEVBj5zrfJTrgjwONs1SsRbnBtH9OKl+IGl3UMcr2B4= github.com/testcontainers/testcontainers-go/modules/mongodb v0.35.0 h1:i1Kh9fmXgHG9z3uzJv5Arz7pDKVaaNpLrqyd+0xhYMA= @@ -209,12 +247,16 @@ golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5 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= +golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= +golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210421230115-4e50805a0758/go.mod h1:72T/g9IO56b78aLF+1Kcs5dz7/ng1VjMUvfKvpfy+jM= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8= golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -229,11 +271,13 @@ golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210420072515-93ed5bcd2bfe/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-20210616094352-59db8d763f22/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-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/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.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -242,12 +286,15 @@ golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 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.29.0 h1:L6pJp37ocefwRRtYPKSWOWzOtWSxVajvz2ldH/xi3iU= golang.org/x/term v0.29.0/go.mod h1:6bl4lRlvVuDgSf3179VpIxBF0o10JUpXWOnI7nErv7s= 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.6/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.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM= golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY= golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 h1:vVKdlvoWBphwdxWKrFZEuM0kGgGLxUOYcY4U/2Vjg44= @@ -257,6 +304,8 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg= +golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -271,9 +320,15 @@ google.golang.org/grpc v1.64.1/go.mod h1:hiQF4LFZelK2WKaP6W0L92zGHtiQdZxk8CrSdvy google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM= google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/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/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +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.0-20200615113413-eeeca48fe776/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= gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU= diff --git a/internal/database/database.go b/internal/database/database.go index 176f133..36736c9 100644 --- a/internal/database/database.go +++ b/internal/database/database.go @@ -23,14 +23,13 @@ type service struct { } var ( - host = os.Getenv("BLUEPRINT_DB_HOST") - port = os.Getenv("BLUEPRINT_DB_PORT") - user = os.Getenv("BLUEPRINT_DB_USER") - pass = os.Getenv("BLUEPRINT_DB_PASS") - database = os.Getenv("BLUEPRINT_DB_NAME") + host = os.Getenv("BLUEPRINT_DB_HOST") + port = os.Getenv("BLUEPRINT_DB_PORT") + user = os.Getenv("BLUEPRINT_DB_USER") + pass = os.Getenv("BLUEPRINT_DB_PASS") ) -func New() Service { +func New(database string) Service { mongoURI := fmt.Sprintf("mongodb://%s:%s@%s:%s/%s?authSource=admin", user, pass, host, port, database) diff --git a/internal/server/routes.go b/internal/server/routes.go index 64bd040..2e2af44 100644 --- a/internal/server/routes.go +++ b/internal/server/routes.go @@ -1,20 +1,26 @@ package server import ( + "github.com/gin-contrib/cors" + "github.com/gin-gonic/gin" + swaggerFiles "github.com/swaggo/files" + ginSwagger "github.com/swaggo/gin-swagger" + "mongotest/pkg/handlers/master_data" "mongotest/pkg/handlers/mongo" "mongotest/pkg/handlers/user" "net/http" - - "github.com/gin-contrib/cors" - "github.com/gin-gonic/gin" ) func (s *Server) RegisterRoutes() http.Handler { r := gin.Default() + r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) + r.POST("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) + r.PUT("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) + r.DELETE("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) + r.GET("/", s.HelloWorldHandler) - r.GET("/health", s.healthHandler) api := r.Group("/api") local := api.Group("/local") { @@ -23,6 +29,11 @@ func (s *Server) RegisterRoutes() http.Handler { local.GET("/getuser/:id", user.GetUserByID) local.POST("/insertuser", user.InsertUser) local.PUT("/updateuser", user.UpdateUser) + local.DELETE("/deleteuser", user.DeleteUser) + } + master := api.Group("/master") + { + master.POST("/createdocument", master_data.InsertDataMaster) } r.Use(cors.New(cors.Config{ AllowOrigins: []string{"*"}, // or specific domains like "http://example.com" @@ -40,7 +51,3 @@ func (s *Server) HelloWorldHandler(c *gin.Context) { c.JSON(http.StatusOK, resp) } - -func (s *Server) healthHandler(c *gin.Context) { - c.JSON(http.StatusOK, s.db.Health()) -} diff --git a/internal/server/server.go b/internal/server/server.go index 77c1b7e..7a94652 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -8,22 +8,16 @@ import ( "time" _ "github.com/joho/godotenv/autoload" - - "mongotest/internal/database" ) type Server struct { port int - - db database.Service } func NewServer() *http.Server { port, _ := strconv.Atoi(os.Getenv("PORT")) NewServer := &Server{ port: port, - - db: database.New(), } // Declare Server config diff --git a/pkg/database/mongo/master_data.go b/pkg/database/mongo/master_data.go new file mode 100644 index 0000000..7d1c361 --- /dev/null +++ b/pkg/database/mongo/master_data.go @@ -0,0 +1,24 @@ +package mongo + +import ( + "context" + "log" + "mongotest/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 +} diff --git a/pkg/database/mongo/user.go b/pkg/database/mongo/user.go index f879880..58adf15 100644 --- a/pkg/database/mongo/user.go +++ b/pkg/database/mongo/user.go @@ -12,10 +12,12 @@ 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, + ID: req.ID, + Name: req.Name, + Age: req.Age, + Address: req.Address, + Gender: req.Gender, + Religion: req.Religion, }) if err != nil { log.Println(err) @@ -53,14 +55,17 @@ func (s *DatabaseService) GetUserById(id string) (*user.User, error) { return user, nil } -func (s *DatabaseService) UpdateUser(reqUpdate *user.User) error { +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, + "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 { @@ -70,3 +75,14 @@ func (s *DatabaseService) UpdateUser(reqUpdate *user.User) error { 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 +} diff --git a/pkg/handlers/master_data/master_data.go b/pkg/handlers/master_data/master_data.go new file mode 100644 index 0000000..3140fc3 --- /dev/null +++ b/pkg/handlers/master_data/master_data.go @@ -0,0 +1,33 @@ +package master_data + +import ( + "github.com/gin-gonic/gin" + "github.com/google/uuid" + "mongotest/internal/database" + "mongotest/pkg/database/mongo" + "mongotest/pkg/models/master_data" + "net/http" + "os" +) + +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"}) +} diff --git a/pkg/handlers/mongo/mongo.go b/pkg/handlers/mongo/mongo.go index b4bb4c0..6c18b35 100644 --- a/pkg/handlers/mongo/mongo.go +++ b/pkg/handlers/mongo/mongo.go @@ -1,22 +1,41 @@ package mongo import ( + "context" "github.com/gin-gonic/gin" + "go.mongodb.org/mongo-driver/bson" + "log" "mongotest/internal/database" "mongotest/pkg/database/mongo" + "mongotest/pkg/models/local" "net/http" + "os" + "time" ) func GetDataLog(c *gin.Context) { - db := database.New().GetDB() + 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) - dataLog, err := mongoDB.GetDataLog() + 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 { - c.JSON(http.StatusInternalServerError, gin.H{"message": err.Error()}) + 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) diff --git a/pkg/handlers/user/user.go b/pkg/handlers/user/user.go index 075b209..82c807c 100644 --- a/pkg/handlers/user/user.go +++ b/pkg/handlers/user/user.go @@ -8,10 +8,23 @@ import ( "mongotest/pkg/database/mongo" "mongotest/pkg/models/user" "net/http" + "os" ) +// 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) { - db := database.New().GetDB() + 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 @@ -38,8 +51,17 @@ func InsertUser(c *gin.Context) { 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) { - db := database.New().GetDB() + 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 @@ -55,8 +77,18 @@ func GetAllUser(c *gin.Context) { 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) { - db := database.New().GetDB() + 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 @@ -74,14 +106,26 @@ func GetUserByID(c *gin.Context) { 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) { - db := database.New().GetDB() + 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.User + var reqUpdate *user.ReqUpdateUser errBind := c.Bind(&reqUpdate) if errBind != nil { c.JSON(400, gin.H{ @@ -89,6 +133,7 @@ func UpdateUser(c *gin.Context) { }) return } + log.Println("REQ UPDATE", reqUpdate) errUpdate := mongoDB.UpdateUser(reqUpdate) if errUpdate != nil { c.JSON(400, gin.H{ @@ -98,3 +143,26 @@ func UpdateUser(c *gin.Context) { } 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"}) +} diff --git a/pkg/models/master_data/master_data.go b/pkg/models/master_data/master_data.go new file mode 100644 index 0000000..e6ba46b --- /dev/null +++ b/pkg/models/master_data/master_data.go @@ -0,0 +1,16 @@ +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"` +} diff --git a/pkg/models/user/user.go b/pkg/models/user/user.go index ffa8ffe..ef26d9a 100644 --- a/pkg/models/user/user.go +++ b/pkg/models/user/user.go @@ -1,15 +1,33 @@ package user type User struct { - ID string `bson:"_id"` - Name string `bson:"name"` - Age int `bson:"age"` - Address string `bson:"address"` + 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"` + 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"` }