add role based permissions

This commit is contained in:
Aditya Siregar
2025-08-19 21:29:37 +07:00
parent 7d5f061a1b
commit 6da48504fa
12 changed files with 461 additions and 12 deletions
+18
View File
@@ -0,0 +1,18 @@
package entities
import (
"time"
"github.com/google/uuid"
)
type Module struct {
ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"`
Name string `gorm:"not null" json:"name"`
Code string `gorm:"uniqueIndex;not null" json:"code"`
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
Permissions []Permission `gorm:"foreignKey:ModuleID" json:"permissions,omitempty"`
}
func (Module) TableName() string { return "modules" }
+8 -5
View File
@@ -18,11 +18,14 @@ type Role struct {
func (Role) TableName() string { return "roles" }
type Permission struct {
ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"`
Code string `gorm:"uniqueIndex;not null" json:"code"`
Description string `json:"description"`
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"`
ModuleID *uuid.UUID `gorm:"type:uuid" json:"module_id"`
Module *Module `gorm:"foreignKey:ModuleID" json:"module,omitempty"`
Action string `json:"action"`
Code string `gorm:"uniqueIndex;not null" json:"code"`
Description string `json:"description"`
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
}
func (Permission) TableName() string { return "permissions" }