diff --git a/cmd/main.go b/cmd/main.go index 1792938..d4ee0e9 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -1,10 +1,11 @@ package main import ( + "rijig/config" + "rijig/router" + "github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2/middleware/cors" - "github.com/pahmiudahgede/senggoldong/config" - "github.com/pahmiudahgede/senggoldong/router" ) func main() { @@ -12,7 +13,7 @@ func main() { app := fiber.New() app.Use(cors.New(cors.Config{ - AllowOrigins: "http://localhost:3000", + AllowOrigins: "http://localhost:3000", AllowMethods: "GET,POST,PUT,DELETE,OPTIONS", AllowHeaders: "Origin, Content-Type, Accept, Authorization, x-api-key", AllowCredentials: true, @@ -21,7 +22,7 @@ func main() { app.Use(func(c *fiber.Ctx) error { c.Set("Access-Control-Allow-Origin", "http://localhost:3000") c.Set("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS") - c.Set("Access-Control-Allow-Headers", "Origin, Content-Type, Accept, Authorization, x-api-key") + c.Set("Access-Control-Allow-Headers", "Origin, Content-Type, Accept, Authorization, x-api-key") c.Set("Access-Control-Allow-Credentials", "true") return c.Next() }) @@ -29,9 +30,9 @@ func main() { app.Options("*", func(c *fiber.Ctx) error { c.Set("Access-Control-Allow-Origin", "http://localhost:3000") c.Set("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS") - c.Set("Access-Control-Allow-Headers", "Origin, Content-Type, Accept, Authorization, x-api-key") + c.Set("Access-Control-Allow-Headers", "Origin, Content-Type, Accept, Authorization, x-api-key") c.Set("Access-Control-Allow-Credentials", "true") - return c.SendStatus(fiber.StatusNoContent) + return c.SendStatus(fiber.StatusNoContent) }) router.SetupRoutes(app) diff --git a/config/database.go b/config/database.go index 9e5a624..52ac433 100644 --- a/config/database.go +++ b/config/database.go @@ -5,7 +5,8 @@ import ( "log" "os" - "github.com/pahmiudahgede/senggoldong/model" + "rijig/model" + "gorm.io/driver/postgres" "gorm.io/gorm" ) diff --git a/dto/auth_dto.go b/dto/auth_dto.go index 6232f8a..de3674d 100644 --- a/dto/auth_dto.go +++ b/dto/auth_dto.go @@ -15,35 +15,22 @@ type VerifyOTPRequest struct { OTP string `json:"otp"` } -type MetaResponse struct { - Status int `json:"status"` - Message string `json:"message"` -} - -// UserDataResponse untuk bagian data type UserDataResponse struct { UserID string `json:"user_id"` UserRole string `json:"user_role"` Token string `json:"token"` } -// Response struct utama -type Response struct { - Meta MetaResponse `json:"meta"` - Data *UserDataResponse `json:"data,omitempty"` // Gunakan pointer agar bisa bernilai nil jika tidak diperlukan -} - -func (l *RegisterRequest) Validate() (map[string][]string, bool) { +func (r *RegisterRequest) Validate() (map[string][]string, bool) { errors := make(map[string][]string) - // Validasi RoleID dan Phone - if strings.TrimSpace(l.RoleID) == "" { - errors["roleid"] = append(errors["roleid"], "Role ID is required") + if strings.TrimSpace(r.RoleID) == "" { + errors["role_id"] = append(errors["role_id"], "Role ID is required") } - if strings.TrimSpace(l.Phone) == "" { + if strings.TrimSpace(r.Phone) == "" { errors["phone"] = append(errors["phone"], "Phone is required") - } else if !IsValidPhoneNumber(l.Phone) { + } else if !IsValidPhoneNumber(r.Phone) { errors["phone"] = append(errors["phone"], "Invalid phone number format. Use 62 followed by 9-13 digits") } @@ -53,131 +40,7 @@ func (l *RegisterRequest) Validate() (map[string][]string, bool) { return nil, true } -// IsValidPhoneNumber untuk validasi format nomor telepon func IsValidPhoneNumber(phone string) bool { - // Validasi format nomor telepon harus dimulai dengan 62 dan 9-13 digit setelahnya re := regexp.MustCompile(`^62\d{9,13}$`) return re.MatchString(phone) } - -// package dto - -// import ( -// "regexp" -// "strings" -// ) - -// type LoginDTO struct { -// RoleID string `json:"roleid"` -// Identifier string `json:"identifier"` -// Password string `json:"password"` -// } - -// type UserResponseWithToken struct { -// UserID string `json:"user_id"` -// RoleName string `json:"role_name"` -// Token string `json:"token"` -// } - -// type RegisterDTO struct { -// Username string `json:"username"` -// Name string `json:"name"` -// Phone string `json:"phone"` -// Email string `json:"email"` -// Password string `json:"password"` -// ConfirmPassword string `json:"confirm_password"` -// RoleID string `json:"roleId,omitempty"` -// } - -// func (l *LoginDTO) Validate() (map[string][]string, bool) { -// errors := make(map[string][]string) - -// if strings.TrimSpace(l.RoleID) == "" { -// errors["roleid"] = append(errors["roleid"], "Role ID is required") -// } -// if strings.TrimSpace(l.Identifier) == "" { -// errors["identifier"] = append(errors["identifier"], "Identifier (username, email, or phone) is required") -// } -// if strings.TrimSpace(l.Password) == "" { -// errors["password"] = append(errors["password"], "Password is required") -// } - -// if len(errors) > 0 { -// return errors, false -// } -// return nil, true -// } - -// func (r *RegisterDTO) Validate() (map[string][]string, bool) { -// errors := make(map[string][]string) - -// r.validateRequiredFields(errors) - -// if r.Phone != "" && !IsValidPhoneNumber(r.Phone) { -// errors["phone"] = append(errors["phone"], "Invalid phone number format. Use +62 followed by 9-13 digits") -// } - -// if r.Email != "" && !IsValidEmail(r.Email) { -// errors["email"] = append(errors["email"], "Invalid email format") -// } - -// if r.Password != "" && !IsValidPassword(r.Password) { -// errors["password"] = append(errors["password"], "Password must be at least 8 characters long and contain at least one number") -// } - -// if r.ConfirmPassword != "" && r.Password != r.ConfirmPassword { -// errors["confirm_password"] = append(errors["confirm_password"], "Password and confirm password do not match") -// } - -// if len(errors) > 0 { -// return errors, false -// } - -// return nil, true -// } - -// func (r *RegisterDTO) validateRequiredFields(errors map[string][]string) { - -// if strings.TrimSpace(r.Username) == "" { -// errors["username"] = append(errors["username"], "Username is required") -// } -// if strings.TrimSpace(r.Name) == "" { -// errors["name"] = append(errors["name"], "Name is required") -// } -// if strings.TrimSpace(r.Phone) == "" { -// errors["phone"] = append(errors["phone"], "Phone number is required") -// } -// if strings.TrimSpace(r.Email) == "" { -// errors["email"] = append(errors["email"], "Email is required") -// } -// if strings.TrimSpace(r.Password) == "" { -// errors["password"] = append(errors["password"], "Password is required") -// } -// if strings.TrimSpace(r.ConfirmPassword) == "" { -// errors["confirm_password"] = append(errors["confirm_password"], "Confirm password is required") -// } -// if strings.TrimSpace(r.RoleID) == "" { -// errors["roleId"] = append(errors["roleId"], "RoleID is required") -// } -// } - -// func IsValidPhoneNumber(phone string) bool { - -// re := regexp.MustCompile(`^\+62\d{9,13}$`) -// return re.MatchString(phone) -// } - -// func IsValidEmail(email string) bool { - -// re := regexp.MustCompile(`^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$`) -// return re.MatchString(email) -// } - -// func IsValidPassword(password string) bool { -// if len(password) < 8 { -// return false -// } - -// re := regexp.MustCompile(`\d`) -// return re.MatchString(password) -// } diff --git a/go.mod b/go.mod index 99bc202..687dde0 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/pahmiudahgede/senggoldong +module rijig go 1.23.3 diff --git a/internal/handler/address_handler.go b/internal/handler/address_handler.go index 44dfe9d..46a550d 100644 --- a/internal/handler/address_handler.go +++ b/internal/handler/address_handler.go @@ -1,10 +1,11 @@ package handler import ( + "rijig/dto" + "rijig/internal/services" + "rijig/utils" + "github.com/gofiber/fiber/v2" - "github.com/pahmiudahgede/senggoldong/dto" - "github.com/pahmiudahgede/senggoldong/internal/services" - "github.com/pahmiudahgede/senggoldong/utils" ) type AddressHandler struct { diff --git a/internal/handler/article_handler.go b/internal/handler/article_handler.go index 6462870..844e554 100644 --- a/internal/handler/article_handler.go +++ b/internal/handler/article_handler.go @@ -5,10 +5,11 @@ import ( "mime/multipart" "strconv" + "rijig/dto" + "rijig/internal/services" + "rijig/utils" + "github.com/gofiber/fiber/v2" - "github.com/pahmiudahgede/senggoldong/dto" - "github.com/pahmiudahgede/senggoldong/internal/services" - "github.com/pahmiudahgede/senggoldong/utils" ) type ArticleHandler struct { diff --git a/internal/handler/auth_handler.go b/internal/handler/auth_handler.go index 50edbe0..4653495 100644 --- a/internal/handler/auth_handler.go +++ b/internal/handler/auth_handler.go @@ -1,88 +1,53 @@ package handler import ( + "rijig/dto" + "rijig/internal/services" + "rijig/utils" + "github.com/gofiber/fiber/v2" - "github.com/pahmiudahgede/senggoldong/dto" - "github.com/pahmiudahgede/senggoldong/internal/services" ) type AuthHandler struct { - AuthService services.AuthService + authService services.AuthService } func NewAuthHandler(authService services.AuthService) *AuthHandler { - return &AuthHandler{AuthService: authService} + return &AuthHandler{ + authService: authService, + } } func (h *AuthHandler) Register(c *fiber.Ctx) error { var request dto.RegisterRequest if err := c.BodyParser(&request); err != nil { - return c.Status(400).SendString("Invalid input") + return utils.ValidationErrorResponse(c, map[string][]string{"body": {"invalid request body"}}) } if errors, valid := request.Validate(); !valid { - return c.Status(400).JSON(errors) + return utils.ValidationErrorResponse(c, errors) } - _, err := h.AuthService.RegisterUser(request) + err := h.authService.RegisterUser(&request) if err != nil { - return c.Status(500).SendString(err.Error()) + return utils.ErrorResponse(c, err.Error()) } - return c.Status(201).JSON(fiber.Map{ - "meta": fiber.Map{ - "status": 201, - "message": "The input register from the user has been successfully recorded. Please check the otp code sent to your number.", - }, - }) + return utils.SuccessResponse(c, nil, "OTP has been sent to your phone") } func (h *AuthHandler) VerifyOTP(c *fiber.Ctx) error { - var request struct { - Phone string `json:"phone"` - OTP string `json:"otp"` - } + var request dto.VerifyOTPRequest if err := c.BodyParser(&request); err != nil { - return c.Status(400).SendString("Invalid input") + return utils.ValidationErrorResponse(c, map[string][]string{"body": {"invalid request body"}}) } - err := h.AuthService.VerifyOTP(request.Phone, request.OTP) + err := h.authService.VerifyOTP(&request) if err != nil { - return c.Status(400).JSON(dto.Response{ - Meta: dto.MetaResponse{ - Status: 400, - Message: "Invalid OTP", - }, - Data: nil, - }) + return utils.ErrorResponse(c, err.Error()) } - user, err := h.AuthService.GetUserByPhone(request.Phone) - if err != nil { - return c.Status(500).SendString("Error retrieving user") - } - if user == nil { - return c.Status(404).SendString("User not found") - } - - token, err := h.AuthService.GenerateJWT(user) - if err != nil { - return c.Status(500).SendString("Error generating token") - } - - response := dto.Response{ - Meta: dto.MetaResponse{ - Status: 200, - Message: "OTP yang dimasukkan valid", - }, - Data: &dto.UserDataResponse{ - UserID: user.ID, - UserRole: user.Role.RoleName, - Token: token, - }, - } - - return c.Status(200).JSON(response) + return utils.SuccessResponse(c, nil, "User successfully registered") } diff --git a/internal/handler/banner_handler.go b/internal/handler/banner_handler.go index ac5bd9e..731fd1f 100644 --- a/internal/handler/banner_handler.go +++ b/internal/handler/banner_handler.go @@ -1,10 +1,11 @@ package handler import ( + "rijig/dto" + "rijig/internal/services" + "rijig/utils" + "github.com/gofiber/fiber/v2" - "github.com/pahmiudahgede/senggoldong/dto" - "github.com/pahmiudahgede/senggoldong/internal/services" - "github.com/pahmiudahgede/senggoldong/utils" ) type BannerHandler struct { diff --git a/internal/handler/initialcoint_handler.go b/internal/handler/initialcoint_handler.go index 2cf275a..c80b466 100644 --- a/internal/handler/initialcoint_handler.go +++ b/internal/handler/initialcoint_handler.go @@ -1,10 +1,11 @@ package handler import ( + "rijig/dto" + "rijig/internal/services" + "rijig/utils" + "github.com/gofiber/fiber/v2" - "github.com/pahmiudahgede/senggoldong/dto" - "github.com/pahmiudahgede/senggoldong/internal/services" - "github.com/pahmiudahgede/senggoldong/utils" ) type InitialCointHandler struct { diff --git a/internal/handler/product_handler.go b/internal/handler/product_handler.go index 9a84911..5c0eccf 100644 --- a/internal/handler/product_handler.go +++ b/internal/handler/product_handler.go @@ -5,10 +5,11 @@ import ( "log" "strconv" + "rijig/dto" + "rijig/internal/services" + "rijig/utils" + "github.com/gofiber/fiber/v2" - "github.com/pahmiudahgede/senggoldong/dto" - "github.com/pahmiudahgede/senggoldong/internal/services" - "github.com/pahmiudahgede/senggoldong/utils" ) type ProductHandler struct { diff --git a/internal/handler/role_handler.go b/internal/handler/role_handler.go index 2141ed5..f0bb07f 100644 --- a/internal/handler/role_handler.go +++ b/internal/handler/role_handler.go @@ -1,9 +1,10 @@ package handler import ( + "rijig/internal/services" + "rijig/utils" + "github.com/gofiber/fiber/v2" - "github.com/pahmiudahgede/senggoldong/internal/services" - "github.com/pahmiudahgede/senggoldong/utils" ) type RoleHandler struct { diff --git a/internal/handler/store_handler.go b/internal/handler/store_handler.go index bf759b8..dde89f1 100644 --- a/internal/handler/store_handler.go +++ b/internal/handler/store_handler.go @@ -3,10 +3,11 @@ package handler import ( "log" + "rijig/dto" + "rijig/internal/services" + "rijig/utils" + "github.com/gofiber/fiber/v2" - "github.com/pahmiudahgede/senggoldong/dto" - "github.com/pahmiudahgede/senggoldong/internal/services" - "github.com/pahmiudahgede/senggoldong/utils" ) type StoreHandler struct { diff --git a/internal/handler/trash_handler.go b/internal/handler/trash_handler.go index d07c8d4..afc85b5 100644 --- a/internal/handler/trash_handler.go +++ b/internal/handler/trash_handler.go @@ -1,10 +1,11 @@ package handler import ( + "rijig/dto" + "rijig/internal/services" + "rijig/utils" + "github.com/gofiber/fiber/v2" - "github.com/pahmiudahgede/senggoldong/dto" - "github.com/pahmiudahgede/senggoldong/internal/services" - "github.com/pahmiudahgede/senggoldong/utils" ) type TrashHandler struct { diff --git a/internal/handler/user_handler.go b/internal/handler/user_handler.go index f8e0d73..e479047 100644 --- a/internal/handler/user_handler.go +++ b/internal/handler/user_handler.go @@ -1,10 +1,11 @@ package handler import ( + "rijig/dto" + "rijig/internal/services" + "rijig/utils" + "github.com/gofiber/fiber/v2" - "github.com/pahmiudahgede/senggoldong/dto" - "github.com/pahmiudahgede/senggoldong/internal/services" - "github.com/pahmiudahgede/senggoldong/utils" ) type UserProfileHandler struct { @@ -30,7 +31,6 @@ func (h *UserProfileHandler) GetUserProfile(c *fiber.Ctx) error { return utils.SuccessResponse(c, userProfile, "User profile retrieved successfully") } - func (h *UserProfileHandler) GetUserProfileById(c *fiber.Ctx) error { userID := c.Params("userid") if userID == "" { @@ -118,8 +118,8 @@ func (h *UserProfileHandler) UpdateUserProfile(c *fiber.Ctx) error { // return utils.GenericResponse(c, fiber.StatusBadRequest, err.Error()) // } -// return utils.GenericResponse(c, fiber.StatusOK, message) -// } +// return utils.GenericResponse(c, fiber.StatusOK, message) +// } func (h *UserProfileHandler) UpdateUserAvatar(c *fiber.Ctx) error { userID, ok := c.Locals("userID").(string) diff --git a/internal/handler/userpin_handler.go b/internal/handler/userpin_handler.go index f0e2908..bb65b4b 100644 --- a/internal/handler/userpin_handler.go +++ b/internal/handler/userpin_handler.go @@ -1,10 +1,11 @@ package handler import ( + "rijig/dto" + "rijig/internal/services" + "rijig/utils" + "github.com/gofiber/fiber/v2" - "github.com/pahmiudahgede/senggoldong/dto" - "github.com/pahmiudahgede/senggoldong/internal/services" - "github.com/pahmiudahgede/senggoldong/utils" ) type UserPinHandler struct { diff --git a/internal/handler/wilayah_indonesia_handler.go b/internal/handler/wilayah_indonesia_handler.go index 02ae1bb..bde943a 100644 --- a/internal/handler/wilayah_indonesia_handler.go +++ b/internal/handler/wilayah_indonesia_handler.go @@ -3,9 +3,10 @@ package handler import ( "strconv" + "rijig/internal/services" + "rijig/utils" + "github.com/gofiber/fiber/v2" - "github.com/pahmiudahgede/senggoldong/internal/services" - "github.com/pahmiudahgede/senggoldong/utils" ) type WilayahIndonesiaHandler struct { diff --git a/internal/repositories/address_repo.go b/internal/repositories/address_repo.go index 1661b6b..d8c2cf5 100644 --- a/internal/repositories/address_repo.go +++ b/internal/repositories/address_repo.go @@ -1,7 +1,8 @@ package repositories import ( - "github.com/pahmiudahgede/senggoldong/model" + "rijig/model" + "gorm.io/gorm" ) @@ -25,7 +26,6 @@ func (r *addressRepository) CreateAddress(address *model.Address) error { return r.DB.Create(address).Error } - func (r *addressRepository) FindAddressByUserID(userID string) ([]model.Address, error) { var addresses []model.Address err := r.DB.Where("user_id = ?", userID).Find(&addresses).Error @@ -58,4 +58,4 @@ func (r *addressRepository) DeleteAddress(id string) error { return err } return nil -} \ No newline at end of file +} diff --git a/internal/repositories/article_repo.go b/internal/repositories/article_repo.go index 79f2fcb..d9a1222 100644 --- a/internal/repositories/article_repo.go +++ b/internal/repositories/article_repo.go @@ -3,7 +3,8 @@ package repositories import ( "fmt" - "github.com/pahmiudahgede/senggoldong/model" + "rijig/model" + "gorm.io/gorm" ) @@ -71,4 +72,4 @@ func (r *articleRepository) UpdateArticle(id string, article *model.Article) err func (r *articleRepository) DeleteArticle(id string) error { result := r.DB.Delete(&model.Article{}, "id = ?", id) return result.Error -} \ No newline at end of file +} diff --git a/internal/repositories/auth_repo.go b/internal/repositories/auth_repo.go index 5ffe64d..0869d2b 100644 --- a/internal/repositories/auth_repo.go +++ b/internal/repositories/auth_repo.go @@ -1,29 +1,40 @@ package repositories import ( - "github.com/pahmiudahgede/senggoldong/model" + "context" + "encoding/json" + "fmt" + "time" + + "rijig/model" + + "github.com/go-redis/redis/v8" "gorm.io/gorm" ) type UserRepository interface { + SaveUser(user *model.User) (*model.User, error) FindByPhone(phone string) (*model.User, error) - FindByPhoneAndRole(phone, roleID string) (*model.User, error) - CreateUser(user *model.User) error } type userRepository struct { - DB *gorm.DB + db *gorm.DB } func NewUserRepository(db *gorm.DB) UserRepository { - return &userRepository{DB: db} + return &userRepository{db: db} +} + +func (r *userRepository) SaveUser(user *model.User) (*model.User, error) { + if err := r.db.Create(user).Error; err != nil { + return nil, err + } + return user, nil } func (r *userRepository) FindByPhone(phone string) (*model.User, error) { var user model.User - - err := r.DB.Preload("Role").Where("phone = ?", phone).First(&user).Error - if err != nil { + if err := r.db.Where("phone = ?", phone).First(&user).Error; err != nil { if err == gorm.ErrRecordNotFound { return nil, nil } @@ -32,15 +43,62 @@ func (r *userRepository) FindByPhone(phone string) (*model.User, error) { return &user, nil } -func (r *userRepository) FindByPhoneAndRole(phone, roleID string) (*model.User, error) { - var user model.User - err := r.DB.Where("phone = ? AND role_id = ?", phone, roleID).First(&user).Error - if err != nil { - return nil, err - } - return &user, nil +type RedisRepository interface { + StoreData(key string, data interface{}, expiration time.Duration) error + GetData(key string) (interface{}, error) // Mengembalikan interface{} + DeleteData(key string) error } -func (r *userRepository) CreateUser(user *model.User) error { - return r.DB.Create(user).Error +type redisRepository struct { + client *redis.Client + ctx context.Context +} + +// NewRedisRepository membuat instance baru dari redisRepository +func NewRedisRepository(client *redis.Client) RedisRepository { + return &redisRepository{ + client: client, + ctx: context.Background(), + } +} + +// StoreData menyimpan data ke dalam Redis (dalam format JSON) +func (r *redisRepository) StoreData(key string, data interface{}, expiration time.Duration) error { + // Marshaling data ke JSON + jsonData, err := json.Marshal(data) + if err != nil { + return fmt.Errorf("failed to marshal data: %v", err) + } + + // Simpan JSON ke Redis + err = r.client.Set(r.ctx, key, jsonData, expiration).Err() + if err != nil { + return fmt.Errorf("failed to store data in Redis: %v", err) + } + return nil +} + +// GetData mengambil data dari Redis berdasarkan key +func (r *redisRepository) GetData(key string) (interface{}, error) { + val, err := r.client.Get(r.ctx, key).Result() + if err != nil { + return nil, fmt.Errorf("failed to get data from Redis: %v", err) + } + + // Unmarshal data JSON kembali ke objek + var data interface{} + err = json.Unmarshal([]byte(val), &data) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal data: %v", err) + } + return data, nil +} + +// DeleteData menghapus data di Redis berdasarkan key +func (r *redisRepository) DeleteData(key string) error { + err := r.client.Del(r.ctx, key).Err() + if err != nil { + return fmt.Errorf("failed to delete data from Redis: %v", err) + } + return nil } diff --git a/internal/repositories/banner_repo.go b/internal/repositories/banner_repo.go index 8f553f9..41803de 100644 --- a/internal/repositories/banner_repo.go +++ b/internal/repositories/banner_repo.go @@ -3,7 +3,8 @@ package repositories import ( "fmt" - "github.com/pahmiudahgede/senggoldong/model" + "rijig/model" + "gorm.io/gorm" ) diff --git a/internal/repositories/initialcoint_repo.go b/internal/repositories/initialcoint_repo.go index 0a64709..ec03479 100644 --- a/internal/repositories/initialcoint_repo.go +++ b/internal/repositories/initialcoint_repo.go @@ -2,7 +2,8 @@ package repositories import ( "fmt" - "github.com/pahmiudahgede/senggoldong/model" + "rijig/model" + "gorm.io/gorm" ) diff --git a/internal/repositories/product_repo.go b/internal/repositories/product_repo.go index 5ab4f56..08f1b1f 100644 --- a/internal/repositories/product_repo.go +++ b/internal/repositories/product_repo.go @@ -3,7 +3,8 @@ package repositories import ( "fmt" - "github.com/pahmiudahgede/senggoldong/model" + "rijig/model" + "gorm.io/gorm" ) diff --git a/internal/repositories/role_repo.go b/internal/repositories/role_repo.go index 7abea10..df4299b 100644 --- a/internal/repositories/role_repo.go +++ b/internal/repositories/role_repo.go @@ -1,7 +1,8 @@ package repositories import ( - "github.com/pahmiudahgede/senggoldong/model" + "rijig/model" + "gorm.io/gorm" ) diff --git a/internal/repositories/store_repo.go b/internal/repositories/store_repo.go index 989e591..9b02bb7 100644 --- a/internal/repositories/store_repo.go +++ b/internal/repositories/store_repo.go @@ -3,7 +3,8 @@ package repositories import ( "fmt" - "github.com/pahmiudahgede/senggoldong/model" + "rijig/model" + "gorm.io/gorm" ) diff --git a/internal/repositories/trash_repo.go b/internal/repositories/trash_repo.go index a41e84d..1fd4861 100644 --- a/internal/repositories/trash_repo.go +++ b/internal/repositories/trash_repo.go @@ -3,7 +3,8 @@ package repositories import ( "fmt" - "github.com/pahmiudahgede/senggoldong/model" + "rijig/model" + "gorm.io/gorm" ) diff --git a/internal/repositories/user_repo.go b/internal/repositories/user_repo.go index 3279377..4243219 100644 --- a/internal/repositories/user_repo.go +++ b/internal/repositories/user_repo.go @@ -3,7 +3,8 @@ package repositories import ( "fmt" - "github.com/pahmiudahgede/senggoldong/model" + "rijig/model" + "gorm.io/gorm" ) diff --git a/internal/repositories/userpin_repo.go b/internal/repositories/userpin_repo.go index 057964e..47d7118 100644 --- a/internal/repositories/userpin_repo.go +++ b/internal/repositories/userpin_repo.go @@ -1,7 +1,8 @@ package repositories import ( - "github.com/pahmiudahgede/senggoldong/model" + "rijig/model" + "gorm.io/gorm" ) diff --git a/internal/repositories/wilayah_indonesia_repo.go b/internal/repositories/wilayah_indonesia_repo.go index ea4bd89..60a53bf 100644 --- a/internal/repositories/wilayah_indonesia_repo.go +++ b/internal/repositories/wilayah_indonesia_repo.go @@ -1,7 +1,8 @@ package repositories import ( - "github.com/pahmiudahgede/senggoldong/model" + "rijig/model" + "gorm.io/gorm" ) @@ -240,4 +241,4 @@ func (r *wilayahIndonesiaRepository) FindVillageByID(id string) (*model.Village, return nil, err } return &village, nil -} \ No newline at end of file +} diff --git a/internal/services/address_service.go b/internal/services/address_service.go index 7e3f22f..0f73781 100644 --- a/internal/services/address_service.go +++ b/internal/services/address_service.go @@ -4,10 +4,10 @@ import ( "fmt" "time" - "github.com/pahmiudahgede/senggoldong/dto" - "github.com/pahmiudahgede/senggoldong/internal/repositories" - "github.com/pahmiudahgede/senggoldong/model" - "github.com/pahmiudahgede/senggoldong/utils" + "rijig/dto" + "rijig/internal/repositories" + "rijig/model" + "rijig/utils" ) type AddressService interface { diff --git a/internal/services/article_service.go b/internal/services/article_service.go index 7d674b8..b733a8d 100644 --- a/internal/services/article_service.go +++ b/internal/services/article_service.go @@ -8,11 +8,12 @@ import ( "path/filepath" "time" + "rijig/dto" + "rijig/internal/repositories" + "rijig/model" + "rijig/utils" + "github.com/google/uuid" - "github.com/pahmiudahgede/senggoldong/dto" - "github.com/pahmiudahgede/senggoldong/internal/repositories" - "github.com/pahmiudahgede/senggoldong/model" - "github.com/pahmiudahgede/senggoldong/utils" ) type ArticleService interface { diff --git a/internal/services/auth_service.go b/internal/services/auth_service.go index 93bc0c2..0c05b6e 100644 --- a/internal/services/auth_service.go +++ b/internal/services/auth_service.go @@ -1,103 +1,127 @@ package services import ( + "encoding/json" "fmt" + "log" "time" - "github.com/go-redis/redis/v8" - "github.com/golang-jwt/jwt/v5" - "github.com/pahmiudahgede/senggoldong/config" - "github.com/pahmiudahgede/senggoldong/dto" - "github.com/pahmiudahgede/senggoldong/internal/repositories" - "github.com/pahmiudahgede/senggoldong/model" + "math/rand" + + "rijig/config" + "rijig/dto" + "rijig/internal/repositories" + "rijig/model" ) type AuthService interface { - RegisterUser(request dto.RegisterRequest) (*model.User, error) - VerifyOTP(phone, otp string) error - GetUserByPhone(phone string) (*model.User, error) - GenerateJWT(user *model.User) (string, error) + RegisterUser(request *dto.RegisterRequest) error + VerifyOTP(request *dto.VerifyOTPRequest) error } type authService struct { - UserRepo repositories.UserRepository + userRepo repositories.UserRepository + roleRepo repositories.RoleRepository + redisRepo repositories.RedisRepository } -func NewAuthService(userRepo repositories.UserRepository) AuthService { - return &authService{UserRepo: userRepo} +func NewAuthService(userRepo repositories.UserRepository, roleRepo repositories.RoleRepository, redisRepo repositories.RedisRepository) AuthService { + return &authService{ + userRepo: userRepo, + roleRepo: roleRepo, + redisRepo: redisRepo, + } } -func (s *authService) RegisterUser(request dto.RegisterRequest) (*model.User, error) { +func (s *authService) RegisterUser(request *dto.RegisterRequest) error { - user, err := s.UserRepo.FindByPhone(request.Phone) - if err == nil && user != nil { - return nil, fmt.Errorf("user with phone %s already exists", request.Phone) + if request.RoleID == "" { + return fmt.Errorf("role_id cannot be empty") } - user = &model.User{ - Phone: request.Phone, - RoleID: request.RoleID, - EmailVerified: false, - } - - err = s.UserRepo.CreateUser(user) + role, err := s.roleRepo.FindByID(request.RoleID) if err != nil { - return nil, fmt.Errorf("failed to create user: %v", err) + return fmt.Errorf("role not found: %v", err) + } + if role == nil { + return fmt.Errorf("role with ID %s not found", request.RoleID) } - _, err = s.SendOTP(request.Phone) + existingUser, err := s.userRepo.FindByPhone(request.Phone) if err != nil { - return nil, fmt.Errorf("failed to send OTP: %v", err) + return fmt.Errorf("failed to check existing user: %v", err) + } + if existingUser != nil { + return fmt.Errorf("phone number already registered") } - return user, nil + temporaryData := &model.User{ + Phone: request.Phone, + RoleID: request.RoleID, + } + + err = s.redisRepo.StoreData(request.Phone, temporaryData, 1*time.Hour) + if err != nil { + return fmt.Errorf("failed to store registration data in Redis: %v", err) + } + + otp := generateOTP() + err = s.redisRepo.StoreData("otp:"+request.Phone, otp, 10*time.Minute) + if err != nil { + return fmt.Errorf("failed to store OTP in Redis: %v", err) + } + + err = config.SendWhatsAppMessage(request.Phone, fmt.Sprintf("Your OTP is: %s", otp)) + if err != nil { + return fmt.Errorf("failed to send OTP via WhatsApp: %v", err) + } + + log.Printf("OTP sent to phone number: %s", request.Phone) + return nil } -func (s *authService) GetUserByPhone(phone string) (*model.User, error) { - user, err := s.UserRepo.FindByPhone(phone) +func (s *authService) VerifyOTP(request *dto.VerifyOTPRequest) error { + + storedOTP, err := s.redisRepo.GetData("otp:" + request.Phone) if err != nil { - return nil, fmt.Errorf("error retrieving user by phone: %v", err) - } - if user == nil { - return nil, fmt.Errorf("user not found") - } - return user, nil -} - -func (s *authService) SendOTP(phone string) (string, error) { - otpCode := generateOTP() - - message := fmt.Sprintf("Your OTP code is: %s", otpCode) - err := config.SendWhatsAppMessage(phone, message) - if err != nil { - return "", fmt.Errorf("failed to send OTP via WhatsApp: %v", err) - } - - expirationTime := 5 * time.Minute - err = config.RedisClient.Set(config.Ctx, phone, otpCode, expirationTime).Err() - if err != nil { - return "", fmt.Errorf("failed to store OTP in Redis: %v", err) - } - - return otpCode, nil -} - -func (s *authService) VerifyOTP(phone, otp string) error { - - otpRecord, err := config.RedisClient.Get(config.Ctx, phone).Result() - if err == redis.Nil { - - return fmt.Errorf("OTP not found or expired") - } else if err != nil { - return fmt.Errorf("failed to retrieve OTP from Redis: %v", err) } - - if otp != otpRecord { + if storedOTP != request.OTP { return fmt.Errorf("invalid OTP") } - err = config.RedisClient.Del(config.Ctx, phone).Err() + temporaryData, err := s.redisRepo.GetData(request.Phone) + if err != nil { + return fmt.Errorf("failed to get registration data from Redis: %v", err) + } + if temporaryData == "" { + return fmt.Errorf("no registration data found for phone: %s", request.Phone) + } + + temporaryDataStr, ok := temporaryData.(string) + if !ok { + return fmt.Errorf("failed to assert data to string") + } + + temporaryDataBytes := []byte(temporaryDataStr) + + var user model.User + err = json.Unmarshal(temporaryDataBytes, &user) + if err != nil { + return fmt.Errorf("failed to unmarshal registration data: %v", err) + } + + _, err = s.userRepo.SaveUser(&user) + if err != nil { + return fmt.Errorf("failed to save user to database: %v", err) + } + + err = s.redisRepo.DeleteData(request.Phone) + if err != nil { + return fmt.Errorf("failed to delete registration data from Redis: %v", err) + } + + err = s.redisRepo.DeleteData("otp:" + request.Phone) if err != nil { return fmt.Errorf("failed to delete OTP from Redis: %v", err) } @@ -105,30 +129,12 @@ func (s *authService) VerifyOTP(phone, otp string) error { return nil } -func (s *authService) GenerateJWT(user *model.User) (string, error) { - if user == nil || user.Role == nil { - return "", fmt.Errorf("user or user role is nil, cannot generate token") - } - - claims := jwt.MapClaims{ - "sub": user.ID, - "role": user.Role.RoleName, - "iat": time.Now().Unix(), - "exp": time.Now().Add(time.Hour * 24).Unix(), - } - - token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims) - - secretKey := config.GetSecretKey() - - tokenString, err := token.SignedString([]byte(secretKey)) - if err != nil { - return "", fmt.Errorf("failed to generate JWT token: %v", err) - } - - return tokenString, nil -} - func generateOTP() string { - return fmt.Sprintf("%06d", time.Now().UnixNano()%1000000) + + return fmt.Sprintf("%06d", RandomInt(100000, 999999)) +} + +func RandomInt(min, max int) int { + rand.Seed(time.Now().UnixNano()) + return rand.Intn(max-min+1) + min } diff --git a/internal/services/banner_service.go b/internal/services/banner_service.go index 67a5d7c..1b1b734 100644 --- a/internal/services/banner_service.go +++ b/internal/services/banner_service.go @@ -7,11 +7,12 @@ import ( "path/filepath" "time" + "rijig/dto" + "rijig/internal/repositories" + "rijig/model" + "rijig/utils" + "github.com/google/uuid" - "github.com/pahmiudahgede/senggoldong/dto" - "github.com/pahmiudahgede/senggoldong/internal/repositories" - "github.com/pahmiudahgede/senggoldong/model" - "github.com/pahmiudahgede/senggoldong/utils" ) type BannerService interface { diff --git a/internal/services/initialcoint_service.go b/internal/services/initialcoint_service.go index 73bb599..2791335 100644 --- a/internal/services/initialcoint_service.go +++ b/internal/services/initialcoint_service.go @@ -4,10 +4,10 @@ import ( "fmt" "time" - "github.com/pahmiudahgede/senggoldong/dto" - "github.com/pahmiudahgede/senggoldong/internal/repositories" - "github.com/pahmiudahgede/senggoldong/model" - "github.com/pahmiudahgede/senggoldong/utils" + "rijig/dto" + "rijig/internal/repositories" + "rijig/model" + "rijig/utils" ) type InitialCointService interface { diff --git a/internal/services/product_service.go b/internal/services/product_service.go index bc6eb23..f448396 100644 --- a/internal/services/product_service.go +++ b/internal/services/product_service.go @@ -6,11 +6,12 @@ import ( "os" "path/filepath" + "rijig/dto" + "rijig/internal/repositories" + "rijig/model" + "rijig/utils" + "github.com/google/uuid" - "github.com/pahmiudahgede/senggoldong/dto" - "github.com/pahmiudahgede/senggoldong/internal/repositories" - "github.com/pahmiudahgede/senggoldong/model" - "github.com/pahmiudahgede/senggoldong/utils" ) type ProductService interface { diff --git a/internal/services/role_service.go b/internal/services/role_service.go index c8a8741..d40d490 100644 --- a/internal/services/role_service.go +++ b/internal/services/role_service.go @@ -4,9 +4,9 @@ import ( "fmt" "time" - "github.com/pahmiudahgede/senggoldong/dto" - "github.com/pahmiudahgede/senggoldong/internal/repositories" - "github.com/pahmiudahgede/senggoldong/utils" + "rijig/dto" + "rijig/internal/repositories" + "rijig/utils" ) type RoleService interface { diff --git a/internal/services/store_service.go b/internal/services/store_service.go index 43467dd..ef855c7 100644 --- a/internal/services/store_service.go +++ b/internal/services/store_service.go @@ -6,11 +6,12 @@ import ( "os" "path/filepath" + "rijig/dto" + "rijig/internal/repositories" + "rijig/model" + "rijig/utils" + "github.com/google/uuid" - "github.com/pahmiudahgede/senggoldong/dto" - "github.com/pahmiudahgede/senggoldong/internal/repositories" - "github.com/pahmiudahgede/senggoldong/model" - "github.com/pahmiudahgede/senggoldong/utils" ) type StoreService interface { @@ -237,7 +238,7 @@ func (s *storeService) DeleteStore(storeID string) error { func (s *storeService) saveStoreImage(file *multipart.FileHeader, imageType string) (string, error) { - imageDir := fmt.Sprintf("./public%s/uploads/store/%s",os.Getenv("BASE_URL"), imageType) + imageDir := fmt.Sprintf("./public%s/uploads/store/%s", os.Getenv("BASE_URL"), imageType) if _, err := os.Stat(imageDir); os.IsNotExist(err) { if err := os.MkdirAll(imageDir, os.ModePerm); err != nil { diff --git a/internal/services/trash_service.go b/internal/services/trash_service.go index 58fa05d..dcc05ca 100644 --- a/internal/services/trash_service.go +++ b/internal/services/trash_service.go @@ -4,10 +4,10 @@ import ( "fmt" "time" - "github.com/pahmiudahgede/senggoldong/dto" - "github.com/pahmiudahgede/senggoldong/internal/repositories" - "github.com/pahmiudahgede/senggoldong/model" - "github.com/pahmiudahgede/senggoldong/utils" + "rijig/dto" + "rijig/internal/repositories" + "rijig/model" + "rijig/utils" ) type TrashService interface { diff --git a/internal/services/user_service.go b/internal/services/user_service.go index 1f5b54e..f1ab25a 100644 --- a/internal/services/user_service.go +++ b/internal/services/user_service.go @@ -10,10 +10,10 @@ import ( "path/filepath" "time" - "github.com/pahmiudahgede/senggoldong/dto" - "github.com/pahmiudahgede/senggoldong/internal/repositories" - "github.com/pahmiudahgede/senggoldong/model" - "github.com/pahmiudahgede/senggoldong/utils" + "rijig/dto" + "rijig/internal/repositories" + "rijig/model" + "rijig/utils" // "golang.org/x/crypto/bcrypt" ) @@ -155,12 +155,12 @@ func (s *userProfileService) UpdateUserProfile(userID string, updateData dto.Upd user.Name = updateData.Name } - if updateData.Phone != "" && updateData.Phone != user.Phone { - if err := s.updatePhoneIfNeeded(user, updateData.Phone); err != nil { - return nil, err - } - user.Phone = updateData.Phone - } + // if updateData.Phone != "" && updateData.Phone != user.Phone { + // if err := s.updatePhoneIfNeeded(user, updateData.Phone); err != nil { + // return nil, err + // } + // user.Phone = updateData.Phone + // } // if updateData.Email != "" && updateData.Email != user.Email { // if err := s.updateEmailIfNeeded(user, updateData.Email); err != nil { @@ -188,13 +188,13 @@ func (s *userProfileService) UpdateUserProfile(userID string, updateData dto.Upd return userResponse, nil } -func (s *userProfileService) updatePhoneIfNeeded(user *model.User, newPhone string) error { - existingPhone, _ := s.UserRepo.FindByPhoneAndRole(newPhone, user.RoleID) - if existingPhone != nil { - return fmt.Errorf("phone number is already used for this role") - } - return nil -} +// func (s *userProfileService) updatePhoneIfNeeded(user *model.User, newPhone string) error { +// existingPhone, _ := s.UserRepo.FindByPhoneAndRole(newPhone, user.RoleID) +// if existingPhone != nil { +// return fmt.Errorf("phone number is already used for this role") +// } +// return nil +// } // func (s *userProfileService) updateEmailIfNeeded(user *model.User, newEmail string) error { // existingEmail, _ := s.UserRepo.FindByEmailAndRole(newEmail, user.RoleID) diff --git a/internal/services/userpin_service.go b/internal/services/userpin_service.go index 4324c17..9a2ba45 100644 --- a/internal/services/userpin_service.go +++ b/internal/services/userpin_service.go @@ -4,9 +4,10 @@ import ( "fmt" "time" - "github.com/pahmiudahgede/senggoldong/internal/repositories" - "github.com/pahmiudahgede/senggoldong/model" - "github.com/pahmiudahgede/senggoldong/utils" + "rijig/internal/repositories" + "rijig/model" + "rijig/utils" + "golang.org/x/crypto/bcrypt" ) diff --git a/internal/services/wilayah_indonesia_service.go b/internal/services/wilayah_indonesia_service.go index 0f78490..519522a 100644 --- a/internal/services/wilayah_indonesia_service.go +++ b/internal/services/wilayah_indonesia_service.go @@ -6,10 +6,10 @@ import ( "strconv" "time" - "github.com/pahmiudahgede/senggoldong/dto" - "github.com/pahmiudahgede/senggoldong/internal/repositories" - "github.com/pahmiudahgede/senggoldong/model" - "github.com/pahmiudahgede/senggoldong/utils" + "rijig/dto" + "rijig/internal/repositories" + "rijig/model" + "rijig/utils" ) type WilayahIndonesiaService interface { diff --git a/middleware/api_key.go b/middleware/api_key.go index 0693eb4..3f2c7d6 100644 --- a/middleware/api_key.go +++ b/middleware/api_key.go @@ -3,8 +3,9 @@ package middleware import ( "os" + "rijig/utils" + "github.com/gofiber/fiber/v2" - "github.com/pahmiudahgede/senggoldong/utils" ) func APIKeyMiddleware(c *fiber.Ctx) error { diff --git a/middleware/auth_middleware.go b/middleware/auth_middleware.go index 427c5f6..c1b868d 100644 --- a/middleware/auth_middleware.go +++ b/middleware/auth_middleware.go @@ -3,9 +3,10 @@ package middleware import ( "os" + "rijig/utils" + "github.com/gofiber/fiber/v2" "github.com/golang-jwt/jwt/v5" - "github.com/pahmiudahgede/senggoldong/utils" ) func AuthMiddleware(c *fiber.Ctx) error { diff --git a/middleware/role_middleware.go b/middleware/role_middleware.go index dcb6687..cfd864c 100644 --- a/middleware/role_middleware.go +++ b/middleware/role_middleware.go @@ -1,8 +1,9 @@ package middleware import ( + "rijig/utils" + "github.com/gofiber/fiber/v2" - "github.com/pahmiudahgede/senggoldong/utils" ) func RoleMiddleware(allowedRoles ...string) fiber.Handler { diff --git a/presentation/address_route.go b/presentation/address_route.go index 84e549d..f9038be 100644 --- a/presentation/address_route.go +++ b/presentation/address_route.go @@ -1,12 +1,13 @@ package presentation import ( + "rijig/config" + "rijig/internal/handler" + "rijig/internal/repositories" + "rijig/internal/services" + "rijig/middleware" + "github.com/gofiber/fiber/v2" - "github.com/pahmiudahgede/senggoldong/config" - "github.com/pahmiudahgede/senggoldong/internal/handler" - "github.com/pahmiudahgede/senggoldong/internal/repositories" - "github.com/pahmiudahgede/senggoldong/internal/services" - "github.com/pahmiudahgede/senggoldong/middleware" ) func AddressRouter(api fiber.Router) { diff --git a/presentation/article_route.go b/presentation/article_route.go index 3d51dd0..1606b01 100644 --- a/presentation/article_route.go +++ b/presentation/article_route.go @@ -1,13 +1,14 @@ package presentation import ( + "rijig/config" + "rijig/internal/handler" + "rijig/internal/repositories" + "rijig/internal/services" + "rijig/middleware" + "rijig/utils" + "github.com/gofiber/fiber/v2" - "github.com/pahmiudahgede/senggoldong/config" - "github.com/pahmiudahgede/senggoldong/internal/handler" - "github.com/pahmiudahgede/senggoldong/internal/repositories" - "github.com/pahmiudahgede/senggoldong/internal/services" - "github.com/pahmiudahgede/senggoldong/middleware" - "github.com/pahmiudahgede/senggoldong/utils" ) func ArticleRouter(api fiber.Router) { diff --git a/presentation/auth_route.go b/presentation/auth_route.go index 16ccc7f..d0f8f33 100644 --- a/presentation/auth_route.go +++ b/presentation/auth_route.go @@ -1,13 +1,14 @@ package presentation import ( + "rijig/config" + "rijig/internal/handler" + "rijig/internal/repositories" + "rijig/internal/services" + "github.com/gofiber/fiber/v2" - "github.com/pahmiudahgede/senggoldong/config" - "github.com/pahmiudahgede/senggoldong/internal/handler" - "github.com/pahmiudahgede/senggoldong/internal/repositories" - "github.com/pahmiudahgede/senggoldong/internal/services" // "gorm.io/gorm" - // "github.com/pahmiudahgede/senggoldong/middleware" + // "rijig/middleware" ) func AuthRouter(api fiber.Router) { @@ -29,12 +30,25 @@ func AuthRouter(api fiber.Router) { // authRoutes := api.Group("/auth") // authRoutes.Post("/send-otp", authHandler.SendOTP) // authRoutes.Post("/verify-otp", authHandler.VerifyOTP) - userRepo := repositories.NewUserRepository(config.DB) - authService := services.NewAuthService(userRepo) + // userRepo := repositories.NewUserRepository(config.DB) + // authService := services.NewAuthService(userRepo) + // authHandler := handler.NewAuthHandler(authService) + + // // Routes + // api.Post("/register", authHandler.Register) + // api.Post("/verify-otp", authHandler.VerifyOTP) + userRepo := repositories.NewUserRepository(config.DB) + roleRepo := repositories.NewRoleRepository(config.DB) + redisRepo := repositories.NewRedisRepository(config.RedisClient) + + // Setup Service + authService := services.NewAuthService(userRepo, roleRepo, redisRepo) + + // Setup Handler authHandler := handler.NewAuthHandler(authService) - // Routes - api.Post("/register", authHandler.Register) + // Define Routes + api.Post("/register", authHandler.Register) // Route untuk registrasi api.Post("/verify-otp", authHandler.VerifyOTP) } diff --git a/presentation/banner_route.go b/presentation/banner_route.go index 7139c4f..411b0f0 100644 --- a/presentation/banner_route.go +++ b/presentation/banner_route.go @@ -1,13 +1,14 @@ package presentation import ( + "rijig/config" + "rijig/internal/handler" + "rijig/internal/repositories" + "rijig/internal/services" + "rijig/middleware" + "rijig/utils" + "github.com/gofiber/fiber/v2" - "github.com/pahmiudahgede/senggoldong/config" - "github.com/pahmiudahgede/senggoldong/internal/handler" - "github.com/pahmiudahgede/senggoldong/internal/repositories" - "github.com/pahmiudahgede/senggoldong/internal/services" - "github.com/pahmiudahgede/senggoldong/middleware" - "github.com/pahmiudahgede/senggoldong/utils" ) func BannerRouter(api fiber.Router) { diff --git a/presentation/initialcoint_route.go b/presentation/initialcoint_route.go index 9ef0dd5..fba9237 100644 --- a/presentation/initialcoint_route.go +++ b/presentation/initialcoint_route.go @@ -1,13 +1,14 @@ package presentation import ( + "rijig/config" + "rijig/internal/handler" + "rijig/internal/repositories" + "rijig/internal/services" + "rijig/middleware" + "rijig/utils" + "github.com/gofiber/fiber/v2" - "github.com/pahmiudahgede/senggoldong/config" - "github.com/pahmiudahgede/senggoldong/internal/handler" - "github.com/pahmiudahgede/senggoldong/internal/repositories" - "github.com/pahmiudahgede/senggoldong/internal/services" - "github.com/pahmiudahgede/senggoldong/middleware" - "github.com/pahmiudahgede/senggoldong/utils" ) func InitialCointRoute(api fiber.Router) { diff --git a/presentation/product_route.go b/presentation/product_route.go index 7afab8d..c1a74e6 100644 --- a/presentation/product_route.go +++ b/presentation/product_route.go @@ -1,13 +1,14 @@ package presentation import ( + "rijig/config" + "rijig/internal/handler" + "rijig/internal/repositories" + "rijig/internal/services" + "rijig/middleware" + "rijig/utils" + "github.com/gofiber/fiber/v2" - "github.com/pahmiudahgede/senggoldong/config" - "github.com/pahmiudahgede/senggoldong/internal/handler" - "github.com/pahmiudahgede/senggoldong/internal/repositories" - "github.com/pahmiudahgede/senggoldong/internal/services" - "github.com/pahmiudahgede/senggoldong/middleware" - "github.com/pahmiudahgede/senggoldong/utils" ) func ProductRouter(api fiber.Router) { diff --git a/presentation/role_route.go b/presentation/role_route.go index 1895e7f..b221e8f 100644 --- a/presentation/role_route.go +++ b/presentation/role_route.go @@ -1,11 +1,12 @@ package presentation import ( + "rijig/config" + "rijig/internal/handler" + "rijig/internal/repositories" + "rijig/internal/services" + "github.com/gofiber/fiber/v2" - "github.com/pahmiudahgede/senggoldong/config" - "github.com/pahmiudahgede/senggoldong/internal/handler" - "github.com/pahmiudahgede/senggoldong/internal/repositories" - "github.com/pahmiudahgede/senggoldong/internal/services" ) func RoleRouter(api fiber.Router) { diff --git a/presentation/store_route.go b/presentation/store_route.go index 085deab..fd6c6e9 100644 --- a/presentation/store_route.go +++ b/presentation/store_route.go @@ -1,13 +1,14 @@ package presentation import ( + "rijig/config" + "rijig/internal/handler" + "rijig/internal/repositories" + "rijig/internal/services" + "rijig/middleware" + "rijig/utils" + "github.com/gofiber/fiber/v2" - "github.com/pahmiudahgede/senggoldong/config" - "github.com/pahmiudahgede/senggoldong/internal/handler" - "github.com/pahmiudahgede/senggoldong/internal/repositories" - "github.com/pahmiudahgede/senggoldong/internal/services" - "github.com/pahmiudahgede/senggoldong/middleware" - "github.com/pahmiudahgede/senggoldong/utils" ) func StoreRouter(api fiber.Router) { diff --git a/presentation/trash_route.go b/presentation/trash_route.go index 5e5eb59..064bf98 100644 --- a/presentation/trash_route.go +++ b/presentation/trash_route.go @@ -1,13 +1,14 @@ package presentation import ( + "rijig/config" + "rijig/internal/handler" + "rijig/internal/repositories" + "rijig/internal/services" + "rijig/middleware" + "rijig/utils" + "github.com/gofiber/fiber/v2" - "github.com/pahmiudahgede/senggoldong/config" - "github.com/pahmiudahgede/senggoldong/internal/handler" - "github.com/pahmiudahgede/senggoldong/internal/repositories" - "github.com/pahmiudahgede/senggoldong/internal/services" - "github.com/pahmiudahgede/senggoldong/middleware" - "github.com/pahmiudahgede/senggoldong/utils" ) func TrashRouter(api fiber.Router) { diff --git a/presentation/user_route.go b/presentation/user_route.go index 2e54a2e..86277eb 100644 --- a/presentation/user_route.go +++ b/presentation/user_route.go @@ -1,12 +1,13 @@ package presentation import ( + "rijig/config" + "rijig/internal/handler" + "rijig/internal/repositories" + "rijig/internal/services" + "rijig/middleware" + "github.com/gofiber/fiber/v2" - "github.com/pahmiudahgede/senggoldong/config" - "github.com/pahmiudahgede/senggoldong/internal/handler" - "github.com/pahmiudahgede/senggoldong/internal/repositories" - "github.com/pahmiudahgede/senggoldong/internal/services" - "github.com/pahmiudahgede/senggoldong/middleware" ) func UserProfileRouter(api fiber.Router) { diff --git a/presentation/userpin_route.go b/presentation/userpin_route.go index 3f1a8ee..15dea4d 100644 --- a/presentation/userpin_route.go +++ b/presentation/userpin_route.go @@ -1,12 +1,13 @@ package presentation import ( + "rijig/config" + "rijig/internal/handler" + "rijig/internal/repositories" + "rijig/internal/services" + "rijig/middleware" + "github.com/gofiber/fiber/v2" - "github.com/pahmiudahgede/senggoldong/config" - "github.com/pahmiudahgede/senggoldong/internal/handler" - "github.com/pahmiudahgede/senggoldong/internal/repositories" - "github.com/pahmiudahgede/senggoldong/internal/services" - "github.com/pahmiudahgede/senggoldong/middleware" ) func UserPinRouter(api fiber.Router) { diff --git a/presentation/wilayahindonesia_route.go b/presentation/wilayahindonesia_route.go index 12aa1d4..9eb1ffa 100644 --- a/presentation/wilayahindonesia_route.go +++ b/presentation/wilayahindonesia_route.go @@ -1,13 +1,14 @@ package presentation import ( + "rijig/config" + "rijig/internal/handler" + "rijig/internal/repositories" + "rijig/internal/services" + "rijig/middleware" + "rijig/utils" + "github.com/gofiber/fiber/v2" - "github.com/pahmiudahgede/senggoldong/config" - "github.com/pahmiudahgede/senggoldong/internal/handler" - "github.com/pahmiudahgede/senggoldong/internal/repositories" - "github.com/pahmiudahgede/senggoldong/internal/services" - "github.com/pahmiudahgede/senggoldong/middleware" - "github.com/pahmiudahgede/senggoldong/utils" ) func WilayahRouter(api fiber.Router) { @@ -16,20 +17,20 @@ func WilayahRouter(api fiber.Router) { wilayahService := services.NewWilayahIndonesiaService(wilayahRepo) wilayahHandler := handler.NewWilayahImportHandler(wilayahService) - api.Post("/import/data-wilayah-indonesia", middleware.AuthMiddleware, middleware.RoleMiddleware(utils.RoleAdministrator), wilayahHandler.ImportWilayahData) + api.Post("/import/data-wilayah-indonesia", middleware.RoleMiddleware(utils.RoleAdministrator), wilayahHandler.ImportWilayahData) wilayahAPI := api.Group("/wilayah-indonesia") - wilayahAPI.Get("/provinces", middleware.AuthMiddleware, wilayahHandler.GetProvinces) - wilayahAPI.Get("/provinces/:provinceid", middleware.AuthMiddleware, wilayahHandler.GetProvinceByID) + wilayahAPI.Get("/provinces", wilayahHandler.GetProvinces) + wilayahAPI.Get("/provinces/:provinceid", wilayahHandler.GetProvinceByID) - wilayahAPI.Get("/regencies", middleware.AuthMiddleware, wilayahHandler.GetAllRegencies) - wilayahAPI.Get("/regencies/:regencyid", middleware.AuthMiddleware, wilayahHandler.GetRegencyByID) + wilayahAPI.Get("/regencies", wilayahHandler.GetAllRegencies) + wilayahAPI.Get("/regencies/:regencyid", wilayahHandler.GetRegencyByID) - wilayahAPI.Get("/districts", middleware.AuthMiddleware, wilayahHandler.GetAllDistricts) - wilayahAPI.Get("/districts/:districtid", middleware.AuthMiddleware, wilayahHandler.GetDistrictByID) + wilayahAPI.Get("/districts", wilayahHandler.GetAllDistricts) + wilayahAPI.Get("/districts/:districtid", wilayahHandler.GetDistrictByID) - wilayahAPI.Get("/villages", middleware.AuthMiddleware, wilayahHandler.GetAllVillages) - wilayahAPI.Get("/villages/:villageid", middleware.AuthMiddleware, wilayahHandler.GetVillageByID) + wilayahAPI.Get("/villages", wilayahHandler.GetAllVillages) + wilayahAPI.Get("/villages/:villageid", wilayahHandler.GetVillageByID) } diff --git a/router/setup_routes.go.go b/router/setup_routes.go.go index 3885718..ef85491 100644 --- a/router/setup_routes.go.go +++ b/router/setup_routes.go.go @@ -3,9 +3,10 @@ package router import ( "os" + "rijig/middleware" + "rijig/presentation" + "github.com/gofiber/fiber/v2" - "github.com/pahmiudahgede/senggoldong/middleware" - "github.com/pahmiudahgede/senggoldong/presentation" ) func SetupRoutes(app *fiber.App) { diff --git a/utils/redis_caching.go b/utils/redis_caching.go index 0cbf2ff..99d4e8c 100644 --- a/utils/redis_caching.go +++ b/utils/redis_caching.go @@ -7,8 +7,9 @@ import ( "log" "time" + "rijig/config" + "github.com/go-redis/redis/v8" - "github.com/pahmiudahgede/senggoldong/config" ) var ctx = context.Background() @@ -137,4 +138,4 @@ func GetOTPFromRedis(phone string) (string, error) { return "", fmt.Errorf("failed to get OTP from Redis: %v", err) } return otpCode, nil -} \ No newline at end of file +}