feat/authentication
+ moved pkg/auth-helper to internal/lib/auth + update AuthInfo + cleaning
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
package authhelper
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func GetAuthInfo(r *http.Request) (*AuthInfo, error) {
|
||||
ctxVal := r.Context().Value(AuthKey{})
|
||||
if ctxVal == nil {
|
||||
return nil, errors.New("can't get auth info")
|
||||
}
|
||||
authInfo := ctxVal.(*AuthInfo)
|
||||
return authInfo, nil
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
package authhelper
|
||||
|
||||
import (
|
||||
ero "simrs-vx/internal/domain/references/organization"
|
||||
)
|
||||
|
||||
type AuthKey struct{}
|
||||
|
||||
type AuthInfo struct {
|
||||
Uuid string
|
||||
User_Id uint
|
||||
User_Name string
|
||||
User_ContractPosition_code string
|
||||
Employee_Position_Code *string
|
||||
Intern_Position_Code *string
|
||||
User_DivisionPositions []DivisionPosition
|
||||
// User_DivisionPositions []DivisionPosition
|
||||
// User_Position_Code string
|
||||
}
|
||||
|
||||
type DivisionPosition struct {
|
||||
Division_Code string `json:"division_code"`
|
||||
DivisionPosition_Code string `json:"divisionPosition_code"`
|
||||
}
|
||||
|
||||
func (a AuthInfo) IsDoctor() bool {
|
||||
if a.Employee_Position_Code == nil {
|
||||
return false
|
||||
}
|
||||
return *a.Employee_Position_Code == string(ero.EPCDoc)
|
||||
}
|
||||
|
||||
func (a AuthInfo) IsNurse() bool {
|
||||
if a.Employee_Position_Code == nil {
|
||||
return false
|
||||
}
|
||||
return *a.Employee_Position_Code == string(ero.EPCNur)
|
||||
}
|
||||
|
||||
func (a AuthInfo) IsNutritionist() bool {
|
||||
if a.Employee_Position_Code == nil {
|
||||
return false
|
||||
}
|
||||
return *a.Employee_Position_Code == string(ero.EPCNut)
|
||||
}
|
||||
|
||||
func (a AuthInfo) IsLaborant() bool {
|
||||
if a.Employee_Position_Code == nil {
|
||||
return false
|
||||
}
|
||||
return *a.Employee_Position_Code == string(ero.EPCLab)
|
||||
}
|
||||
|
||||
func (a AuthInfo) IsPharmacist() bool {
|
||||
if a.Employee_Position_Code == nil {
|
||||
return false
|
||||
}
|
||||
return *a.Employee_Position_Code == string(ero.EPCPha)
|
||||
}
|
||||
|
||||
func (a AuthInfo) IsPayment() bool {
|
||||
if a.Employee_Position_Code == nil {
|
||||
return false
|
||||
}
|
||||
return *a.Employee_Position_Code == string(ero.EPCPay)
|
||||
}
|
||||
|
||||
func (a AuthInfo) IsManagement() bool {
|
||||
if a.Employee_Position_Code == nil {
|
||||
return false
|
||||
}
|
||||
return *a.Employee_Position_Code == string(ero.EPCMan)
|
||||
}
|
||||
|
||||
func (a AuthInfo) IsSpecialistIntern() bool {
|
||||
if a.Intern_Position_Code == nil {
|
||||
return false
|
||||
}
|
||||
return *a.Intern_Position_Code == string(ero.IPCSpecialist)
|
||||
}
|
||||
|
||||
func (a AuthInfo) IsNurseIntern() bool {
|
||||
if a.Intern_Position_Code == nil {
|
||||
return false
|
||||
}
|
||||
return *a.Intern_Position_Code == string(ero.IPCNurse)
|
||||
}
|
||||
Reference in New Issue
Block a user