diff --git a/services/external_authentication_service.go b/services/external_authentication_service.go index 42a6754ca09b41548528a2bcd7ef1d15362dc39b..4fe63453d49c45b5d8d4272de2f54f1184850b35 100644 --- a/services/external_authentication_service.go +++ b/services/external_authentication_service.go @@ -32,17 +32,34 @@ func (s *GoogleAuthService) Authenticate(isAgree bool) { } s.Constructor.UUID = uuid.NewV4() s.Constructor.OauthProvider = "Google" + checkRegisteredEmail := repositories.GetAccountbyEmail(email.(string)) + if !checkRegisteredEmail.NoRecord { + s.Exception.DataDuplicate = true + s.Exception.Message = "Account with email" + email.(string) + "already registered!" + return + } + createAccount := repositories.CreateAccount(models.Account{ UUID: uuid.NewV4(), Email: email.(string), IsEmailVerified: true, }) + s.Constructor.AccountID = createAccount.Result.Id createGoogleAuth := repositories.CreateExternalAuth(s.Constructor) - GoogleAuth.Result.AccountID = createGoogleAuth.Result.ID + + GoogleAuth.Result.AccountID = createGoogleAuth.Result.AccountID + userProfile := UserProfileService{} + userProfile.Constructor.AccountID = GoogleAuth.Result.AccountID + userProfile.Create() + if userProfile.Error != nil { + s.Error = userProfile.Error + return + } s.Error = createGoogleAuth.RowsError s.Error = errors.Join(s.Error, createAccount.RowsError) } + accountData := repositories.GetAccountById(GoogleAuth.Result.AccountID) token, err_tok := GenerateToken(&accountData.Result) diff --git a/space/controller/academy/academy_controller.go b/space/controller/academy/academy_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..f4210c585c26c026eb45a44c42b059cb875a51c4 --- /dev/null +++ b/space/controller/academy/academy_controller.go @@ -0,0 +1,31 @@ +package academy + +import ( + "api.qobiltu.id/controller" + "api.qobiltu.id/models" + "api.qobiltu.id/services" + "github.com/gin-gonic/gin" +) + +func List(c *gin.Context) { + academy := services.AcademyService{} + academyController := controller.Controller[any, models.Academy, models.AllAcademyResponse]{ + Service: &academy.Service, + } + academyController.Service.Constructor.Slug = c.Param("slug") + academy.Retrieve() + academyController.Response(c) + +} + +func Create(c *gin.Context) { + createAcademy := services.CreateAcademyService{} + academyController := controller.Controller[models.AllAcademyResponse, models.AllAcademyResponse, models.AllAcademyResponse]{ + Service: &createAcademy.Service, + } + academyController.RequestJSON(c, func() { + academyController.Service.Constructor.Academies = academyController.Request.Academies + createAcademy.Create() + }) + +} diff --git a/space/logs/error_log.txt b/space/logs/error_log.txt index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0b8db193b330dec003fe3655db3aed2cc2ad878e 100644 --- a/space/logs/error_log.txt +++ b/space/logs/error_log.txt @@ -0,0 +1,2 @@ +2025/04/20 10:05:28 Error Log : duplicated key not allowed +2025/04/20 10:11:41 Error Log : duplicated key not allowed diff --git a/space/models/database_orm_model.go b/space/models/database_orm_model.go index c7d9163ce8ab396cd38c1317229e931e7da31765..96eabef126ed5779aa33b9f1c557192b3668689a 100644 --- a/space/models/database_orm_model.go +++ b/space/models/database_orm_model.go @@ -30,7 +30,7 @@ type AccountDetails struct { LastEducation *string `json:"last_education"` MaritalStatus *string `json:"marital_status"` Avatar *string `json:"avatar"` - PhoneNumber *uint `json:"phone_number"` + PhoneNumber *string `json:"phone_number"` } type EmailVerification struct { @@ -85,12 +85,12 @@ type AcademyMaterial struct { } type AcademyContent struct { - ID uint `gorm:"primaryKey" json:"id"` - UUID uint `json:"uuid"` - Title string `json:"title"` - Order uint `json:"order"` - AcademyMaterialID uint `json:"academy_material_id"` - Description string `json:"description"` + ID uint `gorm:"primaryKey" json:"id"` + UUID uuid.UUID `json:"uuid"` + Title string `json:"title"` + Order uint `json:"order"` + AcademyMaterialID uint `json:"academy_material_id"` + Description string `json:"description"` } type OptionCategory struct { ID uint `gorm:"primaryKey" json:"id"` diff --git a/space/repositories/academy_repository.go b/space/repositories/academy_repository.go index cb0f622ed5478b2289afd6afc1645f4920db15a7..2a9235d4343ea63f784fd65184f498dca8c88338 100644 --- a/space/repositories/academy_repository.go +++ b/space/repositories/academy_repository.go @@ -13,9 +13,9 @@ func GetAllAcademy() Repository[models.Academy, []models.Academy] { return *repo } -func GetAcademyDataById(academyId uint) Repository[models.Academy, models.Academy] { +func GetAcademyDataBySlug(slug string) Repository[models.Academy, models.Academy] { repo := Construct[models.Academy, models.Academy]( - models.Academy{ID: academyId}, + models.Academy{Slug: slug}, ) repo.Transactions( WhereGivenConstructor[models.Academy, models.Academy], @@ -45,3 +45,29 @@ func GetAllAcademyContentsByMaterialID(materialId uint) Repository[models.Academ ) return *repo } + +func CreateAcademy(academies models.Academy) Repository[models.Academy, models.Academy] { + repo := Construct[models.Academy, models.Academy]( + academies, + ) + + Create(repo) + return *repo +} + +func CreateAcademyMaterial(academyMaterial models.AcademyMaterial) Repository[models.AcademyMaterial, models.AcademyMaterial] { + repo := Construct[models.AcademyMaterial, models.AcademyMaterial]( + academyMaterial, + ) + + Create(repo) + return *repo +} + +func CreateAcademyContent(academyContent models.AcademyContent) Repository[models.AcademyContent, models.AcademyContent] { + repo := Construct[models.AcademyContent, models.AcademyContent]( + academyContent, + ) + Create(repo) + return *repo +} diff --git a/space/router/academy_route.go b/space/router/academy_route.go new file mode 100644 index 0000000000000000000000000000000000000000..d8be676cadb26d2e57fd285239a9c6c094b75480 --- /dev/null +++ b/space/router/academy_route.go @@ -0,0 +1,16 @@ +package router + +import ( + AcademyController "api.qobiltu.id/controller/academy" + "api.qobiltu.id/middleware" + "github.com/gin-gonic/gin" +) + +func AcademyRoute(router *gin.Engine) { + routerGroup := router.Group("/api/v1/academy") + { + routerGroup.GET("/list/:slug", middleware.AuthUser, AcademyController.List) + routerGroup.GET("/list", middleware.AuthUser, AcademyController.List) + routerGroup.POST("/create", middleware.AuthUser, AcademyController.Create) + } +} diff --git a/space/router/router.go b/space/router/router.go index 6987e5456230d0a920b4e44a77163fade344beb7..31b36acd86c58c477d59b9f8b7cbaf0bee703550 100644 --- a/space/router/router.go +++ b/space/router/router.go @@ -16,7 +16,7 @@ func StartService() { UserRoute(router) EmailRoute(router) OptionsRoute(router) - + AcademyRoute(router) err := router.Run(config.TCP_ADDRESS) if err != nil { log.Fatalf("Failed to run server: %v", err) diff --git a/space/services/academy_service.go b/space/services/academy_service.go index 1c82f8c535f258bc0743fb84fd6d73d3357b2855..dc76d9e7081bf732839969a398df2c16b756b906 100644 --- a/space/services/academy_service.go +++ b/space/services/academy_service.go @@ -3,38 +3,102 @@ package services import ( "api.qobiltu.id/models" "api.qobiltu.id/repositories" + "github.com/gosimple/slug" + uuid "github.com/satori/go.uuid" ) type AcademyService struct { Service[models.Academy, models.AllAcademyResponse] } +type CreateAcademyService struct { + Service[models.AllAcademyResponse, models.AllAcademyResponse] +} + +func castAcademyMaterials(academyId uint) []models.AcademyMaterialResponse { + var ArrMaterials []models.AcademyMaterialResponse + for _, academyMaterial := range repositories.GetAllAcademyMaterialsByAcademyID(academyId).Result { + ArrMaterials = append(ArrMaterials, models.AcademyMaterialResponse{ + Materials: academyMaterial, + Contents: repositories.GetAllAcademyContentsByMaterialID(academyMaterial.ID).Result, + }) + } + return ArrMaterials +} func (s *AcademyService) Retrieve() { - if s.Constructor.ID != 0 { - AcademyRepo := repositories.GetAcademyDataById(s.Constructor.ID) + if s.Constructor.Slug != "" { + AcademyRepo := repositories.GetAcademyDataBySlug(s.Constructor.Slug) s.Error = AcademyRepo.RowsError if AcademyRepo.NoRecord { s.Exception.Message = "Academy not found" s.Exception.DataNotFound = true return } - var ArrMaterials []models.AcademyMaterialResponse - for _, academyMaterial := range repositories.GetAllAcademyMaterialsByAcademyID(s.Constructor.ID).Result { - ArrMaterials = append(ArrMaterials, models.AcademyMaterialResponse{ - Materials: academyMaterial, - Contents: repositories.GetAllAcademyContentsByMaterialID(academyMaterial.ID).Result, - }) - } + s.Result = models.AllAcademyResponse{ Academies: []models.AcademyResponse{ models.AcademyResponse{ Academy: AcademyRepo.Result, - Materials: ArrMaterials, + Materials: castAcademyMaterials(s.Constructor.ID), }, }, } } else { - // AcademyRepo := repositories.GetAllAcademy() + AcademyRepo := repositories.GetAllAcademy() + s.Error = AcademyRepo.RowsError + var ArrAcademy []models.AcademyResponse + for _, academy := range AcademyRepo.Result { + ArrAcademy = append(ArrAcademy, models.AcademyResponse{ + Academy: academy, + Materials: castAcademyMaterials(academy.ID), + }) + } + s.Result = models.AllAcademyResponse{ + Academies: ArrAcademy, + } + } + +} + +func (s *CreateAcademyService) Create() { + var ArrAcademy []models.AcademyResponse + for _, academy := range s.Constructor.Academies { + academy.Academy.UUID = uuid.NewV4() + if academy.Academy.Slug == "" { + academy.Academy.Slug = slug.Make(academy.Academy.Title) + } + + createdAcademy := repositories.CreateAcademy(academy.Academy) + if createdAcademy.RowsError != nil { + s.Error = createdAcademy.RowsError + return + } + for _, material := range academy.Materials { + material.Materials.AcademyID = createdAcademy.Result.ID + material.Materials.UUID = uuid.NewV4() + if material.Materials.Slug == "" { + material.Materials.Slug = slug.Make(material.Materials.Title) + } + createdMaterial := repositories.CreateAcademyMaterial(material.Materials) + if createdMaterial.RowsError != nil { + s.Error = createdMaterial.RowsError + return + } + for _, content := range material.Contents { + content.UUID = uuid.NewV4() + content.AcademyMaterialID = createdMaterial.Result.ID + createdContent := repositories.CreateAcademyContent(content) + if createdContent.RowsError != nil { + s.Error = createdContent.RowsError + return + } + ArrAcademy = append(ArrAcademy, models.AcademyResponse{ + Academy: createdAcademy.Result, + Materials: castAcademyMaterials(createdAcademy.Result.ID), + }) + } + } } + s.Result = models.AllAcademyResponse{Academies: ArrAcademy} } diff --git a/space/services/email_verification_service.go b/space/services/email_verification_service.go index ea6a81d13ba4bcbea9c844dd2156911555133bd2..d156bc532db21abb6f992626e82cc931648bf62c 100644 --- a/space/services/email_verification_service.go +++ b/space/services/email_verification_service.go @@ -29,7 +29,10 @@ func (s *EmailVerificationService) Create() { remainingTime := time.Duration(config.EMAIL_VERIFICATION_DURATION) * time.Hour dueTime := CalculateDueTime(remainingTime) - token := uint(rand.IntN(100000)) + token := uint(rand.IntN(1000000)) + for token < 1000000 { + token = uint(rand.IntN(1000000)) + } s.Constructor.UUID = uuid.NewV4() repo := repositories.CreateEmailVerification(s.Constructor.UUID, s.Constructor.AccountID, dueTime, token) @@ -83,7 +86,7 @@ func (s *EmailVerificationService) Validate() { } account := repositories.GetAccountById(repo.Result.AccountID) account.Result.IsEmailVerified = true - + repositories.UpdateAccount(account.Result) s.Result = repo.Result } diff --git a/space/services/forgot_password_service.go b/space/services/forgot_password_service.go index 1e6475810c7ef360a35d597405e38f9b287003db..473bcf17fa8d55afdc313a25659e29ddae6f7e16 100644 --- a/space/services/forgot_password_service.go +++ b/space/services/forgot_password_service.go @@ -34,7 +34,10 @@ func (s *ForgotPasswordService) Create(email string) { remainingTime := time.Duration(config.EMAIL_VERIFICATION_DURATION) * time.Hour dueTime := CalculateDueTime(remainingTime) - token := uint(rand.IntN(100000)) + token := uint(rand.IntN(1000000)) + for token < 1000000 { + token = uint(rand.IntN(1000000)) + } s.Constructor.UUID = uuid.NewV4() s.Constructor.ExpiredAt = dueTime s.Constructor.AccountID = accountRepo.Result.Id diff --git a/space/space/logs/error_log.txt b/space/space/logs/error_log.txt index 8b137891791fe96927ad78e64b0aad7bded08bdc..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 --- a/space/space/logs/error_log.txt +++ b/space/space/logs/error_log.txt @@ -1 +0,0 @@ - diff --git a/space/space/models/response_model.go b/space/space/models/response_model.go index 72a976d610df12deaa49c571c86c47bf2d04e0ae..eee34890fbf3519de21c401fbdcbf6c60bebb852 100644 --- a/space/space/models/response_model.go +++ b/space/space/models/response_model.go @@ -31,12 +31,15 @@ type UserProfileResponse struct { Details AccountDetails `json:"details"` } -type AkademiDasar struct { - Academies Academy `json:"academy"` - Materials []AcademyMaterial `json:"academy_material"` - Contents []AcademyContent `json:"academy_content"` +type AcademyMaterialResponse struct { + Materials AcademyMaterial + Contents []AcademyContent +} +type AcademyResponse struct { + Academy Academy `json:"academy"` + Materials []AcademyMaterialResponse `json:"academy_materials"` } -type AkademiDasarResponse struct { - AkademiDasar []AkademiDasar `json:"academy_dasar"` +type AllAcademyResponse struct { + Academies []AcademyResponse `json:"academy_dasar"` } diff --git a/space/space/repositories/academy_repository.go b/space/space/repositories/academy_repository.go new file mode 100644 index 0000000000000000000000000000000000000000..cb0f622ed5478b2289afd6afc1645f4920db15a7 --- /dev/null +++ b/space/space/repositories/academy_repository.go @@ -0,0 +1,47 @@ +package repositories + +import "api.qobiltu.id/models" + +func GetAllAcademy() Repository[models.Academy, []models.Academy] { + repo := Construct[models.Academy, []models.Academy]( + models.Academy{}, + ) + repo.Transactions( + WhereGivenConstructor[models.Academy, []models.Academy], + Find[models.Academy, []models.Academy], + ) + return *repo +} + +func GetAcademyDataById(academyId uint) Repository[models.Academy, models.Academy] { + repo := Construct[models.Academy, models.Academy]( + models.Academy{ID: academyId}, + ) + repo.Transactions( + WhereGivenConstructor[models.Academy, models.Academy], + Find[models.Academy, models.Academy], + ) + return *repo +} + +func GetAllAcademyMaterialsByAcademyID(acaddemyId uint) Repository[models.AcademyMaterial, []models.AcademyMaterial] { + repo := Construct[models.AcademyMaterial, []models.AcademyMaterial]( + models.AcademyMaterial{AcademyID: acaddemyId}, + ) + repo.Transactions( + WhereGivenConstructor[models.AcademyMaterial, []models.AcademyMaterial], + Find[models.AcademyMaterial, []models.AcademyMaterial], + ) + return *repo +} + +func GetAllAcademyContentsByMaterialID(materialId uint) Repository[models.AcademyContent, []models.AcademyContent] { + repo := Construct[models.AcademyContent, []models.AcademyContent]( + models.AcademyContent{AcademyMaterialID: materialId}, + ) + repo.Transactions( + WhereGivenConstructor[models.AcademyContent, []models.AcademyContent], + Find[models.AcademyContent, []models.AcademyContent], + ) + return *repo +} diff --git a/space/space/services/academy_service.go b/space/space/services/academy_service.go new file mode 100644 index 0000000000000000000000000000000000000000..1c82f8c535f258bc0743fb84fd6d73d3357b2855 --- /dev/null +++ b/space/space/services/academy_service.go @@ -0,0 +1,40 @@ +package services + +import ( + "api.qobiltu.id/models" + "api.qobiltu.id/repositories" +) + +type AcademyService struct { + Service[models.Academy, models.AllAcademyResponse] +} + +func (s *AcademyService) Retrieve() { + if s.Constructor.ID != 0 { + AcademyRepo := repositories.GetAcademyDataById(s.Constructor.ID) + s.Error = AcademyRepo.RowsError + if AcademyRepo.NoRecord { + s.Exception.Message = "Academy not found" + s.Exception.DataNotFound = true + return + } + var ArrMaterials []models.AcademyMaterialResponse + for _, academyMaterial := range repositories.GetAllAcademyMaterialsByAcademyID(s.Constructor.ID).Result { + ArrMaterials = append(ArrMaterials, models.AcademyMaterialResponse{ + Materials: academyMaterial, + Contents: repositories.GetAllAcademyContentsByMaterialID(academyMaterial.ID).Result, + }) + } + s.Result = models.AllAcademyResponse{ + Academies: []models.AcademyResponse{ + models.AcademyResponse{ + Academy: AcademyRepo.Result, + Materials: ArrMaterials, + }, + }, + } + } else { + // AcademyRepo := repositories.GetAllAcademy() + } + +} diff --git a/space/space/services/external_authentication_service.go b/space/space/services/external_authentication_service.go index 22d723bd821f351074a1840afd7474338872a15d..42a6754ca09b41548528a2bcd7ef1d15362dc39b 100644 --- a/space/space/services/external_authentication_service.go +++ b/space/space/services/external_authentication_service.go @@ -33,6 +33,7 @@ func (s *GoogleAuthService) Authenticate(isAgree bool) { s.Constructor.UUID = uuid.NewV4() s.Constructor.OauthProvider = "Google" createAccount := repositories.CreateAccount(models.Account{ + UUID: uuid.NewV4(), Email: email.(string), IsEmailVerified: true, }) diff --git a/space/space/services/forgot_password_service.go b/space/space/services/forgot_password_service.go index d4d232aeaed0f9cf844b708148c99b2c1e165a6a..1e6475810c7ef360a35d597405e38f9b287003db 100644 --- a/space/space/services/forgot_password_service.go +++ b/space/space/services/forgot_password_service.go @@ -71,13 +71,6 @@ func (s *ForgotPasswordService) Create(email string) { } func (s *ForgotPasswordService) Validate(newPassword *string) { - accountRepo := repositories.GetAccountById(s.Constructor.AccountID) - if accountRepo.NoRecord { - s.Error = accountRepo.RowsError - s.Exception.DataNotFound = true - s.Exception.Message = "There is no account data with given credentials!" - return - } fgPasswordRepo := repositories.GetForgotPasswordByToken(s.Constructor.Token) s.Error = fgPasswordRepo.RowsError @@ -91,13 +84,24 @@ func (s *ForgotPasswordService) Validate(newPassword *string) { s.Exception.Message = "Token has expired!" return } + + accountRepo := repositories.GetAccountById(fgPasswordRepo.Result.AccountID) + if accountRepo.NoRecord { + s.Error = accountRepo.RowsError + s.Exception.DataNotFound = true + s.Exception.Message = "There is no account data with given credentials!" + return + } s.Result = fgPasswordRepo.Result if newPassword == nil { return } + // fmt.Println("Previous Account", accountRepo.Result) + // fmt.Println("New password", *newPassword) hashed_password, _ := HashPassword(*newPassword) accountRepo.Result.Password = hashed_password changePassword := repositories.UpdateAccount(accountRepo.Result) + // fmt.Println("New Account", changePassword.Result) if changePassword.RowsError != nil { s.Error = changePassword.RowsError s.Exception.QueryError = true diff --git a/space/space/space/space/go.mod b/space/space/space/space/go.mod index b2be1362b4b37f0263c167a1280104d999ea356d..aa7905ab737698db63d0a25f6ff4ca83c195e4e1 100644 --- a/space/space/space/space/go.mod +++ b/space/space/space/space/go.mod @@ -5,9 +5,11 @@ go 1.24.0 require ( github.com/gin-gonic/gin v1.10.0 github.com/golang-jwt/jwt/v5 v5.2.1 + github.com/gosimple/slug v1.15.0 github.com/joho/godotenv v1.5.1 github.com/satori/go.uuid v1.2.0 golang.org/x/crypto v0.36.0 + google.golang.org/api v0.228.0 gorm.io/driver/postgres v1.5.11 gorm.io/gorm v1.25.12 ) @@ -31,7 +33,6 @@ require ( github.com/google/s2a-go v0.1.9 // indirect github.com/googleapis/enterprise-certificate-proxy v0.3.6 // indirect github.com/googleapis/gax-go/v2 v2.14.1 // indirect - github.com/gosimple/slug v1.15.0 // indirect github.com/gosimple/unidecode v1.0.1 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect @@ -41,13 +42,11 @@ require ( github.com/jinzhu/now v1.1.5 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/cpuid/v2 v2.2.10 // indirect - github.com/kr/text v0.2.0 // indirect github.com/leodido/go-urn v1.4.0 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/pelletier/go-toml/v2 v2.2.3 // indirect - github.com/rogpeppe/go-internal v1.13.1 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.12 // indirect go.opentelemetry.io/auto/sdk v1.1.0 // indirect @@ -56,13 +55,11 @@ require ( go.opentelemetry.io/otel/metric v1.34.0 // indirect go.opentelemetry.io/otel/trace v1.34.0 // indirect golang.org/x/arch v0.15.0 // indirect - golang.org/x/exp v0.0.0-20250305212735-054e65f0b394 // indirect golang.org/x/net v0.37.0 // indirect golang.org/x/oauth2 v0.28.0 // indirect golang.org/x/sync v0.12.0 // indirect golang.org/x/sys v0.31.0 // indirect golang.org/x/text v0.23.0 // indirect - google.golang.org/api v0.228.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20250313205543-e70fdf4c4cb4 // indirect google.golang.org/grpc v1.71.0 // indirect google.golang.org/protobuf v1.36.6 // indirect diff --git a/space/space/space/space/go.sum b/space/space/space/space/go.sum index 5497ec831debdb4d4cfb521ba2a52edced87edb2..4fac69c64291b273a4a6b4d6887c80b0f43f7bc3 100644 --- a/space/space/space/space/go.sum +++ b/space/space/space/space/go.sum @@ -12,7 +12,6 @@ github.com/bytedance/sonic/loader v0.2.4/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFos github.com/cloudwego/base64x v0.1.5 h1:XPciSp1xaq2VCSt6lF0phncD4koWyULpl5bUxbfCyP4= github.com/cloudwego/base64x v0.1.5/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY= -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -41,11 +40,15 @@ github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4= github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk= github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= -github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= +github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= +github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/s2a-go v0.1.9 h1:LGD7gtMgezd8a/Xak7mEWL0PjoTQFvpRudN895yqKW0= github.com/google/s2a-go v0.1.9/go.mod h1:YA0Ei2ZQL3acow2O62kdp9UlnvMmU7kA6Eutn0dXayM= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/enterprise-certificate-proxy v0.3.6 h1:GW/XbdyBFQ8Qe+YAmFU9uHLo7OnF5tL52HFAgMmyrf4= github.com/googleapis/enterprise-certificate-proxy v0.3.6/go.mod h1:MkHOF77EYAE7qfSuSS9PU6g4Nt4e11cnsDUowfwewLA= github.com/googleapis/gax-go/v2 v2.14.1 h1:hb0FFeiPaQskmvakKu5EbCbpntQn48jyHuvrkurSS/Q= @@ -74,8 +77,8 @@ github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa02 github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE= github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0= github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= -github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= -github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= @@ -91,8 +94,7 @@ github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNH github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= -github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= +github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII= github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o= github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww= github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= @@ -114,20 +116,24 @@ github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65E github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA= go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A= +go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.59.0 h1:rgMkmiGfix9vFJDcDi1PK8WEQP4FLQwLDfhp5ZLpFeE= +go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.59.0/go.mod h1:ijPqXp5P6IRRByFVVg9DY8P5HkxkHE5ARIa+86aXPf4= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.59.0 h1:CV7UdSGJt/Ao6Gp4CXckLxVRRsRgDHoI8XjbL3PDl8s= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.59.0/go.mod h1:FRmFuRJfag1IZ2dPkHnEoSFVgTVPUd2qf5Vi69hLb8I= go.opentelemetry.io/otel v1.34.0 h1:zRLXxLCgL1WyKsPVrgbSdMN4c0FMkDAskSTQP+0hdUY= go.opentelemetry.io/otel v1.34.0/go.mod h1:OWFPOQ+h4G8xpyjgqo4SxJYdDQ/qmRH+wivy7zzx9oI= go.opentelemetry.io/otel/metric v1.34.0 h1:+eTR3U0MyfWjRDhmFMxe2SsW64QrZ84AOhvqS7Y+PoQ= go.opentelemetry.io/otel/metric v1.34.0/go.mod h1:CEDrp0fy2D0MvkXE+dPV7cMi8tWZwX3dmaIhwPOaqHE= +go.opentelemetry.io/otel/sdk v1.34.0 h1:95zS4k/2GOy069d321O8jWgYsW3MzVV+KuSPKp7Wr1A= +go.opentelemetry.io/otel/sdk v1.34.0/go.mod h1:0e/pNiaMAqaykJGKbi+tSjWfNNHMTxoC9qANsCzbyxU= +go.opentelemetry.io/otel/sdk/metric v1.34.0 h1:5CeK9ujjbFVL5c1PhLuStg1wxA7vQv7ce1EK0Gyvahk= +go.opentelemetry.io/otel/sdk/metric v1.34.0/go.mod h1:jQ/r8Ze28zRKoNRdkjCZxfs6YvBTG1+YIqyFVFYec5w= go.opentelemetry.io/otel/trace v1.34.0 h1:+ouXS2V8Rd4hp4580a8q23bg0azF2nI8cqLYnC8mh/k= go.opentelemetry.io/otel/trace v1.34.0/go.mod h1:Svm7lSjQD7kG7KJ/MUHPVXSDGz2OX4h0M2jHBhmSfRE= golang.org/x/arch v0.15.0 h1:QtOrQd0bTUnhNVNndMpLHNWrDmYzZ2KDqSrEymqInZw= golang.org/x/arch v0.15.0/go.mod h1:JmwW7aLIoRUKgaTzhkiEFxvcEiQGyOg9BMonBJUS7EE= golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34= golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc= -golang.org/x/exp v0.0.0-20250305212735-054e65f0b394 h1:nDVHiLt8aIbd/VzvPWN6kSOPE7+F/fNFDSXLVYkE/Iw= -golang.org/x/exp v0.0.0-20250305212735-054e65f0b394/go.mod h1:sIifuuw/Yco/y6yb6+bDNfyeQ/MdPUy/hKEMYQV17cM= golang.org/x/net v0.37.0 h1:1zLorHbz+LYj7MQlSf1+2tPIIgibq2eL5xkrGk6f+2c= golang.org/x/net v0.37.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8= golang.org/x/oauth2 v0.28.0 h1:CrgCKl8PPAVtLnU3c+EDw6x11699EWlsDeWNWKdIOkc= @@ -139,16 +145,14 @@ golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik= golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY= golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/time v0.11.0 h1:/bpjEDfN9tkoN/ryeYHnv5hcMlc8ncjMcM4XBk5NWV0= +golang.org/x/time v0.11.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg= google.golang.org/api v0.228.0 h1:X2DJ/uoWGnY5obVjewbp8icSL5U4FzuCfy9OjbLSnLs= google.golang.org/api v0.228.0/go.mod h1:wNvRS1Pbe8r4+IfBIniV8fwCpGwTrYa+kMUDiC5z5a4= google.golang.org/genproto/googleapis/rpc v0.0.0-20250313205543-e70fdf4c4cb4 h1:iK2jbkWL86DXjEx0qiHcRE9dE4/Ahua5k6V8OWFb//c= google.golang.org/genproto/googleapis/rpc v0.0.0-20250313205543-e70fdf4c4cb4/go.mod h1:LuRYeWDFV6WOn90g357N17oMCaxpgCnbi/44qJvDn2I= google.golang.org/grpc v1.71.0 h1:kF77BGdPTQ4/JZWMlb9VpJ5pa25aqvVqogsxNHHdeBg= google.golang.org/grpc v1.71.0/go.mod h1:H0GRtasmQOh9LkFoCPDu3ZrwUtD1YGE+b2vYBYd/8Ec= -google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM= -google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY= google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/space/space/space/space/space/models/request_model.go b/space/space/space/space/space/models/request_model.go index a37348207592c3450462cf468b9d3edab86962dc..80e5e088cf171bff6841265d01caf14510b7ac53 100644 --- a/space/space/space/space/space/models/request_model.go +++ b/space/space/space/space/space/models/request_model.go @@ -38,5 +38,5 @@ type ForgotPasswordRequest struct { } type ValidateForgotPasswordRequest struct { Token uint `json:"token" binding:"required"` - NewPassword string `json:"new_password" binding:"required"` + NewPassword string `json:"new_password"` } diff --git a/space/space/space/space/space/models/response_model.go b/space/space/space/space/space/models/response_model.go index 3b90d6d4505bb2677ff4b44a9088e0a62cd656c8..72a976d610df12deaa49c571c86c47bf2d04e0ae 100644 --- a/space/space/space/space/space/models/response_model.go +++ b/space/space/space/space/space/models/response_model.go @@ -30,3 +30,13 @@ type UserProfileResponse struct { Account Account `json:"account"` Details AccountDetails `json:"details"` } + +type AkademiDasar struct { + Academies Academy `json:"academy"` + Materials []AcademyMaterial `json:"academy_material"` + Contents []AcademyContent `json:"academy_content"` +} + +type AkademiDasarResponse struct { + AkademiDasar []AkademiDasar `json:"academy_dasar"` +} diff --git a/space/space/space/space/space/services/forgot_password_service.go b/space/space/space/space/space/services/forgot_password_service.go index 50eaf00379e50ea7979b228a0c3a7a016a03c3a9..d4d232aeaed0f9cf844b708148c99b2c1e165a6a 100644 --- a/space/space/space/space/space/services/forgot_password_service.go +++ b/space/space/space/space/space/services/forgot_password_service.go @@ -70,7 +70,7 @@ func (s *ForgotPasswordService) Create(email string) { // s.Result.Token = 0 } -func (s *ForgotPasswordService) Validate(newPassword string) { +func (s *ForgotPasswordService) Validate(newPassword *string) { accountRepo := repositories.GetAccountById(s.Constructor.AccountID) if accountRepo.NoRecord { s.Error = accountRepo.RowsError @@ -91,7 +91,11 @@ func (s *ForgotPasswordService) Validate(newPassword string) { s.Exception.Message = "Token has expired!" return } - hashed_password, _ := HashPassword(newPassword) + s.Result = fgPasswordRepo.Result + if newPassword == nil { + return + } + hashed_password, _ := HashPassword(*newPassword) accountRepo.Result.Password = hashed_password changePassword := repositories.UpdateAccount(accountRepo.Result) if changePassword.RowsError != nil { @@ -101,5 +105,5 @@ func (s *ForgotPasswordService) Validate(newPassword string) { return } // fgPasswordRepo.Result.Token = 0 - s.Result = fgPasswordRepo.Result + } diff --git a/space/space/space/space/space/space/controller/auth/auth_external_controller.go b/space/space/space/space/space/space/controller/auth/auth_external_controller.go index 06eecf8ab46e2c57ef61014182c930c738b9709d..f6ee46a8d353258cb4058b6ba1c9921eb0af79f3 100644 --- a/space/space/space/space/space/space/controller/auth/auth_external_controller.go +++ b/space/space/space/space/space/space/controller/auth/auth_external_controller.go @@ -14,7 +14,7 @@ func ExternalAuth(c *gin.Context) { GoogleLogin := services.GoogleAuthService{} ExternalAuthController.Service = &GoogleLogin.Service ExternalAuthController.Service.Constructor.OauthID = ExternalAuthController.Request.OauthID - GoogleLogin.Authenticate() + GoogleLogin.Authenticate(ExternalAuthController.Request.IsAgreeTerms && !ExternalAuthController.Request.IsSexualDisease) } }) } diff --git a/space/space/space/space/space/space/controller/auth/auth_forgot_password_controller.go b/space/space/space/space/space/space/controller/auth/auth_forgot_password_controller.go index b963f60bb1154f2b2517d4793cb423a3aea3ece5..a1cbf45dac96d2e4d64dba1971b5ea678e2f52aa 100644 --- a/space/space/space/space/space/space/controller/auth/auth_forgot_password_controller.go +++ b/space/space/space/space/space/space/controller/auth/auth_forgot_password_controller.go @@ -1 +1,29 @@ package auth + +import ( + "api.qobiltu.id/controller" + "api.qobiltu.id/models" + "api.qobiltu.id/services" + "github.com/gin-gonic/gin" +) + +func CreateForgotPassword(c *gin.Context) { + ForgotPassword := services.ForgotPasswordService{} + ForgotPasswordController := controller.Controller[models.ForgotPasswordRequest, models.ForgotPassword, models.ForgotPassword]{ + Service: &ForgotPassword.Service, + } + ForgotPasswordController.RequestJSON(c, func() { + ForgotPassword.Create(ForgotPasswordController.Request.Email) + }) + +} +func ValidateForgotPassword(c *gin.Context) { + ForgotPassword := services.ForgotPasswordService{} + ForgotPasswordController := controller.Controller[models.ValidateForgotPasswordRequest, models.ForgotPassword, models.ForgotPassword]{ + Service: &ForgotPassword.Service, + } + ForgotPasswordController.RequestJSON(c, func() { + ForgotPasswordController.Service.Constructor.Token = ForgotPasswordController.Request.Token + ForgotPassword.Validate(&ForgotPasswordController.Request.NewPassword) + }) +} diff --git a/space/space/space/space/space/space/controller/email/email_validate_controller.go b/space/space/space/space/space/space/controller/email/email_validate_controller.go index f166c5d8df0164e6470a821bbee95e67a61f05d4..d22c912477bd131fb16529d0ffea44fed088e4f8 100644 --- a/space/space/space/space/space/space/controller/email/email_validate_controller.go +++ b/space/space/space/space/space/space/controller/email/email_validate_controller.go @@ -16,7 +16,6 @@ func Verify(c *gin.Context) { emailVerificationController.Service.Constructor.AccountID = uint(emailVerificationController.AccountData.UserID) emailVerificationController.RequestJSON(c, func() { emailVerificationController.Service.Constructor.Token = emailVerificationController.Request.Token - emailVerificationController.Service.Constructor.UUID = emailVerificationController.Request.UUID emailVerification.Validate() }) }) diff --git a/space/space/space/space/space/space/models/request_model.go b/space/space/space/space/space/space/models/request_model.go index 249f6bfeb94001273154ad7cdc2aa8f68fa6a4ac..a37348207592c3450462cf468b9d3edab86962dc 100644 --- a/space/space/space/space/space/space/models/request_model.go +++ b/space/space/space/space/space/space/models/request_model.go @@ -1,7 +1,5 @@ package models -import uuid "github.com/satori/go.uuid" - type LoginRequest struct { Email string `json:"email" binding:"required"` Password string `json:"password" binding:"required"` @@ -20,8 +18,7 @@ type ChangePasswordRequest struct { } type CreateVerifyEmailRequest struct { - Token uint `json:"token" binding:"required"` - UUID uuid.UUID `json:"uuid" binding:"required"` + Token uint `json:"token" binding:"required"` } type OptionsRequest struct { @@ -35,3 +32,11 @@ type ExternalAuthRequest struct { IsAgreeTerms bool `json:"is_agree_terms"` IsSexualDisease bool `json:"is_sexual_disease"` } + +type ForgotPasswordRequest struct { + Email string `json:"email" binding:"required,email"` +} +type ValidateForgotPasswordRequest struct { + Token uint `json:"token" binding:"required"` + NewPassword string `json:"new_password" binding:"required"` +} diff --git a/space/space/space/space/space/space/repositories/account_repository.go b/space/space/space/space/space/space/repositories/account_repository.go index 978e1e4c584390f8e8941e3b1c464b967cf8af3a..0cceb9094856d6284d6321676b170a1222201063 100644 --- a/space/space/space/space/space/space/repositories/account_repository.go +++ b/space/space/space/space/space/space/repositories/account_repository.go @@ -39,10 +39,8 @@ func UpdateAccount(account models.Account) Repository[models.Account, models.Acc repo := Construct[models.Account, models.Account]( account, ) - repo.Transactions( - WhereGivenConstructor[models.Account, models.Account], - Update[models.Account], - ) + repo.Transaction.Save(&repo.Constructor) + repo.Result = repo.Constructor return *repo } diff --git a/space/space/space/space/space/space/router/auth_route.go b/space/space/space/space/space/space/router/auth_route.go index 808b568cf02fd0137a46cb808a2c9102c636eccc..a30c769644383c52d4e234a9b1ba2d414dc443a4 100644 --- a/space/space/space/space/space/space/router/auth_route.go +++ b/space/space/space/space/space/space/router/auth_route.go @@ -13,5 +13,7 @@ func AuthRoute(router *gin.Engine) { routerGroup.POST("/login", AuthController.Login) routerGroup.POST("/register", AuthController.Register) routerGroup.PUT("/change-password", middleware.AuthUser, AuthController.ChangePassword) + routerGroup.POST("/forgot-password", AuthController.CreateForgotPassword) + routerGroup.PUT("/forgot-password", AuthController.ValidateForgotPassword) } } diff --git a/space/space/space/space/space/space/services/authentication_service.go b/space/space/space/space/space/space/services/authentication_service.go index 296771a68cedc99f869f398a50e56a4f0db5dbd8..8c507be6297b02accb45e0688f019d5dd97851ce 100644 --- a/space/space/space/space/space/space/services/authentication_service.go +++ b/space/space/space/space/space/space/services/authentication_service.go @@ -58,7 +58,8 @@ func (s *AuthenticationService) Update(oldPassword string, newPassword string) { s.Exception.Message = "incorrect old password!" return } - accountData.Result.Password = newPassword + hashed_password, _ := HashPassword(newPassword) + accountData.Result.Password = hashed_password changePassword := repositories.UpdateAccount(accountData.Result) changePassword.Result.Password = "SECRET" s.Result = models.AuthenticatedUser{ diff --git a/space/space/space/space/space/space/services/email_verification_service.go b/space/space/space/space/space/space/services/email_verification_service.go index 4876c4bc0bd36cebebee1f930a980a0e61d9f05b..ea6a81d13ba4bcbea9c844dd2156911555133bd2 100644 --- a/space/space/space/space/space/space/services/email_verification_service.go +++ b/space/space/space/space/space/space/services/email_verification_service.go @@ -61,6 +61,7 @@ func (s *EmailVerificationService) Create() { return } }(accountRepo.Result.Email, token) + // s.Result.Token = 0 } func (s *EmailVerificationService) Validate() { @@ -80,8 +81,11 @@ func (s *EmailVerificationService) Validate() { s.Delete() return } + account := repositories.GetAccountById(repo.Result.AccountID) + account.Result.IsEmailVerified = true + + repositories.UpdateAccount(account.Result) s.Result = repo.Result - s.Delete() } func (s *EmailVerificationService) Delete() { diff --git a/space/space/space/space/space/space/services/external_authentication_service.go b/space/space/space/space/space/space/services/external_authentication_service.go index 9d575a2294842ae83d732e718e4b4c7540c3da7f..22d723bd821f351074a1840afd7474338872a15d 100644 --- a/space/space/space/space/space/space/services/external_authentication_service.go +++ b/space/space/space/space/space/space/services/external_authentication_service.go @@ -14,7 +14,7 @@ type GoogleAuthService struct { Service[models.ExternalAuth, models.AuthenticatedUser] } -func (s *GoogleAuthService) Authenticate() { +func (s *GoogleAuthService) Authenticate(isAgree bool) { GoogleAuth := repositories.GetExternalAccountByOauthId(s.Constructor.OauthID) payload, errGoogleAuth := idtoken.Validate(context.Background(), s.Constructor.OauthID, "") s.Error = errGoogleAuth @@ -25,6 +25,11 @@ func (s *GoogleAuthService) Authenticate() { } email := payload.Claims["email"] if GoogleAuth.NoRecord { + if !isAgree { + s.Exception.BadRequest = true + s.Exception.Message = "Please agree to the terms and conditions to create an account" + return + } s.Constructor.UUID = uuid.NewV4() s.Constructor.OauthProvider = "Google" createAccount := repositories.CreateAccount(models.Account{ diff --git a/space/space/space/space/space/space/services/forgot_password_service.go b/space/space/space/space/space/space/services/forgot_password_service.go new file mode 100644 index 0000000000000000000000000000000000000000..50eaf00379e50ea7979b228a0c3a7a016a03c3a9 --- /dev/null +++ b/space/space/space/space/space/space/services/forgot_password_service.go @@ -0,0 +1,105 @@ +package services + +import ( + "fmt" + "log" + "math/rand/v2" + "net/smtp" + "time" + + "api.qobiltu.id/config" + "api.qobiltu.id/models" + "api.qobiltu.id/repositories" + uuid "github.com/satori/go.uuid" +) + +type ForgotPasswordService struct { + Service[models.ForgotPassword, models.ForgotPassword] +} + +func (s *ForgotPasswordService) Create(email string) { + if email == "" { + s.Exception.BadRequest = true + s.Exception.Message = "Email is required!" + return + } + accountRepo := repositories.GetAccountbyEmail(email) + if accountRepo.NoRecord { + s.Error = accountRepo.RowsError + s.Exception.DataNotFound = true + s.Exception.Message = "There is no account data with given credentials!" + return + } + + remainingTime := time.Duration(config.EMAIL_VERIFICATION_DURATION) * time.Hour + dueTime := CalculateDueTime(remainingTime) + + token := uint(rand.IntN(100000)) + s.Constructor.UUID = uuid.NewV4() + s.Constructor.ExpiredAt = dueTime + s.Constructor.AccountID = accountRepo.Result.Id + s.Constructor.Token = token + repo := repositories.CreateForgotPassword(s.Constructor) + + s.Error = repo.RowsError + s.Result = repo.Result + // ⬇ Kirim token ke email user menggunakan SMTP + go func(toEmail string, token uint) { + from := config.SMTP_SENDER_EMAIL + password := config.SMTP_SENDER_PASSWORD + smtpHost := config.SMTP_HOST + smtpPort := config.SMTP_PORT + + auth := smtp.PlainAuth("", from, password, smtpHost) + + subject := "Forgot Password Token" + body := fmt.Sprintf("Your Forgot Password token is: %06d\nPlease use it before it expires.", token) + + msg := []byte("To: " + toEmail + "\r\n" + + "Subject: " + subject + "\r\n" + + "\r\n" + + body + "\r\n") + + err := smtp.SendMail(smtpHost+":"+smtpPort, auth, from, []string{toEmail}, msg) + if err != nil { + s.Error = err + log.Printf("Error sending verification email: %v", err) + return + } + }(accountRepo.Result.Email, token) + // s.Result.Token = 0 +} + +func (s *ForgotPasswordService) Validate(newPassword string) { + accountRepo := repositories.GetAccountById(s.Constructor.AccountID) + if accountRepo.NoRecord { + s.Error = accountRepo.RowsError + s.Exception.DataNotFound = true + s.Exception.Message = "There is no account data with given credentials!" + return + } + + fgPasswordRepo := repositories.GetForgotPasswordByToken(s.Constructor.Token) + s.Error = fgPasswordRepo.RowsError + if fgPasswordRepo.NoRecord { + s.Exception.DataNotFound = true + s.Exception.Message = "There is no forgot password data with given credentials!" + return + } + if fgPasswordRepo.Result.ExpiredAt.Before(time.Now()) { + s.Exception.Unauthorized = true + s.Exception.Message = "Token has expired!" + return + } + hashed_password, _ := HashPassword(newPassword) + accountRepo.Result.Password = hashed_password + changePassword := repositories.UpdateAccount(accountRepo.Result) + if changePassword.RowsError != nil { + s.Error = changePassword.RowsError + s.Exception.QueryError = true + s.Exception.Message = "Failed to update password!" + return + } + // fgPasswordRepo.Result.Token = 0 + s.Result = fgPasswordRepo.Result +} diff --git a/space/space/space/space/space/space/services/user_profile_service.go b/space/space/space/space/space/space/services/user_profile_service.go index 4308555dd3674be1068959b571bc80f0809ac623..c8803332f0467a840fdcb2099ac1785bde70a06d 100644 --- a/space/space/space/space/space/space/services/user_profile_service.go +++ b/space/space/space/space/space/space/services/user_profile_service.go @@ -69,6 +69,7 @@ func (s *UserProfileService) Retrieve() { Account: repositories.GetAccountById(s.Constructor.AccountID).Result, Details: userProfile.Result, } + s.Result.Account.Password = "SECRET" } func (s *UserProfileService) Update() { @@ -78,11 +79,14 @@ func (s *UserProfileService) Update() { } usersCount := repositories.GetAllAccount().RowsCount var initialName string - if *s.Constructor.Gender { - initialName = "IKH_" - } else { - initialName = "AKH_" + if s.Constructor.Gender != nil { + if *s.Constructor.Gender { + initialName = "IKH_" + } else { + initialName = "AKH_" + } } + initialName += strconv.Itoa(usersCount) s.Constructor.InitialName = initialName userProfile := repositories.UpdateAccountDetails(s.Constructor) @@ -92,8 +96,19 @@ func (s *UserProfileService) Update() { s.Exception.Message = "There is no account with given credentials!" return } + account := repositories.GetAccountById(s.Constructor.AccountID) + account.Result.IsDetailCompleted = (userProfile.Result.InitialName != "" && + userProfile.Result.FullName != nil && + userProfile.Result.DateOfBirth != nil && + userProfile.Result.PlaceOfBirth != nil && + userProfile.Result.Domicile != nil && + userProfile.Result.LastJob != nil && + userProfile.Result.Gender != nil && + userProfile.Result.LastEducation != nil && + userProfile.Result.MaritalStatus != nil) + repositories.UpdateAccount(account.Result) s.Result = models.UserProfileResponse{ - Account: repositories.GetAccountById(s.Constructor.AccountID).Result, + Account: account.Result, Details: userProfile.Result, } s.Result.Account.Password = "SECRET" diff --git a/space/space/space/space/space/space/space/space/services/email_verification_service.go b/space/space/space/space/space/space/space/space/services/email_verification_service.go index 5255a607afb53c6f64e4c590f5b7723b4806973f..4876c4bc0bd36cebebee1f930a980a0e61d9f05b 100644 --- a/space/space/space/space/space/space/space/space/services/email_verification_service.go +++ b/space/space/space/space/space/space/space/space/services/email_verification_service.go @@ -1,8 +1,8 @@ package services import ( - "crypto/tls" "fmt" + "log" "math/rand/v2" "net/smtp" "time" @@ -44,71 +44,22 @@ func (s *EmailVerificationService) Create() { smtpHost := config.SMTP_HOST smtpPort := config.SMTP_PORT - tlsconfig := &tls.Config{ - InsecureSkipVerify: true, - ServerName: smtpHost, - } - - conn, err := tls.Dial("tcp", fmt.Sprintf("%s:%d", smtpHost, smtpPort), tlsconfig) - if err != nil { - panic(err) - } - - client, err := smtp.NewClient(conn, smtpHost) - if err != nil { - panic(err) - } - - // auth := smtp.PlainAuth("", from, password, smtpHost) auth := smtp.PlainAuth("", from, password, smtpHost) - if err = client.Auth(auth); err != nil { - panic(err) - } - if err = client.Mail(from); err != nil { - panic(err) - } + subject := "Email Verification Token" + body := fmt.Sprintf("Your verification token is: %06d\nPlease use it before it expires.", token) - to := []string{toEmail} - for _, addr := range to { - if err = client.Rcpt(addr); err != nil { - panic(err) - } - } + msg := []byte("To: " + toEmail + "\r\n" + + "Subject: " + subject + "\r\n" + + "\r\n" + + body + "\r\n") - wc, err := client.Data() + err := smtp.SendMail(smtpHost+":"+smtpPort, auth, from, []string{toEmail}, msg) if err != nil { - panic(err) + s.Error = err + log.Printf("Error sending verification email: %v", err) + return } - - msg := []byte("Subject: Test Email\r\n\r\nThis is the email body.") - _, err = wc.Write(msg) - if err != nil { - panic(err) - } - - err = wc.Close() - if err != nil { - panic(err) - } - - client.Quit() - fmt.Println("Email sent successfully!") - - // subject := "Email Verification Token" - // body := fmt.Sprintf("Your verification token is: %06d\nPlease use it before it expires.", token) - - // msg := []byte("To: " + toEmail + "\r\n" + - // "Subject: " + subject + "\r\n" + - // "\r\n" + - // body + "\r\n") - - // err := smtp.SendMail(smtpHost+":"+smtpPort, auth, from, []string{toEmail}, msg) - // if err != nil { - // s.Error = err - // log.Printf("Error sending verification email: %v", err) - // return - // } }(accountRepo.Result.Email, token) } diff --git a/space/space/space/space/space/space/space/space/space/space/services/email_verification_service.go b/space/space/space/space/space/space/space/space/space/space/services/email_verification_service.go index 4876c4bc0bd36cebebee1f930a980a0e61d9f05b..5255a607afb53c6f64e4c590f5b7723b4806973f 100644 --- a/space/space/space/space/space/space/space/space/space/space/services/email_verification_service.go +++ b/space/space/space/space/space/space/space/space/space/space/services/email_verification_service.go @@ -1,8 +1,8 @@ package services import ( + "crypto/tls" "fmt" - "log" "math/rand/v2" "net/smtp" "time" @@ -44,22 +44,71 @@ func (s *EmailVerificationService) Create() { smtpHost := config.SMTP_HOST smtpPort := config.SMTP_PORT + tlsconfig := &tls.Config{ + InsecureSkipVerify: true, + ServerName: smtpHost, + } + + conn, err := tls.Dial("tcp", fmt.Sprintf("%s:%d", smtpHost, smtpPort), tlsconfig) + if err != nil { + panic(err) + } + + client, err := smtp.NewClient(conn, smtpHost) + if err != nil { + panic(err) + } + + // auth := smtp.PlainAuth("", from, password, smtpHost) auth := smtp.PlainAuth("", from, password, smtpHost) + if err = client.Auth(auth); err != nil { + panic(err) + } - subject := "Email Verification Token" - body := fmt.Sprintf("Your verification token is: %06d\nPlease use it before it expires.", token) + if err = client.Mail(from); err != nil { + panic(err) + } - msg := []byte("To: " + toEmail + "\r\n" + - "Subject: " + subject + "\r\n" + - "\r\n" + - body + "\r\n") + to := []string{toEmail} + for _, addr := range to { + if err = client.Rcpt(addr); err != nil { + panic(err) + } + } - err := smtp.SendMail(smtpHost+":"+smtpPort, auth, from, []string{toEmail}, msg) + wc, err := client.Data() if err != nil { - s.Error = err - log.Printf("Error sending verification email: %v", err) - return + panic(err) } + + msg := []byte("Subject: Test Email\r\n\r\nThis is the email body.") + _, err = wc.Write(msg) + if err != nil { + panic(err) + } + + err = wc.Close() + if err != nil { + panic(err) + } + + client.Quit() + fmt.Println("Email sent successfully!") + + // subject := "Email Verification Token" + // body := fmt.Sprintf("Your verification token is: %06d\nPlease use it before it expires.", token) + + // msg := []byte("To: " + toEmail + "\r\n" + + // "Subject: " + subject + "\r\n" + + // "\r\n" + + // body + "\r\n") + + // err := smtp.SendMail(smtpHost+":"+smtpPort, auth, from, []string{toEmail}, msg) + // if err != nil { + // s.Error = err + // log.Printf("Error sending verification email: %v", err) + // return + // } }(accountRepo.Result.Email, token) } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/models/request_model.go b/space/space/space/space/space/space/space/space/space/space/space/space/models/request_model.go index d59213670e8b21d29270349fa9c598ccb2207bed..249f6bfeb94001273154ad7cdc2aa8f68fa6a4ac 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/models/request_model.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/models/request_model.go @@ -30,6 +30,8 @@ type OptionsRequest struct { } type ExternalAuthRequest struct { - OauthID string `json:"oauth_id" binding:"required"` - OauthProvider string `json:"oauth_provider" binding:"required"` + OauthID string `json:"oauth_id" binding:"required"` + OauthProvider string `json:"oauth_provider" binding:"required"` + IsAgreeTerms bool `json:"is_agree_terms"` + IsSexualDisease bool `json:"is_sexual_disease"` } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/services/authentication_service.go b/space/space/space/space/space/space/space/space/space/space/space/space/services/authentication_service.go index 8b3474fa876993fe8a09fde9a241c8a54df5feee..296771a68cedc99f869f398a50e56a4f0db5dbd8 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/services/authentication_service.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/services/authentication_service.go @@ -18,6 +18,7 @@ func (s *AuthenticationService) Authenticate() { s.Exception.Message = "there is no account with given credentials!" return } + if VerifyPassword(accountData.Result.Password, s.Constructor.Password) != nil { s.Exception.Unauthorized = true s.Exception.Message = "incorrect password!" @@ -28,6 +29,7 @@ func (s *AuthenticationService) Authenticate() { if err_tok != nil { s.Error = errors.Join(s.Error, err_tok) + return } accountData.Result.Password = "SECRET" diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/services/email_verification_service.go b/space/space/space/space/space/space/space/space/space/space/space/space/services/email_verification_service.go index c0eaba5711783161d526de88c0090a594bacfda2..4876c4bc0bd36cebebee1f930a980a0e61d9f05b 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/services/email_verification_service.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/services/email_verification_service.go @@ -56,7 +56,9 @@ func (s *EmailVerificationService) Create() { err := smtp.SendMail(smtpHost+":"+smtpPort, auth, from, []string{toEmail}, msg) if err != nil { + s.Error = err log.Printf("Error sending verification email: %v", err) + return } }(accountRepo.Result.Email, token) } @@ -75,9 +77,11 @@ func (s *EmailVerificationService) Validate() { s.Exception.Unauthorized = true s.Exception.Message = "Token has expired!" repositories.UpdateExpiredEmailVerification(s.Constructor.UUID) + s.Delete() return } s.Result = repo.Result + s.Delete() } func (s *EmailVerificationService) Delete() { diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/services/user_profile_service.go b/space/space/space/space/space/space/space/space/space/space/space/space/services/user_profile_service.go index 66e673f5e3830b2e1ffd5515ee1d9861675572a9..4308555dd3674be1068959b571bc80f0809ac623 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/services/user_profile_service.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/services/user_profile_service.go @@ -2,6 +2,7 @@ package services import ( "regexp" + "strconv" "strings" "api.qobiltu.id/models" @@ -71,8 +72,10 @@ func (s *UserProfileService) Retrieve() { } func (s *UserProfileService) Update() { - phoneNumber := *s.Constructor.PhoneNumber - *s.Constructor.PhoneNumber = SanitizePhoneNumber(phoneNumber) + if s.Constructor.PhoneNumber != nil { + phoneNumber := *s.Constructor.PhoneNumber + *s.Constructor.PhoneNumber = SanitizePhoneNumber(phoneNumber) + } usersCount := repositories.GetAllAccount().RowsCount var initialName string if *s.Constructor.Gender { @@ -80,7 +83,8 @@ func (s *UserProfileService) Update() { } else { initialName = "AKH_" } - initialName += string(usersCount) + initialName += strconv.Itoa(usersCount) + s.Constructor.InitialName = initialName userProfile := repositories.UpdateAccountDetails(s.Constructor) s.Error = userProfile.RowsError if userProfile.NoRecord { @@ -92,4 +96,5 @@ func (s *UserProfileService) Update() { Account: repositories.GetAccountById(s.Constructor.AccountID).Result, Details: userProfile.Result, } + s.Result.Account.Password = "SECRET" } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/account_repository.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/account_repository.go index 8aad7510cf6ff2f1146de5a8da0d0f61debe7cb6..978e1e4c584390f8e8941e3b1c464b967cf8af3a 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/account_repository.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/account_repository.go @@ -15,6 +15,15 @@ func GetAccountbyEmail(email string) Repository[models.Account, models.Account] return *repo } +func GetAllAccount() Repository[models.Account, []models.Account] { + repo := Construct[models.Account, []models.Account]( + models.Account{}, + ) + repo.Transactions( + Find[models.Account, []models.Account], + ) + return *repo +} func GetAccountById(accountId uint) Repository[models.Account, models.Account] { repo := Construct[models.Account, models.Account]( models.Account{Id: accountId}, diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/services/external_authentication_service.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/services/external_authentication_service.go index 3145d18c671432bfa78ef892b911424476cf79c4..9d575a2294842ae83d732e718e4b4c7540c3da7f 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/services/external_authentication_service.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/services/external_authentication_service.go @@ -33,7 +33,7 @@ func (s *GoogleAuthService) Authenticate() { }) s.Constructor.AccountID = createAccount.Result.Id createGoogleAuth := repositories.CreateExternalAuth(s.Constructor) - + GoogleAuth.Result.AccountID = createGoogleAuth.Result.ID s.Error = createGoogleAuth.RowsError s.Error = errors.Join(s.Error, createAccount.RowsError) } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/user_profile_service.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/user_profile_service.go index 180bb9b399fa74ab1db9b164f72e1b699481467c..66e673f5e3830b2e1ffd5515ee1d9861675572a9 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/user_profile_service.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/user_profile_service.go @@ -44,8 +44,6 @@ func SanitizePhoneNumber(input string) string { return input } func (s *UserProfileService) Create() { - phoneNumber := *s.Constructor.PhoneNumber - *s.Constructor.PhoneNumber = SanitizePhoneNumber(phoneNumber) userProfile := repositories.CreateAccountDetails(s.Constructor) s.Error = userProfile.RowsError if userProfile.NoRecord { @@ -75,6 +73,14 @@ func (s *UserProfileService) Retrieve() { func (s *UserProfileService) Update() { phoneNumber := *s.Constructor.PhoneNumber *s.Constructor.PhoneNumber = SanitizePhoneNumber(phoneNumber) + usersCount := repositories.GetAllAccount().RowsCount + var initialName string + if *s.Constructor.Gender { + initialName = "IKH_" + } else { + initialName = "AKH_" + } + initialName += string(usersCount) userProfile := repositories.UpdateAccountDetails(s.Constructor) s.Error = userProfile.RowsError if userProfile.NoRecord { diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/docker-compose.yml b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/docker-compose.yml index a821c467525af186355b5837f8673e77a84f7563..5d48addfd86709968791ce0c398bd0a4cb75e2ec 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/docker-compose.yml +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/docker-compose.yml @@ -24,7 +24,7 @@ services: ports: - "5432:5432" volumes: - - db-data:/var/lib/postgresql/data + - /home/qobiltu/postgres-data:/var/lib/postgresql/data restart: always volumes: diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/Dockerfile b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/Dockerfile index d7d9de6f6ae86a458866ad773e9886db45197e9b..8483ea7af8b5c6267fb167d8dd7b84354ceed129 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/Dockerfile +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/Dockerfile @@ -28,6 +28,9 @@ WORKDIR /app # Copy hasil build dari builder ke image runtime COPY --from=builder /app/main . +# Copy folder utils (termasuk file seeder) dari builder ke runtime +COPY --from=builder /app/utils ./utils + # Copy file .env untuk konfigurasi environment COPY .env .env diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/user_profile_controller.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/user_profile_controller.go index f30ee7177fa8bd15be000bcfe941ceb2732a74c1..08f850c1f5991e30eabd8d66d364110d83dcfd75 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/user_profile_controller.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/user_profile_controller.go @@ -9,7 +9,7 @@ import ( func Profile(c *gin.Context) { userProfile := services.UserProfileService{} - userProfileController := controller.Controller[any, models.AccountDetails, models.AccountDetails]{ + userProfileController := controller.Controller[any, models.AccountDetails, models.UserProfileResponse]{ Service: &userProfile.Service, } userProfileController.HeaderParse(c, func() { diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/user_update_profile_controller.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/user_update_profile_controller.go index ec2b5ab25518d1aa9221afe7b07527ba298b14bc..058d97e7fea905feb469147c880d9141c25e0de3 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/user_update_profile_controller.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/user_update_profile_controller.go @@ -1,8 +1,6 @@ package user import ( - "fmt" - "api.qobiltu.id/controller" "api.qobiltu.id/models" "api.qobiltu.id/services" @@ -11,7 +9,7 @@ import ( func UpdateProfile(c *gin.Context) { userProfile := services.UserProfileService{} - userUpdateProfileController := controller.Controller[models.AccountDetails, models.AccountDetails, models.AccountDetails]{ + userUpdateProfileController := controller.Controller[models.AccountDetails, models.AccountDetails, models.UserProfileResponse]{ Service: &userProfile.Service, } @@ -19,7 +17,7 @@ func UpdateProfile(c *gin.Context) { userUpdateProfileController.Service.Constructor = userUpdateProfileController.Request userUpdateProfileController.HeaderParse(c, func() { userUpdateProfileController.Service.Constructor.AccountID = uint(userUpdateProfileController.AccountData.UserID) - fmt.Println("Account ID:", userUpdateProfileController.Service.Constructor.AccountID) + }) userProfile.Update() }, diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/logs/error_log.txt b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/logs/error_log.txt index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..8b137891791fe96927ad78e64b0aad7bded08bdc 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/logs/error_log.txt +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/logs/error_log.txt @@ -0,0 +1 @@ + diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/response_model.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/response_model.go index 7c744950bba893f98e47ab946dd112c1474872ee..3b90d6d4505bb2677ff4b44a9088e0a62cd656c8 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/response_model.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/response_model.go @@ -25,3 +25,8 @@ type Options struct { type OptionsResponse struct { Options []Options `json:"options"` } + +type UserProfileResponse struct { + Account Account `json:"account"` + Details AccountDetails `json:"details"` +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/account_repository.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/account_repository.go index a91a7779aaee9b85bfcadd25a6fb7cdbd3fb0647..8aad7510cf6ff2f1146de5a8da0d0f61debe7cb6 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/account_repository.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/account_repository.go @@ -1,8 +1,6 @@ package repositories import ( - "fmt" - "api.qobiltu.id/models" ) @@ -64,8 +62,6 @@ func CreateAccountDetails(accountDetails models.AccountDetails) Repository[model repo := Construct[models.AccountDetails, models.AccountDetails]( accountDetails, ) - fmt.Println(accountDetails) - fmt.Println("Account ID : ", accountDetails.AccountID) Create(repo) return *repo } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/forgot_password_repository.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/forgot_password_repository.go new file mode 100644 index 0000000000000000000000000000000000000000..90c293823afee7c5aaf1583cf16bbd44620894fb --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/forgot_password_repository.go @@ -0,0 +1,22 @@ +package repositories + +import "api.qobiltu.id/models" + +func CreateForgotPassword(forgotPassword models.ForgotPassword) Repository[models.ForgotPassword, models.ForgotPassword] { + repo := Construct[models.ForgotPassword, models.ForgotPassword]( + forgotPassword, + ) + Create(repo) + return *repo +} + +func GetForgotPasswordByToken(token uint) Repository[models.ForgotPassword, models.ForgotPassword] { + repo := Construct[models.ForgotPassword, models.ForgotPassword]( + models.ForgotPassword{Token: token}, + ) + repo.Transactions( + WhereGivenConstructor[models.ForgotPassword, models.ForgotPassword], + Find[models.ForgotPassword, models.ForgotPassword], + ) + return *repo +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/router.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/router.go index c414889615c83c047f89d4e2ba6f97ba074edd08..6987e5456230d0a920b4e44a77163fade344beb7 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/router.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/router.go @@ -1,6 +1,8 @@ package router import ( + "log" + "api.qobiltu.id/config" "api.qobiltu.id/controller" "github.com/gin-gonic/gin" @@ -9,9 +11,14 @@ import ( func StartService() { router := gin.Default() router.GET("/", controller.HomeController) + AuthRoute(router) UserRoute(router) EmailRoute(router) OptionsRoute(router) - router.Run(config.TCP_ADDRESS) + + err := router.Run(config.TCP_ADDRESS) + if err != nil { + log.Fatalf("Failed to run server: %v", err) + } } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/external_authentication_service.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/external_authentication_service.go index 71a13b170924f10698468b6a6ee1870f51ad6a57..3145d18c671432bfa78ef892b911424476cf79c4 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/external_authentication_service.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/external_authentication_service.go @@ -27,15 +27,14 @@ func (s *GoogleAuthService) Authenticate() { if GoogleAuth.NoRecord { s.Constructor.UUID = uuid.NewV4() s.Constructor.OauthProvider = "Google" - - createGoogleAuth := repositories.CreateExternalAuth(s.Constructor) - - s.Error = createGoogleAuth.RowsError - createAccount := repositories.CreateAccount(models.Account{ Email: email.(string), IsEmailVerified: true, }) + s.Constructor.AccountID = createAccount.Result.Id + createGoogleAuth := repositories.CreateExternalAuth(s.Constructor) + + s.Error = createGoogleAuth.RowsError s.Error = errors.Join(s.Error, createAccount.RowsError) } accountData := repositories.GetAccountById(GoogleAuth.Result.AccountID) diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/user_profile_service.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/user_profile_service.go index 4807849046127c92c0dfdc98d156e58cc9403492..180bb9b399fa74ab1db9b164f72e1b699481467c 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/user_profile_service.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/user_profile_service.go @@ -1,17 +1,51 @@ package services import ( - "fmt" + "regexp" + "strings" "api.qobiltu.id/models" "api.qobiltu.id/repositories" ) type UserProfileService struct { - Service[models.AccountDetails, models.AccountDetails] + Service[models.AccountDetails, models.UserProfileResponse] } +// SanitizePhoneNumber membersihkan dan menormalkan nomor telepon ke format +62 +func SanitizePhoneNumber(input string) string { + // Hilangkan semua spasi dan strip + input = strings.ReplaceAll(input, " ", "") + input = strings.ReplaceAll(input, "-", "") + input = strings.ReplaceAll(input, "(", "") + input = strings.ReplaceAll(input, ")", "") + + // Hilangkan semua karakter non-digit kecuali + + re := regexp.MustCompile(`[^0-9\+]`) + input = re.ReplaceAllString(input, "") + + // Handle nomor diawali 0 (contoh: 0812...) menjadi +62812... + if strings.HasPrefix(input, "0") { + input = "+62" + input[1:] + } + + // Handle jika diawali dengan 62 tanpa + (contoh: 62812...) + if strings.HasPrefix(input, "62") && !strings.HasPrefix(input, "+62") { + input = "+" + input + } + + // Handle jika tidak ada awalan +62 sama sekali (contoh: 8123456789) + if !strings.HasPrefix(input, "+62") { + if strings.HasPrefix(input, "8") { + input = "+62" + input + } + } + + return input +} func (s *UserProfileService) Create() { + phoneNumber := *s.Constructor.PhoneNumber + *s.Constructor.PhoneNumber = SanitizePhoneNumber(phoneNumber) userProfile := repositories.CreateAccountDetails(s.Constructor) s.Error = userProfile.RowsError if userProfile.NoRecord { @@ -19,7 +53,10 @@ func (s *UserProfileService) Create() { s.Exception.Message = "There is no account with given credentials!" return } - s.Result = userProfile.Result + s.Result = models.UserProfileResponse{ + Account: repositories.GetAccountById(s.Constructor.AccountID).Result, + Details: userProfile.Result, + } } func (s *UserProfileService) Retrieve() { userProfile := repositories.GetDetailAccountById(s.Constructor.AccountID) @@ -29,11 +66,15 @@ func (s *UserProfileService) Retrieve() { s.Exception.Message = "There is no account with given credentials!" return } - s.Result = userProfile.Result + s.Result = models.UserProfileResponse{ + Account: repositories.GetAccountById(s.Constructor.AccountID).Result, + Details: userProfile.Result, + } } func (s *UserProfileService) Update() { - fmt.Println("Account ID:", s.Constructor.AccountID) + phoneNumber := *s.Constructor.PhoneNumber + *s.Constructor.PhoneNumber = SanitizePhoneNumber(phoneNumber) userProfile := repositories.UpdateAccountDetails(s.Constructor) s.Error = userProfile.RowsError if userProfile.NoRecord { @@ -41,5 +82,8 @@ func (s *UserProfileService) Update() { s.Exception.Message = "There is no account with given credentials!" return } - s.Result = userProfile.Result + s.Result = models.UserProfileResponse{ + Account: repositories.GetAccountById(s.Constructor.AccountID).Result, + Details: userProfile.Result, + } } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/.gitignore b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/.gitignore index df8cf1c15e2917803db7f00fbc386495fe8f5479..0a375ebb173c72b4a9eea6189d87c76acf362583 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/.gitignore +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/.gitignore @@ -1,5 +1,7 @@ .env vendor/ quzuu-be.exe -README.md -.qodo +README.md +.qodo +.error +logs/ \ No newline at end of file diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/config/config.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/config/config.go index 823888a64fd867db2cee438c8cb64f792ec16920..55487887878907689a66b9e5897895013b1b708f 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/config/config.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/config/config.go @@ -9,10 +9,16 @@ import ( var TCP_ADDRESS string var LOG_PATH string + var HOST_ADDRESS string var HOST_PORT string var EMAIL_VERIFICATION_DURATION int +var SMTP_SENDER_EMAIL string +var SMTP_SENDER_PASSWORD string +var SMTP_HOST string +var SMTP_PORT string + func init() { godotenv.Load() HOST_ADDRESS = os.Getenv("HOST_ADDRESS") @@ -20,5 +26,9 @@ func init() { TCP_ADDRESS = HOST_ADDRESS + ":" + HOST_PORT LOG_PATH = os.Getenv("LOG_PATH") EMAIL_VERIFICATION_DURATION, _ = strconv.Atoi(os.Getenv("EMAIL_VERIFICATION_DURATION")) + SMTP_SENDER_EMAIL = os.Getenv("SMTP_SENDER_EMAIL") + SMTP_SENDER_PASSWORD = os.Getenv("SMTP_SENDER_PASSWORD") + SMTP_HOST = os.Getenv("SMTP_HOST") + SMTP_PORT = os.Getenv("SMTP_PORT") // Menampilkan nilai variabel lingkungan } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/config/database_connection_config.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/config/database_connection_config.go index 3eea63fb7b3d4ffd51970404cadf1af8267c046d..0588c0a120d8455f8cdb8c998042a5815af9e48e 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/config/database_connection_config.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/config/database_connection_config.go @@ -60,6 +60,10 @@ func AutoMigrateAll(db *gorm.DB) { &models.AcademyContent{}, &models.AcademyMaterialProgress{}, &models.AcademyContentProgress{}, + &models.RegionCity{}, + &models.RegionProvince{}, + &models.OptionCategory{}, + &models.OptionValues{}, ) if err != nil { diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/auth/auth_external_controller.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/auth/auth_external_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..06eecf8ab46e2c57ef61014182c930c738b9709d --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/auth/auth_external_controller.go @@ -0,0 +1,20 @@ +package auth + +import ( + "api.qobiltu.id/controller" + "api.qobiltu.id/models" + "api.qobiltu.id/services" + "github.com/gin-gonic/gin" +) + +func ExternalAuth(c *gin.Context) { + ExternalAuthController := controller.Controller[models.ExternalAuthRequest, models.ExternalAuth, models.AuthenticatedUser]{} + ExternalAuthController.RequestJSON(c, func() { + if ExternalAuthController.Request.OauthProvider == "google" { + GoogleLogin := services.GoogleAuthService{} + ExternalAuthController.Service = &GoogleLogin.Service + ExternalAuthController.Service.Constructor.OauthID = ExternalAuthController.Request.OauthID + GoogleLogin.Authenticate() + } + }) +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/auth/auth_forgot_password_controller.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/auth/auth_forgot_password_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..b963f60bb1154f2b2517d4793cb423a3aea3ece5 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/auth/auth_forgot_password_controller.go @@ -0,0 +1 @@ +package auth diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/email/email_create_verification_controller.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/email/email_create_verification_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..75d6a1a52383fac94e73c477dd29bda62624f31b --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/email/email_create_verification_controller.go @@ -0,0 +1,21 @@ +package controller + +import ( + "api.qobiltu.id/controller" + "api.qobiltu.id/models" + "api.qobiltu.id/services" + "github.com/gin-gonic/gin" +) + +func CreateVerification(c *gin.Context) { + emailVerification := services.EmailVerificationService{} + emailVerificationController := controller.Controller[models.CreateVerifyEmailRequest, models.EmailVerification, models.EmailVerification]{ + Service: &emailVerification.Service, + } + emailVerificationController.HeaderParse(c, func() { + emailVerificationController.Service.Constructor.AccountID = uint(emailVerificationController.AccountData.UserID) + emailVerification.Create() + emailVerificationController.Response(c) + }) + +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/email/email_validate_controller.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/email/email_validate_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..f166c5d8df0164e6470a821bbee95e67a61f05d4 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/email/email_validate_controller.go @@ -0,0 +1,24 @@ +package controller + +import ( + "api.qobiltu.id/controller" + "api.qobiltu.id/models" + "api.qobiltu.id/services" + "github.com/gin-gonic/gin" +) + +func Verify(c *gin.Context) { + emailVerification := services.EmailVerificationService{} + emailVerificationController := controller.Controller[models.CreateVerifyEmailRequest, models.EmailVerification, models.EmailVerification]{ + Service: &emailVerification.Service, + } + emailVerificationController.HeaderParse(c, func() { + emailVerificationController.Service.Constructor.AccountID = uint(emailVerificationController.AccountData.UserID) + emailVerificationController.RequestJSON(c, func() { + emailVerificationController.Service.Constructor.Token = emailVerificationController.Request.Token + emailVerificationController.Service.Constructor.UUID = emailVerificationController.Request.UUID + emailVerification.Validate() + }) + }) + +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/options/option_category_controller.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/options/option_category_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..c2824888af9eec3dca62f9f7690cfe3579fda1e5 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/options/option_category_controller.go @@ -0,0 +1,19 @@ +package options + +import ( + "api.qobiltu.id/controller" + "api.qobiltu.id/models" + "api.qobiltu.id/services" + "github.com/gin-gonic/gin" +) + +func AddOptions(c *gin.Context) { + options := services.OptionService{} + addOptionController := controller.Controller[[]models.OptionsRequest, []models.OptionsRequest, models.OptionsResponse]{ + Service: &options.Service, + } + addOptionController.RequestJSON(c, func() { + options.Constructor = addOptionController.Request + options.Create() + }) +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/options/option_value_controller.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/options/option_value_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..116f380726839b5629c00a46e0c31c484ba0d8f1 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/options/option_value_controller.go @@ -0,0 +1,19 @@ +package options + +import ( + "api.qobiltu.id/controller" + "api.qobiltu.id/models" + "api.qobiltu.id/services" + "github.com/gin-gonic/gin" +) + +func List(c *gin.Context) { + options := services.OptionValueService{} + optionValueController := controller.Controller[any, models.OptionCategory, models.Options]{ + Service: &options.Service, + } + slug := c.Param("slug") + options.Constructor.OptionSlug = slug + options.Retrieve() + optionValueController.Response(c) +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/region/city/city_list_controller.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/region/city/city_list_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..48e0158ef229664f16bff23f593355ec39d964c9 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/region/city/city_list_controller.go @@ -0,0 +1,21 @@ +package city + +import ( + "strconv" + + "api.qobiltu.id/controller" + "api.qobiltu.id/models" + "api.qobiltu.id/services" + "github.com/gin-gonic/gin" +) + +func List(c *gin.Context) { + city := services.CityService{} + CityController := controller.Controller[any, models.RegionCity, []models.RegionCity]{ + Service: &city.Service, + } + ProvinceID, _ := strconv.Atoi(c.Query("province_id")) + city.Constructor.ProvinceID = uint(ProvinceID) + city.Retrieve() + CityController.Response(c) +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/region/city/city_seeds_controller.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/region/city/city_seeds_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..08f0b8ae4ed1faa1ebf0c3442f480bb5879aa3a5 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/region/city/city_seeds_controller.go @@ -0,0 +1,17 @@ +package city + +import ( + "api.qobiltu.id/controller" + "api.qobiltu.id/models" + "api.qobiltu.id/services" + "github.com/gin-gonic/gin" +) + +func Seeds(c *gin.Context) { + city := services.CityService{} + CityController := controller.Controller[any, models.RegionCity, []models.RegionCity]{ + Service: &city.Service, + } + city.Create() + CityController.Response(c) +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/region/province/province_list_controller.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/region/province/province_list_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..5976fb0144da4ab9de16d8ccf80cff47ad81c78b --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/region/province/province_list_controller.go @@ -0,0 +1,17 @@ +package province + +import ( + "api.qobiltu.id/controller" + "api.qobiltu.id/models" + "api.qobiltu.id/services" + "github.com/gin-gonic/gin" +) + +func List(c *gin.Context) { + province := services.ProvinceService{} + ProvinceController := controller.Controller[any, models.RegionProvince, []models.RegionProvince]{ + Service: &province.Service, + } + province.Retrieve() + ProvinceController.Response(c) +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/region/province/province_seeds_controller.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/region/province/province_seeds_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..b1e6b630f63571e59d2ef9b1a1c12c0267b6004c --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/region/province/province_seeds_controller.go @@ -0,0 +1,17 @@ +package province + +import ( + "api.qobiltu.id/controller" + "api.qobiltu.id/models" + "api.qobiltu.id/services" + "github.com/gin-gonic/gin" +) + +func Seeds(c *gin.Context) { + province := services.ProvinceService{} + ProvinceController := controller.Controller[any, models.RegionProvince, []models.RegionProvince]{ + Service: &province.Service, + } + province.Create() + ProvinceController.Response(c) +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.mod b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.mod index 405345ca21ac9dd77eec5b3d4e48775287157552..b2be1362b4b37f0263c167a1280104d999ea356d 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.mod +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.mod @@ -13,15 +13,26 @@ require ( ) require ( + cloud.google.com/go/auth v0.15.0 // indirect + cloud.google.com/go/auth/oauth2adapt v0.2.8 // indirect + cloud.google.com/go/compute/metadata v0.6.0 // indirect github.com/bytedance/sonic v1.13.1 // indirect github.com/bytedance/sonic/loader v0.2.4 // indirect github.com/cloudwego/base64x v0.1.5 // indirect + github.com/felixge/httpsnoop v1.0.4 // indirect github.com/gabriel-vasile/mimetype v1.4.8 // indirect github.com/gin-contrib/sse v1.0.0 // indirect + github.com/go-logr/logr v1.4.2 // indirect + github.com/go-logr/stdr v1.2.2 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.25.0 // indirect github.com/goccy/go-json v0.10.5 // indirect + github.com/google/s2a-go v0.1.9 // indirect + github.com/googleapis/enterprise-certificate-proxy v0.3.6 // indirect + github.com/googleapis/gax-go/v2 v2.14.1 // indirect + github.com/gosimple/slug v1.15.0 // indirect + github.com/gosimple/unidecode v1.0.1 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect github.com/jackc/pgx/v5 v5.7.2 // indirect @@ -36,14 +47,24 @@ require ( github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/pelletier/go-toml/v2 v2.2.3 // indirect - github.com/rogpeppe/go-internal v1.11.0 // indirect + github.com/rogpeppe/go-internal v1.13.1 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.12 // indirect + go.opentelemetry.io/auto/sdk v1.1.0 // indirect + go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.59.0 // indirect + go.opentelemetry.io/otel v1.34.0 // indirect + go.opentelemetry.io/otel/metric v1.34.0 // indirect + go.opentelemetry.io/otel/trace v1.34.0 // indirect golang.org/x/arch v0.15.0 // indirect + golang.org/x/exp v0.0.0-20250305212735-054e65f0b394 // indirect golang.org/x/net v0.37.0 // indirect + golang.org/x/oauth2 v0.28.0 // indirect golang.org/x/sync v0.12.0 // indirect golang.org/x/sys v0.31.0 // indirect golang.org/x/text v0.23.0 // indirect - google.golang.org/protobuf v1.36.5 // indirect + google.golang.org/api v0.228.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20250313205543-e70fdf4c4cb4 // indirect + google.golang.org/grpc v1.71.0 // indirect + google.golang.org/protobuf v1.36.6 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.sum b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.sum index fc9ac2ce0112e916606dc13ba95b03d9c01f9373..5497ec831debdb4d4cfb521ba2a52edced87edb2 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.sum +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.sum @@ -1,3 +1,9 @@ +cloud.google.com/go/auth v0.15.0 h1:Ly0u4aA5vG/fsSsxu98qCQBemXtAtJf+95z9HK+cxps= +cloud.google.com/go/auth v0.15.0/go.mod h1:WJDGqZ1o9E9wKIL+IwStfyn/+s59zl4Bi+1KQNVXLZ8= +cloud.google.com/go/auth/oauth2adapt v0.2.8 h1:keo8NaayQZ6wimpNSmW5OPc283g65QNIiLpZnkHRbnc= +cloud.google.com/go/auth/oauth2adapt v0.2.8/go.mod h1:XQ9y31RkqZCcwJWNSx2Xvric3RrU88hAYYbjDWYDL+c= +cloud.google.com/go/compute/metadata v0.6.0 h1:A6hENjEsCDtC1k8byVsgwvVcioamEHvZ4j01OwKxG9I= +cloud.google.com/go/compute/metadata v0.6.0/go.mod h1:FjyFAW1MW0C203CEOMDTu3Dk1FlqW3Rga40jzHL4hfg= github.com/bytedance/sonic v1.13.1 h1:Jyd5CIvdFnkOWuKXr+wm4Nyk2h0yAFsr8ucJgEasO3g= github.com/bytedance/sonic v1.13.1/go.mod h1:o68xyaF9u2gvVBuGHPlUVCy+ZfmNNO5ETf1+KgkJhz4= github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= @@ -10,12 +16,19 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= +github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM= github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8= github.com/gin-contrib/sse v1.0.0 h1:y3bT1mUWUxDpW4JLQg/HnTqV4rozuW4tC9eFKTxYI9E= github.com/gin-contrib/sse v1.0.0/go.mod h1:zNuFdwarAygJBht0NTKiSi3jRf6RbqeILZ9Sp6Slhe0= github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU= github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= +github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= @@ -31,6 +44,16 @@ github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVI github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/s2a-go v0.1.9 h1:LGD7gtMgezd8a/Xak7mEWL0PjoTQFvpRudN895yqKW0= +github.com/google/s2a-go v0.1.9/go.mod h1:YA0Ei2ZQL3acow2O62kdp9UlnvMmU7kA6Eutn0dXayM= +github.com/googleapis/enterprise-certificate-proxy v0.3.6 h1:GW/XbdyBFQ8Qe+YAmFU9uHLo7OnF5tL52HFAgMmyrf4= +github.com/googleapis/enterprise-certificate-proxy v0.3.6/go.mod h1:MkHOF77EYAE7qfSuSS9PU6g4Nt4e11cnsDUowfwewLA= +github.com/googleapis/gax-go/v2 v2.14.1 h1:hb0FFeiPaQskmvakKu5EbCbpntQn48jyHuvrkurSS/Q= +github.com/googleapis/gax-go/v2 v2.14.1/go.mod h1:Hb/NubMaVM88SrNkvl8X/o8XWwDJEPqouaLeN2IUxoA= +github.com/gosimple/slug v1.15.0 h1:wRZHsRrRcs6b0XnxMUBM6WK1U1Vg5B0R7VkIf1Xzobo= +github.com/gosimple/slug v1.15.0/go.mod h1:UiRaFH+GEilHstLUmcBgWcI42viBN7mAb818JrYOeFQ= +github.com/gosimple/unidecode v1.0.1 h1:hZzFTMMqSswvf0LBJZCZgThIZrpDHFXux9KeGmn6T/o= +github.com/gosimple/unidecode v1.0.1/go.mod h1:CP0Cr1Y1kogOtx0bJblKzsVWrqYaqfNOnHzpgWw4Awc= github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo= @@ -70,6 +93,7 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= +github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o= github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww= github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -88,12 +112,26 @@ github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= +go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA= +go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.59.0 h1:CV7UdSGJt/Ao6Gp4CXckLxVRRsRgDHoI8XjbL3PDl8s= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.59.0/go.mod h1:FRmFuRJfag1IZ2dPkHnEoSFVgTVPUd2qf5Vi69hLb8I= +go.opentelemetry.io/otel v1.34.0 h1:zRLXxLCgL1WyKsPVrgbSdMN4c0FMkDAskSTQP+0hdUY= +go.opentelemetry.io/otel v1.34.0/go.mod h1:OWFPOQ+h4G8xpyjgqo4SxJYdDQ/qmRH+wivy7zzx9oI= +go.opentelemetry.io/otel/metric v1.34.0 h1:+eTR3U0MyfWjRDhmFMxe2SsW64QrZ84AOhvqS7Y+PoQ= +go.opentelemetry.io/otel/metric v1.34.0/go.mod h1:CEDrp0fy2D0MvkXE+dPV7cMi8tWZwX3dmaIhwPOaqHE= +go.opentelemetry.io/otel/trace v1.34.0 h1:+ouXS2V8Rd4hp4580a8q23bg0azF2nI8cqLYnC8mh/k= +go.opentelemetry.io/otel/trace v1.34.0/go.mod h1:Svm7lSjQD7kG7KJ/MUHPVXSDGz2OX4h0M2jHBhmSfRE= golang.org/x/arch v0.15.0 h1:QtOrQd0bTUnhNVNndMpLHNWrDmYzZ2KDqSrEymqInZw= golang.org/x/arch v0.15.0/go.mod h1:JmwW7aLIoRUKgaTzhkiEFxvcEiQGyOg9BMonBJUS7EE= golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34= golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc= +golang.org/x/exp v0.0.0-20250305212735-054e65f0b394 h1:nDVHiLt8aIbd/VzvPWN6kSOPE7+F/fNFDSXLVYkE/Iw= +golang.org/x/exp v0.0.0-20250305212735-054e65f0b394/go.mod h1:sIifuuw/Yco/y6yb6+bDNfyeQ/MdPUy/hKEMYQV17cM= golang.org/x/net v0.37.0 h1:1zLorHbz+LYj7MQlSf1+2tPIIgibq2eL5xkrGk6f+2c= golang.org/x/net v0.37.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8= +golang.org/x/oauth2 v0.28.0 h1:CrgCKl8PPAVtLnU3c+EDw6x11699EWlsDeWNWKdIOkc= +golang.org/x/oauth2 v0.28.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8= golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw= golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -103,8 +141,16 @@ golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY= golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/api v0.228.0 h1:X2DJ/uoWGnY5obVjewbp8icSL5U4FzuCfy9OjbLSnLs= +google.golang.org/api v0.228.0/go.mod h1:wNvRS1Pbe8r4+IfBIniV8fwCpGwTrYa+kMUDiC5z5a4= +google.golang.org/genproto/googleapis/rpc v0.0.0-20250313205543-e70fdf4c4cb4 h1:iK2jbkWL86DXjEx0qiHcRE9dE4/Ahua5k6V8OWFb//c= +google.golang.org/genproto/googleapis/rpc v0.0.0-20250313205543-e70fdf4c4cb4/go.mod h1:LuRYeWDFV6WOn90g357N17oMCaxpgCnbi/44qJvDn2I= +google.golang.org/grpc v1.71.0 h1:kF77BGdPTQ4/JZWMlb9VpJ5pa25aqvVqogsxNHHdeBg= +google.golang.org/grpc v1.71.0/go.mod h1:H0GRtasmQOh9LkFoCPDu3ZrwUtD1YGE+b2vYBYd/8Ec= google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM= google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= +google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY= +google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/authentication_middleware.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/authentication_middleware.go index e413a98e080bcf0700af246cd083a9337263dba1..7a06a07a9c505e034cba8020776da4eb84afddaa 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/authentication_middleware.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/authentication_middleware.go @@ -13,11 +13,8 @@ func AuthUser(c *gin.Context) { var currAccData models.AccountData if c.Request.Header["Authorization"] != nil { token := c.Request.Header["Authorization"] - // fmt.Println("Authorization :", token) currAccData.UserID, currAccData.VerifyStatus, currAccData.ErrVerif = services.VerifyToken(token[0]) - // fmt.Println("Verify Status :", currAccData.VerifyStatus) - // fmt.Println("Verify UserID :", currAccData.UserID) if currAccData.VerifyStatus == "invalid-token" || currAccData.VerifyStatus == "expired" { currAccData.UserID = 0 diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/request_model.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/request_model.go index dfb4bfd35cd08440c3d106dd517a1821d90460c8..d59213670e8b21d29270349fa9c598ccb2207bed 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/request_model.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/request_model.go @@ -1,5 +1,7 @@ package models +import uuid "github.com/satori/go.uuid" + type LoginRequest struct { Email string `json:"email" binding:"required"` Password string `json:"password" binding:"required"` @@ -12,11 +14,22 @@ type RegisterRequest struct { Password string `json:"password" binding:"required"` } -type CreateEmailVerificationRequest struct { - AccountID int `json:"account_id" binding:"required"` -} - type ChangePasswordRequest struct { OldPassword string `json:"old_password" binding:"required" ` NewPassword string `json:"new_password" binding:"required" ` } + +type CreateVerifyEmailRequest struct { + Token uint `json:"token" binding:"required"` + UUID uuid.UUID `json:"uuid" binding:"required"` +} + +type OptionsRequest struct { + OptionName string `json:"option_name" binding:"required"` + OptionValue []string `json:"option_values" binding:"required"` +} + +type ExternalAuthRequest struct { + OauthID string `json:"oauth_id" binding:"required"` + OauthProvider string `json:"oauth_provider" binding:"required"` +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/response_model.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/response_model.go index 7e049aac3f7c5a196f9a54ce924b5424f5986553..7c744950bba893f98e47ab946dd112c1474872ee 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/response_model.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/response_model.go @@ -18,3 +18,10 @@ type AuthenticatedUser struct { Account Account `json:"account"` Token string `json:"token"` } +type Options struct { + OptionCategory OptionCategory `json:"option_category"` + OptionValues []OptionValues `json:"option_values"` +} +type OptionsResponse struct { + Options []Options `json:"options"` +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/email_verification_repository.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/email_verification_repository.go index 0072ea0952f85bc719bf4bd0d1cf90e6a7270870..f41d8f97fa93a536f7ae1c523fd2c0163a0ed00a 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/email_verification_repository.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/email_verification_repository.go @@ -4,15 +4,17 @@ import ( "time" "api.qobiltu.id/models" + uuid "github.com/satori/go.uuid" ) -func CreateEmailVerification(accountId uint, dueTime time.Time, token uint) Repository[models.EmailVerification, models.EmailVerification] { +func CreateEmailVerification(uuid uuid.UUID, accountId uint, dueTime time.Time, token uint) Repository[models.EmailVerification, models.EmailVerification] { repo := Construct[models.EmailVerification, models.EmailVerification]( models.EmailVerification{ AccountID: accountId, IsExpired: false, ExpiredAt: dueTime, Token: token, + UUID: uuid, }, ) Create(repo) @@ -34,6 +36,18 @@ func GetEmailVerification(accountId uint, token uint) Repository[models.EmailVer return *repo } +func UpdateExpiredEmailVerification(uuid uuid.UUID) Repository[models.EmailVerification, models.EmailVerification] { + repo := Construct[models.EmailVerification, models.EmailVerification]( + models.EmailVerification{UUID: uuid}, + ) + + repo.Transaction.Where("UUID = ?", uuid).First(&repo.Constructor) + repo.Constructor.IsExpired = true + repo.Transaction.Updates(repo.Constructor) + repo.Result = repo.Constructor + return *repo +} + func DeleteEmailVerification(token uint) Repository[models.EmailVerification, models.EmailVerification] { repo := Construct[models.EmailVerification, models.EmailVerification]( models.EmailVerification{ diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/external_auth_repository.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/external_auth_repository.go new file mode 100644 index 0000000000000000000000000000000000000000..77b6d6c3da3bc7a252a12702b12115331fc747b2 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/external_auth_repository.go @@ -0,0 +1,37 @@ +package repositories + +import "api.qobiltu.id/models" + +func CreateExternalAuth(oauth models.ExternalAuth) Repository[models.ExternalAuth, models.ExternalAuth] { + repo := Construct[models.ExternalAuth, models.ExternalAuth]( + oauth, + ) + Create(repo) + return *repo +} + +func GetExternalAuthByAccountId(accountId uint) Repository[models.ExternalAuth, []models.ExternalAuth] { + repo := Construct[models.ExternalAuth, []models.ExternalAuth]( + models.ExternalAuth{ + AccountID: accountId, + }, + ) + repo.Transactions( + WhereGivenConstructor[models.ExternalAuth, []models.ExternalAuth], + Find[models.ExternalAuth, []models.ExternalAuth], + ) + return *repo +} + +func GetExternalAccountByOauthId(oauthId string) Repository[models.ExternalAuth, models.ExternalAuth] { + repo := Construct[models.ExternalAuth, models.ExternalAuth]( + models.ExternalAuth{ + OauthID: oauthId, + }, + ) + repo.Transactions( + WhereGivenConstructor[models.ExternalAuth, models.ExternalAuth], + Find[models.ExternalAuth, models.ExternalAuth], + ) + return *repo +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/option_repository.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/option_repository.go new file mode 100644 index 0000000000000000000000000000000000000000..760678f7ac3f9916c3ed0e8f9ccf10f9fb4e8e51 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/option_repository.go @@ -0,0 +1,43 @@ +package repositories + +import ( + "api.qobiltu.id/models" +) + +func CreateOptionCategory(categories models.OptionCategory) Repository[models.OptionCategory, models.OptionCategory] { + repo := Construct[models.OptionCategory, models.OptionCategory]( + categories, + ) + Create(repo) + return *repo +} + +func CreateOptionValues(values models.OptionValues) Repository[models.OptionValues, models.OptionValues] { + repo := Construct[models.OptionValues, models.OptionValues]( + values, + ) + Create(repo) + return *repo +} + +func GetOptionCategoryBySlug(slug string) Repository[models.OptionCategory, models.OptionCategory] { + repo := Construct[models.OptionCategory, models.OptionCategory]( + models.OptionCategory{OptionSlug: slug}, + ) + repo.Transactions( + WhereGivenConstructor[models.OptionCategory, models.OptionCategory], + Find[models.OptionCategory, models.OptionCategory], + ) + return *repo +} + +func GetOptionValuesByCategoryId(categoryId uint) Repository[models.OptionValues, []models.OptionValues] { + repo := Construct[models.OptionValues, []models.OptionValues]( + models.OptionValues{OptionCategoryID: categoryId}, + ) + repo.Transactions( + WhereGivenConstructor[models.OptionValues, []models.OptionValues], + Find[models.OptionValues, []models.OptionValues], + ) + return *repo +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/region_repository.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/region_repository.go new file mode 100644 index 0000000000000000000000000000000000000000..64ae641efeeb9a8361a8e5a4d1e43eeb2b50e98c --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/region_repository.go @@ -0,0 +1,47 @@ +package repositories + +import ( + "api.qobiltu.id/models" +) + +func BulkCreateProvince(provinces []models.RegionProvince) Repository[[]models.RegionProvince, []models.RegionProvince] { + repo := Construct[[]models.RegionProvince, []models.RegionProvince]( + provinces, + ) + + Create(repo) + return *repo +} + +func BulkCreateCity(cities []models.RegionCity) Repository[[]models.RegionCity, []models.RegionCity] { + repo := Construct[[]models.RegionCity, []models.RegionCity]( + cities, + ) + + Create(repo) + return *repo +} + +func GetListProvinces() Repository[models.RegionProvince, []models.RegionProvince] { + repo := Construct[models.RegionProvince, []models.RegionProvince]( + models.RegionProvince{}, + ) + + repo.Transactions( + Find[models.RegionProvince, []models.RegionProvince], + ) + return *repo +} + +func GetListCitiesByProvinceId(provinceId uint) Repository[models.RegionCity, []models.RegionCity] { + repo := Construct[models.RegionCity, []models.RegionCity]( + models.RegionCity{ + ProvinceID: provinceId, + }, + ) + repo.Transactions( + WhereGivenConstructor[models.RegionCity, []models.RegionCity], + Find[models.RegionCity, []models.RegionCity], + ) + return *repo +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/auth_route.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/auth_route.go index 6ca2498ea0746d60de9cddf3b605fe0ecb9107bc..808b568cf02fd0137a46cb808a2c9102c636eccc 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/auth_route.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/auth_route.go @@ -9,6 +9,7 @@ import ( func AuthRoute(router *gin.Engine) { routerGroup := router.Group("/api/v1/auth") { + routerGroup.POST("/external-login", AuthController.ExternalAuth) routerGroup.POST("/login", AuthController.Login) routerGroup.POST("/register", AuthController.Register) routerGroup.PUT("/change-password", middleware.AuthUser, AuthController.ChangePassword) diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/email_route.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/email_route.go index 8f2f59e88a8cf958d200ee36174549e839a0a33c..f76fc498313541896253315be8d1e57bd3b03a05 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/email_route.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/email_route.go @@ -2,14 +2,14 @@ package router import ( EmailController "api.qobiltu.id/controller/email" + "api.qobiltu.id/middleware" "github.com/gin-gonic/gin" ) func EmailRoute(router *gin.Engine) { routerGroup := router.Group("/api/v1/email") { - routerGroup.POST("/verify", EmailController.CreateVerification) - routerGroup.POST("/create-verification", EmailController.CreateVerification) - routerGroup.DELETE("/delete-verification", EmailController.DeleteVerification) + routerGroup.POST("/verify", middleware.AuthUser, EmailController.Verify) + routerGroup.POST("/create-verification", middleware.AuthUser, EmailController.CreateVerification) } } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/options_route.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/options_route.go new file mode 100644 index 0000000000000000000000000000000000000000..1f935c0a433d00bdefa0f5bb3c75d00795012def --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/options_route.go @@ -0,0 +1,20 @@ +package router + +import ( + OptionsController "api.qobiltu.id/controller/options" + CityController "api.qobiltu.id/controller/region/city" + ProvinceController "api.qobiltu.id/controller/region/province" + "github.com/gin-gonic/gin" +) + +func OptionsRoute(router *gin.Engine) { + routerGroup := router.Group("/api/v1/options") + { + routerGroup.POST("/create", OptionsController.AddOptions) + routerGroup.GET("/list/:slug", OptionsController.List) + routerGroup.GET("/region/provinces", ProvinceController.List) + routerGroup.GET("/region/cities", CityController.List) + routerGroup.POST("/region/seed-provinces", ProvinceController.Seeds) + routerGroup.POST("/region/seed-cities", CityController.Seeds) + } +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/router.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/router.go index fa10e4899db30cae716cc34f9d165cffcb5b7c1d..c414889615c83c047f89d4e2ba6f97ba074edd08 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/router.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/router.go @@ -12,5 +12,6 @@ func StartService() { AuthRoute(router) UserRoute(router) EmailRoute(router) + OptionsRoute(router) router.Run(config.TCP_ADDRESS) } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/authentication_service.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/authentication_service.go index 22a82cb0fe7042139cfa992ca4ac35bfcc9b4490..8b3474fa876993fe8a09fde9a241c8a54df5feee 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/authentication_service.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/authentication_service.go @@ -2,7 +2,6 @@ package services import ( "errors" - "fmt" "api.qobiltu.id/models" "api.qobiltu.id/repositories" @@ -45,15 +44,13 @@ func (s *AuthenticationService) Update(oldPassword string, newPassword string) { s.Exception.Message = "Password must have at least 8 characters!" return } - accountData := repositories.GetAccountbyId(s.Constructor.Id) + accountData := repositories.GetAccountById(s.Constructor.Id) if accountData.NoRecord { s.Exception.DataNotFound = true s.Exception.Message = "there is no account with given credentials!" return } - fmt.Println("Result Password", accountData.Result.Password) - fmt.Println("old Password given", oldPassword) if VerifyPassword(accountData.Result.Password, oldPassword) != nil { s.Exception.Unauthorized = true s.Exception.Message = "incorrect old password!" diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/external_authentication_service.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/external_authentication_service.go new file mode 100644 index 0000000000000000000000000000000000000000..71a13b170924f10698468b6a6ee1870f51ad6a57 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/external_authentication_service.go @@ -0,0 +1,55 @@ +package services + +import ( + "context" + "errors" + + "api.qobiltu.id/models" + "api.qobiltu.id/repositories" + uuid "github.com/satori/go.uuid" + "google.golang.org/api/idtoken" +) + +type GoogleAuthService struct { + Service[models.ExternalAuth, models.AuthenticatedUser] +} + +func (s *GoogleAuthService) Authenticate() { + GoogleAuth := repositories.GetExternalAccountByOauthId(s.Constructor.OauthID) + payload, errGoogleAuth := idtoken.Validate(context.Background(), s.Constructor.OauthID, "") + s.Error = errGoogleAuth + if errGoogleAuth != nil { + s.Exception.Unauthorized = true + s.Exception.Message = "Oauth Provider Failed Login (Google Authentication)" + return + } + email := payload.Claims["email"] + if GoogleAuth.NoRecord { + s.Constructor.UUID = uuid.NewV4() + s.Constructor.OauthProvider = "Google" + + createGoogleAuth := repositories.CreateExternalAuth(s.Constructor) + + s.Error = createGoogleAuth.RowsError + + createAccount := repositories.CreateAccount(models.Account{ + Email: email.(string), + IsEmailVerified: true, + }) + s.Error = errors.Join(s.Error, createAccount.RowsError) + } + accountData := repositories.GetAccountById(GoogleAuth.Result.AccountID) + token, err_tok := GenerateToken(&accountData.Result) + + if err_tok != nil { + s.Error = errors.Join(s.Error, err_tok) + } + + accountData.Result.Password = "SECRET" + s.Result = models.AuthenticatedUser{ + Account: accountData.Result, + Token: token, + } + s.Error = accountData.RowsError + +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/option_service.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/option_service.go new file mode 100644 index 0000000000000000000000000000000000000000..a95ee656c17e94747d5a3929d7eb3f2701a59255 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/option_service.go @@ -0,0 +1,70 @@ +package services + +import ( + "api.qobiltu.id/models" + "api.qobiltu.id/repositories" + "github.com/gosimple/slug" +) + +type OptionService struct { + Service[[]models.OptionsRequest, models.OptionsResponse] +} + +type OptionValueService struct { + Service[models.OptionCategory, models.Options] +} + +func (s *OptionService) Create() { + optionsResult := []models.Options{} + for _, option := range s.Constructor { + OptionCategoryRepo := repositories.CreateOptionCategory( + models.OptionCategory{ + OptionName: option.OptionName, + OptionSlug: slug.Make(option.OptionName), + }, + ) + if OptionCategoryRepo.RowsError != nil { + OptionCategoryRepo.Transaction.Rollback() + s.Error = OptionCategoryRepo.RowsError + return + } + optionsValueResult := []models.OptionValues{} + for _, value := range option.OptionValue { + OptionValuesRepo := repositories.CreateOptionValues( + models.OptionValues{ + OptionCategoryID: OptionCategoryRepo.Result.ID, + OptionValue: value, + }, + ) + + if OptionValuesRepo.RowsError != nil { + OptionValuesRepo.Transaction.Rollback() + s.Error = OptionValuesRepo.RowsError + return + } + optionsValueResult = append(optionsValueResult, OptionValuesRepo.Result) + } + optionsResult = append(optionsResult, models.Options{OptionCategory: OptionCategoryRepo.Result, OptionValues: optionsValueResult}) + } + s.Result = models.OptionsResponse{ + Options: optionsResult, + } +} + +func (s *OptionValueService) Retrieve() { + optionCategory := repositories.GetOptionCategoryBySlug(s.Constructor.OptionSlug) + if optionCategory.RowsError != nil { + s.Error = optionCategory.RowsError + return + } + optionValues := repositories.GetOptionValuesByCategoryId(optionCategory.Result.ID) + if optionValues.RowsError != nil { + s.Error = optionValues.RowsError + return + } + s.Result = models.Options{ + OptionCategory: optionCategory.Result, + OptionValues: optionValues.Result, + } + +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/region_service.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/region_service.go new file mode 100644 index 0000000000000000000000000000000000000000..493269736cc9a952b2c354b85e40eb04c93cb0eb --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/region_service.go @@ -0,0 +1,90 @@ +package services + +import ( + "encoding/json" + "log" + "os" + "path/filepath" + "runtime" + + "api.qobiltu.id/models" + "api.qobiltu.id/repositories" +) + +type ProvinceService struct { + Service[models.RegionProvince, []models.RegionProvince] +} + +type CityService struct { + Service[models.RegionCity, []models.RegionCity] +} + +func seedCity() ([]models.RegionCity, error) { + log.Println("Seed City") + _, b, _, _ := runtime.Caller(0) + basePath := filepath.Dir(b) + file, err := os.Open(filepath.Join(basePath, "..", "utils", "seeds", "city.json")) + if err != nil { + return nil, err + } + defer file.Close() + var cities []models.RegionCity + if err := json.NewDecoder(file).Decode(&cities); err != nil { + return nil, err + } + return cities, nil +} + +func seedProvince() ([]models.RegionProvince, error) { + log.Println("Seed City") + _, b, _, _ := runtime.Caller(0) + basePath := filepath.Dir(b) + file, err := os.Open(filepath.Join(basePath, "..", "utils", "seeds", "province.json")) + if err != nil { + return nil, err + } + defer file.Close() + var provinces []models.RegionProvince + if err := json.NewDecoder(file).Decode(&provinces); err != nil { + return nil, err + } + return provinces, nil +} + +func (s *ProvinceService) Create() { + provinces, errSeed := seedProvince() + if errSeed != nil { + s.Error = errSeed + s.Exception.InternalServerError = true + s.Exception.Message = "Failed to seed province" + return + } + createProvince := repositories.BulkCreateProvince(provinces) + s.Error = createProvince.RowsError + s.Result = createProvince.Result +} + +func (s *CityService) Create() { + cities, errSeed := seedCity() + if errSeed != nil { + s.Error = errSeed + s.Exception.InternalServerError = true + s.Exception.Message = "Failed to seed province" + return + } + createCity := repositories.BulkCreateCity(cities) + s.Error = createCity.RowsError + s.Result = createCity.Result +} + +func (s *ProvinceService) Retrieve() { + Province := repositories.GetListProvinces() + s.Error = Province.RowsError + s.Result = Province.Result +} + +func (s *CityService) Retrieve() { + cities := repositories.GetListCitiesByProvinceId(s.Constructor.ProvinceID) + s.Error = cities.RowsError + s.Result = cities.Result +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/email/email_create_verification.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/email/email_create_verification.go index 44ee9b005702e30354ef25f46d80e9551dbfcf6b..bf5f8d44118c25981fa22cb46c17eefb2d12c684 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/email/email_create_verification.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/email/email_create_verification.go @@ -1,8 +1,6 @@ package controller import ( - "strconv" - "api.qobiltu.id/controller" "api.qobiltu.id/models" "api.qobiltu.id/services" @@ -14,9 +12,10 @@ func CreateVerification(c *gin.Context) { emailVerificationController := controller.Controller[any, models.EmailVerification, models.EmailVerification]{ Service: &emailVerification.Service, } - query, _ := c.GetQuery("account_id") - accountId, _ := strconv.Atoi(query) - emailVerificationController.Service.Constructor.AccountID = uint(accountId) - emailVerification.Create() - emailVerificationController.Response(c) + emailVerificationController.HeaderParse(c, func() { + emailVerificationController.Service.Constructor.AccountID = uint(emailVerificationController.AccountData.UserID) + emailVerification.Create() + emailVerificationController.Response(c) + }) + } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/user_update_profile_controller.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/user_update_profile_controller.go index 4821ed13bbf913726e6512251db3bf43728a8a19..ec2b5ab25518d1aa9221afe7b07527ba298b14bc 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/user_update_profile_controller.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/user_update_profile_controller.go @@ -1,6 +1,8 @@ package user import ( + "fmt" + "api.qobiltu.id/controller" "api.qobiltu.id/models" "api.qobiltu.id/services" @@ -17,6 +19,7 @@ func UpdateProfile(c *gin.Context) { userUpdateProfileController.Service.Constructor = userUpdateProfileController.Request userUpdateProfileController.HeaderParse(c, func() { userUpdateProfileController.Service.Constructor.AccountID = uint(userUpdateProfileController.AccountData.UserID) + fmt.Println("Account ID:", userUpdateProfileController.Service.Constructor.AccountID) }) userProfile.Update() }, diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/database_orm_model.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/database_orm_model.go index ac953006acff71b8ab536fe0519255e65a02deae..c7d9163ce8ab396cd38c1317229e931e7da31765 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/database_orm_model.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/database_orm_model.go @@ -28,13 +28,14 @@ type AccountDetails struct { LastJob *string `json:"last_job"` Gender *bool `json:"gender"` LastEducation *string `json:"last_education"` - MaritalStatus *bool `json:"marital_status"` + MaritalStatus *string `json:"marital_status"` Avatar *string `json:"avatar"` PhoneNumber *uint `json:"phone_number"` } type EmailVerification struct { ID uint `gorm:"primaryKey" json:"id"` + UUID uuid.UUID `gorm:"type:uuid" json:"uuid" ` Token uint `json:"token"` AccountID uint `json:"account_id"` IsExpired bool `json:"is_expired"` @@ -43,10 +44,11 @@ type EmailVerification struct { } type ExternalAuth struct { - ID uint `gorm:"primaryKey" json:"id"` - OauthID string `json:"oauth_id"` - AccountID uint `json:"account_id"` - OauthProvider string `json:"oauth_provider"` + ID uint `gorm:"primaryKey" json:"id"` + UUID uuid.UUID `gorm:"type:uuid" json:"uuid" ` + OauthID string `json:"oauth_id"` + AccountID uint `json:"account_id"` + OauthProvider string `json:"oauth_provider"` } type FCM struct { @@ -57,6 +59,7 @@ type FCM struct { type ForgotPassword struct { ID uint `gorm:"primaryKey" json:"id"` + UUID uuid.UUID `gorm:"type:uuid" json:"uuid" ` Token uint `json:"token"` AccountID uint `json:"account_id"` IsExpired bool `json:"is_expired"` @@ -89,7 +92,17 @@ type AcademyContent struct { AcademyMaterialID uint `json:"academy_material_id"` Description string `json:"description"` } +type OptionCategory struct { + ID uint `gorm:"primaryKey" json:"id"` + OptionName string `json:"option_name"` + OptionSlug string `json:"option_slug"` +} +type OptionValues struct { + ID uint `gorm:"primaryKey" json:"id"` + OptionCategoryID uint `json:"option_category_id"` + OptionValue string `json:"option_value"` +} type AcademyMaterialProgress struct { ID uint `gorm:"primaryKey" json:"id"` UUID uuid.UUID `gorm:"type:uuid" json:"uuid"` @@ -105,6 +118,21 @@ type AcademyContentProgress struct { AcademyID uint `json:"academy_id"` } +type RegionProvince struct { + ID uint `json:"id"` + Name string `json:"name"` + Code string `json:"code"` +} + +type RegionCity struct { + ID uint `json:"id"` + Type string `json:"type"` + Name string `json:"name"` + Code string `json:"code"` + FullCode string `json:"full_code"` + ProvinceID uint `json:"province_id"` +} + // Gorm table name settings func (Account) TableName() string { return "account" } func (AccountDetails) TableName() string { return "account_details" } @@ -117,3 +145,5 @@ func (AcademyMaterial) TableName() string { return "academy_materials" } func (AcademyContent) TableName() string { return "academy_contents" } func (AcademyMaterialProgress) TableName() string { return "academy_materials_progress" } func (AcademyContentProgress) TableName() string { return "academy_contents_progress" } +func (RegionProvince) TableName() string { return "region_provinces" } +func (RegionCity) TableName() string { return "region_cities" } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/account_repository.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/account_repository.go index 686ccc92e7a56587581e345bbb3dca284fb1d7da..a91a7779aaee9b85bfcadd25a6fb7cdbd3fb0647 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/account_repository.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/account_repository.go @@ -32,7 +32,10 @@ func UpdateAccount(account models.Account) Repository[models.Account, models.Acc repo := Construct[models.Account, models.Account]( account, ) - Update(repo) + repo.Transactions( + WhereGivenConstructor[models.Account, models.Account], + Update[models.Account], + ) return *repo } @@ -69,10 +72,13 @@ func CreateAccountDetails(accountDetails models.AccountDetails) Repository[model func UpdateAccountDetails(accountDetails models.AccountDetails) Repository[models.AccountDetails, models.AccountDetails] { repo := Construct[models.AccountDetails, models.AccountDetails]( - accountDetails, + models.AccountDetails{AccountID: accountDetails.AccountID}, ) - fmt.Println(accountDetails) - fmt.Println("Account ID : ", accountDetails.AccountID) - Update(repo) + repo.Transaction.Where("account_id = ?", accountDetails.AccountID).First(&repo.Constructor) + accountDetails.ID = repo.Constructor.ID + // fmt.Println(repo.Constructor) + // fmt.Println(accountDetails) + repo.Transaction.Updates(accountDetails) + repo.Result = accountDetails return *repo } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/repository.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/repository.go index 0c6b1ee5c41b63f4414e7013717d7fbd58a7dbf4..89367e50d27d076540f8b7766d9b3a8cbbdf0913 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/repository.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/repository.go @@ -92,7 +92,7 @@ func Create[T1 any](repo *Repository[T1, T1]) *gorm.DB { } func Update[T1 any](repo *Repository[T1, T1]) *gorm.DB { - tx := repo.Transaction.Save(&repo.Constructor) + tx := repo.Transaction.Updates(&repo.Constructor) repo.RowsCount = int(tx.RowsAffected) repo.NoRecord = repo.RowsCount == 0 repo.RowsError = tx.Error diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/email_verification_service.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/email_verification_service.go index d94c65bc93550413c285e2817b68392664fb3b2a..c0eaba5711783161d526de88c0090a594bacfda2 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/email_verification_service.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/email_verification_service.go @@ -1,12 +1,16 @@ package services import ( - "math/rand" + "fmt" + "log" + "math/rand/v2" + "net/smtp" "time" "api.qobiltu.id/config" "api.qobiltu.id/models" "api.qobiltu.id/repositories" + uuid "github.com/satori/go.uuid" ) type EmailVerificationService struct { @@ -14,7 +18,7 @@ type EmailVerificationService struct { } func (s *EmailVerificationService) Create() { - accountRepo := repositories.GetAccountbyId(s.Constructor.AccountID) + accountRepo := repositories.GetAccountById(s.Constructor.AccountID) if accountRepo.NoRecord { s.Error = accountRepo.RowsError s.Exception.DataNotFound = true @@ -25,23 +29,54 @@ func (s *EmailVerificationService) Create() { remainingTime := time.Duration(config.EMAIL_VERIFICATION_DURATION) * time.Hour dueTime := CalculateDueTime(remainingTime) - randomizer := rand.New(rand.NewSource(10)) - token := uint(randomizer.Int()) + token := uint(rand.IntN(100000)) + s.Constructor.UUID = uuid.NewV4() - repo := repositories.CreateEmailVerification(s.Constructor.AccountID, dueTime, token) + repo := repositories.CreateEmailVerification(s.Constructor.UUID, s.Constructor.AccountID, dueTime, token) s.Error = repo.RowsError s.Result = repo.Result + + // ⬇ Kirim token ke email user menggunakan SMTP + go func(toEmail string, token uint) { + from := config.SMTP_SENDER_EMAIL + password := config.SMTP_SENDER_PASSWORD + smtpHost := config.SMTP_HOST + smtpPort := config.SMTP_PORT + + auth := smtp.PlainAuth("", from, password, smtpHost) + + subject := "Email Verification Token" + body := fmt.Sprintf("Your verification token is: %06d\nPlease use it before it expires.", token) + + msg := []byte("To: " + toEmail + "\r\n" + + "Subject: " + subject + "\r\n" + + "\r\n" + + body + "\r\n") + + err := smtp.SendMail(smtpHost+":"+smtpPort, auth, from, []string{toEmail}, msg) + if err != nil { + log.Printf("Error sending verification email: %v", err) + } + }(accountRepo.Result.Email, token) } func (s *EmailVerificationService) Validate() { repo := repositories.GetEmailVerification(s.Constructor.AccountID, s.Constructor.Token) s.Error = repo.RowsError + if repo.NoRecord { s.Exception.DataNotFound = true s.Exception.Message = "Invalid token!" return } + + if repo.Result.ExpiredAt.Before(time.Now()) { + s.Exception.Unauthorized = true + s.Exception.Message = "Token has expired!" + repositories.UpdateExpiredEmailVerification(s.Constructor.UUID) + return + } s.Result = repo.Result } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/user_profile_service.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/user_profile_service.go index 419458a7d1e4845f1e4049bc3c3edabbbef748fb..4807849046127c92c0dfdc98d156e58cc9403492 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/user_profile_service.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/user_profile_service.go @@ -1,6 +1,8 @@ package services import ( + "fmt" + "api.qobiltu.id/models" "api.qobiltu.id/repositories" ) @@ -31,6 +33,7 @@ func (s *UserProfileService) Retrieve() { } func (s *UserProfileService) Update() { + fmt.Println("Account ID:", s.Constructor.AccountID) userProfile := repositories.UpdateAccountDetails(s.Constructor) s.Error = userProfile.RowsError if userProfile.NoRecord { diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/auth_profile_controller.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/auth_profile_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..f30ee7177fa8bd15be000bcfe941ceb2732a74c1 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/auth_profile_controller.go @@ -0,0 +1,21 @@ +package user + +import ( + "api.qobiltu.id/controller" + "api.qobiltu.id/models" + "api.qobiltu.id/services" + "github.com/gin-gonic/gin" +) + +func Profile(c *gin.Context) { + userProfile := services.UserProfileService{} + userProfileController := controller.Controller[any, models.AccountDetails, models.AccountDetails]{ + Service: &userProfile.Service, + } + userProfileController.HeaderParse(c, func() { + userProfileController.Service.Constructor.AccountID = uint(userProfileController.AccountData.UserID) + userProfile.Retrieve() + userProfileController.Response(c) + }, + ) +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/auth_update_profile_controller.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/auth_update_profile_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..4821ed13bbf913726e6512251db3bf43728a8a19 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/auth_update_profile_controller.go @@ -0,0 +1,24 @@ +package user + +import ( + "api.qobiltu.id/controller" + "api.qobiltu.id/models" + "api.qobiltu.id/services" + "github.com/gin-gonic/gin" +) + +func UpdateProfile(c *gin.Context) { + userProfile := services.UserProfileService{} + userUpdateProfileController := controller.Controller[models.AccountDetails, models.AccountDetails, models.AccountDetails]{ + Service: &userProfile.Service, + } + + userUpdateProfileController.RequestJSON(c, func() { + userUpdateProfileController.Service.Constructor = userUpdateProfileController.Request + userUpdateProfileController.HeaderParse(c, func() { + userUpdateProfileController.Service.Constructor.AccountID = uint(userUpdateProfileController.AccountData.UserID) + }) + userProfile.Update() + }, + ) +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/auth_route.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/auth_route.go index 4bd0d347f3705976e9973248b50103893c3f603e..6ca2498ea0746d60de9cddf3b605fe0ecb9107bc 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/auth_route.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/auth_route.go @@ -11,8 +11,6 @@ func AuthRoute(router *gin.Engine) { { routerGroup.POST("/login", AuthController.Login) routerGroup.POST("/register", AuthController.Register) - routerGroup.GET("/me", middleware.AuthUser, AuthController.Profile) - routerGroup.PUT("/me", middleware.AuthUser, AuthController.UpdateProfile) routerGroup.PUT("/change-password", middleware.AuthUser, AuthController.ChangePassword) } } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/router.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/router.go index a7dde2e239a2d254991cd00c712b9eeebe6102d1..fa10e4899db30cae716cc34f9d165cffcb5b7c1d 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/router.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/router.go @@ -9,6 +9,7 @@ import ( func StartService() { router := gin.Default() router.GET("/", controller.HomeController) + AuthRoute(router) UserRoute(router) EmailRoute(router) router.Run(config.TCP_ADDRESS) diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/database_orm_model.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/database_orm_model.go index 6d1cb93a61de13e3ae0f178cc701c77ed791ae7a..ac953006acff71b8ab536fe0519255e65a02deae 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/database_orm_model.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/database_orm_model.go @@ -14,23 +14,23 @@ type Account struct { IsEmailVerified bool `json:"is_email_verified"` IsDetailCompleted bool `json:"is_detail_completed"` CreatedAt time.Time `json:"created_at"` - DeletedAt *time.Time `json:"deleted_at,omitempty" gorm:"default:null"` + DeletedAt *time.Time `json:"deleted_at" gorm:"default:null"` } type AccountDetails struct { ID uint `gorm:"primaryKey" json:"id"` AccountID uint `json:"account_id"` InitialName string `json:"initial_name"` - FullName *string `json:"full_name,omitempty"` - DateOfBirth *time.Time `json:"date_of_birth,omitempty"` - PlaceOfBirth *string `json:"place_of_birth,omitempty"` - Domicile *string `json:"domicile,omitempty"` - LastJob *string `json:"last_job,omitempty"` - Gender *bool `json:"gender,omitempty"` - LastEducation *string `json:"last_education,omitempty"` - MaritalStatus *bool `json:"marital_status,omitempty"` - Avatar *string `json:"avatar,omitempty"` - PhoneNumber *uint `json:"phone_number,omitempty"` + FullName *string `json:"full_name"` + DateOfBirth *time.Time `json:"date_of_birth"` + PlaceOfBirth *string `json:"place_of_birth"` + Domicile *string `json:"domicile"` + LastJob *string `json:"last_job"` + Gender *bool `json:"gender"` + LastEducation *string `json:"last_education"` + MaritalStatus *bool `json:"marital_status"` + Avatar *string `json:"avatar"` + PhoneNumber *uint `json:"phone_number"` } type EmailVerification struct { @@ -57,7 +57,7 @@ type FCM struct { type ForgotPassword struct { ID uint `gorm:"primaryKey" json:"id"` - UUID uint `json:"uuid"` + Token uint `json:"token"` AccountID uint `json:"account_id"` IsExpired bool `json:"is_expired"` CreatedAt time.Time `json:"created_at"` diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/authentication_route.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/authentication_route.go new file mode 100644 index 0000000000000000000000000000000000000000..1559be8c370509101ce8508c226e252824d215ec --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/authentication_route.go @@ -0,0 +1,16 @@ +package router + +import ( + UserController "api.qobiltu.id/controller/user" + "api.qobiltu.id/middleware" + "github.com/gin-gonic/gin" +) + +func AuthRoute(router *gin.Engine) { + routerGroup := router.Group("/api/v1/auth") + { + routerGroup.POST("/login", UserController.Login) + routerGroup.POST("/register", UserController.Register) + routerGroup.PUT("/change-password", middleware.AuthUser, UserController.ChangePassword) + } +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/user_route.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/user_route.go index 1e5f9e405b0d936a86aed41c552cd8030fdc12bb..de080e4a230b6be743f69ce59a474cc47bc8c560 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/user_route.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/user_route.go @@ -9,10 +9,7 @@ import ( func UserRoute(router *gin.Engine) { routerGroup := router.Group("/api/v1/user") { - routerGroup.POST("/login", UserController.Login) - routerGroup.POST("/register", UserController.Register) routerGroup.GET("/me", middleware.AuthUser, UserController.Profile) routerGroup.PUT("/me", middleware.AuthUser, UserController.UpdateProfile) - routerGroup.PUT("/change-password", middleware.AuthUser, UserController.ChangePassword) } } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/auth/auth_change_password_controller.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/auth/auth_change_password_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..80aa4ac00b85babbbbbcab4de6c7d1fa3514ea6a --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/auth/auth_change_password_controller.go @@ -0,0 +1,21 @@ +package user + +import ( + "api.qobiltu.id/controller" + "api.qobiltu.id/models" + "api.qobiltu.id/services" + "github.com/gin-gonic/gin" +) + +func ChangePassword(c *gin.Context) { + authentication := services.AuthenticationService{} + changePasswordController := controller.Controller[models.ChangePasswordRequest, models.Account, models.AuthenticatedUser]{ + Service: &authentication.Service, + } + changePasswordController.HeaderParse(c, func() { + changePasswordController.Service.Constructor.Id = uint(changePasswordController.AccountData.UserID) + }) + changePasswordController.RequestJSON(c, func() { + authentication.Update(changePasswordController.Request.OldPassword, changePasswordController.Request.NewPassword) + }) +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/auth/auth_login_controller.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/auth/auth_login_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..679fc5a018d75e815dea00cca2012d5d56034eed --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/auth/auth_login_controller.go @@ -0,0 +1,20 @@ +package user + +import ( + "api.qobiltu.id/controller" + "api.qobiltu.id/models" + "api.qobiltu.id/services" + "github.com/gin-gonic/gin" +) + +func Login(c *gin.Context) { + authentication := services.AuthenticationService{} + loginController := controller.Controller[models.LoginRequest, models.Account, models.AuthenticatedUser]{ + Service: &authentication.Service, + } + loginController.RequestJSON(c, func() { + loginController.Service.Constructor.Email = loginController.Request.Email + loginController.Service.Constructor.Password = loginController.Request.Password + authentication.Authenticate() + }) +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/auth/auth_profile_controller.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/auth/auth_profile_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..f30ee7177fa8bd15be000bcfe941ceb2732a74c1 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/auth/auth_profile_controller.go @@ -0,0 +1,21 @@ +package user + +import ( + "api.qobiltu.id/controller" + "api.qobiltu.id/models" + "api.qobiltu.id/services" + "github.com/gin-gonic/gin" +) + +func Profile(c *gin.Context) { + userProfile := services.UserProfileService{} + userProfileController := controller.Controller[any, models.AccountDetails, models.AccountDetails]{ + Service: &userProfile.Service, + } + userProfileController.HeaderParse(c, func() { + userProfileController.Service.Constructor.AccountID = uint(userProfileController.AccountData.UserID) + userProfile.Retrieve() + userProfileController.Response(c) + }, + ) +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/auth/auth_register_controller.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/auth/auth_register_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..17051bee42f7b1d3fe144cedb6e8f11dbb5ac5b2 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/auth/auth_register_controller.go @@ -0,0 +1,20 @@ +package user + +import ( + "api.qobiltu.id/controller" + "api.qobiltu.id/models" + "api.qobiltu.id/services" + "github.com/gin-gonic/gin" +) + +func Register(c *gin.Context) { + register := services.RegisterService{} + registerController := controller.Controller[models.RegisterRequest, models.Account, models.Account]{ + Service: ®ister.Service, + } + registerController.RequestJSON(c, func() { + registerController.Service.Constructor.Password = registerController.Request.Password + registerController.Service.Constructor.Email = registerController.Request.Email + register.Create() + }) +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/auth/auth_update_profile_controller.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/auth/auth_update_profile_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..4821ed13bbf913726e6512251db3bf43728a8a19 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/auth/auth_update_profile_controller.go @@ -0,0 +1,24 @@ +package user + +import ( + "api.qobiltu.id/controller" + "api.qobiltu.id/models" + "api.qobiltu.id/services" + "github.com/gin-gonic/gin" +) + +func UpdateProfile(c *gin.Context) { + userProfile := services.UserProfileService{} + userUpdateProfileController := controller.Controller[models.AccountDetails, models.AccountDetails, models.AccountDetails]{ + Service: &userProfile.Service, + } + + userUpdateProfileController.RequestJSON(c, func() { + userUpdateProfileController.Service.Constructor = userUpdateProfileController.Request + userUpdateProfileController.HeaderParse(c, func() { + userUpdateProfileController.Service.Constructor.AccountID = uint(userUpdateProfileController.AccountData.UserID) + }) + userProfile.Update() + }, + ) +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.mod b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.mod index 0c2b7a92ff9c9eddbfa0d1506ccb9b4d0614163e..405345ca21ac9dd77eec5b3d4e48775287157552 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.mod +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.mod @@ -3,7 +3,6 @@ module api.qobiltu.id go 1.24.0 require ( - github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/gin-gonic/gin v1.10.0 github.com/golang-jwt/jwt/v5 v5.2.1 github.com/joho/godotenv v1.5.1 diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.sum b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.sum index b7d196affb731541ab18f7ba85fbb21dd47867ac..fc9ac2ce0112e916606dc13ba95b03d9c01f9373 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.sum +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.sum @@ -10,8 +10,6 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= -github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM= github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8= github.com/gin-contrib/sse v1.0.0 h1:y3bT1mUWUxDpW4JLQg/HnTqV4rozuW4tC9eFKTxYI9E= diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/authentication_middleware.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/authentication_middleware.go index 41ed5f2fb2eefa1f43c991f2f502d39505c76e3b..e413a98e080bcf0700af246cd083a9337263dba1 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/authentication_middleware.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/authentication_middleware.go @@ -3,52 +3,22 @@ package middleware import ( - "time" - - "api.qobiltu.id/config" "api.qobiltu.id/models" + "api.qobiltu.id/services" "api.qobiltu.id/utils" "github.com/gin-gonic/gin" - "github.com/golang-jwt/jwt/v5" ) -var salt = config.Salt -var secretKey = []byte(salt) - -// VerifyPassword verifies if the provided password matches the hashed password - -type CustomClaims struct { - jwt.RegisteredClaims - UserID int `json:"id"` -} - -func VerifyToken(bearer_token string) (int, string, error) { - // fmt.Println(bearer_token) - token, err := jwt.ParseWithClaims(bearer_token, &CustomClaims{}, func(token *jwt.Token) (interface{}, error) { - return secretKey, nil - }) - if err != nil { - return 0, "invalid-token", err - } - - // Extract the claims - claims, ok := token.Claims.(*CustomClaims) - if !ok || !token.Valid { - return 0, "invalid-token", err - } - if claims.ExpiresAt != nil && claims.ExpiresAt.Time.Before(time.Now()) { - return 0, "expired", err - } - - return claims.UserID, "valid", err -} - func AuthUser(c *gin.Context) { var currAccData models.AccountData - if c.Request.Header["Auth-Bearer-Token"] != nil { - token := c.Request.Header["Auth-Bearer-Token"] - currAccData.UserID, currAccData.VerifyStatus, currAccData.ErrVerif = VerifyToken(token[0]) - // fmt.Println("Verify Status :", currAccData.verifyStatus) + if c.Request.Header["Authorization"] != nil { + token := c.Request.Header["Authorization"] + // fmt.Println("Authorization :", token) + + currAccData.UserID, currAccData.VerifyStatus, currAccData.ErrVerif = services.VerifyToken(token[0]) + // fmt.Println("Verify Status :", currAccData.VerifyStatus) + // fmt.Println("Verify UserID :", currAccData.UserID) + if currAccData.VerifyStatus == "invalid-token" || currAccData.VerifyStatus == "expired" { currAccData.UserID = 0 utils.ResponseFAIL(c, 401, models.Exception{Unauthorized: true, Message: "Your session is expired, Please re-Login!"}) diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/authentication_payload_model.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/authentication_payload_model.go index 0203b9b340d066705491edf66830674602f89655..41f31eb02e14a1ad1e3b6cf372a69dd91deb12b8 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/authentication_payload_model.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/authentication_payload_model.go @@ -1,7 +1,7 @@ package models type AccountData struct { - UserID int + UserID uint VerifyStatus string ErrVerif error } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/custom_claim.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/custom_claim.go new file mode 100644 index 0000000000000000000000000000000000000000..858c6b95b7c9bc880b5d163dd4469b129e9355cf --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/custom_claim.go @@ -0,0 +1,8 @@ +package models + +import "github.com/golang-jwt/jwt/v5" + +type CustomClaims struct { + jwt.RegisteredClaims + UserID uint `json:"id"` +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/response_model.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/response_model.go index c45df0dbc642de90cc3537722b359a2f09a06b02..7e049aac3f7c5a196f9a54ce924b5424f5986553 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/response_model.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/response_model.go @@ -13,6 +13,7 @@ type ErrorResponse struct { Errors Exception `json:"errors"` MetaData any `json:"meta_data"` } + type AuthenticatedUser struct { Account Account `json:"account"` Token string `json:"token"` diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/account_repository.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/account_repository.go index d56c1262ec89f2dabee886d89b3fb5b67a41b797..686ccc92e7a56587581e345bbb3dca284fb1d7da 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/account_repository.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/account_repository.go @@ -17,9 +17,9 @@ func GetAccountbyEmail(email string) Repository[models.Account, models.Account] return *repo } -func GetAccountbyId(account_id uint) Repository[models.Account, models.Account] { +func GetAccountById(accountId uint) Repository[models.Account, models.Account] { repo := Construct[models.Account, models.Account]( - models.Account{Id: account_id}, + models.Account{Id: accountId}, ) repo.Transactions( WhereGivenConstructor[models.Account, models.Account], @@ -27,6 +27,7 @@ func GetAccountbyId(account_id uint) Repository[models.Account, models.Account] ) return *repo } + func UpdateAccount(account models.Account) Repository[models.Account, models.Account] { repo := Construct[models.Account, models.Account]( account, @@ -34,17 +35,20 @@ func UpdateAccount(account models.Account) Repository[models.Account, models.Acc Update(repo) return *repo } -func GetAccountDetailsbyId(account_id uint) Repository[models.AccountDetails, models.AccountDetails] { + +func GetDetailAccountById(accountId uint) Repository[models.AccountDetails, models.AccountDetails] { repo := Construct[models.AccountDetails, models.AccountDetails]( - models.AccountDetails{AccountID: account_id}, + models.AccountDetails{AccountID: accountId}, ) - fmt.Println("Account ID:", repo.Constructor.AccountID) + + // fmt.Println("Account ID:", repo.Constructor.AccountID) repo.Transactions( WhereGivenConstructor[models.AccountDetails, models.AccountDetails], Find[models.AccountDetails, models.AccountDetails], ) return *repo } + func CreateAccount(account models.Account) Repository[models.Account, models.Account] { repo := Construct[models.Account, models.Account]( account, @@ -52,6 +56,7 @@ func CreateAccount(account models.Account) Repository[models.Account, models.Acc Create(repo) return *repo } + func CreateAccountDetails(accountDetails models.AccountDetails) Repository[models.AccountDetails, models.AccountDetails] { repo := Construct[models.AccountDetails, models.AccountDetails]( accountDetails, @@ -61,6 +66,7 @@ func CreateAccountDetails(accountDetails models.AccountDetails) Repository[model Create(repo) return *repo } + func UpdateAccountDetails(accountDetails models.AccountDetails) Repository[models.AccountDetails, models.AccountDetails] { repo := Construct[models.AccountDetails, models.AccountDetails]( accountDetails, diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/email_verification_repository.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/email_verification_repository.go index c737e6d4b782e17630568f3616f0bf7ef36dc31f..0072ea0952f85bc719bf4bd0d1cf90e6a7270870 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/email_verification_repository.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/email_verification_repository.go @@ -19,10 +19,10 @@ func CreateEmailVerification(accountId uint, dueTime time.Time, token uint) Repo return *repo } -func GetEmailVerification(account_id uint, token uint) Repository[models.EmailVerification, models.EmailVerification] { +func GetEmailVerification(accountId uint, token uint) Repository[models.EmailVerification, models.EmailVerification] { repo := Construct[models.EmailVerification, models.EmailVerification]( models.EmailVerification{ - AccountID: account_id, + AccountID: accountId, IsExpired: false, Token: token, }, diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/repository.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/repository.go index 0ad72d912c734386edc16a3fe9d74465b2352382..0c6b1ee5c41b63f4414e7013717d7fbd58a7dbf4 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/repository.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/repository.go @@ -48,6 +48,7 @@ func Construct[TConstructor any, TResult any](constructor ...TConstructor) *Repo Transaction: config.DB.Begin(), } } + func (repo *Repository[T1, T2]) Transactions(transactions ...func(*Repository[T1, T2]) *gorm.DB) { for _, tx := range transactions { repo.Transaction = tx(repo) @@ -56,6 +57,7 @@ func (repo *Repository[T1, T2]) Transactions(transactions ...func(*Repository[T1 } } } + func WhereGivenConstructor[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB { tx := repo.Transaction.Where(&repo.Constructor) repo.RowsCount = int(tx.RowsAffected) @@ -63,6 +65,7 @@ func WhereGivenConstructor[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB { repo.RowsError = tx.Error return tx } + func Find[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB { tx := repo.Transaction.Find(&repo.Result) repo.RowsCount = int(tx.RowsAffected) diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/auth_route.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/auth_route.go new file mode 100644 index 0000000000000000000000000000000000000000..4bd0d347f3705976e9973248b50103893c3f603e --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/auth_route.go @@ -0,0 +1,18 @@ +package router + +import ( + AuthController "api.qobiltu.id/controller/auth" + "api.qobiltu.id/middleware" + "github.com/gin-gonic/gin" +) + +func AuthRoute(router *gin.Engine) { + routerGroup := router.Group("/api/v1/auth") + { + routerGroup.POST("/login", AuthController.Login) + routerGroup.POST("/register", AuthController.Register) + routerGroup.GET("/me", middleware.AuthUser, AuthController.Profile) + routerGroup.PUT("/me", middleware.AuthUser, AuthController.UpdateProfile) + routerGroup.PUT("/change-password", middleware.AuthUser, AuthController.ChangePassword) + } +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/jwt_service.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/jwt_service.go index 92024df8afa7fe83da747bddc969cc1066cf431c..3fdce4e4735d65dabdd71357a6d915f07219ddfb 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/jwt_service.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/jwt_service.go @@ -2,11 +2,12 @@ package services import ( "errors" + "strings" "time" "api.qobiltu.id/config" "api.qobiltu.id/models" - "github.com/dgrijalva/jwt-go" + "github.com/golang-jwt/jwt/v5" "golang.org/x/crypto/bcrypt" ) @@ -14,22 +15,56 @@ var salt = config.Salt var secretKey = []byte(salt) func GenerateToken(user *models.Account) (string, error) { + claims := models.CustomClaims{ + UserID: user.Id, + RegisteredClaims: jwt.RegisteredClaims{ + ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Hour * 24)), // Token berlaku 24 jam + IssuedAt: jwt.NewNumericDate(time.Now()), + Issuer: "qobiltu.id", + }, + } + + // Buat token dengan metode signing + token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims) + return token.SignedString(secretKey) +} + +func ExtractBearerToken(authHeader string) (string, error) { + parts := strings.Split(authHeader, " ") + if len(parts) != 2 || parts[0] != "Bearer" { + return "", errors.New("invalid authorization header format") + } + return parts[1], nil +} - // Create a new token - token := jwt.New(jwt.SigningMethodHS256) +func VerifyToken(bearerToken string) (uint, string, error) { + // fmt.Println("bearerToken :", bearerToken) - // Set claims - claims := token.Claims.(jwt.MapClaims) - claims["id"] = user.Id - claims["exp"] = time.Now().Add(time.Hour * 24).Unix() // Token expires in 24 hours + tokenData, err := ExtractBearerToken(bearerToken) + if err != nil { + return 0, "invalid-token", err + } else { + // fmt.Println("Extracted Token:", tokenData) + } + + token, err := jwt.ParseWithClaims(tokenData, &models.CustomClaims{}, func(token *jwt.Token) (interface{}, error) { + return secretKey, nil + }) - // Sign the token with the secret key - tokenString, err := token.SignedString(secretKey) if err != nil { - return "", err + return 0, "invalid-token", err + } + + // Extract the claims + claims, ok := token.Claims.(*models.CustomClaims) + if !ok || !token.Valid { + return 0, "invalid-token", err + } + if claims.ExpiresAt != nil && claims.ExpiresAt.Time.Before(time.Now()) { + return 0, "expired", err } - return tokenString, nil + return claims.UserID, "valid", err } func VerifyPassword(hashedPassword, password string) error { diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/user_change_password_controller.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/user_change_password_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..80aa4ac00b85babbbbbcab4de6c7d1fa3514ea6a --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/user_change_password_controller.go @@ -0,0 +1,21 @@ +package user + +import ( + "api.qobiltu.id/controller" + "api.qobiltu.id/models" + "api.qobiltu.id/services" + "github.com/gin-gonic/gin" +) + +func ChangePassword(c *gin.Context) { + authentication := services.AuthenticationService{} + changePasswordController := controller.Controller[models.ChangePasswordRequest, models.Account, models.AuthenticatedUser]{ + Service: &authentication.Service, + } + changePasswordController.HeaderParse(c, func() { + changePasswordController.Service.Constructor.Id = uint(changePasswordController.AccountData.UserID) + }) + changePasswordController.RequestJSON(c, func() { + authentication.Update(changePasswordController.Request.OldPassword, changePasswordController.Request.NewPassword) + }) +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/user_login_controller.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/user_login_controller.go index b7b9673901e26d2dca8bff51c4fdf834eef30646..679fc5a018d75e815dea00cca2012d5d56034eed 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/user_login_controller.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/user_login_controller.go @@ -9,7 +9,7 @@ import ( func Login(c *gin.Context) { authentication := services.AuthenticationService{} - loginController := controller.Controller[models.LoginRequest, services.LoginConstructor, models.AuthenticatedUser]{ + loginController := controller.Controller[models.LoginRequest, models.Account, models.AuthenticatedUser]{ Service: &authentication.Service, } loginController.RequestJSON(c, func() { diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/user_profile_controller.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/user_profile_controller.go index 177520bc297345eaaf66099fe9a71efb8e53b5c5..f30ee7177fa8bd15be000bcfe941ceb2732a74c1 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/user_profile_controller.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/user_profile_controller.go @@ -1,8 +1,6 @@ package user import ( - "fmt" - "api.qobiltu.id/controller" "api.qobiltu.id/models" "api.qobiltu.id/services" @@ -11,12 +9,11 @@ import ( func Profile(c *gin.Context) { userProfile := services.UserProfileService{} - userProfileController := controller.Controller[any, services.UserProfileConstructor, models.Account]{ + userProfileController := controller.Controller[any, models.AccountDetails, models.AccountDetails]{ Service: &userProfile.Service, } - fmt.Println(userProfileController.AccountData) userProfileController.HeaderParse(c, func() { - userProfileController.Service.Constructor.AccountId = userProfileController.AccountData.UserID + userProfileController.Service.Constructor.AccountID = uint(userProfileController.AccountData.UserID) userProfile.Retrieve() userProfileController.Response(c) }, diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/user_update_profile_controller.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/user_update_profile_controller.go index 64072242e2eea309c68624c2b86ad02b3596095b..4821ed13bbf913726e6512251db3bf43728a8a19 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/user_update_profile_controller.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/user_update_profile_controller.go @@ -1,8 +1,6 @@ package user import ( - "fmt" - "api.qobiltu.id/controller" "api.qobiltu.id/models" "api.qobiltu.id/services" @@ -11,14 +9,16 @@ import ( func UpdateProfile(c *gin.Context) { userProfile := services.UserProfileService{} - userUpdateProfileController := controller.Controller[any, services.UserProfileConstructor, models.Account]{ + userUpdateProfileController := controller.Controller[models.AccountDetails, models.AccountDetails, models.AccountDetails]{ Service: &userProfile.Service, } - fmt.Println(userUpdateProfileController.AccountData) - userUpdateProfileController.HeaderParse(c, func() { - userUpdateProfileController.Service.Constructor.AccountId = userUpdateProfileController.AccountData.UserID - userProfile.Retrieve() - userUpdateProfileController.Response(c) + + userUpdateProfileController.RequestJSON(c, func() { + userUpdateProfileController.Service.Constructor = userUpdateProfileController.Request + userUpdateProfileController.HeaderParse(c, func() { + userUpdateProfileController.Service.Constructor.AccountID = uint(userUpdateProfileController.AccountData.UserID) + }) + userProfile.Update() }, ) } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/logserror_log.txt b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/logserror_log.txt index 30ecdec40a51b2cc4d2181b7108e953e7c77166f..58309e5256ae56f8b8feef85a64e685cfdc86000 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/logserror_log.txt +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/logserror_log.txt @@ -1 +1,3 @@ 2025/03/18 21:08:07 Error Log : ERROR: relasi « email_verifications » tidak ada (SQLSTATE 42P01) +2025/03/22 14:00:34 Error Log : duplicated key not allowed +2025/03/22 16:57:13 Error Log : ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification (SQLSTATE 42P10) diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/request_model.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/request_model.go index bb4170dfd5e176800d18a19e52ba8feb55531b1d..dfb4bfd35cd08440c3d106dd517a1821d90460c8 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/request_model.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/request_model.go @@ -14,5 +14,9 @@ type RegisterRequest struct { type CreateEmailVerificationRequest struct { AccountID int `json:"account_id" binding:"required"` +} +type ChangePasswordRequest struct { + OldPassword string `json:"old_password" binding:"required" ` + NewPassword string `json:"new_password" binding:"required" ` } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/account_repository.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/account_repository.go index ef028bd358dd2e0f419ad4cbbad7eb3769fb1477..d56c1262ec89f2dabee886d89b3fb5b67a41b797 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/account_repository.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/account_repository.go @@ -1,6 +1,8 @@ package repositories import ( + "fmt" + "api.qobiltu.id/models" ) @@ -25,6 +27,24 @@ func GetAccountbyId(account_id uint) Repository[models.Account, models.Account] ) return *repo } +func UpdateAccount(account models.Account) Repository[models.Account, models.Account] { + repo := Construct[models.Account, models.Account]( + account, + ) + Update(repo) + return *repo +} +func GetAccountDetailsbyId(account_id uint) Repository[models.AccountDetails, models.AccountDetails] { + repo := Construct[models.AccountDetails, models.AccountDetails]( + models.AccountDetails{AccountID: account_id}, + ) + fmt.Println("Account ID:", repo.Constructor.AccountID) + repo.Transactions( + WhereGivenConstructor[models.AccountDetails, models.AccountDetails], + Find[models.AccountDetails, models.AccountDetails], + ) + return *repo +} func CreateAccount(account models.Account) Repository[models.Account, models.Account] { repo := Construct[models.Account, models.Account]( account, @@ -32,7 +52,21 @@ func CreateAccount(account models.Account) Repository[models.Account, models.Acc Create(repo) return *repo } - -// func UpdateAccount(account models.Account) Repository[models.Account, models.Account] { -// repo := Construct -// } +func CreateAccountDetails(accountDetails models.AccountDetails) Repository[models.AccountDetails, models.AccountDetails] { + repo := Construct[models.AccountDetails, models.AccountDetails]( + accountDetails, + ) + fmt.Println(accountDetails) + fmt.Println("Account ID : ", accountDetails.AccountID) + Create(repo) + return *repo +} +func UpdateAccountDetails(accountDetails models.AccountDetails) Repository[models.AccountDetails, models.AccountDetails] { + repo := Construct[models.AccountDetails, models.AccountDetails]( + accountDetails, + ) + fmt.Println(accountDetails) + fmt.Println("Account ID : ", accountDetails.AccountID) + Update(repo) + return *repo +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/repository.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/repository.go index 3617e40936bf9e50e39a50285105622f080d210f..0ad72d912c734386edc16a3fe9d74465b2352382 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/repository.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/repository.go @@ -93,6 +93,7 @@ func Update[T1 any](repo *Repository[T1, T1]) *gorm.DB { repo.RowsCount = int(tx.RowsAffected) repo.NoRecord = repo.RowsCount == 0 repo.RowsError = tx.Error + repo.Result = repo.Constructor return tx } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/user_route.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/user_route.go index c1abce045debeff19dabe5af38b9903abd5083a0..1e5f9e405b0d936a86aed41c552cd8030fdc12bb 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/user_route.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/user_route.go @@ -12,5 +12,7 @@ func UserRoute(router *gin.Engine) { routerGroup.POST("/login", UserController.Login) routerGroup.POST("/register", UserController.Register) routerGroup.GET("/me", middleware.AuthUser, UserController.Profile) + routerGroup.PUT("/me", middleware.AuthUser, UserController.UpdateProfile) + routerGroup.PUT("/change-password", middleware.AuthUser, UserController.ChangePassword) } } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/authentication_service.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/authentication_service.go new file mode 100644 index 0000000000000000000000000000000000000000..22a82cb0fe7042139cfa992ca4ac35bfcc9b4490 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/authentication_service.go @@ -0,0 +1,71 @@ +package services + +import ( + "errors" + "fmt" + + "api.qobiltu.id/models" + "api.qobiltu.id/repositories" +) + +type AuthenticationService struct { + Service[models.Account, models.AuthenticatedUser] +} + +func (s *AuthenticationService) Authenticate() { + accountData := repositories.GetAccountbyEmail(s.Constructor.Email) + if accountData.NoRecord { + s.Exception.DataNotFound = true + s.Exception.Message = "there is no account with given credentials!" + return + } + if VerifyPassword(accountData.Result.Password, s.Constructor.Password) != nil { + s.Exception.Unauthorized = true + s.Exception.Message = "incorrect password!" + return + } + + token, err_tok := GenerateToken(&accountData.Result) + + if err_tok != nil { + s.Error = errors.Join(s.Error, err_tok) + } + + accountData.Result.Password = "SECRET" + s.Result = models.AuthenticatedUser{ + Account: accountData.Result, + Token: token, + } + s.Error = accountData.RowsError +} + +func (s *AuthenticationService) Update(oldPassword string, newPassword string) { + if len(newPassword) < 8 { + s.Exception.InvalidPasswordLength = true + s.Exception.Message = "Password must have at least 8 characters!" + return + } + accountData := repositories.GetAccountbyId(s.Constructor.Id) + + if accountData.NoRecord { + s.Exception.DataNotFound = true + s.Exception.Message = "there is no account with given credentials!" + return + } + fmt.Println("Result Password", accountData.Result.Password) + fmt.Println("old Password given", oldPassword) + if VerifyPassword(accountData.Result.Password, oldPassword) != nil { + s.Exception.Unauthorized = true + s.Exception.Message = "incorrect old password!" + return + } + accountData.Result.Password = newPassword + changePassword := repositories.UpdateAccount(accountData.Result) + changePassword.Result.Password = "SECRET" + s.Result = models.AuthenticatedUser{ + Account: changePassword.Result, + } + s.Error = changePassword.RowsError +} + +// LoginHandler handles user login diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/register_service.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/register_service.go index f9e0d2216bd033155ffcbd73dd1b9de44d20bfa8..4802c35b8bd0a7f5b29214a68fc8f6eb1ea8dfde 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/register_service.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/register_service.go @@ -33,6 +33,13 @@ func (s *RegisterService) Create() { s.Exception.Message = "Bad request!" return } + userProfile := UserProfileService{} + userProfile.Constructor.AccountID = accountCreated.Result.Id + userProfile.Create() + if userProfile.Error != nil { + s.Error = userProfile.Error + return + } s.Error = accountCreated.RowsError s.Result = accountCreated.Result s.Result.Password = "SECRET" diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/user_profile_service.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/user_profile_service.go index afea5ccbf0885293e2f782692e229b6948e2228e..419458a7d1e4845f1e4049bc3c3edabbbef748fb 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/user_profile_service.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/user_profile_service.go @@ -5,33 +5,38 @@ import ( "api.qobiltu.id/repositories" ) -type UserProfileConstructor struct { - AccountId int -} type UserProfileService struct { - Service[UserProfileConstructor, models.Account] + Service[models.AccountDetails, models.AccountDetails] } +func (s *UserProfileService) Create() { + userProfile := repositories.CreateAccountDetails(s.Constructor) + s.Error = userProfile.RowsError + if userProfile.NoRecord { + s.Exception.DataNotFound = true + s.Exception.Message = "There is no account with given credentials!" + return + } + s.Result = userProfile.Result +} func (s *UserProfileService) Retrieve() { - userProfile := repositories.GetAccountbyId(uint(s.Constructor.AccountId)) + userProfile := repositories.GetDetailAccountById(s.Constructor.AccountID) s.Error = userProfile.RowsError if userProfile.NoRecord { s.Exception.DataNotFound = true s.Exception.Message = "There is no account with given credentials!" return } - s.Result.Password = "SECRET" s.Result = userProfile.Result } func (s *UserProfileService) Update() { - userProfile := repositories.GetAccountbyId(uint(s.Constructor.AccountId)) + userProfile := repositories.UpdateAccountDetails(s.Constructor) s.Error = userProfile.RowsError if userProfile.NoRecord { s.Exception.DataNotFound = true s.Exception.Message = "There is no account with given credentials!" return } - s.Result.Password = "SECRET" s.Result = userProfile.Result } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/.github/workflows/main.yml b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/.github/workflows/main.yml index 39a67571ac3a2e6a6e2a972b9550becd551bdded..65c8cabfc8ef2a61bf1694229cb9bf3126a94f4b 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/.github/workflows/main.yml +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/.github/workflows/main.yml @@ -1,4 +1,4 @@ -name: Deploy to Development via Huggingface +name: Deploy Golang App on: push: @@ -6,47 +6,23 @@ on: - main jobs: - deploy-to-huggingface: + deploy: runs-on: ubuntu-latest steps: - # Checkout repository - name: Checkout Repository uses: actions/checkout@v3 - # Setup Git - - name: Setup Git for Huggingface - run: | - git config --global user.email "abdan.hafidz@gmail.com" - git config --global user.name "abdanhafidz" - - # Clone Huggingface Space Repository - - name: Clone Huggingface Space - env: - HF_TOKEN: ${{ secrets.HF_TOKEN }} - run: | - git clone https://huggingface.co/spaces/lifedebugger/api-qobiltu-dev space - - # Update Git Remote URL and Pull Latest Changes - - name: Update Remote and Pull Changes - env: - HF_TOKEN: ${{ secrets.HF_TOKEN }} - run: | - cd space - git remote set-url origin https://lifedebugger:$HF_TOKEN@huggingface.co/spaces/lifedebugger/api-qobiltu-dev - git pull origin main || echo "No changes to pull" - - # Copy Files to Huggingface Space - - name: Copy Files to Space - run: | - rsync -av --exclude='.git' ./ space/ + - name: Set up SSH key + uses: webfactory/ssh-agent@v0.5.4 + with: + ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} - # Commit and Push to Huggingface Space - - name: Commit and Push to Huggingface - env: - HF_TOKEN: ${{ secrets.HF_TOKEN }} + - name: Deploy to VPS run: | - cd space - git add . - git commit -m "Deploy files from GitHub repository" || echo "No changes to commit" - git push origin main || echo "No changes to push" + ssh -o StrictHostKeyChecking=no qobiltu@103.23.199.136 << 'EOF' + cd /home/qobiltu/api-qobiltu + git pull origin main + docker-compose down -v + docker-compose up --build -d + EOF diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/.github/workflows/main_huggingface.yml b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/.github/workflows/main_huggingface.yml new file mode 100644 index 0000000000000000000000000000000000000000..39a67571ac3a2e6a6e2a972b9550becd551bdded --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/.github/workflows/main_huggingface.yml @@ -0,0 +1,52 @@ +name: Deploy to Development via Huggingface + +on: + push: + branches: + - main + +jobs: + deploy-to-huggingface: + runs-on: ubuntu-latest + + steps: + # Checkout repository + - name: Checkout Repository + uses: actions/checkout@v3 + + # Setup Git + - name: Setup Git for Huggingface + run: | + git config --global user.email "abdan.hafidz@gmail.com" + git config --global user.name "abdanhafidz" + + # Clone Huggingface Space Repository + - name: Clone Huggingface Space + env: + HF_TOKEN: ${{ secrets.HF_TOKEN }} + run: | + git clone https://huggingface.co/spaces/lifedebugger/api-qobiltu-dev space + + # Update Git Remote URL and Pull Latest Changes + - name: Update Remote and Pull Changes + env: + HF_TOKEN: ${{ secrets.HF_TOKEN }} + run: | + cd space + git remote set-url origin https://lifedebugger:$HF_TOKEN@huggingface.co/spaces/lifedebugger/api-qobiltu-dev + git pull origin main || echo "No changes to pull" + + # Copy Files to Huggingface Space + - name: Copy Files to Space + run: | + rsync -av --exclude='.git' ./ space/ + + # Commit and Push to Huggingface Space + - name: Commit and Push to Huggingface + env: + HF_TOKEN: ${{ secrets.HF_TOKEN }} + run: | + cd space + git add . + git commit -m "Deploy files from GitHub repository" || echo "No changes to commit" + git push origin main || echo "No changes to push" diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/Dockerfile b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/Dockerfile index 6183c94745bf456bad5ea308482bd6c3602ad543..d7d9de6f6ae86a458866ad773e9886db45197e9b 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/Dockerfile +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/Dockerfile @@ -1,30 +1,37 @@ -# Gunakan image dasar Golang versi 1.21.6 -FROM golang:1.21.6 - -# Set working directory -WORKDIR /app - -# Copy go.mod dan go.sum -COPY go.mod go.sum ./ - -# Download dependencies -RUN go mod download - -# Copy seluruh kode -COPY . . - -# Buat file .env dengan variabel environment yang dibutuhkan -RUN echo "DB_HOST=aws-0-ap-southeast-1.pooler.supabase.com" >> .env && \ - echo "DB_USER=postgres.rdscploxoikqsevhduii" >> .env && \ - echo "DB_PASSWORD=Qobiltu12233334444" >> .env && \ - echo "DB_PORT=5432" >> .env && \ - echo "DB_NAME=postgres" >> .env && \ - echo "HOST_ADDRESS = 0.0.0.0" >> .env && \ - echo "HOST_PORT = 7860" >> .env && \ - echo "SALT=NZNZtY7dNPz8l0dWINJZLKafWaJrql1s" >> .env && \ - echo "LOG_PATH = logs" >> .env -# Build aplikasi -RUN go build -o main . - -# Jalankan aplikasi -CMD ["./main"] +# Gunakan image dasar Golang versi 1.24.1 +FROM golang:1.24.1 AS builder + +# Set working directory +WORKDIR /app + +# Copy go.mod dan go.sum +COPY go.mod go.sum ./ + +# Download dependencies +RUN go mod download + +# Copy seluruh kode +COPY . . + +# Build aplikasi +# RUN go build -o /app/main . + +# Build aplikasi untuk Linux +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /app/main . + +# Stage 2: Gunakan image runtime yang lebih kecil +FROM alpine:latest + +# Set working directory +WORKDIR /app + +# Copy hasil build dari builder ke image runtime +COPY --from=builder /app/main . + +# Copy file .env untuk konfigurasi environment +COPY .env .env + +RUN chmod +x /app/main + +# Jalankan aplikasi +CMD ["./main"] diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/docker-compose.yml b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/docker-compose.yml new file mode 100644 index 0000000000000000000000000000000000000000..a821c467525af186355b5837f8673e77a84f7563 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/docker-compose.yml @@ -0,0 +1,31 @@ +version: '3.8' + +services: + app: + container_name: api-qobiltu + build: . + depends_on: + - db + env_file: .env + ports: + - "8080:8080" + # volumes: + # - ./logs:/app/logs + # - /home/qobiltu/api-qobiltu:/app + restart: unless-stopped + + db: + image: postgres:15 + container_name: postgres-db + environment: + POSTGRES_USER: ${DB_USER} + POSTGRES_PASSWORD: ${DB_PASSWORD} + POSTGRES_DB: ${DB_NAME} + ports: + - "5432:5432" + volumes: + - db-data:/var/lib/postgresql/data + restart: always + +volumes: + db-data: diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/.gitignore b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/.gitignore index bd10d926e1c503ff128e21bf273fe2732e526abf..df8cf1c15e2917803db7f00fbc386495fe8f5479 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/.gitignore +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/.gitignore @@ -1,4 +1,5 @@ .env vendor/ quzuu-be.exe -README.md \ No newline at end of file +README.md +.qodo diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/config/config.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/config/config.go index 96d88fd641bf8a6b538d1324abff58c8d5b912a0..823888a64fd867db2cee438c8cb64f792ec16920 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/config/config.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/config/config.go @@ -2,6 +2,7 @@ package config import ( "os" + "strconv" "github.com/joho/godotenv" ) @@ -10,6 +11,7 @@ var TCP_ADDRESS string var LOG_PATH string var HOST_ADDRESS string var HOST_PORT string +var EMAIL_VERIFICATION_DURATION int func init() { godotenv.Load() @@ -17,5 +19,6 @@ func init() { HOST_PORT = os.Getenv("HOST_PORT") TCP_ADDRESS = HOST_ADDRESS + ":" + HOST_PORT LOG_PATH = os.Getenv("LOG_PATH") + EMAIL_VERIFICATION_DURATION, _ = strconv.Atoi(os.Getenv("EMAIL_VERIFICATION_DURATION")) // Menampilkan nilai variabel lingkungan } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/config/database_connection_config.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/config/database_connection_config.go index 458388d26dd8408234352e2a835552d6a278f267..3eea63fb7b3d4ffd51970404cadf1af8267c046d 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/config/database_connection_config.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/config/database_connection_config.go @@ -51,7 +51,17 @@ func AutoMigrateAll(db *gorm.DB) { err := db.AutoMigrate( &models.Account{}, &models.AccountDetails{}, + &models.EmailVerification{}, + &models.ExternalAuth{}, + &models.FCM{}, + &models.ForgotPassword{}, + &models.Academy{}, + &models.AcademyMaterial{}, + &models.AcademyContent{}, + &models.AcademyMaterialProgress{}, + &models.AcademyContentProgress{}, ) + if err != nil { log.Fatal(err) } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/controller.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/controller.go index 32a528d703f974515cc1baa4960e87ac56481629..456c424696e845d0f994bd91a43f42623d427045 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/controller.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/controller.go @@ -19,6 +19,13 @@ type ( } ) +func (controller *Controller[T1, T2, T3]) HeaderParse(c *gin.Context, act func()) { + cParam, _ := c.Get("accountData") + if cParam != nil { + controller.AccountData = cParam.(models.AccountData) + } + act() +} func (controller *Controller[T1, T2, T3]) RequestJSON(c *gin.Context, act func()) { cParam, _ := c.Get("accountData") if cParam != nil { diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/email/email_create_verification.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/email/email_create_verification.go new file mode 100644 index 0000000000000000000000000000000000000000..44ee9b005702e30354ef25f46d80e9551dbfcf6b --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/email/email_create_verification.go @@ -0,0 +1,22 @@ +package controller + +import ( + "strconv" + + "api.qobiltu.id/controller" + "api.qobiltu.id/models" + "api.qobiltu.id/services" + "github.com/gin-gonic/gin" +) + +func CreateVerification(c *gin.Context) { + emailVerification := services.EmailVerificationService{} + emailVerificationController := controller.Controller[any, models.EmailVerification, models.EmailVerification]{ + Service: &emailVerification.Service, + } + query, _ := c.GetQuery("account_id") + accountId, _ := strconv.Atoi(query) + emailVerificationController.Service.Constructor.AccountID = uint(accountId) + emailVerification.Create() + emailVerificationController.Response(c) +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/email/email_delete_verification.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/email/email_delete_verification.go new file mode 100644 index 0000000000000000000000000000000000000000..2cd98fbc53a1234cdcbec565d8d42c4247936dd7 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/email/email_delete_verification.go @@ -0,0 +1,22 @@ +package controller + +import ( + "strconv" + + "api.qobiltu.id/controller" + "api.qobiltu.id/models" + "api.qobiltu.id/services" + "github.com/gin-gonic/gin" +) + +func DeleteVerification(c *gin.Context) { + emailVerification := services.EmailVerificationService{} + emailVerificationController := controller.Controller[any, models.EmailVerification, models.EmailVerification]{ + Service: &emailVerification.Service, + } + query, _ := c.GetQuery("account_id") + accountId, _ := strconv.Atoi(query) + emailVerificationController.Service.Constructor.AccountID = uint(accountId) + emailVerification.Delete() + emailVerificationController.Response(c) +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/email/email_verify.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/email/email_verify.go new file mode 100644 index 0000000000000000000000000000000000000000..695bbccdbfbd8dedf63048f8734c4fe879544d33 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/email/email_verify.go @@ -0,0 +1,22 @@ +package controller + +import ( + "strconv" + + "api.qobiltu.id/controller" + "api.qobiltu.id/models" + "api.qobiltu.id/services" + "github.com/gin-gonic/gin" +) + +func Verify(c *gin.Context) { + emailVerification := services.EmailVerificationService{} + emailVerificationController := controller.Controller[any, models.EmailVerification, models.EmailVerification]{ + Service: &emailVerification.Service, + } + query, _ := c.GetQuery("account_id") + accountId, _ := strconv.Atoi(query) + emailVerificationController.Service.Constructor.AccountID = uint(accountId) + emailVerification.Validate() + emailVerificationController.Response(c) +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/user_login_controller.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/user_login_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..b7b9673901e26d2dca8bff51c4fdf834eef30646 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/user_login_controller.go @@ -0,0 +1,20 @@ +package user + +import ( + "api.qobiltu.id/controller" + "api.qobiltu.id/models" + "api.qobiltu.id/services" + "github.com/gin-gonic/gin" +) + +func Login(c *gin.Context) { + authentication := services.AuthenticationService{} + loginController := controller.Controller[models.LoginRequest, services.LoginConstructor, models.AuthenticatedUser]{ + Service: &authentication.Service, + } + loginController.RequestJSON(c, func() { + loginController.Service.Constructor.Email = loginController.Request.Email + loginController.Service.Constructor.Password = loginController.Request.Password + authentication.Authenticate() + }) +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/user_profile_controller.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/user_profile_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..177520bc297345eaaf66099fe9a71efb8e53b5c5 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/user_profile_controller.go @@ -0,0 +1,24 @@ +package user + +import ( + "fmt" + + "api.qobiltu.id/controller" + "api.qobiltu.id/models" + "api.qobiltu.id/services" + "github.com/gin-gonic/gin" +) + +func Profile(c *gin.Context) { + userProfile := services.UserProfileService{} + userProfileController := controller.Controller[any, services.UserProfileConstructor, models.Account]{ + Service: &userProfile.Service, + } + fmt.Println(userProfileController.AccountData) + userProfileController.HeaderParse(c, func() { + userProfileController.Service.Constructor.AccountId = userProfileController.AccountData.UserID + userProfile.Retrieve() + userProfileController.Response(c) + }, + ) +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/user_register_controller.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/user_register_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..17051bee42f7b1d3fe144cedb6e8f11dbb5ac5b2 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/user_register_controller.go @@ -0,0 +1,20 @@ +package user + +import ( + "api.qobiltu.id/controller" + "api.qobiltu.id/models" + "api.qobiltu.id/services" + "github.com/gin-gonic/gin" +) + +func Register(c *gin.Context) { + register := services.RegisterService{} + registerController := controller.Controller[models.RegisterRequest, models.Account, models.Account]{ + Service: ®ister.Service, + } + registerController.RequestJSON(c, func() { + registerController.Service.Constructor.Password = registerController.Request.Password + registerController.Service.Constructor.Email = registerController.Request.Email + register.Create() + }) +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/user_update_profile_controller.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/user_update_profile_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..64072242e2eea309c68624c2b86ad02b3596095b --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/user/user_update_profile_controller.go @@ -0,0 +1,24 @@ +package user + +import ( + "fmt" + + "api.qobiltu.id/controller" + "api.qobiltu.id/models" + "api.qobiltu.id/services" + "github.com/gin-gonic/gin" +) + +func UpdateProfile(c *gin.Context) { + userProfile := services.UserProfileService{} + userUpdateProfileController := controller.Controller[any, services.UserProfileConstructor, models.Account]{ + Service: &userProfile.Service, + } + fmt.Println(userUpdateProfileController.AccountData) + userUpdateProfileController.HeaderParse(c, func() { + userUpdateProfileController.Service.Constructor.AccountId = userUpdateProfileController.AccountData.UserID + userProfile.Retrieve() + userUpdateProfileController.Response(c) + }, + ) +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/docker-compose.yaml b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/docker-compose.yaml new file mode 100644 index 0000000000000000000000000000000000000000..daf0d5d58dca553ce0c035978ec48d8d4fe52456 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/docker-compose.yaml @@ -0,0 +1,10 @@ +services: + postgres: + container_name: postgres + image: postgres + environment: + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=password + - POSTGRES_DB=qobiltu + ports: + - 5432:5432 diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.mod b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.mod index 9b6fd06b10d941bc76ba173ba5f2983e9c1408d8..0c2b7a92ff9c9eddbfa0d1506ccb9b4d0614163e 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.mod +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.mod @@ -3,6 +3,7 @@ module api.qobiltu.id go 1.24.0 require ( + github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/gin-gonic/gin v1.10.0 github.com/golang-jwt/jwt/v5 v5.2.1 github.com/joho/godotenv v1.5.1 @@ -46,4 +47,4 @@ require ( golang.org/x/text v0.23.0 // indirect google.golang.org/protobuf v1.36.5 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect -) \ No newline at end of file +) diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.sum b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.sum index 6f39995754d2f66f294c1866a62d1810e8d524c5..b7d196affb731541ab18f7ba85fbb21dd47867ac 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.sum +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.sum @@ -10,6 +10,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= +github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM= github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8= github.com/gin-contrib/sse v1.0.0 h1:y3bT1mUWUxDpW4JLQg/HnTqV4rozuW4tC9eFKTxYI9E= @@ -115,4 +117,4 @@ gorm.io/driver/postgres v1.5.11 h1:ubBVAfbKEUld/twyKZ0IYn9rSQh448EdelLYk9Mv314= gorm.io/driver/postgres v1.5.11/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI= gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8= gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ= -nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= \ No newline at end of file +nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/logserror_log.txt b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/logserror_log.txt new file mode 100644 index 0000000000000000000000000000000000000000..30ecdec40a51b2cc4d2181b7108e953e7c77166f --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/logserror_log.txt @@ -0,0 +1 @@ +2025/03/18 21:08:07 Error Log : ERROR: relasi « email_verifications » tidak ada (SQLSTATE 42P01) diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/authentication_middleware.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/authentication_middleware.go index 44178a96738817742fd4f6f7fe1ca63bbecc2d27..41ed5f2fb2eefa1f43c991f2f502d39505c76e3b 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/authentication_middleware.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/authentication_middleware.go @@ -3,52 +3,19 @@ package middleware import ( - "errors" "time" "api.qobiltu.id/config" "api.qobiltu.id/models" + "api.qobiltu.id/utils" "github.com/gin-gonic/gin" "github.com/golang-jwt/jwt/v5" - "golang.org/x/crypto/bcrypt" ) -// Define a secret key for signing the JWT token var salt = config.Salt var secretKey = []byte(salt) -// GenerateToken generates a JWT token for the given user -func GenerateToken(user *models.Account) (string, error) { - - // Create a new token - token := jwt.New(jwt.SigningMethodHS256) - - // Set claims - claims := token.Claims.(jwt.MapClaims) - claims["id"] = user.Id - claims["exp"] = time.Now().Add(time.Hour * 24).Unix() // Token expires in 24 hours - - // Sign the token with the secret key - tokenString, err := token.SignedString(secretKey) - if err != nil { - return "", err - } - - return tokenString, nil -} - // VerifyPassword verifies if the provided password matches the hashed password -func VerifyPassword(hashedPassword, password string) error { - err := bcrypt.CompareHashAndPassword([]byte(hashedPassword), []byte(password)) - if err != nil { - return errors.New("invalid password") - } - return nil -} -func HashPassword(password string) (string, error) { - bytes, err := bcrypt.GenerateFromPassword([]byte(password), 14) - return string(bytes), err -} type CustomClaims struct { jwt.RegisteredClaims @@ -84,21 +51,20 @@ func AuthUser(c *gin.Context) { // fmt.Println("Verify Status :", currAccData.verifyStatus) if currAccData.VerifyStatus == "invalid-token" || currAccData.VerifyStatus == "expired" { currAccData.UserID = 0 - message := "Your session is expired, Please re-Login!" - SendJSON401(c, &currAccData.VerifyStatus, &message) + utils.ResponseFAIL(c, 401, models.Exception{Unauthorized: true, Message: "Your session is expired, Please re-Login!"}) c.Abort() return + } else { + c.Set("accountData", currAccData) + c.Next() } } else { currAccData.UserID = 0 currAccData.VerifyStatus = "no-token" currAccData.ErrVerif = nil - message := "You have to Login First!" - SendJSON401(c, &currAccData.VerifyStatus, &message) + utils.ResponseFAIL(c, 401, models.Exception{Unauthorized: true, Message: "You have to login first!"}) c.Abort() return } - c.Set("accountData", currAccData) - c.Next() } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/response_middleware.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/response_middleware.go index 55f3385077839115eadb8dace294229f4b4c3df2..d52391cd3607e6ec2697e6a5813b348d49ff5ee2 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/response_middleware.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/response_middleware.go @@ -9,31 +9,37 @@ import ( // SendJSON200 sends a JSON response with HTTP status code 200 func SendJSON200(c *gin.Context, data interface{}) { c.JSON(http.StatusOK, gin.H{"status": "success", "data": data}) + return } // SendJSON400 sends a JSON response with HTTP status code 400 func SendJSON400(c *gin.Context, error_status *string, message *string) { c.JSON(http.StatusBadRequest, gin.H{"status": "error", "error-status": error_status, "message": message}) + return } // SendJSON401 sends a JSON response with HTTP status code 401 func SendJSON401(c *gin.Context, error_status *string, message *string) { c.JSON(http.StatusUnauthorized, gin.H{"status": "error", "error-status": error_status, "message": message}) + return } // SendJSON403 sends a JSON response with HTTP status code 403 func SendJSON403(c *gin.Context, message *string) { c.JSON(http.StatusForbidden, gin.H{"status": "error", "message": message}) + return } // SendJSON404 sends a JSON response with HTTP status code 404 func SendJSON404(c *gin.Context, message *string) { c.JSON(http.StatusNotFound, gin.H{"status": "error", "message": message}) + return } // SendJSON500 sends a JSON response with HTTP status code 500 func SendJSON500(c *gin.Context, error_status *string, message *string) { c.JSON(http.StatusInternalServerError, gin.H{"status": "error", "error-status": error_status, "message": message}) + return } // JSONResponseMiddleware is a middleware that provides functions for sending JSON responses diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/database_orm_model.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/database_orm_model.go index 82e8b95b39b86be5fb0a4ce538d697e9df8fd0d5..6d1cb93a61de13e3ae0f178cc701c77ed791ae7a 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/database_orm_model.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/database_orm_model.go @@ -7,25 +7,113 @@ import ( ) type Account struct { - Id uint `gorm:"primaryKey" json:"id"` - UUID uuid.UUID `gorm:"type:uuid" json:"uuid" ` - Email string `gorm:"uniqueIndex" json:"email"` - Password string `json:"password"` - IsEmailVerified bool `json:"is_email_verified"` - CreatedAt time.Time `json:"created_at"` - DeletedAt time.Time `json:"deleted_at"` + Id uint `gorm:"primaryKey" json:"id"` + UUID uuid.UUID `gorm:"type:uuid" json:"uuid" ` + Email string `gorm:"uniqueIndex" json:"email"` + Password string `json:"password"` + IsEmailVerified bool `json:"is_email_verified"` + IsDetailCompleted bool `json:"is_detail_completed"` + CreatedAt time.Time `json:"created_at"` + DeletedAt *time.Time `json:"deleted_at,omitempty" gorm:"default:null"` } type AccountDetails struct { - IDDetail uint `gorm:"primaryKey" json:"id_detail"` - Account_id uint `json:"id_account"` - Province string `json:"province"` - City string `json:"city"` - Institution string `json:"institution"` - UpdatedAt time.Time `json:"updated_at"` - DeletedAt time.Time `json:"deleted_at"` + ID uint `gorm:"primaryKey" json:"id"` + AccountID uint `json:"account_id"` + InitialName string `json:"initial_name"` + FullName *string `json:"full_name,omitempty"` + DateOfBirth *time.Time `json:"date_of_birth,omitempty"` + PlaceOfBirth *string `json:"place_of_birth,omitempty"` + Domicile *string `json:"domicile,omitempty"` + LastJob *string `json:"last_job,omitempty"` + Gender *bool `json:"gender,omitempty"` + LastEducation *string `json:"last_education,omitempty"` + MaritalStatus *bool `json:"marital_status,omitempty"` + Avatar *string `json:"avatar,omitempty"` + PhoneNumber *uint `json:"phone_number,omitempty"` +} + +type EmailVerification struct { + ID uint `gorm:"primaryKey" json:"id"` + Token uint `json:"token"` + AccountID uint `json:"account_id"` + IsExpired bool `json:"is_expired"` + CreatedAt time.Time `json:"created_at"` + ExpiredAt time.Time `json:"expired_at"` +} + +type ExternalAuth struct { + ID uint `gorm:"primaryKey" json:"id"` + OauthID string `json:"oauth_id"` + AccountID uint `json:"account_id"` + OauthProvider string `json:"oauth_provider"` +} + +type FCM struct { + ID uint `gorm:"primaryKey" json:"id"` + AccountID uint `json:"account_id"` + FCMToken string `json:"fcm_token"` +} + +type ForgotPassword struct { + ID uint `gorm:"primaryKey" json:"id"` + UUID uint `json:"uuid"` + AccountID uint `json:"account_id"` + IsExpired bool `json:"is_expired"` + CreatedAt time.Time `json:"created_at"` + ExpiredAt time.Time `json:"expired_at"` +} + +type Academy struct { + ID uint `gorm:"primaryKey" json:"id"` + UUID uuid.UUID `gorm:"type:uuid" json:"uuid"` + Title string `json:"title"` + Slug string `json:"slug"` + Description string `json:"description"` +} + +type AcademyMaterial struct { + ID uint `gorm:"primaryKey" json:"id"` + UUID uuid.UUID `gorm:"type:uuid" json:"uuid"` + AcademyID uint `json:"academy_id"` + Title string `json:"title"` + Slug string `json:"slug"` + Description string `json:"description"` +} + +type AcademyContent struct { + ID uint `gorm:"primaryKey" json:"id"` + UUID uint `json:"uuid"` + Title string `json:"title"` + Order uint `json:"order"` + AcademyMaterialID uint `json:"academy_material_id"` + Description string `json:"description"` +} + +type AcademyMaterialProgress struct { + ID uint `gorm:"primaryKey" json:"id"` + UUID uuid.UUID `gorm:"type:uuid" json:"uuid"` + AccountID uint `json:"account_id"` + AcademyMaterialID uint `json:"academy_material_id"` + Progress uint `json:"progress"` +} + +type AcademyContentProgress struct { + ID uint `gorm:"primaryKey" json:"id"` + UUID uuid.UUID `gorm:"type:uuid" json:"uuid"` + AccountID uint `json:"account_id"` + AcademyID uint `json:"academy_id"` } // Gorm table name settings -func (Account) TableName() string { return "account" } -func (AccountDetails) TableName() string { return "account_details" } +func (Account) TableName() string { return "account" } +func (AccountDetails) TableName() string { return "account_details" } +func (EmailVerification) TableName() string { return "email_verifications" } +func (ExternalAuth) TableName() string { return "extern_auth" } +func (FCM) TableName() string { return "fcm" } +func (ForgotPassword) TableName() string { return "forgot_password" } +func (Academy) TableName() string { return "academy" } +func (AcademyMaterial) TableName() string { return "academy_materials" } +func (AcademyContent) TableName() string { return "academy_contents" } +func (AcademyMaterialProgress) TableName() string { return "academy_materials_progress" } +func (AcademyContentProgress) TableName() string { return "academy_contents_progress" } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/request_model.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/request_model.go index cfae888ec34edbdd3f5b6588050e2b382c63792d..bb4170dfd5e176800d18a19e52ba8feb55531b1d 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/request_model.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/request_model.go @@ -11,3 +11,8 @@ type RegisterRequest struct { Phone int `json:"phone"` Password string `json:"password" binding:"required"` } + +type CreateEmailVerificationRequest struct { + AccountID int `json:"account_id" binding:"required"` + +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/account_repository.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/account_repository.go index 41bd903aff7bf12c9d81cbed1ad00521ae629640..ef028bd358dd2e0f419ad4cbbad7eb3769fb1477 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/account_repository.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/account_repository.go @@ -15,6 +15,16 @@ func GetAccountbyEmail(email string) Repository[models.Account, models.Account] return *repo } +func GetAccountbyId(account_id uint) Repository[models.Account, models.Account] { + repo := Construct[models.Account, models.Account]( + models.Account{Id: account_id}, + ) + repo.Transactions( + WhereGivenConstructor[models.Account, models.Account], + Find[models.Account, models.Account], + ) + return *repo +} func CreateAccount(account models.Account) Repository[models.Account, models.Account] { repo := Construct[models.Account, models.Account]( account, @@ -22,3 +32,7 @@ func CreateAccount(account models.Account) Repository[models.Account, models.Acc Create(repo) return *repo } + +// func UpdateAccount(account models.Account) Repository[models.Account, models.Account] { +// repo := Construct +// } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/email_verification_repository.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/email_verification_repository.go new file mode 100644 index 0000000000000000000000000000000000000000..c737e6d4b782e17630568f3616f0bf7ef36dc31f --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/email_verification_repository.go @@ -0,0 +1,49 @@ +package repositories + +import ( + "time" + + "api.qobiltu.id/models" +) + +func CreateEmailVerification(accountId uint, dueTime time.Time, token uint) Repository[models.EmailVerification, models.EmailVerification] { + repo := Construct[models.EmailVerification, models.EmailVerification]( + models.EmailVerification{ + AccountID: accountId, + IsExpired: false, + ExpiredAt: dueTime, + Token: token, + }, + ) + Create(repo) + return *repo +} + +func GetEmailVerification(account_id uint, token uint) Repository[models.EmailVerification, models.EmailVerification] { + repo := Construct[models.EmailVerification, models.EmailVerification]( + models.EmailVerification{ + AccountID: account_id, + IsExpired: false, + Token: token, + }, + ) + repo.Transactions( + WhereGivenConstructor[models.EmailVerification, models.EmailVerification], + Find[models.EmailVerification, models.EmailVerification], + ) + return *repo +} + +func DeleteEmailVerification(token uint) Repository[models.EmailVerification, models.EmailVerification] { + repo := Construct[models.EmailVerification, models.EmailVerification]( + models.EmailVerification{ + Token: token, + }, + ) + + repo.Transactions( + WhereGivenConstructor[models.EmailVerification, models.EmailVerification], + Delete[models.EmailVerification], + ) + return *repo +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/email_route.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/email_route.go new file mode 100644 index 0000000000000000000000000000000000000000..8f2f59e88a8cf958d200ee36174549e839a0a33c --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/email_route.go @@ -0,0 +1,15 @@ +package router + +import ( + EmailController "api.qobiltu.id/controller/email" + "github.com/gin-gonic/gin" +) + +func EmailRoute(router *gin.Engine) { + routerGroup := router.Group("/api/v1/email") + { + routerGroup.POST("/verify", EmailController.CreateVerification) + routerGroup.POST("/create-verification", EmailController.CreateVerification) + routerGroup.DELETE("/delete-verification", EmailController.DeleteVerification) + } +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/router.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/router.go index 114a87bb4eb5bd9713a0cd097c9b46f05eb761df..a7dde2e239a2d254991cd00c712b9eeebe6102d1 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/router.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/router.go @@ -8,11 +8,8 @@ import ( func StartService() { router := gin.Default() - routerGroup := router.Group("/api/v1") - { - routerGroup.GET("/", controller.HomeController) - routerGroup.POST("/login", controller.LoginController) - routerGroup.POST("/register", controller.RegisterController) - } + router.GET("/", controller.HomeController) + UserRoute(router) + EmailRoute(router) router.Run(config.TCP_ADDRESS) } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/user_route.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/user_route.go new file mode 100644 index 0000000000000000000000000000000000000000..c1abce045debeff19dabe5af38b9903abd5083a0 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/user_route.go @@ -0,0 +1,16 @@ +package router + +import ( + UserController "api.qobiltu.id/controller/user" + "api.qobiltu.id/middleware" + "github.com/gin-gonic/gin" +) + +func UserRoute(router *gin.Engine) { + routerGroup := router.Group("/api/v1/user") + { + routerGroup.POST("/login", UserController.Login) + routerGroup.POST("/register", UserController.Register) + routerGroup.GET("/me", middleware.AuthUser, UserController.Profile) + } +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/email_verification_service.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/email_verification_service.go new file mode 100644 index 0000000000000000000000000000000000000000..d94c65bc93550413c285e2817b68392664fb3b2a --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/email_verification_service.go @@ -0,0 +1,57 @@ +package services + +import ( + "math/rand" + "time" + + "api.qobiltu.id/config" + "api.qobiltu.id/models" + "api.qobiltu.id/repositories" +) + +type EmailVerificationService struct { + Service[models.EmailVerification, models.EmailVerification] +} + +func (s *EmailVerificationService) Create() { + accountRepo := repositories.GetAccountbyId(s.Constructor.AccountID) + if accountRepo.NoRecord { + s.Error = accountRepo.RowsError + s.Exception.DataNotFound = true + s.Exception.Message = "There is no account data with given credentials!" + return + } + + remainingTime := time.Duration(config.EMAIL_VERIFICATION_DURATION) * time.Hour + dueTime := CalculateDueTime(remainingTime) + + randomizer := rand.New(rand.NewSource(10)) + token := uint(randomizer.Int()) + + repo := repositories.CreateEmailVerification(s.Constructor.AccountID, dueTime, token) + + s.Error = repo.RowsError + s.Result = repo.Result +} + +func (s *EmailVerificationService) Validate() { + repo := repositories.GetEmailVerification(s.Constructor.AccountID, s.Constructor.Token) + s.Error = repo.RowsError + if repo.NoRecord { + s.Exception.DataNotFound = true + s.Exception.Message = "Invalid token!" + return + } + s.Result = repo.Result +} + +func (s *EmailVerificationService) Delete() { + repo := repositories.DeleteEmailVerification(s.Constructor.Token) + s.Error = repo.RowsError + if repo.NoRecord { + s.Exception.DataNotFound = true + s.Exception.Message = "Invalid token!" + return + } + s.Result = repo.Result +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/jwt_service.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/jwt_service.go new file mode 100644 index 0000000000000000000000000000000000000000..92024df8afa7fe83da747bddc969cc1066cf431c --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/jwt_service.go @@ -0,0 +1,45 @@ +package services + +import ( + "errors" + "time" + + "api.qobiltu.id/config" + "api.qobiltu.id/models" + "github.com/dgrijalva/jwt-go" + "golang.org/x/crypto/bcrypt" +) + +var salt = config.Salt +var secretKey = []byte(salt) + +func GenerateToken(user *models.Account) (string, error) { + + // Create a new token + token := jwt.New(jwt.SigningMethodHS256) + + // Set claims + claims := token.Claims.(jwt.MapClaims) + claims["id"] = user.Id + claims["exp"] = time.Now().Add(time.Hour * 24).Unix() // Token expires in 24 hours + + // Sign the token with the secret key + tokenString, err := token.SignedString(secretKey) + if err != nil { + return "", err + } + + return tokenString, nil +} + +func VerifyPassword(hashedPassword, password string) error { + err := bcrypt.CompareHashAndPassword([]byte(hashedPassword), []byte(password)) + if err != nil { + return errors.New("invalid password") + } + return nil +} +func HashPassword(password string) (string, error) { + bytes, err := bcrypt.GenerateFromPassword([]byte(password), 14) + return string(bytes), err +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/login_service.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/login_service.go index 06ea6bb57e6ccdb5fa55784476af50fcda77eff1..93256b042c4daf76a9f3501111792b940a5ff200 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/login_service.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/login_service.go @@ -3,7 +3,6 @@ package services import ( "errors" - "api.qobiltu.id/middleware" "api.qobiltu.id/models" "api.qobiltu.id/repositories" ) @@ -24,13 +23,13 @@ func (s *AuthenticationService) Authenticate() { s.Exception.Message = "there is no account with given credentials!" return } - if middleware.VerifyPassword(accountData.Result.Password, s.Constructor.Password) != nil { + if VerifyPassword(accountData.Result.Password, s.Constructor.Password) != nil { s.Exception.Unauthorized = true s.Exception.Message = "incorrect password!" return } - token, err_tok := middleware.GenerateToken(&accountData.Result) + token, err_tok := GenerateToken(&accountData.Result) if err_tok != nil { s.Error = errors.Join(s.Error, err_tok) diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/register_service.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/register_service.go index 6732f99fabbd315504042de844f59841294e2025..f9e0d2216bd033155ffcbd73dd1b9de44d20bfa8 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/register_service.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/register_service.go @@ -3,7 +3,6 @@ package services import ( "errors" - "api.qobiltu.id/middleware" "api.qobiltu.id/models" "api.qobiltu.id/repositories" uuid "github.com/satori/go.uuid" @@ -20,7 +19,7 @@ func (s *RegisterService) Create() { s.Exception.Message = "Password must have at least 8 characters!" return } - hashed_password, err_hash := middleware.HashPassword(s.Constructor.Password) + hashed_password, err_hash := HashPassword(s.Constructor.Password) s.Error = err_hash s.Constructor.Password = hashed_password s.Constructor.UUID = uuid.NewV4() diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/service.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/service.go index 7d56d45d633a3e7fd485bc9348527494512a0a50..3e6cda14fae0b3b8b7c50747311d2d8c67ee4d66 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/service.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/service.go @@ -1,6 +1,10 @@ package services -import "api.qobiltu.id/models" +import ( + "time" + + "api.qobiltu.id/models" +) type ( Services interface { @@ -29,3 +33,7 @@ func Construct[TConstructor any, TResult any](constructor ...TConstructor) *Serv Constructor: constructor[0], } } + +func CalculateDueTime(duration time.Duration) time.Time { + return time.Now().Add(duration) +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/user_profile_service.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/user_profile_service.go new file mode 100644 index 0000000000000000000000000000000000000000..afea5ccbf0885293e2f782692e229b6948e2228e --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/user_profile_service.go @@ -0,0 +1,37 @@ +package services + +import ( + "api.qobiltu.id/models" + "api.qobiltu.id/repositories" +) + +type UserProfileConstructor struct { + AccountId int +} +type UserProfileService struct { + Service[UserProfileConstructor, models.Account] +} + +func (s *UserProfileService) Retrieve() { + userProfile := repositories.GetAccountbyId(uint(s.Constructor.AccountId)) + s.Error = userProfile.RowsError + if userProfile.NoRecord { + s.Exception.DataNotFound = true + s.Exception.Message = "There is no account with given credentials!" + return + } + s.Result.Password = "SECRET" + s.Result = userProfile.Result +} + +func (s *UserProfileService) Update() { + userProfile := repositories.GetAccountbyId(uint(s.Constructor.AccountId)) + s.Error = userProfile.RowsError + if userProfile.NoRecord { + s.Exception.DataNotFound = true + s.Exception.Message = "There is no account with given credentials!" + return + } + s.Result.Password = "SECRET" + s.Result = userProfile.Result +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/LICENSE b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..79da4b69760d1658f4dbc42604187316b368d857 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2025 Abdan Hafidz + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/.github/workflows/main.yml b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/.github/workflows/main.yml index 37c1b056c4f04eaa76005b0f10c04f8764cd2d13..39a67571ac3a2e6a6e2a972b9550becd551bdded 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/.github/workflows/main.yml +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/.github/workflows/main.yml @@ -49,4 +49,4 @@ jobs: cd space git add . git commit -m "Deploy files from GitHub repository" || echo "No changes to commit" - git push --force origin main || echo "No changes to push" + git push origin main || echo "No changes to push" diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/.github/workflows/main.yml b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/.github/workflows/main.yml index 39a67571ac3a2e6a6e2a972b9550becd551bdded..37c1b056c4f04eaa76005b0f10c04f8764cd2d13 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/.github/workflows/main.yml +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/.github/workflows/main.yml @@ -49,4 +49,4 @@ jobs: cd space git add . git commit -m "Deploy files from GitHub repository" || echo "No changes to commit" - git push origin main || echo "No changes to push" + git push --force origin main || echo "No changes to push" diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/.gitignore b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/.gitignore index deeb9479f4cb982ccd42fa0d7210b9777509e4ae..bd10d926e1c503ff128e21bf273fe2732e526abf 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/.gitignore +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/.gitignore @@ -1,3 +1,4 @@ .env vendor/ -quzuu-be.exe \ No newline at end of file +quzuu-be.exe +README.md \ No newline at end of file diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/config/config.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/config/config.go new file mode 100644 index 0000000000000000000000000000000000000000..96d88fd641bf8a6b538d1324abff58c8d5b912a0 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/config/config.go @@ -0,0 +1,21 @@ +package config + +import ( + "os" + + "github.com/joho/godotenv" +) + +var TCP_ADDRESS string +var LOG_PATH string +var HOST_ADDRESS string +var HOST_PORT string + +func init() { + godotenv.Load() + HOST_ADDRESS = os.Getenv("HOST_ADDRESS") + HOST_PORT = os.Getenv("HOST_PORT") + TCP_ADDRESS = HOST_ADDRESS + ":" + HOST_PORT + LOG_PATH = os.Getenv("LOG_PATH") + // Menampilkan nilai variabel lingkungan +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/config/database_connection_config.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/config/database_connection_config.go new file mode 100644 index 0000000000000000000000000000000000000000..458388d26dd8408234352e2a835552d6a278f267 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/config/database_connection_config.go @@ -0,0 +1,60 @@ +package config + +import ( + "fmt" + "log" + "os" + + "gorm.io/driver/postgres" + "gorm.io/gorm" + "gorm.io/gorm/logger" + + "api.qobiltu.id/models" + "github.com/joho/godotenv" +) + +var DB *gorm.DB +var err error +var Salt string + +func init() { + godotenv.Load() + if err != nil { + fmt.Println("Gagal membaca file .env") + return + } + os.Setenv("TZ", "Asia/Jakarta") + dbHost := os.Getenv("DB_HOST") + dbPort := os.Getenv("DB_PORT") + dbUser := os.Getenv("DB_USER") + dbPassword := os.Getenv("DB_PASSWORD") + dbName := os.Getenv("DB_NAME") + Salt := os.Getenv("SALT") + dsn := "host=" + dbHost + " user=" + dbUser + " password=" + dbPassword + " dbname=" + dbName + " port=" + dbPort + " sslmode=disable TimeZone=Asia/Jakarta" + DB, err = gorm.Open(postgres.Open(dsn), &gorm.Config{TranslateError: true}) + if err != nil { + panic(err) + } + if Salt == "" { + Salt = "D3f4u|t" + } + + // Call AutoMigrateAll to perform auto-migration + AutoMigrateAll(DB) +} + +func AutoMigrateAll(db *gorm.DB) { + // Enable logger to see SQL logs + db.Logger.LogMode(logger.Info) + + // Auto-migrate all models + err := db.AutoMigrate( + &models.Account{}, + &models.AccountDetails{}, + ) + if err != nil { + log.Fatal(err) + } + + fmt.Println("Migration completed successfully.") +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/home_controller.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/home_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..06cfc3d7fac0385d6aef847a186de2eae7dbb4bb --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/home_controller.go @@ -0,0 +1,9 @@ +package controller + +import "github.com/gin-gonic/gin" + +func HomeController(c *gin.Context) { + c.JSON(200, gin.H{ + "message": "Api Qobiltu 2025!", + }) +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/login_controller.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/login_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..b411fa438a6d877515eca1d40dcb21060edd68c4 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/login_controller.go @@ -0,0 +1,19 @@ +package controller + +import ( + "api.qobiltu.id/models" + "api.qobiltu.id/services" + "github.com/gin-gonic/gin" +) + +func LoginController(c *gin.Context) { + authentication := services.AuthenticationService{} + loginController := Controller[models.LoginRequest, services.LoginConstructor, models.AuthenticatedUser]{ + Service: &authentication.Service, + } + loginController.RequestJSON(c, func() { + loginController.Service.Constructor.Email = loginController.Request.Email + loginController.Service.Constructor.Password = loginController.Request.Password + authentication.Authenticate() + }) +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/register_controller.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/register_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..3dc0f3c21343fe3279a492db3e994cbf8eef3561 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/register_controller.go @@ -0,0 +1,19 @@ +package controller + +import ( + "api.qobiltu.id/models" + "api.qobiltu.id/services" + "github.com/gin-gonic/gin" +) + +func RegisterController(c *gin.Context) { + register := services.RegisterService{} + registerController := Controller[models.RegisterRequest, models.Account, models.Account]{ + Service: ®ister.Service, + } + registerController.RequestJSON(c, func() { + registerController.Service.Constructor.Password = registerController.Request.Password + registerController.Service.Constructor.Email = registerController.Request.Email + register.Create() + }) +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/authentication_middleware.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/authentication_middleware.go new file mode 100644 index 0000000000000000000000000000000000000000..44178a96738817742fd4f6f7fe1ca63bbecc2d27 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/authentication_middleware.go @@ -0,0 +1,104 @@ +// auth/auth.go + +package middleware + +import ( + "errors" + "time" + + "api.qobiltu.id/config" + "api.qobiltu.id/models" + "github.com/gin-gonic/gin" + "github.com/golang-jwt/jwt/v5" + "golang.org/x/crypto/bcrypt" +) + +// Define a secret key for signing the JWT token +var salt = config.Salt +var secretKey = []byte(salt) + +// GenerateToken generates a JWT token for the given user +func GenerateToken(user *models.Account) (string, error) { + + // Create a new token + token := jwt.New(jwt.SigningMethodHS256) + + // Set claims + claims := token.Claims.(jwt.MapClaims) + claims["id"] = user.Id + claims["exp"] = time.Now().Add(time.Hour * 24).Unix() // Token expires in 24 hours + + // Sign the token with the secret key + tokenString, err := token.SignedString(secretKey) + if err != nil { + return "", err + } + + return tokenString, nil +} + +// VerifyPassword verifies if the provided password matches the hashed password +func VerifyPassword(hashedPassword, password string) error { + err := bcrypt.CompareHashAndPassword([]byte(hashedPassword), []byte(password)) + if err != nil { + return errors.New("invalid password") + } + return nil +} +func HashPassword(password string) (string, error) { + bytes, err := bcrypt.GenerateFromPassword([]byte(password), 14) + return string(bytes), err +} + +type CustomClaims struct { + jwt.RegisteredClaims + UserID int `json:"id"` +} + +func VerifyToken(bearer_token string) (int, string, error) { + // fmt.Println(bearer_token) + token, err := jwt.ParseWithClaims(bearer_token, &CustomClaims{}, func(token *jwt.Token) (interface{}, error) { + return secretKey, nil + }) + if err != nil { + return 0, "invalid-token", err + } + + // Extract the claims + claims, ok := token.Claims.(*CustomClaims) + if !ok || !token.Valid { + return 0, "invalid-token", err + } + if claims.ExpiresAt != nil && claims.ExpiresAt.Time.Before(time.Now()) { + return 0, "expired", err + } + + return claims.UserID, "valid", err +} + +func AuthUser(c *gin.Context) { + var currAccData models.AccountData + if c.Request.Header["Auth-Bearer-Token"] != nil { + token := c.Request.Header["Auth-Bearer-Token"] + currAccData.UserID, currAccData.VerifyStatus, currAccData.ErrVerif = VerifyToken(token[0]) + // fmt.Println("Verify Status :", currAccData.verifyStatus) + if currAccData.VerifyStatus == "invalid-token" || currAccData.VerifyStatus == "expired" { + currAccData.UserID = 0 + message := "Your session is expired, Please re-Login!" + SendJSON401(c, &currAccData.VerifyStatus, &message) + c.Abort() + return + } + } else { + currAccData.UserID = 0 + currAccData.VerifyStatus = "no-token" + currAccData.ErrVerif = nil + message := "You have to Login First!" + SendJSON401(c, &currAccData.VerifyStatus, &message) + c.Abort() + return + } + + c.Set("accountData", currAccData) + c.Next() +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/response_middleware.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/response_middleware.go new file mode 100644 index 0000000000000000000000000000000000000000..55f3385077839115eadb8dace294229f4b4c3df2 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/response_middleware.go @@ -0,0 +1,39 @@ +package middleware + +import ( + "net/http" + + "github.com/gin-gonic/gin" +) + +// SendJSON200 sends a JSON response with HTTP status code 200 +func SendJSON200(c *gin.Context, data interface{}) { + c.JSON(http.StatusOK, gin.H{"status": "success", "data": data}) +} + +// SendJSON400 sends a JSON response with HTTP status code 400 +func SendJSON400(c *gin.Context, error_status *string, message *string) { + c.JSON(http.StatusBadRequest, gin.H{"status": "error", "error-status": error_status, "message": message}) +} + +// SendJSON401 sends a JSON response with HTTP status code 401 +func SendJSON401(c *gin.Context, error_status *string, message *string) { + c.JSON(http.StatusUnauthorized, gin.H{"status": "error", "error-status": error_status, "message": message}) +} + +// SendJSON403 sends a JSON response with HTTP status code 403 +func SendJSON403(c *gin.Context, message *string) { + c.JSON(http.StatusForbidden, gin.H{"status": "error", "message": message}) +} + +// SendJSON404 sends a JSON response with HTTP status code 404 +func SendJSON404(c *gin.Context, message *string) { + c.JSON(http.StatusNotFound, gin.H{"status": "error", "message": message}) +} + +// SendJSON500 sends a JSON response with HTTP status code 500 +func SendJSON500(c *gin.Context, error_status *string, message *string) { + c.JSON(http.StatusInternalServerError, gin.H{"status": "error", "error-status": error_status, "message": message}) +} + +// JSONResponseMiddleware is a middleware that provides functions for sending JSON responses diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/authentication_payload_model.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/authentication_payload_model.go new file mode 100644 index 0000000000000000000000000000000000000000..0203b9b340d066705491edf66830674602f89655 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/authentication_payload_model.go @@ -0,0 +1,7 @@ +package models + +type AccountData struct { + UserID int + VerifyStatus string + ErrVerif error +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/database_orm_model.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/database_orm_model.go new file mode 100644 index 0000000000000000000000000000000000000000..82e8b95b39b86be5fb0a4ce538d697e9df8fd0d5 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/database_orm_model.go @@ -0,0 +1,31 @@ +package models + +import ( + "time" + + uuid "github.com/satori/go.uuid" +) + +type Account struct { + Id uint `gorm:"primaryKey" json:"id"` + UUID uuid.UUID `gorm:"type:uuid" json:"uuid" ` + Email string `gorm:"uniqueIndex" json:"email"` + Password string `json:"password"` + IsEmailVerified bool `json:"is_email_verified"` + CreatedAt time.Time `json:"created_at"` + DeletedAt time.Time `json:"deleted_at"` +} + +type AccountDetails struct { + IDDetail uint `gorm:"primaryKey" json:"id_detail"` + Account_id uint `json:"id_account"` + Province string `json:"province"` + City string `json:"city"` + Institution string `json:"institution"` + UpdatedAt time.Time `json:"updated_at"` + DeletedAt time.Time `json:"deleted_at"` +} + +// Gorm table name settings +func (Account) TableName() string { return "account" } +func (AccountDetails) TableName() string { return "account_details" } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/exception_model.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/exception_model.go new file mode 100644 index 0000000000000000000000000000000000000000..f2c026a993f950652158318977783e8563e595fb --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/exception_model.go @@ -0,0 +1,12 @@ +package models + +type Exception struct { + Unauthorized bool `json:"unauthorized,omitempty"` + BadRequest bool `json:"bad_request,omitempty"` + DataNotFound bool `json:"data_not_found,omitempty"` + InternalServerError bool `json:"internal_server_error,omitempty"` + DataDuplicate bool `json:"data_duplicate,omitempty"` + QueryError bool `json:"query_error,omitempty"` + InvalidPasswordLength bool `json:"invalid_password_length,omitempty"` + Message string `json:"message,omitempty"` +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/model.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/model.go new file mode 100644 index 0000000000000000000000000000000000000000..9ce401186cb92d50737155815c1f511164b86407 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/model.go @@ -0,0 +1 @@ +package models diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/request_model.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/request_model.go new file mode 100644 index 0000000000000000000000000000000000000000..cfae888ec34edbdd3f5b6588050e2b382c63792d --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/request_model.go @@ -0,0 +1,13 @@ +package models + +type LoginRequest struct { + Email string `json:"email" binding:"required"` + Password string `json:"password" binding:"required"` +} + +type RegisterRequest struct { + Name string `json:"name"` + Email string `json:"email" binding:"required,email"` + Phone int `json:"phone"` + Password string `json:"password" binding:"required"` +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/response_model.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/response_model.go new file mode 100644 index 0000000000000000000000000000000000000000..c45df0dbc642de90cc3537722b359a2f09a06b02 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/response_model.go @@ -0,0 +1,19 @@ +package models + +type SuccessResponse struct { + Status string `json:"status"` + Message string `json:"message"` + Data any `json:"data"` + MetaData any `json:"meta_data"` +} + +type ErrorResponse struct { + Status string `json:"status"` + Message string `json:"message"` + Errors Exception `json:"errors"` + MetaData any `json:"meta_data"` +} +type AuthenticatedUser struct { + Account Account `json:"account"` + Token string `json:"token"` +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/account_repository.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/account_repository.go new file mode 100644 index 0000000000000000000000000000000000000000..41bd903aff7bf12c9d81cbed1ad00521ae629640 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/account_repository.go @@ -0,0 +1,24 @@ +package repositories + +import ( + "api.qobiltu.id/models" +) + +func GetAccountbyEmail(email string) Repository[models.Account, models.Account] { + repo := Construct[models.Account, models.Account]( + models.Account{Email: email}, + ) + repo.Transactions( + WhereGivenConstructor[models.Account, models.Account], + Find[models.Account, models.Account], + ) + return *repo +} + +func CreateAccount(account models.Account) Repository[models.Account, models.Account] { + repo := Construct[models.Account, models.Account]( + account, + ) + Create(repo) + return *repo +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/repository.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/repository.go new file mode 100644 index 0000000000000000000000000000000000000000..3617e40936bf9e50e39a50285105622f080d210f --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/repository.go @@ -0,0 +1,113 @@ +package repositories + +import ( + "api.qobiltu.id/config" + "gorm.io/gorm" +) + +type Repositories interface { + FindAllPaginate() + Where() + Find() + Create() + Update() + CustomQuery() + Delete() +} +type PaginationConstructor struct { + Limit int + Offset int + Filter string +} + +type CustomQueryConstructor struct { + SQL string + Values interface{} +} + +type Repository[TConstructor any, TResult any] struct { + Constructor TConstructor + Pagination PaginationConstructor + CustomQuery CustomQueryConstructor + Result TResult + Transaction *gorm.DB + RowsCount int + NoRecord bool + RowsError error +} + +func Construct[TConstructor any, TResult any](constructor ...TConstructor) *Repository[TConstructor, TResult] { + if len(constructor) == 1 { + return &Repository[TConstructor, TResult]{ + Constructor: constructor[0], + Transaction: config.DB, + } + } + return &Repository[TConstructor, TResult]{ + Constructor: constructor[0], + Transaction: config.DB.Begin(), + } +} +func (repo *Repository[T1, T2]) Transactions(transactions ...func(*Repository[T1, T2]) *gorm.DB) { + for _, tx := range transactions { + repo.Transaction = tx(repo) + if repo.RowsError != nil { + return + } + } +} +func WhereGivenConstructor[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB { + tx := repo.Transaction.Where(&repo.Constructor) + repo.RowsCount = int(tx.RowsAffected) + repo.NoRecord = repo.RowsCount == 0 + repo.RowsError = tx.Error + return tx +} +func Find[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB { + tx := repo.Transaction.Find(&repo.Result) + repo.RowsCount = int(tx.RowsAffected) + repo.NoRecord = repo.RowsCount == 0 + repo.RowsError = tx.Error + return tx +} + +func FinddAllPaginate[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB { + tx := repo.Transaction.Limit(repo.Pagination.Limit).Offset(repo.Pagination.Offset).Find(&repo.Result) + repo.RowsCount = int(tx.RowsAffected) + repo.NoRecord = repo.RowsCount == 0 + repo.RowsError = tx.Error + return tx +} + +func Create[T1 any](repo *Repository[T1, T1]) *gorm.DB { + tx := repo.Transaction.Create(&repo.Constructor) + repo.RowsCount = int(tx.RowsAffected) + repo.NoRecord = repo.RowsCount == 0 + repo.RowsError = tx.Error + repo.Result = repo.Constructor + return tx +} + +func Update[T1 any](repo *Repository[T1, T1]) *gorm.DB { + tx := repo.Transaction.Save(&repo.Constructor) + repo.RowsCount = int(tx.RowsAffected) + repo.NoRecord = repo.RowsCount == 0 + repo.RowsError = tx.Error + return tx +} + +func Delete[T1 any](repo *Repository[T1, T1]) *gorm.DB { + tx := repo.Transaction.Delete(&repo.Constructor) + repo.RowsCount = int(tx.RowsAffected) + repo.NoRecord = repo.RowsCount == 0 + repo.RowsError = tx.Error + return tx +} + +func CustomQuery[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB { + tx := repo.Transaction.Raw(repo.CustomQuery.SQL, repo.CustomQuery.Values).Scan(&repo.Result) + repo.RowsCount = int(tx.RowsAffected) + repo.NoRecord = repo.RowsCount == 0 + repo.RowsError = tx.Error + return tx +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/login_service.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/login_service.go new file mode 100644 index 0000000000000000000000000000000000000000..06ea6bb57e6ccdb5fa55784476af50fcda77eff1 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/login_service.go @@ -0,0 +1,47 @@ +package services + +import ( + "errors" + + "api.qobiltu.id/middleware" + "api.qobiltu.id/models" + "api.qobiltu.id/repositories" +) + +type LoginConstructor struct { + Email string + Password string +} + +type AuthenticationService struct { + Service[LoginConstructor, models.AuthenticatedUser] +} + +func (s *AuthenticationService) Authenticate() { + accountData := repositories.GetAccountbyEmail(s.Constructor.Email) + if accountData.NoRecord { + s.Exception.DataNotFound = true + s.Exception.Message = "there is no account with given credentials!" + return + } + if middleware.VerifyPassword(accountData.Result.Password, s.Constructor.Password) != nil { + s.Exception.Unauthorized = true + s.Exception.Message = "incorrect password!" + return + } + + token, err_tok := middleware.GenerateToken(&accountData.Result) + + if err_tok != nil { + s.Error = errors.Join(s.Error, err_tok) + } + + accountData.Result.Password = "SECRET" + s.Result = models.AuthenticatedUser{ + Account: accountData.Result, + Token: token, + } + s.Error = accountData.RowsError +} + +// LoginHandler handles user login diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/register_service.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/register_service.go new file mode 100644 index 0000000000000000000000000000000000000000..6732f99fabbd315504042de844f59841294e2025 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/register_service.go @@ -0,0 +1,40 @@ +package services + +import ( + "errors" + + "api.qobiltu.id/middleware" + "api.qobiltu.id/models" + "api.qobiltu.id/repositories" + uuid "github.com/satori/go.uuid" + "gorm.io/gorm" +) + +type RegisterService struct { + Service[models.Account, models.Account] +} + +func (s *RegisterService) Create() { + if len(s.Constructor.Password) < 8 { + s.Exception.InvalidPasswordLength = true + s.Exception.Message = "Password must have at least 8 characters!" + return + } + hashed_password, err_hash := middleware.HashPassword(s.Constructor.Password) + s.Error = err_hash + s.Constructor.Password = hashed_password + s.Constructor.UUID = uuid.NewV4() + accountCreated := repositories.CreateAccount(s.Constructor) + if errors.Is(accountCreated.RowsError, gorm.ErrDuplicatedKey) { + s.Exception.DataDuplicate = true + s.Exception.Message = "Account with email " + s.Constructor.Email + " already exists!" + return + } 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) { + s.Exception.BadRequest = true + s.Exception.Message = "Bad request!" + return + } + s.Error = accountCreated.RowsError + s.Result = accountCreated.Result + s.Result.Password = "SECRET" +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/service.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/service.go new file mode 100644 index 0000000000000000000000000000000000000000..7d56d45d633a3e7fd485bc9348527494512a0a50 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/service.go @@ -0,0 +1,31 @@ +package services + +import "api.qobiltu.id/models" + +type ( + Services interface { + Retrieve() + Update() + Create() + Delete() + Validate() + Authenticate() + Authorize() + } + Service[TConstructor any, TResult any] struct { + Constructor TConstructor + Result TResult + Exception models.Exception + Error error + } +) + +func Construct[TConstructor any, TResult any](constructor ...TConstructor) *Service[TConstructor, TResult] { + if len(constructor) == 1 { + return &Service[TConstructor, TResult]{} + } + + return &Service[TConstructor, TResult]{ + Constructor: constructor[0], + } +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/config/DatabaseConfig.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/config/DatabaseConfig.go index 7dfa116ec7152e6338c764ce5853ad21782bd26f..458388d26dd8408234352e2a835552d6a278f267 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/config/DatabaseConfig.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/config/DatabaseConfig.go @@ -9,26 +9,10 @@ import ( "gorm.io/gorm" "gorm.io/gorm/logger" + "api.qobiltu.id/models" "github.com/joho/godotenv" - "go-dp.abdanhafidz.com/models" ) -func AutoMigrateAll(db *gorm.DB) { - // Enable logger to see SQL logs - db.Logger.LogMode(logger.Info) - - // Auto-migrate all models - err := db.AutoMigrate( - &models.Account{}, - &models.AccountDetails{}, - ) - if err != nil { - log.Fatal(err) - } - - fmt.Println("Migration completed successfully.") -} - var DB *gorm.DB var err error var Salt string @@ -58,3 +42,19 @@ func init() { // Call AutoMigrateAll to perform auto-migration AutoMigrateAll(DB) } + +func AutoMigrateAll(db *gorm.DB) { + // Enable logger to see SQL logs + db.Logger.LogMode(logger.Info) + + // Auto-migrate all models + err := db.AutoMigrate( + &models.Account{}, + &models.AccountDetails{}, + ) + if err != nil { + log.Fatal(err) + } + + fmt.Println("Migration completed successfully.") +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/LoginController.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/LoginController.go index 6d04567f7a776399c5faafc4f11dff4c0735ae9a..b411fa438a6d877515eca1d40dcb21060edd68c4 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/LoginController.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/LoginController.go @@ -1,9 +1,9 @@ package controller import ( + "api.qobiltu.id/models" + "api.qobiltu.id/services" "github.com/gin-gonic/gin" - "go-dp.abdanhafidz.com/models" - "go-dp.abdanhafidz.com/services" ) func LoginController(c *gin.Context) { diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/RegisterController.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/RegisterController.go index e3375ba58212ddd73d2d4e29fbf67d247e89398b..3dc0f3c21343fe3279a492db3e994cbf8eef3561 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/RegisterController.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/RegisterController.go @@ -1,9 +1,9 @@ package controller import ( + "api.qobiltu.id/models" + "api.qobiltu.id/services" "github.com/gin-gonic/gin" - "go-dp.abdanhafidz.com/models" - "go-dp.abdanhafidz.com/services" ) func RegisterController(c *gin.Context) { diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/controller.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/controller.go index fa14d0b2c6ed4e25a72839a3fad18b2d59e40af3..32a528d703f974515cc1baa4960e87ac56481629 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/controller.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/controller.go @@ -1,10 +1,10 @@ package controller import ( + "api.qobiltu.id/models" + "api.qobiltu.id/services" + "api.qobiltu.id/utils" "github.com/gin-gonic/gin" - "go-dp.abdanhafidz.com/models" - "go-dp.abdanhafidz.com/services" - "go-dp.abdanhafidz.com/utils" ) type ( diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.mod b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.mod index f6d85920f3d50bf7a3fc013a4ee8875237b0e108..9b6fd06b10d941bc76ba173ba5f2983e9c1408d8 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.mod +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.mod @@ -1,49 +1,49 @@ -module go-dp.abdanhafidz.com +module api.qobiltu.id -go 1.21.0 +go 1.24.0 require ( - github.com/dgrijalva/jwt-go v3.2.0+incompatible - github.com/gin-gonic/gin v1.9.1 + github.com/gin-gonic/gin v1.10.0 + github.com/golang-jwt/jwt/v5 v5.2.1 github.com/joho/godotenv v1.5.1 - golang.org/x/crypto v0.32.0 - gorm.io/driver/postgres v1.5.4 - gorm.io/gorm v1.25.5 + github.com/satori/go.uuid v1.2.0 + golang.org/x/crypto v0.36.0 + gorm.io/driver/postgres v1.5.11 + gorm.io/gorm v1.25.12 ) require ( - github.com/bytedance/sonic v1.10.2 // indirect - github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect - github.com/chenzhuoyu/iasm v0.9.0 // indirect + github.com/bytedance/sonic v1.13.1 // indirect + github.com/bytedance/sonic/loader v0.2.4 // indirect + github.com/cloudwego/base64x v0.1.5 // indirect github.com/gabriel-vasile/mimetype v1.4.8 // indirect - github.com/gin-contrib/sse v0.1.0 // indirect + github.com/gin-contrib/sse v1.0.0 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.25.0 // indirect - github.com/goccy/go-json v0.10.2 // indirect + github.com/goccy/go-json v0.10.5 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect - github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect - github.com/jackc/pgx/v5 v5.5.0 // indirect - github.com/jackc/puddle/v2 v2.2.1 // indirect + github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect + github.com/jackc/pgx/v5 v5.7.2 // indirect + github.com/jackc/puddle/v2 v2.2.2 // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect github.com/json-iterator/go v1.1.12 // indirect - github.com/klauspost/cpuid/v2 v2.2.6 // indirect + github.com/klauspost/cpuid/v2 v2.2.10 // indirect github.com/kr/text v0.2.0 // indirect github.com/leodido/go-urn v1.4.0 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect - github.com/pelletier/go-toml/v2 v2.1.0 // indirect + github.com/pelletier/go-toml/v2 v2.2.3 // indirect github.com/rogpeppe/go-internal v1.11.0 // indirect - github.com/satori/go.uuid v1.2.0 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect - github.com/ugorji/go/codec v1.2.11 // indirect - golang.org/x/arch v0.6.0 // indirect - golang.org/x/net v0.34.0 // indirect - golang.org/x/sync v0.10.0 // indirect - golang.org/x/sys v0.29.0 // indirect - golang.org/x/text v0.21.0 // indirect - google.golang.org/protobuf v1.31.0 // indirect + github.com/ugorji/go/codec v1.2.12 // indirect + golang.org/x/arch v0.15.0 // indirect + golang.org/x/net v0.37.0 // indirect + golang.org/x/sync v0.12.0 // indirect + golang.org/x/sys v0.31.0 // indirect + golang.org/x/text v0.23.0 // indirect + google.golang.org/protobuf v1.36.5 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect -) +) \ No newline at end of file diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.sum b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.sum index a82e88494d1f86d0560792cace9c2a61284c1d8a..6f39995754d2f66f294c1866a62d1810e8d524c5 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.sum +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.sum @@ -1,51 +1,44 @@ -github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= -github.com/bytedance/sonic v1.10.0-rc/go.mod h1:ElCzW+ufi8qKqNW0FY314xriJhyJhuoJ3gFZdAHF7NM= -github.com/bytedance/sonic v1.10.2 h1:GQebETVBxYB7JGWJtLBi07OVzWwt+8dWA00gEVW2ZFE= -github.com/bytedance/sonic v1.10.2/go.mod h1:iZcSUejdk5aukTND/Eu/ivjQuEL0Cu9/rf50Hi0u/g4= -github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= -github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= -github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d h1:77cEq6EriyTZ0g/qfRdp61a3Uu/AWrgIq2s0ClJV1g0= -github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d/go.mod h1:8EPpVsBuRksnlj1mLy4AWzRNQYxauNi62uWcE3to6eA= -github.com/chenzhuoyu/iasm v0.9.0 h1:9fhXjVzq5hUy2gkhhgHl95zG2cEAhw9OSGs8toWWAwo= -github.com/chenzhuoyu/iasm v0.9.0/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog= +github.com/bytedance/sonic v1.13.1 h1:Jyd5CIvdFnkOWuKXr+wm4Nyk2h0yAFsr8ucJgEasO3g= +github.com/bytedance/sonic v1.13.1/go.mod h1:o68xyaF9u2gvVBuGHPlUVCy+ZfmNNO5ETf1+KgkJhz4= +github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= +github.com/bytedance/sonic/loader v0.2.4 h1:ZWCw4stuXUsn1/+zQDqeE7JKP+QO47tz7QCNan80NzY= +github.com/bytedance/sonic/loader v0.2.4/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI= +github.com/cloudwego/base64x v0.1.5 h1:XPciSp1xaq2VCSt6lF0phncD4koWyULpl5bUxbfCyP4= +github.com/cloudwego/base64x v0.1.5/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= +github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= -github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= -github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= -github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM= github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8= -github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= -github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= -github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg= -github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU= +github.com/gin-contrib/sse v1.0.0 h1:y3bT1mUWUxDpW4JLQg/HnTqV4rozuW4tC9eFKTxYI9E= +github.com/gin-contrib/sse v1.0.0/go.mod h1:zNuFdwarAygJBht0NTKiSi3jRf6RbqeILZ9Sp6Slhe0= +github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU= +github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y= github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= -github.com/go-playground/validator/v10 v10.16.0 h1:x+plE831WK4vaKHO/jpgUGsvLKIqRRkz6M78GuJAfGE= -github.com/go-playground/validator/v10 v10.16.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= github.com/go-playground/validator/v10 v10.25.0 h1:5Dh7cjvzR7BRZadnsVOzPhWsrwUr0nmsZJxEAnFLNO8= github.com/go-playground/validator/v10 v10.25.0/go.mod h1:GGzBIJMuE98Ic/kJsBXbz1x/7cByt++cQ+YOuDM5wus= -github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= -github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4= +github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= +github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk= +github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= -github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk= -github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= -github.com/jackc/pgx/v5 v5.5.0 h1:NxstgwndsTRy7eq9/kqYc/BZh5w2hHJV86wjvO+1xPw= -github.com/jackc/pgx/v5 v5.5.0/go.mod h1:Ig06C2Vu0t5qXC60W8sqIthScaEnFvojjj9dSljmHRA= -github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk= -github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= +github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo= +github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= +github.com/jackc/pgx/v5 v5.7.2 h1:mLoDLV6sonKlvjIEsV56SkWNCnuNv531l94GaIzO+XI= +github.com/jackc/pgx/v5 v5.7.2/go.mod h1:ncY89UGWxg82EykZUwSpUKEfccBGGYq1xjrOpsbsfGQ= +github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo= +github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= @@ -55,15 +48,13 @@ github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwA github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= -github.com/klauspost/cpuid/v2 v2.2.6 h1:ndNyv040zDGIDh8thGkXYjnFtiN02M1PVVF+JE/48xc= -github.com/klauspost/cpuid/v2 v2.2.6/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= +github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE= +github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0= github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= -github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= 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 github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= -github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4= -github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= +github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M= +github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 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 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= -github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU= -github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= -golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= -golang.org/x/arch v0.6.0 h1:S0JTfE48HbRj80+4tbvZDYsJ3tGv6BUU3XxyZ7CirAc= -golang.org/x/arch v0.6.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= -golang.org/x/crypto v0.15.0 h1:frVn1TEaCEaZcn3Tmd7Y2b5KKPaZ+I32Q2OA3kYp5TA= -golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g= -golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc= -golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc= -golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg= -golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ= -golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0= -golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k= -golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= -golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ= -golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= +github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= +golang.org/x/arch v0.15.0 h1:QtOrQd0bTUnhNVNndMpLHNWrDmYzZ2KDqSrEymqInZw= +golang.org/x/arch v0.15.0/go.mod h1:JmwW7aLIoRUKgaTzhkiEFxvcEiQGyOg9BMonBJUS7EE= +golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34= +golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc= +golang.org/x/net v0.37.0 h1:1zLorHbz+LYj7MQlSf1+2tPIIgibq2eL5xkrGk6f+2c= +golang.org/x/net v0.37.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8= +golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw= +golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= -golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU= -golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= -golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= +golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik= +golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY= +golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= -google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM= +google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gorm.io/driver/postgres v1.5.4 h1:Iyrp9Meh3GmbSuyIAGyjkN+n9K+GHX9b9MqsTL4EJCo= -gorm.io/driver/postgres v1.5.4/go.mod h1:Bgo89+h0CRcdA33Y6frlaHHVuTdOf87pmyzwW9C/BH0= -gorm.io/gorm v1.25.5 h1:zR9lOiiYf09VNh5Q1gphfyia1JpiClIWG9hQaxB/mls= -gorm.io/gorm v1.25.5/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8= -nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= -rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= +gorm.io/driver/postgres v1.5.11 h1:ubBVAfbKEUld/twyKZ0IYn9rSQh448EdelLYk9Mv314= +gorm.io/driver/postgres v1.5.11/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI= +gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8= +gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ= +nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= \ No newline at end of file diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/main.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/main.go index d89532891b559d7d8361e79a1090e77a31cafb95..676f1b4f77f3957678f711cc402e21791cf11471 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/main.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/main.go @@ -3,8 +3,8 @@ package main import ( "fmt" - "go-dp.abdanhafidz.com/config" - "go-dp.abdanhafidz.com/router" + "api.qobiltu.id/config" + "api.qobiltu.id/router" ) func main() { diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/AuthMiddleware.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/AuthMiddleware.go index c153979ac01f108193541d23f821c288b4752f01..44178a96738817742fd4f6f7fe1ca63bbecc2d27 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/AuthMiddleware.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/AuthMiddleware.go @@ -6,10 +6,10 @@ import ( "errors" "time" - "github.com/dgrijalva/jwt-go" + "api.qobiltu.id/config" + "api.qobiltu.id/models" "github.com/gin-gonic/gin" - "go-dp.abdanhafidz.com/config" - "go-dp.abdanhafidz.com/models" + "github.com/golang-jwt/jwt/v5" "golang.org/x/crypto/bcrypt" ) @@ -51,8 +51,8 @@ func HashPassword(password string) (string, error) { } type CustomClaims struct { - jwt.StandardClaims - IDUser int `json:"id"` + jwt.RegisteredClaims + UserID int `json:"id"` } func VerifyToken(bearer_token string) (int, string, error) { @@ -63,33 +63,34 @@ func VerifyToken(bearer_token string) (int, string, error) { if err != nil { return 0, "invalid-token", err } + + // Extract the claims claims, ok := token.Claims.(*CustomClaims) if !ok || !token.Valid { return 0, "invalid-token", err - } else if claims.StandardClaims.ExpiresAt != 0 && claims.ExpiresAt < time.Now().Unix() { + } + if claims.ExpiresAt != nil && claims.ExpiresAt.Time.Before(time.Now()) { return 0, "expired", err - } else if !ok && token.Valid { - return 0, "invalid-token", err } - return claims.IDUser, "valid", err + return claims.UserID, "valid", err } func AuthUser(c *gin.Context) { var currAccData models.AccountData if c.Request.Header["Auth-Bearer-Token"] != nil { token := c.Request.Header["Auth-Bearer-Token"] - currAccData.IdUser, currAccData.VerifyStatus, currAccData.ErrVerif = VerifyToken(token[0]) + currAccData.UserID, currAccData.VerifyStatus, currAccData.ErrVerif = VerifyToken(token[0]) // fmt.Println("Verify Status :", currAccData.verifyStatus) if currAccData.VerifyStatus == "invalid-token" || currAccData.VerifyStatus == "expired" { - currAccData.IdUser = 0 + currAccData.UserID = 0 message := "Your session is expired, Please re-Login!" SendJSON401(c, &currAccData.VerifyStatus, &message) c.Abort() return } } else { - currAccData.IdUser = 0 + currAccData.UserID = 0 currAccData.VerifyStatus = "no-token" currAccData.ErrVerif = nil message := "You have to Login First!" diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/AccountRepository.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/AccountRepository.go index f191583a0de0f8ec9291985a06d40c00161522d0..41bd903aff7bf12c9d81cbed1ad00521ae629640 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/AccountRepository.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/AccountRepository.go @@ -1,7 +1,7 @@ package repositories import ( - "go-dp.abdanhafidz.com/models" + "api.qobiltu.id/models" ) func GetAccountbyEmail(email string) Repository[models.Account, models.Account] { diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/DatabaseScoope.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/DatabaseScoope.go index e11987b79a890dc6e84923fe7c241c6e8fa99c35..560945a97953d6c1bfef5db40b56cdab15024204 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/DatabaseScoope.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/DatabaseScoope.go @@ -1,5 +1,5 @@ package repositories -import "go-dp.abdanhafidz.com/config" +import "api.qobiltu.id/config" var db = config.DB diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/repositories.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/repositories.go index 9d34eda9880d655f8b4200d4792fff50fc144a54..3617e40936bf9e50e39a50285105622f080d210f 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/repositories.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/repositories.go @@ -1,7 +1,7 @@ package repositories import ( - "go-dp.abdanhafidz.com/config" + "api.qobiltu.id/config" "gorm.io/gorm" ) diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/router.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/router.go index 27ce310f782a252cab580d08873505f02ec38a03..114a87bb4eb5bd9713a0cd097c9b46f05eb761df 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/router.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/router.go @@ -1,9 +1,9 @@ package router import ( + "api.qobiltu.id/config" + "api.qobiltu.id/controller" "github.com/gin-gonic/gin" - "go-dp.abdanhafidz.com/config" - "go-dp.abdanhafidz.com/controller" ) func StartService() { diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/LoginService.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/LoginService.go index 21778c5b70ddeded49df2a7069057abe28fb7c5d..06ea6bb57e6ccdb5fa55784476af50fcda77eff1 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/LoginService.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/LoginService.go @@ -3,9 +3,9 @@ package services import ( "errors" - "go-dp.abdanhafidz.com/middleware" - "go-dp.abdanhafidz.com/models" - "go-dp.abdanhafidz.com/repositories" + "api.qobiltu.id/middleware" + "api.qobiltu.id/models" + "api.qobiltu.id/repositories" ) type LoginConstructor struct { diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/RegisterService.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/RegisterService.go index 106c30887c103cba810c602b4431fae9f0520d5d..6732f99fabbd315504042de844f59841294e2025 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/RegisterService.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/RegisterService.go @@ -3,10 +3,10 @@ package services import ( "errors" + "api.qobiltu.id/middleware" + "api.qobiltu.id/models" + "api.qobiltu.id/repositories" uuid "github.com/satori/go.uuid" - "go-dp.abdanhafidz.com/middleware" - "go-dp.abdanhafidz.com/models" - "go-dp.abdanhafidz.com/repositories" "gorm.io/gorm" ) diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/services.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/services.go index e684786fdd3dc071dd085b87f27a0e7bb8becfff..7d56d45d633a3e7fd485bc9348527494512a0a50 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/services.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/services.go @@ -1,6 +1,6 @@ package services -import "go-dp.abdanhafidz.com/models" +import "api.qobiltu.id/models" type ( Services interface { @@ -21,7 +21,7 @@ type ( ) func Construct[TConstructor any, TResult any](constructor ...TConstructor) *Service[TConstructor, TResult] { - if len(constructor) == 0 { + if len(constructor) == 1 { return &Service[TConstructor, TResult]{} } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/ExceptionModel.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/ExceptionModel.go index b4e76203056e9c2ee6ea5b447b6d3b90842f1d88..f2c026a993f950652158318977783e8563e595fb 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/ExceptionModel.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/ExceptionModel.go @@ -1,11 +1,12 @@ package models type Exception struct { - Unauthorized bool `json:"unauthorized,omitempty"` - BadRequest bool `json:"bad_request,omitempty"` - DataNotFound bool `json:"data_not_found,omitempty"` - InternalServerError bool `json:"internal_server_error,omitempty"` - DataDuplicate bool `json:"data_duplicate,omitempty"` - QueryError bool `json:"query_error,omitempty"` - Message string `json:"message,omitempty"` + Unauthorized bool `json:"unauthorized,omitempty"` + BadRequest bool `json:"bad_request,omitempty"` + DataNotFound bool `json:"data_not_found,omitempty"` + InternalServerError bool `json:"internal_server_error,omitempty"` + DataDuplicate bool `json:"data_duplicate,omitempty"` + QueryError bool `json:"query_error,omitempty"` + InvalidPasswordLength bool `json:"invalid_password_length,omitempty"` + Message string `json:"message,omitempty"` } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/RegisterService.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/RegisterService.go index 93acaba8cfa9364f620c1481dec0bf913e2bbfb5..106c30887c103cba810c602b4431fae9f0520d5d 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/RegisterService.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/RegisterService.go @@ -15,6 +15,11 @@ type RegisterService struct { } func (s *RegisterService) Create() { + if len(s.Constructor.Password) < 8 { + s.Exception.InvalidPasswordLength = true + s.Exception.Message = "Password must have at least 8 characters!" + return + } hashed_password, err_hash := middleware.HashPassword(s.Constructor.Password) s.Error = err_hash s.Constructor.Password = hashed_password diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/AccountRepository.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/AccountRepository.go index b868ad4c0353135ae0659d8fa9db3ead4f334eb8..f191583a0de0f8ec9291985a06d40c00161522d0 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/AccountRepository.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/AccountRepository.go @@ -4,9 +4,9 @@ import ( "go-dp.abdanhafidz.com/models" ) -func GetAccountbyEmailPassword(email string, password string) Repository[models.Account, models.Account] { +func GetAccountbyEmail(email string) Repository[models.Account, models.Account] { repo := Construct[models.Account, models.Account]( - models.Account{Email: email, Password: password}, + models.Account{Email: email}, ) repo.Transactions( WhereGivenConstructor[models.Account, models.Account], diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/repositories.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/repositories.go index 7a5c2816396cbb729fc1e0df162e9d0eea6ea42b..9d34eda9880d655f8b4200d4792fff50fc144a54 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/repositories.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/repositories.go @@ -1,8 +1,6 @@ package repositories import ( - "strconv" - "go-dp.abdanhafidz.com/config" "gorm.io/gorm" ) @@ -51,15 +49,10 @@ func Construct[TConstructor any, TResult any](constructor ...TConstructor) *Repo } } func (repo *Repository[T1, T2]) Transactions(transactions ...func(*Repository[T1, T2]) *gorm.DB) { - i := 1 for _, tx := range transactions { repo.Transaction = tx(repo) if repo.RowsError != nil { - repo.Transaction.Rollback() return - } else { - repo.Transaction.SavePoint("Save Point : " + strconv.Itoa(i)) - repo.Transaction.Commit() } } } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/LoginService.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/LoginService.go index f1bdc1d654ff34ce16ece776c45919bd3841b38d..21778c5b70ddeded49df2a7069057abe28fb7c5d 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/LoginService.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/LoginService.go @@ -18,7 +18,7 @@ type AuthenticationService struct { } func (s *AuthenticationService) Authenticate() { - accountData := repositories.GetAccountbyEmailPassword(s.Constructor.Email, s.Constructor.Password) + accountData := repositories.GetAccountbyEmail(s.Constructor.Email) if accountData.NoRecord { s.Exception.DataNotFound = true s.Exception.Message = "there is no account with given credentials!" diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/RegisterService.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/RegisterService.go index 8809621fac0e901ca8c058868b6318d0ad9470ca..93acaba8cfa9364f620c1481dec0bf913e2bbfb5 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/RegisterService.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/RegisterService.go @@ -3,6 +3,7 @@ package services import ( "errors" + uuid "github.com/satori/go.uuid" "go-dp.abdanhafidz.com/middleware" "go-dp.abdanhafidz.com/models" "go-dp.abdanhafidz.com/repositories" @@ -17,6 +18,7 @@ func (s *RegisterService) Create() { hashed_password, err_hash := middleware.HashPassword(s.Constructor.Password) s.Error = err_hash s.Constructor.Password = hashed_password + s.Constructor.UUID = uuid.NewV4() accountCreated := repositories.CreateAccount(s.Constructor) if errors.Is(accountCreated.RowsError, gorm.ErrDuplicatedKey) { s.Exception.DataDuplicate = true diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.mod b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.mod index efe450181fc1f3927c0b6658778233ce43ac1d76..f6d85920f3d50bf7a3fc013a4ee8875237b0e108 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.mod +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.mod @@ -36,6 +36,7 @@ require ( github.com/modern-go/reflect2 v1.0.2 // indirect github.com/pelletier/go-toml/v2 v2.1.0 // indirect github.com/rogpeppe/go-internal v1.11.0 // indirect + github.com/satori/go.uuid v1.2.0 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.11 // indirect golang.org/x/arch v0.6.0 // indirect diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.sum b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.sum index 79ffaec719b95b12a37e3a787b1576ef5a53db03..a82e88494d1f86d0560792cace9c2a61284c1d8a 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.sum +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.sum @@ -79,6 +79,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= +github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww= +github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/RegisterController.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/RegisterController.go index 25244306baf7b5ff373c0e1c925c584740710eee..e3375ba58212ddd73d2d4e29fbf67d247e89398b 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/RegisterController.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/RegisterController.go @@ -11,9 +11,9 @@ func RegisterController(c *gin.Context) { registerController := Controller[models.RegisterRequest, models.Account, models.Account]{ Service: ®ister.Service, } - registerController.RequestJSON(c) - registerController.Service.Constructor.Password = registerController.Request.Password - registerController.Service.Constructor.Email = registerController.Request.Email - register.Create() - registerController.Response(c) + registerController.RequestJSON(c, func() { + registerController.Service.Constructor.Password = registerController.Request.Password + registerController.Service.Constructor.Email = registerController.Request.Email + register.Create() + }) } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/DatabaseModel.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/DatabaseModel.go index 355323a487ca5c8fc593a1bdea525f30081b884d..b2f38ee65f5094a7311928d1567e5263d87f9c7a 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/DatabaseModel.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/DatabaseModel.go @@ -2,14 +2,18 @@ package models import ( "time" + + uuid "github.com/satori/go.uuid" ) type Account struct { - Id uint `gorm:"primaryKey" json:"id"` - Email string `gorm:"primaryKey" json:"email"` - Password string `json:"password"` - CreatedAt time.Time `json:"created_at"` - DeletedAt time.Time `json:"deleted_at"` + Id uint `gorm:"primaryKey" json:"id"` + UUID uuid.UUID `gorm:"type:uuid" json:"uuid" ` + Email string `gorm:"uniqueIndex" json:"email"` + Password string `json:"password"` + IsEmailVerified bool `json:"is_email_verified"` + CreatedAt time.Time `json:"created_at"` + DeletedAt time.Time `json:"deleted_at"` } type AccountDetails struct { @@ -22,6 +26,14 @@ type AccountDetails struct { DeletedAt time.Time `json:"deleted_at"` } +type EmailVerification struct { + Id int `gorm:"primaryKey" json:"id"` + AccountId int `json:"account_id"` + UUID uuid.UUID `gorm:"type:uuid" json:"uuid" ` + CreatedAt time.Time `json:"created_at"` + ExpiredAt time.Time `json:"expired_at"` +} + // Gorm table name settings func (Account) TableName() string { return "account" } func (AccountDetails) TableName() string { return "account_details" } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/AccountRepository.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/AccountRepository.go index 9243b47af1fc1184b20eae52a1300010764f5bab..b868ad4c0353135ae0659d8fa9db3ead4f334eb8 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/AccountRepository.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/AccountRepository.go @@ -8,7 +8,10 @@ func GetAccountbyEmailPassword(email string, password string) Repository[models. repo := Construct[models.Account, models.Account]( models.Account{Email: email, Password: password}, ) - Find(repo) + repo.Transactions( + WhereGivenConstructor[models.Account, models.Account], + Find[models.Account, models.Account], + ) return *repo } @@ -16,7 +19,6 @@ func CreateAccount(account models.Account) Repository[models.Account, models.Acc repo := Construct[models.Account, models.Account]( account, ) - Create(repo) return *repo } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/repositories.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/repositories.go index 767e3d93bb01248012ed0a89768db740be5157c9..7a5c2816396cbb729fc1e0df162e9d0eea6ea42b 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/repositories.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/repositories.go @@ -1,6 +1,8 @@ package repositories import ( + "strconv" + "go-dp.abdanhafidz.com/config" "gorm.io/gorm" ) @@ -56,52 +58,63 @@ func (repo *Repository[T1, T2]) Transactions(transactions ...func(*Repository[T1 repo.Transaction.Rollback() return } else { - repo.Transaction.SavePoint("Save Point : " + string(i)) + repo.Transaction.SavePoint("Save Point : " + strconv.Itoa(i)) repo.Transaction.Commit() } } } func WhereGivenConstructor[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB { tx := repo.Transaction.Where(&repo.Constructor) - repo.RowsError = repo.Transaction.Error + repo.RowsCount = int(tx.RowsAffected) + repo.NoRecord = repo.RowsCount == 0 repo.RowsError = tx.Error return tx } func Find[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB { tx := repo.Transaction.Find(&repo.Result) - repo.RowsError = repo.Transaction.Error + repo.RowsCount = int(tx.RowsAffected) + repo.NoRecord = repo.RowsCount == 0 repo.RowsError = tx.Error return tx } func FinddAllPaginate[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB { tx := repo.Transaction.Limit(repo.Pagination.Limit).Offset(repo.Pagination.Offset).Find(&repo.Result) + repo.RowsCount = int(tx.RowsAffected) + repo.NoRecord = repo.RowsCount == 0 repo.RowsError = tx.Error return tx } func Create[T1 any](repo *Repository[T1, T1]) *gorm.DB { tx := repo.Transaction.Create(&repo.Constructor) - repo.Result = repo.Constructor + repo.RowsCount = int(tx.RowsAffected) + repo.NoRecord = repo.RowsCount == 0 repo.RowsError = tx.Error + repo.Result = repo.Constructor return tx } func Update[T1 any](repo *Repository[T1, T1]) *gorm.DB { tx := repo.Transaction.Save(&repo.Constructor) - repo.Result = repo.Constructor + repo.RowsCount = int(tx.RowsAffected) + repo.NoRecord = repo.RowsCount == 0 repo.RowsError = tx.Error return tx } func Delete[T1 any](repo *Repository[T1, T1]) *gorm.DB { tx := repo.Transaction.Delete(&repo.Constructor) + repo.RowsCount = int(tx.RowsAffected) + repo.NoRecord = repo.RowsCount == 0 repo.RowsError = tx.Error return tx } func CustomQuery[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB { tx := repo.Transaction.Raw(repo.CustomQuery.SQL, repo.CustomQuery.Values).Scan(&repo.Result) + repo.RowsCount = int(tx.RowsAffected) + repo.NoRecord = repo.RowsCount == 0 repo.RowsError = tx.Error return tx } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/LoginService.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/LoginService.go index 2d734758bcd0ea31246376da2e71187be98d81ca..f1bdc1d654ff34ce16ece776c45919bd3841b38d 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/LoginService.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/LoginService.go @@ -21,10 +21,9 @@ func (s *AuthenticationService) Authenticate() { accountData := repositories.GetAccountbyEmailPassword(s.Constructor.Email, s.Constructor.Password) if accountData.NoRecord { s.Exception.DataNotFound = true - s.Exception.Message = "there is no account with given email!" + s.Exception.Message = "there is no account with given credentials!" return } - if middleware.VerifyPassword(accountData.Result.Password, s.Constructor.Password) != nil { s.Exception.Unauthorized = true s.Exception.Message = "incorrect password!" diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/RegisterService.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/RegisterService.go index 0aca7d7de67105b79deaf19685ec9414df3f5d45..8809621fac0e901ca8c058868b6318d0ad9470ca 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/RegisterService.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/RegisterService.go @@ -2,7 +2,6 @@ package services import ( "errors" - "fmt" "go-dp.abdanhafidz.com/middleware" "go-dp.abdanhafidz.com/models" @@ -15,12 +14,10 @@ type RegisterService struct { } func (s *RegisterService) Create() { - hashed_password, _ := middleware.HashPassword(s.Constructor.Password) + hashed_password, err_hash := middleware.HashPassword(s.Constructor.Password) + s.Error = err_hash s.Constructor.Password = hashed_password accountCreated := repositories.CreateAccount(s.Constructor) - - // fmt.Println("Error :", accountCreated.RowsError.Error()) - fmt.Println(errors.Is(accountCreated.RowsError, gorm.ErrDuplicatedKey)) if errors.Is(accountCreated.RowsError, gorm.ErrDuplicatedKey) { s.Exception.DataDuplicate = true s.Exception.Message = "Account with email " + s.Constructor.Email + " already exists!" @@ -30,7 +27,7 @@ func (s *RegisterService) Create() { s.Exception.Message = "Bad request!" return } - + s.Error = accountCreated.RowsError s.Result = accountCreated.Result s.Result.Password = "SECRET" } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/LoginController.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/LoginController.go index 78d94dcb74fe945b45f4491f85d9b3784a6947a1..6d04567f7a776399c5faafc4f11dff4c0735ae9a 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/LoginController.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/LoginController.go @@ -8,12 +8,12 @@ import ( func LoginController(c *gin.Context) { authentication := services.AuthenticationService{} - loginController := Controller[models.LoginRequest, services.LoginConstructor, models.Account]{ + loginController := Controller[models.LoginRequest, services.LoginConstructor, models.AuthenticatedUser]{ Service: &authentication.Service, } - loginController.RequestJSON(c) - loginController.Service.Constructor.Email = loginController.Request.Email - loginController.Service.Constructor.Password = loginController.Request.Password - authentication.Authenticate() - loginController.Response(c) + loginController.RequestJSON(c, func() { + loginController.Service.Constructor.Email = loginController.Request.Email + loginController.Service.Constructor.Password = loginController.Request.Password + authentication.Authenticate() + }) } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/controller.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/controller.go index aba28ae8d9d64b8bb62cda08de9658163b038602..fa14d0b2c6ed4e25a72839a3fad18b2d59e40af3 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/controller.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/controller.go @@ -19,7 +19,7 @@ type ( } ) -func (controller *Controller[T1, T2, T3]) RequestJSON(c *gin.Context) { +func (controller *Controller[T1, T2, T3]) RequestJSON(c *gin.Context, act func()) { cParam, _ := c.Get("accountData") if cParam != nil { controller.AccountData = cParam.(models.AccountData) @@ -28,9 +28,12 @@ func (controller *Controller[T1, T2, T3]) RequestJSON(c *gin.Context) { if errBinding != nil { utils.ResponseFAIL(c, 400, models.Exception{ BadRequest: true, - Message: "Invalid Request Type", + Message: "Invalid Request!, recheck your request, there's must be some problem about required parameter or type parameter", }) return + } else { + act() + controller.Response(c) } } func (controller *Controller[T1, T2, T3]) Response(c *gin.Context) { @@ -41,6 +44,8 @@ func (controller *Controller[T1, T2, T3]) Response(c *gin.Context) { Message: "Internal Server Error", }) utils.LogError(controller.Service.Error) + case controller.Service.Exception.DataDuplicate: + utils.ResponseFAIL(c, 400, controller.Service.Exception) case controller.Service.Exception.Unauthorized: utils.ResponseFAIL(c, 401, controller.Service.Exception) case controller.Service.Exception.DataNotFound: diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/AuthMiddleware.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/AuthMiddleware.go index 6dc04aa18ba75ef21252e87baf23c0158cc3daea..c153979ac01f108193541d23f821c288b4752f01 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/AuthMiddleware.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/AuthMiddleware.go @@ -25,7 +25,7 @@ func GenerateToken(user *models.Account) (string, error) { // Set claims claims := token.Claims.(jwt.MapClaims) - claims["id"] = user.IDAccount + claims["id"] = user.Id claims["exp"] = time.Now().Add(time.Hour * 24).Unix() // Token expires in 24 hours // Sign the token with the secret key diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/DatabaseModel.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/DatabaseModel.go index f048c17a9838438555d6fd795e6c7617c2c1b729..355323a487ca5c8fc593a1bdea525f30081b884d 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/DatabaseModel.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/DatabaseModel.go @@ -5,14 +5,11 @@ import ( ) type Account struct { - IDAccount uint `gorm:"primaryKey" json:"id_account"` - Name string `json:"name"` - Username string `json:"username"` - Email string `json:"email"` - Password string `json:"password"` - PhoneNumber int `json:"phone_number"` - CreatedAt time.Time `json:"created_at"` - DeletedAt time.Time `json:"deleted_at"` + Id uint `gorm:"primaryKey" json:"id"` + Email string `gorm:"primaryKey" json:"email"` + Password string `json:"password"` + CreatedAt time.Time `json:"created_at"` + DeletedAt time.Time `json:"deleted_at"` } type AccountDetails struct { diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/ResponseModel.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/ResponseModel.go index 9ce401186cb92d50737155815c1f511164b86407..cd7b65b6a4ffd53ca1cc3c430abf0b256d0a4936 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/ResponseModel.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/ResponseModel.go @@ -1 +1,6 @@ package models + +type AuthenticatedUser struct { + Account Account `json:"account"` + Token string `json:"token"` +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/AccountRepository.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/AccountRepository.go index 79e43f0707a436c344e5cddd53187d428274bde9..9243b47af1fc1184b20eae52a1300010764f5bab 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/AccountRepository.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/AccountRepository.go @@ -1,24 +1,22 @@ package repositories import ( - "fmt" - "go-dp.abdanhafidz.com/models" ) -func GetAccountbyEmailPassword(username string, password string) Repository[models.Account, models.Account] { +func GetAccountbyEmailPassword(email string, password string) Repository[models.Account, models.Account] { repo := Construct[models.Account, models.Account]( - models.Account{Username: username, Password: password}, + models.Account{Email: email, Password: password}, ) Find(repo) return *repo } func CreateAccount(account models.Account) Repository[models.Account, models.Account] { - fmt.Println(account) repo := Construct[models.Account, models.Account]( account, ) + Create(repo) return *repo } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/repositories.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/repositories.go index c82f550472331b9b8d0f5d4cdcf5aab441e5cdfa..767e3d93bb01248012ed0a89768db740be5157c9 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/repositories.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/repositories.go @@ -1,8 +1,6 @@ package repositories import ( - "fmt" - "go-dp.abdanhafidz.com/config" "gorm.io/gorm" ) @@ -39,7 +37,6 @@ type Repository[TConstructor any, TResult any] struct { } func Construct[TConstructor any, TResult any](constructor ...TConstructor) *Repository[TConstructor, TResult] { - fmt.Println("Len = ", len(constructor)) if len(constructor) == 1 { return &Repository[TConstructor, TResult]{ Constructor: constructor[0], @@ -51,11 +48,10 @@ func Construct[TConstructor any, TResult any](constructor ...TConstructor) *Repo Transaction: config.DB.Begin(), } } -func (repo *Repository[T1, T2]) Transactions(transactions ...func(*Repository[T1, T2])) { +func (repo *Repository[T1, T2]) Transactions(transactions ...func(*Repository[T1, T2]) *gorm.DB) { i := 1 for _, tx := range transactions { - tx(repo) - repo.RowsError = repo.Transaction.Error + repo.Transaction = tx(repo) if repo.RowsError != nil { repo.Transaction.Rollback() return @@ -65,32 +61,47 @@ func (repo *Repository[T1, T2]) Transactions(transactions ...func(*Repository[T1 } } } -func WhereGivenConstructor[T1 any, T2 any](repo *Repository[T1, T2]) { - repo.Transaction.Where(&repo.Constructor) +func WhereGivenConstructor[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB { + tx := repo.Transaction.Where(&repo.Constructor) + repo.RowsError = repo.Transaction.Error + repo.RowsError = tx.Error + return tx } -func Find[T1 any, T2 any](repo *Repository[T1, T2]) { - repo.Transaction.Find(&repo.Result) +func Find[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB { + tx := repo.Transaction.Find(&repo.Result) + repo.RowsError = repo.Transaction.Error + repo.RowsError = tx.Error + return tx } -func FinddAllPaginate[T1 any, T2 any](repo *Repository[T1, T2]) { - repo.Transaction.Limit(repo.Pagination.Limit).Offset(repo.Pagination.Offset).Find(&repo.Result) +func FinddAllPaginate[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB { + tx := repo.Transaction.Limit(repo.Pagination.Limit).Offset(repo.Pagination.Offset).Find(&repo.Result) + repo.RowsError = tx.Error + return tx } -func Create[T1 any](repo *Repository[T1, T1]) { - fmt.Println(repo.Constructor) - repo.Transaction.Create(&repo.Constructor) +func Create[T1 any](repo *Repository[T1, T1]) *gorm.DB { + tx := repo.Transaction.Create(&repo.Constructor) repo.Result = repo.Constructor + repo.RowsError = tx.Error + return tx } -func Update[T1 any](repo *Repository[T1, T1]) { - repo.Transaction.Save(&repo.Constructor) +func Update[T1 any](repo *Repository[T1, T1]) *gorm.DB { + tx := repo.Transaction.Save(&repo.Constructor) repo.Result = repo.Constructor + repo.RowsError = tx.Error + return tx } -func Delete[T1 any](repo *Repository[T1, T1]) { - repo.Transaction.Delete(&repo.Constructor) +func Delete[T1 any](repo *Repository[T1, T1]) *gorm.DB { + tx := repo.Transaction.Delete(&repo.Constructor) + repo.RowsError = tx.Error + return tx } -func CustomQuery[T1 any, T2 any](repo *Repository[T1, T2]) { - repo.Transaction.Raw(repo.CustomQuery.SQL, repo.CustomQuery.Values).Scan(&repo.Result) +func CustomQuery[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB { + tx := repo.Transaction.Raw(repo.CustomQuery.SQL, repo.CustomQuery.Values).Scan(&repo.Result) + repo.RowsError = tx.Error + return tx } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/LoginService.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/LoginService.go index e798298cb58036f0b00cc04a919500d6b9c83c09..2d734758bcd0ea31246376da2e71187be98d81ca 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/LoginService.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/LoginService.go @@ -1,6 +1,8 @@ package services import ( + "errors" + "go-dp.abdanhafidz.com/middleware" "go-dp.abdanhafidz.com/models" "go-dp.abdanhafidz.com/repositories" @@ -12,7 +14,7 @@ type LoginConstructor struct { } type AuthenticationService struct { - Service[LoginConstructor, models.Account] + Service[LoginConstructor, models.AuthenticatedUser] } func (s *AuthenticationService) Authenticate() { @@ -29,7 +31,17 @@ func (s *AuthenticationService) Authenticate() { return } - s.Result = accountData.Result + token, err_tok := middleware.GenerateToken(&accountData.Result) + + if err_tok != nil { + s.Error = errors.Join(s.Error, err_tok) + } + + accountData.Result.Password = "SECRET" + s.Result = models.AuthenticatedUser{ + Account: accountData.Result, + Token: token, + } s.Error = accountData.RowsError } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/RegisterService.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/RegisterService.go index 615a3a595a056802ecd6e130c8f0f04be2643d05..0aca7d7de67105b79deaf19685ec9414df3f5d45 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/RegisterService.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/RegisterService.go @@ -2,6 +2,7 @@ package services import ( "errors" + "fmt" "go-dp.abdanhafidz.com/middleware" "go-dp.abdanhafidz.com/models" @@ -17,15 +18,19 @@ func (s *RegisterService) Create() { hashed_password, _ := middleware.HashPassword(s.Constructor.Password) s.Constructor.Password = hashed_password accountCreated := repositories.CreateAccount(s.Constructor) + + // fmt.Println("Error :", accountCreated.RowsError.Error()) + fmt.Println(errors.Is(accountCreated.RowsError, gorm.ErrDuplicatedKey)) if errors.Is(accountCreated.RowsError, gorm.ErrDuplicatedKey) { s.Exception.DataDuplicate = true - s.Exception.Message = "There is account registered with given data!" + s.Exception.Message = "Account with email " + s.Constructor.Email + " already exists!" return } 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) { s.Exception.BadRequest = true s.Exception.Message = "Bad request!" return } + s.Result = accountCreated.Result s.Result.Password = "SECRET" } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/Dockerfile b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/Dockerfile index 7d4a695141f39c703c8e6188f6a2b6eba686d624..6183c94745bf456bad5ea308482bd6c3602ad543 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/Dockerfile +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/Dockerfile @@ -21,8 +21,8 @@ RUN echo "DB_HOST=aws-0-ap-southeast-1.pooler.supabase.com" >> .env && \ echo "DB_NAME=postgres" >> .env && \ echo "HOST_ADDRESS = 0.0.0.0" >> .env && \ echo "HOST_PORT = 7860" >> .env && \ - echo "SALT=NZNZtY7dNPz8l0dWINJZLKafWaJrql1s" >> .env - echo "LOG_PATH = logs" + echo "SALT=NZNZtY7dNPz8l0dWINJZLKafWaJrql1s" >> .env && \ + echo "LOG_PATH = logs" >> .env # Build aplikasi RUN go build -o main . diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/.env.example b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/.env.example new file mode 100644 index 0000000000000000000000000000000000000000..7a13c9d5665f68dc7087f208910958eb620cc5c6 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/.env.example @@ -0,0 +1,9 @@ +DB_HOST = +DB_USER = +DB_PASSWORD = +DB_PORT = +DB_NAME = +SALT = +HOST_ADDRESS = +HOST_PORT = +LOG_PATH = logs \ No newline at end of file diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/.github/workflows/main.yml b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/.github/workflows/main.yml new file mode 100644 index 0000000000000000000000000000000000000000..39a67571ac3a2e6a6e2a972b9550becd551bdded --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/.github/workflows/main.yml @@ -0,0 +1,52 @@ +name: Deploy to Development via Huggingface + +on: + push: + branches: + - main + +jobs: + deploy-to-huggingface: + runs-on: ubuntu-latest + + steps: + # Checkout repository + - name: Checkout Repository + uses: actions/checkout@v3 + + # Setup Git + - name: Setup Git for Huggingface + run: | + git config --global user.email "abdan.hafidz@gmail.com" + git config --global user.name "abdanhafidz" + + # Clone Huggingface Space Repository + - name: Clone Huggingface Space + env: + HF_TOKEN: ${{ secrets.HF_TOKEN }} + run: | + git clone https://huggingface.co/spaces/lifedebugger/api-qobiltu-dev space + + # Update Git Remote URL and Pull Latest Changes + - name: Update Remote and Pull Changes + env: + HF_TOKEN: ${{ secrets.HF_TOKEN }} + run: | + cd space + git remote set-url origin https://lifedebugger:$HF_TOKEN@huggingface.co/spaces/lifedebugger/api-qobiltu-dev + git pull origin main || echo "No changes to pull" + + # Copy Files to Huggingface Space + - name: Copy Files to Space + run: | + rsync -av --exclude='.git' ./ space/ + + # Commit and Push to Huggingface Space + - name: Commit and Push to Huggingface + env: + HF_TOKEN: ${{ secrets.HF_TOKEN }} + run: | + cd space + git add . + git commit -m "Deploy files from GitHub repository" || echo "No changes to commit" + git push origin main || echo "No changes to push" diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/.gitignore b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..deeb9479f4cb982ccd42fa0d7210b9777509e4ae --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/.gitignore @@ -0,0 +1,3 @@ +.env +vendor/ +quzuu-be.exe \ No newline at end of file diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/Dockerfile b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..7d4a695141f39c703c8e6188f6a2b6eba686d624 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/Dockerfile @@ -0,0 +1,30 @@ +# Gunakan image dasar Golang versi 1.21.6 +FROM golang:1.21.6 + +# Set working directory +WORKDIR /app + +# Copy go.mod dan go.sum +COPY go.mod go.sum ./ + +# Download dependencies +RUN go mod download + +# Copy seluruh kode +COPY . . + +# Buat file .env dengan variabel environment yang dibutuhkan +RUN echo "DB_HOST=aws-0-ap-southeast-1.pooler.supabase.com" >> .env && \ + echo "DB_USER=postgres.rdscploxoikqsevhduii" >> .env && \ + echo "DB_PASSWORD=Qobiltu12233334444" >> .env && \ + echo "DB_PORT=5432" >> .env && \ + echo "DB_NAME=postgres" >> .env && \ + echo "HOST_ADDRESS = 0.0.0.0" >> .env && \ + echo "HOST_PORT = 7860" >> .env && \ + echo "SALT=NZNZtY7dNPz8l0dWINJZLKafWaJrql1s" >> .env + echo "LOG_PATH = logs" +# Build aplikasi +RUN go build -o main . + +# Jalankan aplikasi +CMD ["./main"] diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/config/DatabaseConfig.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/config/DatabaseConfig.go new file mode 100644 index 0000000000000000000000000000000000000000..7dfa116ec7152e6338c764ce5853ad21782bd26f --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/config/DatabaseConfig.go @@ -0,0 +1,60 @@ +package config + +import ( + "fmt" + "log" + "os" + + "gorm.io/driver/postgres" + "gorm.io/gorm" + "gorm.io/gorm/logger" + + "github.com/joho/godotenv" + "go-dp.abdanhafidz.com/models" +) + +func AutoMigrateAll(db *gorm.DB) { + // Enable logger to see SQL logs + db.Logger.LogMode(logger.Info) + + // Auto-migrate all models + err := db.AutoMigrate( + &models.Account{}, + &models.AccountDetails{}, + ) + if err != nil { + log.Fatal(err) + } + + fmt.Println("Migration completed successfully.") +} + +var DB *gorm.DB +var err error +var Salt string + +func init() { + godotenv.Load() + if err != nil { + fmt.Println("Gagal membaca file .env") + return + } + os.Setenv("TZ", "Asia/Jakarta") + dbHost := os.Getenv("DB_HOST") + dbPort := os.Getenv("DB_PORT") + dbUser := os.Getenv("DB_USER") + dbPassword := os.Getenv("DB_PASSWORD") + dbName := os.Getenv("DB_NAME") + Salt := os.Getenv("SALT") + dsn := "host=" + dbHost + " user=" + dbUser + " password=" + dbPassword + " dbname=" + dbName + " port=" + dbPort + " sslmode=disable TimeZone=Asia/Jakarta" + DB, err = gorm.Open(postgres.Open(dsn), &gorm.Config{TranslateError: true}) + if err != nil { + panic(err) + } + if Salt == "" { + Salt = "D3f4u|t" + } + + // Call AutoMigrateAll to perform auto-migration + AutoMigrateAll(DB) +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/config/EnvConfig.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/config/EnvConfig.go new file mode 100644 index 0000000000000000000000000000000000000000..ae4a686c65b851a6e8d960b47a77e4c67470c615 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/config/EnvConfig.go @@ -0,0 +1,16 @@ +package config + +import "os" + +var TCP_ADDRESS string +var LOG_PATH string +var HOST_ADDRESS string +var HOST_PORT string + +func init() { + HOST_ADDRESS = os.Getenv("HOST_ADDRESS") + HOST_PORT = os.Getenv("HOST_PORT") + TCP_ADDRESS = HOST_ADDRESS + ":" + HOST_PORT + LOG_PATH = os.Getenv("LOG_PATH") + // Menampilkan nilai variabel lingkungan +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/HomeController.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/HomeController.go new file mode 100644 index 0000000000000000000000000000000000000000..06cfc3d7fac0385d6aef847a186de2eae7dbb4bb --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/HomeController.go @@ -0,0 +1,9 @@ +package controller + +import "github.com/gin-gonic/gin" + +func HomeController(c *gin.Context) { + c.JSON(200, gin.H{ + "message": "Api Qobiltu 2025!", + }) +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/LoginController.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/LoginController.go new file mode 100644 index 0000000000000000000000000000000000000000..78d94dcb74fe945b45f4491f85d9b3784a6947a1 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/LoginController.go @@ -0,0 +1,19 @@ +package controller + +import ( + "github.com/gin-gonic/gin" + "go-dp.abdanhafidz.com/models" + "go-dp.abdanhafidz.com/services" +) + +func LoginController(c *gin.Context) { + authentication := services.AuthenticationService{} + loginController := Controller[models.LoginRequest, services.LoginConstructor, models.Account]{ + Service: &authentication.Service, + } + loginController.RequestJSON(c) + loginController.Service.Constructor.Email = loginController.Request.Email + loginController.Service.Constructor.Password = loginController.Request.Password + authentication.Authenticate() + loginController.Response(c) +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/RegisterController.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/RegisterController.go new file mode 100644 index 0000000000000000000000000000000000000000..25244306baf7b5ff373c0e1c925c584740710eee --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/RegisterController.go @@ -0,0 +1,19 @@ +package controller + +import ( + "github.com/gin-gonic/gin" + "go-dp.abdanhafidz.com/models" + "go-dp.abdanhafidz.com/services" +) + +func RegisterController(c *gin.Context) { + register := services.RegisterService{} + registerController := Controller[models.RegisterRequest, models.Account, models.Account]{ + Service: ®ister.Service, + } + registerController.RequestJSON(c) + registerController.Service.Constructor.Password = registerController.Request.Password + registerController.Service.Constructor.Email = registerController.Request.Email + register.Create() + registerController.Response(c) +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/controller.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/controller.go new file mode 100644 index 0000000000000000000000000000000000000000..aba28ae8d9d64b8bb62cda08de9658163b038602 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/controller/controller.go @@ -0,0 +1,53 @@ +package controller + +import ( + "github.com/gin-gonic/gin" + "go-dp.abdanhafidz.com/models" + "go-dp.abdanhafidz.com/services" + "go-dp.abdanhafidz.com/utils" +) + +type ( + Controllers interface { + RequestJSON(c *gin.Context) + Response(c *gin.Context) + } + Controller[T1 any, T2 any, T3 any] struct { + AccountData models.AccountData + Request T1 + Service *services.Service[T2, T3] + } +) + +func (controller *Controller[T1, T2, T3]) RequestJSON(c *gin.Context) { + cParam, _ := c.Get("accountData") + if cParam != nil { + controller.AccountData = cParam.(models.AccountData) + } + errBinding := c.ShouldBindJSON(&controller.Request) + if errBinding != nil { + utils.ResponseFAIL(c, 400, models.Exception{ + BadRequest: true, + Message: "Invalid Request Type", + }) + return + } +} +func (controller *Controller[T1, T2, T3]) Response(c *gin.Context) { + switch { + case controller.Service.Error != nil: + utils.ResponseFAIL(c, 500, models.Exception{ + InternalServerError: true, + Message: "Internal Server Error", + }) + utils.LogError(controller.Service.Error) + case controller.Service.Exception.Unauthorized: + utils.ResponseFAIL(c, 401, controller.Service.Exception) + case controller.Service.Exception.DataNotFound: + utils.ResponseFAIL(c, 404, controller.Service.Exception) + case controller.Service.Exception.Message != "": + utils.ResponseFAIL(c, 400, controller.Service.Exception) + default: + utils.ResponseOK(c, controller.Service.Result) + } +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.mod b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.mod new file mode 100644 index 0000000000000000000000000000000000000000..efe450181fc1f3927c0b6658778233ce43ac1d76 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.mod @@ -0,0 +1,48 @@ +module go-dp.abdanhafidz.com + +go 1.21.0 + +require ( + github.com/dgrijalva/jwt-go v3.2.0+incompatible + github.com/gin-gonic/gin v1.9.1 + github.com/joho/godotenv v1.5.1 + golang.org/x/crypto v0.32.0 + gorm.io/driver/postgres v1.5.4 + gorm.io/gorm v1.25.5 +) + +require ( + github.com/bytedance/sonic v1.10.2 // indirect + github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect + github.com/chenzhuoyu/iasm v0.9.0 // indirect + github.com/gabriel-vasile/mimetype v1.4.8 // indirect + github.com/gin-contrib/sse v0.1.0 // indirect + github.com/go-playground/locales v0.14.1 // indirect + github.com/go-playground/universal-translator v0.18.1 // indirect + github.com/go-playground/validator/v10 v10.25.0 // indirect + github.com/goccy/go-json v0.10.2 // indirect + github.com/jackc/pgpassfile v1.0.0 // indirect + github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect + github.com/jackc/pgx/v5 v5.5.0 // indirect + github.com/jackc/puddle/v2 v2.2.1 // indirect + github.com/jinzhu/inflection v1.0.0 // indirect + github.com/jinzhu/now v1.1.5 // indirect + github.com/json-iterator/go v1.1.12 // indirect + github.com/klauspost/cpuid/v2 v2.2.6 // indirect + github.com/kr/text v0.2.0 // indirect + github.com/leodido/go-urn v1.4.0 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/pelletier/go-toml/v2 v2.1.0 // indirect + github.com/rogpeppe/go-internal v1.11.0 // indirect + github.com/twitchyliquid64/golang-asm v0.15.1 // indirect + github.com/ugorji/go/codec v1.2.11 // indirect + golang.org/x/arch v0.6.0 // indirect + golang.org/x/net v0.34.0 // indirect + golang.org/x/sync v0.10.0 // indirect + golang.org/x/sys v0.29.0 // indirect + golang.org/x/text v0.21.0 // indirect + google.golang.org/protobuf v1.31.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.sum b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.sum new file mode 100644 index 0000000000000000000000000000000000000000..79ffaec719b95b12a37e3a787b1576ef5a53db03 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/go.sum @@ -0,0 +1,138 @@ +github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= +github.com/bytedance/sonic v1.10.0-rc/go.mod h1:ElCzW+ufi8qKqNW0FY314xriJhyJhuoJ3gFZdAHF7NM= +github.com/bytedance/sonic v1.10.2 h1:GQebETVBxYB7JGWJtLBi07OVzWwt+8dWA00gEVW2ZFE= +github.com/bytedance/sonic v1.10.2/go.mod h1:iZcSUejdk5aukTND/Eu/ivjQuEL0Cu9/rf50Hi0u/g4= +github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= +github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= +github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d h1:77cEq6EriyTZ0g/qfRdp61a3Uu/AWrgIq2s0ClJV1g0= +github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d/go.mod h1:8EPpVsBuRksnlj1mLy4AWzRNQYxauNi62uWcE3to6eA= +github.com/chenzhuoyu/iasm v0.9.0 h1:9fhXjVzq5hUy2gkhhgHl95zG2cEAhw9OSGs8toWWAwo= +github.com/chenzhuoyu/iasm v0.9.0/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= +github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= +github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= +github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= +github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM= +github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8= +github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= +github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= +github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg= +github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU= +github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= +github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= +github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= +github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= +github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= +github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= +github.com/go-playground/validator/v10 v10.16.0 h1:x+plE831WK4vaKHO/jpgUGsvLKIqRRkz6M78GuJAfGE= +github.com/go-playground/validator/v10 v10.16.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= +github.com/go-playground/validator/v10 v10.25.0 h1:5Dh7cjvzR7BRZadnsVOzPhWsrwUr0nmsZJxEAnFLNO8= +github.com/go-playground/validator/v10 v10.25.0/go.mod h1:GGzBIJMuE98Ic/kJsBXbz1x/7cByt++cQ+YOuDM5wus= +github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= +github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= +github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= +github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk= +github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= +github.com/jackc/pgx/v5 v5.5.0 h1:NxstgwndsTRy7eq9/kqYc/BZh5w2hHJV86wjvO+1xPw= +github.com/jackc/pgx/v5 v5.5.0/go.mod h1:Ig06C2Vu0t5qXC60W8sqIthScaEnFvojjj9dSljmHRA= +github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk= +github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= +github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= +github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= +github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= +github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= +github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= +github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= +github.com/klauspost/cpuid/v2 v2.2.6 h1:ndNyv040zDGIDh8thGkXYjnFtiN02M1PVVF+JE/48xc= +github.com/klauspost/cpuid/v2 v2.2.6/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= +github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= +github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= +github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= +github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= +github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= +github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4= +github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= +github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= +github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= +github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU= +github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= +golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= +golang.org/x/arch v0.6.0 h1:S0JTfE48HbRj80+4tbvZDYsJ3tGv6BUU3XxyZ7CirAc= +golang.org/x/arch v0.6.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= +golang.org/x/crypto v0.15.0 h1:frVn1TEaCEaZcn3Tmd7Y2b5KKPaZ+I32Q2OA3kYp5TA= +golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g= +golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc= +golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc= +golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg= +golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ= +golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0= +golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k= +golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ= +golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= +golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU= +golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= +golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= +google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gorm.io/driver/postgres v1.5.4 h1:Iyrp9Meh3GmbSuyIAGyjkN+n9K+GHX9b9MqsTL4EJCo= +gorm.io/driver/postgres v1.5.4/go.mod h1:Bgo89+h0CRcdA33Y6frlaHHVuTdOf87pmyzwW9C/BH0= +gorm.io/gorm v1.25.5 h1:zR9lOiiYf09VNh5Q1gphfyia1JpiClIWG9hQaxB/mls= +gorm.io/gorm v1.25.5/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8= +nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= +rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/main.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/main.go new file mode 100644 index 0000000000000000000000000000000000000000..d89532891b559d7d8361e79a1090e77a31cafb95 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/main.go @@ -0,0 +1,14 @@ +package main + +import ( + "fmt" + + "go-dp.abdanhafidz.com/config" + "go-dp.abdanhafidz.com/router" +) + +func main() { + fmt.Println("Server started on ", config.TCP_ADDRESS, ", port :", config.HOST_PORT) + router.StartService() + +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/AuthMiddleware.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/AuthMiddleware.go new file mode 100644 index 0000000000000000000000000000000000000000..6dc04aa18ba75ef21252e87baf23c0158cc3daea --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/AuthMiddleware.go @@ -0,0 +1,103 @@ +// auth/auth.go + +package middleware + +import ( + "errors" + "time" + + "github.com/dgrijalva/jwt-go" + "github.com/gin-gonic/gin" + "go-dp.abdanhafidz.com/config" + "go-dp.abdanhafidz.com/models" + "golang.org/x/crypto/bcrypt" +) + +// Define a secret key for signing the JWT token +var salt = config.Salt +var secretKey = []byte(salt) + +// GenerateToken generates a JWT token for the given user +func GenerateToken(user *models.Account) (string, error) { + + // Create a new token + token := jwt.New(jwt.SigningMethodHS256) + + // Set claims + claims := token.Claims.(jwt.MapClaims) + claims["id"] = user.IDAccount + claims["exp"] = time.Now().Add(time.Hour * 24).Unix() // Token expires in 24 hours + + // Sign the token with the secret key + tokenString, err := token.SignedString(secretKey) + if err != nil { + return "", err + } + + return tokenString, nil +} + +// VerifyPassword verifies if the provided password matches the hashed password +func VerifyPassword(hashedPassword, password string) error { + err := bcrypt.CompareHashAndPassword([]byte(hashedPassword), []byte(password)) + if err != nil { + return errors.New("invalid password") + } + return nil +} +func HashPassword(password string) (string, error) { + bytes, err := bcrypt.GenerateFromPassword([]byte(password), 14) + return string(bytes), err +} + +type CustomClaims struct { + jwt.StandardClaims + IDUser int `json:"id"` +} + +func VerifyToken(bearer_token string) (int, string, error) { + // fmt.Println(bearer_token) + token, err := jwt.ParseWithClaims(bearer_token, &CustomClaims{}, func(token *jwt.Token) (interface{}, error) { + return secretKey, nil + }) + if err != nil { + return 0, "invalid-token", err + } + claims, ok := token.Claims.(*CustomClaims) + if !ok || !token.Valid { + return 0, "invalid-token", err + } else if claims.StandardClaims.ExpiresAt != 0 && claims.ExpiresAt < time.Now().Unix() { + return 0, "expired", err + } else if !ok && token.Valid { + return 0, "invalid-token", err + } + + return claims.IDUser, "valid", err +} + +func AuthUser(c *gin.Context) { + var currAccData models.AccountData + if c.Request.Header["Auth-Bearer-Token"] != nil { + token := c.Request.Header["Auth-Bearer-Token"] + currAccData.IdUser, currAccData.VerifyStatus, currAccData.ErrVerif = VerifyToken(token[0]) + // fmt.Println("Verify Status :", currAccData.verifyStatus) + if currAccData.VerifyStatus == "invalid-token" || currAccData.VerifyStatus == "expired" { + currAccData.IdUser = 0 + message := "Your session is expired, Please re-Login!" + SendJSON401(c, &currAccData.VerifyStatus, &message) + c.Abort() + return + } + } else { + currAccData.IdUser = 0 + currAccData.VerifyStatus = "no-token" + currAccData.ErrVerif = nil + message := "You have to Login First!" + SendJSON401(c, &currAccData.VerifyStatus, &message) + c.Abort() + return + } + + c.Set("accountData", currAccData) + c.Next() +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/middleware.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/middleware.go new file mode 100644 index 0000000000000000000000000000000000000000..5b140903a637aa1d80f02382cb8dbb821c5c01bf --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/middleware.go @@ -0,0 +1,31 @@ +package middleware + +import ( + "math" + "time" + + "gorm.io/gorm" +) + +func RecordCheck(rows *gorm.DB) (string, error) { + count := rows.RowsAffected + err := rows.Error + // fmt.Println(rows) + // fmt.Println(count) + if count == 0 { + return "no-record", err + } else if err != nil { + return "query-error", err + } else { + return "ok", err + } +} + +func DiffTime(t1 time.Time, t2 time.Time) (int, int, int) { + hs := t1.Sub(t2).Hours() + hs, mf := math.Modf(hs) + ms := mf * 60 + ms, sf := math.Modf(ms) + ss := sf * 60 + return int(hs), int(ms), int(ss) +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/responseMiddleware.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/responseMiddleware.go new file mode 100644 index 0000000000000000000000000000000000000000..55f3385077839115eadb8dace294229f4b4c3df2 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/middleware/responseMiddleware.go @@ -0,0 +1,39 @@ +package middleware + +import ( + "net/http" + + "github.com/gin-gonic/gin" +) + +// SendJSON200 sends a JSON response with HTTP status code 200 +func SendJSON200(c *gin.Context, data interface{}) { + c.JSON(http.StatusOK, gin.H{"status": "success", "data": data}) +} + +// SendJSON400 sends a JSON response with HTTP status code 400 +func SendJSON400(c *gin.Context, error_status *string, message *string) { + c.JSON(http.StatusBadRequest, gin.H{"status": "error", "error-status": error_status, "message": message}) +} + +// SendJSON401 sends a JSON response with HTTP status code 401 +func SendJSON401(c *gin.Context, error_status *string, message *string) { + c.JSON(http.StatusUnauthorized, gin.H{"status": "error", "error-status": error_status, "message": message}) +} + +// SendJSON403 sends a JSON response with HTTP status code 403 +func SendJSON403(c *gin.Context, message *string) { + c.JSON(http.StatusForbidden, gin.H{"status": "error", "message": message}) +} + +// SendJSON404 sends a JSON response with HTTP status code 404 +func SendJSON404(c *gin.Context, message *string) { + c.JSON(http.StatusNotFound, gin.H{"status": "error", "message": message}) +} + +// SendJSON500 sends a JSON response with HTTP status code 500 +func SendJSON500(c *gin.Context, error_status *string, message *string) { + c.JSON(http.StatusInternalServerError, gin.H{"status": "error", "error-status": error_status, "message": message}) +} + +// JSONResponseMiddleware is a middleware that provides functions for sending JSON responses diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/AuthModel.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/AuthModel.go new file mode 100644 index 0000000000000000000000000000000000000000..5f7c52925aee7c529ef737ae0feb88ee3cb3dbc7 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/AuthModel.go @@ -0,0 +1,7 @@ +package models + +type AccountData struct { + IdUser int + VerifyStatus string + ErrVerif error +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/DatabaseModel.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/DatabaseModel.go new file mode 100644 index 0000000000000000000000000000000000000000..f048c17a9838438555d6fd795e6c7617c2c1b729 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/DatabaseModel.go @@ -0,0 +1,30 @@ +package models + +import ( + "time" +) + +type Account struct { + IDAccount uint `gorm:"primaryKey" json:"id_account"` + Name string `json:"name"` + Username string `json:"username"` + Email string `json:"email"` + Password string `json:"password"` + PhoneNumber int `json:"phone_number"` + CreatedAt time.Time `json:"created_at"` + DeletedAt time.Time `json:"deleted_at"` +} + +type AccountDetails struct { + IDDetail uint `gorm:"primaryKey" json:"id_detail"` + IDAccount uint `json:"id_account"` + Province string `json:"province"` + City string `json:"city"` + Institution string `json:"institution"` + UpdatedAt time.Time `json:"updated_at"` + DeletedAt time.Time `json:"deleted_at"` +} + +// Gorm table name settings +func (Account) TableName() string { return "account" } +func (AccountDetails) TableName() string { return "account_details" } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/ExceptionModel.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/ExceptionModel.go new file mode 100644 index 0000000000000000000000000000000000000000..b4e76203056e9c2ee6ea5b447b6d3b90842f1d88 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/ExceptionModel.go @@ -0,0 +1,11 @@ +package models + +type Exception struct { + Unauthorized bool `json:"unauthorized,omitempty"` + BadRequest bool `json:"bad_request,omitempty"` + DataNotFound bool `json:"data_not_found,omitempty"` + InternalServerError bool `json:"internal_server_error,omitempty"` + DataDuplicate bool `json:"data_duplicate,omitempty"` + QueryError bool `json:"query_error,omitempty"` + Message string `json:"message,omitempty"` +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/RequestModel.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/RequestModel.go new file mode 100644 index 0000000000000000000000000000000000000000..cfae888ec34edbdd3f5b6588050e2b382c63792d --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/RequestModel.go @@ -0,0 +1,13 @@ +package models + +type LoginRequest struct { + Email string `json:"email" binding:"required"` + Password string `json:"password" binding:"required"` +} + +type RegisterRequest struct { + Name string `json:"name"` + Email string `json:"email" binding:"required,email"` + Phone int `json:"phone"` + Password string `json:"password" binding:"required"` +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/ResponseModel.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/ResponseModel.go new file mode 100644 index 0000000000000000000000000000000000000000..9ce401186cb92d50737155815c1f511164b86407 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/models/ResponseModel.go @@ -0,0 +1 @@ +package models diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/AccountRepository.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/AccountRepository.go new file mode 100644 index 0000000000000000000000000000000000000000..79e43f0707a436c344e5cddd53187d428274bde9 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/AccountRepository.go @@ -0,0 +1,24 @@ +package repositories + +import ( + "fmt" + + "go-dp.abdanhafidz.com/models" +) + +func GetAccountbyEmailPassword(username string, password string) Repository[models.Account, models.Account] { + repo := Construct[models.Account, models.Account]( + models.Account{Username: username, Password: password}, + ) + Find(repo) + return *repo +} + +func CreateAccount(account models.Account) Repository[models.Account, models.Account] { + fmt.Println(account) + repo := Construct[models.Account, models.Account]( + account, + ) + Create(repo) + return *repo +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/DatabaseScoope.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/DatabaseScoope.go new file mode 100644 index 0000000000000000000000000000000000000000..e11987b79a890dc6e84923fe7c241c6e8fa99c35 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/DatabaseScoope.go @@ -0,0 +1,5 @@ +package repositories + +import "go-dp.abdanhafidz.com/config" + +var db = config.DB diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/repositories.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/repositories.go new file mode 100644 index 0000000000000000000000000000000000000000..c82f550472331b9b8d0f5d4cdcf5aab441e5cdfa --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/repositories/repositories.go @@ -0,0 +1,96 @@ +package repositories + +import ( + "fmt" + + "go-dp.abdanhafidz.com/config" + "gorm.io/gorm" +) + +type Repositories interface { + FindAllPaginate() + Where() + Find() + Create() + Update() + CustomQuery() + Delete() +} +type PaginationConstructor struct { + Limit int + Offset int + Filter string +} + +type CustomQueryConstructor struct { + SQL string + Values interface{} +} + +type Repository[TConstructor any, TResult any] struct { + Constructor TConstructor + Pagination PaginationConstructor + CustomQuery CustomQueryConstructor + Result TResult + Transaction *gorm.DB + RowsCount int + NoRecord bool + RowsError error +} + +func Construct[TConstructor any, TResult any](constructor ...TConstructor) *Repository[TConstructor, TResult] { + fmt.Println("Len = ", len(constructor)) + if len(constructor) == 1 { + return &Repository[TConstructor, TResult]{ + Constructor: constructor[0], + Transaction: config.DB, + } + } + return &Repository[TConstructor, TResult]{ + Constructor: constructor[0], + Transaction: config.DB.Begin(), + } +} +func (repo *Repository[T1, T2]) Transactions(transactions ...func(*Repository[T1, T2])) { + i := 1 + for _, tx := range transactions { + tx(repo) + repo.RowsError = repo.Transaction.Error + if repo.RowsError != nil { + repo.Transaction.Rollback() + return + } else { + repo.Transaction.SavePoint("Save Point : " + string(i)) + repo.Transaction.Commit() + } + } +} +func WhereGivenConstructor[T1 any, T2 any](repo *Repository[T1, T2]) { + repo.Transaction.Where(&repo.Constructor) +} +func Find[T1 any, T2 any](repo *Repository[T1, T2]) { + repo.Transaction.Find(&repo.Result) +} + +func FinddAllPaginate[T1 any, T2 any](repo *Repository[T1, T2]) { + repo.Transaction.Limit(repo.Pagination.Limit).Offset(repo.Pagination.Offset).Find(&repo.Result) +} + +func Create[T1 any](repo *Repository[T1, T1]) { + fmt.Println(repo.Constructor) + repo.Transaction.Create(&repo.Constructor) + repo.Result = repo.Constructor +} + +func Update[T1 any](repo *Repository[T1, T1]) { + repo.Transaction.Save(&repo.Constructor) + repo.Result = repo.Constructor +} + +func Delete[T1 any](repo *Repository[T1, T1]) { + repo.Transaction.Delete(&repo.Constructor) +} + +func CustomQuery[T1 any, T2 any](repo *Repository[T1, T2]) { + repo.Transaction.Raw(repo.CustomQuery.SQL, repo.CustomQuery.Values).Scan(&repo.Result) +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/router.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/router.go new file mode 100644 index 0000000000000000000000000000000000000000..27ce310f782a252cab580d08873505f02ec38a03 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/router/router.go @@ -0,0 +1,18 @@ +package router + +import ( + "github.com/gin-gonic/gin" + "go-dp.abdanhafidz.com/config" + "go-dp.abdanhafidz.com/controller" +) + +func StartService() { + router := gin.Default() + routerGroup := router.Group("/api/v1") + { + routerGroup.GET("/", controller.HomeController) + routerGroup.POST("/login", controller.LoginController) + routerGroup.POST("/register", controller.RegisterController) + } + router.Run(config.TCP_ADDRESS) +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/LoginService.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/LoginService.go new file mode 100644 index 0000000000000000000000000000000000000000..e798298cb58036f0b00cc04a919500d6b9c83c09 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/LoginService.go @@ -0,0 +1,36 @@ +package services + +import ( + "go-dp.abdanhafidz.com/middleware" + "go-dp.abdanhafidz.com/models" + "go-dp.abdanhafidz.com/repositories" +) + +type LoginConstructor struct { + Email string + Password string +} + +type AuthenticationService struct { + Service[LoginConstructor, models.Account] +} + +func (s *AuthenticationService) Authenticate() { + accountData := repositories.GetAccountbyEmailPassword(s.Constructor.Email, s.Constructor.Password) + if accountData.NoRecord { + s.Exception.DataNotFound = true + s.Exception.Message = "there is no account with given email!" + return + } + + if middleware.VerifyPassword(accountData.Result.Password, s.Constructor.Password) != nil { + s.Exception.Unauthorized = true + s.Exception.Message = "incorrect password!" + return + } + + s.Result = accountData.Result + s.Error = accountData.RowsError +} + +// LoginHandler handles user login diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/RegisterService.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/RegisterService.go new file mode 100644 index 0000000000000000000000000000000000000000..615a3a595a056802ecd6e130c8f0f04be2643d05 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/RegisterService.go @@ -0,0 +1,31 @@ +package services + +import ( + "errors" + + "go-dp.abdanhafidz.com/middleware" + "go-dp.abdanhafidz.com/models" + "go-dp.abdanhafidz.com/repositories" + "gorm.io/gorm" +) + +type RegisterService struct { + Service[models.Account, models.Account] +} + +func (s *RegisterService) Create() { + hashed_password, _ := middleware.HashPassword(s.Constructor.Password) + s.Constructor.Password = hashed_password + accountCreated := repositories.CreateAccount(s.Constructor) + if errors.Is(accountCreated.RowsError, gorm.ErrDuplicatedKey) { + s.Exception.DataDuplicate = true + s.Exception.Message = "There is account registered with given data!" + return + } 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) { + s.Exception.BadRequest = true + s.Exception.Message = "Bad request!" + return + } + s.Result = accountCreated.Result + s.Result.Password = "SECRET" +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/services.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/services.go new file mode 100644 index 0000000000000000000000000000000000000000..e684786fdd3dc071dd085b87f27a0e7bb8becfff --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/services/services.go @@ -0,0 +1,31 @@ +package services + +import "go-dp.abdanhafidz.com/models" + +type ( + Services interface { + Retrieve() + Update() + Create() + Delete() + Validate() + Authenticate() + Authorize() + } + Service[TConstructor any, TResult any] struct { + Constructor TConstructor + Result TResult + Exception models.Exception + Error error + } +) + +func Construct[TConstructor any, TResult any](constructor ...TConstructor) *Service[TConstructor, TResult] { + if len(constructor) == 0 { + return &Service[TConstructor, TResult]{} + } + + return &Service[TConstructor, TResult]{ + Constructor: constructor[0], + } +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/.gitattributes b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/.gitattributes new file mode 100644 index 0000000000000000000000000000000000000000..a6344aac8c09253b3b630fb776ae94478aa0275b --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/.gitattributes @@ -0,0 +1,35 @@ +*.7z filter=lfs diff=lfs merge=lfs -text +*.arrow filter=lfs diff=lfs merge=lfs -text +*.bin filter=lfs diff=lfs merge=lfs -text +*.bz2 filter=lfs diff=lfs merge=lfs -text +*.ckpt filter=lfs diff=lfs merge=lfs -text +*.ftz filter=lfs diff=lfs merge=lfs -text +*.gz filter=lfs diff=lfs merge=lfs -text +*.h5 filter=lfs diff=lfs merge=lfs -text +*.joblib filter=lfs diff=lfs merge=lfs -text +*.lfs.* filter=lfs diff=lfs merge=lfs -text +*.mlmodel filter=lfs diff=lfs merge=lfs -text +*.model filter=lfs diff=lfs merge=lfs -text +*.msgpack filter=lfs diff=lfs merge=lfs -text +*.npy filter=lfs diff=lfs merge=lfs -text +*.npz filter=lfs diff=lfs merge=lfs -text +*.onnx filter=lfs diff=lfs merge=lfs -text +*.ot filter=lfs diff=lfs merge=lfs -text +*.parquet filter=lfs diff=lfs merge=lfs -text +*.pb filter=lfs diff=lfs merge=lfs -text +*.pickle filter=lfs diff=lfs merge=lfs -text +*.pkl filter=lfs diff=lfs merge=lfs -text +*.pt filter=lfs diff=lfs merge=lfs -text +*.pth filter=lfs diff=lfs merge=lfs -text +*.rar filter=lfs diff=lfs merge=lfs -text +*.safetensors filter=lfs diff=lfs merge=lfs -text +saved_model/**/* filter=lfs diff=lfs merge=lfs -text +*.tar.* filter=lfs diff=lfs merge=lfs -text +*.tar filter=lfs diff=lfs merge=lfs -text +*.tflite filter=lfs diff=lfs merge=lfs -text +*.tgz filter=lfs diff=lfs merge=lfs -text +*.wasm filter=lfs diff=lfs merge=lfs -text +*.xz filter=lfs diff=lfs merge=lfs -text +*.zip filter=lfs diff=lfs merge=lfs -text +*.zst filter=lfs diff=lfs merge=lfs -text +*tfevents* filter=lfs diff=lfs merge=lfs -text diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/APIResponse.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/APIResponse.go new file mode 100644 index 0000000000000000000000000000000000000000..7a3e7df219e76ae94bc17ef748c6dfe7f8afeb93 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/APIResponse.go @@ -0,0 +1,39 @@ +package utils + +import ( + "net/http" + "reflect" + + "github.com/gin-gonic/gin" + "go-dp.abdanhafidz.com/models" + "go-dp.abdanhafidz.com/services" +) + +func ResponseOK(c *gin.Context, data any) { + c.JSON(http.StatusOK, gin.H{"message": "Request Success!", "data": data, "status": "success"}) +} + +func ResponseFAIL(c *gin.Context, status int, exception models.Exception) { + message := exception.Message + exception.Message = "" + c.AbortWithStatusJSON(status, gin.H{"status": "error", "message": message, "error": exception}) + return +} + +func SendResponse(c *gin.Context, data services.Service[any, any]) { + if reflect.ValueOf(data.Exception).IsNil() { + ResponseOK(c, data) + } else { + if data.Exception.Unauthorized { + ResponseFAIL(c, 401, data.Exception) + } else if data.Exception.BadRequest { + ResponseFAIL(c, 400, data.Exception) + } else if data.Exception.DataNotFound { + ResponseFAIL(c, 404, data.Exception) + } else if data.Exception.InternalServerError { + ResponseFAIL(c, 500, data.Exception) + } else { + ResponseFAIL(c, 403, data.Exception) + } + } +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/Exception.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/Exception.go new file mode 100644 index 0000000000000000000000000000000000000000..0b273b83d7e7cb140e2b9df6801f161f0ff08be4 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/Exception.go @@ -0,0 +1 @@ +package utils diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/Helper.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/Helper.go new file mode 100644 index 0000000000000000000000000000000000000000..3e36fc57268d71ef58e1511b038f8c56e7f8928c --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/Helper.go @@ -0,0 +1,11 @@ +package utils + +import ( + "github.com/gin-gonic/gin" + "go-dp.abdanhafidz.com/models" +) + +func GetAccount(c *gin.Context) models.AccountData { + cParam, _ := c.Get("accountData") + return cParam.(models.AccountData) +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/Logger.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/Logger.go new file mode 100644 index 0000000000000000000000000000000000000000..98d4a9447588e08458738263844c45eb0d6ae98b --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/Logger.go @@ -0,0 +1,19 @@ +package utils + +import ( + "log" + "os" + + "go-dp.abdanhafidz.com/config" +) + +func LogError(errorLogged error) { + file, err := os.OpenFile(config.LOG_PATH+"error_log.txt", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666) + if err != nil { + log.Fatal(err) + } + + log.SetOutput(file) + + log.Println(errorLogged) +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/utils.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/utils.go new file mode 100644 index 0000000000000000000000000000000000000000..480645d434c01f7152d6747171e5e3ea53969533 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/utils.go @@ -0,0 +1,9 @@ +package utils + +func ternaryMessage(condition bool, valueIfTrue string, valueIfFalse string) string { + if condition { + return valueIfTrue + } else { + return valueIfFalse + } +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/APIResponse.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/APIResponse.go index 7a3e7df219e76ae94bc17ef748c6dfe7f8afeb93..da8a2be04c3d8ef4a28939d5c40cdb3574efb650 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/APIResponse.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/APIResponse.go @@ -11,6 +11,7 @@ import ( func ResponseOK(c *gin.Context, data any) { c.JSON(http.StatusOK, gin.H{"message": "Request Success!", "data": data, "status": "success"}) + return } func ResponseFAIL(c *gin.Context, status int, exception models.Exception) { diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/APIResponse.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/APIResponse.go index da8a2be04c3d8ef4a28939d5c40cdb3574efb650..68eb789f1daf3ed57cfe6ea600c948f2ee0be9cc 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/APIResponse.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/APIResponse.go @@ -18,6 +18,7 @@ func ResponseFAIL(c *gin.Context, status int, exception models.Exception) { message := exception.Message exception.Message = "" c.AbortWithStatusJSON(status, gin.H{"status": "error", "message": message, "error": exception}) + c. return } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/APIResponse.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/APIResponse.go index 68eb789f1daf3ed57cfe6ea600c948f2ee0be9cc..da8a2be04c3d8ef4a28939d5c40cdb3574efb650 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/APIResponse.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/APIResponse.go @@ -18,7 +18,6 @@ func ResponseFAIL(c *gin.Context, status int, exception models.Exception) { message := exception.Message exception.Message = "" c.AbortWithStatusJSON(status, gin.H{"status": "error", "message": message, "error": exception}) - c. return } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/Logger.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/Logger.go index 98d4a9447588e08458738263844c45eb0d6ae98b..6473e869e33fbe10150a80de942cfcb9f46a4749 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/Logger.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/Logger.go @@ -15,5 +15,5 @@ func LogError(errorLogged error) { log.SetOutput(file) - log.Println(errorLogged) + log.Println("Error Log :", errorLogged) } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/Logger.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/Logger.go index 6473e869e33fbe10150a80de942cfcb9f46a4749..2bb3f755429b22e6c3d62cdf95ac630010eacae6 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/Logger.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/Logger.go @@ -1,6 +1,7 @@ package utils import ( + "fmt" "log" "os" @@ -8,6 +9,7 @@ import ( ) func LogError(errorLogged error) { + fmt.Println("There is an error!") file, err := os.OpenFile(config.LOG_PATH+"error_log.txt", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666) if err != nil { log.Fatal(err) diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/APIResponse.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/APIResponse.go index da8a2be04c3d8ef4a28939d5c40cdb3574efb650..455109a156badaed17549222ed98a6b0d268b98a 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/APIResponse.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/APIResponse.go @@ -4,9 +4,9 @@ import ( "net/http" "reflect" + "api.qobiltu.id/models" + "api.qobiltu.id/services" "github.com/gin-gonic/gin" - "go-dp.abdanhafidz.com/models" - "go-dp.abdanhafidz.com/services" ) func ResponseOK(c *gin.Context, data any) { diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/Helper.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/Helper.go index 3e36fc57268d71ef58e1511b038f8c56e7f8928c..4742c7fa5c357435cb9bdfb86e48828670a9792b 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/Helper.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/Helper.go @@ -1,8 +1,8 @@ package utils import ( + "api.qobiltu.id/models" "github.com/gin-gonic/gin" - "go-dp.abdanhafidz.com/models" ) func GetAccount(c *gin.Context) models.AccountData { diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/Logger.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/Logger.go index 2bb3f755429b22e6c3d62cdf95ac630010eacae6..d0f8ec5600ab6a524e594198900de51e76b460a8 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/Logger.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/Logger.go @@ -5,7 +5,7 @@ import ( "log" "os" - "go-dp.abdanhafidz.com/config" + "api.qobiltu.id/config" ) func LogError(errorLogged error) { diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/api_response.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/api_response.go new file mode 100644 index 0000000000000000000000000000000000000000..aae210ee39978d67c5412c665a041f45685f0c13 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/api_response.go @@ -0,0 +1,52 @@ +package utils + +import ( + "net/http" + "reflect" + + "api.qobiltu.id/models" + "api.qobiltu.id/services" + "github.com/gin-gonic/gin" +) + +func ResponseOK(c *gin.Context, data any) { + res := models.SuccessResponse{ + Status: "success", + Message: "Data retrieved successfully!", + Data: data, + MetaData: c.Request.Body, + } + c.JSON(http.StatusOK, res) + return +} + +func ResponseFAIL(c *gin.Context, status int, exception models.Exception) { + message := exception.Message + exception.Message = "" + res := models.ErrorResponse{ + Status: "error", + Message: message, + Errors: exception, + MetaData: c.Request.Body, + } + c.AbortWithStatusJSON(status, res) + return +} + +func SendResponse(c *gin.Context, data services.Service[any, any]) { + if reflect.ValueOf(data.Exception).IsNil() { + ResponseOK(c, data) + } else { + if data.Exception.Unauthorized { + ResponseFAIL(c, 401, data.Exception) + } else if data.Exception.BadRequest { + ResponseFAIL(c, 400, data.Exception) + } else if data.Exception.DataNotFound { + ResponseFAIL(c, 404, data.Exception) + } else if data.Exception.InternalServerError { + ResponseFAIL(c, 500, data.Exception) + } else { + ResponseFAIL(c, 403, data.Exception) + } + } +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/util.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/util.go new file mode 100644 index 0000000000000000000000000000000000000000..480645d434c01f7152d6747171e5e3ea53969533 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/util.go @@ -0,0 +1,9 @@ +package utils + +func ternaryMessage(condition bool, valueIfTrue string, valueIfFalse string) string { + if condition { + return valueIfTrue + } else { + return valueIfFalse + } +} diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/Logger.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/Logger.go index d0f8ec5600ab6a524e594198900de51e76b460a8..a3d0718f321d11e5b83abd02c43e7cd849ce5cad 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/Logger.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/Logger.go @@ -10,7 +10,7 @@ import ( func LogError(errorLogged error) { fmt.Println("There is an error!") - file, err := os.OpenFile(config.LOG_PATH+"error_log.txt", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666) + file, err := os.OpenFile(config.LOG_PATH+"/error_log.txt", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666) if err != nil { log.Fatal(err) } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/seeds/city.json b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/seeds/city.json new file mode 100644 index 0000000000000000000000000000000000000000..56d547fed553f1a98f9e13e0f161a9c7a83edf33 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/seeds/city.json @@ -0,0 +1,4114 @@ +[ + { + "id": 1, + "type": "Kabupaten", + "name": "Aceh Barat", + "code": "05", + "full_code": "1105", + "provinsi_id": 1 + }, + { + "id": 2, + "type": "Kabupaten", + "name": "Aceh Barat Daya", + "code": "12", + "full_code": "1112", + "provinsi_id": 1 + }, + { + "id": 3, + "type": "Kabupaten", + "name": "Sabu Raijua", + "code": "20", + "full_code": "5320", + "provinsi_id": 23 + }, + { + "id": 4, + "type": "Kota", + "name": "Salatiga", + "code": "73", + "full_code": "3373", + "provinsi_id": 10 + }, + { + "id": 5, + "type": "Kabupaten", + "name": "Aceh Besar", + "code": "06", + "full_code": "1106", + "provinsi_id": 1 + }, + { + "id": 6, + "type": "Kabupaten", + "name": "Aceh Jaya", + "code": "14", + "full_code": "1114", + "provinsi_id": 1 + }, + { + "id": 7, + "type": "Kabupaten", + "name": "Aceh Selatan", + "code": "01", + "full_code": "1101", + "provinsi_id": 1 + }, + { + "id": 8, + "type": "Kabupaten", + "name": "Aceh Singkil", + "code": "10", + "full_code": "1110", + "provinsi_id": 1 + }, + { + "id": 9, + "type": "Kabupaten", + "name": "Aceh Tamiang", + "code": "16", + "full_code": "1116", + "provinsi_id": 1 + }, + { + "id": 10, + "type": "Kabupaten", + "name": "Aceh Tengah", + "code": "04", + "full_code": "1104", + "provinsi_id": 1 + }, + { + "id": 11, + "type": "Kabupaten", + "name": "Aceh Tenggara", + "code": "02", + "full_code": "1102", + "provinsi_id": 1 + }, + { + "id": 12, + "type": "Kabupaten", + "name": "Aceh Timur", + "code": "03", + "full_code": "1103", + "provinsi_id": 1 + }, + { + "id": 13, + "type": "Kabupaten", + "name": "Gorontalo Utara", + "code": "05", + "full_code": "7505", + "provinsi_id": 7 + }, + { + "id": 14, + "type": "Kabupaten", + "name": "Aceh Utara", + "code": "08", + "full_code": "1108", + "provinsi_id": 1 + }, + { + "id": 15, + "type": "Kabupaten", + "name": "Agam", + "code": "06", + "full_code": "1306", + "provinsi_id": 36 + }, + { + "id": 16, + "type": "Kabupaten", + "name": "Alor", + "code": "05", + "full_code": "5305", + "provinsi_id": 23 + }, + { + "id": 17, + "type": "Kota", + "name": "Ambon", + "code": "71", + "full_code": "8171", + "provinsi_id": 20 + }, + { + "id": 18, + "type": "Kabupaten", + "name": "Gowa", + "code": "06", + "full_code": "7306", + "provinsi_id": 32 + }, + { + "id": 19, + "type": "Kota", + "name": "Samarinda", + "code": "72", + "full_code": "6472", + "provinsi_id": 15 + }, + { + "id": 20, + "type": "Kabupaten", + "name": "Asahan", + "code": "09", + "full_code": "1209", + "provinsi_id": 38 + }, + { + "id": 21, + "type": "Kabupaten", + "name": "Sambas", + "code": "01", + "full_code": "6101", + "provinsi_id": 12 + }, + { + "id": 22, + "type": "Kabupaten", + "name": "Asmat", + "code": "04", + "full_code": "9304", + "provinsi_id": 28 + }, + { + "id": 23, + "type": "Kabupaten", + "name": "Samosir", + "code": "17", + "full_code": "1217", + "provinsi_id": 38 + }, + { + "id": 24, + "type": "Kabupaten", + "name": "Badung", + "code": "03", + "full_code": "5103", + "provinsi_id": 2 + }, + { + "id": 25, + "type": "Kabupaten", + "name": "Sampang", + "code": "27", + "full_code": "3527", + "provinsi_id": 11 + }, + { + "id": 26, + "type": "Kabupaten", + "name": "Balangan", + "code": "11", + "full_code": "6311", + "provinsi_id": 13 + }, + { + "id": 27, + "type": "Kabupaten", + "name": "Sanggau", + "code": "03", + "full_code": "6103", + "provinsi_id": 12 + }, + { + "id": 28, + "type": "Kabupaten", + "name": "Sarmi", + "code": "10", + "full_code": "9110", + "provinsi_id": 24 + }, + { + "id": 29, + "type": "Kabupaten", + "name": "Gresik", + "code": "25", + "full_code": "3525", + "provinsi_id": 11 + }, + { + "id": 30, + "type": "Kabupaten", + "name": "Grobogan", + "code": "15", + "full_code": "3315", + "provinsi_id": 10 + }, + { + "id": 31, + "type": "Kabupaten", + "name": "Gunung Mas", + "code": "10", + "full_code": "6210", + "provinsi_id": 14 + }, + { + "id": 32, + "type": "Kabupaten", + "name": "Gunungkidul", + "code": "03", + "full_code": "3403", + "provinsi_id": 5 + }, + { + "id": 33, + "type": "Kabupaten", + "name": "Sarolangun", + "code": "03", + "full_code": "1503", + "provinsi_id": 8 + }, + { + "id": 34, + "type": "Kota", + "name": "Gunungsitoli", + "code": "78", + "full_code": "1278", + "provinsi_id": 38 + }, + { + "id": 35, + "type": "Kota", + "name": "Sawahlunto", + "code": "73", + "full_code": "1373", + "provinsi_id": 36 + }, + { + "id": 36, + "type": "Kabupaten", + "name": "Halmahera Barat", + "code": "01", + "full_code": "8201", + "provinsi_id": 21 + }, + { + "id": 37, + "type": "Kabupaten", + "name": "Sekadau", + "code": "09", + "full_code": "6109", + "provinsi_id": 12 + }, + { + "id": 38, + "type": "Kabupaten", + "name": "Halmahera Selatan", + "code": "04", + "full_code": "8204", + "provinsi_id": 21 + }, + { + "id": 39, + "type": "Kabupaten", + "name": "Seluma", + "code": "05", + "full_code": "1705", + "provinsi_id": 4 + }, + { + "id": 40, + "type": "Kabupaten", + "name": "Halmahera Tengah", + "code": "02", + "full_code": "8202", + "provinsi_id": 21 + }, + { + "id": 41, + "type": "Kabupaten", + "name": "Semarang", + "code": "22", + "full_code": "3322", + "provinsi_id": 10 + }, + { + "id": 42, + "type": "Kota", + "name": "Semarang", + "code": "74", + "full_code": "3374", + "provinsi_id": 10 + }, + { + "id": 43, + "type": "Kabupaten", + "name": "Halmahera Timur", + "code": "06", + "full_code": "8206", + "provinsi_id": 21 + }, + { + "id": 44, + "type": "Kabupaten", + "name": "Seram Bagian Barat", + "code": "06", + "full_code": "8106", + "provinsi_id": 20 + }, + { + "id": 45, + "type": "Kabupaten", + "name": "Halmahera Utara", + "code": "03", + "full_code": "8203", + "provinsi_id": 21 + }, + { + "id": 46, + "type": "Kabupaten", + "name": "Seram Bagian Timur", + "code": "05", + "full_code": "8105", + "provinsi_id": 20 + }, + { + "id": 47, + "type": "Kabupaten", + "name": "Hulu Sungai Selatan", + "code": "06", + "full_code": "6306", + "provinsi_id": 13 + }, + { + "id": 48, + "type": "Kabupaten", + "name": "Hulu Sungai Tengah", + "code": "07", + "full_code": "6307", + "provinsi_id": 13 + }, + { + "id": 49, + "type": "Kabupaten", + "name": "Hulu Sungai Utara", + "code": "08", + "full_code": "6308", + "provinsi_id": 13 + }, + { + "id": 50, + "type": "Kota", + "name": "Serang", + "code": "73", + "full_code": "3673", + "provinsi_id": 3 + }, + { + "id": 51, + "type": "Kabupaten", + "name": "Serang", + "code": "04", + "full_code": "3604", + "provinsi_id": 3 + }, + { + "id": 52, + "type": "Kabupaten", + "name": "Humbang Hasundutan", + "code": "16", + "full_code": "1216", + "provinsi_id": 38 + }, + { + "id": 53, + "type": "Kota", + "name": "Balikpapan", + "code": "71", + "full_code": "6471", + "provinsi_id": 15 + }, + { + "id": 54, + "type": "Kabupaten", + "name": "Indragiri Hilir", + "code": "04", + "full_code": "1404", + "provinsi_id": 30 + }, + { + "id": 55, + "type": "Kabupaten", + "name": "Indragiri Hulu", + "code": "02", + "full_code": "1402", + "provinsi_id": 30 + }, + { + "id": 56, + "type": "Kota", + "name": "Banda Aceh", + "code": "71", + "full_code": "1171", + "provinsi_id": 1 + }, + { + "id": 57, + "type": "Kota", + "name": "Bandar Lampung", + "code": "71", + "full_code": "1871", + "provinsi_id": 19 + }, + { + "id": 58, + "type": "Kota", + "name": "Bandung", + "code": "73", + "full_code": "3273", + "provinsi_id": 9 + }, + { + "id": 59, + "type": "Kabupaten", + "name": "Bandung", + "code": "04", + "full_code": "3204", + "provinsi_id": 9 + }, + { + "id": 60, + "type": "Kabupaten", + "name": "Bandung Barat", + "code": "17", + "full_code": "3217", + "provinsi_id": 9 + }, + { + "id": 61, + "type": "Kabupaten", + "name": "Banggai", + "code": "01", + "full_code": "7201", + "provinsi_id": 33 + }, + { + "id": 62, + "type": "Kabupaten", + "name": "Banggai Kepulauan", + "code": "07", + "full_code": "7207", + "provinsi_id": 33 + }, + { + "id": 63, + "type": "Kabupaten", + "name": "Banggai Laut", + "code": "11", + "full_code": "7211", + "provinsi_id": 33 + }, + { + "id": 64, + "type": "Kabupaten", + "name": "Bangka", + "code": "01", + "full_code": "1901", + "provinsi_id": 17 + }, + { + "id": 65, + "type": "Kabupaten", + "name": "Bangka Barat", + "code": "05", + "full_code": "1905", + "provinsi_id": 17 + }, + { + "id": 66, + "type": "Kabupaten", + "name": "Bangka Selatan", + "code": "03", + "full_code": "1903", + "provinsi_id": 17 + }, + { + "id": 67, + "type": "Kabupaten", + "name": "Bangka Tengah", + "code": "04", + "full_code": "1904", + "provinsi_id": 17 + }, + { + "id": 68, + "type": "Kabupaten", + "name": "Bangkalan", + "code": "26", + "full_code": "3526", + "provinsi_id": 11 + }, + { + "id": 69, + "type": "Kabupaten", + "name": "Bangli", + "code": "06", + "full_code": "5106", + "provinsi_id": 2 + }, + { + "id": 70, + "type": "Kota", + "name": "Banjar", + "code": "79", + "full_code": "3279", + "provinsi_id": 9 + }, + { + "id": 71, + "type": "Kabupaten", + "name": "Banjar", + "code": "03", + "full_code": "6303", + "provinsi_id": 13 + }, + { + "id": 72, + "type": "Kota", + "name": "Banjarbaru", + "code": "72", + "full_code": "6372", + "provinsi_id": 13 + }, + { + "id": 73, + "type": "Kota", + "name": "Banjarmasin", + "code": "71", + "full_code": "6371", + "provinsi_id": 13 + }, + { + "id": 74, + "type": "Kabupaten", + "name": "Banjarnegara", + "code": "04", + "full_code": "3304", + "provinsi_id": 10 + }, + { + "id": 75, + "type": "Kabupaten", + "name": "Bantaeng", + "code": "03", + "full_code": "7303", + "provinsi_id": 32 + }, + { + "id": 76, + "type": "Kabupaten", + "name": "Bantul", + "code": "02", + "full_code": "3402", + "provinsi_id": 5 + }, + { + "id": 77, + "type": "Kabupaten", + "name": "Banyuasin", + "code": "07", + "full_code": "1607", + "provinsi_id": 37 + }, + { + "id": 78, + "type": "Kabupaten", + "name": "Banyumas", + "code": "02", + "full_code": "3302", + "provinsi_id": 10 + }, + { + "id": 79, + "type": "Kabupaten", + "name": "Banyuwangi", + "code": "10", + "full_code": "3510", + "provinsi_id": 11 + }, + { + "id": 80, + "type": "Kabupaten", + "name": "Barito Kuala", + "code": "04", + "full_code": "6304", + "provinsi_id": 13 + }, + { + "id": 81, + "type": "Kabupaten", + "name": "Barito Selatan", + "code": "04", + "full_code": "6204", + "provinsi_id": 14 + }, + { + "id": 82, + "type": "Kabupaten", + "name": "Barito Timur", + "code": "13", + "full_code": "6213", + "provinsi_id": 14 + }, + { + "id": 83, + "type": "Kabupaten", + "name": "Barito Utara", + "code": "05", + "full_code": "6205", + "provinsi_id": 14 + }, + { + "id": 84, + "type": "Kabupaten", + "name": "Barru", + "code": "11", + "full_code": "7311", + "provinsi_id": 32 + }, + { + "id": 85, + "type": "Kota", + "name": "Batam", + "code": "71", + "full_code": "2171", + "provinsi_id": 18 + }, + { + "id": 86, + "type": "Kabupaten", + "name": "Batang", + "code": "25", + "full_code": "3325", + "provinsi_id": 10 + }, + { + "id": 87, + "type": "Kabupaten", + "name": "Batanghari", + "code": "04", + "full_code": "1504", + "provinsi_id": 8 + }, + { + "id": 88, + "type": "Kota", + "name": "Batu", + "code": "79", + "full_code": "3579", + "provinsi_id": 11 + }, + { + "id": 89, + "type": "Kabupaten", + "name": "Batu Bara", + "code": "19", + "full_code": "1219", + "provinsi_id": 38 + }, + { + "id": 90, + "type": "Kota", + "name": "Bau Bau", + "code": "72", + "full_code": "7472", + "provinsi_id": 34 + }, + { + "id": 91, + "type": "Kota", + "name": "Bekasi", + "code": "75", + "full_code": "3275", + "provinsi_id": 9 + }, + { + "id": 92, + "type": "Kabupaten", + "name": "Bekasi", + "code": "16", + "full_code": "3216", + "provinsi_id": 9 + }, + { + "id": 93, + "type": "Kabupaten", + "name": "Belitung", + "code": "02", + "full_code": "1902", + "provinsi_id": 17 + }, + { + "id": 94, + "type": "Kabupaten", + "name": "Belitung Timur", + "code": "06", + "full_code": "1906", + "provinsi_id": 17 + }, + { + "id": 95, + "type": "Kabupaten", + "name": "Belu", + "code": "04", + "full_code": "5304", + "provinsi_id": 23 + }, + { + "id": 96, + "type": "Kabupaten", + "name": "Bener Meriah", + "code": "17", + "full_code": "1117", + "provinsi_id": 1 + }, + { + "id": 97, + "type": "Kabupaten", + "name": "Bengkalis", + "code": "03", + "full_code": "1403", + "provinsi_id": 30 + }, + { + "id": 98, + "type": "Kabupaten", + "name": "Bengkayang", + "code": "07", + "full_code": "6107", + "provinsi_id": 12 + }, + { + "id": 99, + "type": "Kabupaten", + "name": "Serdang Bedagai", + "code": "18", + "full_code": "1218", + "provinsi_id": 38 + }, + { + "id": 100, + "type": "Kota", + "name": "Bengkulu", + "code": "71", + "full_code": "1771", + "provinsi_id": 4 + }, + { + "id": 101, + "type": "Kabupaten", + "name": "Bengkulu Selatan", + "code": "01", + "full_code": "1701", + "provinsi_id": 4 + }, + { + "id": 102, + "type": "Kabupaten", + "name": "Seruyan", + "code": "07", + "full_code": "6207", + "provinsi_id": 14 + }, + { + "id": 103, + "type": "Kabupaten", + "name": "Indramayu", + "code": "12", + "full_code": "3212", + "provinsi_id": 9 + }, + { + "id": 104, + "type": "Kabupaten", + "name": "Siak", + "code": "08", + "full_code": "1408", + "provinsi_id": 30 + }, + { + "id": 105, + "type": "Kabupaten", + "name": "Intan Jaya", + "code": "07", + "full_code": "9407", + "provinsi_id": 29 + }, + { + "id": 106, + "type": "Kota", + "name": "Jakarta Barat", + "code": "73", + "full_code": "3173", + "provinsi_id": 6 + }, + { + "id": 107, + "type": "Kota", + "name": "Sibolga", + "code": "73", + "full_code": "1273", + "provinsi_id": 38 + }, + { + "id": 108, + "type": "Kabupaten", + "name": "Bengkulu Tengah", + "code": "09", + "full_code": "1709", + "provinsi_id": 4 + }, + { + "id": 109, + "type": "Kota", + "name": "Jakarta Pusat", + "code": "71", + "full_code": "3171", + "provinsi_id": 6 + }, + { + "id": 110, + "type": "Kabupaten", + "name": "Sidenreng Rappang", + "code": "14", + "full_code": "7314", + "provinsi_id": 32 + }, + { + "id": 111, + "type": "Kabupaten", + "name": "Bengkulu Utara", + "code": "03", + "full_code": "1703", + "provinsi_id": 4 + }, + { + "id": 112, + "type": "Kota", + "name": "Jakarta Selatan", + "code": "74", + "full_code": "3174", + "provinsi_id": 6 + }, + { + "id": 113, + "type": "Kabupaten", + "name": "Sidoarjo", + "code": "15", + "full_code": "3515", + "provinsi_id": 11 + }, + { + "id": 114, + "type": "Kota", + "name": "Jakarta Timur", + "code": "75", + "full_code": "3175", + "provinsi_id": 6 + }, + { + "id": 115, + "type": "Kabupaten", + "name": "Sigi", + "code": "10", + "full_code": "7210", + "provinsi_id": 33 + }, + { + "id": 116, + "type": "Kabupaten", + "name": "Berau", + "code": "03", + "full_code": "6403", + "provinsi_id": 15 + }, + { + "id": 117, + "type": "Kabupaten", + "name": "Biak Numfor", + "code": "06", + "full_code": "9106", + "provinsi_id": 24 + }, + { + "id": 118, + "type": "Kabupaten", + "name": "Bima", + "code": "06", + "full_code": "5206", + "provinsi_id": 22 + }, + { + "id": 119, + "type": "Kota", + "name": "Jakarta Utara", + "code": "72", + "full_code": "3172", + "provinsi_id": 6 + }, + { + "id": 120, + "type": "Kota", + "name": "Bima", + "code": "72", + "full_code": "5272", + "provinsi_id": 22 + }, + { + "id": 121, + "type": "Kota", + "name": "Jambi", + "code": "71", + "full_code": "1571", + "provinsi_id": 8 + }, + { + "id": 122, + "type": "Kabupaten", + "name": "Sijunjung", + "code": "03", + "full_code": "1303", + "provinsi_id": 36 + }, + { + "id": 123, + "type": "Kota", + "name": "Binjai", + "code": "75", + "full_code": "1275", + "provinsi_id": 38 + }, + { + "id": 124, + "type": "Kabupaten", + "name": "Jayapura", + "code": "03", + "full_code": "9103", + "provinsi_id": 24 + }, + { + "id": 125, + "type": "Kabupaten", + "name": "Bintan", + "code": "01", + "full_code": "2101", + "provinsi_id": 18 + }, + { + "id": 126, + "type": "Kabupaten", + "name": "Sikka", + "code": "07", + "full_code": "5307", + "provinsi_id": 23 + }, + { + "id": 127, + "type": "Kabupaten", + "name": "Bireuen", + "code": "11", + "full_code": "1111", + "provinsi_id": 1 + }, + { + "id": 128, + "type": "Kabupaten", + "name": "Simalungun", + "code": "08", + "full_code": "1208", + "provinsi_id": 38 + }, + { + "id": 129, + "type": "Kota", + "name": "Bitung", + "code": "72", + "full_code": "7172", + "provinsi_id": 35 + }, + { + "id": 130, + "type": "Kota", + "name": "Jayapura", + "code": "71", + "full_code": "9171", + "provinsi_id": 24 + }, + { + "id": 131, + "type": "Kabupaten", + "name": "Simeulue", + "code": "09", + "full_code": "1109", + "provinsi_id": 1 + }, + { + "id": 132, + "type": "Kabupaten", + "name": "Jayawijaya", + "code": "01", + "full_code": "9501", + "provinsi_id": 27 + }, + { + "id": 133, + "type": "Kabupaten", + "name": "Jember", + "code": "09", + "full_code": "3509", + "provinsi_id": 11 + }, + { + "id": 134, + "type": "Kota", + "name": "Singkawang", + "code": "72", + "full_code": "6172", + "provinsi_id": 12 + }, + { + "id": 135, + "type": "Kabupaten", + "name": "Blitar", + "code": "05", + "full_code": "3505", + "provinsi_id": 11 + }, + { + "id": 136, + "type": "Kabupaten", + "name": "Jembrana", + "code": "01", + "full_code": "5101", + "provinsi_id": 2 + }, + { + "id": 137, + "type": "Kabupaten", + "name": "Sinjai", + "code": "07", + "full_code": "7307", + "provinsi_id": 32 + }, + { + "id": 138, + "type": "Kota", + "name": "Blitar", + "code": "72", + "full_code": "3572", + "provinsi_id": 11 + }, + { + "id": 139, + "type": "Kabupaten", + "name": "Jeneponto", + "code": "04", + "full_code": "7304", + "provinsi_id": 32 + }, + { + "id": 140, + "type": "Kabupaten", + "name": "Blora", + "code": "16", + "full_code": "3316", + "provinsi_id": 10 + }, + { + "id": 141, + "type": "Kabupaten", + "name": "Jepara", + "code": "20", + "full_code": "3320", + "provinsi_id": 10 + }, + { + "id": 142, + "type": "Kabupaten", + "name": "Sintang", + "code": "05", + "full_code": "6105", + "provinsi_id": 12 + }, + { + "id": 143, + "type": "Kabupaten", + "name": "Boalemo", + "code": "02", + "full_code": "7502", + "provinsi_id": 7 + }, + { + "id": 144, + "type": "Kabupaten", + "name": "Jombang", + "code": "17", + "full_code": "3517", + "provinsi_id": 11 + }, + { + "id": 145, + "type": "Kabupaten", + "name": "Bogor", + "code": "01", + "full_code": "3201", + "provinsi_id": 9 + }, + { + "id": 146, + "type": "Kabupaten", + "name": "Situbondo", + "code": "12", + "full_code": "3512", + "provinsi_id": 11 + }, + { + "id": 147, + "type": "Kabupaten", + "name": "Kaimana", + "code": "08", + "full_code": "9208", + "provinsi_id": 25 + }, + { + "id": 148, + "type": "Kota", + "name": "Bogor", + "code": "71", + "full_code": "3271", + "provinsi_id": 9 + }, + { + "id": 149, + "type": "Kabupaten", + "name": "Sleman", + "code": "04", + "full_code": "3404", + "provinsi_id": 5 + }, + { + "id": 150, + "type": "Kabupaten", + "name": "Kampar", + "code": "01", + "full_code": "1401", + "provinsi_id": 30 + }, + { + "id": 151, + "type": "Kabupaten", + "name": "Bojonegoro", + "code": "22", + "full_code": "3522", + "provinsi_id": 11 + }, + { + "id": 152, + "type": "Kabupaten", + "name": "Solok", + "code": "02", + "full_code": "1302", + "provinsi_id": 36 + }, + { + "id": 153, + "type": "Kabupaten", + "name": "Bolaang Mongondow", + "code": "01", + "full_code": "7101", + "provinsi_id": 35 + }, + { + "id": 154, + "type": "Kabupaten", + "name": "Bolaang Mongondow Selatan", + "code": "11", + "full_code": "7111", + "provinsi_id": 35 + }, + { + "id": 155, + "type": "Kota", + "name": "Solok", + "code": "72", + "full_code": "1372", + "provinsi_id": 36 + }, + { + "id": 156, + "type": "Kabupaten", + "name": "Kapuas", + "code": "03", + "full_code": "6203", + "provinsi_id": 14 + }, + { + "id": 157, + "type": "Kabupaten", + "name": "Solok Selatan", + "code": "11", + "full_code": "1311", + "provinsi_id": 36 + }, + { + "id": 158, + "type": "Kabupaten", + "name": "Bolaang Mongondow Timur", + "code": "10", + "full_code": "7110", + "provinsi_id": 35 + }, + { + "id": 159, + "type": "Kabupaten", + "name": "Kapuas Hulu", + "code": "06", + "full_code": "6106", + "provinsi_id": 12 + }, + { + "id": 160, + "type": "Kabupaten", + "name": "Karanganyar", + "code": "13", + "full_code": "3313", + "provinsi_id": 10 + }, + { + "id": 161, + "type": "Kabupaten", + "name": "Karangasem", + "code": "07", + "full_code": "5107", + "provinsi_id": 2 + }, + { + "id": 162, + "type": "Kabupaten", + "name": "Bolaang Mongondow Utara", + "code": "08", + "full_code": "7108", + "provinsi_id": 35 + }, + { + "id": 163, + "type": "Kabupaten", + "name": "Karawang", + "code": "15", + "full_code": "3215", + "provinsi_id": 9 + }, + { + "id": 164, + "type": "Kabupaten", + "name": "Bombana", + "code": "06", + "full_code": "7406", + "provinsi_id": 34 + }, + { + "id": 165, + "type": "Kabupaten", + "name": "Karimun", + "code": "02", + "full_code": "2102", + "provinsi_id": 18 + }, + { + "id": 166, + "type": "Kabupaten", + "name": "Bondowoso", + "code": "11", + "full_code": "3511", + "provinsi_id": 11 + }, + { + "id": 167, + "type": "Kabupaten", + "name": "Karo", + "code": "06", + "full_code": "1206", + "provinsi_id": 38 + }, + { + "id": 168, + "type": "Kabupaten", + "name": "Soppeng", + "code": "12", + "full_code": "7312", + "provinsi_id": 32 + }, + { + "id": 169, + "type": "Kabupaten", + "name": "Katingan", + "code": "06", + "full_code": "6206", + "provinsi_id": 14 + }, + { + "id": 170, + "type": "Kabupaten", + "name": "Kaur", + "code": "04", + "full_code": "1704", + "provinsi_id": 4 + }, + { + "id": 171, + "type": "Kabupaten", + "name": "Sorong", + "code": "01", + "full_code": "9201", + "provinsi_id": 26 + }, + { + "id": 172, + "type": "Kabupaten", + "name": "Kayong Utara", + "code": "11", + "full_code": "6111", + "provinsi_id": 12 + }, + { + "id": 173, + "type": "Kota", + "name": "Sorong", + "code": "71", + "full_code": "9271", + "provinsi_id": 26 + }, + { + "id": 174, + "type": "Kabupaten", + "name": "Sorong Selatan", + "code": "04", + "full_code": "9204", + "provinsi_id": 26 + }, + { + "id": 175, + "type": "Kabupaten", + "name": "Kebumen", + "code": "05", + "full_code": "3305", + "provinsi_id": 10 + }, + { + "id": 176, + "type": "Kabupaten", + "name": "Sragen", + "code": "14", + "full_code": "3314", + "provinsi_id": 10 + }, + { + "id": 177, + "type": "Kabupaten", + "name": "Kediri", + "code": "06", + "full_code": "3506", + "provinsi_id": 11 + }, + { + "id": 178, + "type": "Kabupaten", + "name": "Subang", + "code": "13", + "full_code": "3213", + "provinsi_id": 9 + }, + { + "id": 179, + "type": "Kota", + "name": "Subulussalam", + "code": "75", + "full_code": "1175", + "provinsi_id": 1 + }, + { + "id": 180, + "type": "Kota", + "name": "Sukabumi", + "code": "72", + "full_code": "3272", + "provinsi_id": 9 + }, + { + "id": 181, + "type": "Kota", + "name": "Kediri", + "code": "71", + "full_code": "3571", + "provinsi_id": 11 + }, + { + "id": 182, + "type": "Kabupaten", + "name": "Bone", + "code": "08", + "full_code": "7308", + "provinsi_id": 32 + }, + { + "id": 183, + "type": "Kabupaten", + "name": "Keerom", + "code": "11", + "full_code": "9111", + "provinsi_id": 24 + }, + { + "id": 184, + "type": "Kabupaten", + "name": "Sukabumi", + "code": "02", + "full_code": "3202", + "provinsi_id": 9 + }, + { + "id": 185, + "type": "Kabupaten", + "name": "Bone Bolango", + "code": "03", + "full_code": "7503", + "provinsi_id": 7 + }, + { + "id": 186, + "type": "Kabupaten", + "name": "Kendal", + "code": "24", + "full_code": "3324", + "provinsi_id": 10 + }, + { + "id": 187, + "type": "Kota", + "name": "Bontang", + "code": "74", + "full_code": "6474", + "provinsi_id": 15 + }, + { + "id": 188, + "type": "Kota", + "name": "Kendari", + "code": "71", + "full_code": "7471", + "provinsi_id": 34 + }, + { + "id": 189, + "type": "Kabupaten", + "name": "Boven Digoel", + "code": "02", + "full_code": "9302", + "provinsi_id": 28 + }, + { + "id": 190, + "type": "Kabupaten", + "name": "Kepahiang", + "code": "08", + "full_code": "1708", + "provinsi_id": 4 + }, + { + "id": 191, + "type": "Kabupaten", + "name": "Boyolali", + "code": "09", + "full_code": "3309", + "provinsi_id": 10 + }, + { + "id": 192, + "type": "Kabupaten", + "name": "Sukamara", + "code": "08", + "full_code": "6208", + "provinsi_id": 14 + }, + { + "id": 193, + "type": "Kabupaten", + "name": "Kepulauan Anambas", + "code": "05", + "full_code": "2105", + "provinsi_id": 18 + }, + { + "id": 194, + "type": "Kabupaten", + "name": "Sukoharjo", + "code": "11", + "full_code": "3311", + "provinsi_id": 10 + }, + { + "id": 195, + "type": "Kabupaten", + "name": "Sumba Barat", + "code": "12", + "full_code": "5312", + "provinsi_id": 23 + }, + { + "id": 196, + "type": "Kabupaten", + "name": "Brebes", + "code": "29", + "full_code": "3329", + "provinsi_id": 10 + }, + { + "id": 197, + "type": "Kota", + "name": "Bukittinggi", + "code": "75", + "full_code": "1375", + "provinsi_id": 36 + }, + { + "id": 198, + "type": "Kabupaten", + "name": "Buleleng", + "code": "08", + "full_code": "5108", + "provinsi_id": 2 + }, + { + "id": 199, + "type": "Kabupaten", + "name": "Bulukumba", + "code": "02", + "full_code": "7302", + "provinsi_id": 32 + }, + { + "id": 200, + "type": "Kabupaten", + "name": "Sumba Barat Daya", + "code": "18", + "full_code": "5318", + "provinsi_id": 23 + }, + { + "id": 201, + "type": "Kabupaten", + "name": "Sumba Tengah", + "code": "17", + "full_code": "5317", + "provinsi_id": 23 + }, + { + "id": 202, + "type": "Kabupaten", + "name": "Sumba Timur", + "code": "11", + "full_code": "5311", + "provinsi_id": 23 + }, + { + "id": 203, + "type": "Kabupaten", + "name": "Bulungan", + "code": "01", + "full_code": "6501", + "provinsi_id": 16 + }, + { + "id": 204, + "type": "Kabupaten", + "name": "Sumbawa", + "code": "04", + "full_code": "5204", + "provinsi_id": 22 + }, + { + "id": 205, + "type": "Kabupaten", + "name": "Bungo", + "code": "08", + "full_code": "1508", + "provinsi_id": 8 + }, + { + "id": 206, + "type": "Kabupaten", + "name": "Sumbawa Barat", + "code": "07", + "full_code": "5207", + "provinsi_id": 22 + }, + { + "id": 207, + "type": "Kabupaten", + "name": "Buol", + "code": "05", + "full_code": "7205", + "provinsi_id": 33 + }, + { + "id": 208, + "type": "Kabupaten", + "name": "Sumedang", + "code": "11", + "full_code": "3211", + "provinsi_id": 9 + }, + { + "id": 209, + "type": "Kabupaten", + "name": "Buru", + "code": "04", + "full_code": "8104", + "provinsi_id": 20 + }, + { + "id": 210, + "type": "Kabupaten", + "name": "Buru Selatan", + "code": "09", + "full_code": "8109", + "provinsi_id": 20 + }, + { + "id": 211, + "type": "Kabupaten", + "name": "Kepulauan Aru", + "code": "07", + "full_code": "8107", + "provinsi_id": 20 + }, + { + "id": 212, + "type": "Kabupaten", + "name": "Sumenep", + "code": "29", + "full_code": "3529", + "provinsi_id": 11 + }, + { + "id": 213, + "type": "Kabupaten", + "name": "Buton", + "code": "04", + "full_code": "7404", + "provinsi_id": 34 + }, + { + "id": 214, + "type": "Kota", + "name": "Sungai Penuh", + "code": "72", + "full_code": "1572", + "provinsi_id": 8 + }, + { + "id": 215, + "type": "Kabupaten", + "name": "Buton Selatan", + "code": "15", + "full_code": "7415", + "provinsi_id": 34 + }, + { + "id": 216, + "type": "Kabupaten", + "name": "Supiori", + "code": "19", + "full_code": "9119", + "provinsi_id": 24 + }, + { + "id": 217, + "type": "Kabupaten", + "name": "Buton Tengah", + "code": "14", + "full_code": "7414", + "provinsi_id": 34 + }, + { + "id": 218, + "type": "Kabupaten", + "name": "Buton Utara", + "code": "10", + "full_code": "7410", + "provinsi_id": 34 + }, + { + "id": 219, + "type": "Kota", + "name": "Surabaya", + "code": "78", + "full_code": "3578", + "provinsi_id": 11 + }, + { + "id": 220, + "type": "Kabupaten", + "name": "Kepulauan Mentawai", + "code": "09", + "full_code": "1309", + "provinsi_id": 36 + }, + { + "id": 221, + "type": "Kabupaten", + "name": "Ciamis", + "code": "07", + "full_code": "3207", + "provinsi_id": 9 + }, + { + "id": 222, + "type": "Kota", + "name": "Surakarta", + "code": "72", + "full_code": "3372", + "provinsi_id": 10 + }, + { + "id": 223, + "type": "Kabupaten", + "name": "Kepulauan Meranti", + "code": "10", + "full_code": "1410", + "provinsi_id": 30 + }, + { + "id": 224, + "type": "Kabupaten", + "name": "Cianjur", + "code": "03", + "full_code": "3203", + "provinsi_id": 9 + }, + { + "id": 225, + "type": "Kabupaten", + "name": "Tabalong", + "code": "09", + "full_code": "6309", + "provinsi_id": 13 + }, + { + "id": 226, + "type": "Kabupaten", + "name": "Kepulauan Sangihe", + "code": "03", + "full_code": "7103", + "provinsi_id": 35 + }, + { + "id": 227, + "type": "Kabupaten", + "name": "Kepulauan Selayar", + "code": "01", + "full_code": "7301", + "provinsi_id": 32 + }, + { + "id": 228, + "type": "Kabupaten", + "name": "Cilacap", + "code": "01", + "full_code": "3301", + "provinsi_id": 10 + }, + { + "id": 229, + "type": "Kota", + "name": "Cilegon", + "code": "72", + "full_code": "3672", + "provinsi_id": 3 + }, + { + "id": 230, + "type": "Kabupaten", + "name": "Tabanan", + "code": "02", + "full_code": "5102", + "provinsi_id": 2 + }, + { + "id": 231, + "type": "Kota", + "name": "Cimahi", + "code": "77", + "full_code": "3277", + "provinsi_id": 9 + }, + { + "id": 232, + "type": "Kabupaten", + "name": "Kepulauan Seribu", + "code": "01", + "full_code": "3101", + "provinsi_id": 6 + }, + { + "id": 233, + "type": "Kabupaten", + "name": "Takalar", + "code": "05", + "full_code": "7305", + "provinsi_id": 32 + }, + { + "id": 234, + "type": "Kota", + "name": "Cirebon", + "code": "74", + "full_code": "3274", + "provinsi_id": 9 + }, + { + "id": 235, + "type": "Kabupaten", + "name": "Kepulauan Siau Tagulandang Biaro (Sitaro)", + "code": "09", + "full_code": "7109", + "provinsi_id": 35 + }, + { + "id": 236, + "type": "Kabupaten", + "name": "Kepulauan Sula", + "code": "05", + "full_code": "8205", + "provinsi_id": 21 + }, + { + "id": 237, + "type": "Kabupaten", + "name": "Tambrauw", + "code": "09", + "full_code": "9209", + "provinsi_id": 26 + }, + { + "id": 238, + "type": "Kabupaten", + "name": "Kepulauan Talaud", + "code": "04", + "full_code": "7104", + "provinsi_id": 35 + }, + { + "id": 239, + "type": "Kabupaten", + "name": "Kepulauan Tanimbar (Maluku Tenggara Barat)", + "code": "03", + "full_code": "8103", + "provinsi_id": 20 + }, + { + "id": 240, + "type": "Kabupaten", + "name": "Cirebon", + "code": "09", + "full_code": "3209", + "provinsi_id": 9 + }, + { + "id": 241, + "type": "Kabupaten", + "name": "Dairi", + "code": "11", + "full_code": "1211", + "provinsi_id": 38 + }, + { + "id": 242, + "type": "Kabupaten", + "name": "Tana Tidung", + "code": "04", + "full_code": "6504", + "provinsi_id": 16 + }, + { + "id": 243, + "type": "Kabupaten", + "name": "Deiyai", + "code": "08", + "full_code": "9408", + "provinsi_id": 29 + }, + { + "id": 244, + "type": "Kabupaten", + "name": "Kepulauan Yapen", + "code": "05", + "full_code": "9105", + "provinsi_id": 24 + }, + { + "id": 245, + "type": "Kabupaten", + "name": "Deli Serdang", + "code": "07", + "full_code": "1207", + "provinsi_id": 38 + }, + { + "id": 246, + "type": "Kabupaten", + "name": "Tana Toraja", + "code": "18", + "full_code": "7318", + "provinsi_id": 32 + }, + { + "id": 247, + "type": "Kabupaten", + "name": "Demak", + "code": "21", + "full_code": "3321", + "provinsi_id": 10 + }, + { + "id": 248, + "type": "Kabupaten", + "name": "Kerinci", + "code": "01", + "full_code": "1501", + "provinsi_id": 8 + }, + { + "id": 249, + "type": "Kabupaten", + "name": "Tanah Bumbu", + "code": "10", + "full_code": "6310", + "provinsi_id": 13 + }, + { + "id": 250, + "type": "Kota", + "name": "Denpasar", + "code": "71", + "full_code": "5171", + "provinsi_id": 2 + }, + { + "id": 251, + "type": "Kabupaten", + "name": "Ketapang", + "code": "04", + "full_code": "6104", + "provinsi_id": 12 + }, + { + "id": 252, + "type": "Kota", + "name": "Depok", + "code": "76", + "full_code": "3276", + "provinsi_id": 9 + }, + { + "id": 253, + "type": "Kabupaten", + "name": "Tanah Datar", + "code": "04", + "full_code": "1304", + "provinsi_id": 36 + }, + { + "id": 254, + "type": "Kabupaten", + "name": "Klaten", + "code": "10", + "full_code": "3310", + "provinsi_id": 10 + }, + { + "id": 255, + "type": "Kabupaten", + "name": "Dharmasraya", + "code": "10", + "full_code": "1310", + "provinsi_id": 36 + }, + { + "id": 256, + "type": "Kabupaten", + "name": "Tanah Laut", + "code": "01", + "full_code": "6301", + "provinsi_id": 13 + }, + { + "id": 257, + "type": "Kabupaten", + "name": "Dogiyai", + "code": "06", + "full_code": "9406", + "provinsi_id": 29 + }, + { + "id": 258, + "type": "Kabupaten", + "name": "Klungkung", + "code": "05", + "full_code": "5105", + "provinsi_id": 2 + }, + { + "id": 259, + "type": "Kabupaten", + "name": "Kolaka", + "code": "01", + "full_code": "7401", + "provinsi_id": 34 + }, + { + "id": 260, + "type": "Kota", + "name": "Tangerang", + "code": "71", + "full_code": "3671", + "provinsi_id": 3 + }, + { + "id": 261, + "type": "Kabupaten", + "name": "Kolaka Timur", + "code": "11", + "full_code": "7411", + "provinsi_id": 34 + }, + { + "id": 262, + "type": "Kabupaten", + "name": "Tangerang", + "code": "03", + "full_code": "3603", + "provinsi_id": 3 + }, + { + "id": 263, + "type": "Kota", + "name": "Tangerang Selatan", + "code": "74", + "full_code": "3674", + "provinsi_id": 3 + }, + { + "id": 264, + "type": "Kabupaten", + "name": "Tanggamus", + "code": "06", + "full_code": "1806", + "provinsi_id": 19 + }, + { + "id": 265, + "type": "Kabupaten", + "name": "Kolaka Utara", + "code": "08", + "full_code": "7408", + "provinsi_id": 34 + }, + { + "id": 266, + "type": "Kabupaten", + "name": "Konawe", + "code": "02", + "full_code": "7402", + "provinsi_id": 34 + }, + { + "id": 267, + "type": "Kabupaten", + "name": "Konawe Kepulauan", + "code": "12", + "full_code": "7412", + "provinsi_id": 34 + }, + { + "id": 268, + "type": "Kota", + "name": "Tanjung Balai", + "code": "74", + "full_code": "1274", + "provinsi_id": 38 + }, + { + "id": 269, + "type": "Kabupaten", + "name": "Konawe Selatan", + "code": "05", + "full_code": "7405", + "provinsi_id": 34 + }, + { + "id": 270, + "type": "Kabupaten", + "name": "Konawe Utara", + "code": "09", + "full_code": "7409", + "provinsi_id": 34 + }, + { + "id": 271, + "type": "Kabupaten", + "name": "Kotabaru", + "code": "02", + "full_code": "6302", + "provinsi_id": 13 + }, + { + "id": 272, + "type": "Kabupaten", + "name": "Tanjung Jabung Barat", + "code": "06", + "full_code": "1506", + "provinsi_id": 8 + }, + { + "id": 273, + "type": "Kota", + "name": "Kotamobagu", + "code": "74", + "full_code": "7174", + "provinsi_id": 35 + }, + { + "id": 274, + "type": "Kabupaten", + "name": "Tanjung Jabung Timur", + "code": "07", + "full_code": "1507", + "provinsi_id": 8 + }, + { + "id": 275, + "type": "Kabupaten", + "name": "Kotawaringin Barat", + "code": "01", + "full_code": "6201", + "provinsi_id": 14 + }, + { + "id": 276, + "type": "Kabupaten", + "name": "Kotawaringin Timur", + "code": "02", + "full_code": "6202", + "provinsi_id": 14 + }, + { + "id": 277, + "type": "Kota", + "name": "Tanjung Pinang", + "code": "72", + "full_code": "2172", + "provinsi_id": 18 + }, + { + "id": 278, + "type": "Kabupaten", + "name": "Kuantan Singingi", + "code": "09", + "full_code": "1409", + "provinsi_id": 30 + }, + { + "id": 279, + "type": "Kabupaten", + "name": "Tapanuli Selatan", + "code": "03", + "full_code": "1203", + "provinsi_id": 38 + }, + { + "id": 280, + "type": "Kabupaten", + "name": "Kubu Raya", + "code": "12", + "full_code": "6112", + "provinsi_id": 12 + }, + { + "id": 281, + "type": "Kabupaten", + "name": "Kudus", + "code": "19", + "full_code": "3319", + "provinsi_id": 10 + }, + { + "id": 282, + "type": "Kabupaten", + "name": "Tapanuli Tengah", + "code": "01", + "full_code": "1201", + "provinsi_id": 38 + }, + { + "id": 283, + "type": "Kabupaten", + "name": "Tapanuli Utara", + "code": "02", + "full_code": "1202", + "provinsi_id": 38 + }, + { + "id": 284, + "type": "Kabupaten", + "name": "Tapin", + "code": "05", + "full_code": "6305", + "provinsi_id": 13 + }, + { + "id": 285, + "type": "Kota", + "name": "Tarakan", + "code": "71", + "full_code": "6571", + "provinsi_id": 16 + }, + { + "id": 286, + "type": "Kota", + "name": "Tasikmalaya", + "code": "78", + "full_code": "3278", + "provinsi_id": 9 + }, + { + "id": 287, + "type": "Kabupaten", + "name": "Kulon Progo", + "code": "01", + "full_code": "3401", + "provinsi_id": 5 + }, + { + "id": 288, + "type": "Kabupaten", + "name": "Kuningan", + "code": "08", + "full_code": "3208", + "provinsi_id": 9 + }, + { + "id": 289, + "type": "Kabupaten", + "name": "Kupang", + "code": "01", + "full_code": "5301", + "provinsi_id": 23 + }, + { + "id": 290, + "type": "Kota", + "name": "Kupang", + "code": "71", + "full_code": "5371", + "provinsi_id": 23 + }, + { + "id": 291, + "type": "Kabupaten", + "name": "Tasikmalaya", + "code": "06", + "full_code": "3206", + "provinsi_id": 9 + }, + { + "id": 292, + "type": "Kabupaten", + "name": "Kutai Barat", + "code": "07", + "full_code": "6407", + "provinsi_id": 15 + }, + { + "id": 293, + "type": "Kabupaten", + "name": "Kutai Kartanegara", + "code": "02", + "full_code": "6402", + "provinsi_id": 15 + }, + { + "id": 294, + "type": "Kabupaten", + "name": "Kutai Timur", + "code": "08", + "full_code": "6408", + "provinsi_id": 15 + }, + { + "id": 295, + "type": "Kabupaten", + "name": "Labuhanbatu", + "code": "10", + "full_code": "1210", + "provinsi_id": 38 + }, + { + "id": 296, + "type": "Kota", + "name": "Tebing Tinggi", + "code": "76", + "full_code": "1276", + "provinsi_id": 38 + }, + { + "id": 297, + "type": "Kabupaten", + "name": "Labuhanbatu Selatan", + "code": "22", + "full_code": "1222", + "provinsi_id": 38 + }, + { + "id": 298, + "type": "Kabupaten", + "name": "Tebo", + "code": "09", + "full_code": "1509", + "provinsi_id": 8 + }, + { + "id": 299, + "type": "Kabupaten", + "name": "Tegal", + "code": "28", + "full_code": "3328", + "provinsi_id": 10 + }, + { + "id": 300, + "type": "Kota", + "name": "Tegal", + "code": "76", + "full_code": "3376", + "provinsi_id": 10 + }, + { + "id": 301, + "type": "Kabupaten", + "name": "Teluk Bintuni", + "code": "06", + "full_code": "9206", + "provinsi_id": 25 + }, + { + "id": 302, + "type": "Kabupaten", + "name": "Teluk Wondama", + "code": "07", + "full_code": "9207", + "provinsi_id": 25 + }, + { + "id": 303, + "type": "Kabupaten", + "name": "Labuhanbatu Utara", + "code": "23", + "full_code": "1223", + "provinsi_id": 38 + }, + { + "id": 304, + "type": "Kabupaten", + "name": "Temanggung", + "code": "23", + "full_code": "3323", + "provinsi_id": 10 + }, + { + "id": 305, + "type": "Kabupaten", + "name": "Lahat", + "code": "04", + "full_code": "1604", + "provinsi_id": 37 + }, + { + "id": 306, + "type": "Kota", + "name": "Ternate", + "code": "71", + "full_code": "8271", + "provinsi_id": 21 + }, + { + "id": 307, + "type": "Kabupaten", + "name": "Lamandau", + "code": "09", + "full_code": "6209", + "provinsi_id": 14 + }, + { + "id": 308, + "type": "Kabupaten", + "name": "Dompu", + "code": "05", + "full_code": "5205", + "provinsi_id": 22 + }, + { + "id": 309, + "type": "Kabupaten", + "name": "Donggala", + "code": "03", + "full_code": "7203", + "provinsi_id": 33 + }, + { + "id": 310, + "type": "Kota", + "name": "Dumai", + "code": "72", + "full_code": "1472", + "provinsi_id": 30 + }, + { + "id": 311, + "type": "Kabupaten", + "name": "Empat Lawang", + "code": "11", + "full_code": "1611", + "provinsi_id": 37 + }, + { + "id": 312, + "type": "Kabupaten", + "name": "Lamongan", + "code": "24", + "full_code": "3524", + "provinsi_id": 11 + }, + { + "id": 313, + "type": "Kabupaten", + "name": "Ende", + "code": "08", + "full_code": "5308", + "provinsi_id": 23 + }, + { + "id": 314, + "type": "Kabupaten", + "name": "Lampung Barat", + "code": "04", + "full_code": "1804", + "provinsi_id": 19 + }, + { + "id": 315, + "type": "Kota", + "name": "Tidore Kepulauan", + "code": "72", + "full_code": "8272", + "provinsi_id": 21 + }, + { + "id": 316, + "type": "Kabupaten", + "name": "Enrekang", + "code": "16", + "full_code": "7316", + "provinsi_id": 32 + }, + { + "id": 317, + "type": "Kabupaten", + "name": "Lampung Selatan", + "code": "01", + "full_code": "1801", + "provinsi_id": 19 + }, + { + "id": 318, + "type": "Kabupaten", + "name": "Fak Fak", + "code": "03", + "full_code": "9203", + "provinsi_id": 25 + }, + { + "id": 319, + "type": "Kabupaten", + "name": "Timor Tengah Selatan", + "code": "02", + "full_code": "5302", + "provinsi_id": 23 + }, + { + "id": 320, + "type": "Kabupaten", + "name": "Lampung Tengah", + "code": "02", + "full_code": "1802", + "provinsi_id": 19 + }, + { + "id": 321, + "type": "Kabupaten", + "name": "Flores Timur", + "code": "06", + "full_code": "5306", + "provinsi_id": 23 + }, + { + "id": 322, + "type": "Kabupaten", + "name": "Lampung Timur", + "code": "07", + "full_code": "1807", + "provinsi_id": 19 + }, + { + "id": 323, + "type": "Kabupaten", + "name": "Garut", + "code": "05", + "full_code": "3205", + "provinsi_id": 9 + }, + { + "id": 324, + "type": "Kabupaten", + "name": "Timor Tengah Utara", + "code": "03", + "full_code": "5303", + "provinsi_id": 23 + }, + { + "id": 325, + "type": "Kabupaten", + "name": "Lampung Utara", + "code": "03", + "full_code": "1803", + "provinsi_id": 19 + }, + { + "id": 326, + "type": "Kabupaten", + "name": "Toba", + "code": "12", + "full_code": "1212", + "provinsi_id": 38 + }, + { + "id": 327, + "type": "Kabupaten", + "name": "Tojo Una Una", + "code": "09", + "full_code": "7209", + "provinsi_id": 33 + }, + { + "id": 328, + "type": "Kabupaten", + "name": "Gayo Lues", + "code": "13", + "full_code": "1113", + "provinsi_id": 1 + }, + { + "id": 329, + "type": "Kabupaten", + "name": "Landak", + "code": "08", + "full_code": "6108", + "provinsi_id": 12 + }, + { + "id": 330, + "type": "Kabupaten", + "name": "Gianyar", + "code": "04", + "full_code": "5104", + "provinsi_id": 2 + }, + { + "id": 331, + "type": "Kabupaten", + "name": "Langkat", + "code": "05", + "full_code": "1205", + "provinsi_id": 38 + }, + { + "id": 332, + "type": "Kabupaten", + "name": "Gorontalo", + "code": "01", + "full_code": "7501", + "provinsi_id": 7 + }, + { + "id": 333, + "type": "Kota", + "name": "Langsa", + "code": "74", + "full_code": "1174", + "provinsi_id": 1 + }, + { + "id": 334, + "type": "Kabupaten", + "name": "Toli Toli", + "code": "04", + "full_code": "7204", + "provinsi_id": 33 + }, + { + "id": 335, + "type": "Kabupaten", + "name": "Lanny Jaya", + "code": "07", + "full_code": "9507", + "provinsi_id": 27 + }, + { + "id": 336, + "type": "Kabupaten", + "name": "Lebak", + "code": "02", + "full_code": "3602", + "provinsi_id": 3 + }, + { + "id": 337, + "type": "Kota", + "name": "Gorontalo", + "code": "71", + "full_code": "7571", + "provinsi_id": 7 + }, + { + "id": 338, + "type": "Kabupaten", + "name": "Tolikara", + "code": "04", + "full_code": "9504", + "provinsi_id": 27 + }, + { + "id": 339, + "type": "Kota", + "name": "Tomohon", + "code": "73", + "full_code": "7173", + "provinsi_id": 35 + }, + { + "id": 340, + "type": "Kabupaten", + "name": "Lebong", + "code": "07", + "full_code": "1707", + "provinsi_id": 4 + }, + { + "id": 341, + "type": "Kabupaten", + "name": "Toraja Utara", + "code": "26", + "full_code": "7326", + "provinsi_id": 32 + }, + { + "id": 342, + "type": "Kabupaten", + "name": "Lembata", + "code": "13", + "full_code": "5313", + "provinsi_id": 23 + }, + { + "id": 343, + "type": "Kota", + "name": "Lhokseumawe", + "code": "73", + "full_code": "1173", + "provinsi_id": 1 + }, + { + "id": 344, + "type": "Kabupaten", + "name": "Lima Puluh Kota", + "code": "07", + "full_code": "1307", + "provinsi_id": 36 + }, + { + "id": 345, + "type": "Kabupaten", + "name": "Lingga", + "code": "04", + "full_code": "2104", + "provinsi_id": 18 + }, + { + "id": 346, + "type": "Kabupaten", + "name": "Trenggalek", + "code": "03", + "full_code": "3503", + "provinsi_id": 11 + }, + { + "id": 347, + "type": "Kota", + "name": "Tual", + "code": "72", + "full_code": "8172", + "provinsi_id": 20 + }, + { + "id": 348, + "type": "Kabupaten", + "name": "Tuban", + "code": "23", + "full_code": "3523", + "provinsi_id": 11 + }, + { + "id": 349, + "type": "Kabupaten", + "name": "Lombok Barat", + "code": "01", + "full_code": "5201", + "provinsi_id": 22 + }, + { + "id": 350, + "type": "Kabupaten", + "name": "Tulang Bawang", + "code": "05", + "full_code": "1805", + "provinsi_id": 19 + }, + { + "id": 351, + "type": "Kabupaten", + "name": "Lombok Tengah", + "code": "02", + "full_code": "5202", + "provinsi_id": 22 + }, + { + "id": 352, + "type": "Kabupaten", + "name": "Lombok Timur", + "code": "03", + "full_code": "5203", + "provinsi_id": 22 + }, + { + "id": 353, + "type": "Kabupaten", + "name": "Tulang Bawang Barat", + "code": "12", + "full_code": "1812", + "provinsi_id": 19 + }, + { + "id": 354, + "type": "Kabupaten", + "name": "Lombok Utara", + "code": "08", + "full_code": "5208", + "provinsi_id": 22 + }, + { + "id": 355, + "type": "Kota", + "name": "Lubuk Linggau", + "code": "73", + "full_code": "1673", + "provinsi_id": 37 + }, + { + "id": 356, + "type": "Kabupaten", + "name": "Tulungagung", + "code": "04", + "full_code": "3504", + "provinsi_id": 11 + }, + { + "id": 357, + "type": "Kabupaten", + "name": "Lumajang", + "code": "08", + "full_code": "3508", + "provinsi_id": 11 + }, + { + "id": 358, + "type": "Kabupaten", + "name": "Wajo", + "code": "13", + "full_code": "7313", + "provinsi_id": 32 + }, + { + "id": 359, + "type": "Kabupaten", + "name": "Luwu", + "code": "17", + "full_code": "7317", + "provinsi_id": 32 + }, + { + "id": 360, + "type": "Kabupaten", + "name": "Luwu Timur", + "code": "24", + "full_code": "7324", + "provinsi_id": 32 + }, + { + "id": 361, + "type": "Kabupaten", + "name": "Wakatobi", + "code": "07", + "full_code": "7407", + "provinsi_id": 34 + }, + { + "id": 362, + "type": "Kabupaten", + "name": "Waropen", + "code": "15", + "full_code": "9115", + "provinsi_id": 24 + }, + { + "id": 363, + "type": "Kabupaten", + "name": "Way Kanan", + "code": "08", + "full_code": "1808", + "provinsi_id": 19 + }, + { + "id": 364, + "type": "Kabupaten", + "name": "Wonogiri", + "code": "12", + "full_code": "3312", + "provinsi_id": 10 + }, + { + "id": 365, + "type": "Kabupaten", + "name": "Wonosobo", + "code": "07", + "full_code": "3307", + "provinsi_id": 10 + }, + { + "id": 366, + "type": "Kabupaten", + "name": "Yahukimo", + "code": "03", + "full_code": "9503", + "provinsi_id": 27 + }, + { + "id": 367, + "type": "Kabupaten", + "name": "Yalimo", + "code": "06", + "full_code": "9506", + "provinsi_id": 27 + }, + { + "id": 368, + "type": "Kota", + "name": "Yogyakarta", + "code": "71", + "full_code": "3471", + "provinsi_id": 5 + }, + { + "id": 369, + "type": "Kabupaten", + "name": "Luwu Utara", + "code": "22", + "full_code": "7322", + "provinsi_id": 32 + }, + { + "id": 370, + "type": "Kabupaten", + "name": "Madiun", + "code": "19", + "full_code": "3519", + "provinsi_id": 11 + }, + { + "id": 371, + "type": "Kota", + "name": "Madiun", + "code": "77", + "full_code": "3577", + "provinsi_id": 11 + }, + { + "id": 372, + "type": "Kabupaten", + "name": "Magelang", + "code": "08", + "full_code": "3308", + "provinsi_id": 10 + }, + { + "id": 373, + "type": "Kota", + "name": "Magelang", + "code": "71", + "full_code": "3371", + "provinsi_id": 10 + }, + { + "id": 374, + "type": "Kabupaten", + "name": "Magetan", + "code": "20", + "full_code": "3520", + "provinsi_id": 11 + }, + { + "id": 375, + "type": "Kabupaten", + "name": "Mahakam Ulu", + "code": "11", + "full_code": "6411", + "provinsi_id": 15 + }, + { + "id": 376, + "type": "Kabupaten", + "name": "Majalengka", + "code": "10", + "full_code": "3210", + "provinsi_id": 9 + }, + { + "id": 377, + "type": "Kabupaten", + "name": "Majene", + "code": "05", + "full_code": "7605", + "provinsi_id": 31 + }, + { + "id": 378, + "type": "Kota", + "name": "Makassar", + "code": "71", + "full_code": "7371", + "provinsi_id": 32 + }, + { + "id": 379, + "type": "Kabupaten", + "name": "Malaka", + "code": "21", + "full_code": "5321", + "provinsi_id": 23 + }, + { + "id": 380, + "type": "Kabupaten", + "name": "Malang", + "code": "07", + "full_code": "3507", + "provinsi_id": 11 + }, + { + "id": 381, + "type": "Kota", + "name": "Malang", + "code": "73", + "full_code": "3573", + "provinsi_id": 11 + }, + { + "id": 382, + "type": "Kabupaten", + "name": "Malinau", + "code": "02", + "full_code": "6502", + "provinsi_id": 16 + }, + { + "id": 383, + "type": "Kabupaten", + "name": "Maluku Barat Daya", + "code": "08", + "full_code": "8108", + "provinsi_id": 20 + }, + { + "id": 384, + "type": "Kabupaten", + "name": "Maluku Tengah", + "code": "01", + "full_code": "8101", + "provinsi_id": 20 + }, + { + "id": 385, + "type": "Kabupaten", + "name": "Maluku Tenggara", + "code": "02", + "full_code": "8102", + "provinsi_id": 20 + }, + { + "id": 386, + "type": "Kabupaten", + "name": "Mamasa", + "code": "03", + "full_code": "7603", + "provinsi_id": 31 + }, + { + "id": 387, + "type": "Kabupaten", + "name": "Mamberamo Raya", + "code": "20", + "full_code": "9120", + "provinsi_id": 24 + }, + { + "id": 388, + "type": "Kabupaten", + "name": "Mamberamo Tengah", + "code": "05", + "full_code": "9505", + "provinsi_id": 27 + }, + { + "id": 389, + "type": "Kabupaten", + "name": "Mamuju", + "code": "02", + "full_code": "7602", + "provinsi_id": 31 + }, + { + "id": 390, + "type": "Kabupaten", + "name": "Mamuju Tengah", + "code": "06", + "full_code": "7606", + "provinsi_id": 31 + }, + { + "id": 391, + "type": "Kota", + "name": "Manado", + "code": "71", + "full_code": "7171", + "provinsi_id": 35 + }, + { + "id": 392, + "type": "Kabupaten", + "name": "Mandailing Natal", + "code": "13", + "full_code": "1213", + "provinsi_id": 38 + }, + { + "id": 393, + "type": "Kabupaten", + "name": "Manggarai", + "code": "10", + "full_code": "5310", + "provinsi_id": 23 + }, + { + "id": 394, + "type": "Kabupaten", + "name": "Manggarai Barat", + "code": "15", + "full_code": "5315", + "provinsi_id": 23 + }, + { + "id": 395, + "type": "Kabupaten", + "name": "Manggarai Timur", + "code": "19", + "full_code": "5319", + "provinsi_id": 23 + }, + { + "id": 396, + "type": "Kabupaten", + "name": "Manokwari", + "code": "02", + "full_code": "9202", + "provinsi_id": 25 + }, + { + "id": 397, + "type": "Kabupaten", + "name": "Manokwari Selatan", + "code": "11", + "full_code": "9211", + "provinsi_id": 25 + }, + { + "id": 398, + "type": "Kabupaten", + "name": "Mappi", + "code": "03", + "full_code": "9303", + "provinsi_id": 28 + }, + { + "id": 399, + "type": "Kabupaten", + "name": "Maros", + "code": "09", + "full_code": "7309", + "provinsi_id": 32 + }, + { + "id": 400, + "type": "Kota", + "name": "Mataram", + "code": "71", + "full_code": "5271", + "provinsi_id": 22 + }, + { + "id": 401, + "type": "Kabupaten", + "name": "Maybrat", + "code": "10", + "full_code": "9210", + "provinsi_id": 26 + }, + { + "id": 402, + "type": "Kota", + "name": "Medan", + "code": "71", + "full_code": "1271", + "provinsi_id": 38 + }, + { + "id": 403, + "type": "Kabupaten", + "name": "Melawi", + "code": "10", + "full_code": "6110", + "provinsi_id": 12 + }, + { + "id": 404, + "type": "Kabupaten", + "name": "Mempawah", + "code": "02", + "full_code": "6102", + "provinsi_id": 12 + }, + { + "id": 405, + "type": "Kabupaten", + "name": "Merangin", + "code": "02", + "full_code": "1502", + "provinsi_id": 8 + }, + { + "id": 406, + "type": "Kabupaten", + "name": "Merauke", + "code": "01", + "full_code": "9301", + "provinsi_id": 28 + }, + { + "id": 407, + "type": "Kabupaten", + "name": "Mesuji", + "code": "11", + "full_code": "1811", + "provinsi_id": 19 + }, + { + "id": 408, + "type": "Kota", + "name": "Metro", + "code": "72", + "full_code": "1872", + "provinsi_id": 19 + }, + { + "id": 409, + "type": "Kabupaten", + "name": "Mimika", + "code": "04", + "full_code": "9404", + "provinsi_id": 29 + }, + { + "id": 410, + "type": "Kabupaten", + "name": "Minahasa", + "code": "02", + "full_code": "7102", + "provinsi_id": 35 + }, + { + "id": 411, + "type": "Kabupaten", + "name": "Minahasa Selatan", + "code": "05", + "full_code": "7105", + "provinsi_id": 35 + }, + { + "id": 412, + "type": "Kabupaten", + "name": "Minahasa Tenggara", + "code": "07", + "full_code": "7107", + "provinsi_id": 35 + }, + { + "id": 413, + "type": "Kabupaten", + "name": "Minahasa Utara", + "code": "06", + "full_code": "7106", + "provinsi_id": 35 + }, + { + "id": 414, + "type": "Kabupaten", + "name": "Mojokerto", + "code": "16", + "full_code": "3516", + "provinsi_id": 11 + }, + { + "id": 415, + "type": "Kota", + "name": "Mojokerto", + "code": "76", + "full_code": "3576", + "provinsi_id": 11 + }, + { + "id": 416, + "type": "Kabupaten", + "name": "Morowali", + "code": "06", + "full_code": "7206", + "provinsi_id": 33 + }, + { + "id": 417, + "type": "Kabupaten", + "name": "Morowali Utara", + "code": "12", + "full_code": "7212", + "provinsi_id": 33 + }, + { + "id": 418, + "type": "Kabupaten", + "name": "Muara Enim", + "code": "03", + "full_code": "1603", + "provinsi_id": 37 + }, + { + "id": 419, + "type": "Kabupaten", + "name": "Muaro Jambi", + "code": "05", + "full_code": "1505", + "provinsi_id": 8 + }, + { + "id": 420, + "type": "Kabupaten", + "name": "Muko Muko", + "code": "06", + "full_code": "1706", + "provinsi_id": 4 + }, + { + "id": 421, + "type": "Kabupaten", + "name": "Muna", + "code": "03", + "full_code": "7403", + "provinsi_id": 34 + }, + { + "id": 422, + "type": "Kabupaten", + "name": "Muna Barat", + "code": "13", + "full_code": "7413", + "provinsi_id": 34 + }, + { + "id": 423, + "type": "Kabupaten", + "name": "Murung Raya", + "code": "12", + "full_code": "6212", + "provinsi_id": 14 + }, + { + "id": 424, + "type": "Kabupaten", + "name": "Musi Banyuasin", + "code": "06", + "full_code": "1606", + "provinsi_id": 37 + }, + { + "id": 425, + "type": "Kabupaten", + "name": "Musi Rawas", + "code": "05", + "full_code": "1605", + "provinsi_id": 37 + }, + { + "id": 426, + "type": "Kabupaten", + "name": "Musi Rawas Utara", + "code": "13", + "full_code": "1613", + "provinsi_id": 37 + }, + { + "id": 427, + "type": "Kabupaten", + "name": "Nabire", + "code": "01", + "full_code": "9401", + "provinsi_id": 29 + }, + { + "id": 428, + "type": "Kabupaten", + "name": "Nagan Raya", + "code": "15", + "full_code": "1115", + "provinsi_id": 1 + }, + { + "id": 429, + "type": "Kabupaten", + "name": "Nagekeo", + "code": "16", + "full_code": "5316", + "provinsi_id": 23 + }, + { + "id": 430, + "type": "Kabupaten", + "name": "Natuna", + "code": "03", + "full_code": "2103", + "provinsi_id": 18 + }, + { + "id": 431, + "type": "Kabupaten", + "name": "Nduga", + "code": "08", + "full_code": "9508", + "provinsi_id": 27 + }, + { + "id": 432, + "type": "Kabupaten", + "name": "Ngada", + "code": "09", + "full_code": "5309", + "provinsi_id": 23 + }, + { + "id": 433, + "type": "Kabupaten", + "name": "Nganjuk", + "code": "18", + "full_code": "3518", + "provinsi_id": 11 + }, + { + "id": 434, + "type": "Kabupaten", + "name": "Ngawi", + "code": "21", + "full_code": "3521", + "provinsi_id": 11 + }, + { + "id": 435, + "type": "Kabupaten", + "name": "Nias", + "code": "04", + "full_code": "1204", + "provinsi_id": 38 + }, + { + "id": 436, + "type": "Kabupaten", + "name": "Nias Barat", + "code": "25", + "full_code": "1225", + "provinsi_id": 38 + }, + { + "id": 437, + "type": "Kabupaten", + "name": "Nias Selatan", + "code": "14", + "full_code": "1214", + "provinsi_id": 38 + }, + { + "id": 438, + "type": "Kabupaten", + "name": "Nias Utara", + "code": "24", + "full_code": "1224", + "provinsi_id": 38 + }, + { + "id": 439, + "type": "Kabupaten", + "name": "Nunukan", + "code": "03", + "full_code": "6503", + "provinsi_id": 16 + }, + { + "id": 440, + "type": "Kabupaten", + "name": "Ogan Ilir", + "code": "10", + "full_code": "1610", + "provinsi_id": 37 + }, + { + "id": 441, + "type": "Kabupaten", + "name": "Ogan Komering Ilir", + "code": "02", + "full_code": "1602", + "provinsi_id": 37 + }, + { + "id": 442, + "type": "Kabupaten", + "name": "Ogan Komering Ulu", + "code": "01", + "full_code": "1601", + "provinsi_id": 37 + }, + { + "id": 443, + "type": "Kabupaten", + "name": "Ogan Komering Ulu Selatan", + "code": "09", + "full_code": "1609", + "provinsi_id": 37 + }, + { + "id": 444, + "type": "Kabupaten", + "name": "Ogan Komering Ulu Timur", + "code": "08", + "full_code": "1608", + "provinsi_id": 37 + }, + { + "id": 445, + "type": "Kabupaten", + "name": "Pacitan", + "code": "01", + "full_code": "3501", + "provinsi_id": 11 + }, + { + "id": 446, + "type": "Kota", + "name": "Padang", + "code": "71", + "full_code": "1371", + "provinsi_id": 36 + }, + { + "id": 447, + "type": "Kabupaten", + "name": "Padang Lawas", + "code": "21", + "full_code": "1221", + "provinsi_id": 38 + }, + { + "id": 448, + "type": "Kabupaten", + "name": "Padang Lawas Utara", + "code": "20", + "full_code": "1220", + "provinsi_id": 38 + }, + { + "id": 449, + "type": "Kota", + "name": "Padang Panjang", + "code": "74", + "full_code": "1374", + "provinsi_id": 36 + }, + { + "id": 450, + "type": "Kabupaten", + "name": "Padang Pariaman", + "code": "05", + "full_code": "1305", + "provinsi_id": 36 + }, + { + "id": 451, + "type": "Kota", + "name": "Padangsidimpuan", + "code": "77", + "full_code": "1277", + "provinsi_id": 38 + }, + { + "id": 452, + "type": "Kota", + "name": "Pagar Alam", + "code": "72", + "full_code": "1672", + "provinsi_id": 37 + }, + { + "id": 453, + "type": "Kabupaten", + "name": "Pahuwato", + "code": "04", + "full_code": "7504", + "provinsi_id": 7 + }, + { + "id": 454, + "type": "Kabupaten", + "name": "Pakpak Bharat", + "code": "15", + "full_code": "1215", + "provinsi_id": 38 + }, + { + "id": 455, + "type": "Kota", + "name": "Palangkaraya", + "code": "71", + "full_code": "6271", + "provinsi_id": 14 + }, + { + "id": 456, + "type": "Kota", + "name": "Palembang", + "code": "71", + "full_code": "1671", + "provinsi_id": 37 + }, + { + "id": 457, + "type": "Kota", + "name": "Palopo", + "code": "73", + "full_code": "7373", + "provinsi_id": 32 + }, + { + "id": 458, + "type": "Kota", + "name": "Palu", + "code": "71", + "full_code": "7271", + "provinsi_id": 33 + }, + { + "id": 459, + "type": "Kabupaten", + "name": "Pamekasan", + "code": "28", + "full_code": "3528", + "provinsi_id": 11 + }, + { + "id": 460, + "type": "Kabupaten", + "name": "Pandeglang", + "code": "01", + "full_code": "3601", + "provinsi_id": 3 + }, + { + "id": 461, + "type": "Kabupaten", + "name": "Pangandaran", + "code": "18", + "full_code": "3218", + "provinsi_id": 9 + }, + { + "id": 462, + "type": "Kabupaten", + "name": "Pangkajene Kepulauan", + "code": "10", + "full_code": "7310", + "provinsi_id": 32 + }, + { + "id": 463, + "type": "Kota", + "name": "Pangkal Pinang", + "code": "71", + "full_code": "1971", + "provinsi_id": 17 + }, + { + "id": 464, + "type": "Kabupaten", + "name": "Paniai", + "code": "03", + "full_code": "9403", + "provinsi_id": 29 + }, + { + "id": 465, + "type": "Kota", + "name": "Pare Pare", + "code": "72", + "full_code": "7372", + "provinsi_id": 32 + }, + { + "id": 466, + "type": "Kota", + "name": "Pariaman", + "code": "77", + "full_code": "1377", + "provinsi_id": 36 + }, + { + "id": 467, + "type": "Kabupaten", + "name": "Parigi Moutong", + "code": "08", + "full_code": "7208", + "provinsi_id": 33 + }, + { + "id": 468, + "type": "Kabupaten", + "name": "Pasaman", + "code": "08", + "full_code": "1308", + "provinsi_id": 36 + }, + { + "id": 469, + "type": "Kabupaten", + "name": "Pasaman Barat", + "code": "12", + "full_code": "1312", + "provinsi_id": 36 + }, + { + "id": 470, + "type": "Kabupaten", + "name": "Pasangkayu (Mamuju Utara)", + "code": "01", + "full_code": "7601", + "provinsi_id": 31 + }, + { + "id": 471, + "type": "Kabupaten", + "name": "Paser", + "code": "01", + "full_code": "6401", + "provinsi_id": 15 + }, + { + "id": 472, + "type": "Kabupaten", + "name": "Pasuruan", + "code": "14", + "full_code": "3514", + "provinsi_id": 11 + }, + { + "id": 473, + "type": "Kota", + "name": "Pasuruan", + "code": "75", + "full_code": "3575", + "provinsi_id": 11 + }, + { + "id": 474, + "type": "Kabupaten", + "name": "Pati", + "code": "18", + "full_code": "3318", + "provinsi_id": 10 + }, + { + "id": 475, + "type": "Kota", + "name": "Payakumbuh", + "code": "76", + "full_code": "1376", + "provinsi_id": 36 + }, + { + "id": 476, + "type": "Kabupaten", + "name": "Pegunungan Arfak", + "code": "12", + "full_code": "9212", + "provinsi_id": 25 + }, + { + "id": 477, + "type": "Kabupaten", + "name": "Pegunungan Bintang", + "code": "02", + "full_code": "9502", + "provinsi_id": 27 + }, + { + "id": 478, + "type": "Kabupaten", + "name": "Pekalongan", + "code": "26", + "full_code": "3326", + "provinsi_id": 10 + }, + { + "id": 479, + "type": "Kota", + "name": "Pekalongan", + "code": "75", + "full_code": "3375", + "provinsi_id": 10 + }, + { + "id": 480, + "type": "Kota", + "name": "Pekanbaru", + "code": "71", + "full_code": "1471", + "provinsi_id": 30 + }, + { + "id": 481, + "type": "Kabupaten", + "name": "Pelalawan", + "code": "05", + "full_code": "1405", + "provinsi_id": 30 + }, + { + "id": 482, + "type": "Kabupaten", + "name": "Pemalang", + "code": "27", + "full_code": "3327", + "provinsi_id": 10 + }, + { + "id": 483, + "type": "Kota", + "name": "Pematangsiantar", + "code": "72", + "full_code": "1272", + "provinsi_id": 38 + }, + { + "id": 484, + "type": "Kabupaten", + "name": "Penajam Paser Utara", + "code": "09", + "full_code": "6409", + "provinsi_id": 15 + }, + { + "id": 485, + "type": "Kabupaten", + "name": "Penukal Abab Lematang Ilir", + "code": "12", + "full_code": "1612", + "provinsi_id": 37 + }, + { + "id": 486, + "type": "Kabupaten", + "name": "Pesawaran", + "code": "09", + "full_code": "1809", + "provinsi_id": 19 + }, + { + "id": 487, + "type": "Kabupaten", + "name": "Pesisir Barat", + "code": "13", + "full_code": "1813", + "provinsi_id": 19 + }, + { + "id": 488, + "type": "Kabupaten", + "name": "Pesisir Selatan", + "code": "01", + "full_code": "1301", + "provinsi_id": 36 + }, + { + "id": 489, + "type": "Kabupaten", + "name": "Pidie", + "code": "07", + "full_code": "1107", + "provinsi_id": 1 + }, + { + "id": 490, + "type": "Kabupaten", + "name": "Pidie Jaya", + "code": "18", + "full_code": "1118", + "provinsi_id": 1 + }, + { + "id": 491, + "type": "Kabupaten", + "name": "Pinrang", + "code": "15", + "full_code": "7315", + "provinsi_id": 32 + }, + { + "id": 492, + "type": "Kabupaten", + "name": "Polewali Mandar", + "code": "04", + "full_code": "7604", + "provinsi_id": 31 + }, + { + "id": 493, + "type": "Kabupaten", + "name": "Ponorogo", + "code": "02", + "full_code": "3502", + "provinsi_id": 11 + }, + { + "id": 494, + "type": "Kota", + "name": "Pontianak", + "code": "71", + "full_code": "6171", + "provinsi_id": 12 + }, + { + "id": 495, + "type": "Kabupaten", + "name": "Poso", + "code": "02", + "full_code": "7202", + "provinsi_id": 33 + }, + { + "id": 496, + "type": "Kota", + "name": "Prabumulih", + "code": "74", + "full_code": "1674", + "provinsi_id": 37 + }, + { + "id": 497, + "type": "Kabupaten", + "name": "Pringsewu", + "code": "10", + "full_code": "1810", + "provinsi_id": 19 + }, + { + "id": 498, + "type": "Kabupaten", + "name": "Probolinggo", + "code": "13", + "full_code": "3513", + "provinsi_id": 11 + }, + { + "id": 499, + "type": "Kota", + "name": "Probolinggo", + "code": "74", + "full_code": "3574", + "provinsi_id": 11 + }, + { + "id": 500, + "type": "Kabupaten", + "name": "Pulang Pisau", + "code": "11", + "full_code": "6211", + "provinsi_id": 14 + }, + { + "id": 501, + "type": "Kabupaten", + "name": "Pulau Morotai", + "code": "07", + "full_code": "8207", + "provinsi_id": 21 + }, + { + "id": 502, + "type": "Kabupaten", + "name": "Pulau Taliabu", + "code": "08", + "full_code": "8208", + "provinsi_id": 21 + }, + { + "id": 503, + "type": "Kabupaten", + "name": "Puncak", + "code": "05", + "full_code": "9405", + "provinsi_id": 29 + }, + { + "id": 504, + "type": "Kabupaten", + "name": "Puncak Jaya", + "code": "02", + "full_code": "9402", + "provinsi_id": 29 + }, + { + "id": 505, + "type": "Kabupaten", + "name": "Purbalingga", + "code": "03", + "full_code": "3303", + "provinsi_id": 10 + }, + { + "id": 506, + "type": "Kabupaten", + "name": "Purwakarta", + "code": "14", + "full_code": "3214", + "provinsi_id": 9 + }, + { + "id": 507, + "type": "Kabupaten", + "name": "Purworejo", + "code": "06", + "full_code": "3306", + "provinsi_id": 10 + }, + { + "id": 508, + "type": "Kabupaten", + "name": "Raja Ampat", + "code": "05", + "full_code": "9205", + "provinsi_id": 26 + }, + { + "id": 509, + "type": "Kabupaten", + "name": "Rejang Lebong", + "code": "02", + "full_code": "1702", + "provinsi_id": 4 + }, + { + "id": 510, + "type": "Kabupaten", + "name": "Rembang", + "code": "17", + "full_code": "3317", + "provinsi_id": 10 + }, + { + "id": 511, + "type": "Kabupaten", + "name": "Rokan Hilir", + "code": "07", + "full_code": "1407", + "provinsi_id": 30 + }, + { + "id": 512, + "type": "Kabupaten", + "name": "Rokan Hulu", + "code": "06", + "full_code": "1406", + "provinsi_id": 30 + }, + { + "id": 513, + "type": "Kabupaten", + "name": "Rote Ndao", + "code": "14", + "full_code": "5314", + "provinsi_id": 23 + }, + { + "id": 514, + "type": "Kota", + "name": "Sabang", + "code": "72", + "full_code": "1172", + "provinsi_id": 1 + } +] \ No newline at end of file diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/seeds/province.json b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/seeds/province.json new file mode 100644 index 0000000000000000000000000000000000000000..c155c28ac8278bdde49211c31c0f56ebd2350255 --- /dev/null +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/seeds/province.json @@ -0,0 +1,192 @@ +[ + { + "id": 1, + "name": "Aceh (NAD)", + "code": "11" + }, + { + "id": 2, + "name": "Bali", + "code": "51" + }, + { + "id": 3, + "name": "Banten", + "code": "36" + }, + { + "id": 4, + "name": "Bengkulu", + "code": "17" + }, + { + "id": 5, + "name": "DI Yogyakarta", + "code": "34" + }, + { + "id": 6, + "name": "DKI Jakarta", + "code": "31" + }, + { + "id": 7, + "name": "Gorontalo", + "code": "75" + }, + { + "id": 8, + "name": "Jambi", + "code": "15" + }, + { + "id": 9, + "name": "Jawa Barat", + "code": "32" + }, + { + "id": 10, + "name": "Jawa Tengah", + "code": "33" + }, + { + "id": 11, + "name": "Jawa Timur", + "code": "35" + }, + { + "id": 12, + "name": "Kalimantan Barat", + "code": "61" + }, + { + "id": 13, + "name": "Kalimantan Selatan", + "code": "63" + }, + { + "id": 14, + "name": "Kalimantan Tengah", + "code": "62" + }, + { + "id": 15, + "name": "Kalimantan Timur", + "code": "64" + }, + { + "id": 16, + "name": "Kalimantan Utara", + "code": "65" + }, + { + "id": 17, + "name": "Kepulauan Bangka Belitung", + "code": "19" + }, + { + "id": 18, + "name": "Kepulauan Riau", + "code": "21" + }, + { + "id": 19, + "name": "Lampung", + "code": "18" + }, + { + "id": 20, + "name": "Maluku", + "code": "81" + }, + { + "id": 21, + "name": "Maluku Utara", + "code": "82" + }, + { + "id": 22, + "name": "Nusa Tenggara Barat (NTB)", + "code": "52" + }, + { + "id": 23, + "name": "Nusa Tenggara Timur (NTT)", + "code": "53" + }, + { + "id": 24, + "name": "Papua", + "code": "91" + }, + { + "id": 25, + "name": "Papua Barat", + "code": "92" + }, + { + "id": 26, + "name": "Papua Barat Daya", + "code": "92" + }, + { + "id": 27, + "name": "Papua Pegunungan", + "code": "95" + }, + { + "id": 28, + "name": "Papua Selatan", + "code": "93" + }, + { + "id": 29, + "name": "Papua Tengah", + "code": "94" + }, + { + "id": 30, + "name": "Riau", + "code": "14" + }, + { + "id": 31, + "name": "Sulawesi Barat", + "code": "76" + }, + { + "id": 32, + "name": "Sulawesi Selatan", + "code": "73" + }, + { + "id": 33, + "name": "Sulawesi Tengah", + "code": "72" + }, + { + "id": 34, + "name": "Sulawesi Tenggara", + "code": "74" + }, + { + "id": 35, + "name": "Sulawesi Utara", + "code": "71" + }, + { + "id": 36, + "name": "Sumatera Barat", + "code": "13" + }, + { + "id": 37, + "name": "Sumatera Selatan", + "code": "16" + }, + { + "id": 38, + "name": "Sumatera Utara", + "code": "12" + } +] \ No newline at end of file diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/Logger.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/Logger.go index a3d0718f321d11e5b83abd02c43e7cd849ce5cad..ce585609f26349805e924bf4769ec2e2cc2dc4d9 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/Logger.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/Logger.go @@ -10,9 +10,19 @@ import ( func LogError(errorLogged error) { fmt.Println("There is an error!") + + // Buat folder 'logs' kalau belum ada + if _, err := os.Stat(config.LOG_PATH); os.IsNotExist(err) { + err := os.Mkdir(config.LOG_PATH, 0755) + if err != nil { + log.Fatalf("Gagal buat folder logs: %v", err) + } + } + file, err := os.OpenFile(config.LOG_PATH+"/error_log.txt", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666) + if err != nil { - log.Fatal(err) + log.Fatalf("Gagal buka file log: %v", err) } log.SetOutput(file) diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/api_response.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/api_response.go index aae210ee39978d67c5412c665a041f45685f0c13..e80d01cbaaec9732ba25efb2106de3a3055dcfd6 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/api_response.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/api_response.go @@ -6,6 +6,7 @@ import ( "api.qobiltu.id/models" "api.qobiltu.id/services" + "github.com/gin-gonic/gin" ) diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/Logger.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/Logger.go index ce585609f26349805e924bf4769ec2e2cc2dc4d9..0aae4a5b1bab4c9ac15e661a9b9d364db927de09 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/Logger.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/Logger.go @@ -10,14 +10,7 @@ import ( func LogError(errorLogged error) { fmt.Println("There is an error!") - - // Buat folder 'logs' kalau belum ada - if _, err := os.Stat(config.LOG_PATH); os.IsNotExist(err) { - err := os.Mkdir(config.LOG_PATH, 0755) - if err != nil { - log.Fatalf("Gagal buat folder logs: %v", err) - } - } + log.Println("Error Log :", errorLogged) file, err := os.OpenFile(config.LOG_PATH+"/error_log.txt", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666) @@ -26,6 +19,4 @@ func LogError(errorLogged error) { } log.SetOutput(file) - - log.Println("Error Log :", errorLogged) } diff --git a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/Logger.go b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/Logger.go index 0aae4a5b1bab4c9ac15e661a9b9d364db927de09..0c869361b9fadf16ebb08a7c47a7ffa845ffbc6b 100644 --- a/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/Logger.go +++ b/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/space/utils/Logger.go @@ -1,7 +1,6 @@ package utils import ( - "fmt" "log" "os" @@ -9,9 +8,16 @@ import ( ) func LogError(errorLogged error) { - fmt.Println("There is an error!") log.Println("Error Log :", errorLogged) + _, err := os.Stat(config.LOG_PATH + "/error_log.txt") + if os.IsNotExist(err) { + _, err = os.Create(config.LOG_PATH + "/error_log.txt") + if err != nil { + log.Fatalf("Gagal buka file log: %v", err) + } + } + file, err := os.OpenFile(config.LOG_PATH+"/error_log.txt", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666) if err != nil {