Skip to content

Commit

Permalink
refactoring code base
Browse files Browse the repository at this point in the history
  • Loading branch information
GenesisBlock3301 committed Mar 17, 2024
1 parent de2639b commit de20da1
Show file tree
Hide file tree
Showing 17 changed files with 207 additions and 472 deletions.
2 changes: 1 addition & 1 deletion backend/configurations/db/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package db

import (
"fmt"
"github.com/GenesisBlock3301/role_based_access_boilerplate_go/backend/configurations"
"github.com/go_user_role/backend/configurations"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
Expand Down
4 changes: 2 additions & 2 deletions backend/controllers/role_controller.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package controllers

import (
"github.com/GenesisBlock3301/role_based_access_boilerplate_go/backend/serializers"
"github.com/GenesisBlock3301/role_based_access_boilerplate_go/backend/services"
"github.com/gin-gonic/gin"
"github.com/go_user_role/backend/serializers"
"github.com/go_user_role/backend/services"
"net/http"
)

Expand Down
23 changes: 12 additions & 11 deletions backend/controllers/user_controller.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package controllers

import (
"github.com/GenesisBlock3301/role_based_access_boilerplate_go/backend/configurations"
"github.com/GenesisBlock3301/role_based_access_boilerplate_go/backend/serializers"
"github.com/GenesisBlock3301/role_based_access_boilerplate_go/backend/services"
"github.com/GenesisBlock3301/role_based_access_boilerplate_go/backend/utils"
"github.com/GenesisBlock3301/role_based_access_boilerplate_go/backend/validations"
"github.com/diebietse/gotp/v2"
_ "github.com/diebietse/gotp/v2"
"github.com/gin-gonic/gin"
"github.com/go-playground/validator/v10"
"github.com/go_user_role/backend/configurations"
"github.com/go_user_role/backend/serializers"
"github.com/go_user_role/backend/services"
"github.com/go_user_role/backend/utils"
"github.com/go_user_role/backend/validations"
"net/http"
"time"
)
Expand All @@ -33,7 +34,7 @@ func NewUserController(service services.UserService) *UserController {
// @Produce json
// @Success 200 {string} successfully login
// @failure 400 {string} string "error"
// @Router /create [post]
// @Router /user/create [post]
func (u *UserController) CreateUserController(ctx *gin.Context) {
var userInput serializers.RegisterSerializer
// Validate UserInput
Expand Down Expand Up @@ -66,7 +67,7 @@ func (u *UserController) CreateUserController(ctx *gin.Context) {
// @Produce json
// @Success 200 {string} successfully login.
// @failure 400 {string} string "error"
// @Router /login [post]
// @Router /user/login [post]
func (u *UserController) LoginController(ctx *gin.Context) {
var user serializers.User
if err := ctx.ShouldBindJSON(&user); err != nil {
Expand Down Expand Up @@ -101,7 +102,7 @@ func (u *UserController) LoginController(ctx *gin.Context) {
// @Accept json
// @Produce json
// @Success 200 {string} get user successfully.
// @Router / [get]
// @Router /user [get]
func (u *UserController) GetCurrentUserController(ctx *gin.Context) {
userId, err := services.ExtractTokenID(ctx)
if err != nil {
Expand Down Expand Up @@ -130,7 +131,7 @@ func (u *UserController) GetCurrentUserController(ctx *gin.Context) {
// @Accept json
// @Produce json
// @Success 200 {string} successfully verify email.
// @Router /email-verify/ [get]
// @Router /user/email-verify [get]
func (u *UserController) VerifyEmailController(ctx *gin.Context) {
token := ctx.Query("token")

Expand All @@ -153,7 +154,7 @@ func (u *UserController) VerifyEmailController(ctx *gin.Context) {
// @Accept json
// @Produce json
// @Success 200 {string} successfully generate OTP
// @Router /generate-otp/ [get]
// @Router /user/generate-otp [get]
func (u *UserController) GenerateOTP(ctx *gin.Context) {
var UserLogin serializers.LoginSerializer
// Validate UserInput
Expand Down Expand Up @@ -186,7 +187,7 @@ func (u *UserController) GenerateOTP(ctx *gin.Context) {
// @Accept json
// @Produce json
// @Success 200 {string} sent verify init.
// @Router /verify-otp/ [get]
// @Router /user/verify-otp [get]
func (u *UserController) VerifyOTP(ctx *gin.Context) {
var otp serializers.VerifyOTPSerializer
// Validate OTP Input.
Expand Down
2 changes: 1 addition & 1 deletion backend/middlewares/auth-middleware.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package middlewares

import (
"github.com/GenesisBlock3301/role_based_access_boilerplate_go/backend/services"
"github.com/gin-gonic/gin"
"github.com/go_user_role/backend/services"
"net/http"
"os"
)
Expand Down
4 changes: 2 additions & 2 deletions backend/routes/roles_router.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package routes

import (
"github.com/GenesisBlock3301/role_based_access_boilerplate_go/backend/controllers"
"github.com/GenesisBlock3301/role_based_access_boilerplate_go/backend/services"
"github.com/gin-gonic/gin"
"github.com/go_user_role/backend/controllers"
"github.com/go_user_role/backend/services"
)

func RoleRouter(roleRouter *gin.RouterGroup) {
Expand Down
7 changes: 3 additions & 4 deletions backend/routes/user_router.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package routes

import (
"github.com/GenesisBlock3301/role_based_access_boilerplate_go/backend/controllers"
"github.com/GenesisBlock3301/role_based_access_boilerplate_go/backend/middlewares"
"github.com/GenesisBlock3301/role_based_access_boilerplate_go/backend/services"
"github.com/gin-gonic/gin"
"github.com/go_user_role/backend/controllers"
"github.com/go_user_role/backend/services"
)

func UserRouter(userRouter *gin.RouterGroup) {
userService := &services.UserService{}
userController := controllers.NewUserController(*userService)
userRouter.GET("/", middlewares.JWTAuthMiddleware(), userController.GetCurrentUserController)
userRouter.GET("/", userController.GetCurrentUserController)
userRouter.POST("/create/", userController.CreateUserController)
userRouter.GET("/email-verify/", userController.VerifyEmailController)
userRouter.POST("/login", userController.LoginController)
Expand Down
17 changes: 0 additions & 17 deletions backend/services/jwt_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,6 @@ func ExtractTokenID(c *gin.Context) (uint, error) {
}
return []byte("secret_no_sifat"), nil
})
//if err != nil {
// if ve, ok := err.(*jwt.ValidationError); ok {
// if ve.Errors&jwt.ValidationErrorExpired != 0 {
// // Token has expired
// fmt.Println("Token has expired")
// }
// } else {
// // Other validation error occurred
// fmt.Println("Error validating token:", err)
// }
//} else if token.Valid {
// // Token is valid
// fmt.Println("Token is valid")
//} else {
// // Token is not valid for some other reason
// fmt.Println("Token is not valid")
//}
if err != nil {
return 0, err
}
Expand Down
4 changes: 2 additions & 2 deletions backend/services/mail_service.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package services

import (
"github.com/GenesisBlock3301/role_based_access_boilerplate_go/backend/configurations"
"github.com/GenesisBlock3301/role_based_access_boilerplate_go/backend/serializers"
"github.com/go_user_role/backend/configurations"
"github.com/go_user_role/backend/serializers"
"net/smtp"
"os"
)
Expand Down
6 changes: 3 additions & 3 deletions backend/services/role_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package services

import (
"errors"
"github.com/GenesisBlock3301/role_based_access_boilerplate_go/backend/configurations/db"
"github.com/GenesisBlock3301/role_based_access_boilerplate_go/backend/schemas"
"github.com/GenesisBlock3301/role_based_access_boilerplate_go/backend/serializers"
"github.com/go_user_role/backend/configurations/db"
"github.com/go_user_role/backend/schemas"
"github.com/go_user_role/backend/serializers"
"log"
"strconv"
)
Expand Down
10 changes: 5 additions & 5 deletions backend/services/user_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package services

import (
"errors"
"github.com/GenesisBlock3301/role_based_access_boilerplate_go/backend/configurations"
"github.com/GenesisBlock3301/role_based_access_boilerplate_go/backend/configurations/db"
"github.com/GenesisBlock3301/role_based_access_boilerplate_go/backend/schemas"
"github.com/GenesisBlock3301/role_based_access_boilerplate_go/backend/serializers"
"github.com/GenesisBlock3301/role_based_access_boilerplate_go/backend/utils"
"github.com/dgrijalva/jwt-go"
"github.com/go_user_role/backend/configurations"
"github.com/go_user_role/backend/configurations/db"
"github.com/go_user_role/backend/schemas"
"github.com/go_user_role/backend/serializers"
"github.com/go_user_role/backend/utils"
)

type IUserServiceInterface interface {
Expand Down
8 changes: 4 additions & 4 deletions backend/utils/auth_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package utils

import (
"errors"
"github.com/GenesisBlock3301/role_based_access_boilerplate_go/backend/configurations"
"github.com/GenesisBlock3301/role_based_access_boilerplate_go/backend/configurations/db"
"github.com/GenesisBlock3301/role_based_access_boilerplate_go/backend/schemas"
"github.com/GenesisBlock3301/role_based_access_boilerplate_go/backend/serializers"
"github.com/dgrijalva/jwt-go"
"github.com/go_user_role/backend/configurations"
"github.com/go_user_role/backend/configurations/db"
"github.com/go_user_role/backend/schemas"
"github.com/go_user_role/backend/serializers"
"golang.org/x/crypto/bcrypt"
)

Expand Down
122 changes: 61 additions & 61 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,62 @@ const docTemplate = `{
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/": {
"/role/create": {
"post": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Role"
],
"summary": "Create Role.",
"parameters": [
{
"description": "Role Info",
"name": "role",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/serializers.Role"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "string"
}
}
}
}
},
"/role/list": {
"get": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Role"
],
"summary": "GET roles.",
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "string"
}
}
}
}
},
"/user": {
"get": {
"description": "do ping",
"consumes": [
Expand All @@ -47,7 +102,7 @@ const docTemplate = `{
}
}
},
"/create": {
"/user/create": {
"post": {
"description": "User Registration",
"consumes": [
Expand Down Expand Up @@ -87,7 +142,7 @@ const docTemplate = `{
}
}
},
"/email-verify/": {
"/user/email-verify": {
"get": {
"consumes": [
"application/json"
Expand Down Expand Up @@ -119,7 +174,7 @@ const docTemplate = `{
}
}
},
"/generate-otp/": {
"/user/generate-otp": {
"get": {
"consumes": [
"application/json"
Expand Down Expand Up @@ -152,7 +207,7 @@ const docTemplate = `{
}
}
},
"/login": {
"/user/login": {
"post": {
"description": "User login",
"consumes": [
Expand Down Expand Up @@ -192,62 +247,7 @@ const docTemplate = `{
}
}
},
"/role/create": {
"post": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Role"
],
"summary": "Create Role.",
"parameters": [
{
"description": "Role Info",
"name": "role",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/serializers.Role"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "string"
}
}
}
}
},
"/role/list": {
"get": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Role"
],
"summary": "GET roles.",
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "string"
}
}
}
}
},
"/verify-otp/": {
"/user/verify-otp": {
"get": {
"consumes": [
"application/json"
Expand Down
Loading

0 comments on commit de20da1

Please sign in to comment.