Skip to content

Commit

Permalink
Refactor UserInterface in evo bundle
Browse files Browse the repository at this point in the history
Refactored UserInterface methods and variables in evo bundle for better semantics and accessibility. All the method names
  • Loading branch information
iesreza committed Feb 20, 2024
1 parent 5ed022f commit de04d60
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion evo.context.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Request struct {
status int
_break bool
jsonParsedBody *gjson.Result
user *UserInterface
UserInterface *UserInterface
}

type Response struct {
Expand Down
30 changes: 19 additions & 11 deletions evo.user.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ package evo
import "github.com/getevo/evo/v2/lib/generic"

func (r *Request) User() UserInterface {
if r.user == nil {
if r.UserInterface == nil {
var user = (UserInterfaceInstance).FromRequest(r)
r.user = &user
if user == nil {
user = DefaultUserInterface{}
}
r.UserInterface = &user
}
return *r.user
return *r.UserInterface
}

type DefaultUserInterface struct{}
Expand All @@ -25,35 +28,36 @@ func SetUserInterface(v UserInterface) {
}

type UserInterface interface {
Name() string
LastName() string
FullName() string
Email() string
GetFirstName() string
GetLastName() string
GetFullName() string
GetEmail() string
UUID() string
ID() uint64
Anonymous() bool
HasPermission(permission string) bool
Attributes() Attributes
Interface() interface{}
FromRequest(request *Request) UserInterface
}

func (d DefaultUserInterface) HasPermission(permission string) bool {
return true
}

func (d DefaultUserInterface) Name() string {
func (d DefaultUserInterface) GetFirstName() string {
return ""
}

func (d DefaultUserInterface) LastName() string {
func (d DefaultUserInterface) GetLastName() string {
return ""
}

func (d DefaultUserInterface) FullName() string {
func (d DefaultUserInterface) GetFullName() string {
return ""
}

func (d DefaultUserInterface) Email() string {
func (d DefaultUserInterface) GetEmail() string {
return ""
}

Expand All @@ -69,6 +73,10 @@ func (d DefaultUserInterface) Anonymous() bool {
return true
}

func (d DefaultUserInterface) Interface() interface{} {
return d
}

func (d DefaultUserInterface) FromRequest(request *Request) UserInterface {
return DefaultUserInterface{}
}
Expand Down

0 comments on commit de04d60

Please sign in to comment.