-
Notifications
You must be signed in to change notification settings - Fork 0
/
todo.go
57 lines (43 loc) · 1.4 KB
/
todo.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
46
47
48
49
50
51
52
53
54
55
56
57
package services
import (
"context"
"github.com/joaoh82/buildingapi/entities"
"github.com/joaoh82/buildingapi/interfaces"
"github.com/joaoh82/buildingapi/utils"
)
type todoService struct {
todoRepository interfaces.TodoRepository
}
func NewTodoService(todoRepository interfaces.TodoRepository) interfaces.TodoService {
return &todoService{
todoRepository: todoRepository,
}
}
func (service *todoService) Find(ctx context.Context) ([]entities.Todo, error) {
ctx, span := utils.StartSpan(ctx)
defer span.End()
return service.todoRepository.Find(ctx)
}
func (service *todoService) FindByID(ctx context.Context, id uint) (entities.Todo, error) {
ctx, span := utils.StartSpan(ctx)
defer span.End()
return service.todoRepository.FindByID(ctx, id)
}
func (service *todoService) Create(ctx context.Context, name string) (entities.Todo, error) {
ctx, span := utils.StartSpan(ctx)
defer span.End()
todo := entities.NewTodo(name)
err := service.todoRepository.Create(ctx, &todo)
return todo, err
}
func (service *todoService) Update(ctx context.Context, id uint, name string) error {
ctx, span := utils.StartSpan(ctx)
defer span.End()
updateData := entities.Todo{Name: name}
return service.todoRepository.Update(ctx, id, updateData)
}
func (service *todoService) Delete(ctx context.Context, id uint) error {
ctx, span := utils.StartSpan(ctx)
defer span.End()
return service.todoRepository.Delete(ctx, id)
}