-
Notifications
You must be signed in to change notification settings - Fork 0
/
Task.service.go
43 lines (33 loc) · 1.45 KB
/
Task.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
package services
import (
"net/http"
axonlogger "github.com/cognitive-neuroscience/neuron/src/logger"
"github.com/cognitive-neuroscience/neuron/src/models"
)
type TaskService struct{}
// GetAllTasks returns all tasks
// It returns a 200 or 500 status code.
func (t *TaskService) GetAllTasks() ([]models.Task, models.HTTPStatus) {
axonlogger.InfoLogger.Println("TASK SERVICE: GetAllTasks()")
return taskRespositoryImpl.GetAllTasks()
}
// GetTaskById returns a task with the given id
// It returns a 200, 404, or 500
func (t *TaskService) GetTaskById(taskId string) (models.Task, models.HTTPStatus) {
axonlogger.InfoLogger.Println("TASK SERVICE: GetTaskById()")
parsedTaskId, error := convertStringToUint8(taskId)
if error != nil {
return models.Task{}, models.HTTPStatus{Status: http.StatusInternalServerError, Message: http.StatusText(http.StatusInternalServerError)}
}
return taskRespositoryImpl.GetTaskById(parsedTaskId)
}
// GetAllTasksByStudyId gets all tasks for a given study id.
// It returns a 200 or 500
func (t *TaskService) GetAllTasksByStudyId(studyId string) ([]models.Task, models.HTTPStatus) {
axonlogger.InfoLogger.Println("TASK SERVICE: GetAllTasksByStudyId()")
parsedStudyId, error := convertStringToUint8(studyId)
if error != nil {
return []models.Task{}, models.HTTPStatus{Status: http.StatusInternalServerError, Message: http.StatusText(http.StatusInternalServerError)}
}
return taskRespositoryImpl.GetAllTasksByStudyId(parsedStudyId)
}