-
Notifications
You must be signed in to change notification settings - Fork 0
/
cleaning.go
48 lines (41 loc) · 1.11 KB
/
cleaning.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
package config
import (
"context"
"fmt"
pbd "github.com/brotherlogic/discogs/proto"
pb "github.com/brotherlogic/gramophile/proto"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
var (
CLEANED_FIELD_NAME = "Cleaned"
)
type cleaning struct{}
func (*cleaning) GetMoves(c *pb.GramophileConfig) []*pb.FolderMove {
if c.GetCleaningConfig().GetCleaning() != pb.Mandate_NONE {
return []*pb.FolderMove{
{
Name: "move_to_cleaning_pile",
MoveFolder: "Cleaning Pile",
},
}
}
return []*pb.FolderMove{}
}
func (*cleaning) Validate(ctx context.Context, fields []*pbd.Field, c *pb.GramophileConfig) error {
if c.GetCleaningConfig().GetCleaning() != pb.Mandate_NONE {
found := false
for _, field := range fields {
if field.GetName() == CLEANED_FIELD_NAME {
found = true
}
}
if !found {
return status.Errorf(codes.FailedPrecondition, "Add a field called 'Cleaned'")
}
}
if c.GetCleaningConfig().GetCleaningGapInPlays() > 0 && c.GetCleaningConfig().GetCleaningGapInSeconds() > 0 {
return fmt.Errorf("You must set one of plays or seconds, not both")
}
return nil
}