-
Notifications
You must be signed in to change notification settings - Fork 390
/
projectrecords.go
66 lines (58 loc) · 2.42 KB
/
projectrecords.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
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package stripe
import (
"context"
"time"
"storj.io/common/uuid"
)
// ErrProjectRecordExists is error class defining that such project record already exists.
var ErrProjectRecordExists = Error.New("invoice project record already exists")
// ProjectRecordsDB is interface for working with invoice project records.
//
// architecture: Database
type ProjectRecordsDB interface {
// Create creates new invoice project record with credits spendings in the DB.
Create(ctx context.Context, records []CreateProjectRecord, start, end time.Time) error
// CreateToBeAggregated creates new to be aggregated invoice project record with credits spendings in the DB.
CreateToBeAggregated(ctx context.Context, records []CreateProjectRecord, start, end time.Time) error
// Check checks if invoice project record for specified project and billing period exists.
Check(ctx context.Context, projectID uuid.UUID, start, end time.Time) error
// Get returns record for specified project and billing period.
Get(ctx context.Context, projectID uuid.UUID, start, end time.Time) (*ProjectRecord, error)
// Consume consumes invoice project record.
Consume(ctx context.Context, id uuid.UUID) error
// ListUnapplied returns project records page with unapplied project records.
// Cursor is not included into listing results.
ListUnapplied(ctx context.Context, cursor uuid.UUID, limit int, start, end time.Time) (ProjectRecordsPage, error)
// ListToBeAggregated returns to be aggregated project records page with unapplied project records.
// Cursor is not included into listing results.
ListToBeAggregated(ctx context.Context, cursor uuid.UUID, limit int, start, end time.Time) (ProjectRecordsPage, error)
}
// CreateProjectRecord holds info needed for creation new invoice
// project record.
type CreateProjectRecord struct {
ProjectID uuid.UUID
Storage float64
Egress int64
Segments float64
}
// ProjectRecord holds project usage particular for billing period.
type ProjectRecord struct {
ID uuid.UUID
ProjectID uuid.UUID
Storage float64
Egress int64
Segments float64
PeriodStart time.Time
PeriodEnd time.Time
State int
}
// ProjectRecordsPage holds project records and
// indicates if there is more data available
// and provides cursor for next listing.
type ProjectRecordsPage struct {
Records []ProjectRecord
Next bool
Cursor uuid.UUID
}