Spaces:
Configuration error
Configuration error
Commit ·
49102c7
1
Parent(s): 6f9e96f
Deploy files from GitHub repository
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- README.md +71 -8
- config/DatabaseConfig.go +17 -17
- controller/LoginController.go +2 -2
- controller/RegisterController.go +2 -2
- controller/controller.go +3 -3
- go.mod +25 -25
- go.sum +49 -71
- main.go +2 -2
- middleware/AuthMiddleware.go +13 -12
- repositories/AccountRepository.go +1 -1
- repositories/DatabaseScoope.go +1 -1
- repositories/repositories.go +1 -1
- router/router.go +2 -2
- services/LoginService.go +3 -3
- services/RegisterService.go +3 -3
- services/services.go +1 -1
- space/models/ExceptionModel.go +8 -7
- space/services/RegisterService.go +5 -0
- space/space/repositories/AccountRepository.go +2 -2
- space/space/repositories/repositories.go +0 -7
- space/space/services/LoginService.go +1 -1
- space/space/services/RegisterService.go +2 -0
- space/space/space/go.mod +1 -0
- space/space/space/go.sum +2 -0
- space/space/space/models/DatabaseModel.go +17 -5
- space/space/space/repositories/AccountRepository.go +0 -3
- space/space/space/services/RegisterService.go +3 -2
- space/space/space/space/controller/LoginController.go +5 -5
- space/space/space/space/controller/RegisterController.go +5 -5
- space/space/space/space/controller/controller.go +5 -2
- space/space/space/space/models/DatabaseModel.go +1 -1
- space/space/space/space/repositories/AccountRepository.go +7 -2
- space/space/space/space/repositories/repositories.go +18 -5
- space/space/space/space/services/LoginService.go +1 -2
- space/space/space/space/services/RegisterService.go +0 -4
- space/space/space/space/space/controller/LoginController.go +1 -1
- space/space/space/space/space/controller/controller.go +2 -0
- space/space/space/space/space/middleware/AuthMiddleware.go +1 -1
- space/space/space/space/space/models/DatabaseModel.go +5 -8
- space/space/space/space/space/models/ResponseModel.go +5 -0
- space/space/space/space/space/repositories/AccountRepository.go +3 -5
- space/space/space/space/space/repositories/repositories.go +32 -21
- space/space/space/space/space/services/LoginService.go +14 -2
- space/space/space/space/space/services/RegisterService.go +6 -1
- space/space/space/space/space/space/space/Dockerfile +2 -2
- space/space/space/space/space/space/space/space/controller/HomeController.go +1 -1
- space/space/space/space/space/space/space/space/router/router.go +2 -1
- space/space/space/space/space/space/space/space/space/.env.example +9 -0
- space/space/space/space/space/space/space/space/space/.github/workflows/main.yml +52 -0
- space/space/space/space/space/space/space/space/space/.gitignore +3 -0
README.md
CHANGED
|
@@ -1,8 +1,71 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Golang API Boilerplate
|
| 2 |
+
This is a boilerplate for a RESTful API written in Golang.
|
| 3 |
+
|
| 4 |
+
## Features
|
| 5 |
+
- [x] JWT Authentication
|
| 6 |
+
- [x] PostgreSQL Database
|
| 7 |
+
- [x] GORM ORM
|
| 8 |
+
- [x] Gin Framework
|
| 9 |
+
- [x] Docker Support
|
| 10 |
+
- [x] Environment Variables
|
| 11 |
+
- [x] Logging
|
| 12 |
+
- [x] Error Handling
|
| 13 |
+
|
| 14 |
+
## Getting Started
|
| 15 |
+
1. Clone the repository
|
| 16 |
+
2. Run `go get` to download the dependencies
|
| 17 |
+
3. Create a file named `.env` and add the following variables:
|
| 18 |
+
* `DB_HOST`
|
| 19 |
+
* `DB_USER`
|
| 20 |
+
* `DB_PASSWORD`
|
| 21 |
+
* `DB_NAME`
|
| 22 |
+
* `DB_PORT`
|
| 23 |
+
* `SALT`
|
| 24 |
+
* `HOST_ADDRESS`
|
| 25 |
+
* `HOST_PORT`
|
| 26 |
+
* `LOG_PATH`
|
| 27 |
+
4. Run `go run main.go` to start the server
|
| 28 |
+
5. Open your browser and navigate to `http://localhost:HOST_PORT`
|
| 29 |
+
|
| 30 |
+
## API Endpoints
|
| 31 |
+
### Authentication
|
| 32 |
+
- `POST /login`: Login with email and password
|
| 33 |
+
- `POST /register`: Register a new user
|
| 34 |
+
- `GET /logout`: Logout
|
| 35 |
+
|
| 36 |
+
### Users
|
| 37 |
+
- `GET /users`: Get all users
|
| 38 |
+
- `GET /users/:id`: Get a user by ID
|
| 39 |
+
- `PUT /users/:id`: Update a user
|
| 40 |
+
- `DELETE /users/:id`: Delete a user
|
| 41 |
+
|
| 42 |
+
## Docker Support
|
| 43 |
+
You can build a Docker image by running `docker build -t my-api .` and then run it with `docker run -p 8080:8080 my-api`.
|
| 44 |
+
|
| 45 |
+
## Environment Variables
|
| 46 |
+
You can set the following environment variables:
|
| 47 |
+
- `DB_HOST`
|
| 48 |
+
- `DB_USER`
|
| 49 |
+
- `DB_PASSWORD`
|
| 50 |
+
- `DB_NAME`
|
| 51 |
+
- `DB_PORT`
|
| 52 |
+
- `SALT`
|
| 53 |
+
- `HOST_ADDRESS`
|
| 54 |
+
- `HOST_PORT`
|
| 55 |
+
- `LOG_PATH`
|
| 56 |
+
|
| 57 |
+
## Logging
|
| 58 |
+
The API uses the `log` package to log errors. You can set the `LOG_PATH` environment variable to specify the log file path.
|
| 59 |
+
|
| 60 |
+
## Error Handling
|
| 61 |
+
The API uses the `errors` package to handle errors. You can set the `ERROR_PATH` environment variable to specify the error file path.
|
| 62 |
+
|
| 63 |
+
# Command Documentation
|
| 64 |
+
|
| 65 |
+
## Update Golang Project version
|
| 66 |
+
> go mod edit -go 1.24
|
| 67 |
+
> go mod tidy
|
| 68 |
+
|
| 69 |
+
## Update all package
|
| 70 |
+
> go get -u ./...
|
| 71 |
+
> go mod tidy
|
config/DatabaseConfig.go
CHANGED
|
@@ -9,26 +9,10 @@ import (
|
|
| 9 |
"gorm.io/gorm"
|
| 10 |
"gorm.io/gorm/logger"
|
| 11 |
|
|
|
|
| 12 |
"github.com/joho/godotenv"
|
| 13 |
-
"go-dp.abdanhafidz.com/models"
|
| 14 |
)
|
| 15 |
|
| 16 |
-
func AutoMigrateAll(db *gorm.DB) {
|
| 17 |
-
// Enable logger to see SQL logs
|
| 18 |
-
db.Logger.LogMode(logger.Info)
|
| 19 |
-
|
| 20 |
-
// Auto-migrate all models
|
| 21 |
-
err := db.AutoMigrate(
|
| 22 |
-
&models.Account{},
|
| 23 |
-
&models.AccountDetails{},
|
| 24 |
-
)
|
| 25 |
-
if err != nil {
|
| 26 |
-
log.Fatal(err)
|
| 27 |
-
}
|
| 28 |
-
|
| 29 |
-
fmt.Println("Migration completed successfully.")
|
| 30 |
-
}
|
| 31 |
-
|
| 32 |
var DB *gorm.DB
|
| 33 |
var err error
|
| 34 |
var Salt string
|
|
@@ -58,3 +42,19 @@ func init() {
|
|
| 58 |
// Call AutoMigrateAll to perform auto-migration
|
| 59 |
AutoMigrateAll(DB)
|
| 60 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
"gorm.io/gorm"
|
| 10 |
"gorm.io/gorm/logger"
|
| 11 |
|
| 12 |
+
"api.qobiltu.id/models"
|
| 13 |
"github.com/joho/godotenv"
|
|
|
|
| 14 |
)
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
var DB *gorm.DB
|
| 17 |
var err error
|
| 18 |
var Salt string
|
|
|
|
| 42 |
// Call AutoMigrateAll to perform auto-migration
|
| 43 |
AutoMigrateAll(DB)
|
| 44 |
}
|
| 45 |
+
|
| 46 |
+
func AutoMigrateAll(db *gorm.DB) {
|
| 47 |
+
// Enable logger to see SQL logs
|
| 48 |
+
db.Logger.LogMode(logger.Info)
|
| 49 |
+
|
| 50 |
+
// Auto-migrate all models
|
| 51 |
+
err := db.AutoMigrate(
|
| 52 |
+
&models.Account{},
|
| 53 |
+
&models.AccountDetails{},
|
| 54 |
+
)
|
| 55 |
+
if err != nil {
|
| 56 |
+
log.Fatal(err)
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
fmt.Println("Migration completed successfully.")
|
| 60 |
+
}
|
controller/LoginController.go
CHANGED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
package controller
|
| 2 |
|
| 3 |
import (
|
|
|
|
|
|
|
| 4 |
"github.com/gin-gonic/gin"
|
| 5 |
-
"go-dp.abdanhafidz.com/models"
|
| 6 |
-
"go-dp.abdanhafidz.com/services"
|
| 7 |
)
|
| 8 |
|
| 9 |
func LoginController(c *gin.Context) {
|
|
|
|
| 1 |
package controller
|
| 2 |
|
| 3 |
import (
|
| 4 |
+
"api.qobiltu.id/models"
|
| 5 |
+
"api.qobiltu.id/services"
|
| 6 |
"github.com/gin-gonic/gin"
|
|
|
|
|
|
|
| 7 |
)
|
| 8 |
|
| 9 |
func LoginController(c *gin.Context) {
|
controller/RegisterController.go
CHANGED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
package controller
|
| 2 |
|
| 3 |
import (
|
|
|
|
|
|
|
| 4 |
"github.com/gin-gonic/gin"
|
| 5 |
-
"go-dp.abdanhafidz.com/models"
|
| 6 |
-
"go-dp.abdanhafidz.com/services"
|
| 7 |
)
|
| 8 |
|
| 9 |
func RegisterController(c *gin.Context) {
|
|
|
|
| 1 |
package controller
|
| 2 |
|
| 3 |
import (
|
| 4 |
+
"api.qobiltu.id/models"
|
| 5 |
+
"api.qobiltu.id/services"
|
| 6 |
"github.com/gin-gonic/gin"
|
|
|
|
|
|
|
| 7 |
)
|
| 8 |
|
| 9 |
func RegisterController(c *gin.Context) {
|
controller/controller.go
CHANGED
|
@@ -1,10 +1,10 @@
|
|
| 1 |
package controller
|
| 2 |
|
| 3 |
import (
|
|
|
|
|
|
|
|
|
|
| 4 |
"github.com/gin-gonic/gin"
|
| 5 |
-
"go-dp.abdanhafidz.com/models"
|
| 6 |
-
"go-dp.abdanhafidz.com/services"
|
| 7 |
-
"go-dp.abdanhafidz.com/utils"
|
| 8 |
)
|
| 9 |
|
| 10 |
type (
|
|
|
|
| 1 |
package controller
|
| 2 |
|
| 3 |
import (
|
| 4 |
+
"api.qobiltu.id/models"
|
| 5 |
+
"api.qobiltu.id/services"
|
| 6 |
+
"api.qobiltu.id/utils"
|
| 7 |
"github.com/gin-gonic/gin"
|
|
|
|
|
|
|
|
|
|
| 8 |
)
|
| 9 |
|
| 10 |
type (
|
go.mod
CHANGED
|
@@ -1,49 +1,49 @@
|
|
| 1 |
-
module
|
| 2 |
|
| 3 |
-
go 1.
|
| 4 |
|
| 5 |
require (
|
| 6 |
-
github.com/
|
| 7 |
-
github.com/
|
| 8 |
github.com/joho/godotenv v1.5.1
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
gorm.io/
|
|
|
|
| 12 |
)
|
| 13 |
|
| 14 |
require (
|
| 15 |
-
github.com/bytedance/sonic v1.
|
| 16 |
-
github.com/
|
| 17 |
-
github.com/
|
| 18 |
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
|
| 19 |
-
github.com/gin-contrib/sse
|
| 20 |
github.com/go-playground/locales v0.14.1 // indirect
|
| 21 |
github.com/go-playground/universal-translator v0.18.1 // indirect
|
| 22 |
github.com/go-playground/validator/v10 v10.25.0 // indirect
|
| 23 |
-
github.com/goccy/go-json v0.10.
|
| 24 |
github.com/jackc/pgpassfile v1.0.0 // indirect
|
| 25 |
-
github.com/jackc/pgservicefile v0.0.0-
|
| 26 |
-
github.com/jackc/pgx/v5 v5.
|
| 27 |
-
github.com/jackc/puddle/v2 v2.2.
|
| 28 |
github.com/jinzhu/inflection v1.0.0 // indirect
|
| 29 |
github.com/jinzhu/now v1.1.5 // indirect
|
| 30 |
github.com/json-iterator/go v1.1.12 // indirect
|
| 31 |
-
github.com/klauspost/cpuid/v2 v2.2.
|
| 32 |
github.com/kr/text v0.2.0 // indirect
|
| 33 |
github.com/leodido/go-urn v1.4.0 // indirect
|
| 34 |
github.com/mattn/go-isatty v0.0.20 // indirect
|
| 35 |
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
| 36 |
github.com/modern-go/reflect2 v1.0.2 // indirect
|
| 37 |
-
github.com/pelletier/go-toml/v2 v2.
|
| 38 |
github.com/rogpeppe/go-internal v1.11.0 // indirect
|
| 39 |
-
github.com/satori/go.uuid v1.2.0 // indirect
|
| 40 |
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
| 41 |
-
github.com/ugorji/go/codec v1.2.
|
| 42 |
-
golang.org/x/arch v0.
|
| 43 |
-
golang.org/x/net v0.
|
| 44 |
-
golang.org/x/sync v0.
|
| 45 |
-
golang.org/x/sys v0.
|
| 46 |
-
golang.org/x/text v0.
|
| 47 |
-
google.golang.org/protobuf v1.
|
| 48 |
gopkg.in/yaml.v3 v3.0.1 // indirect
|
| 49 |
)
|
|
|
|
| 1 |
+
module api.qobiltu.id
|
| 2 |
|
| 3 |
+
go 1.24
|
| 4 |
|
| 5 |
require (
|
| 6 |
+
github.com/gin-gonic/gin v1.10.0
|
| 7 |
+
github.com/golang-jwt/jwt/v5 v5.2.1
|
| 8 |
github.com/joho/godotenv v1.5.1
|
| 9 |
+
github.com/satori/go.uuid v1.2.0
|
| 10 |
+
golang.org/x/crypto v0.36.0
|
| 11 |
+
gorm.io/driver/postgres v1.5.11
|
| 12 |
+
gorm.io/gorm v1.25.12
|
| 13 |
)
|
| 14 |
|
| 15 |
require (
|
| 16 |
+
github.com/bytedance/sonic v1.13.1 // indirect
|
| 17 |
+
github.com/bytedance/sonic/loader v0.2.4 // indirect
|
| 18 |
+
github.com/cloudwego/base64x v0.1.5 // indirect
|
| 19 |
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
|
| 20 |
+
github.com/gin-contrib/sse v1.0.0 // indirect
|
| 21 |
github.com/go-playground/locales v0.14.1 // indirect
|
| 22 |
github.com/go-playground/universal-translator v0.18.1 // indirect
|
| 23 |
github.com/go-playground/validator/v10 v10.25.0 // indirect
|
| 24 |
+
github.com/goccy/go-json v0.10.5 // indirect
|
| 25 |
github.com/jackc/pgpassfile v1.0.0 // indirect
|
| 26 |
+
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
| 27 |
+
github.com/jackc/pgx/v5 v5.7.2 // indirect
|
| 28 |
+
github.com/jackc/puddle/v2 v2.2.2 // indirect
|
| 29 |
github.com/jinzhu/inflection v1.0.0 // indirect
|
| 30 |
github.com/jinzhu/now v1.1.5 // indirect
|
| 31 |
github.com/json-iterator/go v1.1.12 // indirect
|
| 32 |
+
github.com/klauspost/cpuid/v2 v2.2.10 // indirect
|
| 33 |
github.com/kr/text v0.2.0 // indirect
|
| 34 |
github.com/leodido/go-urn v1.4.0 // indirect
|
| 35 |
github.com/mattn/go-isatty v0.0.20 // indirect
|
| 36 |
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
| 37 |
github.com/modern-go/reflect2 v1.0.2 // indirect
|
| 38 |
+
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
|
| 39 |
github.com/rogpeppe/go-internal v1.11.0 // indirect
|
|
|
|
| 40 |
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
| 41 |
+
github.com/ugorji/go/codec v1.2.12 // indirect
|
| 42 |
+
golang.org/x/arch v0.15.0 // indirect
|
| 43 |
+
golang.org/x/net v0.37.0 // indirect
|
| 44 |
+
golang.org/x/sync v0.12.0 // indirect
|
| 45 |
+
golang.org/x/sys v0.31.0 // indirect
|
| 46 |
+
golang.org/x/text v0.23.0 // indirect
|
| 47 |
+
google.golang.org/protobuf v1.36.5 // indirect
|
| 48 |
gopkg.in/yaml.v3 v3.0.1 // indirect
|
| 49 |
)
|
go.sum
CHANGED
|
@@ -1,51 +1,44 @@
|
|
| 1 |
-
github.com/bytedance/sonic v1.
|
| 2 |
-
github.com/bytedance/sonic v1.
|
| 3 |
-
github.com/bytedance/sonic
|
| 4 |
-
github.com/bytedance/sonic
|
| 5 |
-
github.com/
|
| 6 |
-
github.com/
|
| 7 |
-
github.com/
|
| 8 |
-
github.com/
|
| 9 |
-
github.com/chenzhuoyu/iasm v0.9.0 h1:9fhXjVzq5hUy2gkhhgHl95zG2cEAhw9OSGs8toWWAwo=
|
| 10 |
-
github.com/chenzhuoyu/iasm v0.9.0/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog=
|
| 11 |
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
| 12 |
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
| 13 |
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
| 14 |
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
| 15 |
-
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
|
| 16 |
-
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
| 17 |
-
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
|
| 18 |
-
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
|
| 19 |
github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM=
|
| 20 |
github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8=
|
| 21 |
-
github.com/gin-contrib/sse
|
| 22 |
-
github.com/gin-contrib/sse
|
| 23 |
-
github.com/gin-gonic/gin v1.
|
| 24 |
-
github.com/gin-gonic/gin v1.
|
| 25 |
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
| 26 |
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
| 27 |
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
| 28 |
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
|
| 29 |
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
|
| 30 |
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
|
| 31 |
-
github.com/go-playground/validator/v10 v10.16.0 h1:x+plE831WK4vaKHO/jpgUGsvLKIqRRkz6M78GuJAfGE=
|
| 32 |
-
github.com/go-playground/validator/v10 v10.16.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
|
| 33 |
github.com/go-playground/validator/v10 v10.25.0 h1:5Dh7cjvzR7BRZadnsVOzPhWsrwUr0nmsZJxEAnFLNO8=
|
| 34 |
github.com/go-playground/validator/v10 v10.25.0/go.mod h1:GGzBIJMuE98Ic/kJsBXbz1x/7cByt++cQ+YOuDM5wus=
|
| 35 |
-
github.com/goccy/go-json v0.10.
|
| 36 |
-
github.com/goccy/go-json v0.10.
|
| 37 |
-
github.com/golang/
|
|
|
|
| 38 |
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
| 39 |
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
| 40 |
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
| 41 |
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
| 42 |
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
| 43 |
-
github.com/jackc/pgservicefile v0.0.0-
|
| 44 |
-
github.com/jackc/pgservicefile v0.0.0-
|
| 45 |
-
github.com/jackc/pgx/v5 v5.
|
| 46 |
-
github.com/jackc/pgx/v5 v5.
|
| 47 |
-
github.com/jackc/puddle/v2 v2.2.
|
| 48 |
-
github.com/jackc/puddle/v2 v2.2.
|
| 49 |
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
|
| 50 |
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
|
| 51 |
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
|
|
@@ -55,15 +48,13 @@ github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwA
|
|
| 55 |
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
| 56 |
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
| 57 |
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
| 58 |
-
github.com/klauspost/cpuid/v2 v2.2.
|
| 59 |
-
github.com/klauspost/cpuid/v2 v2.2.
|
| 60 |
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
|
| 61 |
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
|
| 62 |
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
|
| 63 |
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
| 64 |
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
| 65 |
-
github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
|
| 66 |
-
github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
|
| 67 |
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
|
| 68 |
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
|
| 69 |
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
|
@@ -73,8 +64,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w
|
|
| 73 |
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
| 74 |
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
| 75 |
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
| 76 |
-
github.com/pelletier/go-toml/v2 v2.
|
| 77 |
-
github.com/pelletier/go-toml/v2 v2.
|
| 78 |
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
| 79 |
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
| 80 |
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
|
|
@@ -84,57 +75,44 @@ github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdh
|
|
| 84 |
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
| 85 |
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
| 86 |
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
|
|
|
| 87 |
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
| 88 |
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
| 89 |
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
| 90 |
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
| 91 |
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
| 92 |
-
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
| 93 |
-
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
| 94 |
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
|
|
|
|
|
|
| 95 |
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
|
| 96 |
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
|
| 97 |
-
github.com/ugorji/go/codec v1.2.
|
| 98 |
-
github.com/ugorji/go/codec v1.2.
|
| 99 |
-
golang.org/x/arch v0.
|
| 100 |
-
golang.org/x/arch v0.
|
| 101 |
-
golang.org/x/
|
| 102 |
-
golang.org/x/crypto v0.
|
| 103 |
-
golang.org/x/
|
| 104 |
-
golang.org/x/
|
| 105 |
-
golang.org/x/
|
| 106 |
-
golang.org/x/
|
| 107 |
-
golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ=
|
| 108 |
-
golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=
|
| 109 |
-
golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=
|
| 110 |
-
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
|
| 111 |
-
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
| 112 |
-
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
|
| 113 |
-
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
| 114 |
-
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
| 115 |
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
| 116 |
-
golang.org/x/sys v0.
|
| 117 |
-
golang.org/x/sys v0.
|
| 118 |
-
golang.org/x/
|
| 119 |
-
golang.org/x/
|
| 120 |
-
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
|
| 121 |
-
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
| 122 |
-
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
|
| 123 |
-
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
|
| 124 |
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
| 125 |
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
| 126 |
-
google.golang.org/protobuf v1.
|
| 127 |
-
google.golang.org/protobuf v1.
|
| 128 |
-
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
| 129 |
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
| 130 |
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
| 131 |
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
| 132 |
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
| 133 |
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
| 134 |
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
| 135 |
-
gorm.io/driver/postgres v1.5.
|
| 136 |
-
gorm.io/driver/postgres v1.5.
|
| 137 |
-
gorm.io/gorm v1.25.
|
| 138 |
-
gorm.io/gorm v1.25.
|
| 139 |
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
|
| 140 |
-
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
|
|
|
|
| 1 |
+
github.com/bytedance/sonic v1.13.1 h1:Jyd5CIvdFnkOWuKXr+wm4Nyk2h0yAFsr8ucJgEasO3g=
|
| 2 |
+
github.com/bytedance/sonic v1.13.1/go.mod h1:o68xyaF9u2gvVBuGHPlUVCy+ZfmNNO5ETf1+KgkJhz4=
|
| 3 |
+
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
|
| 4 |
+
github.com/bytedance/sonic/loader v0.2.4 h1:ZWCw4stuXUsn1/+zQDqeE7JKP+QO47tz7QCNan80NzY=
|
| 5 |
+
github.com/bytedance/sonic/loader v0.2.4/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI=
|
| 6 |
+
github.com/cloudwego/base64x v0.1.5 h1:XPciSp1xaq2VCSt6lF0phncD4koWyULpl5bUxbfCyP4=
|
| 7 |
+
github.com/cloudwego/base64x v0.1.5/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
|
| 8 |
+
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
|
|
|
|
|
|
|
| 9 |
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
| 10 |
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
| 11 |
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
| 12 |
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM=
|
| 14 |
github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8=
|
| 15 |
+
github.com/gin-contrib/sse v1.0.0 h1:y3bT1mUWUxDpW4JLQg/HnTqV4rozuW4tC9eFKTxYI9E=
|
| 16 |
+
github.com/gin-contrib/sse v1.0.0/go.mod h1:zNuFdwarAygJBht0NTKiSi3jRf6RbqeILZ9Sp6Slhe0=
|
| 17 |
+
github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU=
|
| 18 |
+
github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
|
| 19 |
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
|
| 20 |
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
| 21 |
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
|
| 22 |
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
|
| 23 |
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
|
| 24 |
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
|
|
|
|
|
|
|
| 25 |
github.com/go-playground/validator/v10 v10.25.0 h1:5Dh7cjvzR7BRZadnsVOzPhWsrwUr0nmsZJxEAnFLNO8=
|
| 26 |
github.com/go-playground/validator/v10 v10.25.0/go.mod h1:GGzBIJMuE98Ic/kJsBXbz1x/7cByt++cQ+YOuDM5wus=
|
| 27 |
+
github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4=
|
| 28 |
+
github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
|
| 29 |
+
github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
|
| 30 |
+
github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
|
| 31 |
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
| 32 |
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
| 33 |
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
| 34 |
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
| 35 |
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
| 36 |
+
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
|
| 37 |
+
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
|
| 38 |
+
github.com/jackc/pgx/v5 v5.7.2 h1:mLoDLV6sonKlvjIEsV56SkWNCnuNv531l94GaIzO+XI=
|
| 39 |
+
github.com/jackc/pgx/v5 v5.7.2/go.mod h1:ncY89UGWxg82EykZUwSpUKEfccBGGYq1xjrOpsbsfGQ=
|
| 40 |
+
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
|
| 41 |
+
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
|
| 42 |
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
|
| 43 |
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
|
| 44 |
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
|
|
|
|
| 48 |
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
| 49 |
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
| 50 |
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
| 51 |
+
github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE=
|
| 52 |
+
github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
|
| 53 |
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
|
| 54 |
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
|
| 55 |
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
|
| 56 |
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
| 57 |
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
|
|
|
|
|
|
| 58 |
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
|
| 59 |
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
|
| 60 |
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
|
|
|
| 64 |
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
| 65 |
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
| 66 |
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
| 67 |
+
github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=
|
| 68 |
+
github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=
|
| 69 |
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
| 70 |
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
| 71 |
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
|
|
|
|
| 75 |
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
| 76 |
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
| 77 |
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
| 78 |
+
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
|
| 79 |
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
| 80 |
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
| 81 |
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
| 82 |
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
| 83 |
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
|
|
|
|
|
|
| 84 |
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
| 85 |
+
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
| 86 |
+
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
| 87 |
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
|
| 88 |
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
|
| 89 |
+
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
|
| 90 |
+
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
|
| 91 |
+
golang.org/x/arch v0.15.0 h1:QtOrQd0bTUnhNVNndMpLHNWrDmYzZ2KDqSrEymqInZw=
|
| 92 |
+
golang.org/x/arch v0.15.0/go.mod h1:JmwW7aLIoRUKgaTzhkiEFxvcEiQGyOg9BMonBJUS7EE=
|
| 93 |
+
golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34=
|
| 94 |
+
golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=
|
| 95 |
+
golang.org/x/net v0.37.0 h1:1zLorHbz+LYj7MQlSf1+2tPIIgibq2eL5xkrGk6f+2c=
|
| 96 |
+
golang.org/x/net v0.37.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
|
| 97 |
+
golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw=
|
| 98 |
+
golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
| 100 |
+
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
|
| 101 |
+
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
| 102 |
+
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
|
| 103 |
+
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
| 105 |
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
| 106 |
+
google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM=
|
| 107 |
+
google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
|
|
|
| 108 |
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
| 109 |
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
| 110 |
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
| 111 |
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
| 112 |
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
| 113 |
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
| 114 |
+
gorm.io/driver/postgres v1.5.11 h1:ubBVAfbKEUld/twyKZ0IYn9rSQh448EdelLYk9Mv314=
|
| 115 |
+
gorm.io/driver/postgres v1.5.11/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI=
|
| 116 |
+
gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8=
|
| 117 |
+
gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ=
|
| 118 |
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
|
|
|
main.go
CHANGED
|
@@ -3,8 +3,8 @@ package main
|
|
| 3 |
import (
|
| 4 |
"fmt"
|
| 5 |
|
| 6 |
-
"
|
| 7 |
-
"
|
| 8 |
)
|
| 9 |
|
| 10 |
func main() {
|
|
|
|
| 3 |
import (
|
| 4 |
"fmt"
|
| 5 |
|
| 6 |
+
"api.qobiltu.id/config"
|
| 7 |
+
"api.qobiltu.id/router"
|
| 8 |
)
|
| 9 |
|
| 10 |
func main() {
|
middleware/AuthMiddleware.go
CHANGED
|
@@ -6,10 +6,10 @@ import (
|
|
| 6 |
"errors"
|
| 7 |
"time"
|
| 8 |
|
| 9 |
-
"
|
|
|
|
| 10 |
"github.com/gin-gonic/gin"
|
| 11 |
-
"
|
| 12 |
-
"go-dp.abdanhafidz.com/models"
|
| 13 |
"golang.org/x/crypto/bcrypt"
|
| 14 |
)
|
| 15 |
|
|
@@ -51,8 +51,8 @@ func HashPassword(password string) (string, error) {
|
|
| 51 |
}
|
| 52 |
|
| 53 |
type CustomClaims struct {
|
| 54 |
-
jwt.
|
| 55 |
-
|
| 56 |
}
|
| 57 |
|
| 58 |
func VerifyToken(bearer_token string) (int, string, error) {
|
|
@@ -63,33 +63,34 @@ func VerifyToken(bearer_token string) (int, string, error) {
|
|
| 63 |
if err != nil {
|
| 64 |
return 0, "invalid-token", err
|
| 65 |
}
|
|
|
|
|
|
|
| 66 |
claims, ok := token.Claims.(*CustomClaims)
|
| 67 |
if !ok || !token.Valid {
|
| 68 |
return 0, "invalid-token", err
|
| 69 |
-
}
|
|
|
|
| 70 |
return 0, "expired", err
|
| 71 |
-
} else if !ok && token.Valid {
|
| 72 |
-
return 0, "invalid-token", err
|
| 73 |
}
|
| 74 |
|
| 75 |
-
return claims.
|
| 76 |
}
|
| 77 |
|
| 78 |
func AuthUser(c *gin.Context) {
|
| 79 |
var currAccData models.AccountData
|
| 80 |
if c.Request.Header["Auth-Bearer-Token"] != nil {
|
| 81 |
token := c.Request.Header["Auth-Bearer-Token"]
|
| 82 |
-
currAccData.
|
| 83 |
// fmt.Println("Verify Status :", currAccData.verifyStatus)
|
| 84 |
if currAccData.VerifyStatus == "invalid-token" || currAccData.VerifyStatus == "expired" {
|
| 85 |
-
currAccData.
|
| 86 |
message := "Your session is expired, Please re-Login!"
|
| 87 |
SendJSON401(c, &currAccData.VerifyStatus, &message)
|
| 88 |
c.Abort()
|
| 89 |
return
|
| 90 |
}
|
| 91 |
} else {
|
| 92 |
-
currAccData.
|
| 93 |
currAccData.VerifyStatus = "no-token"
|
| 94 |
currAccData.ErrVerif = nil
|
| 95 |
message := "You have to Login First!"
|
|
|
|
| 6 |
"errors"
|
| 7 |
"time"
|
| 8 |
|
| 9 |
+
"api.qobiltu.id/config"
|
| 10 |
+
"api.qobiltu.id/models"
|
| 11 |
"github.com/gin-gonic/gin"
|
| 12 |
+
"github.com/golang-jwt/jwt/v5"
|
|
|
|
| 13 |
"golang.org/x/crypto/bcrypt"
|
| 14 |
)
|
| 15 |
|
|
|
|
| 51 |
}
|
| 52 |
|
| 53 |
type CustomClaims struct {
|
| 54 |
+
jwt.RegisteredClaims
|
| 55 |
+
UserID int `json:"id"`
|
| 56 |
}
|
| 57 |
|
| 58 |
func VerifyToken(bearer_token string) (int, string, error) {
|
|
|
|
| 63 |
if err != nil {
|
| 64 |
return 0, "invalid-token", err
|
| 65 |
}
|
| 66 |
+
|
| 67 |
+
// Extract the claims
|
| 68 |
claims, ok := token.Claims.(*CustomClaims)
|
| 69 |
if !ok || !token.Valid {
|
| 70 |
return 0, "invalid-token", err
|
| 71 |
+
}
|
| 72 |
+
if claims.ExpiresAt != nil && claims.ExpiresAt.Time.Before(time.Now()) {
|
| 73 |
return 0, "expired", err
|
|
|
|
|
|
|
| 74 |
}
|
| 75 |
|
| 76 |
+
return claims.UserID, "valid", err
|
| 77 |
}
|
| 78 |
|
| 79 |
func AuthUser(c *gin.Context) {
|
| 80 |
var currAccData models.AccountData
|
| 81 |
if c.Request.Header["Auth-Bearer-Token"] != nil {
|
| 82 |
token := c.Request.Header["Auth-Bearer-Token"]
|
| 83 |
+
currAccData.UserID, currAccData.VerifyStatus, currAccData.ErrVerif = VerifyToken(token[0])
|
| 84 |
// fmt.Println("Verify Status :", currAccData.verifyStatus)
|
| 85 |
if currAccData.VerifyStatus == "invalid-token" || currAccData.VerifyStatus == "expired" {
|
| 86 |
+
currAccData.UserID = 0
|
| 87 |
message := "Your session is expired, Please re-Login!"
|
| 88 |
SendJSON401(c, &currAccData.VerifyStatus, &message)
|
| 89 |
c.Abort()
|
| 90 |
return
|
| 91 |
}
|
| 92 |
} else {
|
| 93 |
+
currAccData.UserID = 0
|
| 94 |
currAccData.VerifyStatus = "no-token"
|
| 95 |
currAccData.ErrVerif = nil
|
| 96 |
message := "You have to Login First!"
|
repositories/AccountRepository.go
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
package repositories
|
| 2 |
|
| 3 |
import (
|
| 4 |
-
"
|
| 5 |
)
|
| 6 |
|
| 7 |
func GetAccountbyEmail(email string) Repository[models.Account, models.Account] {
|
|
|
|
| 1 |
package repositories
|
| 2 |
|
| 3 |
import (
|
| 4 |
+
"api.qobiltu.id/models"
|
| 5 |
)
|
| 6 |
|
| 7 |
func GetAccountbyEmail(email string) Repository[models.Account, models.Account] {
|
repositories/DatabaseScoope.go
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
package repositories
|
| 2 |
|
| 3 |
-
import "
|
| 4 |
|
| 5 |
var db = config.DB
|
|
|
|
| 1 |
package repositories
|
| 2 |
|
| 3 |
+
import "api.qobiltu.id/config"
|
| 4 |
|
| 5 |
var db = config.DB
|
repositories/repositories.go
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
package repositories
|
| 2 |
|
| 3 |
import (
|
| 4 |
-
"
|
| 5 |
"gorm.io/gorm"
|
| 6 |
)
|
| 7 |
|
|
|
|
| 1 |
package repositories
|
| 2 |
|
| 3 |
import (
|
| 4 |
+
"api.qobiltu.id/config"
|
| 5 |
"gorm.io/gorm"
|
| 6 |
)
|
| 7 |
|
router/router.go
CHANGED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
package router
|
| 2 |
|
| 3 |
import (
|
|
|
|
|
|
|
| 4 |
"github.com/gin-gonic/gin"
|
| 5 |
-
"go-dp.abdanhafidz.com/config"
|
| 6 |
-
"go-dp.abdanhafidz.com/controller"
|
| 7 |
)
|
| 8 |
|
| 9 |
func StartService() {
|
|
|
|
| 1 |
package router
|
| 2 |
|
| 3 |
import (
|
| 4 |
+
"api.qobiltu.id/config"
|
| 5 |
+
"api.qobiltu.id/controller"
|
| 6 |
"github.com/gin-gonic/gin"
|
|
|
|
|
|
|
| 7 |
)
|
| 8 |
|
| 9 |
func StartService() {
|
services/LoginService.go
CHANGED
|
@@ -3,9 +3,9 @@ package services
|
|
| 3 |
import (
|
| 4 |
"errors"
|
| 5 |
|
| 6 |
-
"
|
| 7 |
-
"
|
| 8 |
-
"
|
| 9 |
)
|
| 10 |
|
| 11 |
type LoginConstructor struct {
|
|
|
|
| 3 |
import (
|
| 4 |
"errors"
|
| 5 |
|
| 6 |
+
"api.qobiltu.id/middleware"
|
| 7 |
+
"api.qobiltu.id/models"
|
| 8 |
+
"api.qobiltu.id/repositories"
|
| 9 |
)
|
| 10 |
|
| 11 |
type LoginConstructor struct {
|
services/RegisterService.go
CHANGED
|
@@ -3,10 +3,10 @@ package services
|
|
| 3 |
import (
|
| 4 |
"errors"
|
| 5 |
|
|
|
|
|
|
|
|
|
|
| 6 |
uuid "github.com/satori/go.uuid"
|
| 7 |
-
"go-dp.abdanhafidz.com/middleware"
|
| 8 |
-
"go-dp.abdanhafidz.com/models"
|
| 9 |
-
"go-dp.abdanhafidz.com/repositories"
|
| 10 |
"gorm.io/gorm"
|
| 11 |
)
|
| 12 |
|
|
|
|
| 3 |
import (
|
| 4 |
"errors"
|
| 5 |
|
| 6 |
+
"api.qobiltu.id/middleware"
|
| 7 |
+
"api.qobiltu.id/models"
|
| 8 |
+
"api.qobiltu.id/repositories"
|
| 9 |
uuid "github.com/satori/go.uuid"
|
|
|
|
|
|
|
|
|
|
| 10 |
"gorm.io/gorm"
|
| 11 |
)
|
| 12 |
|
services/services.go
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
package services
|
| 2 |
|
| 3 |
-
import "
|
| 4 |
|
| 5 |
type (
|
| 6 |
Services interface {
|
|
|
|
| 1 |
package services
|
| 2 |
|
| 3 |
+
import "api.qobiltu.id/models"
|
| 4 |
|
| 5 |
type (
|
| 6 |
Services interface {
|
space/models/ExceptionModel.go
CHANGED
|
@@ -1,11 +1,12 @@
|
|
| 1 |
package models
|
| 2 |
|
| 3 |
type Exception struct {
|
| 4 |
-
Unauthorized
|
| 5 |
-
BadRequest
|
| 6 |
-
DataNotFound
|
| 7 |
-
InternalServerError
|
| 8 |
-
DataDuplicate
|
| 9 |
-
QueryError
|
| 10 |
-
|
|
|
|
| 11 |
}
|
|
|
|
| 1 |
package models
|
| 2 |
|
| 3 |
type Exception struct {
|
| 4 |
+
Unauthorized bool `json:"unauthorized,omitempty"`
|
| 5 |
+
BadRequest bool `json:"bad_request,omitempty"`
|
| 6 |
+
DataNotFound bool `json:"data_not_found,omitempty"`
|
| 7 |
+
InternalServerError bool `json:"internal_server_error,omitempty"`
|
| 8 |
+
DataDuplicate bool `json:"data_duplicate,omitempty"`
|
| 9 |
+
QueryError bool `json:"query_error,omitempty"`
|
| 10 |
+
InvalidPasswordLength bool `json:"invalid_password_length,omitempty"`
|
| 11 |
+
Message string `json:"message,omitempty"`
|
| 12 |
}
|
space/services/RegisterService.go
CHANGED
|
@@ -15,6 +15,11 @@ type RegisterService struct {
|
|
| 15 |
}
|
| 16 |
|
| 17 |
func (s *RegisterService) Create() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
hashed_password, err_hash := middleware.HashPassword(s.Constructor.Password)
|
| 19 |
s.Error = err_hash
|
| 20 |
s.Constructor.Password = hashed_password
|
|
|
|
| 15 |
}
|
| 16 |
|
| 17 |
func (s *RegisterService) Create() {
|
| 18 |
+
if len(s.Constructor.Password) < 8 {
|
| 19 |
+
s.Exception.InvalidPasswordLength = true
|
| 20 |
+
s.Exception.Message = "Password must have at least 8 characters!"
|
| 21 |
+
return
|
| 22 |
+
}
|
| 23 |
hashed_password, err_hash := middleware.HashPassword(s.Constructor.Password)
|
| 24 |
s.Error = err_hash
|
| 25 |
s.Constructor.Password = hashed_password
|
space/space/repositories/AccountRepository.go
CHANGED
|
@@ -4,9 +4,9 @@ import (
|
|
| 4 |
"go-dp.abdanhafidz.com/models"
|
| 5 |
)
|
| 6 |
|
| 7 |
-
func
|
| 8 |
repo := Construct[models.Account, models.Account](
|
| 9 |
-
models.Account{Email: email
|
| 10 |
)
|
| 11 |
repo.Transactions(
|
| 12 |
WhereGivenConstructor[models.Account, models.Account],
|
|
|
|
| 4 |
"go-dp.abdanhafidz.com/models"
|
| 5 |
)
|
| 6 |
|
| 7 |
+
func GetAccountbyEmail(email string) Repository[models.Account, models.Account] {
|
| 8 |
repo := Construct[models.Account, models.Account](
|
| 9 |
+
models.Account{Email: email},
|
| 10 |
)
|
| 11 |
repo.Transactions(
|
| 12 |
WhereGivenConstructor[models.Account, models.Account],
|
space/space/repositories/repositories.go
CHANGED
|
@@ -1,8 +1,6 @@
|
|
| 1 |
package repositories
|
| 2 |
|
| 3 |
import (
|
| 4 |
-
"strconv"
|
| 5 |
-
|
| 6 |
"go-dp.abdanhafidz.com/config"
|
| 7 |
"gorm.io/gorm"
|
| 8 |
)
|
|
@@ -51,15 +49,10 @@ func Construct[TConstructor any, TResult any](constructor ...TConstructor) *Repo
|
|
| 51 |
}
|
| 52 |
}
|
| 53 |
func (repo *Repository[T1, T2]) Transactions(transactions ...func(*Repository[T1, T2]) *gorm.DB) {
|
| 54 |
-
i := 1
|
| 55 |
for _, tx := range transactions {
|
| 56 |
repo.Transaction = tx(repo)
|
| 57 |
if repo.RowsError != nil {
|
| 58 |
-
repo.Transaction.Rollback()
|
| 59 |
return
|
| 60 |
-
} else {
|
| 61 |
-
repo.Transaction.SavePoint("Save Point : " + strconv.Itoa(i))
|
| 62 |
-
repo.Transaction.Commit()
|
| 63 |
}
|
| 64 |
}
|
| 65 |
}
|
|
|
|
| 1 |
package repositories
|
| 2 |
|
| 3 |
import (
|
|
|
|
|
|
|
| 4 |
"go-dp.abdanhafidz.com/config"
|
| 5 |
"gorm.io/gorm"
|
| 6 |
)
|
|
|
|
| 49 |
}
|
| 50 |
}
|
| 51 |
func (repo *Repository[T1, T2]) Transactions(transactions ...func(*Repository[T1, T2]) *gorm.DB) {
|
|
|
|
| 52 |
for _, tx := range transactions {
|
| 53 |
repo.Transaction = tx(repo)
|
| 54 |
if repo.RowsError != nil {
|
|
|
|
| 55 |
return
|
|
|
|
|
|
|
|
|
|
| 56 |
}
|
| 57 |
}
|
| 58 |
}
|
space/space/services/LoginService.go
CHANGED
|
@@ -18,7 +18,7 @@ type AuthenticationService struct {
|
|
| 18 |
}
|
| 19 |
|
| 20 |
func (s *AuthenticationService) Authenticate() {
|
| 21 |
-
accountData := repositories.
|
| 22 |
if accountData.NoRecord {
|
| 23 |
s.Exception.DataNotFound = true
|
| 24 |
s.Exception.Message = "there is no account with given credentials!"
|
|
|
|
| 18 |
}
|
| 19 |
|
| 20 |
func (s *AuthenticationService) Authenticate() {
|
| 21 |
+
accountData := repositories.GetAccountbyEmail(s.Constructor.Email)
|
| 22 |
if accountData.NoRecord {
|
| 23 |
s.Exception.DataNotFound = true
|
| 24 |
s.Exception.Message = "there is no account with given credentials!"
|
space/space/services/RegisterService.go
CHANGED
|
@@ -3,6 +3,7 @@ package services
|
|
| 3 |
import (
|
| 4 |
"errors"
|
| 5 |
|
|
|
|
| 6 |
"go-dp.abdanhafidz.com/middleware"
|
| 7 |
"go-dp.abdanhafidz.com/models"
|
| 8 |
"go-dp.abdanhafidz.com/repositories"
|
|
@@ -17,6 +18,7 @@ func (s *RegisterService) Create() {
|
|
| 17 |
hashed_password, err_hash := middleware.HashPassword(s.Constructor.Password)
|
| 18 |
s.Error = err_hash
|
| 19 |
s.Constructor.Password = hashed_password
|
|
|
|
| 20 |
accountCreated := repositories.CreateAccount(s.Constructor)
|
| 21 |
if errors.Is(accountCreated.RowsError, gorm.ErrDuplicatedKey) {
|
| 22 |
s.Exception.DataDuplicate = true
|
|
|
|
| 3 |
import (
|
| 4 |
"errors"
|
| 5 |
|
| 6 |
+
uuid "github.com/satori/go.uuid"
|
| 7 |
"go-dp.abdanhafidz.com/middleware"
|
| 8 |
"go-dp.abdanhafidz.com/models"
|
| 9 |
"go-dp.abdanhafidz.com/repositories"
|
|
|
|
| 18 |
hashed_password, err_hash := middleware.HashPassword(s.Constructor.Password)
|
| 19 |
s.Error = err_hash
|
| 20 |
s.Constructor.Password = hashed_password
|
| 21 |
+
s.Constructor.UUID = uuid.NewV4()
|
| 22 |
accountCreated := repositories.CreateAccount(s.Constructor)
|
| 23 |
if errors.Is(accountCreated.RowsError, gorm.ErrDuplicatedKey) {
|
| 24 |
s.Exception.DataDuplicate = true
|
space/space/space/go.mod
CHANGED
|
@@ -36,6 +36,7 @@ require (
|
|
| 36 |
github.com/modern-go/reflect2 v1.0.2 // indirect
|
| 37 |
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
|
| 38 |
github.com/rogpeppe/go-internal v1.11.0 // indirect
|
|
|
|
| 39 |
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
| 40 |
github.com/ugorji/go/codec v1.2.11 // indirect
|
| 41 |
golang.org/x/arch v0.6.0 // indirect
|
|
|
|
| 36 |
github.com/modern-go/reflect2 v1.0.2 // indirect
|
| 37 |
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
|
| 38 |
github.com/rogpeppe/go-internal v1.11.0 // indirect
|
| 39 |
+
github.com/satori/go.uuid v1.2.0 // indirect
|
| 40 |
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
| 41 |
github.com/ugorji/go/codec v1.2.11 // indirect
|
| 42 |
golang.org/x/arch v0.6.0 // indirect
|
space/space/space/go.sum
CHANGED
|
@@ -79,6 +79,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
|
|
| 79 |
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
| 80 |
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
|
| 81 |
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
|
|
|
|
|
|
|
| 82 |
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
| 83 |
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
| 84 |
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
|
|
|
| 79 |
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
| 80 |
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
|
| 81 |
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
|
| 82 |
+
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
|
| 83 |
+
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
|
| 84 |
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
| 85 |
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
| 86 |
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
space/space/space/models/DatabaseModel.go
CHANGED
|
@@ -2,14 +2,18 @@ package models
|
|
| 2 |
|
| 3 |
import (
|
| 4 |
"time"
|
|
|
|
|
|
|
| 5 |
)
|
| 6 |
|
| 7 |
type Account struct {
|
| 8 |
-
Id
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
| 13 |
}
|
| 14 |
|
| 15 |
type AccountDetails struct {
|
|
@@ -22,6 +26,14 @@ type AccountDetails struct {
|
|
| 22 |
DeletedAt time.Time `json:"deleted_at"`
|
| 23 |
}
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
// Gorm table name settings
|
| 26 |
func (Account) TableName() string { return "account" }
|
| 27 |
func (AccountDetails) TableName() string { return "account_details" }
|
|
|
|
| 2 |
|
| 3 |
import (
|
| 4 |
"time"
|
| 5 |
+
|
| 6 |
+
uuid "github.com/satori/go.uuid"
|
| 7 |
)
|
| 8 |
|
| 9 |
type Account struct {
|
| 10 |
+
Id uint `gorm:"primaryKey" json:"id"`
|
| 11 |
+
UUID uuid.UUID `gorm:"type:uuid" json:"uuid" `
|
| 12 |
+
Email string `gorm:"uniqueIndex" json:"email"`
|
| 13 |
+
Password string `json:"password"`
|
| 14 |
+
IsEmailVerified bool `json:"is_email_verified"`
|
| 15 |
+
CreatedAt time.Time `json:"created_at"`
|
| 16 |
+
DeletedAt time.Time `json:"deleted_at"`
|
| 17 |
}
|
| 18 |
|
| 19 |
type AccountDetails struct {
|
|
|
|
| 26 |
DeletedAt time.Time `json:"deleted_at"`
|
| 27 |
}
|
| 28 |
|
| 29 |
+
type EmailVerification struct {
|
| 30 |
+
Id int `gorm:"primaryKey" json:"id"`
|
| 31 |
+
AccountId int `json:"account_id"`
|
| 32 |
+
UUID uuid.UUID `gorm:"type:uuid" json:"uuid" `
|
| 33 |
+
CreatedAt time.Time `json:"created_at"`
|
| 34 |
+
ExpiredAt time.Time `json:"expired_at"`
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
// Gorm table name settings
|
| 38 |
func (Account) TableName() string { return "account" }
|
| 39 |
func (AccountDetails) TableName() string { return "account_details" }
|
space/space/space/repositories/AccountRepository.go
CHANGED
|
@@ -1,8 +1,6 @@
|
|
| 1 |
package repositories
|
| 2 |
|
| 3 |
import (
|
| 4 |
-
"fmt"
|
| 5 |
-
|
| 6 |
"go-dp.abdanhafidz.com/models"
|
| 7 |
)
|
| 8 |
|
|
@@ -10,7 +8,6 @@ func GetAccountbyEmailPassword(email string, password string) Repository[models.
|
|
| 10 |
repo := Construct[models.Account, models.Account](
|
| 11 |
models.Account{Email: email, Password: password},
|
| 12 |
)
|
| 13 |
-
fmt.Println(repo.Constructor)
|
| 14 |
repo.Transactions(
|
| 15 |
WhereGivenConstructor[models.Account, models.Account],
|
| 16 |
Find[models.Account, models.Account],
|
|
|
|
| 1 |
package repositories
|
| 2 |
|
| 3 |
import (
|
|
|
|
|
|
|
| 4 |
"go-dp.abdanhafidz.com/models"
|
| 5 |
)
|
| 6 |
|
|
|
|
| 8 |
repo := Construct[models.Account, models.Account](
|
| 9 |
models.Account{Email: email, Password: password},
|
| 10 |
)
|
|
|
|
| 11 |
repo.Transactions(
|
| 12 |
WhereGivenConstructor[models.Account, models.Account],
|
| 13 |
Find[models.Account, models.Account],
|
space/space/space/services/RegisterService.go
CHANGED
|
@@ -14,7 +14,8 @@ type RegisterService struct {
|
|
| 14 |
}
|
| 15 |
|
| 16 |
func (s *RegisterService) Create() {
|
| 17 |
-
hashed_password,
|
|
|
|
| 18 |
s.Constructor.Password = hashed_password
|
| 19 |
accountCreated := repositories.CreateAccount(s.Constructor)
|
| 20 |
if errors.Is(accountCreated.RowsError, gorm.ErrDuplicatedKey) {
|
|
@@ -26,7 +27,7 @@ func (s *RegisterService) Create() {
|
|
| 26 |
s.Exception.Message = "Bad request!"
|
| 27 |
return
|
| 28 |
}
|
| 29 |
-
|
| 30 |
s.Result = accountCreated.Result
|
| 31 |
s.Result.Password = "SECRET"
|
| 32 |
}
|
|
|
|
| 14 |
}
|
| 15 |
|
| 16 |
func (s *RegisterService) Create() {
|
| 17 |
+
hashed_password, err_hash := middleware.HashPassword(s.Constructor.Password)
|
| 18 |
+
s.Error = err_hash
|
| 19 |
s.Constructor.Password = hashed_password
|
| 20 |
accountCreated := repositories.CreateAccount(s.Constructor)
|
| 21 |
if errors.Is(accountCreated.RowsError, gorm.ErrDuplicatedKey) {
|
|
|
|
| 27 |
s.Exception.Message = "Bad request!"
|
| 28 |
return
|
| 29 |
}
|
| 30 |
+
s.Error = accountCreated.RowsError
|
| 31 |
s.Result = accountCreated.Result
|
| 32 |
s.Result.Password = "SECRET"
|
| 33 |
}
|
space/space/space/space/controller/LoginController.go
CHANGED
|
@@ -11,9 +11,9 @@ func LoginController(c *gin.Context) {
|
|
| 11 |
loginController := Controller[models.LoginRequest, services.LoginConstructor, models.AuthenticatedUser]{
|
| 12 |
Service: &authentication.Service,
|
| 13 |
}
|
| 14 |
-
loginController.RequestJSON(c)
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
}
|
|
|
|
| 11 |
loginController := Controller[models.LoginRequest, services.LoginConstructor, models.AuthenticatedUser]{
|
| 12 |
Service: &authentication.Service,
|
| 13 |
}
|
| 14 |
+
loginController.RequestJSON(c, func() {
|
| 15 |
+
loginController.Service.Constructor.Email = loginController.Request.Email
|
| 16 |
+
loginController.Service.Constructor.Password = loginController.Request.Password
|
| 17 |
+
authentication.Authenticate()
|
| 18 |
+
})
|
| 19 |
}
|
space/space/space/space/controller/RegisterController.go
CHANGED
|
@@ -11,9 +11,9 @@ func RegisterController(c *gin.Context) {
|
|
| 11 |
registerController := Controller[models.RegisterRequest, models.Account, models.Account]{
|
| 12 |
Service: ®ister.Service,
|
| 13 |
}
|
| 14 |
-
registerController.RequestJSON(c)
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
}
|
|
|
|
| 11 |
registerController := Controller[models.RegisterRequest, models.Account, models.Account]{
|
| 12 |
Service: ®ister.Service,
|
| 13 |
}
|
| 14 |
+
registerController.RequestJSON(c, func() {
|
| 15 |
+
registerController.Service.Constructor.Password = registerController.Request.Password
|
| 16 |
+
registerController.Service.Constructor.Email = registerController.Request.Email
|
| 17 |
+
register.Create()
|
| 18 |
+
})
|
| 19 |
}
|
space/space/space/space/controller/controller.go
CHANGED
|
@@ -19,7 +19,7 @@ type (
|
|
| 19 |
}
|
| 20 |
)
|
| 21 |
|
| 22 |
-
func (controller *Controller[T1, T2, T3]) RequestJSON(c *gin.Context) {
|
| 23 |
cParam, _ := c.Get("accountData")
|
| 24 |
if cParam != nil {
|
| 25 |
controller.AccountData = cParam.(models.AccountData)
|
|
@@ -28,9 +28,12 @@ func (controller *Controller[T1, T2, T3]) RequestJSON(c *gin.Context) {
|
|
| 28 |
if errBinding != nil {
|
| 29 |
utils.ResponseFAIL(c, 400, models.Exception{
|
| 30 |
BadRequest: true,
|
| 31 |
-
Message: "Invalid Request
|
| 32 |
})
|
| 33 |
return
|
|
|
|
|
|
|
|
|
|
| 34 |
}
|
| 35 |
}
|
| 36 |
func (controller *Controller[T1, T2, T3]) Response(c *gin.Context) {
|
|
|
|
| 19 |
}
|
| 20 |
)
|
| 21 |
|
| 22 |
+
func (controller *Controller[T1, T2, T3]) RequestJSON(c *gin.Context, act func()) {
|
| 23 |
cParam, _ := c.Get("accountData")
|
| 24 |
if cParam != nil {
|
| 25 |
controller.AccountData = cParam.(models.AccountData)
|
|
|
|
| 28 |
if errBinding != nil {
|
| 29 |
utils.ResponseFAIL(c, 400, models.Exception{
|
| 30 |
BadRequest: true,
|
| 31 |
+
Message: "Invalid Request!, recheck your request, there's must be some problem about required parameter or type parameter",
|
| 32 |
})
|
| 33 |
return
|
| 34 |
+
} else {
|
| 35 |
+
act()
|
| 36 |
+
controller.Response(c)
|
| 37 |
}
|
| 38 |
}
|
| 39 |
func (controller *Controller[T1, T2, T3]) Response(c *gin.Context) {
|
space/space/space/space/models/DatabaseModel.go
CHANGED
|
@@ -6,7 +6,7 @@ import (
|
|
| 6 |
|
| 7 |
type Account struct {
|
| 8 |
Id uint `gorm:"primaryKey" json:"id"`
|
| 9 |
-
Email string `gorm:"
|
| 10 |
Password string `json:"password"`
|
| 11 |
CreatedAt time.Time `json:"created_at"`
|
| 12 |
DeletedAt time.Time `json:"deleted_at"`
|
|
|
|
| 6 |
|
| 7 |
type Account struct {
|
| 8 |
Id uint `gorm:"primaryKey" json:"id"`
|
| 9 |
+
Email string `gorm:"uniqueIndex" json:"email"`
|
| 10 |
Password string `json:"password"`
|
| 11 |
CreatedAt time.Time `json:"created_at"`
|
| 12 |
DeletedAt time.Time `json:"deleted_at"`
|
space/space/space/space/repositories/AccountRepository.go
CHANGED
|
@@ -1,6 +1,8 @@
|
|
| 1 |
package repositories
|
| 2 |
|
| 3 |
import (
|
|
|
|
|
|
|
| 4 |
"go-dp.abdanhafidz.com/models"
|
| 5 |
)
|
| 6 |
|
|
@@ -8,7 +10,11 @@ func GetAccountbyEmailPassword(email string, password string) Repository[models.
|
|
| 8 |
repo := Construct[models.Account, models.Account](
|
| 9 |
models.Account{Email: email, Password: password},
|
| 10 |
)
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
return *repo
|
| 13 |
}
|
| 14 |
|
|
@@ -16,7 +22,6 @@ func CreateAccount(account models.Account) Repository[models.Account, models.Acc
|
|
| 16 |
repo := Construct[models.Account, models.Account](
|
| 17 |
account,
|
| 18 |
)
|
| 19 |
-
|
| 20 |
Create(repo)
|
| 21 |
return *repo
|
| 22 |
}
|
|
|
|
| 1 |
package repositories
|
| 2 |
|
| 3 |
import (
|
| 4 |
+
"fmt"
|
| 5 |
+
|
| 6 |
"go-dp.abdanhafidz.com/models"
|
| 7 |
)
|
| 8 |
|
|
|
|
| 10 |
repo := Construct[models.Account, models.Account](
|
| 11 |
models.Account{Email: email, Password: password},
|
| 12 |
)
|
| 13 |
+
fmt.Println(repo.Constructor)
|
| 14 |
+
repo.Transactions(
|
| 15 |
+
WhereGivenConstructor[models.Account, models.Account],
|
| 16 |
+
Find[models.Account, models.Account],
|
| 17 |
+
)
|
| 18 |
return *repo
|
| 19 |
}
|
| 20 |
|
|
|
|
| 22 |
repo := Construct[models.Account, models.Account](
|
| 23 |
account,
|
| 24 |
)
|
|
|
|
| 25 |
Create(repo)
|
| 26 |
return *repo
|
| 27 |
}
|
space/space/space/space/repositories/repositories.go
CHANGED
|
@@ -1,6 +1,8 @@
|
|
| 1 |
package repositories
|
| 2 |
|
| 3 |
import (
|
|
|
|
|
|
|
| 4 |
"go-dp.abdanhafidz.com/config"
|
| 5 |
"gorm.io/gorm"
|
| 6 |
)
|
|
@@ -56,52 +58,63 @@ func (repo *Repository[T1, T2]) Transactions(transactions ...func(*Repository[T1
|
|
| 56 |
repo.Transaction.Rollback()
|
| 57 |
return
|
| 58 |
} else {
|
| 59 |
-
repo.Transaction.SavePoint("Save Point : " +
|
| 60 |
repo.Transaction.Commit()
|
| 61 |
}
|
| 62 |
}
|
| 63 |
}
|
| 64 |
func WhereGivenConstructor[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB {
|
| 65 |
tx := repo.Transaction.Where(&repo.Constructor)
|
| 66 |
-
repo.
|
|
|
|
| 67 |
repo.RowsError = tx.Error
|
| 68 |
return tx
|
| 69 |
}
|
| 70 |
func Find[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB {
|
| 71 |
tx := repo.Transaction.Find(&repo.Result)
|
| 72 |
-
repo.
|
|
|
|
| 73 |
repo.RowsError = tx.Error
|
| 74 |
return tx
|
| 75 |
}
|
| 76 |
|
| 77 |
func FinddAllPaginate[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB {
|
| 78 |
tx := repo.Transaction.Limit(repo.Pagination.Limit).Offset(repo.Pagination.Offset).Find(&repo.Result)
|
|
|
|
|
|
|
| 79 |
repo.RowsError = tx.Error
|
| 80 |
return tx
|
| 81 |
}
|
| 82 |
|
| 83 |
func Create[T1 any](repo *Repository[T1, T1]) *gorm.DB {
|
| 84 |
tx := repo.Transaction.Create(&repo.Constructor)
|
| 85 |
-
repo.
|
|
|
|
| 86 |
repo.RowsError = tx.Error
|
|
|
|
| 87 |
return tx
|
| 88 |
}
|
| 89 |
|
| 90 |
func Update[T1 any](repo *Repository[T1, T1]) *gorm.DB {
|
| 91 |
tx := repo.Transaction.Save(&repo.Constructor)
|
| 92 |
-
repo.
|
|
|
|
| 93 |
repo.RowsError = tx.Error
|
| 94 |
return tx
|
| 95 |
}
|
| 96 |
|
| 97 |
func Delete[T1 any](repo *Repository[T1, T1]) *gorm.DB {
|
| 98 |
tx := repo.Transaction.Delete(&repo.Constructor)
|
|
|
|
|
|
|
| 99 |
repo.RowsError = tx.Error
|
| 100 |
return tx
|
| 101 |
}
|
| 102 |
|
| 103 |
func CustomQuery[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB {
|
| 104 |
tx := repo.Transaction.Raw(repo.CustomQuery.SQL, repo.CustomQuery.Values).Scan(&repo.Result)
|
|
|
|
|
|
|
| 105 |
repo.RowsError = tx.Error
|
| 106 |
return tx
|
| 107 |
}
|
|
|
|
| 1 |
package repositories
|
| 2 |
|
| 3 |
import (
|
| 4 |
+
"strconv"
|
| 5 |
+
|
| 6 |
"go-dp.abdanhafidz.com/config"
|
| 7 |
"gorm.io/gorm"
|
| 8 |
)
|
|
|
|
| 58 |
repo.Transaction.Rollback()
|
| 59 |
return
|
| 60 |
} else {
|
| 61 |
+
repo.Transaction.SavePoint("Save Point : " + strconv.Itoa(i))
|
| 62 |
repo.Transaction.Commit()
|
| 63 |
}
|
| 64 |
}
|
| 65 |
}
|
| 66 |
func WhereGivenConstructor[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB {
|
| 67 |
tx := repo.Transaction.Where(&repo.Constructor)
|
| 68 |
+
repo.RowsCount = int(tx.RowsAffected)
|
| 69 |
+
repo.NoRecord = repo.RowsCount == 0
|
| 70 |
repo.RowsError = tx.Error
|
| 71 |
return tx
|
| 72 |
}
|
| 73 |
func Find[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB {
|
| 74 |
tx := repo.Transaction.Find(&repo.Result)
|
| 75 |
+
repo.RowsCount = int(tx.RowsAffected)
|
| 76 |
+
repo.NoRecord = repo.RowsCount == 0
|
| 77 |
repo.RowsError = tx.Error
|
| 78 |
return tx
|
| 79 |
}
|
| 80 |
|
| 81 |
func FinddAllPaginate[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB {
|
| 82 |
tx := repo.Transaction.Limit(repo.Pagination.Limit).Offset(repo.Pagination.Offset).Find(&repo.Result)
|
| 83 |
+
repo.RowsCount = int(tx.RowsAffected)
|
| 84 |
+
repo.NoRecord = repo.RowsCount == 0
|
| 85 |
repo.RowsError = tx.Error
|
| 86 |
return tx
|
| 87 |
}
|
| 88 |
|
| 89 |
func Create[T1 any](repo *Repository[T1, T1]) *gorm.DB {
|
| 90 |
tx := repo.Transaction.Create(&repo.Constructor)
|
| 91 |
+
repo.RowsCount = int(tx.RowsAffected)
|
| 92 |
+
repo.NoRecord = repo.RowsCount == 0
|
| 93 |
repo.RowsError = tx.Error
|
| 94 |
+
repo.Result = repo.Constructor
|
| 95 |
return tx
|
| 96 |
}
|
| 97 |
|
| 98 |
func Update[T1 any](repo *Repository[T1, T1]) *gorm.DB {
|
| 99 |
tx := repo.Transaction.Save(&repo.Constructor)
|
| 100 |
+
repo.RowsCount = int(tx.RowsAffected)
|
| 101 |
+
repo.NoRecord = repo.RowsCount == 0
|
| 102 |
repo.RowsError = tx.Error
|
| 103 |
return tx
|
| 104 |
}
|
| 105 |
|
| 106 |
func Delete[T1 any](repo *Repository[T1, T1]) *gorm.DB {
|
| 107 |
tx := repo.Transaction.Delete(&repo.Constructor)
|
| 108 |
+
repo.RowsCount = int(tx.RowsAffected)
|
| 109 |
+
repo.NoRecord = repo.RowsCount == 0
|
| 110 |
repo.RowsError = tx.Error
|
| 111 |
return tx
|
| 112 |
}
|
| 113 |
|
| 114 |
func CustomQuery[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB {
|
| 115 |
tx := repo.Transaction.Raw(repo.CustomQuery.SQL, repo.CustomQuery.Values).Scan(&repo.Result)
|
| 116 |
+
repo.RowsCount = int(tx.RowsAffected)
|
| 117 |
+
repo.NoRecord = repo.RowsCount == 0
|
| 118 |
repo.RowsError = tx.Error
|
| 119 |
return tx
|
| 120 |
}
|
space/space/space/space/services/LoginService.go
CHANGED
|
@@ -21,10 +21,9 @@ func (s *AuthenticationService) Authenticate() {
|
|
| 21 |
accountData := repositories.GetAccountbyEmailPassword(s.Constructor.Email, s.Constructor.Password)
|
| 22 |
if accountData.NoRecord {
|
| 23 |
s.Exception.DataNotFound = true
|
| 24 |
-
s.Exception.Message = "there is no account with given
|
| 25 |
return
|
| 26 |
}
|
| 27 |
-
|
| 28 |
if middleware.VerifyPassword(accountData.Result.Password, s.Constructor.Password) != nil {
|
| 29 |
s.Exception.Unauthorized = true
|
| 30 |
s.Exception.Message = "incorrect password!"
|
|
|
|
| 21 |
accountData := repositories.GetAccountbyEmailPassword(s.Constructor.Email, s.Constructor.Password)
|
| 22 |
if accountData.NoRecord {
|
| 23 |
s.Exception.DataNotFound = true
|
| 24 |
+
s.Exception.Message = "there is no account with given credentials!"
|
| 25 |
return
|
| 26 |
}
|
|
|
|
| 27 |
if middleware.VerifyPassword(accountData.Result.Password, s.Constructor.Password) != nil {
|
| 28 |
s.Exception.Unauthorized = true
|
| 29 |
s.Exception.Message = "incorrect password!"
|
space/space/space/space/services/RegisterService.go
CHANGED
|
@@ -2,7 +2,6 @@ package services
|
|
| 2 |
|
| 3 |
import (
|
| 4 |
"errors"
|
| 5 |
-
"fmt"
|
| 6 |
|
| 7 |
"go-dp.abdanhafidz.com/middleware"
|
| 8 |
"go-dp.abdanhafidz.com/models"
|
|
@@ -18,9 +17,6 @@ func (s *RegisterService) Create() {
|
|
| 18 |
hashed_password, _ := middleware.HashPassword(s.Constructor.Password)
|
| 19 |
s.Constructor.Password = hashed_password
|
| 20 |
accountCreated := repositories.CreateAccount(s.Constructor)
|
| 21 |
-
|
| 22 |
-
// fmt.Println("Error :", accountCreated.RowsError.Error())
|
| 23 |
-
fmt.Println(errors.Is(accountCreated.RowsError, gorm.ErrDuplicatedKey))
|
| 24 |
if errors.Is(accountCreated.RowsError, gorm.ErrDuplicatedKey) {
|
| 25 |
s.Exception.DataDuplicate = true
|
| 26 |
s.Exception.Message = "Account with email " + s.Constructor.Email + " already exists!"
|
|
|
|
| 2 |
|
| 3 |
import (
|
| 4 |
"errors"
|
|
|
|
| 5 |
|
| 6 |
"go-dp.abdanhafidz.com/middleware"
|
| 7 |
"go-dp.abdanhafidz.com/models"
|
|
|
|
| 17 |
hashed_password, _ := middleware.HashPassword(s.Constructor.Password)
|
| 18 |
s.Constructor.Password = hashed_password
|
| 19 |
accountCreated := repositories.CreateAccount(s.Constructor)
|
|
|
|
|
|
|
|
|
|
| 20 |
if errors.Is(accountCreated.RowsError, gorm.ErrDuplicatedKey) {
|
| 21 |
s.Exception.DataDuplicate = true
|
| 22 |
s.Exception.Message = "Account with email " + s.Constructor.Email + " already exists!"
|
space/space/space/space/space/controller/LoginController.go
CHANGED
|
@@ -8,7 +8,7 @@ import (
|
|
| 8 |
|
| 9 |
func LoginController(c *gin.Context) {
|
| 10 |
authentication := services.AuthenticationService{}
|
| 11 |
-
loginController := Controller[models.LoginRequest, services.LoginConstructor, models.
|
| 12 |
Service: &authentication.Service,
|
| 13 |
}
|
| 14 |
loginController.RequestJSON(c)
|
|
|
|
| 8 |
|
| 9 |
func LoginController(c *gin.Context) {
|
| 10 |
authentication := services.AuthenticationService{}
|
| 11 |
+
loginController := Controller[models.LoginRequest, services.LoginConstructor, models.AuthenticatedUser]{
|
| 12 |
Service: &authentication.Service,
|
| 13 |
}
|
| 14 |
loginController.RequestJSON(c)
|
space/space/space/space/space/controller/controller.go
CHANGED
|
@@ -41,6 +41,8 @@ func (controller *Controller[T1, T2, T3]) Response(c *gin.Context) {
|
|
| 41 |
Message: "Internal Server Error",
|
| 42 |
})
|
| 43 |
utils.LogError(controller.Service.Error)
|
|
|
|
|
|
|
| 44 |
case controller.Service.Exception.Unauthorized:
|
| 45 |
utils.ResponseFAIL(c, 401, controller.Service.Exception)
|
| 46 |
case controller.Service.Exception.DataNotFound:
|
|
|
|
| 41 |
Message: "Internal Server Error",
|
| 42 |
})
|
| 43 |
utils.LogError(controller.Service.Error)
|
| 44 |
+
case controller.Service.Exception.DataDuplicate:
|
| 45 |
+
utils.ResponseFAIL(c, 400, controller.Service.Exception)
|
| 46 |
case controller.Service.Exception.Unauthorized:
|
| 47 |
utils.ResponseFAIL(c, 401, controller.Service.Exception)
|
| 48 |
case controller.Service.Exception.DataNotFound:
|
space/space/space/space/space/middleware/AuthMiddleware.go
CHANGED
|
@@ -25,7 +25,7 @@ func GenerateToken(user *models.Account) (string, error) {
|
|
| 25 |
|
| 26 |
// Set claims
|
| 27 |
claims := token.Claims.(jwt.MapClaims)
|
| 28 |
-
claims["id"] = user.
|
| 29 |
claims["exp"] = time.Now().Add(time.Hour * 24).Unix() // Token expires in 24 hours
|
| 30 |
|
| 31 |
// Sign the token with the secret key
|
|
|
|
| 25 |
|
| 26 |
// Set claims
|
| 27 |
claims := token.Claims.(jwt.MapClaims)
|
| 28 |
+
claims["id"] = user.Id
|
| 29 |
claims["exp"] = time.Now().Add(time.Hour * 24).Unix() // Token expires in 24 hours
|
| 30 |
|
| 31 |
// Sign the token with the secret key
|
space/space/space/space/space/models/DatabaseModel.go
CHANGED
|
@@ -5,14 +5,11 @@ import (
|
|
| 5 |
)
|
| 6 |
|
| 7 |
type Account struct {
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
PhoneNumber int `json:"phone_number"`
|
| 14 |
-
CreatedAt time.Time `json:"created_at"`
|
| 15 |
-
DeletedAt time.Time `json:"deleted_at"`
|
| 16 |
}
|
| 17 |
|
| 18 |
type AccountDetails struct {
|
|
|
|
| 5 |
)
|
| 6 |
|
| 7 |
type Account struct {
|
| 8 |
+
Id uint `gorm:"primaryKey" json:"id"`
|
| 9 |
+
Email string `gorm:"primaryKey" json:"email"`
|
| 10 |
+
Password string `json:"password"`
|
| 11 |
+
CreatedAt time.Time `json:"created_at"`
|
| 12 |
+
DeletedAt time.Time `json:"deleted_at"`
|
|
|
|
|
|
|
|
|
|
| 13 |
}
|
| 14 |
|
| 15 |
type AccountDetails struct {
|
space/space/space/space/space/models/ResponseModel.go
CHANGED
|
@@ -1 +1,6 @@
|
|
| 1 |
package models
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
package models
|
| 2 |
+
|
| 3 |
+
type AuthenticatedUser struct {
|
| 4 |
+
Account Account `json:"account"`
|
| 5 |
+
Token string `json:"token"`
|
| 6 |
+
}
|
space/space/space/space/space/repositories/AccountRepository.go
CHANGED
|
@@ -1,24 +1,22 @@
|
|
| 1 |
package repositories
|
| 2 |
|
| 3 |
import (
|
| 4 |
-
"fmt"
|
| 5 |
-
|
| 6 |
"go-dp.abdanhafidz.com/models"
|
| 7 |
)
|
| 8 |
|
| 9 |
-
func GetAccountbyEmailPassword(
|
| 10 |
repo := Construct[models.Account, models.Account](
|
| 11 |
-
models.Account{
|
| 12 |
)
|
| 13 |
Find(repo)
|
| 14 |
return *repo
|
| 15 |
}
|
| 16 |
|
| 17 |
func CreateAccount(account models.Account) Repository[models.Account, models.Account] {
|
| 18 |
-
fmt.Println(account)
|
| 19 |
repo := Construct[models.Account, models.Account](
|
| 20 |
account,
|
| 21 |
)
|
|
|
|
| 22 |
Create(repo)
|
| 23 |
return *repo
|
| 24 |
}
|
|
|
|
| 1 |
package repositories
|
| 2 |
|
| 3 |
import (
|
|
|
|
|
|
|
| 4 |
"go-dp.abdanhafidz.com/models"
|
| 5 |
)
|
| 6 |
|
| 7 |
+
func GetAccountbyEmailPassword(email string, password string) Repository[models.Account, models.Account] {
|
| 8 |
repo := Construct[models.Account, models.Account](
|
| 9 |
+
models.Account{Email: email, Password: password},
|
| 10 |
)
|
| 11 |
Find(repo)
|
| 12 |
return *repo
|
| 13 |
}
|
| 14 |
|
| 15 |
func CreateAccount(account models.Account) Repository[models.Account, models.Account] {
|
|
|
|
| 16 |
repo := Construct[models.Account, models.Account](
|
| 17 |
account,
|
| 18 |
)
|
| 19 |
+
|
| 20 |
Create(repo)
|
| 21 |
return *repo
|
| 22 |
}
|
space/space/space/space/space/repositories/repositories.go
CHANGED
|
@@ -1,8 +1,6 @@
|
|
| 1 |
package repositories
|
| 2 |
|
| 3 |
import (
|
| 4 |
-
"fmt"
|
| 5 |
-
|
| 6 |
"go-dp.abdanhafidz.com/config"
|
| 7 |
"gorm.io/gorm"
|
| 8 |
)
|
|
@@ -39,7 +37,6 @@ type Repository[TConstructor any, TResult any] struct {
|
|
| 39 |
}
|
| 40 |
|
| 41 |
func Construct[TConstructor any, TResult any](constructor ...TConstructor) *Repository[TConstructor, TResult] {
|
| 42 |
-
fmt.Println("Len = ", len(constructor))
|
| 43 |
if len(constructor) == 1 {
|
| 44 |
return &Repository[TConstructor, TResult]{
|
| 45 |
Constructor: constructor[0],
|
|
@@ -51,11 +48,10 @@ func Construct[TConstructor any, TResult any](constructor ...TConstructor) *Repo
|
|
| 51 |
Transaction: config.DB.Begin(),
|
| 52 |
}
|
| 53 |
}
|
| 54 |
-
func (repo *Repository[T1, T2]) Transactions(transactions ...func(*Repository[T1, T2])) {
|
| 55 |
i := 1
|
| 56 |
for _, tx := range transactions {
|
| 57 |
-
tx(repo)
|
| 58 |
-
repo.RowsError = repo.Transaction.Error
|
| 59 |
if repo.RowsError != nil {
|
| 60 |
repo.Transaction.Rollback()
|
| 61 |
return
|
|
@@ -65,32 +61,47 @@ func (repo *Repository[T1, T2]) Transactions(transactions ...func(*Repository[T1
|
|
| 65 |
}
|
| 66 |
}
|
| 67 |
}
|
| 68 |
-
func WhereGivenConstructor[T1 any, T2 any](repo *Repository[T1, T2]) {
|
| 69 |
-
repo.Transaction.Where(&repo.Constructor)
|
|
|
|
|
|
|
|
|
|
| 70 |
}
|
| 71 |
-
func Find[T1 any, T2 any](repo *Repository[T1, T2]) {
|
| 72 |
-
repo.Transaction.Find(&repo.Result)
|
|
|
|
|
|
|
|
|
|
| 73 |
}
|
| 74 |
|
| 75 |
-
func FinddAllPaginate[T1 any, T2 any](repo *Repository[T1, T2]) {
|
| 76 |
-
repo.Transaction.Limit(repo.Pagination.Limit).Offset(repo.Pagination.Offset).Find(&repo.Result)
|
|
|
|
|
|
|
| 77 |
}
|
| 78 |
|
| 79 |
-
func Create[T1 any](repo *Repository[T1, T1]) {
|
| 80 |
-
|
| 81 |
-
repo.Transaction.Create(&repo.Constructor)
|
| 82 |
repo.Result = repo.Constructor
|
|
|
|
|
|
|
| 83 |
}
|
| 84 |
|
| 85 |
-
func Update[T1 any](repo *Repository[T1, T1]) {
|
| 86 |
-
repo.Transaction.Save(&repo.Constructor)
|
| 87 |
repo.Result = repo.Constructor
|
|
|
|
|
|
|
| 88 |
}
|
| 89 |
|
| 90 |
-
func Delete[T1 any](repo *Repository[T1, T1]) {
|
| 91 |
-
repo.Transaction.Delete(&repo.Constructor)
|
|
|
|
|
|
|
| 92 |
}
|
| 93 |
|
| 94 |
-
func CustomQuery[T1 any, T2 any](repo *Repository[T1, T2]) {
|
| 95 |
-
repo.Transaction.Raw(repo.CustomQuery.SQL, repo.CustomQuery.Values).Scan(&repo.Result)
|
|
|
|
|
|
|
| 96 |
}
|
|
|
|
| 1 |
package repositories
|
| 2 |
|
| 3 |
import (
|
|
|
|
|
|
|
| 4 |
"go-dp.abdanhafidz.com/config"
|
| 5 |
"gorm.io/gorm"
|
| 6 |
)
|
|
|
|
| 37 |
}
|
| 38 |
|
| 39 |
func Construct[TConstructor any, TResult any](constructor ...TConstructor) *Repository[TConstructor, TResult] {
|
|
|
|
| 40 |
if len(constructor) == 1 {
|
| 41 |
return &Repository[TConstructor, TResult]{
|
| 42 |
Constructor: constructor[0],
|
|
|
|
| 48 |
Transaction: config.DB.Begin(),
|
| 49 |
}
|
| 50 |
}
|
| 51 |
+
func (repo *Repository[T1, T2]) Transactions(transactions ...func(*Repository[T1, T2]) *gorm.DB) {
|
| 52 |
i := 1
|
| 53 |
for _, tx := range transactions {
|
| 54 |
+
repo.Transaction = tx(repo)
|
|
|
|
| 55 |
if repo.RowsError != nil {
|
| 56 |
repo.Transaction.Rollback()
|
| 57 |
return
|
|
|
|
| 61 |
}
|
| 62 |
}
|
| 63 |
}
|
| 64 |
+
func WhereGivenConstructor[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB {
|
| 65 |
+
tx := repo.Transaction.Where(&repo.Constructor)
|
| 66 |
+
repo.RowsError = repo.Transaction.Error
|
| 67 |
+
repo.RowsError = tx.Error
|
| 68 |
+
return tx
|
| 69 |
}
|
| 70 |
+
func Find[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB {
|
| 71 |
+
tx := repo.Transaction.Find(&repo.Result)
|
| 72 |
+
repo.RowsError = repo.Transaction.Error
|
| 73 |
+
repo.RowsError = tx.Error
|
| 74 |
+
return tx
|
| 75 |
}
|
| 76 |
|
| 77 |
+
func FinddAllPaginate[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB {
|
| 78 |
+
tx := repo.Transaction.Limit(repo.Pagination.Limit).Offset(repo.Pagination.Offset).Find(&repo.Result)
|
| 79 |
+
repo.RowsError = tx.Error
|
| 80 |
+
return tx
|
| 81 |
}
|
| 82 |
|
| 83 |
+
func Create[T1 any](repo *Repository[T1, T1]) *gorm.DB {
|
| 84 |
+
tx := repo.Transaction.Create(&repo.Constructor)
|
|
|
|
| 85 |
repo.Result = repo.Constructor
|
| 86 |
+
repo.RowsError = tx.Error
|
| 87 |
+
return tx
|
| 88 |
}
|
| 89 |
|
| 90 |
+
func Update[T1 any](repo *Repository[T1, T1]) *gorm.DB {
|
| 91 |
+
tx := repo.Transaction.Save(&repo.Constructor)
|
| 92 |
repo.Result = repo.Constructor
|
| 93 |
+
repo.RowsError = tx.Error
|
| 94 |
+
return tx
|
| 95 |
}
|
| 96 |
|
| 97 |
+
func Delete[T1 any](repo *Repository[T1, T1]) *gorm.DB {
|
| 98 |
+
tx := repo.Transaction.Delete(&repo.Constructor)
|
| 99 |
+
repo.RowsError = tx.Error
|
| 100 |
+
return tx
|
| 101 |
}
|
| 102 |
|
| 103 |
+
func CustomQuery[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB {
|
| 104 |
+
tx := repo.Transaction.Raw(repo.CustomQuery.SQL, repo.CustomQuery.Values).Scan(&repo.Result)
|
| 105 |
+
repo.RowsError = tx.Error
|
| 106 |
+
return tx
|
| 107 |
}
|
space/space/space/space/space/services/LoginService.go
CHANGED
|
@@ -1,6 +1,8 @@
|
|
| 1 |
package services
|
| 2 |
|
| 3 |
import (
|
|
|
|
|
|
|
| 4 |
"go-dp.abdanhafidz.com/middleware"
|
| 5 |
"go-dp.abdanhafidz.com/models"
|
| 6 |
"go-dp.abdanhafidz.com/repositories"
|
|
@@ -12,7 +14,7 @@ type LoginConstructor struct {
|
|
| 12 |
}
|
| 13 |
|
| 14 |
type AuthenticationService struct {
|
| 15 |
-
Service[LoginConstructor, models.
|
| 16 |
}
|
| 17 |
|
| 18 |
func (s *AuthenticationService) Authenticate() {
|
|
@@ -29,7 +31,17 @@ func (s *AuthenticationService) Authenticate() {
|
|
| 29 |
return
|
| 30 |
}
|
| 31 |
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
s.Error = accountData.RowsError
|
| 34 |
}
|
| 35 |
|
|
|
|
| 1 |
package services
|
| 2 |
|
| 3 |
import (
|
| 4 |
+
"errors"
|
| 5 |
+
|
| 6 |
"go-dp.abdanhafidz.com/middleware"
|
| 7 |
"go-dp.abdanhafidz.com/models"
|
| 8 |
"go-dp.abdanhafidz.com/repositories"
|
|
|
|
| 14 |
}
|
| 15 |
|
| 16 |
type AuthenticationService struct {
|
| 17 |
+
Service[LoginConstructor, models.AuthenticatedUser]
|
| 18 |
}
|
| 19 |
|
| 20 |
func (s *AuthenticationService) Authenticate() {
|
|
|
|
| 31 |
return
|
| 32 |
}
|
| 33 |
|
| 34 |
+
token, err_tok := middleware.GenerateToken(&accountData.Result)
|
| 35 |
+
|
| 36 |
+
if err_tok != nil {
|
| 37 |
+
s.Error = errors.Join(s.Error, err_tok)
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
accountData.Result.Password = "SECRET"
|
| 41 |
+
s.Result = models.AuthenticatedUser{
|
| 42 |
+
Account: accountData.Result,
|
| 43 |
+
Token: token,
|
| 44 |
+
}
|
| 45 |
s.Error = accountData.RowsError
|
| 46 |
}
|
| 47 |
|
space/space/space/space/space/services/RegisterService.go
CHANGED
|
@@ -2,6 +2,7 @@ package services
|
|
| 2 |
|
| 3 |
import (
|
| 4 |
"errors"
|
|
|
|
| 5 |
|
| 6 |
"go-dp.abdanhafidz.com/middleware"
|
| 7 |
"go-dp.abdanhafidz.com/models"
|
|
@@ -17,15 +18,19 @@ func (s *RegisterService) Create() {
|
|
| 17 |
hashed_password, _ := middleware.HashPassword(s.Constructor.Password)
|
| 18 |
s.Constructor.Password = hashed_password
|
| 19 |
accountCreated := repositories.CreateAccount(s.Constructor)
|
|
|
|
|
|
|
|
|
|
| 20 |
if errors.Is(accountCreated.RowsError, gorm.ErrDuplicatedKey) {
|
| 21 |
s.Exception.DataDuplicate = true
|
| 22 |
-
s.Exception.Message = "
|
| 23 |
return
|
| 24 |
} else if errors.Is(accountCreated.RowsError, gorm.ErrModelAccessibleFieldsRequired) || errors.Is(accountCreated.RowsError, gorm.ErrInvalidData) || errors.Is(accountCreated.RowsError, gorm.ErrInvalidValue) || errors.Is(accountCreated.RowsError, gorm.ErrInvalidField) {
|
| 25 |
s.Exception.BadRequest = true
|
| 26 |
s.Exception.Message = "Bad request!"
|
| 27 |
return
|
| 28 |
}
|
|
|
|
| 29 |
s.Result = accountCreated.Result
|
| 30 |
s.Result.Password = "SECRET"
|
| 31 |
}
|
|
|
|
| 2 |
|
| 3 |
import (
|
| 4 |
"errors"
|
| 5 |
+
"fmt"
|
| 6 |
|
| 7 |
"go-dp.abdanhafidz.com/middleware"
|
| 8 |
"go-dp.abdanhafidz.com/models"
|
|
|
|
| 18 |
hashed_password, _ := middleware.HashPassword(s.Constructor.Password)
|
| 19 |
s.Constructor.Password = hashed_password
|
| 20 |
accountCreated := repositories.CreateAccount(s.Constructor)
|
| 21 |
+
|
| 22 |
+
// fmt.Println("Error :", accountCreated.RowsError.Error())
|
| 23 |
+
fmt.Println(errors.Is(accountCreated.RowsError, gorm.ErrDuplicatedKey))
|
| 24 |
if errors.Is(accountCreated.RowsError, gorm.ErrDuplicatedKey) {
|
| 25 |
s.Exception.DataDuplicate = true
|
| 26 |
+
s.Exception.Message = "Account with email " + s.Constructor.Email + " already exists!"
|
| 27 |
return
|
| 28 |
} else if errors.Is(accountCreated.RowsError, gorm.ErrModelAccessibleFieldsRequired) || errors.Is(accountCreated.RowsError, gorm.ErrInvalidData) || errors.Is(accountCreated.RowsError, gorm.ErrInvalidValue) || errors.Is(accountCreated.RowsError, gorm.ErrInvalidField) {
|
| 29 |
s.Exception.BadRequest = true
|
| 30 |
s.Exception.Message = "Bad request!"
|
| 31 |
return
|
| 32 |
}
|
| 33 |
+
|
| 34 |
s.Result = accountCreated.Result
|
| 35 |
s.Result.Password = "SECRET"
|
| 36 |
}
|
space/space/space/space/space/space/space/Dockerfile
CHANGED
|
@@ -21,8 +21,8 @@ RUN echo "DB_HOST=aws-0-ap-southeast-1.pooler.supabase.com" >> .env && \
|
|
| 21 |
echo "DB_NAME=postgres" >> .env && \
|
| 22 |
echo "HOST_ADDRESS = 0.0.0.0" >> .env && \
|
| 23 |
echo "HOST_PORT = 7860" >> .env && \
|
| 24 |
-
echo "SALT=NZNZtY7dNPz8l0dWINJZLKafWaJrql1s" >> .env
|
| 25 |
-
echo "LOG_PATH = logs"
|
| 26 |
# Build aplikasi
|
| 27 |
RUN go build -o main .
|
| 28 |
|
|
|
|
| 21 |
echo "DB_NAME=postgres" >> .env && \
|
| 22 |
echo "HOST_ADDRESS = 0.0.0.0" >> .env && \
|
| 23 |
echo "HOST_PORT = 7860" >> .env && \
|
| 24 |
+
echo "SALT=NZNZtY7dNPz8l0dWINJZLKafWaJrql1s" >> .env && \
|
| 25 |
+
echo "LOG_PATH = logs" >> .env
|
| 26 |
# Build aplikasi
|
| 27 |
RUN go build -o main .
|
| 28 |
|
space/space/space/space/space/space/space/space/controller/HomeController.go
CHANGED
|
@@ -4,6 +4,6 @@ import "github.com/gin-gonic/gin"
|
|
| 4 |
|
| 5 |
func HomeController(c *gin.Context) {
|
| 6 |
c.JSON(200, gin.H{
|
| 7 |
-
"message": "Api
|
| 8 |
})
|
| 9 |
}
|
|
|
|
| 4 |
|
| 5 |
func HomeController(c *gin.Context) {
|
| 6 |
c.JSON(200, gin.H{
|
| 7 |
+
"message": "Api Qobiltu 2025!",
|
| 8 |
})
|
| 9 |
}
|
space/space/space/space/space/space/space/space/router/router.go
CHANGED
|
@@ -8,8 +8,9 @@ import (
|
|
| 8 |
|
| 9 |
func StartService() {
|
| 10 |
router := gin.Default()
|
| 11 |
-
routerGroup := router.Group("/api")
|
| 12 |
{
|
|
|
|
| 13 |
routerGroup.POST("/login", controller.LoginController)
|
| 14 |
routerGroup.POST("/register", controller.RegisterController)
|
| 15 |
}
|
|
|
|
| 8 |
|
| 9 |
func StartService() {
|
| 10 |
router := gin.Default()
|
| 11 |
+
routerGroup := router.Group("/api/v1")
|
| 12 |
{
|
| 13 |
+
routerGroup.GET("/", controller.HomeController)
|
| 14 |
routerGroup.POST("/login", controller.LoginController)
|
| 15 |
routerGroup.POST("/register", controller.RegisterController)
|
| 16 |
}
|
space/space/space/space/space/space/space/space/space/.env.example
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
DB_HOST =
|
| 2 |
+
DB_USER =
|
| 3 |
+
DB_PASSWORD =
|
| 4 |
+
DB_PORT =
|
| 5 |
+
DB_NAME =
|
| 6 |
+
SALT =
|
| 7 |
+
HOST_ADDRESS =
|
| 8 |
+
HOST_PORT =
|
| 9 |
+
LOG_PATH = logs
|
space/space/space/space/space/space/space/space/space/.github/workflows/main.yml
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: Deploy to Development via Huggingface
|
| 2 |
+
|
| 3 |
+
on:
|
| 4 |
+
push:
|
| 5 |
+
branches:
|
| 6 |
+
- main
|
| 7 |
+
|
| 8 |
+
jobs:
|
| 9 |
+
deploy-to-huggingface:
|
| 10 |
+
runs-on: ubuntu-latest
|
| 11 |
+
|
| 12 |
+
steps:
|
| 13 |
+
# Checkout repository
|
| 14 |
+
- name: Checkout Repository
|
| 15 |
+
uses: actions/checkout@v3
|
| 16 |
+
|
| 17 |
+
# Setup Git
|
| 18 |
+
- name: Setup Git for Huggingface
|
| 19 |
+
run: |
|
| 20 |
+
git config --global user.email "abdan.hafidz@gmail.com"
|
| 21 |
+
git config --global user.name "abdanhafidz"
|
| 22 |
+
|
| 23 |
+
# Clone Huggingface Space Repository
|
| 24 |
+
- name: Clone Huggingface Space
|
| 25 |
+
env:
|
| 26 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
| 27 |
+
run: |
|
| 28 |
+
git clone https://huggingface.co/spaces/lifedebugger/api-qobiltu-dev space
|
| 29 |
+
|
| 30 |
+
# Update Git Remote URL and Pull Latest Changes
|
| 31 |
+
- name: Update Remote and Pull Changes
|
| 32 |
+
env:
|
| 33 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
| 34 |
+
run: |
|
| 35 |
+
cd space
|
| 36 |
+
git remote set-url origin https://lifedebugger:$HF_TOKEN@huggingface.co/spaces/lifedebugger/api-qobiltu-dev
|
| 37 |
+
git pull origin main || echo "No changes to pull"
|
| 38 |
+
|
| 39 |
+
# Copy Files to Huggingface Space
|
| 40 |
+
- name: Copy Files to Space
|
| 41 |
+
run: |
|
| 42 |
+
rsync -av --exclude='.git' ./ space/
|
| 43 |
+
|
| 44 |
+
# Commit and Push to Huggingface Space
|
| 45 |
+
- name: Commit and Push to Huggingface
|
| 46 |
+
env:
|
| 47 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
| 48 |
+
run: |
|
| 49 |
+
cd space
|
| 50 |
+
git add .
|
| 51 |
+
git commit -m "Deploy files from GitHub repository" || echo "No changes to commit"
|
| 52 |
+
git push origin main || echo "No changes to push"
|
space/space/space/space/space/space/space/space/space/.gitignore
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.env
|
| 2 |
+
vendor/
|
| 3 |
+
quzuu-be.exe
|