feat/authentication

+ moved pkg/auth-helper to internal/lib/auth
+ update AuthInfo
+ cleaning
This commit is contained in:
2025-10-26 21:29:41 +07:00
parent b5b0a8183d
commit 2c432a7bef
33 changed files with 227 additions and 121 deletions
-15
View File
@@ -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
}
-87
View File
@@ -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)
}