sqlx
This commit is contained in:
@@ -13,28 +13,25 @@ import (
|
||||
type AuditLogRepository interface {
|
||||
Create(ctx context.Context, obj *AuditLog) error
|
||||
BatchCreate(ctx context.Context, objs []*AuditLog) error
|
||||
List(ctx context.Context, q dto.SearchDto) ([]*AuditLog, int64, error)
|
||||
Count(ctx context.Context, filter dto.SearchDto) (int64, error)
|
||||
List(ctx context.Context, q dto.SearchDto) ([]*AuditLog, error)
|
||||
}
|
||||
|
||||
type AuditLog struct {
|
||||
ID int64 `json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Email string `json:"email"`
|
||||
StartAt time.Time `json:"start_at"`
|
||||
EndAt time.Time `json:"end_at"`
|
||||
Duration string `json:"duration"`
|
||||
Url string `json:"url"`
|
||||
Method string `json:"method"`
|
||||
Parameters string `json:"parameters"`
|
||||
RefererUrl string `json:"referer_url"`
|
||||
Os string `json:"os"`
|
||||
Ip string `json:"ip"`
|
||||
Browser string `json:"browser"`
|
||||
Remark string `json:"remark"`
|
||||
}
|
||||
|
||||
func (AuditLog) TableName() string {
|
||||
return "sys_audit_log"
|
||||
ID int64 `db:"id" json:"id"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
Email string `db:"email" json:"email"`
|
||||
StartAt time.Time `db:"start_at" json:"start_at"`
|
||||
EndAt time.Time `db:"end_at" json:"end_at"`
|
||||
Duration string `db:"duration" json:"duration"`
|
||||
Url string `db:"url" json:"url"`
|
||||
Method string `db:"method" json:"method"`
|
||||
Parameters string `db:"parameters" json:"parameters"`
|
||||
RefererUrl string `db:"referer_url" json:"referer_url"`
|
||||
Os string `db:"os" json:"os"`
|
||||
Ip string `db:"ip" json:"ip"`
|
||||
Browser string `db:"browser" json:"browser"`
|
||||
Remark string `db:"remark" json:"remark"`
|
||||
}
|
||||
|
||||
func NewAuditLog(r *http.Request, email, os, browser string, start, end time.Time) *AuditLog {
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
package system
|
||||
|
||||
type Category struct {
|
||||
ID int32 `json:"id" gorm:"primaryKey;autoIncrement;not null"`
|
||||
Name string `json:"name" gorm:"type:varchar(200);not null;uniqueIndex"`
|
||||
}
|
||||
|
||||
func (Category) TableName() string {
|
||||
return "categories"
|
||||
}
|
||||
@@ -15,18 +15,14 @@ type ConfigRepository interface {
|
||||
Update(ctx context.Context, obj *Config) error
|
||||
Get(ctx context.Context, id int32) (*Config, error)
|
||||
GetByKey(ctx context.Context, key string) (*Config, error)
|
||||
GetValueByKey(ctx context.Context, key string) ([]byte, error)
|
||||
List(ctx context.Context, q dto.SearchDto) ([]*Config, int64, error)
|
||||
Count(ctx context.Context, filter dto.SearchDto) (int64, error)
|
||||
List(ctx context.Context, filter dto.SearchDto) ([]*Config, error)
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
ID int32 `json:"id" gorm:"primaryKey;autoIncrement;not null"`
|
||||
Key string `json:"key" gorm:"type:varchar(200);not null;uniqueIndex"`
|
||||
Value datatypes.JSON `json:"value" gorm:"type:jsonb;not null;"`
|
||||
CreatedAt time.Time `json:"created_at" gorm:"type:timestamptz;not null;default:'now()'"`
|
||||
UpdatedAt time.Time `json:"updated_at" gorm:"type:timestamptz;not null;default:'0001-01-01 00:00:00+8';"`
|
||||
}
|
||||
|
||||
func (Config) TableName() string {
|
||||
return "sys_config"
|
||||
ID int32 `db:"id" json:"id"`
|
||||
Key string `db:"key" json:"key"`
|
||||
Value datatypes.JSON `db:"value" json:"value"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
|
||||
}
|
||||
|
||||
@@ -13,21 +13,18 @@ type DepartmentRepository interface {
|
||||
Update(ctx context.Context, obj *Department) error
|
||||
Get(ctx context.Context, id int32) (*Department, error)
|
||||
All(ctx context.Context) ([]*Department, error)
|
||||
List(ctx context.Context, q dto.SearchDto) ([]*Department, int64, error)
|
||||
Count(ctx context.Context, filter dto.SearchDto) (int64, error)
|
||||
List(ctx context.Context, filter dto.SearchDto) ([]*Department, error)
|
||||
RebuildParentPath(ctx context.Context) error
|
||||
}
|
||||
|
||||
type Department struct {
|
||||
ID int32 `json:"id" gorm:"primaryKey;autoIncrement;not null"`
|
||||
Name string `json:"name" gorm:"type:varchar(200);not null;uniqueIndex"`
|
||||
ParentID int32 `json:"parent_id" gorm:"type:int;not null;"`
|
||||
ParentPath string `json:"parent_path" gorm:"type:varchar(500);not null;"`
|
||||
Status int32 `json:"status" gorm:"type:int;not null;default:0;"`
|
||||
Sort int32 `json:"sort" gorm:"type:int;not null;default:0;"`
|
||||
CreatedAt time.Time `json:"created_at" gorm:"type:timestamptz;not null;default:'now()'"`
|
||||
UpdatedAt time.Time `json:"updated_at" gorm:"type:timestamptz;not null;default:'0001-01-01 00:00:00+8';"`
|
||||
}
|
||||
|
||||
func (Department) TableName() string {
|
||||
return "sys_department"
|
||||
ID int32 `db:"id" json:"id"`
|
||||
Name string `db:"name" json:"name"`
|
||||
ParentID int32 `db:"parent_id" json:"parent_id"`
|
||||
ParentPath string `db:"parent_path" json:"parent_path"`
|
||||
Status int32 `db:"status" json:"status"`
|
||||
Sort int32 `db:"sort" json:"sort"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
|
||||
}
|
||||
|
||||
@@ -10,25 +10,21 @@ import (
|
||||
type LoginLogRepository interface {
|
||||
Create(ctx context.Context, obj *LoginLog) error
|
||||
GetLatest(ctx context.Context, email string) ([]*LoginLog, error)
|
||||
List(ctx context.Context, q dto.SearchDto) ([]*LoginLog, int64, error)
|
||||
Count(ctx context.Context, email string) (int64, error)
|
||||
Count(ctx context.Context, filter dto.SearchDto) (int64, error)
|
||||
List(ctx context.Context, filter dto.SearchDto) ([]*LoginLog, error)
|
||||
}
|
||||
|
||||
type LoginLog struct {
|
||||
ID int64 `json:"id" gorm:"primaryKey;autoIncrement;not null"`
|
||||
CreatedAt time.Time `json:"created_at" gorm:"type:timestamptz;not null;default:'now()'"`
|
||||
Email string `json:"email" gorm:"type:varchar(100);not null;"`
|
||||
IsSuccess bool `json:"is_success" gorm:"type:boolean;not null;"`
|
||||
Message string `json:"message" gorm:"type:varchar(300);not null;"`
|
||||
RefererUrl string `json:"referer_url" gorm:"type:varchar(500);not null;"`
|
||||
Url string `json:"url" gorm:"type:varchar(500);not null;"`
|
||||
Os string `json:"os" gorm:"type:varchar(50);not null;"`
|
||||
Ip string `json:"ip" gorm:"type:varchar(20);not null;"`
|
||||
Browser string `json:"browser" gorm:"type:varchar(100);not null;"`
|
||||
}
|
||||
|
||||
func (*LoginLog) TableName() string {
|
||||
return "sys_user_login_log"
|
||||
ID int64 `db:"id" json:"id"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
Email string `db:"email" json:"email"`
|
||||
IsSuccess bool `db:"is_success" json:"is_success"`
|
||||
Message string `db:"message" json:"message"`
|
||||
RefererUrl string `db:"referer_url" json:"referer_url"`
|
||||
Url string `db:"url" json:"url"`
|
||||
Os string `db:"os" json:"os"`
|
||||
Ip string `db:"ip" json:"ip"`
|
||||
Browser string `db:"browser" json:"browser"`
|
||||
}
|
||||
|
||||
func NewLoginLog(email, os, ip, browser, url, referer string) *LoginLog {
|
||||
|
||||
@@ -12,27 +12,24 @@ type MenuRepository interface {
|
||||
Get(ctx context.Context, id int32) (*Menu, error)
|
||||
GetByUrl(ctx context.Context, url string) (*Menu, error)
|
||||
All(ctx context.Context) ([]*Menu, error)
|
||||
Count(ctx context.Context) (int64, error)
|
||||
RebuildParentPath(ctx context.Context) error
|
||||
}
|
||||
|
||||
type Menu struct {
|
||||
ID int32 `json:"id" gorm:"primaryKey;autoIncrement;not null"`
|
||||
Name string `json:"name" gorm:"type:varchar(200);not null;uniqueIndex"`
|
||||
DisplayName string `json:"display_name" gorm:"type:varchar(200);not null;uniqueIndex"`
|
||||
Url string `json:"url" gorm:"type:varchar(200);not null;"`
|
||||
Type string `json:"type" gorm:"type:varchar(50);not null;"`
|
||||
ParentID int32 `json:"parent_id" gorm:"type:int;not null;"`
|
||||
ParentPath string `json:"parent_path" gorm:"type:varchar(500);not null;"`
|
||||
Avatar string `json:"avatar" gorm:"type:varchar(100);not null;"`
|
||||
Style string `json:"style" gorm:"type:varchar(100);not null;"`
|
||||
Visible bool `json:"visible" gorm:"type:boolean;not null;"`
|
||||
IsList bool `json:"is_list" gorm:"type:boolean;not null;"`
|
||||
Status int32 `json:"status" gorm:"type:int;not null;default:0;"`
|
||||
Sort int32 `json:"sort" gorm:"type:int;not null;default:0;"`
|
||||
CreatedAt time.Time `json:"created_at" gorm:"type:timestamptz;not null;default:'now()'"`
|
||||
UpdatedAt time.Time `json:"updated_at" gorm:"type:timestamptz;not null;default:'0001-01-01 00:00:00+8';"`
|
||||
}
|
||||
|
||||
func (Menu) TableName() string {
|
||||
return "sys_menu"
|
||||
ID int32 `db:"id" json:"id"`
|
||||
Name string `db:"name" json:"name"`
|
||||
DisplayName string `db:"display_name" json:"display_name"`
|
||||
Url string `db:"url" json:"url"`
|
||||
Type string `db:"type" json:"type"`
|
||||
ParentID int32 `db:"parent_id" json:"parent_id"`
|
||||
ParentPath string `db:"parent_path" json:"parent_path"`
|
||||
Avatar string `db:"avatar" json:"avatar"`
|
||||
Style string `db:"style" json:"style"`
|
||||
Visible bool `db:"visible" json:"visible"`
|
||||
IsList bool `db:"is_list" json:"is_list"`
|
||||
Status int32 `db:"status" json:"status"`
|
||||
Sort int32 `db:"sort" json:"sort"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
|
||||
}
|
||||
|
||||
@@ -12,24 +12,22 @@ type RoleRepository interface {
|
||||
Create(ctx context.Context, obj *Role) error
|
||||
Update(ctx context.Context, obj *Role) error
|
||||
Get(ctx context.Context, id int32) (*Role, error)
|
||||
GetByVip(ctx context.Context, vip bool) (*Role, error)
|
||||
All(ctx context.Context) ([]*Role, error)
|
||||
List(ctx context.Context, q dto.SearchDto) ([]*Role, int64, error)
|
||||
Count(ctx context.Context, filter dto.SearchDto) (int64, error)
|
||||
List(ctx context.Context, filter dto.SearchDto) ([]*Role, error)
|
||||
RebuildParentPath(ctx context.Context) error
|
||||
}
|
||||
|
||||
type Role struct {
|
||||
ID int32 `json:"id" gorm:"primaryKey;autoIncrement;not null"`
|
||||
Name string `json:"name" gorm:"type:varchar(200);not null;uniqueIndex"`
|
||||
DisplayName string `json:"display_name" gorm:"type:varchar(200);not null;uniqueIndex"`
|
||||
ParentID int32 `json:"parent_id" gorm:"type:int;not null;"`
|
||||
ParentPath string `json:"parent_path" gorm:"type:varchar(500);not null;"`
|
||||
Vip bool `json:"-" gorm:"type:boolean;not null;"`
|
||||
Status int32 `json:"status" gorm:"type:int;not null;default:0;"`
|
||||
Sort int32 `json:"sort" gorm:"type:int;not null;default:0;"`
|
||||
CreatedAt time.Time `json:"created_at" gorm:"type:timestamptz;not null;default:'now()'"`
|
||||
UpdatedAt time.Time `json:"updated_at" gorm:"type:timestamptz;not null;default:'0001-01-01 00:00:00+8';"`
|
||||
}
|
||||
|
||||
func (Role) TableName() string {
|
||||
return "sys_role"
|
||||
ID int32 `db:"id" json:"id"`
|
||||
Name string `db:"name" json:"name"`
|
||||
DisplayName string `db:"display_name" json:"display_name"`
|
||||
ParentID int32 `db:"parent_id" json:"parent_id"`
|
||||
ParentPath string `db:"parent_path" json:"parent_path"`
|
||||
Vip bool `db:"vip" json:"-"`
|
||||
Status int32 `db:"status" json:"status"`
|
||||
Sort int32 `db:"sort" json:"sort"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
|
||||
}
|
||||
|
||||
@@ -9,10 +9,6 @@ type RoleMenuRepository interface {
|
||||
}
|
||||
|
||||
type RoleMenu struct {
|
||||
RoleID int32 `json:"role_id" gorm:"primaryKey;autoIncrement:false;type:int;not null;"`
|
||||
MenuID int32 `json:"menu_id" gorm:"primaryKey;autoIncrement:false;type:int;not null;"`
|
||||
}
|
||||
|
||||
func (RoleMenu) TableName() string {
|
||||
return "sys_role_menu"
|
||||
RoleID int32 `db:"role_id" json:"role_id"`
|
||||
MenuID int32 `db:"menu_id" json:"menu_id"`
|
||||
}
|
||||
|
||||
@@ -16,29 +16,26 @@ type UserRepository interface {
|
||||
Get(ctx context.Context, id int32) (*User, error)
|
||||
GetByEmail(ctx context.Context, email string) (*User, error)
|
||||
All(ctx context.Context) ([]*User, error)
|
||||
List(ctx context.Context, q dto.SearchDto) ([]*User, int64, error)
|
||||
Count(ctx context.Context, filter dto.SearchDto) (int64, error)
|
||||
List(ctx context.Context, filter dto.SearchDto) ([]*User, error)
|
||||
}
|
||||
|
||||
type User struct {
|
||||
ID int32 `json:"id" gorm:"primaryKey;autoIncrement;not null"`
|
||||
Uuid uuid.UUID `json:"uuid" gorm:"type:uuid;not null;uniqueIndex"`
|
||||
Email string `json:"email" gorm:"type:varchar(100);not null;uniqueIndex"`
|
||||
Username string `json:"username" gorm:"type:varchar(100);not null;uniqueIndex"`
|
||||
HashedPassword []byte `json:"-" gorm:"type:bytea;not null;"`
|
||||
Salt string `json:"-" gorm:"type:varchar(20);not null;"`
|
||||
Avatar string `json:"avatar" gorm:"type:varchar(200);not null;"`
|
||||
Gender int32 `json:"gender" gorm:"type:int;not null;default:0;"`
|
||||
DepartmentID int32 `json:"department_id" gorm:"type:int;not null;default:0;"`
|
||||
RoleID int32 `json:"role_id" gorm:"type:int;not null;default:0;"`
|
||||
Status int32 `json:"status" gorm:"type:int;not null;default:0;"`
|
||||
ChangePasswordAt time.Time `json:"-" gorm:"type:timestamptz;not null;default:'0001-01-01 00:00:00+8';"`
|
||||
CreatedAt time.Time `json:"created_at" gorm:"type:timestamptz;not null;default:'now()'"`
|
||||
UpdatedAt time.Time `json:"updated_at" gorm:"type:timestamptz;not null;default:'0001-01-01 00:00:00+8';"`
|
||||
ID int32 `db:"id" json:"id"`
|
||||
Uuid uuid.UUID `db:"uuid" json:"uuid"`
|
||||
Email string `db:"email" json:"email"`
|
||||
Username string `db:"username" json:"username"`
|
||||
HashedPassword []byte `db:"hashed_password" json:"-"`
|
||||
Salt string `db:"salt" json:"-"`
|
||||
Avatar string `db:"avatar" json:"avatar"`
|
||||
Gender int32 `db:"gender" json:"gender"`
|
||||
DepartmentID int32 `db:"department_id" json:"department_id"`
|
||||
RoleID int32 `db:"role_id" json:"role_id"`
|
||||
Status int32 `db:"status" json:"status"`
|
||||
ChangePasswordAt time.Time `db:"change_password_at" json:"-"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
|
||||
|
||||
Role *Role `json:"role" gorm:"ForeignKey:RoleID"`
|
||||
Department *Department `json:"department" gorm:"ForeignKey:DepartmentID"`
|
||||
}
|
||||
|
||||
func (User) TableName() string {
|
||||
return "sys_user"
|
||||
Role *Role `json:"role"`
|
||||
Department *Department `json:"department"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user