github.com/ngocphuongnb/tetua@v0.0.7-alpha/app/entities/permission.go (about) 1 package entities 2 3 import ( 4 "net/url" 5 "strconv" 6 "time" 7 8 "github.com/ngocphuongnb/tetua/app/utils" 9 ) 10 11 // Permission is the model entity for the Permission schema. 12 type Permission struct { 13 ID int `json:"id,omitempty"` 14 CreatedAt *time.Time `json:"created_at,omitempty"` 15 UpdatedAt *time.Time `json:"updated_at,omitempty"` 16 DeletedAt *time.Time `json:"Deleted_at,omitempty"` 17 RoleID int `json:"role_id,omitempty"` 18 Action string `json:"action,omitempty" validate:"max=255"` 19 Value string `json:"value,omitempty"` 20 Role *Role `json:"role,omitempty"` 21 } 22 23 type PermissionFilter struct { 24 *Filter 25 RoleIDs []int `form:"role_ids" json:"role_ids"` 26 } 27 28 func (p *PermissionFilter) Base() string { 29 q := url.Values{} 30 if !utils.SliceContains(p.IgnoreUrlParams, "search") && p.Search != "" { 31 q.Add("q", p.Search) 32 } 33 if !utils.SliceContains(p.IgnoreUrlParams, "role") && len(p.RoleIDs) > 0 { 34 q.Add("role", strconv.Itoa(p.RoleIDs[0])) 35 } 36 37 if queryString := q.Encode(); queryString != "" { 38 return p.FilterBaseUrl() + "?" + q.Encode() 39 } 40 41 return p.FilterBaseUrl() 42 }