aboutsummaryrefslogtreecommitdiffstats
path: root/timetask/fields.go
blob: fb3a026ff669c28eae670cda1719d5cf2eb21ead (plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package timetask

import "fmt"

type Client struct {
	ID       int
	Name     string
	Projects []Project
}

type Project struct {
	ID        int
	Name      string
	Modules   []Module
	Tasks     []Task
	WorkTypes []WorkType `yaml:"work_types"`
}

type Module struct {
	ID   int
	Name string
}
type Task struct {
	ID   int
	Name string
}
type WorkType struct {
	ID   int
	Name string
}

type Fields struct {
	PersonID int `yaml:"person_id"`
	Clients  []Client
}

func (f *Fields) ClientByName(client_name string) (*Client, error) {
	for _, client := range f.Clients {
		if client.Name == client_name {
			return &client, nil
		}
	}

	return nil, fmt.Errorf("Client %s not found", client_name)
}

func (c *Client) ProjectByName(project_name string) (*Project, error) {
	for _, project := range c.Projects {
		if project.Name == project_name {
			return &project, nil
		}
	}

	return nil, fmt.Errorf("Project %s not found", project_name)
}

func (p *Project) ModuleByName(module_name string) (*Module, error) {
	for _, module := range p.Modules {
		if module.Name == module_name {
			return &module, nil
		}
	}

	return nil, fmt.Errorf("Module %s not found", module_name)
}

func (p *Project) TaskByName(task_name string) (*Task, error) {
	for _, task := range p.Tasks {
		if task.Name == task_name {
			return &task, nil
		}
	}

	return nil, fmt.Errorf("Task %s not found", task_name)
}

func (p *Project) WorkTypeByName(work_type_name string) (*WorkType, error) {
	for _, work_type := range p.WorkTypes {
		if work_type.Name == work_type_name {
			return &work_type, nil
		}
	}

	return nil, fmt.Errorf("Work type %s not found", work_type_name)
}