-
Notifications
You must be signed in to change notification settings - Fork 0
/
service.go
45 lines (38 loc) · 1.26 KB
/
service.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
43
44
45
package service
import (
"github.com/oneils/todo-app"
"github.com/oneils/todo-app/pkg/repository"
)
//go:generate mockgen -source=service.go -destination=mocks/mock.go
type Authorization interface {
CreateUser(user todo.User) (int, error)
GenerateToken(username string, password string) (string, error)
ParseToken(accessToken string) (int, error)
}
type TodoList interface {
Create(userId int, list todo.TodoList) (int, error)
GetAll(userId int) ([]todo.TodoList, error)
FindById(userId, id int) (todo.TodoList, error)
Delete(userId, id int) error
Update(userId, id int, updateListRequest todo.UpdateTodoListRequest) error
}
type TodoItem interface {
Create(userId, listId int, item todo.TodoItem) (int, error)
GetAll(userId, listId int) ([]todo.TodoItem, error)
GetById(userId, itemId int) (todo.TodoItem, error)
Delete(userId, itemId int) error
Update(userId, itemId int, input todo.UpdateItemInput) error
}
type Service struct {
Authorization
TodoList
TodoItem
}
// NewService creates a new instance of Service
func NewService(repos *repository.Repository) *Service {
return &Service{
Authorization: NewAuthService(repos.Authorization),
TodoList: NewTodoListService(repos.TodoList),
TodoItem: NewTodoItemService(repos.TodoItem, repos.TodoList),
}
}