Move server to sub-folder

This commit is contained in:
Jan Zípek 2022-08-21 19:33:30 +02:00
parent 37efde7281
commit f2d1de9b31
Signed by: kamen
GPG Key ID: A17882625B33AC31
17 changed files with 23 additions and 0 deletions

View File

View File

@ -0,0 +1,17 @@
package services
import "github.com/gin-gonic/gin"
type AuthService struct {
ctx *Context
}
func (s *AuthService) FromContext(ctx *gin.Context) (*User, error) {
session, err := s.ctx.Services.Sessions.FromContext(ctx)
if err != nil {
return nil, err
}
return s.ctx.Services.Users.GetById(session.UserId)
}

View File

@ -9,6 +9,9 @@ type Services struct {
SensorConfig *SensorConfigService SensorConfig *SensorConfigService
SensorValues *SensorValuesService SensorValues *SensorValuesService
Sensors *SensorsService Sensors *SensorsService
Sessions *SessionsService
Users *UsersService
Auth *AuthService
} }
type Context struct { type Context struct {
@ -25,6 +28,9 @@ func InitializeServices(ctx *Context) *Services {
services.SensorConfig = &SensorConfigService{ctx: ctx} services.SensorConfig = &SensorConfigService{ctx: ctx}
services.SensorValues = &SensorValuesService{ctx: ctx} services.SensorValues = &SensorValuesService{ctx: ctx}
services.Sensors = &SensorsService{ctx: ctx} services.Sensors = &SensorsService{ctx: ctx}
services.Sessions = &SessionsService{ctx: ctx}
services.Auth = &AuthService{ctx: ctx}
services.Users = &UsersService{ctx: ctx}
return &services return &services
} }