diff --git a/.env.example b/.env.example new file mode 100644 index 0000000000000000000000000000000000000000..feb492ff198e4d926dde0702af85f2c2d477264b --- /dev/null +++ b/.env.example @@ -0,0 +1,14 @@ +DB_HOST = localhost +DB_USER = postgres +DB_PASSWORD = +DB_PORT = +DB_NAME = +SALT = +HOST_ADDRESS = localhost +HOST_PORT = 8080 +LOG_PATH = logs +EMAIL_VERIFICATION_DURATION = +SMTP_SENDER_EMAIL = +SMTP_SENDER_PASSWORD = +SMTP_HOST = +SMTP_PORT = diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000000000000000000000000000000000000..f553a86f16133c1c35b6b0a0068d20d5eeb032a1 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,49 @@ +name: Deploy to Huggingface +on: + push: + branches: + - master +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/quzuu-api-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/quzuu-api-dev + git pull origin main || echo "No changes to pull" + # Clean Space Directory - Delete all files except .git + - name: Clean Space Directory + run: | + cd space + find . -mindepth 1 -not -path "./.git*" -delete + # 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" \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..12e9c2828d5e6123511726539434148f473d501f --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.env +vendor/ +quzuu-be.exe +README.md +.qodo +.idea/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..3a59bde7236c3cc038be2579c4fade01a6299b67 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,30 @@ +# 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 . . + +# 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.zvcysrvqmkmgtcqryslt" >> .env && \ + echo "DB_PASSWORD=QuzuuAPIDEV2025" >> .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 "EMAIL_VERIFICATION_DURATION = 2" >> .env + +# Build aplikasi +RUN go build -o main . + +# Jalankan aplikasi +CMD ["./main"] diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..79da4b69760d1658f4dbc42604187316b368d857 --- /dev/null +++ b/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/README.md b/README.md index 5a200b81bae6191e689093595c979d0aaa82a7a4..3f4275ebec0e8c6273605f15b21c07d61cb0ada4 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,8 @@ --- title: Quzuu Api Dev emoji: 🐠 -colorFrom: purple -colorTo: pink +colorFrom: indigo +colorTo: gray sdk: docker pinned: false --- - -Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference diff --git a/config/config.go b/config/config.go new file mode 100644 index 0000000000000000000000000000000000000000..55487887878907689a66b9e5897895013b1b708f --- /dev/null +++ b/config/config.go @@ -0,0 +1,34 @@ +package config + +import ( + "os" + "strconv" + + "github.com/joho/godotenv" +) + +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") + 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")) + 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/config/database_connection_config.go b/config/database_connection_config.go new file mode 100644 index 0000000000000000000000000000000000000000..183bf3e70a73de6a495c98c7cc5e75971fee90bb --- /dev/null +++ b/config/database_connection_config.go @@ -0,0 +1,99 @@ +package config + +import ( + "fmt" + "godp.abdanhafidz.com/models" + "log" + "os" + + "gorm.io/driver/postgres" + "gorm.io/gorm" + "gorm.io/gorm/logger" + + "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 + db.Exec("CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";") + if err := db.AutoMigrate(&models.Account{}); err != nil { + log.Fatal(err) + } + if err := db.AutoMigrate(&models.AccountDetails{}); err != nil { + log.Fatal(err) + } + if err := db.AutoMigrate(&models.EmailVerification{}); err != nil { + log.Fatal(err) + } + if err := db.AutoMigrate(&models.ExternalAuth{}); err != nil { + log.Fatal(err) + } + if err := db.AutoMigrate(&models.FCM{}); err != nil { + log.Fatal(err) + } + if err := db.AutoMigrate(&models.ForgotPassword{}); err != nil { + log.Fatal(err) + } + if err := db.AutoMigrate(&models.Events{}); err != nil { + log.Fatal(err) + } + if err := db.AutoMigrate(&models.Announcement{}); err != nil { + log.Fatal(err) + } + if err := db.AutoMigrate(&models.ProblemSet{}); err != nil { + log.Fatal(err) + } + if err := db.AutoMigrate(&models.Questions{}); err != nil { + log.Fatal(err) + } + if err := db.AutoMigrate(&models.EventAssign{}); err != nil { + log.Fatal(err) + } + if err := db.AutoMigrate(&models.ProblemSetAssign{}); err != nil { + log.Fatal(err) + } + if err := db.AutoMigrate(&models.ExamProgress{}); err != nil { + log.Fatal(err) + } + if err := db.AutoMigrate(&models.ExamProgress_Result{}); err != nil { + log.Fatal(err) + } + if err := db.AutoMigrate(&models.Result{}); err != nil { + log.Fatal(err) + } + + fmt.Println("Migration completed successfully.") +} diff --git a/controller/auth/auth_change_password_controller.go b/controller/auth/auth_change_password_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..6692c31b3f0585afaa46bf343b743f0a0461e0dc --- /dev/null +++ b/controller/auth/auth_change_password_controller.go @@ -0,0 +1,21 @@ +package auth + +import ( + "github.com/gin-gonic/gin" + "godp.abdanhafidz.com/controller" + "godp.abdanhafidz.com/models" + "godp.abdanhafidz.com/services" +) + +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 = changePasswordController.AccountData.UserID + }) + changePasswordController.RequestJSON(c, func() { + authentication.Update(changePasswordController.Request.OldPassword, changePasswordController.Request.NewPassword) + }) +} diff --git a/controller/auth/auth_external_controller.go b/controller/auth/auth_external_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..6e21a972e7be49d0e34e29de52437902a21a894f --- /dev/null +++ b/controller/auth/auth_external_controller.go @@ -0,0 +1,20 @@ +package auth + +import ( + "github.com/gin-gonic/gin" + "godp.abdanhafidz.com/controller" + "godp.abdanhafidz.com/models" + "godp.abdanhafidz.com/services" +) + +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(true) + } + }) +} diff --git a/controller/auth/auth_forgot_password_controller.go b/controller/auth/auth_forgot_password_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..0e3c7942d8a9d7d98fdf3aeced07dc773f70e510 --- /dev/null +++ b/controller/auth/auth_forgot_password_controller.go @@ -0,0 +1,29 @@ +package auth + +import ( + "github.com/gin-gonic/gin" + "godp.abdanhafidz.com/controller" + "godp.abdanhafidz.com/models" + "godp.abdanhafidz.com/services" +) + +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/controller/auth/auth_login_controller.go b/controller/auth/auth_login_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..9ab5b87d3003083a24e0077b064ef197ff03ecc4 --- /dev/null +++ b/controller/auth/auth_login_controller.go @@ -0,0 +1,20 @@ +package auth + +import ( + "github.com/gin-gonic/gin" + "godp.abdanhafidz.com/controller" + "godp.abdanhafidz.com/models" + "godp.abdanhafidz.com/services" +) + +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/controller/auth/auth_register_controller.go b/controller/auth/auth_register_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..23ae59be7977980b96fb687f8a87d27a3c28ae47 --- /dev/null +++ b/controller/auth/auth_register_controller.go @@ -0,0 +1,22 @@ +package auth + +import ( + "github.com/gin-gonic/gin" + "godp.abdanhafidz.com/controller" + "godp.abdanhafidz.com/models" + "godp.abdanhafidz.com/services" +) + +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 + registerController.Service.Constructor.Username = registerController.Request.Username + registerController.Service.Constructor.Role = "USER" + register.Create() + }) +} diff --git a/controller/controller.go b/controller/controller.go new file mode 100644 index 0000000000000000000000000000000000000000..ce255c94a1d2fe6033b3fc0853b9d4a44409d76b --- /dev/null +++ b/controller/controller.go @@ -0,0 +1,71 @@ +package controller + +import ( + "github.com/gin-gonic/gin" + "godp.abdanhafidz.com/models" + "godp.abdanhafidz.com/repositories" + "godp.abdanhafidz.com/services" + "godp.abdanhafidz.com/utils" +) + +type ( + Controllers interface { + RequestJSON(c *gin.Context) + Response(c *gin.Context) + } + Controller[TRequest any, TConstructor any, TResult any] struct { + AccountData models.AccountData + Request TRequest + Service *services.Service[TConstructor, TResult] + } +) + +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 { + controller.AccountData = cParam.(models.AccountData) + } + errBinding := c.ShouldBindJSON(&controller.Request) + if errBinding != nil { + utils.ResponseFAIL(c, 400, models.Exception{ + BadRequest: true, + 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) { + switch { + case controller.Service.Error != nil: + utils.LogError(controller.Service.Error) + utils.ResponseFAIL(c, 500, models.Exception{ + InternalServerError: true, + Message: "Internal Server 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: + utils.ResponseFAIL(c, 404, controller.Service.Exception) + case controller.Service.Exception.Message != "": + utils.ResponseFAIL(c, 400, controller.Service.Exception) + default: + if controller.Service.MetaData != (repositories.PaginationMetadata{}) { + utils.ResponseOK(c, controller.Service.Result, controller.Service.MetaData) + } else { + utils.ResponseOK(c, controller.Service.Result, struct{}{}) + } + } +} diff --git a/controller/email/email_create_verification_controller.go b/controller/email/email_create_verification_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..ca6b6e99e2adfe2a5694911eb52a89daad968d21 --- /dev/null +++ b/controller/email/email_create_verification_controller.go @@ -0,0 +1,20 @@ +package controller + +import ( + "github.com/gin-gonic/gin" + "godp.abdanhafidz.com/controller" + "godp.abdanhafidz.com/models" + "godp.abdanhafidz.com/services" +) + +func CreateVerification(c *gin.Context) { + emailVerification := services.EmailVerificationService{} + emailVerificationController := controller.Controller[models.CreateEmailVerificationRequest, models.EmailVerification, models.EmailVerification]{ + Service: &emailVerification.Service, + } + emailVerificationController.RequestJSON(c, func() { + emailVerification.Create(emailVerificationController.Request.Email) + emailVerificationController.Response(c) + }) + +} diff --git a/controller/email/email_validate_controller.go b/controller/email/email_validate_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..4a78bcd1a7185eb6a9719278dd457792934e1fe9 --- /dev/null +++ b/controller/email/email_validate_controller.go @@ -0,0 +1,21 @@ +package controller + +import ( + "github.com/gin-gonic/gin" + "godp.abdanhafidz.com/controller" + "godp.abdanhafidz.com/models" + "godp.abdanhafidz.com/services" +) + +func Verify(c *gin.Context) { + emailVerification := services.EmailVerificationService{} + emailVerificationController := controller.Controller[models.ValidateVerifyEmailRequest, models.EmailVerification, models.EmailVerification]{ + Service: &emailVerification.Service, + } + emailVerificationController.RequestJSON(c, func() { + + emailVerificationController.Service.Constructor.Token = emailVerificationController.Request.Token + emailVerification.Validate(emailVerificationController.Request.Email) + }) + +} diff --git a/controller/event/event_detail_controller.go b/controller/event/event_detail_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..073af278db7d38f76c93cd3ec247b1bbf7205284 --- /dev/null +++ b/controller/event/event_detail_controller.go @@ -0,0 +1,21 @@ +package event + +import ( + "github.com/gin-gonic/gin" + "godp.abdanhafidz.com/controller" + "godp.abdanhafidz.com/models" + "godp.abdanhafidz.com/services" +) + +func EventDetail(c *gin.Context) { + eventDetail := services.EventDetailService{} + eventDetailController := controller.Controller[any, models.Events, models.EventDetailResponse]{ + Service: &eventDetail.Service, + } + + eventDetailController.HeaderParse(c, func() { + eventDetailController.Service.Constructor.Slug = c.Param("event_slug") + eventDetail.Retrieve(eventDetailController.AccountData.UserID) + eventDetailController.Response(c) + }) +} diff --git a/controller/event/event_join_controller.go b/controller/event/event_join_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..7a5a1e83f6a5a0b649289863a1f7100578806dfe --- /dev/null +++ b/controller/event/event_join_controller.go @@ -0,0 +1,22 @@ +package event + +import ( + "github.com/gin-gonic/gin" + "godp.abdanhafidz.com/controller" + "godp.abdanhafidz.com/models" + "godp.abdanhafidz.com/services" +) + +func Register(c *gin.Context) { + eventAssign := services.JoinEventService{} + eventAssignController := controller.Controller[models.JoinEventRequest, models.JoinEventRequest, models.EventDetailResponse]{ + Service: &eventAssign.Service, + } + + eventAssignController.RequestJSON(c, func() { + eventAssignController.Service.Constructor.EventId = eventAssignController.Request.EventId + eventAssignController.Service.Constructor.EventCode = eventAssignController.Request.EventCode + idUser := eventAssignController.AccountData.UserID + eventAssign.Create(idUser) + }) +} diff --git a/controller/event/event_list_controller.go b/controller/event/event_list_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..6589063c3665215a0fb52115898a7a76baa60269 --- /dev/null +++ b/controller/event/event_list_controller.go @@ -0,0 +1,54 @@ +package event + +import ( + "strconv" + + "github.com/gin-gonic/gin" + "godp.abdanhafidz.com/controller" + "godp.abdanhafidz.com/models" + "godp.abdanhafidz.com/repositories" + "godp.abdanhafidz.com/services" + "godp.abdanhafidz.com/utils" +) + +func EventList(c *gin.Context) { + limit, err := strconv.Atoi(c.DefaultQuery("limit", "10")) + if err != nil { + service := services.Service[any, any]{ + Exception: models.Exception{ + Message: "Invalid limit parameter", + }, + } + utils.SendResponse(c, service) + return + } + + offset, err := strconv.Atoi(c.DefaultQuery("offset", "0")) + if err != nil { + service := services.Service[any, any]{ + Exception: models.Exception{ + Message: "Invalid offset parameter", + }, + } + utils.SendResponse(c, service) + return + } + filter := c.DefaultQuery("filter", "") + filterBy := c.DefaultQuery("filter_by", "") + + pagination := repositories.PaginationConstructor{ + Limit: limit, + Offset: offset, + Filter: filter, + FilterBy: filterBy, + } + + eventsService := services.GetAllEventService{} + getAllEventController := controller.Controller[any, models.Events, []models.Events]{ + Service: &eventsService.Service, + } + + eventsService.Retrieve(pagination) + + getAllEventController.Response(c) +} diff --git a/controller/home_controller.go b/controller/home_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..06cfc3d7fac0385d6aef847a186de2eae7dbb4bb --- /dev/null +++ b/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/controller/options/option_category_controller.go b/controller/options/option_category_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..cf959ee6aa30d00d31a4efcc62c13548dea7d2d3 --- /dev/null +++ b/controller/options/option_category_controller.go @@ -0,0 +1,19 @@ +package options + +import ( + "github.com/gin-gonic/gin" + "godp.abdanhafidz.com/controller" + "godp.abdanhafidz.com/models" + "godp.abdanhafidz.com/services" +) + +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/controller/options/option_value_controller.go b/controller/options/option_value_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..48c62fb5a97372138df082b2758ae5e7e5eabea5 --- /dev/null +++ b/controller/options/option_value_controller.go @@ -0,0 +1,19 @@ +package options + +import ( + "github.com/gin-gonic/gin" + "godp.abdanhafidz.com/controller" + "godp.abdanhafidz.com/models" + "godp.abdanhafidz.com/services" +) + +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/controller/region/city/city_list_controller.go b/controller/region/city/city_list_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..d6e2425e46b66aef4234ac68f8b14e9f8f9d0bfa --- /dev/null +++ b/controller/region/city/city_list_controller.go @@ -0,0 +1,21 @@ +package city + +import ( + "strconv" + + "github.com/gin-gonic/gin" + "godp.abdanhafidz.com/controller" + "godp.abdanhafidz.com/models" + "godp.abdanhafidz.com/services" +) + +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/controller/region/city/city_seeds_controller.go b/controller/region/city/city_seeds_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..4e3d23d18aaf5d00ef432a480981d0cbfa5281c3 --- /dev/null +++ b/controller/region/city/city_seeds_controller.go @@ -0,0 +1,17 @@ +package city + +import ( + "github.com/gin-gonic/gin" + "godp.abdanhafidz.com/controller" + "godp.abdanhafidz.com/models" + "godp.abdanhafidz.com/services" +) + +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/controller/region/province/province_list_controller.go b/controller/region/province/province_list_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..0b2361e675003f8a62d0dc9818c509a3b85009b3 --- /dev/null +++ b/controller/region/province/province_list_controller.go @@ -0,0 +1,17 @@ +package province + +import ( + "github.com/gin-gonic/gin" + "godp.abdanhafidz.com/controller" + "godp.abdanhafidz.com/models" + "godp.abdanhafidz.com/services" +) + +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/controller/region/province/province_seeds_controller.go b/controller/region/province/province_seeds_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..662741647766ae0323f25b58300ae3d4fd4a3540 --- /dev/null +++ b/controller/region/province/province_seeds_controller.go @@ -0,0 +1,17 @@ +package province + +import ( + "github.com/gin-gonic/gin" + "godp.abdanhafidz.com/controller" + "godp.abdanhafidz.com/models" + "godp.abdanhafidz.com/services" +) + +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/controller/user/user_profile_controller.go b/controller/user/user_profile_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..723a9b3a7f7e1ac4416524032fff5e05df642603 --- /dev/null +++ b/controller/user/user_profile_controller.go @@ -0,0 +1,21 @@ +package user + +import ( + "github.com/gin-gonic/gin" + "godp.abdanhafidz.com/controller" + "godp.abdanhafidz.com/models" + "godp.abdanhafidz.com/services" +) + +func Profile(c *gin.Context) { + userProfile := services.UserProfileService{} + userProfileController := controller.Controller[any, models.AccountDetails, models.UserProfileResponse]{ + Service: &userProfile.Service, + } + userProfileController.HeaderParse(c, func() { + userProfileController.Service.Constructor.AccountId = userProfileController.AccountData.UserID + userProfile.Retrieve() + userProfileController.Response(c) + }, + ) +} diff --git a/controller/user/user_update_profile_controller.go b/controller/user/user_update_profile_controller.go new file mode 100644 index 0000000000000000000000000000000000000000..5763c061566dd9508ec8697ff6e81555f4f43b12 --- /dev/null +++ b/controller/user/user_update_profile_controller.go @@ -0,0 +1,25 @@ +package user + +import ( + "github.com/gin-gonic/gin" + "godp.abdanhafidz.com/controller" + "godp.abdanhafidz.com/models" + "godp.abdanhafidz.com/services" +) + +func UpdateProfile(c *gin.Context) { + userProfile := services.UserProfileService{} + userUpdateProfileController := controller.Controller[models.AccountDetails, models.AccountDetails, models.UserProfileResponse]{ + Service: &userProfile.Service, + } + + userUpdateProfileController.RequestJSON(c, func() { + userUpdateProfileController.Service.Constructor = userUpdateProfileController.Request + userUpdateProfileController.HeaderParse(c, func() { + userUpdateProfileController.Service.Constructor.AccountId = userUpdateProfileController.AccountData.UserID + + }) + userProfile.Update() + }, + ) +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000000000000000000000000000000000000..7f8e8b6f7bf5aac31c0344e15b4c5b8e8e45fab0 --- /dev/null +++ b/go.mod @@ -0,0 +1,73 @@ +module godp.abdanhafidz.com + +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 + github.com/satori/go.uuid v1.2.0 + golang.org/x/crypto v0.37.0 + gorm.io/driver/postgres v1.5.11 + gorm.io/gorm v1.25.12 +) + +require ( + cloud.google.com/go/auth v0.16.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/google/uuid v1.6.0 // 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 + github.com/jackc/puddle/v2 v2.2.2 // indirect + github.com/jinzhu/gorm v1.9.16 // 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.10 // indirect + github.com/kr/text v0.2.0 // indirect + github.com/leodido/go-urn v1.4.0 // indirect + github.com/lib/pq v1.1.1 // 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 + go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.60.0 // indirect + go.opentelemetry.io/otel v1.35.0 // indirect + go.opentelemetry.io/otel/metric v1.35.0 // indirect + go.opentelemetry.io/otel/trace v1.35.0 // indirect + golang.org/x/arch v0.15.0 // indirect + golang.org/x/net v0.39.0 // indirect + golang.org/x/oauth2 v0.29.0 // indirect + golang.org/x/sync v0.13.0 // indirect + golang.org/x/sys v0.32.0 // indirect + golang.org/x/text v0.24.0 // indirect + google.golang.org/api v0.229.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20250414145226-207652e42e2e // indirect + google.golang.org/grpc v1.71.1 // indirect + google.golang.org/protobuf v1.36.6 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000000000000000000000000000000000000..520c54e5fdf18e306881fb86a9168a9d1c013da7 --- /dev/null +++ b/go.sum @@ -0,0 +1,200 @@ +cloud.google.com/go/auth v0.16.0 h1:Pd8P1s9WkcrBE2n/PhAwKsdrR35V3Sg2II9B+ndM3CU= +cloud.google.com/go/auth v0.16.0/go.mod h1:1howDHJ5IETh/LwYs3ZxvlkXF48aSqqJUM+5o02dNOI= +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/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc= +github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y= +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/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU= +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/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a2zkGnVExMxdzMo3M0Hi/3sEU+cWnZpSni0O6/Yb/P0= +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= +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.25.0 h1:5Dh7cjvzR7BRZadnsVOzPhWsrwUr0nmsZJxEAnFLNO8= +github.com/go-playground/validator/v10 v10.25.0/go.mod h1:GGzBIJMuE98Ic/kJsBXbz1x/7cByt++cQ+YOuDM5wus= +github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= +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/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0= +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/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= +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= +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= +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/gorm v1.9.16 h1:+IyIjPEABKRpsu/F8OvDPy9fyQlgsg2luMV2ZIH5i5o= +github.com/jinzhu/gorm v1.9.16/go.mod h1:G3LB3wezTOWM2ITLzPxEXgSkOXAntiLHS7UdBefADcs= +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.0.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= +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.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.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= +github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= +github.com/lib/pq v1.1.1 h1:sJZmqHoEaY7f+NPP8pgLB/WxulyR3fewgCM2qaSlBb4= +github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= +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/mattn/go-sqlite3 v1.14.0/go.mod h1:JIl7NbARA7phWnGvh0LKTyg7S9BA+6gx71ShQilpsus= +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.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= +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= +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.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.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.60.0 h1:sbiXRNDSWJOTobXh5HyQKjq6wUC5tNybqjIqDpAY4CU= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.60.0/go.mod h1:69uWxva0WgAA/4bu2Yy70SLDBwZXuQ6PbBpbsa5iZrQ= +go.opentelemetry.io/otel v1.35.0 h1:xKWKPxrxB6OtMCbmMY021CqC45J+3Onta9MqjhnusiQ= +go.opentelemetry.io/otel v1.35.0/go.mod h1:UEqy8Zp11hpkUrL73gSlELM0DupHoiq72dR+Zqel/+Y= +go.opentelemetry.io/otel/metric v1.35.0 h1:0znxYu2SNyuMSQT4Y9WDWej0VpcsxkuklLa4/siN90M= +go.opentelemetry.io/otel/metric v1.35.0/go.mod h1:nKVFgxBZ2fReX6IlyW28MgZojkoAkJGaE8CpgeAU3oE= +go.opentelemetry.io/otel/trace v1.35.0 h1:dPpEfJu1sDIqruz7BHFG3c7528f6ddfSWfFDVt/xgMs= +go.opentelemetry.io/otel/trace v1.35.0/go.mod h1:WUk7DtFp1Aw2MkvqGdwiXYDZZNvA/1J8o6xRXLrIkyc= +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.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191205180655-e7c4368fe9dd/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34= +golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc= +golang.org/x/crypto v0.37.0 h1:kJNSjF/Xp7kU0iB2Z+9viTPMW4EqqsrywMXLJOOsXSE= +golang.org/x/crypto v0.37.0/go.mod h1:vg+k43peMZ0pUMhYmVAWysMK35e6ioLh3wB8ZCAfbVc= +golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +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/net v0.39.0 h1:ZCu7HMWDxpXpaiKdhzIfaltL9Lp31x/3fCP11bc6/fY= +golang.org/x/net v0.39.0/go.mod h1:X7NRbYVEA+ewNkCNyJ513WmMdQ3BineSwVtN2zD/d+E= +golang.org/x/oauth2 v0.29.0 h1:WdYw2tdTK1S8olAzWHdgeqfy+Mtm9XNhv/xJsY65d98= +golang.org/x/oauth2 v0.29.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/sync v0.13.0 h1:AauUjRAJ9OSnvULf/ARrrVywoJDy0YS2AwQ98I37610= +golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik= +golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20= +golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY= +golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4= +golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0= +golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU= +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.229.0 h1:p98ymMtqeJ5i3lIBMj5MpR9kzIIgzpHHh8vQ+vgAzx8= +google.golang.org/api v0.229.0/go.mod h1:wyDfmq5g1wYJWn29O22FDWN48P7Xcz0xz+LBpptYvB0= +google.golang.org/genproto/googleapis/rpc v0.0.0-20250414145226-207652e42e2e h1:ztQaXfzEXTmCBvbtWYRhJxW+0iJcz2qXfd38/e9l7bA= +google.golang.org/genproto/googleapis/rpc v0.0.0-20250414145226-207652e42e2e/go.mod h1:qQ0YXyHHx3XkvlzUtpXDkS29lDSafHMZBAZDc03LQ3A= +google.golang.org/grpc v1.71.1 h1:ffsFWr7ygTUscGPI0KKK6TLrGz0476KUvvsbqWK0rPI= +google.golang.org/grpc v1.71.1/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= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gorm.io/driver/postgres v1.5.11 h1:ubBVAfbKEUld/twyKZ0IYn9rSQh448EdelLYk9Mv314= +gorm.io/driver/postgres v1.5.11/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI= +gorm.io/gorm v1.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= diff --git a/logs/error_log.txt b/logs/error_log.txt new file mode 100644 index 0000000000000000000000000000000000000000..8b137891791fe96927ad78e64b0aad7bded08bdc --- /dev/null +++ b/logs/error_log.txt @@ -0,0 +1 @@ + diff --git a/logs/security_log.txt b/logs/security_log.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/main.go b/main.go new file mode 100644 index 0000000000000000000000000000000000000000..558128c832dd8b2af9fb021f025a3475948797f6 --- /dev/null +++ b/main.go @@ -0,0 +1,14 @@ +package main + +import ( + "fmt" + + "godp.abdanhafidz.com/config" + "godp.abdanhafidz.com/router" +) + +func main() { + fmt.Println("Server started on ", config.TCP_ADDRESS, ", port :", config.HOST_PORT) + router.StartService() + +} diff --git a/middleware/authentication_middleware.go b/middleware/authentication_middleware.go new file mode 100644 index 0000000000000000000000000000000000000000..4e37fe22b48c27071b88b699ea5fd20cce3a8132 --- /dev/null +++ b/middleware/authentication_middleware.go @@ -0,0 +1,38 @@ +// auth/auth.go + +package middleware + +import ( + "github.com/gin-gonic/gin" + "github.com/google/uuid" + "godp.abdanhafidz.com/models" + "godp.abdanhafidz.com/services" + "godp.abdanhafidz.com/utils" +) + +func AuthUser(c *gin.Context) { + var currAccData models.AccountData + if c.Request.Header["Authorization"] != nil { + token := c.Request.Header["Authorization"] + + currAccData.UserID, currAccData.VerifyStatus, currAccData.ErrVerif = services.VerifyToken(token[0]) + + if currAccData.VerifyStatus == "invalid-token" || currAccData.VerifyStatus == "expired" { + currAccData.UserID = uuid.UUID{} + 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 = uuid.UUID{} + currAccData.VerifyStatus = "no-token" + currAccData.ErrVerif = nil + utils.ResponseFAIL(c, 401, models.Exception{Unauthorized: true, Message: "You have to login first!"}) + c.Abort() + return + } + +} diff --git a/middleware/middleware.go b/middleware/middleware.go new file mode 100644 index 0000000000000000000000000000000000000000..cce0f4f3e125d37ff4feb157c980c9a9f14f4673 --- /dev/null +++ b/middleware/middleware.go @@ -0,0 +1,30 @@ +package middleware + +import ( + "math" + "time" + + "gorm.io/gorm" +) + +func RecordCheck(rows *gorm.DB) (string, error) { + count := rows.RowsAffected + err := rows.Error + + 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/middleware/response_middleware.go b/middleware/response_middleware.go new file mode 100644 index 0000000000000000000000000000000000000000..d52391cd3607e6ec2697e6a5813b348d49ff5ee2 --- /dev/null +++ b/middleware/response_middleware.go @@ -0,0 +1,45 @@ +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}) + 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/models/authentication_payload_model.go b/models/authentication_payload_model.go new file mode 100644 index 0000000000000000000000000000000000000000..2dc5d6e8662d9192b0482e0c413a0158f33e8f47 --- /dev/null +++ b/models/authentication_payload_model.go @@ -0,0 +1,18 @@ +package models + +import ( + "github.com/golang-jwt/jwt/v5" + "github.com/google/uuid" +) + +type AccountData struct { + UserID uuid.UUID + VerifyStatus string + Role string + ErrVerif error +} +type CustomClaims struct { + jwt.RegisteredClaims + UserID uuid.UUID `json:"id"` + Role string `json:"role"` +} diff --git a/models/database_orm_model.go b/models/database_orm_model.go new file mode 100644 index 0000000000000000000000000000000000000000..3434e575470bb9a64f88491763653dfec2ffc0fd --- /dev/null +++ b/models/database_orm_model.go @@ -0,0 +1,264 @@ +package models + +import ( + "time" + + "github.com/google/uuid" + "github.com/jinzhu/gorm/dialects/postgres" +) + +type Account struct { + Id uuid.UUID `gorm:"type:uuid;primary_key;default:uuid_generate_v4()" json:"id"` + Username string `gorm:"uniqueIndex" json:"username"` + Email string `gorm:"uniqueIndex" json:"email"` + Role string `json:"role"` + 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" gorm:"default:null"` +} + +type AccountDetails struct { + Id uuid.UUID `gorm:"type:uuid;primary_key;default:uuid_generate_v4()" json:"id"` + AccountId uuid.UUID `json:"account_id"` + FullName *string `json:"full_name"` + SchoolName *string `json:"school_name"` + Province *string `json:"province"` + City *string `json:"city"` + Avatar *string `json:"avatar"` + PhoneNumber *string `json:"phone_number"` + Account *Account `gorm:"foreignKey:AccountId"` +} + +type EmailVerification struct { + Id uuid.UUID `gorm:"type:uuid;primary_key;default:uuid_generate_v4()" json:"id"` + Token uint `json:"token"` + AccountId uuid.UUID `json:"account_id"` + IsExpired bool `json:"is_expired"` + CreatedAt time.Time `json:"created_at"` + ExpiredAt time.Time `json:"expired_at"` + + Account *Account `gorm:"foreignKey:AccountId"` +} + +type ExternalAuth struct { + Id uuid.UUID `gorm:"type:uuid;primary_key;default:uuid_generate_v4()" json:"id"` + OauthID string `json:"oauth_id"` + AccountId uuid.UUID `json:"account_id"` + OauthProvider string `json:"oauth_provider"` +} + +type FCM struct { + Id uuid.UUID `gorm:"type:uuid;primary_key;default:uuid_generate_v4()" json:"id"` + AccountId uuid.UUID `json:"account_id"` + FCMToken string `json:"fcm_token"` +} + +type ForgotPassword struct { + Id uuid.UUID `gorm:"type:uuid;primary_key;default:uuid_generate_v4()" json:"id"` + Token uint `json:"token"` + AccountId uuid.UUID `json:"account_id"` + IsExpired bool `json:"is_expired"` + CreatedAt time.Time `json:"created_at"` + ExpiredAt time.Time `json:"expired_at"` +} + +type Events struct { + Id uuid.UUID `gorm:"type:uuid;primary_key;default:uuid_generate_v4()" json:"id_event"` + Title string `json:"title"` + Slug string `json:"slug"` + StartEvent time.Time `json:"start_event"` + EndEvent time.Time `json:"end_event"` + EventCode string `json:"event_code"` + IsPublic bool `json:"is_public"` +} + +type Announcement struct { + Id uuid.UUID `gorm:"type:uuid;primary_key;default:uuid_generate_v4()" json:"id_announcement"` + Title string `json:"title"` + CreatedAt time.Time `json:"created_at"` + Message string `json:"message"` + Publisher string `json:"publisher"` + EventId uuid.UUID `json:"id_event"` +} + +type ProblemSet struct { + Id uuid.UUID `gorm:"type:uuid;primary_key;default:uuid_generate_v4()" json:"id_problem_set"` + Title string `json:"title"` + Duration time.Duration `json:"duration"` + Randomize uint `json:"randomize"` + MC_Count uint `json:"mc_count"` + SA_Count uint `json:"sa_count"` + Essay_Count uint `json:"essay_count"` +} + +type Questions struct { + Id uuid.UUID `gorm:"type:uuid;primary_key;default:uuid_generate_v4()" json:"id_question"` + Type string `json:"type"` //MultChoices, ShortAns, Essay, IntPuzzle, IntType + Question string `json:"question"` + Options []string `gorm:"type:text[]" json:"options"` + AnsKey []string `gorm:"type:text[]" json:"ans_key"` + CorrMark float64 `json:"corr_mark"` + IncorrMark float64 `json:"incorr_mark"` + NullMark float64 `json:"null_mark"` + ProblemSetId uuid.UUID `json:"id_problem_set"` + + ProblemSet *ProblemSet `gorm:"foreignKey:ProblemSetId"` +} + +type EventAssign struct { + Id uuid.UUID `gorm:"type:uuid;primary_key;default:uuid_generate_v4()" json:"id_assign"` + AccountId uuid.UUID `json:"id_account"` + EventId uuid.UUID `json:"id_event"` + AssignedAt time.Time `json:"assigned_at"` + + Account *Account `gorm:"foreignKey:AccountId"` + Event *Events `gorm:"foreignKey:EventId"` +} + +type ProblemSetAssign struct { + Id uuid.UUID `gorm:"type:uuid;primary_key;default:uuid_generate_v4()" json:"id_problem_set_assign"` + EventId uuid.UUID `json:"id_event"` + ProblemSetId uuid.UUID `json:"id_problem_set"` + + Event *Events `gorm:"foreignKey:EventId"` + ProblemSet *ProblemSet `gorm:"foreignKey:ProblemSetId"` +} + +type ExamProgress struct { + Id uuid.UUID `gorm:"type:uuid;primary_key;default:uuid_generate_v4()" json:"id_progress"` + AccountId uuid.UUID `json:"id_account"` + EventId uuid.UUID `json:"id_event"` + ProblemSetId uuid.UUID `json:"id_problem_set"` + CreatedAt time.Time `json:"created_at"` + DueAt time.Time `json:"due_at"` + QuestionsOrder []string `gorm:"type:text[]" json:"questions_order"` + Answers any `gorm:"type:jsonb" json:"answers"` + + Account *Account `gorm:"foreignKey:AccountId"` + Event *Events `gorm:"foreignKey:EventId"` + ProblemSet *ProblemSet `gorm:"foreignKey:ProblemSetId"` +} + +type ExamProgress_Result struct { + Id uuid.UUID `gorm:"type:uuid;primary_key;default:uuid_generate_v4()" json:"id_progress"` + AccountId uuid.UUID `json:"id_account"` + EventId uuid.UUID `json:"id_event"` + ProblemSetId uuid.UUID `json:"id_problem_set"` + CreatedAt time.Time `json:"created_at"` + DueAt time.Time `json:"due_at"` + QuestionsOrder []string `gorm:"type:text[]" json:"questions_order"` + Answers postgres.Jsonb `gorm:"type:jsonb" json:"answers"` + + Account *Account `gorm:"foreignKey:AccountId"` + Event *Events `gorm:"foreignKey:EventId"` + ProblemSet *ProblemSet `gorm:"foreignKey:ProblemSetId"` +} + +type Result struct { + Id uuid.UUID `gorm:"type:uuid;primary_key;default:uuid_generate_v4()" json:"id_result"` + AccountId uuid.UUID `json:"id_account"` + EventId uuid.UUID `json:"id_event"` + ProblemSetId uuid.UUID `json:"id_problem_set"` + ProgressId uuid.UUID `json:"id_progress"` + FinishTime time.Time `json:"finish_time"` + Correct uint `json:"correct"` + Incorrect uint `json:"incorrect"` + Empty uint `json:"empty"` + OnCorrection uint `json:"on_correction"` + ManualScoring float64 `json:"manual_scoring"` + MCScore float64 `json:"mc_score"` + ManualScore float64 `json:"manual_score"` + FinalScore float64 `json:"final_score"` + + Account *Account `gorm:"foreignKey:AccountId"` + Event *Events `gorm:"foreignKey:EventId"` + ProblemSet *ProblemSet `gorm:"foreignKey:ProblemSetId"` + ExamProgress *ExamProgress `gorm:"foreignKey:ProgressId"` +} + +type Academy struct { + Id uuid.UUID `gorm:"primaryKey" json:"id"` + Title string `json:"title"` + Slug string `json:"slug"` + Description string `json:"description"` +} + +type AcademyMaterial struct { + ID uuid.UUID `gorm:"primaryKey" json:"id"` + AcademyId uint `json:"academy_id"` + Title string `json:"title"` + Slug string `json:"slug"` + Description string `json:"description"` +} + +type AcademyContent struct { + Id uuid.UUID `gorm:"primaryKey" json:"id"` + 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"` + 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 uuid.UUID `gorm:"primaryKey" json:"id"` + AccountId uint `json:"account_id"` + AcademyMaterialId uint `json:"academy_material_id"` + Progress uint `json:"progress"` +} + +type AcademyContentProgress struct { + Id uuid.UUID `gorm:"primaryKey" json:"id"` + AccountId uuid.UUID `json:"account_id"` + AcademyId uuid.UUID `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" } +func (EmailVerification) TableName() string { return "email_verification" } +func (ExternalAuth) TableName() string { return "external_auth" } +func (FCM) TableName() string { return "fcm" } +func (ForgotPassword) TableName() string { return "forgot_password" } +func (Events) TableName() string { return "events" } +func (Announcement) TableName() string { return "announcement" } +func (ProblemSet) TableName() string { return "problem_sets" } +func (Questions) TableName() string { return "questions" } +func (EventAssign) TableName() string { return "event_assign" } +func (ProblemSetAssign) TableName() string { return "problem_sets_assign" } +func (Result) TableName() string { return "result" } +func (ExamProgress) TableName() string { return "exam_progress" } +func (ExamProgress_Result) TableName() string { return "exam_progress_result" } +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" } +func (RegionProvince) TableName() string { return "region_provinces" } +func (RegionCity) TableName() string { return "region_cities" } diff --git a/models/exception_model.go b/models/exception_model.go new file mode 100644 index 0000000000000000000000000000000000000000..f2c026a993f950652158318977783e8563e595fb --- /dev/null +++ b/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/models/model.go b/models/model.go new file mode 100644 index 0000000000000000000000000000000000000000..9ce401186cb92d50737155815c1f511164b86407 --- /dev/null +++ b/models/model.go @@ -0,0 +1 @@ +package models diff --git a/models/request_model.go b/models/request_model.go new file mode 100644 index 0000000000000000000000000000000000000000..df6e38acc5b67366c59dfc23076937e0f155765d --- /dev/null +++ b/models/request_model.go @@ -0,0 +1,57 @@ +package models + +import "github.com/google/uuid" + +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"` + Username string `json:"username" binding:"required"` + Password string `json:"password" binding:"required"` +} + +type CreateEmailVerificationRequest struct { + Email string `json:"email" binding:"required,email"` +} + +type ChangePasswordRequest struct { + OldPassword string `json:"old_password" binding:"required" ` + NewPassword string `json:"new_password" binding:"required" ` +} + +type EventDetailRequest struct { + IdUser uuid.UUID `json:"id_user"` + EventId uuid.UUID `json:"id_event"` +} + +type JoinEventRequest struct { + EventId uuid.UUID `json:"id_event"` + EventCode string `json:"event_code"` +} + +type ValidateVerifyEmailRequest struct { + Email string `json:"email" binding:"required,email"` + Token uint `json:"token" 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"` +} + +type ForgotPasswordRequest struct { + Email string `json:"email" binding:"required,email"` +} +type ValidateForgotPasswordRequest struct { + Token uint `json:"token" binding:"required"` + NewPassword string `json:"new_password"` +} diff --git a/models/response_model.go b/models/response_model.go new file mode 100644 index 0000000000000000000000000000000000000000..5d54d4ccb3822fb35d4441ff462a16e58e4d6f16 --- /dev/null +++ b/models/response_model.go @@ -0,0 +1,50 @@ +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"` +} + +type EventDetailResponse struct { + Data *Events + RegisterStatus int `json:"register_status"` +} + +type Options struct { + OptionCategory OptionCategory `json:"option_category"` + OptionValues []OptionValues `json:"option_values"` +} +type OptionsResponse struct { + Options []Options `json:"options"` +} + +type UserProfileResponse struct { + Account Account `json:"account"` + Details AccountDetails `json:"details"` +} + +type AcademyMaterialResponse struct { + Materials AcademyMaterial + Contents []AcademyContent +} +type AcademyResponse struct { + Academy Academy `json:"academy"` + Materials []AcademyMaterialResponse `json:"academy_materials"` +} + +type AllAcademyResponse struct { + Academies []AcademyResponse `json:"academy_dasar"` +} diff --git a/repositories/academy_repository.go b/repositories/academy_repository.go new file mode 100644 index 0000000000000000000000000000000000000000..4b2231f629d809b1d2e64ad32ec823c4eca2c99d --- /dev/null +++ b/repositories/academy_repository.go @@ -0,0 +1,73 @@ +package repositories + +import "godp.abdanhafidz.com/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 GetAcademyDataBySlug(slug string) Repository[models.Academy, models.Academy] { + repo := Construct[models.Academy, models.Academy]( + models.Academy{Slug: slug}, + ) + 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 +} + +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/repositories/account_repository.go b/repositories/account_repository.go new file mode 100644 index 0000000000000000000000000000000000000000..c2abeffe92115678acde138bf590e7a0084fa1b0 --- /dev/null +++ b/repositories/account_repository.go @@ -0,0 +1,88 @@ +package repositories + +import ( + "github.com/google/uuid" + "godp.abdanhafidz.com/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 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 uuid.UUID) Repository[models.Account, models.Account] { + repo := Construct[models.Account, models.Account]( + models.Account{Id: AccountId}, + ) + repo.Transactions( + WhereGivenConstructor[models.Account, models.Account], + Find[models.Account, models.Account], + ) + return *repo +} + +func UpdateAccount(account models.Account) Repository[models.Account, models.Account] { + repo := Construct[models.Account, models.Account]( + account, + ) + repo.Transaction.Save(&repo.Constructor) + repo.Result = repo.Constructor + return *repo +} + +func GetDetailAccountById(AccountId uuid.UUID) Repository[models.AccountDetails, models.AccountDetails] { + repo := Construct[models.AccountDetails, models.AccountDetails]( + models.AccountDetails{AccountId: 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, + ) + Create(repo) + return *repo +} + +func CreateAccountDetails(accountDetails models.AccountDetails) Repository[models.AccountDetails, models.AccountDetails] { + repo := Construct[models.AccountDetails, models.AccountDetails]( + accountDetails, + ) + Create(repo) + return *repo +} + +func UpdateAccountDetails(accountDetails models.AccountDetails) Repository[models.AccountDetails, models.AccountDetails] { + repo := Construct[models.AccountDetails, models.AccountDetails]( + models.AccountDetails{AccountId: accountDetails.AccountId}, + ) + 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/repositories/email_verification_repository.go b/repositories/email_verification_repository.go new file mode 100644 index 0000000000000000000000000000000000000000..ec2fea432686017791203812a04b3cb9131c0433 --- /dev/null +++ b/repositories/email_verification_repository.go @@ -0,0 +1,63 @@ +package repositories + +import ( + "time" + + "github.com/google/uuid" + "godp.abdanhafidz.com/models" +) + +func CreateEmailVerification(uuid uuid.UUID, AccountId uuid.UUID, 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, + Id: uuid, + }, + ) + Create(repo) + return *repo +} + +func GetEmailVerification(AccountId uuid.UUID, token uint) Repository[models.EmailVerification, models.EmailVerification] { + repo := Construct[models.EmailVerification, models.EmailVerification]( + models.EmailVerification{ + AccountId: AccountId, + IsExpired: false, + Token: token, + }, + ) + repo.Transactions( + WhereGivenConstructor[models.EmailVerification, models.EmailVerification], + Find[models.EmailVerification, models.EmailVerification], + ) + return *repo +} + +func UpdateExpiredEmailVerification(uuid uuid.UUID) Repository[models.EmailVerification, models.EmailVerification] { + repo := Construct[models.EmailVerification, models.EmailVerification]( + models.EmailVerification{Id: 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{ + Token: token, + }, + ) + + repo.Transactions( + WhereGivenConstructor[models.EmailVerification, models.EmailVerification], + Delete[models.EmailVerification], + ) + return *repo +} diff --git a/repositories/event_repository.go b/repositories/event_repository.go new file mode 100644 index 0000000000000000000000000000000000000000..29a90b04205123cc95a58d2a7bac844c32f4ad32 --- /dev/null +++ b/repositories/event_repository.go @@ -0,0 +1,93 @@ +package repositories + +import ( + "log" + + "github.com/google/uuid" + "godp.abdanhafidz.com/models" +) + +func GetAllEventsPaginate(pagination PaginationConstructor) Repository[models.Events, []models.Events] { + repo := Construct[models.Events, []models.Events]( + models.Events{}, + ) + repo.Pagination = pagination + + // Add debug log to verify pagination values + log.Printf("Pagination - Limit: %d, Offset: %d", pagination.Limit, pagination.Offset) + + // Transactions that execute the query + repo.Transactions( + FindAllPaginate[models.Events, []models.Events], + ) + + // Check if there's an error or no records + if repo.RowsCount == 0 { + log.Println("No events found with the provided pagination") + } + + return *repo +} + +func GetEventDetailByEventId(EventId uuid.UUID) Repository[models.Events, models.Events] { + repo := Construct[models.Events, models.Events]( + models.Events{ + Id: EventId, + }, + ) + repo.Transactions( + WhereGivenConstructor[models.Events, models.Events], + Find[models.Events, models.Events], + ) + return *repo +} + +func GetEventDetailBySlug(slug string) Repository[models.Events, models.Events] { + repo := Construct[models.Events, models.Events]( + models.Events{ + Slug: slug, + }, + ) + repo.Transactions( + WhereGivenConstructor[models.Events, models.Events], + Find[models.Events, models.Events], + ) + return *repo +} + +func GetEventAssigned(EventId uuid.UUID, AccountId uuid.UUID) Repository[models.EventAssign, models.EventAssign] { + repo := Construct[models.EventAssign, models.EventAssign]( + models.EventAssign{ + EventId: EventId, + AccountId: AccountId, + }, + ) + repo.Transactions( + WhereGivenConstructor[models.EventAssign, models.EventAssign], + Find[models.EventAssign, models.EventAssign], + ) + return *repo +} + +func GetEventByCode(code string) Repository[models.Events, models.Events] { + repo := Construct[models.Events, models.Events]( + models.Events{EventCode: code}, + ) + + repo.Transactions( + WhereGivenConstructor[models.Events, models.Events], + Find[models.Events, models.Events], + ) + if repo.RowsCount == 0 { + log.Println("No events found with the provided code") + } + return *repo +} + +func AssignEvent(eventAssign models.EventAssign) Repository[models.EventAssign, models.EventAssign] { + repo := Construct[models.EventAssign, models.EventAssign]( + eventAssign, + ) + Create(repo) + return *repo +} diff --git a/repositories/external_auth_repository.go b/repositories/external_auth_repository.go new file mode 100644 index 0000000000000000000000000000000000000000..9fdb371b167e7cba7d35384ec3f21457bf5cd158 --- /dev/null +++ b/repositories/external_auth_repository.go @@ -0,0 +1,40 @@ +package repositories + +import ( + "github.com/google/uuid" + "godp.abdanhafidz.com/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 uuid.UUID) 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/repositories/forgot_password_repository.go b/repositories/forgot_password_repository.go new file mode 100644 index 0000000000000000000000000000000000000000..e045556c05e18384c38e386586a43d400100002e --- /dev/null +++ b/repositories/forgot_password_repository.go @@ -0,0 +1,22 @@ +package repositories + +import "godp.abdanhafidz.com/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/repositories/option_repository.go b/repositories/option_repository.go new file mode 100644 index 0000000000000000000000000000000000000000..b2e718343d02247bd3a1c33ac2e1e18013e7725d --- /dev/null +++ b/repositories/option_repository.go @@ -0,0 +1,43 @@ +package repositories + +import ( + "godp.abdanhafidz.com/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/repositories/region_repository.go b/repositories/region_repository.go new file mode 100644 index 0000000000000000000000000000000000000000..2d7d1917dd6e7189f162f17ff931eb968d1e02fe --- /dev/null +++ b/repositories/region_repository.go @@ -0,0 +1,47 @@ +package repositories + +import ( + "godp.abdanhafidz.com/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/repositories/repository.go b/repositories/repository.go new file mode 100644 index 0000000000000000000000000000000000000000..f105755904ec3be306d31e28af0c687ad68ceaa6 --- /dev/null +++ b/repositories/repository.go @@ -0,0 +1,149 @@ +package repositories + +import ( + "fmt" + "godp.abdanhafidz.com/config" + "gorm.io/gorm" + "strings" +) + +type Repositories interface { + FindAllPaginate() + Where() + Find() + Create() + Update() + CustomQuery() + Delete() +} +type PaginationConstructor struct { + Limit int + Offset int + Filter string + FilterBy string +} + +type PaginationMetadata struct { + TotalRecords int `json:"total_records"` + TotalPages int `json:"total_pages"` + CurrentPage int `json:"current_page"` + PageSize int `json:"page_size"` +} + +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 FindAllPaginate[T1 any, T2 any](repo *Repository[T1, T2]) *gorm.DB { + tx := repo.Transaction.Limit(repo.Pagination.Limit).Offset(repo.Pagination.Offset) + + tx = buildFilter(tx, repo.Pagination) + + tx = tx.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 + repo.Result = repo.Constructor + 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 +} + +func buildFilter(db *gorm.DB, pagination PaginationConstructor) *gorm.DB { + if pagination.Filter != "" && pagination.FilterBy != "" { + filterFields := strings.Split(pagination.FilterBy, ",") + filterValues := strings.Split(pagination.Filter, ",") + + for i, field := range filterFields { + if i >= len(filterValues) { + break + } + filterValue := filterValues[i] + if filterValue != "" { + condition := fmt.Sprintf("%s ILIKE ?", field) + db = db.Where(condition, "%"+filterValue+"%") + } + } + } + return db +} diff --git a/router/auth_route.go b/router/auth_route.go new file mode 100644 index 0000000000000000000000000000000000000000..e38c577d06458d809e7306b002824e3b40ae70df --- /dev/null +++ b/router/auth_route.go @@ -0,0 +1,19 @@ +package router + +import ( + "github.com/gin-gonic/gin" + AuthController "godp.abdanhafidz.com/controller/auth" + "godp.abdanhafidz.com/middleware" +) + +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) + routerGroup.POST("/forgot-password", AuthController.CreateForgotPassword) + routerGroup.PUT("/forgot-password", AuthController.ValidateForgotPassword) + } +} diff --git a/router/email_route copy.go b/router/email_route copy.go new file mode 100644 index 0000000000000000000000000000000000000000..8909e45605fb75ce37976cc552191fbc41ecf37b --- /dev/null +++ b/router/email_route copy.go @@ -0,0 +1,14 @@ +package router + +import ( + "github.com/gin-gonic/gin" + EmailController "godp.abdanhafidz.com/controller/email" +) + +func EmailRoute(router *gin.Engine) { + routerGroup := router.Group("/api/v1/email") + { + routerGroup.POST("/verify", EmailController.Verify) + routerGroup.POST("/create-verification", EmailController.CreateVerification) + } +} diff --git a/router/event_route.go b/router/event_route.go new file mode 100644 index 0000000000000000000000000000000000000000..a98e86125d2a610468a6bea793cae65ec9517e85 --- /dev/null +++ b/router/event_route.go @@ -0,0 +1,16 @@ +package router + +import ( + "github.com/gin-gonic/gin" + "godp.abdanhafidz.com/controller/event" + "godp.abdanhafidz.com/middleware" +) + +func EventRoute(router *gin.Engine) { + routerGroup := router.Group("api/v1/events") + { + routerGroup.GET("/", event.EventList) + routerGroup.GET("/details/:id_event", middleware.AuthUser, event.EventDetail) + routerGroup.POST("/register-event", middleware.AuthUser, event.Register) + } +} diff --git a/router/options_route.go b/router/options_route.go new file mode 100644 index 0000000000000000000000000000000000000000..664e5101f9ed015ca60b4edcf5f4806331756a91 --- /dev/null +++ b/router/options_route.go @@ -0,0 +1,20 @@ +package router + +import ( + "github.com/gin-gonic/gin" + OptionsController "godp.abdanhafidz.com/controller/options" + CityController "godp.abdanhafidz.com/controller/region/city" + ProvinceController "godp.abdanhafidz.com/controller/region/province" +) + +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/router/router.go b/router/router.go new file mode 100644 index 0000000000000000000000000000000000000000..3e54a46e842243ac926c3fc7f60e9d6e37118555 --- /dev/null +++ b/router/router.go @@ -0,0 +1,24 @@ +package router + +import ( + "log" + + "github.com/gin-gonic/gin" + "godp.abdanhafidz.com/config" + "godp.abdanhafidz.com/controller" +) + +func StartService() { + router := gin.Default() + router.GET("/", controller.HomeController) + + AuthRoute(router) + UserRoute(router) + EmailRoute(router) + OptionsRoute(router) + EventRoute(router) + err := router.Run(config.TCP_ADDRESS) + if err != nil { + log.Fatalf("Failed to run server: %v", err) + } +} diff --git a/router/user_route copy.go b/router/user_route copy.go new file mode 100644 index 0000000000000000000000000000000000000000..ec985579f88cf31ac2005614d5c77e7e10347b30 --- /dev/null +++ b/router/user_route copy.go @@ -0,0 +1,15 @@ +package router + +import ( + "github.com/gin-gonic/gin" + UserController "godp.abdanhafidz.com/controller/user" + "godp.abdanhafidz.com/middleware" +) + +func UserRoute(router *gin.Engine) { + routerGroup := router.Group("/api/v1/user") + { + routerGroup.GET("/me", middleware.AuthUser, UserController.Profile) + routerGroup.PUT("/me", middleware.AuthUser, UserController.UpdateProfile) + } +} diff --git a/services/authentication_service.go b/services/authentication_service.go new file mode 100644 index 0000000000000000000000000000000000000000..38de68f3021d6149dc8ac71f5c26ea49b40fb566 --- /dev/null +++ b/services/authentication_service.go @@ -0,0 +1,71 @@ +package services + +import ( + "errors" + + "godp.abdanhafidz.com/models" + "godp.abdanhafidz.com/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) + return + } + + 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 + } + if VerifyPassword(accountData.Result.Password, oldPassword) != nil { + s.Exception.Unauthorized = true + s.Exception.Message = "incorrect old password!" + return + } + hashed_password, _ := HashPassword(newPassword) + accountData.Result.Password = hashed_password + 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/services/email_verification_service.go b/services/email_verification_service.go new file mode 100644 index 0000000000000000000000000000000000000000..7e26e9a14e6d6fdc3bc48499467dcef954586e06 --- /dev/null +++ b/services/email_verification_service.go @@ -0,0 +1,103 @@ +package services + +import ( + "math/rand/v2" + "time" + + "godp.abdanhafidz.com/config" + "godp.abdanhafidz.com/models" + "godp.abdanhafidz.com/repositories" +) + +type EmailVerificationService struct { + Service[models.EmailVerification, models.EmailVerification] +} + +func (s *EmailVerificationService) Create(email string) { + 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(999999-100000) + 100000) + + repo := repositories.CreateEmailVerification(s.Constructor.Id, accountRepo.Result.Id, 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 { + // s.Error = err + // log.Printf("Error sending verification email: %v", err) + // return + // } + // }(accountRepo.Result.Email, token) + // s.Result.Token = repo.Result.Token +} + +func (s *EmailVerificationService) Validate(email string) { + 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 + } + + repo := repositories.GetEmailVerification(accountRepo.Result.Id, 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.Id) + s.Delete() + return + } + account := repositories.GetAccountById(repo.Result.AccountId) + account.Result.IsEmailVerified = true + + repositories.UpdateAccount(account.Result) + 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/services/event_detail_service.go b/services/event_detail_service.go new file mode 100644 index 0000000000000000000000000000000000000000..361a7d6d3588386b19633cd09507aa8dd7ad75c5 --- /dev/null +++ b/services/event_detail_service.go @@ -0,0 +1,47 @@ +package services + +import ( + "github.com/google/uuid" + "godp.abdanhafidz.com/models" + "godp.abdanhafidz.com/repositories" +) + +type EventDetailService struct { + Service[models.Events, models.EventDetailResponse] +} + +func (s *EventDetailService) Retrieve(userId uuid.UUID) { + // ngecek event nya dulu + detail := repositories.GetEventDetailBySlug(s.Constructor.Slug) + if detail.NoRecord { + s.Error = detail.RowsError + s.Exception.DataNotFound = true + s.Exception.Message = "Event detail not found" + return + } + // ngecek apakah si event dan si user udah ke assign/register + assigned := repositories.GetEventAssigned(detail.Result.Id, userId) + + // kalo eventnya private dan di assigned itu ga ditemuin data antara event dan account ke register + // bakal ke tolak karena unauthorized + // el event tidak public mamka tidak boleh masuk + if !detail.Result.IsPublic && assigned.NoRecord { + s.Error = assigned.RowsError + s.Exception.Unauthorized = true + s.Exception.Message = "your account doesnt have access to this event" + return + } + + // ini ngecek kalo ke assign/register ke event public atau ngga + // sudah boolean, jadi ga usah dibandingin + var registerStatus int + if assigned.NoRecord { + registerStatus = 0 + } else { + registerStatus = 1 + } + + s.Error = detail.RowsError + s.Result.Data = &detail.Result + s.Result.RegisterStatus = registerStatus +} diff --git a/services/event_list_service.go b/services/event_list_service.go new file mode 100644 index 0000000000000000000000000000000000000000..7ec52729a55dee7d2040cdef3ada83f270cd8504 --- /dev/null +++ b/services/event_list_service.go @@ -0,0 +1,29 @@ +package services + +import ( + "godp.abdanhafidz.com/models" + "godp.abdanhafidz.com/repositories" +) + +type GetAllEventService struct { + Service[models.Events, []models.Events] +} + +func (s *GetAllEventService) Retrieve(pagination repositories.PaginationConstructor) { + eventsRepo := repositories.GetAllEventsPaginate(pagination) + + events := eventsRepo.Result + + totalRecords := eventsRepo.RowsCount + totalPages := (totalRecords / pagination.Limit) + 1 + + metadata := repositories.PaginationMetadata{ + TotalRecords: totalRecords, + TotalPages: totalPages, + CurrentPage: (pagination.Offset / pagination.Limit) + 1, + PageSize: pagination.Limit, + } + + s.Result = events + s.MetaData = metadata +} diff --git a/services/event_register_service.go b/services/event_register_service.go new file mode 100644 index 0000000000000000000000000000000000000000..8daac2b59025391916f252184f468943c582d0ec --- /dev/null +++ b/services/event_register_service.go @@ -0,0 +1,38 @@ +package services + +import ( + "github.com/google/uuid" + "godp.abdanhafidz.com/models" + "godp.abdanhafidz.com/repositories" +) + +type JoinEventService struct { + Service[models.JoinEventRequest, models.EventDetailResponse] +} + +func (s *JoinEventService) Create(AccountId uuid.UUID) { + event := repositories.GetEventByCode(s.Constructor.EventCode) + // log.Printf("event: %v", event) + if event.NoRecord { + s.Error = event.RowsError + s.Exception.DataNotFound = true + s.Exception.Message = "event not found" + return + } + // ngecek apakah si event dan si user udah ke assign/register + assigned := repositories.GetEventAssigned(s.Constructor.EventId, AccountId) + if assigned.NoRecord == true { + accountAssigned := &models.EventAssign{ + Id: uuid.New(), + EventId: s.Constructor.EventId, + AccountId: AccountId, + } + repositories.AssignEvent(*accountAssigned) + } else { + s.Exception.DataDuplicate = true + s.Exception.Message = "account already assigned to this event" + return + } + s.Result.Data = &event.Result + s.Result.RegisterStatus = 1 +} diff --git a/services/external_authentication_service.go b/services/external_authentication_service.go new file mode 100644 index 0000000000000000000000000000000000000000..902cc749854f5194634db14c8463b83842c8e3de --- /dev/null +++ b/services/external_authentication_service.go @@ -0,0 +1,78 @@ +package services + +import ( + "context" + "errors" + + "godp.abdanhafidz.com/models" + "godp.abdanhafidz.com/repositories" + "google.golang.org/api/idtoken" +) + +type GoogleAuthService struct { + Service[models.ExternalAuth, models.AuthenticatedUser] +} + +func (s *GoogleAuthService) Authenticate(isAgree bool) { + 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"] + checkRegisteredEmail := repositories.GetAccountbyEmail(email.(string)) + if !checkRegisteredEmail.NoRecord { + token, _ := GenerateToken(&checkRegisteredEmail.Result) + checkRegisteredEmail.Result.Password = "SECRET" + s.Result = models.AuthenticatedUser{ + Account: checkRegisteredEmail.Result, + Token: token, + } + return + } + 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.OauthProvider = "Google" + + createAccount := repositories.CreateAccount(models.Account{ + Email: email.(string), + IsEmailVerified: true, + }) + + s.Constructor.AccountId = createAccount.Result.Id + createGoogleAuth := repositories.CreateExternalAuth(s.Constructor) + + 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) + + 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/services/forgot_password_service.go b/services/forgot_password_service.go new file mode 100644 index 0000000000000000000000000000000000000000..bd01b10533e82d5c600ff9a9c192d0f2e4fa3d55 --- /dev/null +++ b/services/forgot_password_service.go @@ -0,0 +1,109 @@ +package services + +import ( + "math/rand/v2" + "time" + + "godp.abdanhafidz.com/config" + "godp.abdanhafidz.com/models" + "godp.abdanhafidz.com/repositories" +) + +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(999999-100000) + 100000) + 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 + return +} + +func (s *ForgotPasswordService) Validate(newPassword *string) { + + 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 + } + + 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 + s.Exception.Message = "Failed to update password!" + return + } + fgPasswordRepo.Result.Token = 0 + +} diff --git a/services/jwt_service.go b/services/jwt_service.go new file mode 100644 index 0000000000000000000000000000000000000000..5ff0cc959ff02be1ea2813fcb8b92a559dac8c34 --- /dev/null +++ b/services/jwt_service.go @@ -0,0 +1,81 @@ +package services + +import ( + "errors" + "strings" + "time" + + "github.com/golang-jwt/jwt/v5" + "github.com/google/uuid" + "godp.abdanhafidz.com/config" + "godp.abdanhafidz.com/models" + "golang.org/x/crypto/bcrypt" +) + +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: "apqobiltu.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 +} + +func VerifyToken(bearerToken string) (uuid.UUID, string, error) { + // fmt.Println("bearerToken :", bearerToken) + + tokenData, err := ExtractBearerToken(bearerToken) + if err != nil { + return uuid.UUID{}, "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 + }) + + if err != nil { + return uuid.UUID{}, "invalid-token", err + } + + // Extract the claims + claims, ok := token.Claims.(*models.CustomClaims) + if !ok || !token.Valid { + return uuid.UUID{}, "invalid-token", err + } + if claims.ExpiresAt != nil && claims.ExpiresAt.Time.Before(time.Now()) { + return uuid.UUID{}, "expired", err + } + + return claims.UserID, "valid", err +} + +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/services/option_service.go b/services/option_service.go new file mode 100644 index 0000000000000000000000000000000000000000..9546f8ba91cd264918d74c5910f5884fa111a3aa --- /dev/null +++ b/services/option_service.go @@ -0,0 +1,70 @@ +package services + +import ( + "github.com/gosimple/slug" + "godp.abdanhafidz.com/models" + "godp.abdanhafidz.com/repositories" +) + +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/services/region_service.go b/services/region_service.go new file mode 100644 index 0000000000000000000000000000000000000000..0fa4cab06e4cedc9ceea7aad4a5e3fdc2a3def12 --- /dev/null +++ b/services/region_service.go @@ -0,0 +1,90 @@ +package services + +import ( + "encoding/json" + "log" + "os" + "path/filepath" + "runtime" + + "godp.abdanhafidz.com/models" + "godp.abdanhafidz.com/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/services/register_service.go b/services/register_service.go new file mode 100644 index 0000000000000000000000000000000000000000..31c2bf389157244d15c44a5dbbec28f92e91a9b3 --- /dev/null +++ b/services/register_service.go @@ -0,0 +1,46 @@ +package services + +import ( + "errors" + + "github.com/google/uuid" + "godp.abdanhafidz.com/models" + "godp.abdanhafidz.com/repositories" + "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 := HashPassword(s.Constructor.Password) + s.Error = err_hash + s.Constructor.Password = hashed_password + s.Constructor.Id = uuid.New() + 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 + } + 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/services/service.go b/services/service.go new file mode 100644 index 0000000000000000000000000000000000000000..5d61741bb04c25de6be35efa40b516797ac9b873 --- /dev/null +++ b/services/service.go @@ -0,0 +1,44 @@ +package services + +import ( + "time" + + "godp.abdanhafidz.com/models" + "godp.abdanhafidz.com/repositories" +) + +type ( + Services interface { + Retrieve() + Update() + Create() + Delete() + Validate() + Authenticate() + Authorize() + } + IService interface { + Implements() + } + Service[TConstructor any, TResult any] struct { + Constructor TConstructor + Result TResult + Exception models.Exception + Error error + MetaData repositories.PaginationMetadata + } +) + +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], + } +} + +func CalculateDueTime(duration time.Duration) time.Time { + return time.Now().Add(duration) +} diff --git a/services/user_profile_service.go b/services/user_profile_service.go new file mode 100644 index 0000000000000000000000000000000000000000..635f2085d0ceee2f8dad2ff199380c630bb2ddc2 --- /dev/null +++ b/services/user_profile_service.go @@ -0,0 +1,98 @@ +package services + +import ( + "regexp" + "strings" + + "godp.abdanhafidz.com/models" + "godp.abdanhafidz.com/repositories" +) + +type UserProfileService struct { + 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() { + 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 = models.UserProfileResponse{ + Account: repositories.GetAccountById(s.Constructor.AccountId).Result, + Details: userProfile.Result, + } +} +func (s *UserProfileService) Retrieve() { + 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 = models.UserProfileResponse{ + Account: repositories.GetAccountById(s.Constructor.AccountId).Result, + Details: userProfile.Result, + } + s.Result.Account.Password = "SECRET" +} + +func (s *UserProfileService) Update() { + if s.Constructor.PhoneNumber != nil { + phoneNumber := *s.Constructor.PhoneNumber + *s.Constructor.PhoneNumber = SanitizePhoneNumber(phoneNumber) + } + 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 + } + account := repositories.GetAccountById(s.Constructor.AccountId) + account.Result.IsDetailCompleted = (userProfile.Result.FullName != nil && + userProfile.Result.PhoneNumber != nil && + userProfile.Result.SchoolName != nil && + userProfile.Result.Province != nil && + userProfile.Result.City != nil) + repositories.UpdateAccount(account.Result) + s.Result = models.UserProfileResponse{ + Account: account.Result, + Details: userProfile.Result, + } + s.Result.Account.Password = "SECRET" +} diff --git a/space/.gitattributes b/space/.gitattributes new file mode 100644 index 0000000000000000000000000000000000000000..a6344aac8c09253b3b630fb776ae94478aa0275b --- /dev/null +++ b/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/utils/Helper.go b/utils/Helper.go new file mode 100644 index 0000000000000000000000000000000000000000..a5c395dc51aa4d829024bee303c6a96985c9eae7 --- /dev/null +++ b/utils/Helper.go @@ -0,0 +1,11 @@ +package utils + +import ( + "github.com/gin-gonic/gin" + "godp.abdanhafidz.com/models" +) + +func GetAccount(c *gin.Context) models.AccountData { + cParam, _ := c.Get("accountData") + return cParam.(models.AccountData) +} diff --git a/utils/Logger.go b/utils/Logger.go new file mode 100644 index 0000000000000000000000000000000000000000..ee135204582e4849890e27891de7bfaab566b583 --- /dev/null +++ b/utils/Logger.go @@ -0,0 +1,22 @@ +package utils + +import ( + "fmt" + "log" + "os" + + "godp.abdanhafidz.com/config" +) + +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) + } + + fmt.Println("Error Log :", errorLogged) + log.SetOutput(file) + + log.Println("Error Log :", errorLogged) +} diff --git a/utils/api_response.go b/utils/api_response.go new file mode 100644 index 0000000000000000000000000000000000000000..8e314a142c5a6c6a928800104f9f625e8d1f627d --- /dev/null +++ b/utils/api_response.go @@ -0,0 +1,52 @@ +package utils + +import ( + "net/http" + "reflect" + + "github.com/gin-gonic/gin" + "godp.abdanhafidz.com/models" + "godp.abdanhafidz.com/services" +) + +func ResponseOK(c *gin.Context, data any, metadata any) { + res := models.SuccessResponse{ + Status: "success", + Message: "Data retrieved successfully!", + Data: data, + MetaData: metadata, + } + 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, nil) + } 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/utils/seeds/city.json b/utils/seeds/city.json new file mode 100644 index 0000000000000000000000000000000000000000..35dcd333d40c752ddff4003e57aff5242e466d73 --- /dev/null +++ b/utils/seeds/city.json @@ -0,0 +1,4114 @@ +[ + { + "id": 1, + "type": "Kabupaten", + "name": "Aceh Barat", + "code": "05", + "full_code": "1105", + "province_id": 1 + }, + { + "id": 2, + "type": "Kabupaten", + "name": "Aceh Barat Daya", + "code": "12", + "full_code": "1112", + "province_id": 1 + }, + { + "id": 3, + "type": "Kabupaten", + "name": "Sabu Raijua", + "code": "20", + "full_code": "5320", + "province_id": 23 + }, + { + "id": 4, + "type": "Kota", + "name": "Salatiga", + "code": "73", + "full_code": "3373", + "province_id": 10 + }, + { + "id": 5, + "type": "Kabupaten", + "name": "Aceh Besar", + "code": "06", + "full_code": "1106", + "province_id": 1 + }, + { + "id": 6, + "type": "Kabupaten", + "name": "Aceh Jaya", + "code": "14", + "full_code": "1114", + "province_id": 1 + }, + { + "id": 7, + "type": "Kabupaten", + "name": "Aceh Selatan", + "code": "01", + "full_code": "1101", + "province_id": 1 + }, + { + "id": 8, + "type": "Kabupaten", + "name": "Aceh Singkil", + "code": "10", + "full_code": "1110", + "province_id": 1 + }, + { + "id": 9, + "type": "Kabupaten", + "name": "Aceh Tamiang", + "code": "16", + "full_code": "1116", + "province_id": 1 + }, + { + "id": 10, + "type": "Kabupaten", + "name": "Aceh Tengah", + "code": "04", + "full_code": "1104", + "province_id": 1 + }, + { + "id": 11, + "type": "Kabupaten", + "name": "Aceh Tenggara", + "code": "02", + "full_code": "1102", + "province_id": 1 + }, + { + "id": 12, + "type": "Kabupaten", + "name": "Aceh Timur", + "code": "03", + "full_code": "1103", + "province_id": 1 + }, + { + "id": 13, + "type": "Kabupaten", + "name": "Gorontalo Utara", + "code": "05", + "full_code": "7505", + "province_id": 7 + }, + { + "id": 14, + "type": "Kabupaten", + "name": "Aceh Utara", + "code": "08", + "full_code": "1108", + "province_id": 1 + }, + { + "id": 15, + "type": "Kabupaten", + "name": "Agam", + "code": "06", + "full_code": "1306", + "province_id": 36 + }, + { + "id": 16, + "type": "Kabupaten", + "name": "Alor", + "code": "05", + "full_code": "5305", + "province_id": 23 + }, + { + "id": 17, + "type": "Kota", + "name": "Ambon", + "code": "71", + "full_code": "8171", + "province_id": 20 + }, + { + "id": 18, + "type": "Kabupaten", + "name": "Gowa", + "code": "06", + "full_code": "7306", + "province_id": 32 + }, + { + "id": 19, + "type": "Kota", + "name": "Samarinda", + "code": "72", + "full_code": "6472", + "province_id": 15 + }, + { + "id": 20, + "type": "Kabupaten", + "name": "Asahan", + "code": "09", + "full_code": "1209", + "province_id": 38 + }, + { + "id": 21, + "type": "Kabupaten", + "name": "Sambas", + "code": "01", + "full_code": "6101", + "province_id": 12 + }, + { + "id": 22, + "type": "Kabupaten", + "name": "Asmat", + "code": "04", + "full_code": "9304", + "province_id": 28 + }, + { + "id": 23, + "type": "Kabupaten", + "name": "Samosir", + "code": "17", + "full_code": "1217", + "province_id": 38 + }, + { + "id": 24, + "type": "Kabupaten", + "name": "Badung", + "code": "03", + "full_code": "5103", + "province_id": 2 + }, + { + "id": 25, + "type": "Kabupaten", + "name": "Sampang", + "code": "27", + "full_code": "3527", + "province_id": 11 + }, + { + "id": 26, + "type": "Kabupaten", + "name": "Balangan", + "code": "11", + "full_code": "6311", + "province_id": 13 + }, + { + "id": 27, + "type": "Kabupaten", + "name": "Sanggau", + "code": "03", + "full_code": "6103", + "province_id": 12 + }, + { + "id": 28, + "type": "Kabupaten", + "name": "Sarmi", + "code": "10", + "full_code": "9110", + "province_id": 24 + }, + { + "id": 29, + "type": "Kabupaten", + "name": "Gresik", + "code": "25", + "full_code": "3525", + "province_id": 11 + }, + { + "id": 30, + "type": "Kabupaten", + "name": "Grobogan", + "code": "15", + "full_code": "3315", + "province_id": 10 + }, + { + "id": 31, + "type": "Kabupaten", + "name": "Gunung Mas", + "code": "10", + "full_code": "6210", + "province_id": 14 + }, + { + "id": 32, + "type": "Kabupaten", + "name": "Gunungkidul", + "code": "03", + "full_code": "3403", + "province_id": 5 + }, + { + "id": 33, + "type": "Kabupaten", + "name": "Sarolangun", + "code": "03", + "full_code": "1503", + "province_id": 8 + }, + { + "id": 34, + "type": "Kota", + "name": "Gunungsitoli", + "code": "78", + "full_code": "1278", + "province_id": 38 + }, + { + "id": 35, + "type": "Kota", + "name": "Sawahlunto", + "code": "73", + "full_code": "1373", + "province_id": 36 + }, + { + "id": 36, + "type": "Kabupaten", + "name": "Halmahera Barat", + "code": "01", + "full_code": "8201", + "province_id": 21 + }, + { + "id": 37, + "type": "Kabupaten", + "name": "Sekadau", + "code": "09", + "full_code": "6109", + "province_id": 12 + }, + { + "id": 38, + "type": "Kabupaten", + "name": "Halmahera Selatan", + "code": "04", + "full_code": "8204", + "province_id": 21 + }, + { + "id": 39, + "type": "Kabupaten", + "name": "Seluma", + "code": "05", + "full_code": "1705", + "province_id": 4 + }, + { + "id": 40, + "type": "Kabupaten", + "name": "Halmahera Tengah", + "code": "02", + "full_code": "8202", + "province_id": 21 + }, + { + "id": 41, + "type": "Kabupaten", + "name": "Semarang", + "code": "22", + "full_code": "3322", + "province_id": 10 + }, + { + "id": 42, + "type": "Kota", + "name": "Semarang", + "code": "74", + "full_code": "3374", + "province_id": 10 + }, + { + "id": 43, + "type": "Kabupaten", + "name": "Halmahera Timur", + "code": "06", + "full_code": "8206", + "province_id": 21 + }, + { + "id": 44, + "type": "Kabupaten", + "name": "Seram Bagian Barat", + "code": "06", + "full_code": "8106", + "province_id": 20 + }, + { + "id": 45, + "type": "Kabupaten", + "name": "Halmahera Utara", + "code": "03", + "full_code": "8203", + "province_id": 21 + }, + { + "id": 46, + "type": "Kabupaten", + "name": "Seram Bagian Timur", + "code": "05", + "full_code": "8105", + "province_id": 20 + }, + { + "id": 47, + "type": "Kabupaten", + "name": "Hulu Sungai Selatan", + "code": "06", + "full_code": "6306", + "province_id": 13 + }, + { + "id": 48, + "type": "Kabupaten", + "name": "Hulu Sungai Tengah", + "code": "07", + "full_code": "6307", + "province_id": 13 + }, + { + "id": 49, + "type": "Kabupaten", + "name": "Hulu Sungai Utara", + "code": "08", + "full_code": "6308", + "province_id": 13 + }, + { + "id": 50, + "type": "Kota", + "name": "Serang", + "code": "73", + "full_code": "3673", + "province_id": 3 + }, + { + "id": 51, + "type": "Kabupaten", + "name": "Serang", + "code": "04", + "full_code": "3604", + "province_id": 3 + }, + { + "id": 52, + "type": "Kabupaten", + "name": "Humbang Hasundutan", + "code": "16", + "full_code": "1216", + "province_id": 38 + }, + { + "id": 53, + "type": "Kota", + "name": "Balikpapan", + "code": "71", + "full_code": "6471", + "province_id": 15 + }, + { + "id": 54, + "type": "Kabupaten", + "name": "Indragiri Hilir", + "code": "04", + "full_code": "1404", + "province_id": 30 + }, + { + "id": 55, + "type": "Kabupaten", + "name": "Indragiri Hulu", + "code": "02", + "full_code": "1402", + "province_id": 30 + }, + { + "id": 56, + "type": "Kota", + "name": "Banda Aceh", + "code": "71", + "full_code": "1171", + "province_id": 1 + }, + { + "id": 57, + "type": "Kota", + "name": "Bandar Lampung", + "code": "71", + "full_code": "1871", + "province_id": 19 + }, + { + "id": 58, + "type": "Kota", + "name": "Bandung", + "code": "73", + "full_code": "3273", + "province_id": 9 + }, + { + "id": 59, + "type": "Kabupaten", + "name": "Bandung", + "code": "04", + "full_code": "3204", + "province_id": 9 + }, + { + "id": 60, + "type": "Kabupaten", + "name": "Bandung Barat", + "code": "17", + "full_code": "3217", + "province_id": 9 + }, + { + "id": 61, + "type": "Kabupaten", + "name": "Banggai", + "code": "01", + "full_code": "7201", + "province_id": 33 + }, + { + "id": 62, + "type": "Kabupaten", + "name": "Banggai Kepulauan", + "code": "07", + "full_code": "7207", + "province_id": 33 + }, + { + "id": 63, + "type": "Kabupaten", + "name": "Banggai Laut", + "code": "11", + "full_code": "7211", + "province_id": 33 + }, + { + "id": 64, + "type": "Kabupaten", + "name": "Bangka", + "code": "01", + "full_code": "1901", + "province_id": 17 + }, + { + "id": 65, + "type": "Kabupaten", + "name": "Bangka Barat", + "code": "05", + "full_code": "1905", + "province_id": 17 + }, + { + "id": 66, + "type": "Kabupaten", + "name": "Bangka Selatan", + "code": "03", + "full_code": "1903", + "province_id": 17 + }, + { + "id": 67, + "type": "Kabupaten", + "name": "Bangka Tengah", + "code": "04", + "full_code": "1904", + "province_id": 17 + }, + { + "id": 68, + "type": "Kabupaten", + "name": "Bangkalan", + "code": "26", + "full_code": "3526", + "province_id": 11 + }, + { + "id": 69, + "type": "Kabupaten", + "name": "Bangli", + "code": "06", + "full_code": "5106", + "province_id": 2 + }, + { + "id": 70, + "type": "Kota", + "name": "Banjar", + "code": "79", + "full_code": "3279", + "province_id": 9 + }, + { + "id": 71, + "type": "Kabupaten", + "name": "Banjar", + "code": "03", + "full_code": "6303", + "province_id": 13 + }, + { + "id": 72, + "type": "Kota", + "name": "Banjarbaru", + "code": "72", + "full_code": "6372", + "province_id": 13 + }, + { + "id": 73, + "type": "Kota", + "name": "Banjarmasin", + "code": "71", + "full_code": "6371", + "province_id": 13 + }, + { + "id": 74, + "type": "Kabupaten", + "name": "Banjarnegara", + "code": "04", + "full_code": "3304", + "province_id": 10 + }, + { + "id": 75, + "type": "Kabupaten", + "name": "Bantaeng", + "code": "03", + "full_code": "7303", + "province_id": 32 + }, + { + "id": 76, + "type": "Kabupaten", + "name": "Bantul", + "code": "02", + "full_code": "3402", + "province_id": 5 + }, + { + "id": 77, + "type": "Kabupaten", + "name": "Banyuasin", + "code": "07", + "full_code": "1607", + "province_id": 37 + }, + { + "id": 78, + "type": "Kabupaten", + "name": "Banyumas", + "code": "02", + "full_code": "3302", + "province_id": 10 + }, + { + "id": 79, + "type": "Kabupaten", + "name": "Banyuwangi", + "code": "10", + "full_code": "3510", + "province_id": 11 + }, + { + "id": 80, + "type": "Kabupaten", + "name": "Barito Kuala", + "code": "04", + "full_code": "6304", + "province_id": 13 + }, + { + "id": 81, + "type": "Kabupaten", + "name": "Barito Selatan", + "code": "04", + "full_code": "6204", + "province_id": 14 + }, + { + "id": 82, + "type": "Kabupaten", + "name": "Barito Timur", + "code": "13", + "full_code": "6213", + "province_id": 14 + }, + { + "id": 83, + "type": "Kabupaten", + "name": "Barito Utara", + "code": "05", + "full_code": "6205", + "province_id": 14 + }, + { + "id": 84, + "type": "Kabupaten", + "name": "Barru", + "code": "11", + "full_code": "7311", + "province_id": 32 + }, + { + "id": 85, + "type": "Kota", + "name": "Batam", + "code": "71", + "full_code": "2171", + "province_id": 18 + }, + { + "id": 86, + "type": "Kabupaten", + "name": "Batang", + "code": "25", + "full_code": "3325", + "province_id": 10 + }, + { + "id": 87, + "type": "Kabupaten", + "name": "Batanghari", + "code": "04", + "full_code": "1504", + "province_id": 8 + }, + { + "id": 88, + "type": "Kota", + "name": "Batu", + "code": "79", + "full_code": "3579", + "province_id": 11 + }, + { + "id": 89, + "type": "Kabupaten", + "name": "Batu Bara", + "code": "19", + "full_code": "1219", + "province_id": 38 + }, + { + "id": 90, + "type": "Kota", + "name": "Bau Bau", + "code": "72", + "full_code": "7472", + "province_id": 34 + }, + { + "id": 91, + "type": "Kota", + "name": "Bekasi", + "code": "75", + "full_code": "3275", + "province_id": 9 + }, + { + "id": 92, + "type": "Kabupaten", + "name": "Bekasi", + "code": "16", + "full_code": "3216", + "province_id": 9 + }, + { + "id": 93, + "type": "Kabupaten", + "name": "Belitung", + "code": "02", + "full_code": "1902", + "province_id": 17 + }, + { + "id": 94, + "type": "Kabupaten", + "name": "Belitung Timur", + "code": "06", + "full_code": "1906", + "province_id": 17 + }, + { + "id": 95, + "type": "Kabupaten", + "name": "Belu", + "code": "04", + "full_code": "5304", + "province_id": 23 + }, + { + "id": 96, + "type": "Kabupaten", + "name": "Bener Meriah", + "code": "17", + "full_code": "1117", + "province_id": 1 + }, + { + "id": 97, + "type": "Kabupaten", + "name": "Bengkalis", + "code": "03", + "full_code": "1403", + "province_id": 30 + }, + { + "id": 98, + "type": "Kabupaten", + "name": "Bengkayang", + "code": "07", + "full_code": "6107", + "province_id": 12 + }, + { + "id": 99, + "type": "Kabupaten", + "name": "Serdang Bedagai", + "code": "18", + "full_code": "1218", + "province_id": 38 + }, + { + "id": 100, + "type": "Kota", + "name": "Bengkulu", + "code": "71", + "full_code": "1771", + "province_id": 4 + }, + { + "id": 101, + "type": "Kabupaten", + "name": "Bengkulu Selatan", + "code": "01", + "full_code": "1701", + "province_id": 4 + }, + { + "id": 102, + "type": "Kabupaten", + "name": "Seruyan", + "code": "07", + "full_code": "6207", + "province_id": 14 + }, + { + "id": 103, + "type": "Kabupaten", + "name": "Indramayu", + "code": "12", + "full_code": "3212", + "province_id": 9 + }, + { + "id": 104, + "type": "Kabupaten", + "name": "Siak", + "code": "08", + "full_code": "1408", + "province_id": 30 + }, + { + "id": 105, + "type": "Kabupaten", + "name": "Intan Jaya", + "code": "07", + "full_code": "9407", + "province_id": 29 + }, + { + "id": 106, + "type": "Kota", + "name": "Jakarta Barat", + "code": "73", + "full_code": "3173", + "province_id": 6 + }, + { + "id": 107, + "type": "Kota", + "name": "Sibolga", + "code": "73", + "full_code": "1273", + "province_id": 38 + }, + { + "id": 108, + "type": "Kabupaten", + "name": "Bengkulu Tengah", + "code": "09", + "full_code": "1709", + "province_id": 4 + }, + { + "id": 109, + "type": "Kota", + "name": "Jakarta Pusat", + "code": "71", + "full_code": "3171", + "province_id": 6 + }, + { + "id": 110, + "type": "Kabupaten", + "name": "Sidenreng Rappang", + "code": "14", + "full_code": "7314", + "province_id": 32 + }, + { + "id": 111, + "type": "Kabupaten", + "name": "Bengkulu Utara", + "code": "03", + "full_code": "1703", + "province_id": 4 + }, + { + "id": 112, + "type": "Kota", + "name": "Jakarta Selatan", + "code": "74", + "full_code": "3174", + "province_id": 6 + }, + { + "id": 113, + "type": "Kabupaten", + "name": "Sidoarjo", + "code": "15", + "full_code": "3515", + "province_id": 11 + }, + { + "id": 114, + "type": "Kota", + "name": "Jakarta Timur", + "code": "75", + "full_code": "3175", + "province_id": 6 + }, + { + "id": 115, + "type": "Kabupaten", + "name": "Sigi", + "code": "10", + "full_code": "7210", + "province_id": 33 + }, + { + "id": 116, + "type": "Kabupaten", + "name": "Berau", + "code": "03", + "full_code": "6403", + "province_id": 15 + }, + { + "id": 117, + "type": "Kabupaten", + "name": "Biak Numfor", + "code": "06", + "full_code": "9106", + "province_id": 24 + }, + { + "id": 118, + "type": "Kabupaten", + "name": "Bima", + "code": "06", + "full_code": "5206", + "province_id": 22 + }, + { + "id": 119, + "type": "Kota", + "name": "Jakarta Utara", + "code": "72", + "full_code": "3172", + "province_id": 6 + }, + { + "id": 120, + "type": "Kota", + "name": "Bima", + "code": "72", + "full_code": "5272", + "province_id": 22 + }, + { + "id": 121, + "type": "Kota", + "name": "Jambi", + "code": "71", + "full_code": "1571", + "province_id": 8 + }, + { + "id": 122, + "type": "Kabupaten", + "name": "Sijunjung", + "code": "03", + "full_code": "1303", + "province_id": 36 + }, + { + "id": 123, + "type": "Kota", + "name": "Binjai", + "code": "75", + "full_code": "1275", + "province_id": 38 + }, + { + "id": 124, + "type": "Kabupaten", + "name": "Jayapura", + "code": "03", + "full_code": "9103", + "province_id": 24 + }, + { + "id": 125, + "type": "Kabupaten", + "name": "Bintan", + "code": "01", + "full_code": "2101", + "province_id": 18 + }, + { + "id": 126, + "type": "Kabupaten", + "name": "Sikka", + "code": "07", + "full_code": "5307", + "province_id": 23 + }, + { + "id": 127, + "type": "Kabupaten", + "name": "Bireuen", + "code": "11", + "full_code": "1111", + "province_id": 1 + }, + { + "id": 128, + "type": "Kabupaten", + "name": "Simalungun", + "code": "08", + "full_code": "1208", + "province_id": 38 + }, + { + "id": 129, + "type": "Kota", + "name": "Bitung", + "code": "72", + "full_code": "7172", + "province_id": 35 + }, + { + "id": 130, + "type": "Kota", + "name": "Jayapura", + "code": "71", + "full_code": "9171", + "province_id": 24 + }, + { + "id": 131, + "type": "Kabupaten", + "name": "Simeulue", + "code": "09", + "full_code": "1109", + "province_id": 1 + }, + { + "id": 132, + "type": "Kabupaten", + "name": "Jayawijaya", + "code": "01", + "full_code": "9501", + "province_id": 27 + }, + { + "id": 133, + "type": "Kabupaten", + "name": "Jember", + "code": "09", + "full_code": "3509", + "province_id": 11 + }, + { + "id": 134, + "type": "Kota", + "name": "Singkawang", + "code": "72", + "full_code": "6172", + "province_id": 12 + }, + { + "id": 135, + "type": "Kabupaten", + "name": "Blitar", + "code": "05", + "full_code": "3505", + "province_id": 11 + }, + { + "id": 136, + "type": "Kabupaten", + "name": "Jembrana", + "code": "01", + "full_code": "5101", + "province_id": 2 + }, + { + "id": 137, + "type": "Kabupaten", + "name": "Sinjai", + "code": "07", + "full_code": "7307", + "province_id": 32 + }, + { + "id": 138, + "type": "Kota", + "name": "Blitar", + "code": "72", + "full_code": "3572", + "province_id": 11 + }, + { + "id": 139, + "type": "Kabupaten", + "name": "Jeneponto", + "code": "04", + "full_code": "7304", + "province_id": 32 + }, + { + "id": 140, + "type": "Kabupaten", + "name": "Blora", + "code": "16", + "full_code": "3316", + "province_id": 10 + }, + { + "id": 141, + "type": "Kabupaten", + "name": "Jepara", + "code": "20", + "full_code": "3320", + "province_id": 10 + }, + { + "id": 142, + "type": "Kabupaten", + "name": "Sintang", + "code": "05", + "full_code": "6105", + "province_id": 12 + }, + { + "id": 143, + "type": "Kabupaten", + "name": "Boalemo", + "code": "02", + "full_code": "7502", + "province_id": 7 + }, + { + "id": 144, + "type": "Kabupaten", + "name": "Jombang", + "code": "17", + "full_code": "3517", + "province_id": 11 + }, + { + "id": 145, + "type": "Kabupaten", + "name": "Bogor", + "code": "01", + "full_code": "3201", + "province_id": 9 + }, + { + "id": 146, + "type": "Kabupaten", + "name": "Situbondo", + "code": "12", + "full_code": "3512", + "province_id": 11 + }, + { + "id": 147, + "type": "Kabupaten", + "name": "Kaimana", + "code": "08", + "full_code": "9208", + "province_id": 25 + }, + { + "id": 148, + "type": "Kota", + "name": "Bogor", + "code": "71", + "full_code": "3271", + "province_id": 9 + }, + { + "id": 149, + "type": "Kabupaten", + "name": "Sleman", + "code": "04", + "full_code": "3404", + "province_id": 5 + }, + { + "id": 150, + "type": "Kabupaten", + "name": "Kampar", + "code": "01", + "full_code": "1401", + "province_id": 30 + }, + { + "id": 151, + "type": "Kabupaten", + "name": "Bojonegoro", + "code": "22", + "full_code": "3522", + "province_id": 11 + }, + { + "id": 152, + "type": "Kabupaten", + "name": "Solok", + "code": "02", + "full_code": "1302", + "province_id": 36 + }, + { + "id": 153, + "type": "Kabupaten", + "name": "Bolaang Mongondow", + "code": "01", + "full_code": "7101", + "province_id": 35 + }, + { + "id": 154, + "type": "Kabupaten", + "name": "Bolaang Mongondow Selatan", + "code": "11", + "full_code": "7111", + "province_id": 35 + }, + { + "id": 155, + "type": "Kota", + "name": "Solok", + "code": "72", + "full_code": "1372", + "province_id": 36 + }, + { + "id": 156, + "type": "Kabupaten", + "name": "Kapuas", + "code": "03", + "full_code": "6203", + "province_id": 14 + }, + { + "id": 157, + "type": "Kabupaten", + "name": "Solok Selatan", + "code": "11", + "full_code": "1311", + "province_id": 36 + }, + { + "id": 158, + "type": "Kabupaten", + "name": "Bolaang Mongondow Timur", + "code": "10", + "full_code": "7110", + "province_id": 35 + }, + { + "id": 159, + "type": "Kabupaten", + "name": "Kapuas Hulu", + "code": "06", + "full_code": "6106", + "province_id": 12 + }, + { + "id": 160, + "type": "Kabupaten", + "name": "Karanganyar", + "code": "13", + "full_code": "3313", + "province_id": 10 + }, + { + "id": 161, + "type": "Kabupaten", + "name": "Karangasem", + "code": "07", + "full_code": "5107", + "province_id": 2 + }, + { + "id": 162, + "type": "Kabupaten", + "name": "Bolaang Mongondow Utara", + "code": "08", + "full_code": "7108", + "province_id": 35 + }, + { + "id": 163, + "type": "Kabupaten", + "name": "Karawang", + "code": "15", + "full_code": "3215", + "province_id": 9 + }, + { + "id": 164, + "type": "Kabupaten", + "name": "Bombana", + "code": "06", + "full_code": "7406", + "province_id": 34 + }, + { + "id": 165, + "type": "Kabupaten", + "name": "Karimun", + "code": "02", + "full_code": "2102", + "province_id": 18 + }, + { + "id": 166, + "type": "Kabupaten", + "name": "Bondowoso", + "code": "11", + "full_code": "3511", + "province_id": 11 + }, + { + "id": 167, + "type": "Kabupaten", + "name": "Karo", + "code": "06", + "full_code": "1206", + "province_id": 38 + }, + { + "id": 168, + "type": "Kabupaten", + "name": "Soppeng", + "code": "12", + "full_code": "7312", + "province_id": 32 + }, + { + "id": 169, + "type": "Kabupaten", + "name": "Katingan", + "code": "06", + "full_code": "6206", + "province_id": 14 + }, + { + "id": 170, + "type": "Kabupaten", + "name": "Kaur", + "code": "04", + "full_code": "1704", + "province_id": 4 + }, + { + "id": 171, + "type": "Kabupaten", + "name": "Sorong", + "code": "01", + "full_code": "9201", + "province_id": 26 + }, + { + "id": 172, + "type": "Kabupaten", + "name": "Kayong Utara", + "code": "11", + "full_code": "6111", + "province_id": 12 + }, + { + "id": 173, + "type": "Kota", + "name": "Sorong", + "code": "71", + "full_code": "9271", + "province_id": 26 + }, + { + "id": 174, + "type": "Kabupaten", + "name": "Sorong Selatan", + "code": "04", + "full_code": "9204", + "province_id": 26 + }, + { + "id": 175, + "type": "Kabupaten", + "name": "Kebumen", + "code": "05", + "full_code": "3305", + "province_id": 10 + }, + { + "id": 176, + "type": "Kabupaten", + "name": "Sragen", + "code": "14", + "full_code": "3314", + "province_id": 10 + }, + { + "id": 177, + "type": "Kabupaten", + "name": "Kediri", + "code": "06", + "full_code": "3506", + "province_id": 11 + }, + { + "id": 178, + "type": "Kabupaten", + "name": "Subang", + "code": "13", + "full_code": "3213", + "province_id": 9 + }, + { + "id": 179, + "type": "Kota", + "name": "Subulussalam", + "code": "75", + "full_code": "1175", + "province_id": 1 + }, + { + "id": 180, + "type": "Kota", + "name": "Sukabumi", + "code": "72", + "full_code": "3272", + "province_id": 9 + }, + { + "id": 181, + "type": "Kota", + "name": "Kediri", + "code": "71", + "full_code": "3571", + "province_id": 11 + }, + { + "id": 182, + "type": "Kabupaten", + "name": "Bone", + "code": "08", + "full_code": "7308", + "province_id": 32 + }, + { + "id": 183, + "type": "Kabupaten", + "name": "Keerom", + "code": "11", + "full_code": "9111", + "province_id": 24 + }, + { + "id": 184, + "type": "Kabupaten", + "name": "Sukabumi", + "code": "02", + "full_code": "3202", + "province_id": 9 + }, + { + "id": 185, + "type": "Kabupaten", + "name": "Bone Bolango", + "code": "03", + "full_code": "7503", + "province_id": 7 + }, + { + "id": 186, + "type": "Kabupaten", + "name": "Kendal", + "code": "24", + "full_code": "3324", + "province_id": 10 + }, + { + "id": 187, + "type": "Kota", + "name": "Bontang", + "code": "74", + "full_code": "6474", + "province_id": 15 + }, + { + "id": 188, + "type": "Kota", + "name": "Kendari", + "code": "71", + "full_code": "7471", + "province_id": 34 + }, + { + "id": 189, + "type": "Kabupaten", + "name": "Boven Digoel", + "code": "02", + "full_code": "9302", + "province_id": 28 + }, + { + "id": 190, + "type": "Kabupaten", + "name": "Kepahiang", + "code": "08", + "full_code": "1708", + "province_id": 4 + }, + { + "id": 191, + "type": "Kabupaten", + "name": "Boyolali", + "code": "09", + "full_code": "3309", + "province_id": 10 + }, + { + "id": 192, + "type": "Kabupaten", + "name": "Sukamara", + "code": "08", + "full_code": "6208", + "province_id": 14 + }, + { + "id": 193, + "type": "Kabupaten", + "name": "Kepulauan Anambas", + "code": "05", + "full_code": "2105", + "province_id": 18 + }, + { + "id": 194, + "type": "Kabupaten", + "name": "Sukoharjo", + "code": "11", + "full_code": "3311", + "province_id": 10 + }, + { + "id": 195, + "type": "Kabupaten", + "name": "Sumba Barat", + "code": "12", + "full_code": "5312", + "province_id": 23 + }, + { + "id": 196, + "type": "Kabupaten", + "name": "Brebes", + "code": "29", + "full_code": "3329", + "province_id": 10 + }, + { + "id": 197, + "type": "Kota", + "name": "Bukittinggi", + "code": "75", + "full_code": "1375", + "province_id": 36 + }, + { + "id": 198, + "type": "Kabupaten", + "name": "Buleleng", + "code": "08", + "full_code": "5108", + "province_id": 2 + }, + { + "id": 199, + "type": "Kabupaten", + "name": "Bulukumba", + "code": "02", + "full_code": "7302", + "province_id": 32 + }, + { + "id": 200, + "type": "Kabupaten", + "name": "Sumba Barat Daya", + "code": "18", + "full_code": "5318", + "province_id": 23 + }, + { + "id": 201, + "type": "Kabupaten", + "name": "Sumba Tengah", + "code": "17", + "full_code": "5317", + "province_id": 23 + }, + { + "id": 202, + "type": "Kabupaten", + "name": "Sumba Timur", + "code": "11", + "full_code": "5311", + "province_id": 23 + }, + { + "id": 203, + "type": "Kabupaten", + "name": "Bulungan", + "code": "01", + "full_code": "6501", + "province_id": 16 + }, + { + "id": 204, + "type": "Kabupaten", + "name": "Sumbawa", + "code": "04", + "full_code": "5204", + "province_id": 22 + }, + { + "id": 205, + "type": "Kabupaten", + "name": "Bungo", + "code": "08", + "full_code": "1508", + "province_id": 8 + }, + { + "id": 206, + "type": "Kabupaten", + "name": "Sumbawa Barat", + "code": "07", + "full_code": "5207", + "province_id": 22 + }, + { + "id": 207, + "type": "Kabupaten", + "name": "Buol", + "code": "05", + "full_code": "7205", + "province_id": 33 + }, + { + "id": 208, + "type": "Kabupaten", + "name": "Sumedang", + "code": "11", + "full_code": "3211", + "province_id": 9 + }, + { + "id": 209, + "type": "Kabupaten", + "name": "Buru", + "code": "04", + "full_code": "8104", + "province_id": 20 + }, + { + "id": 210, + "type": "Kabupaten", + "name": "Buru Selatan", + "code": "09", + "full_code": "8109", + "province_id": 20 + }, + { + "id": 211, + "type": "Kabupaten", + "name": "Kepulauan Aru", + "code": "07", + "full_code": "8107", + "province_id": 20 + }, + { + "id": 212, + "type": "Kabupaten", + "name": "Sumenep", + "code": "29", + "full_code": "3529", + "province_id": 11 + }, + { + "id": 213, + "type": "Kabupaten", + "name": "Buton", + "code": "04", + "full_code": "7404", + "province_id": 34 + }, + { + "id": 214, + "type": "Kota", + "name": "Sungai Penuh", + "code": "72", + "full_code": "1572", + "province_id": 8 + }, + { + "id": 215, + "type": "Kabupaten", + "name": "Buton Selatan", + "code": "15", + "full_code": "7415", + "province_id": 34 + }, + { + "id": 216, + "type": "Kabupaten", + "name": "Supiori", + "code": "19", + "full_code": "9119", + "province_id": 24 + }, + { + "id": 217, + "type": "Kabupaten", + "name": "Buton Tengah", + "code": "14", + "full_code": "7414", + "province_id": 34 + }, + { + "id": 218, + "type": "Kabupaten", + "name": "Buton Utara", + "code": "10", + "full_code": "7410", + "province_id": 34 + }, + { + "id": 219, + "type": "Kota", + "name": "Surabaya", + "code": "78", + "full_code": "3578", + "province_id": 11 + }, + { + "id": 220, + "type": "Kabupaten", + "name": "Kepulauan Mentawai", + "code": "09", + "full_code": "1309", + "province_id": 36 + }, + { + "id": 221, + "type": "Kabupaten", + "name": "Ciamis", + "code": "07", + "full_code": "3207", + "province_id": 9 + }, + { + "id": 222, + "type": "Kota", + "name": "Surakarta", + "code": "72", + "full_code": "3372", + "province_id": 10 + }, + { + "id": 223, + "type": "Kabupaten", + "name": "Kepulauan Meranti", + "code": "10", + "full_code": "1410", + "province_id": 30 + }, + { + "id": 224, + "type": "Kabupaten", + "name": "Cianjur", + "code": "03", + "full_code": "3203", + "province_id": 9 + }, + { + "id": 225, + "type": "Kabupaten", + "name": "Tabalong", + "code": "09", + "full_code": "6309", + "province_id": 13 + }, + { + "id": 226, + "type": "Kabupaten", + "name": "Kepulauan Sangihe", + "code": "03", + "full_code": "7103", + "province_id": 35 + }, + { + "id": 227, + "type": "Kabupaten", + "name": "Kepulauan Selayar", + "code": "01", + "full_code": "7301", + "province_id": 32 + }, + { + "id": 228, + "type": "Kabupaten", + "name": "Cilacap", + "code": "01", + "full_code": "3301", + "province_id": 10 + }, + { + "id": 229, + "type": "Kota", + "name": "Cilegon", + "code": "72", + "full_code": "3672", + "province_id": 3 + }, + { + "id": 230, + "type": "Kabupaten", + "name": "Tabanan", + "code": "02", + "full_code": "5102", + "province_id": 2 + }, + { + "id": 231, + "type": "Kota", + "name": "Cimahi", + "code": "77", + "full_code": "3277", + "province_id": 9 + }, + { + "id": 232, + "type": "Kabupaten", + "name": "Kepulauan Seribu", + "code": "01", + "full_code": "3101", + "province_id": 6 + }, + { + "id": 233, + "type": "Kabupaten", + "name": "Takalar", + "code": "05", + "full_code": "7305", + "province_id": 32 + }, + { + "id": 234, + "type": "Kota", + "name": "Cirebon", + "code": "74", + "full_code": "3274", + "province_id": 9 + }, + { + "id": 235, + "type": "Kabupaten", + "name": "Kepulauan Siau Tagulandang Biaro (Sitaro)", + "code": "09", + "full_code": "7109", + "province_id": 35 + }, + { + "id": 236, + "type": "Kabupaten", + "name": "Kepulauan Sula", + "code": "05", + "full_code": "8205", + "province_id": 21 + }, + { + "id": 237, + "type": "Kabupaten", + "name": "Tambrauw", + "code": "09", + "full_code": "9209", + "province_id": 26 + }, + { + "id": 238, + "type": "Kabupaten", + "name": "Kepulauan Talaud", + "code": "04", + "full_code": "7104", + "province_id": 35 + }, + { + "id": 239, + "type": "Kabupaten", + "name": "Kepulauan Tanimbar (Maluku Tenggara Barat)", + "code": "03", + "full_code": "8103", + "province_id": 20 + }, + { + "id": 240, + "type": "Kabupaten", + "name": "Cirebon", + "code": "09", + "full_code": "3209", + "province_id": 9 + }, + { + "id": 241, + "type": "Kabupaten", + "name": "Dairi", + "code": "11", + "full_code": "1211", + "province_id": 38 + }, + { + "id": 242, + "type": "Kabupaten", + "name": "Tana Tidung", + "code": "04", + "full_code": "6504", + "province_id": 16 + }, + { + "id": 243, + "type": "Kabupaten", + "name": "Deiyai", + "code": "08", + "full_code": "9408", + "province_id": 29 + }, + { + "id": 244, + "type": "Kabupaten", + "name": "Kepulauan Yapen", + "code": "05", + "full_code": "9105", + "province_id": 24 + }, + { + "id": 245, + "type": "Kabupaten", + "name": "Deli Serdang", + "code": "07", + "full_code": "1207", + "province_id": 38 + }, + { + "id": 246, + "type": "Kabupaten", + "name": "Tana Toraja", + "code": "18", + "full_code": "7318", + "province_id": 32 + }, + { + "id": 247, + "type": "Kabupaten", + "name": "Demak", + "code": "21", + "full_code": "3321", + "province_id": 10 + }, + { + "id": 248, + "type": "Kabupaten", + "name": "Kerinci", + "code": "01", + "full_code": "1501", + "province_id": 8 + }, + { + "id": 249, + "type": "Kabupaten", + "name": "Tanah Bumbu", + "code": "10", + "full_code": "6310", + "province_id": 13 + }, + { + "id": 250, + "type": "Kota", + "name": "Denpasar", + "code": "71", + "full_code": "5171", + "province_id": 2 + }, + { + "id": 251, + "type": "Kabupaten", + "name": "Ketapang", + "code": "04", + "full_code": "6104", + "province_id": 12 + }, + { + "id": 252, + "type": "Kota", + "name": "Depok", + "code": "76", + "full_code": "3276", + "province_id": 9 + }, + { + "id": 253, + "type": "Kabupaten", + "name": "Tanah Datar", + "code": "04", + "full_code": "1304", + "province_id": 36 + }, + { + "id": 254, + "type": "Kabupaten", + "name": "Klaten", + "code": "10", + "full_code": "3310", + "province_id": 10 + }, + { + "id": 255, + "type": "Kabupaten", + "name": "Dharmasraya", + "code": "10", + "full_code": "1310", + "province_id": 36 + }, + { + "id": 256, + "type": "Kabupaten", + "name": "Tanah Laut", + "code": "01", + "full_code": "6301", + "province_id": 13 + }, + { + "id": 257, + "type": "Kabupaten", + "name": "Dogiyai", + "code": "06", + "full_code": "9406", + "province_id": 29 + }, + { + "id": 258, + "type": "Kabupaten", + "name": "Klungkung", + "code": "05", + "full_code": "5105", + "province_id": 2 + }, + { + "id": 259, + "type": "Kabupaten", + "name": "Kolaka", + "code": "01", + "full_code": "7401", + "province_id": 34 + }, + { + "id": 260, + "type": "Kota", + "name": "Tangerang", + "code": "71", + "full_code": "3671", + "province_id": 3 + }, + { + "id": 261, + "type": "Kabupaten", + "name": "Kolaka Timur", + "code": "11", + "full_code": "7411", + "province_id": 34 + }, + { + "id": 262, + "type": "Kabupaten", + "name": "Tangerang", + "code": "03", + "full_code": "3603", + "province_id": 3 + }, + { + "id": 263, + "type": "Kota", + "name": "Tangerang Selatan", + "code": "74", + "full_code": "3674", + "province_id": 3 + }, + { + "id": 264, + "type": "Kabupaten", + "name": "Tanggamus", + "code": "06", + "full_code": "1806", + "province_id": 19 + }, + { + "id": 265, + "type": "Kabupaten", + "name": "Kolaka Utara", + "code": "08", + "full_code": "7408", + "province_id": 34 + }, + { + "id": 266, + "type": "Kabupaten", + "name": "Konawe", + "code": "02", + "full_code": "7402", + "province_id": 34 + }, + { + "id": 267, + "type": "Kabupaten", + "name": "Konawe Kepulauan", + "code": "12", + "full_code": "7412", + "province_id": 34 + }, + { + "id": 268, + "type": "Kota", + "name": "Tanjung Balai", + "code": "74", + "full_code": "1274", + "province_id": 38 + }, + { + "id": 269, + "type": "Kabupaten", + "name": "Konawe Selatan", + "code": "05", + "full_code": "7405", + "province_id": 34 + }, + { + "id": 270, + "type": "Kabupaten", + "name": "Konawe Utara", + "code": "09", + "full_code": "7409", + "province_id": 34 + }, + { + "id": 271, + "type": "Kabupaten", + "name": "Kotabaru", + "code": "02", + "full_code": "6302", + "province_id": 13 + }, + { + "id": 272, + "type": "Kabupaten", + "name": "Tanjung Jabung Barat", + "code": "06", + "full_code": "1506", + "province_id": 8 + }, + { + "id": 273, + "type": "Kota", + "name": "Kotamobagu", + "code": "74", + "full_code": "7174", + "province_id": 35 + }, + { + "id": 274, + "type": "Kabupaten", + "name": "Tanjung Jabung Timur", + "code": "07", + "full_code": "1507", + "province_id": 8 + }, + { + "id": 275, + "type": "Kabupaten", + "name": "Kotawaringin Barat", + "code": "01", + "full_code": "6201", + "province_id": 14 + }, + { + "id": 276, + "type": "Kabupaten", + "name": "Kotawaringin Timur", + "code": "02", + "full_code": "6202", + "province_id": 14 + }, + { + "id": 277, + "type": "Kota", + "name": "Tanjung Pinang", + "code": "72", + "full_code": "2172", + "province_id": 18 + }, + { + "id": 278, + "type": "Kabupaten", + "name": "Kuantan Singingi", + "code": "09", + "full_code": "1409", + "province_id": 30 + }, + { + "id": 279, + "type": "Kabupaten", + "name": "Tapanuli Selatan", + "code": "03", + "full_code": "1203", + "province_id": 38 + }, + { + "id": 280, + "type": "Kabupaten", + "name": "Kubu Raya", + "code": "12", + "full_code": "6112", + "province_id": 12 + }, + { + "id": 281, + "type": "Kabupaten", + "name": "Kudus", + "code": "19", + "full_code": "3319", + "province_id": 10 + }, + { + "id": 282, + "type": "Kabupaten", + "name": "Tapanuli Tengah", + "code": "01", + "full_code": "1201", + "province_id": 38 + }, + { + "id": 283, + "type": "Kabupaten", + "name": "Tapanuli Utara", + "code": "02", + "full_code": "1202", + "province_id": 38 + }, + { + "id": 284, + "type": "Kabupaten", + "name": "Tapin", + "code": "05", + "full_code": "6305", + "province_id": 13 + }, + { + "id": 285, + "type": "Kota", + "name": "Tarakan", + "code": "71", + "full_code": "6571", + "province_id": 16 + }, + { + "id": 286, + "type": "Kota", + "name": "Tasikmalaya", + "code": "78", + "full_code": "3278", + "province_id": 9 + }, + { + "id": 287, + "type": "Kabupaten", + "name": "Kulon Progo", + "code": "01", + "full_code": "3401", + "province_id": 5 + }, + { + "id": 288, + "type": "Kabupaten", + "name": "Kuningan", + "code": "08", + "full_code": "3208", + "province_id": 9 + }, + { + "id": 289, + "type": "Kabupaten", + "name": "Kupang", + "code": "01", + "full_code": "5301", + "province_id": 23 + }, + { + "id": 290, + "type": "Kota", + "name": "Kupang", + "code": "71", + "full_code": "5371", + "province_id": 23 + }, + { + "id": 291, + "type": "Kabupaten", + "name": "Tasikmalaya", + "code": "06", + "full_code": "3206", + "province_id": 9 + }, + { + "id": 292, + "type": "Kabupaten", + "name": "Kutai Barat", + "code": "07", + "full_code": "6407", + "province_id": 15 + }, + { + "id": 293, + "type": "Kabupaten", + "name": "Kutai Kartanegara", + "code": "02", + "full_code": "6402", + "province_id": 15 + }, + { + "id": 294, + "type": "Kabupaten", + "name": "Kutai Timur", + "code": "08", + "full_code": "6408", + "province_id": 15 + }, + { + "id": 295, + "type": "Kabupaten", + "name": "Labuhanbatu", + "code": "10", + "full_code": "1210", + "province_id": 38 + }, + { + "id": 296, + "type": "Kota", + "name": "Tebing Tinggi", + "code": "76", + "full_code": "1276", + "province_id": 38 + }, + { + "id": 297, + "type": "Kabupaten", + "name": "Labuhanbatu Selatan", + "code": "22", + "full_code": "1222", + "province_id": 38 + }, + { + "id": 298, + "type": "Kabupaten", + "name": "Tebo", + "code": "09", + "full_code": "1509", + "province_id": 8 + }, + { + "id": 299, + "type": "Kabupaten", + "name": "Tegal", + "code": "28", + "full_code": "3328", + "province_id": 10 + }, + { + "id": 300, + "type": "Kota", + "name": "Tegal", + "code": "76", + "full_code": "3376", + "province_id": 10 + }, + { + "id": 301, + "type": "Kabupaten", + "name": "Teluk Bintuni", + "code": "06", + "full_code": "9206", + "province_id": 25 + }, + { + "id": 302, + "type": "Kabupaten", + "name": "Teluk Wondama", + "code": "07", + "full_code": "9207", + "province_id": 25 + }, + { + "id": 303, + "type": "Kabupaten", + "name": "Labuhanbatu Utara", + "code": "23", + "full_code": "1223", + "province_id": 38 + }, + { + "id": 304, + "type": "Kabupaten", + "name": "Temanggung", + "code": "23", + "full_code": "3323", + "province_id": 10 + }, + { + "id": 305, + "type": "Kabupaten", + "name": "Lahat", + "code": "04", + "full_code": "1604", + "province_id": 37 + }, + { + "id": 306, + "type": "Kota", + "name": "Ternate", + "code": "71", + "full_code": "8271", + "province_id": 21 + }, + { + "id": 307, + "type": "Kabupaten", + "name": "Lamandau", + "code": "09", + "full_code": "6209", + "province_id": 14 + }, + { + "id": 308, + "type": "Kabupaten", + "name": "Dompu", + "code": "05", + "full_code": "5205", + "province_id": 22 + }, + { + "id": 309, + "type": "Kabupaten", + "name": "Donggala", + "code": "03", + "full_code": "7203", + "province_id": 33 + }, + { + "id": 310, + "type": "Kota", + "name": "Dumai", + "code": "72", + "full_code": "1472", + "province_id": 30 + }, + { + "id": 311, + "type": "Kabupaten", + "name": "Empat Lawang", + "code": "11", + "full_code": "1611", + "province_id": 37 + }, + { + "id": 312, + "type": "Kabupaten", + "name": "Lamongan", + "code": "24", + "full_code": "3524", + "province_id": 11 + }, + { + "id": 313, + "type": "Kabupaten", + "name": "Ende", + "code": "08", + "full_code": "5308", + "province_id": 23 + }, + { + "id": 314, + "type": "Kabupaten", + "name": "Lampung Barat", + "code": "04", + "full_code": "1804", + "province_id": 19 + }, + { + "id": 315, + "type": "Kota", + "name": "Tidore Kepulauan", + "code": "72", + "full_code": "8272", + "province_id": 21 + }, + { + "id": 316, + "type": "Kabupaten", + "name": "Enrekang", + "code": "16", + "full_code": "7316", + "province_id": 32 + }, + { + "id": 317, + "type": "Kabupaten", + "name": "Lampung Selatan", + "code": "01", + "full_code": "1801", + "province_id": 19 + }, + { + "id": 318, + "type": "Kabupaten", + "name": "Fak Fak", + "code": "03", + "full_code": "9203", + "province_id": 25 + }, + { + "id": 319, + "type": "Kabupaten", + "name": "Timor Tengah Selatan", + "code": "02", + "full_code": "5302", + "province_id": 23 + }, + { + "id": 320, + "type": "Kabupaten", + "name": "Lampung Tengah", + "code": "02", + "full_code": "1802", + "province_id": 19 + }, + { + "id": 321, + "type": "Kabupaten", + "name": "Flores Timur", + "code": "06", + "full_code": "5306", + "province_id": 23 + }, + { + "id": 322, + "type": "Kabupaten", + "name": "Lampung Timur", + "code": "07", + "full_code": "1807", + "province_id": 19 + }, + { + "id": 323, + "type": "Kabupaten", + "name": "Garut", + "code": "05", + "full_code": "3205", + "province_id": 9 + }, + { + "id": 324, + "type": "Kabupaten", + "name": "Timor Tengah Utara", + "code": "03", + "full_code": "5303", + "province_id": 23 + }, + { + "id": 325, + "type": "Kabupaten", + "name": "Lampung Utara", + "code": "03", + "full_code": "1803", + "province_id": 19 + }, + { + "id": 326, + "type": "Kabupaten", + "name": "Toba", + "code": "12", + "full_code": "1212", + "province_id": 38 + }, + { + "id": 327, + "type": "Kabupaten", + "name": "Tojo Una Una", + "code": "09", + "full_code": "7209", + "province_id": 33 + }, + { + "id": 328, + "type": "Kabupaten", + "name": "Gayo Lues", + "code": "13", + "full_code": "1113", + "province_id": 1 + }, + { + "id": 329, + "type": "Kabupaten", + "name": "Landak", + "code": "08", + "full_code": "6108", + "province_id": 12 + }, + { + "id": 330, + "type": "Kabupaten", + "name": "Gianyar", + "code": "04", + "full_code": "5104", + "province_id": 2 + }, + { + "id": 331, + "type": "Kabupaten", + "name": "Langkat", + "code": "05", + "full_code": "1205", + "province_id": 38 + }, + { + "id": 332, + "type": "Kabupaten", + "name": "Gorontalo", + "code": "01", + "full_code": "7501", + "province_id": 7 + }, + { + "id": 333, + "type": "Kota", + "name": "Langsa", + "code": "74", + "full_code": "1174", + "province_id": 1 + }, + { + "id": 334, + "type": "Kabupaten", + "name": "Toli Toli", + "code": "04", + "full_code": "7204", + "province_id": 33 + }, + { + "id": 335, + "type": "Kabupaten", + "name": "Lanny Jaya", + "code": "07", + "full_code": "9507", + "province_id": 27 + }, + { + "id": 336, + "type": "Kabupaten", + "name": "Lebak", + "code": "02", + "full_code": "3602", + "province_id": 3 + }, + { + "id": 337, + "type": "Kota", + "name": "Gorontalo", + "code": "71", + "full_code": "7571", + "province_id": 7 + }, + { + "id": 338, + "type": "Kabupaten", + "name": "Tolikara", + "code": "04", + "full_code": "9504", + "province_id": 27 + }, + { + "id": 339, + "type": "Kota", + "name": "Tomohon", + "code": "73", + "full_code": "7173", + "province_id": 35 + }, + { + "id": 340, + "type": "Kabupaten", + "name": "Lebong", + "code": "07", + "full_code": "1707", + "province_id": 4 + }, + { + "id": 341, + "type": "Kabupaten", + "name": "Toraja Utara", + "code": "26", + "full_code": "7326", + "province_id": 32 + }, + { + "id": 342, + "type": "Kabupaten", + "name": "Lembata", + "code": "13", + "full_code": "5313", + "province_id": 23 + }, + { + "id": 343, + "type": "Kota", + "name": "Lhokseumawe", + "code": "73", + "full_code": "1173", + "province_id": 1 + }, + { + "id": 344, + "type": "Kabupaten", + "name": "Lima Puluh Kota", + "code": "07", + "full_code": "1307", + "province_id": 36 + }, + { + "id": 345, + "type": "Kabupaten", + "name": "Lingga", + "code": "04", + "full_code": "2104", + "province_id": 18 + }, + { + "id": 346, + "type": "Kabupaten", + "name": "Trenggalek", + "code": "03", + "full_code": "3503", + "province_id": 11 + }, + { + "id": 347, + "type": "Kota", + "name": "Tual", + "code": "72", + "full_code": "8172", + "province_id": 20 + }, + { + "id": 348, + "type": "Kabupaten", + "name": "Tuban", + "code": "23", + "full_code": "3523", + "province_id": 11 + }, + { + "id": 349, + "type": "Kabupaten", + "name": "Lombok Barat", + "code": "01", + "full_code": "5201", + "province_id": 22 + }, + { + "id": 350, + "type": "Kabupaten", + "name": "Tulang Bawang", + "code": "05", + "full_code": "1805", + "province_id": 19 + }, + { + "id": 351, + "type": "Kabupaten", + "name": "Lombok Tengah", + "code": "02", + "full_code": "5202", + "province_id": 22 + }, + { + "id": 352, + "type": "Kabupaten", + "name": "Lombok Timur", + "code": "03", + "full_code": "5203", + "province_id": 22 + }, + { + "id": 353, + "type": "Kabupaten", + "name": "Tulang Bawang Barat", + "code": "12", + "full_code": "1812", + "province_id": 19 + }, + { + "id": 354, + "type": "Kabupaten", + "name": "Lombok Utara", + "code": "08", + "full_code": "5208", + "province_id": 22 + }, + { + "id": 355, + "type": "Kota", + "name": "Lubuk Linggau", + "code": "73", + "full_code": "1673", + "province_id": 37 + }, + { + "id": 356, + "type": "Kabupaten", + "name": "Tulungagung", + "code": "04", + "full_code": "3504", + "province_id": 11 + }, + { + "id": 357, + "type": "Kabupaten", + "name": "Lumajang", + "code": "08", + "full_code": "3508", + "province_id": 11 + }, + { + "id": 358, + "type": "Kabupaten", + "name": "Wajo", + "code": "13", + "full_code": "7313", + "province_id": 32 + }, + { + "id": 359, + "type": "Kabupaten", + "name": "Luwu", + "code": "17", + "full_code": "7317", + "province_id": 32 + }, + { + "id": 360, + "type": "Kabupaten", + "name": "Luwu Timur", + "code": "24", + "full_code": "7324", + "province_id": 32 + }, + { + "id": 361, + "type": "Kabupaten", + "name": "Wakatobi", + "code": "07", + "full_code": "7407", + "province_id": 34 + }, + { + "id": 362, + "type": "Kabupaten", + "name": "Waropen", + "code": "15", + "full_code": "9115", + "province_id": 24 + }, + { + "id": 363, + "type": "Kabupaten", + "name": "Way Kanan", + "code": "08", + "full_code": "1808", + "province_id": 19 + }, + { + "id": 364, + "type": "Kabupaten", + "name": "Wonogiri", + "code": "12", + "full_code": "3312", + "province_id": 10 + }, + { + "id": 365, + "type": "Kabupaten", + "name": "Wonosobo", + "code": "07", + "full_code": "3307", + "province_id": 10 + }, + { + "id": 366, + "type": "Kabupaten", + "name": "Yahukimo", + "code": "03", + "full_code": "9503", + "province_id": 27 + }, + { + "id": 367, + "type": "Kabupaten", + "name": "Yalimo", + "code": "06", + "full_code": "9506", + "province_id": 27 + }, + { + "id": 368, + "type": "Kota", + "name": "Yogyakarta", + "code": "71", + "full_code": "3471", + "province_id": 5 + }, + { + "id": 369, + "type": "Kabupaten", + "name": "Luwu Utara", + "code": "22", + "full_code": "7322", + "province_id": 32 + }, + { + "id": 370, + "type": "Kabupaten", + "name": "Madiun", + "code": "19", + "full_code": "3519", + "province_id": 11 + }, + { + "id": 371, + "type": "Kota", + "name": "Madiun", + "code": "77", + "full_code": "3577", + "province_id": 11 + }, + { + "id": 372, + "type": "Kabupaten", + "name": "Magelang", + "code": "08", + "full_code": "3308", + "province_id": 10 + }, + { + "id": 373, + "type": "Kota", + "name": "Magelang", + "code": "71", + "full_code": "3371", + "province_id": 10 + }, + { + "id": 374, + "type": "Kabupaten", + "name": "Magetan", + "code": "20", + "full_code": "3520", + "province_id": 11 + }, + { + "id": 375, + "type": "Kabupaten", + "name": "Mahakam Ulu", + "code": "11", + "full_code": "6411", + "province_id": 15 + }, + { + "id": 376, + "type": "Kabupaten", + "name": "Majalengka", + "code": "10", + "full_code": "3210", + "province_id": 9 + }, + { + "id": 377, + "type": "Kabupaten", + "name": "Majene", + "code": "05", + "full_code": "7605", + "province_id": 31 + }, + { + "id": 378, + "type": "Kota", + "name": "Makassar", + "code": "71", + "full_code": "7371", + "province_id": 32 + }, + { + "id": 379, + "type": "Kabupaten", + "name": "Malaka", + "code": "21", + "full_code": "5321", + "province_id": 23 + }, + { + "id": 380, + "type": "Kabupaten", + "name": "Malang", + "code": "07", + "full_code": "3507", + "province_id": 11 + }, + { + "id": 381, + "type": "Kota", + "name": "Malang", + "code": "73", + "full_code": "3573", + "province_id": 11 + }, + { + "id": 382, + "type": "Kabupaten", + "name": "Malinau", + "code": "02", + "full_code": "6502", + "province_id": 16 + }, + { + "id": 383, + "type": "Kabupaten", + "name": "Maluku Barat Daya", + "code": "08", + "full_code": "8108", + "province_id": 20 + }, + { + "id": 384, + "type": "Kabupaten", + "name": "Maluku Tengah", + "code": "01", + "full_code": "8101", + "province_id": 20 + }, + { + "id": 385, + "type": "Kabupaten", + "name": "Maluku Tenggara", + "code": "02", + "full_code": "8102", + "province_id": 20 + }, + { + "id": 386, + "type": "Kabupaten", + "name": "Mamasa", + "code": "03", + "full_code": "7603", + "province_id": 31 + }, + { + "id": 387, + "type": "Kabupaten", + "name": "Mamberamo Raya", + "code": "20", + "full_code": "9120", + "province_id": 24 + }, + { + "id": 388, + "type": "Kabupaten", + "name": "Mamberamo Tengah", + "code": "05", + "full_code": "9505", + "province_id": 27 + }, + { + "id": 389, + "type": "Kabupaten", + "name": "Mamuju", + "code": "02", + "full_code": "7602", + "province_id": 31 + }, + { + "id": 390, + "type": "Kabupaten", + "name": "Mamuju Tengah", + "code": "06", + "full_code": "7606", + "province_id": 31 + }, + { + "id": 391, + "type": "Kota", + "name": "Manado", + "code": "71", + "full_code": "7171", + "province_id": 35 + }, + { + "id": 392, + "type": "Kabupaten", + "name": "Mandailing Natal", + "code": "13", + "full_code": "1213", + "province_id": 38 + }, + { + "id": 393, + "type": "Kabupaten", + "name": "Manggarai", + "code": "10", + "full_code": "5310", + "province_id": 23 + }, + { + "id": 394, + "type": "Kabupaten", + "name": "Manggarai Barat", + "code": "15", + "full_code": "5315", + "province_id": 23 + }, + { + "id": 395, + "type": "Kabupaten", + "name": "Manggarai Timur", + "code": "19", + "full_code": "5319", + "province_id": 23 + }, + { + "id": 396, + "type": "Kabupaten", + "name": "Manokwari", + "code": "02", + "full_code": "9202", + "province_id": 25 + }, + { + "id": 397, + "type": "Kabupaten", + "name": "Manokwari Selatan", + "code": "11", + "full_code": "9211", + "province_id": 25 + }, + { + "id": 398, + "type": "Kabupaten", + "name": "Mappi", + "code": "03", + "full_code": "9303", + "province_id": 28 + }, + { + "id": 399, + "type": "Kabupaten", + "name": "Maros", + "code": "09", + "full_code": "7309", + "province_id": 32 + }, + { + "id": 400, + "type": "Kota", + "name": "Mataram", + "code": "71", + "full_code": "5271", + "province_id": 22 + }, + { + "id": 401, + "type": "Kabupaten", + "name": "Maybrat", + "code": "10", + "full_code": "9210", + "province_id": 26 + }, + { + "id": 402, + "type": "Kota", + "name": "Medan", + "code": "71", + "full_code": "1271", + "province_id": 38 + }, + { + "id": 403, + "type": "Kabupaten", + "name": "Melawi", + "code": "10", + "full_code": "6110", + "province_id": 12 + }, + { + "id": 404, + "type": "Kabupaten", + "name": "Mempawah", + "code": "02", + "full_code": "6102", + "province_id": 12 + }, + { + "id": 405, + "type": "Kabupaten", + "name": "Merangin", + "code": "02", + "full_code": "1502", + "province_id": 8 + }, + { + "id": 406, + "type": "Kabupaten", + "name": "Merauke", + "code": "01", + "full_code": "9301", + "province_id": 28 + }, + { + "id": 407, + "type": "Kabupaten", + "name": "Mesuji", + "code": "11", + "full_code": "1811", + "province_id": 19 + }, + { + "id": 408, + "type": "Kota", + "name": "Metro", + "code": "72", + "full_code": "1872", + "province_id": 19 + }, + { + "id": 409, + "type": "Kabupaten", + "name": "Mimika", + "code": "04", + "full_code": "9404", + "province_id": 29 + }, + { + "id": 410, + "type": "Kabupaten", + "name": "Minahasa", + "code": "02", + "full_code": "7102", + "province_id": 35 + }, + { + "id": 411, + "type": "Kabupaten", + "name": "Minahasa Selatan", + "code": "05", + "full_code": "7105", + "province_id": 35 + }, + { + "id": 412, + "type": "Kabupaten", + "name": "Minahasa Tenggara", + "code": "07", + "full_code": "7107", + "province_id": 35 + }, + { + "id": 413, + "type": "Kabupaten", + "name": "Minahasa Utara", + "code": "06", + "full_code": "7106", + "province_id": 35 + }, + { + "id": 414, + "type": "Kabupaten", + "name": "Mojokerto", + "code": "16", + "full_code": "3516", + "province_id": 11 + }, + { + "id": 415, + "type": "Kota", + "name": "Mojokerto", + "code": "76", + "full_code": "3576", + "province_id": 11 + }, + { + "id": 416, + "type": "Kabupaten", + "name": "Morowali", + "code": "06", + "full_code": "7206", + "province_id": 33 + }, + { + "id": 417, + "type": "Kabupaten", + "name": "Morowali Utara", + "code": "12", + "full_code": "7212", + "province_id": 33 + }, + { + "id": 418, + "type": "Kabupaten", + "name": "Muara Enim", + "code": "03", + "full_code": "1603", + "province_id": 37 + }, + { + "id": 419, + "type": "Kabupaten", + "name": "Muaro Jambi", + "code": "05", + "full_code": "1505", + "province_id": 8 + }, + { + "id": 420, + "type": "Kabupaten", + "name": "Muko Muko", + "code": "06", + "full_code": "1706", + "province_id": 4 + }, + { + "id": 421, + "type": "Kabupaten", + "name": "Muna", + "code": "03", + "full_code": "7403", + "province_id": 34 + }, + { + "id": 422, + "type": "Kabupaten", + "name": "Muna Barat", + "code": "13", + "full_code": "7413", + "province_id": 34 + }, + { + "id": 423, + "type": "Kabupaten", + "name": "Murung Raya", + "code": "12", + "full_code": "6212", + "province_id": 14 + }, + { + "id": 424, + "type": "Kabupaten", + "name": "Musi Banyuasin", + "code": "06", + "full_code": "1606", + "province_id": 37 + }, + { + "id": 425, + "type": "Kabupaten", + "name": "Musi Rawas", + "code": "05", + "full_code": "1605", + "province_id": 37 + }, + { + "id": 426, + "type": "Kabupaten", + "name": "Musi Rawas Utara", + "code": "13", + "full_code": "1613", + "province_id": 37 + }, + { + "id": 427, + "type": "Kabupaten", + "name": "Nabire", + "code": "01", + "full_code": "9401", + "province_id": 29 + }, + { + "id": 428, + "type": "Kabupaten", + "name": "Nagan Raya", + "code": "15", + "full_code": "1115", + "province_id": 1 + }, + { + "id": 429, + "type": "Kabupaten", + "name": "Nagekeo", + "code": "16", + "full_code": "5316", + "province_id": 23 + }, + { + "id": 430, + "type": "Kabupaten", + "name": "Natuna", + "code": "03", + "full_code": "2103", + "province_id": 18 + }, + { + "id": 431, + "type": "Kabupaten", + "name": "Nduga", + "code": "08", + "full_code": "9508", + "province_id": 27 + }, + { + "id": 432, + "type": "Kabupaten", + "name": "Ngada", + "code": "09", + "full_code": "5309", + "province_id": 23 + }, + { + "id": 433, + "type": "Kabupaten", + "name": "Nganjuk", + "code": "18", + "full_code": "3518", + "province_id": 11 + }, + { + "id": 434, + "type": "Kabupaten", + "name": "Ngawi", + "code": "21", + "full_code": "3521", + "province_id": 11 + }, + { + "id": 435, + "type": "Kabupaten", + "name": "Nias", + "code": "04", + "full_code": "1204", + "province_id": 38 + }, + { + "id": 436, + "type": "Kabupaten", + "name": "Nias Barat", + "code": "25", + "full_code": "1225", + "province_id": 38 + }, + { + "id": 437, + "type": "Kabupaten", + "name": "Nias Selatan", + "code": "14", + "full_code": "1214", + "province_id": 38 + }, + { + "id": 438, + "type": "Kabupaten", + "name": "Nias Utara", + "code": "24", + "full_code": "1224", + "province_id": 38 + }, + { + "id": 439, + "type": "Kabupaten", + "name": "Nunukan", + "code": "03", + "full_code": "6503", + "province_id": 16 + }, + { + "id": 440, + "type": "Kabupaten", + "name": "Ogan Ilir", + "code": "10", + "full_code": "1610", + "province_id": 37 + }, + { + "id": 441, + "type": "Kabupaten", + "name": "Ogan Komering Ilir", + "code": "02", + "full_code": "1602", + "province_id": 37 + }, + { + "id": 442, + "type": "Kabupaten", + "name": "Ogan Komering Ulu", + "code": "01", + "full_code": "1601", + "province_id": 37 + }, + { + "id": 443, + "type": "Kabupaten", + "name": "Ogan Komering Ulu Selatan", + "code": "09", + "full_code": "1609", + "province_id": 37 + }, + { + "id": 444, + "type": "Kabupaten", + "name": "Ogan Komering Ulu Timur", + "code": "08", + "full_code": "1608", + "province_id": 37 + }, + { + "id": 445, + "type": "Kabupaten", + "name": "Pacitan", + "code": "01", + "full_code": "3501", + "province_id": 11 + }, + { + "id": 446, + "type": "Kota", + "name": "Padang", + "code": "71", + "full_code": "1371", + "province_id": 36 + }, + { + "id": 447, + "type": "Kabupaten", + "name": "Padang Lawas", + "code": "21", + "full_code": "1221", + "province_id": 38 + }, + { + "id": 448, + "type": "Kabupaten", + "name": "Padang Lawas Utara", + "code": "20", + "full_code": "1220", + "province_id": 38 + }, + { + "id": 449, + "type": "Kota", + "name": "Padang Panjang", + "code": "74", + "full_code": "1374", + "province_id": 36 + }, + { + "id": 450, + "type": "Kabupaten", + "name": "Padang Pariaman", + "code": "05", + "full_code": "1305", + "province_id": 36 + }, + { + "id": 451, + "type": "Kota", + "name": "Padangsidimpuan", + "code": "77", + "full_code": "1277", + "province_id": 38 + }, + { + "id": 452, + "type": "Kota", + "name": "Pagar Alam", + "code": "72", + "full_code": "1672", + "province_id": 37 + }, + { + "id": 453, + "type": "Kabupaten", + "name": "Pahuwato", + "code": "04", + "full_code": "7504", + "province_id": 7 + }, + { + "id": 454, + "type": "Kabupaten", + "name": "Pakpak Bharat", + "code": "15", + "full_code": "1215", + "province_id": 38 + }, + { + "id": 455, + "type": "Kota", + "name": "Palangkaraya", + "code": "71", + "full_code": "6271", + "province_id": 14 + }, + { + "id": 456, + "type": "Kota", + "name": "Palembang", + "code": "71", + "full_code": "1671", + "province_id": 37 + }, + { + "id": 457, + "type": "Kota", + "name": "Palopo", + "code": "73", + "full_code": "7373", + "province_id": 32 + }, + { + "id": 458, + "type": "Kota", + "name": "Palu", + "code": "71", + "full_code": "7271", + "province_id": 33 + }, + { + "id": 459, + "type": "Kabupaten", + "name": "Pamekasan", + "code": "28", + "full_code": "3528", + "province_id": 11 + }, + { + "id": 460, + "type": "Kabupaten", + "name": "Pandeglang", + "code": "01", + "full_code": "3601", + "province_id": 3 + }, + { + "id": 461, + "type": "Kabupaten", + "name": "Pangandaran", + "code": "18", + "full_code": "3218", + "province_id": 9 + }, + { + "id": 462, + "type": "Kabupaten", + "name": "Pangkajene Kepulauan", + "code": "10", + "full_code": "7310", + "province_id": 32 + }, + { + "id": 463, + "type": "Kota", + "name": "Pangkal Pinang", + "code": "71", + "full_code": "1971", + "province_id": 17 + }, + { + "id": 464, + "type": "Kabupaten", + "name": "Paniai", + "code": "03", + "full_code": "9403", + "province_id": 29 + }, + { + "id": 465, + "type": "Kota", + "name": "Pare Pare", + "code": "72", + "full_code": "7372", + "province_id": 32 + }, + { + "id": 466, + "type": "Kota", + "name": "Pariaman", + "code": "77", + "full_code": "1377", + "province_id": 36 + }, + { + "id": 467, + "type": "Kabupaten", + "name": "Parigi Moutong", + "code": "08", + "full_code": "7208", + "province_id": 33 + }, + { + "id": 468, + "type": "Kabupaten", + "name": "Pasaman", + "code": "08", + "full_code": "1308", + "province_id": 36 + }, + { + "id": 469, + "type": "Kabupaten", + "name": "Pasaman Barat", + "code": "12", + "full_code": "1312", + "province_id": 36 + }, + { + "id": 470, + "type": "Kabupaten", + "name": "Pasangkayu (Mamuju Utara)", + "code": "01", + "full_code": "7601", + "province_id": 31 + }, + { + "id": 471, + "type": "Kabupaten", + "name": "Paser", + "code": "01", + "full_code": "6401", + "province_id": 15 + }, + { + "id": 472, + "type": "Kabupaten", + "name": "Pasuruan", + "code": "14", + "full_code": "3514", + "province_id": 11 + }, + { + "id": 473, + "type": "Kota", + "name": "Pasuruan", + "code": "75", + "full_code": "3575", + "province_id": 11 + }, + { + "id": 474, + "type": "Kabupaten", + "name": "Pati", + "code": "18", + "full_code": "3318", + "province_id": 10 + }, + { + "id": 475, + "type": "Kota", + "name": "Payakumbuh", + "code": "76", + "full_code": "1376", + "province_id": 36 + }, + { + "id": 476, + "type": "Kabupaten", + "name": "Pegunungan Arfak", + "code": "12", + "full_code": "9212", + "province_id": 25 + }, + { + "id": 477, + "type": "Kabupaten", + "name": "Pegunungan Bintang", + "code": "02", + "full_code": "9502", + "province_id": 27 + }, + { + "id": 478, + "type": "Kabupaten", + "name": "Pekalongan", + "code": "26", + "full_code": "3326", + "province_id": 10 + }, + { + "id": 479, + "type": "Kota", + "name": "Pekalongan", + "code": "75", + "full_code": "3375", + "province_id": 10 + }, + { + "id": 480, + "type": "Kota", + "name": "Pekanbaru", + "code": "71", + "full_code": "1471", + "province_id": 30 + }, + { + "id": 481, + "type": "Kabupaten", + "name": "Pelalawan", + "code": "05", + "full_code": "1405", + "province_id": 30 + }, + { + "id": 482, + "type": "Kabupaten", + "name": "Pemalang", + "code": "27", + "full_code": "3327", + "province_id": 10 + }, + { + "id": 483, + "type": "Kota", + "name": "Pematangsiantar", + "code": "72", + "full_code": "1272", + "province_id": 38 + }, + { + "id": 484, + "type": "Kabupaten", + "name": "Penajam Paser Utara", + "code": "09", + "full_code": "6409", + "province_id": 15 + }, + { + "id": 485, + "type": "Kabupaten", + "name": "Penukal Abab Lematang Ilir", + "code": "12", + "full_code": "1612", + "province_id": 37 + }, + { + "id": 486, + "type": "Kabupaten", + "name": "Pesawaran", + "code": "09", + "full_code": "1809", + "province_id": 19 + }, + { + "id": 487, + "type": "Kabupaten", + "name": "Pesisir Barat", + "code": "13", + "full_code": "1813", + "province_id": 19 + }, + { + "id": 488, + "type": "Kabupaten", + "name": "Pesisir Selatan", + "code": "01", + "full_code": "1301", + "province_id": 36 + }, + { + "id": 489, + "type": "Kabupaten", + "name": "Pidie", + "code": "07", + "full_code": "1107", + "province_id": 1 + }, + { + "id": 490, + "type": "Kabupaten", + "name": "Pidie Jaya", + "code": "18", + "full_code": "1118", + "province_id": 1 + }, + { + "id": 491, + "type": "Kabupaten", + "name": "Pinrang", + "code": "15", + "full_code": "7315", + "province_id": 32 + }, + { + "id": 492, + "type": "Kabupaten", + "name": "Polewali Mandar", + "code": "04", + "full_code": "7604", + "province_id": 31 + }, + { + "id": 493, + "type": "Kabupaten", + "name": "Ponorogo", + "code": "02", + "full_code": "3502", + "province_id": 11 + }, + { + "id": 494, + "type": "Kota", + "name": "Pontianak", + "code": "71", + "full_code": "6171", + "province_id": 12 + }, + { + "id": 495, + "type": "Kabupaten", + "name": "Poso", + "code": "02", + "full_code": "7202", + "province_id": 33 + }, + { + "id": 496, + "type": "Kota", + "name": "Prabumulih", + "code": "74", + "full_code": "1674", + "province_id": 37 + }, + { + "id": 497, + "type": "Kabupaten", + "name": "Pringsewu", + "code": "10", + "full_code": "1810", + "province_id": 19 + }, + { + "id": 498, + "type": "Kabupaten", + "name": "Probolinggo", + "code": "13", + "full_code": "3513", + "province_id": 11 + }, + { + "id": 499, + "type": "Kota", + "name": "Probolinggo", + "code": "74", + "full_code": "3574", + "province_id": 11 + }, + { + "id": 500, + "type": "Kabupaten", + "name": "Pulang Pisau", + "code": "11", + "full_code": "6211", + "province_id": 14 + }, + { + "id": 501, + "type": "Kabupaten", + "name": "Pulau Morotai", + "code": "07", + "full_code": "8207", + "province_id": 21 + }, + { + "id": 502, + "type": "Kabupaten", + "name": "Pulau Taliabu", + "code": "08", + "full_code": "8208", + "province_id": 21 + }, + { + "id": 503, + "type": "Kabupaten", + "name": "Puncak", + "code": "05", + "full_code": "9405", + "province_id": 29 + }, + { + "id": 504, + "type": "Kabupaten", + "name": "Puncak Jaya", + "code": "02", + "full_code": "9402", + "province_id": 29 + }, + { + "id": 505, + "type": "Kabupaten", + "name": "Purbalingga", + "code": "03", + "full_code": "3303", + "province_id": 10 + }, + { + "id": 506, + "type": "Kabupaten", + "name": "Purwakarta", + "code": "14", + "full_code": "3214", + "province_id": 9 + }, + { + "id": 507, + "type": "Kabupaten", + "name": "Purworejo", + "code": "06", + "full_code": "3306", + "province_id": 10 + }, + { + "id": 508, + "type": "Kabupaten", + "name": "Raja Ampat", + "code": "05", + "full_code": "9205", + "province_id": 26 + }, + { + "id": 509, + "type": "Kabupaten", + "name": "Rejang Lebong", + "code": "02", + "full_code": "1702", + "province_id": 4 + }, + { + "id": 510, + "type": "Kabupaten", + "name": "Rembang", + "code": "17", + "full_code": "3317", + "province_id": 10 + }, + { + "id": 511, + "type": "Kabupaten", + "name": "Rokan Hilir", + "code": "07", + "full_code": "1407", + "province_id": 30 + }, + { + "id": 512, + "type": "Kabupaten", + "name": "Rokan Hulu", + "code": "06", + "full_code": "1406", + "province_id": 30 + }, + { + "id": 513, + "type": "Kabupaten", + "name": "Rote Ndao", + "code": "14", + "full_code": "5314", + "province_id": 23 + }, + { + "id": 514, + "type": "Kota", + "name": "Sabang", + "code": "72", + "full_code": "1172", + "province_id": 1 + } +] \ No newline at end of file diff --git a/utils/seeds/province.json b/utils/seeds/province.json new file mode 100644 index 0000000000000000000000000000000000000000..c155c28ac8278bdde49211c31c0f56ebd2350255 --- /dev/null +++ b/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/utils/util.go b/utils/util.go new file mode 100644 index 0000000000000000000000000000000000000000..480645d434c01f7152d6747171e5e3ea53969533 --- /dev/null +++ b/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 + } +}