-
Notifications
You must be signed in to change notification settings - Fork 48
/
UserController.go
42 lines (33 loc) · 1.23 KB
/
UserController.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package controller
import (
"go-api-boilerplate/logger"
"go-api-boilerplate/model/repository"
"go-api-boilerplate/model/service"
"github.com/gin-gonic/gin"
)
type UserListParametersHydrator struct {
*BaseParametersHydrator
}
func NewUserListParametersHydrator(logger *logger.Logger) ParametersHydratorInterface {
base := NewBaseParametersHydrator(logger).(*BaseParametersHydrator)
return &UserListParametersHydrator{BaseParametersHydrator: base}
}
func (c UserListParametersHydrator) Hydrate(context *gin.Context) (repository.ListParametersInterface, error) {
crudParams, _ := c.BaseParametersHydrator.Hydrate(context)
parameters := &repository.UserListParameters{
CrudListParameters: crudParams.(*repository.CrudListParameters),
}
if err := context.ShouldBindQuery(parameters); err != nil {
return crudParams, err
}
return parameters, nil
}
type UserController struct {
*CrudController
service service.UserServiceInterface
}
func NewUserController(service service.UserServiceInterface, logger *logger.Logger) *UserController {
parametersHydrator := NewUserListParametersHydrator(logger)
controller := NewCrudController(service, parametersHydrator, logger)
return &UserController{CrudController: controller, service: service}
}