lifedebugger commited on
Commit
6596fcc
·
1 Parent(s): 73f8fa4

Deploy files from GitHub repository

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. repositories/AccountRepository.go +2 -2
  2. repositories/repositories.go +0 -7
  3. services/LoginService.go +1 -1
  4. services/RegisterService.go +2 -0
  5. space/go.mod +1 -0
  6. space/go.sum +2 -0
  7. space/models/DatabaseModel.go +17 -5
  8. space/repositories/AccountRepository.go +0 -3
  9. space/services/RegisterService.go +3 -2
  10. space/space/controller/LoginController.go +5 -5
  11. space/space/controller/RegisterController.go +5 -5
  12. space/space/controller/controller.go +5 -2
  13. space/space/models/DatabaseModel.go +1 -1
  14. space/space/repositories/AccountRepository.go +7 -2
  15. space/space/repositories/repositories.go +18 -5
  16. space/space/services/LoginService.go +1 -2
  17. space/space/services/RegisterService.go +0 -4
  18. space/space/space/controller/LoginController.go +1 -1
  19. space/space/space/controller/controller.go +2 -0
  20. space/space/space/middleware/AuthMiddleware.go +1 -1
  21. space/space/space/models/DatabaseModel.go +5 -8
  22. space/space/space/models/ResponseModel.go +5 -0
  23. space/space/space/repositories/AccountRepository.go +3 -5
  24. space/space/space/repositories/repositories.go +32 -21
  25. space/space/space/services/LoginService.go +14 -2
  26. space/space/space/services/RegisterService.go +6 -1
  27. space/space/space/space/space/Dockerfile +2 -2
  28. space/space/space/space/space/space/controller/HomeController.go +1 -1
  29. space/space/space/space/space/space/router/router.go +2 -1
  30. space/space/space/space/space/space/space/.env.example +9 -0
  31. space/space/space/space/space/space/space/.github/workflows/main.yml +52 -0
  32. space/space/space/space/space/space/space/.gitignore +3 -0
  33. space/space/space/space/space/space/space/Dockerfile +30 -0
  34. space/space/space/space/space/space/space/config/DatabaseConfig.go +60 -0
  35. space/space/space/space/space/space/space/config/EnvConfig.go +16 -0
  36. space/space/space/space/space/space/space/controller/HomeController.go +9 -0
  37. space/space/space/space/space/space/space/controller/LoginController.go +19 -0
  38. space/space/space/space/space/space/space/controller/RegisterController.go +19 -0
  39. space/space/space/space/space/space/space/controller/controller.go +53 -0
  40. space/space/space/space/space/space/space/go.mod +48 -0
  41. space/space/space/space/space/space/space/go.sum +138 -0
  42. space/space/space/space/space/space/space/logs/error_log.txt +0 -0
  43. space/space/space/space/space/space/space/logs/security_log.txt +0 -0
  44. space/space/space/space/space/space/space/main.go +14 -0
  45. space/space/space/space/space/space/space/middleware/AuthMiddleware.go +103 -0
  46. space/space/space/space/space/space/space/middleware/middleware.go +31 -0
  47. space/space/space/space/space/space/space/middleware/responseMiddleware.go +39 -0
  48. space/space/space/space/space/space/space/models/AuthModel.go +7 -0
  49. space/space/space/space/space/space/space/models/DatabaseModel.go +30 -0
  50. space/space/space/space/space/space/space/models/ExceptionModel.go +11 -0
repositories/AccountRepository.go CHANGED
@@ -4,9 +4,9 @@ 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
  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],
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
  }
services/LoginService.go CHANGED
@@ -18,7 +18,7 @@ type AuthenticationService struct {
18
  }
19
 
20
  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 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!"
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/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/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/models/DatabaseModel.go CHANGED
@@ -2,14 +2,18 @@ package models
2
 
3
  import (
4
  "time"
 
 
5
  )
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"`
 
 
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/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/services/RegisterService.go CHANGED
@@ -14,7 +14,8 @@ type RegisterService struct {
14
  }
15
 
16
  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) {
@@ -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/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
- loginController.Service.Constructor.Email = loginController.Request.Email
16
- loginController.Service.Constructor.Password = loginController.Request.Password
17
- authentication.Authenticate()
18
- loginController.Response(c)
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/controller/RegisterController.go CHANGED
@@ -11,9 +11,9 @@ func RegisterController(c *gin.Context) {
11
  registerController := Controller[models.RegisterRequest, models.Account, models.Account]{
12
  Service: &register.Service,
13
  }
14
- registerController.RequestJSON(c)
15
- registerController.Service.Constructor.Password = registerController.Request.Password
16
- registerController.Service.Constructor.Email = registerController.Request.Email
17
- register.Create()
18
- registerController.Response(c)
19
  }
 
11
  registerController := Controller[models.RegisterRequest, models.Account, models.Account]{
12
  Service: &register.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/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 Type",
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/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:"primaryKey" json:"email"`
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/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
- Find(repo)
 
 
 
 
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/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 : " + string(i))
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.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
  }
 
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/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 email!"
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/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/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.Account]{
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/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/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.IDAccount
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/models/DatabaseModel.go CHANGED
@@ -5,14 +5,11 @@ import (
5
  )
6
 
7
  type Account struct {
8
- IDAccount uint `gorm:"primaryKey" json:"id_account"`
9
- Name string `json:"name"`
10
- Username string `json:"username"`
11
- Email string `json:"email"`
12
- Password string `json:"password"`
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/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/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(username string, password string) Repository[models.Account, models.Account] {
10
  repo := Construct[models.Account, models.Account](
11
- models.Account{Username: username, Password: password},
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/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
- fmt.Println(repo.Constructor)
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/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.Account]
16
  }
17
 
18
  func (s *AuthenticationService) Authenticate() {
@@ -29,7 +31,17 @@ func (s *AuthenticationService) Authenticate() {
29
  return
30
  }
31
 
32
- s.Result = accountData.Result
 
 
 
 
 
 
 
 
 
 
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/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 = "There is account registered with given data!"
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/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/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 Quzuu Backend 2024!",
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/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/.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/.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/.gitignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ .env
2
+ vendor/
3
+ quzuu-be.exe
space/space/space/space/space/space/space/Dockerfile ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Gunakan image dasar Golang versi 1.21.6
2
+ FROM golang:1.21.6
3
+
4
+ # Set working directory
5
+ WORKDIR /app
6
+
7
+ # Copy go.mod dan go.sum
8
+ COPY go.mod go.sum ./
9
+
10
+ # Download dependencies
11
+ RUN go mod download
12
+
13
+ # Copy seluruh kode
14
+ COPY . .
15
+
16
+ # Buat file .env dengan variabel environment yang dibutuhkan
17
+ RUN echo "DB_HOST=aws-0-ap-southeast-1.pooler.supabase.com" >> .env && \
18
+ echo "DB_USER=postgres.rdscploxoikqsevhduii" >> .env && \
19
+ echo "DB_PASSWORD=Qobiltu12233334444" >> .env && \
20
+ echo "DB_PORT=5432" >> .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
+
29
+ # Jalankan aplikasi
30
+ CMD ["./main"]
space/space/space/space/space/space/space/config/DatabaseConfig.go ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package config
2
+
3
+ import (
4
+ "fmt"
5
+ "log"
6
+ "os"
7
+
8
+ "gorm.io/driver/postgres"
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
35
+
36
+ func init() {
37
+ godotenv.Load()
38
+ if err != nil {
39
+ fmt.Println("Gagal membaca file .env")
40
+ return
41
+ }
42
+ os.Setenv("TZ", "Asia/Jakarta")
43
+ dbHost := os.Getenv("DB_HOST")
44
+ dbPort := os.Getenv("DB_PORT")
45
+ dbUser := os.Getenv("DB_USER")
46
+ dbPassword := os.Getenv("DB_PASSWORD")
47
+ dbName := os.Getenv("DB_NAME")
48
+ Salt := os.Getenv("SALT")
49
+ dsn := "host=" + dbHost + " user=" + dbUser + " password=" + dbPassword + " dbname=" + dbName + " port=" + dbPort + " sslmode=disable TimeZone=Asia/Jakarta"
50
+ DB, err = gorm.Open(postgres.Open(dsn), &gorm.Config{TranslateError: true})
51
+ if err != nil {
52
+ panic(err)
53
+ }
54
+ if Salt == "" {
55
+ Salt = "D3f4u|t"
56
+ }
57
+
58
+ // Call AutoMigrateAll to perform auto-migration
59
+ AutoMigrateAll(DB)
60
+ }
space/space/space/space/space/space/space/config/EnvConfig.go ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package config
2
+
3
+ import "os"
4
+
5
+ var TCP_ADDRESS string
6
+ var LOG_PATH string
7
+ var HOST_ADDRESS string
8
+ var HOST_PORT string
9
+
10
+ func init() {
11
+ HOST_ADDRESS = os.Getenv("HOST_ADDRESS")
12
+ HOST_PORT = os.Getenv("HOST_PORT")
13
+ TCP_ADDRESS = HOST_ADDRESS + ":" + HOST_PORT
14
+ LOG_PATH = os.Getenv("LOG_PATH")
15
+ // Menampilkan nilai variabel lingkungan
16
+ }
space/space/space/space/space/space/space/controller/HomeController.go ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ package controller
2
+
3
+ import "github.com/gin-gonic/gin"
4
+
5
+ func HomeController(c *gin.Context) {
6
+ c.JSON(200, gin.H{
7
+ "message": "Api Quzuu Backend 2024!",
8
+ })
9
+ }
space/space/space/space/space/space/space/controller/LoginController.go ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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) {
10
+ authentication := services.AuthenticationService{}
11
+ loginController := Controller[models.LoginRequest, services.LoginConstructor, models.Account]{
12
+ Service: &authentication.Service,
13
+ }
14
+ loginController.RequestJSON(c)
15
+ loginController.Service.Constructor.Email = loginController.Request.Email
16
+ loginController.Service.Constructor.Password = loginController.Request.Password
17
+ authentication.Authenticate()
18
+ loginController.Response(c)
19
+ }
space/space/space/space/space/space/space/controller/RegisterController.go ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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) {
10
+ register := services.RegisterService{}
11
+ registerController := Controller[models.RegisterRequest, models.Account, models.Account]{
12
+ Service: &register.Service,
13
+ }
14
+ registerController.RequestJSON(c)
15
+ registerController.Service.Constructor.Password = registerController.Request.Password
16
+ registerController.Service.Constructor.Email = registerController.Request.Email
17
+ register.Create()
18
+ registerController.Response(c)
19
+ }
space/space/space/space/space/space/space/controller/controller.go ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 (
11
+ Controllers interface {
12
+ RequestJSON(c *gin.Context)
13
+ Response(c *gin.Context)
14
+ }
15
+ Controller[T1 any, T2 any, T3 any] struct {
16
+ AccountData models.AccountData
17
+ Request T1
18
+ Service *services.Service[T2, T3]
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)
26
+ }
27
+ errBinding := c.ShouldBindJSON(&controller.Request)
28
+ if errBinding != nil {
29
+ utils.ResponseFAIL(c, 400, models.Exception{
30
+ BadRequest: true,
31
+ Message: "Invalid Request Type",
32
+ })
33
+ return
34
+ }
35
+ }
36
+ func (controller *Controller[T1, T2, T3]) Response(c *gin.Context) {
37
+ switch {
38
+ case controller.Service.Error != nil:
39
+ utils.ResponseFAIL(c, 500, models.Exception{
40
+ InternalServerError: true,
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:
47
+ utils.ResponseFAIL(c, 404, controller.Service.Exception)
48
+ case controller.Service.Exception.Message != "":
49
+ utils.ResponseFAIL(c, 400, controller.Service.Exception)
50
+ default:
51
+ utils.ResponseOK(c, controller.Service.Result)
52
+ }
53
+ }
space/space/space/space/space/space/space/go.mod ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module go-dp.abdanhafidz.com
2
+
3
+ go 1.21.0
4
+
5
+ require (
6
+ github.com/dgrijalva/jwt-go v3.2.0+incompatible
7
+ github.com/gin-gonic/gin v1.9.1
8
+ github.com/joho/godotenv v1.5.1
9
+ golang.org/x/crypto v0.32.0
10
+ gorm.io/driver/postgres v1.5.4
11
+ gorm.io/gorm v1.25.5
12
+ )
13
+
14
+ require (
15
+ github.com/bytedance/sonic v1.10.2 // indirect
16
+ github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
17
+ github.com/chenzhuoyu/iasm v0.9.0 // indirect
18
+ github.com/gabriel-vasile/mimetype v1.4.8 // indirect
19
+ github.com/gin-contrib/sse v0.1.0 // indirect
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.2 // indirect
24
+ github.com/jackc/pgpassfile v1.0.0 // indirect
25
+ github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
26
+ github.com/jackc/pgx/v5 v5.5.0 // indirect
27
+ github.com/jackc/puddle/v2 v2.2.1 // indirect
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.6 // indirect
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.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
42
+ golang.org/x/net v0.34.0 // indirect
43
+ golang.org/x/sync v0.10.0 // indirect
44
+ golang.org/x/sys v0.29.0 // indirect
45
+ golang.org/x/text v0.21.0 // indirect
46
+ google.golang.org/protobuf v1.31.0 // indirect
47
+ gopkg.in/yaml.v3 v3.0.1 // indirect
48
+ )
space/space/space/space/space/space/space/go.sum ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
2
+ github.com/bytedance/sonic v1.10.0-rc/go.mod h1:ElCzW+ufi8qKqNW0FY314xriJhyJhuoJ3gFZdAHF7NM=
3
+ github.com/bytedance/sonic v1.10.2 h1:GQebETVBxYB7JGWJtLBi07OVzWwt+8dWA00gEVW2ZFE=
4
+ github.com/bytedance/sonic v1.10.2/go.mod h1:iZcSUejdk5aukTND/Eu/ivjQuEL0Cu9/rf50Hi0u/g4=
5
+ github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY=
6
+ github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk=
7
+ github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d h1:77cEq6EriyTZ0g/qfRdp61a3Uu/AWrgIq2s0ClJV1g0=
8
+ github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d/go.mod h1:8EPpVsBuRksnlj1mLy4AWzRNQYxauNi62uWcE3to6eA=
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 v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
22
+ github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
23
+ github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg=
24
+ github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU=
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.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
36
+ github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
37
+ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
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-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=
44
+ github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
45
+ github.com/jackc/pgx/v5 v5.5.0 h1:NxstgwndsTRy7eq9/kqYc/BZh5w2hHJV86wjvO+1xPw=
46
+ github.com/jackc/pgx/v5 v5.5.0/go.mod h1:Ig06C2Vu0t5qXC60W8sqIthScaEnFvojjj9dSljmHRA=
47
+ github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk=
48
+ github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
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=
52
+ github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
53
+ github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
54
+ github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
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.6 h1:ndNyv040zDGIDh8thGkXYjnFtiN02M1PVVF+JE/48xc=
59
+ github.com/klauspost/cpuid/v2 v2.2.6/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
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=
70
+ github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
71
+ github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
72
+ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
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.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4=
77
+ github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
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=
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=
85
+ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
86
+ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
87
+ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
88
+ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
89
+ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
90
+ github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
91
+ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
92
+ github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
93
+ github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
94
+ github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
95
+ github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
96
+ github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
97
+ golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
98
+ golang.org/x/arch v0.6.0 h1:S0JTfE48HbRj80+4tbvZDYsJ3tGv6BUU3XxyZ7CirAc=
99
+ golang.org/x/arch v0.6.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
100
+ golang.org/x/crypto v0.15.0 h1:frVn1TEaCEaZcn3Tmd7Y2b5KKPaZ+I32Q2OA3kYp5TA=
101
+ golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g=
102
+ golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc=
103
+ golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc=
104
+ golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg=
105
+ golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ=
106
+ golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=
107
+ golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=
108
+ golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
109
+ golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
110
+ golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
111
+ golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
112
+ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
113
+ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
114
+ golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
115
+ golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
116
+ golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
117
+ golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
118
+ golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
119
+ golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
120
+ golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
121
+ golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
122
+ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
123
+ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
124
+ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
125
+ google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
126
+ google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
127
+ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
128
+ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
129
+ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
130
+ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
131
+ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
132
+ gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
133
+ gorm.io/driver/postgres v1.5.4 h1:Iyrp9Meh3GmbSuyIAGyjkN+n9K+GHX9b9MqsTL4EJCo=
134
+ gorm.io/driver/postgres v1.5.4/go.mod h1:Bgo89+h0CRcdA33Y6frlaHHVuTdOf87pmyzwW9C/BH0=
135
+ gorm.io/gorm v1.25.5 h1:zR9lOiiYf09VNh5Q1gphfyia1JpiClIWG9hQaxB/mls=
136
+ gorm.io/gorm v1.25.5/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
137
+ nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
138
+ rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
space/space/space/space/space/space/space/logs/error_log.txt ADDED
File without changes
space/space/space/space/space/space/space/logs/security_log.txt ADDED
File without changes
space/space/space/space/space/space/space/main.go ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package main
2
+
3
+ import (
4
+ "fmt"
5
+
6
+ "go-dp.abdanhafidz.com/config"
7
+ "go-dp.abdanhafidz.com/router"
8
+ )
9
+
10
+ func main() {
11
+ fmt.Println("Server started on ", config.TCP_ADDRESS, ", port :", config.HOST_PORT)
12
+ router.StartService()
13
+
14
+ }
space/space/space/space/space/space/space/middleware/AuthMiddleware.go ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // auth/auth.go
2
+
3
+ package middleware
4
+
5
+ import (
6
+ "errors"
7
+ "time"
8
+
9
+ "github.com/dgrijalva/jwt-go"
10
+ "github.com/gin-gonic/gin"
11
+ "go-dp.abdanhafidz.com/config"
12
+ "go-dp.abdanhafidz.com/models"
13
+ "golang.org/x/crypto/bcrypt"
14
+ )
15
+
16
+ // Define a secret key for signing the JWT token
17
+ var salt = config.Salt
18
+ var secretKey = []byte(salt)
19
+
20
+ // GenerateToken generates a JWT token for the given user
21
+ func GenerateToken(user *models.Account) (string, error) {
22
+
23
+ // Create a new token
24
+ token := jwt.New(jwt.SigningMethodHS256)
25
+
26
+ // Set claims
27
+ claims := token.Claims.(jwt.MapClaims)
28
+ claims["id"] = user.IDAccount
29
+ claims["exp"] = time.Now().Add(time.Hour * 24).Unix() // Token expires in 24 hours
30
+
31
+ // Sign the token with the secret key
32
+ tokenString, err := token.SignedString(secretKey)
33
+ if err != nil {
34
+ return "", err
35
+ }
36
+
37
+ return tokenString, nil
38
+ }
39
+
40
+ // VerifyPassword verifies if the provided password matches the hashed password
41
+ func VerifyPassword(hashedPassword, password string) error {
42
+ err := bcrypt.CompareHashAndPassword([]byte(hashedPassword), []byte(password))
43
+ if err != nil {
44
+ return errors.New("invalid password")
45
+ }
46
+ return nil
47
+ }
48
+ func HashPassword(password string) (string, error) {
49
+ bytes, err := bcrypt.GenerateFromPassword([]byte(password), 14)
50
+ return string(bytes), err
51
+ }
52
+
53
+ type CustomClaims struct {
54
+ jwt.StandardClaims
55
+ IDUser int `json:"id"`
56
+ }
57
+
58
+ func VerifyToken(bearer_token string) (int, string, error) {
59
+ // fmt.Println(bearer_token)
60
+ token, err := jwt.ParseWithClaims(bearer_token, &CustomClaims{}, func(token *jwt.Token) (interface{}, error) {
61
+ return secretKey, nil
62
+ })
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
+ } else if claims.StandardClaims.ExpiresAt != 0 && claims.ExpiresAt < time.Now().Unix() {
70
+ return 0, "expired", err
71
+ } else if !ok && token.Valid {
72
+ return 0, "invalid-token", err
73
+ }
74
+
75
+ return claims.IDUser, "valid", err
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.IdUser, currAccData.VerifyStatus, currAccData.ErrVerif = VerifyToken(token[0])
83
+ // fmt.Println("Verify Status :", currAccData.verifyStatus)
84
+ if currAccData.VerifyStatus == "invalid-token" || currAccData.VerifyStatus == "expired" {
85
+ currAccData.IdUser = 0
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.IdUser = 0
93
+ currAccData.VerifyStatus = "no-token"
94
+ currAccData.ErrVerif = nil
95
+ message := "You have to Login First!"
96
+ SendJSON401(c, &currAccData.VerifyStatus, &message)
97
+ c.Abort()
98
+ return
99
+ }
100
+
101
+ c.Set("accountData", currAccData)
102
+ c.Next()
103
+ }
space/space/space/space/space/space/space/middleware/middleware.go ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package middleware
2
+
3
+ import (
4
+ "math"
5
+ "time"
6
+
7
+ "gorm.io/gorm"
8
+ )
9
+
10
+ func RecordCheck(rows *gorm.DB) (string, error) {
11
+ count := rows.RowsAffected
12
+ err := rows.Error
13
+ // fmt.Println(rows)
14
+ // fmt.Println(count)
15
+ if count == 0 {
16
+ return "no-record", err
17
+ } else if err != nil {
18
+ return "query-error", err
19
+ } else {
20
+ return "ok", err
21
+ }
22
+ }
23
+
24
+ func DiffTime(t1 time.Time, t2 time.Time) (int, int, int) {
25
+ hs := t1.Sub(t2).Hours()
26
+ hs, mf := math.Modf(hs)
27
+ ms := mf * 60
28
+ ms, sf := math.Modf(ms)
29
+ ss := sf * 60
30
+ return int(hs), int(ms), int(ss)
31
+ }
space/space/space/space/space/space/space/middleware/responseMiddleware.go ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package middleware
2
+
3
+ import (
4
+ "net/http"
5
+
6
+ "github.com/gin-gonic/gin"
7
+ )
8
+
9
+ // SendJSON200 sends a JSON response with HTTP status code 200
10
+ func SendJSON200(c *gin.Context, data interface{}) {
11
+ c.JSON(http.StatusOK, gin.H{"status": "success", "data": data})
12
+ }
13
+
14
+ // SendJSON400 sends a JSON response with HTTP status code 400
15
+ func SendJSON400(c *gin.Context, error_status *string, message *string) {
16
+ c.JSON(http.StatusBadRequest, gin.H{"status": "error", "error-status": error_status, "message": message})
17
+ }
18
+
19
+ // SendJSON401 sends a JSON response with HTTP status code 401
20
+ func SendJSON401(c *gin.Context, error_status *string, message *string) {
21
+ c.JSON(http.StatusUnauthorized, gin.H{"status": "error", "error-status": error_status, "message": message})
22
+ }
23
+
24
+ // SendJSON403 sends a JSON response with HTTP status code 403
25
+ func SendJSON403(c *gin.Context, message *string) {
26
+ c.JSON(http.StatusForbidden, gin.H{"status": "error", "message": message})
27
+ }
28
+
29
+ // SendJSON404 sends a JSON response with HTTP status code 404
30
+ func SendJSON404(c *gin.Context, message *string) {
31
+ c.JSON(http.StatusNotFound, gin.H{"status": "error", "message": message})
32
+ }
33
+
34
+ // SendJSON500 sends a JSON response with HTTP status code 500
35
+ func SendJSON500(c *gin.Context, error_status *string, message *string) {
36
+ c.JSON(http.StatusInternalServerError, gin.H{"status": "error", "error-status": error_status, "message": message})
37
+ }
38
+
39
+ // JSONResponseMiddleware is a middleware that provides functions for sending JSON responses
space/space/space/space/space/space/space/models/AuthModel.go ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ package models
2
+
3
+ type AccountData struct {
4
+ IdUser int
5
+ VerifyStatus string
6
+ ErrVerif error
7
+ }
space/space/space/space/space/space/space/models/DatabaseModel.go ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package models
2
+
3
+ import (
4
+ "time"
5
+ )
6
+
7
+ type Account struct {
8
+ IDAccount uint `gorm:"primaryKey" json:"id_account"`
9
+ Name string `json:"name"`
10
+ Username string `json:"username"`
11
+ Email string `json:"email"`
12
+ Password string `json:"password"`
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 {
19
+ IDDetail uint `gorm:"primaryKey" json:"id_detail"`
20
+ IDAccount uint `json:"id_account"`
21
+ Province string `json:"province"`
22
+ City string `json:"city"`
23
+ Institution string `json:"institution"`
24
+ UpdatedAt time.Time `json:"updated_at"`
25
+ DeletedAt time.Time `json:"deleted_at"`
26
+ }
27
+
28
+ // Gorm table name settings
29
+ func (Account) TableName() string { return "account" }
30
+ func (AccountDetails) TableName() string { return "account_details" }
space/space/space/space/space/space/space/models/ExceptionModel.go ADDED
@@ -0,0 +1,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
+ Message string `json:"message,omitempty"`
11
+ }