-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_task_undone.go
51 lines (40 loc) · 1.17 KB
/
update_task_undone.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
package usecase
import (
"context"
"github.com/tiagompalte/golang-clean-arch-template/internal/app/repository"
pkgErrors "github.com/tiagompalte/golang-clean-arch-template/internal/pkg/errors"
"github.com/tiagompalte/golang-clean-arch-template/pkg/errors"
)
type UpdateTaskUndoneUseCase interface {
Execute(ctx context.Context, input UpdateTaskUndoneUseCaseInput) error
}
type UpdateTaskUndoneUseCaseInput struct {
UUID string
UserID uint32
}
type UpdateTaskUndoneUseCaseImpl struct {
taskRepository repository.TaskRepository
}
func NewUpdateTaskUndoneUseCaseImpl(taskRepository repository.TaskRepository) UpdateTaskUndoneUseCase {
return UpdateTaskUndoneUseCaseImpl{
taskRepository: taskRepository,
}
}
func (u UpdateTaskUndoneUseCaseImpl) Execute(ctx context.Context, input UpdateTaskUndoneUseCaseInput) error {
task, err := u.taskRepository.FindByUUID(ctx, input.UUID)
if err != nil {
return errors.Wrap(err)
}
if input.UserID != task.UserID {
return errors.Wrap(pkgErrors.NewInvalidUserError())
}
if !task.Done {
return nil
}
task.Done = false
err = u.taskRepository.UpdateDone(ctx, task)
if err != nil {
return errors.Wrap(err)
}
return nil
}