This repository has been archived by the owner on Aug 14, 2023. It is now read-only.
/
data.go
69 lines (60 loc) · 2.05 KB
/
data.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
58
59
60
61
62
63
64
65
66
67
68
69
// the distributed package contains all the functionality for the distributed mode
// (learn more about this in the README). This is mainly the reading and writing of
// the data using as much concurrency as possible.
package distributed
import (
"github.com/72nd/acc/pkg/schema"
)
// CustomersToSave is a slice of CustomerToSave's.
type CustomersToSave []CustomerToSave
// CustomerToSave serves as the information source to save all customers and their
// projects in the repository structure.
type CustomerToSave struct {
Customer schema.Party
ProjectFiles ProjectFiles
}
// ProjectFiles is a slice of ProjectFile's.
type ProjectFiles []ProjectFile
// Projects returns all projects of all ProjectFile's.
func (p ProjectFiles) Projects() schema.Projects {
var rsl schema.Projects
for i := range p {
rsl = append(rsl, p[i].Project)
}
return rsl
}
// Expenses returns all expenses of all ProjectFile's.
func (p ProjectFiles) Expenses() schema.Expenses {
var rsl schema.Expenses
for i := range p {
rsl = append(rsl, p[i].Expenses...)
}
return rsl
}
// Invoices returns all Invoices of all ProjectFile's.
func (p ProjectFiles) Invoices() schema.Invoices {
var rsl schema.Invoices
for i := range p {
rsl = append(rsl, p[i].Invoices...)
}
return rsl
}
// ProjectFile is only used in distributed mode to store all invoices and expenses of a given
// project in the same file in the project folder. This data structure is exclusively used
// to store data in distributed mode and is not used internally.
type ProjectFile struct {
Project schema.Project `yaml:"project"`
Expenses schema.Expenses `yaml:"expenses"`
Invoices schema.Invoices `yaml:"invoices"`
}
// AbsolutePaths takes the location of the project folder and changes the relative paths
// of the assets to the correct absolute path.
func (p ProjectFile) AbsolutePaths(prjPath string) ProjectFile {
for i := range p.Expenses {
p.Expenses[i].Path = absolutPath(prjPath, p.Expenses[i].Path)
}
for i := range p.Invoices {
p.Invoices[i].Path = absolutPath(prjPath, p.Invoices[i].Path)
}
return p
}