Added source and user marks to opportunities type. Any ignored errors are deferred to //nolint with a comment instead of being silently dropped
This commit is contained in:
1 parent
6e6dec68c0
commit
9b0e6dccfe
7 files changed
+65
-4
No files matched your search
@@ -1,9 +1,14 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Opportunity is a procurement opportunity (an OCDS contracting process,
|
||||
// identified by UUID) as of its latest release, with its classifications,
|
||||
// releases and the user's marks. Fields tagged db:"-" are stored in their
|
||||
// own tables.
|
||||
type Opportunity struct {
|
||||
UUID string `db:"uuid" json:"uuid"`
|
||||
UUIDType string `db:"uuid_type" json:"uuid_type"`
|
||||
@@ -22,8 +27,10 @@ type Opportunity struct {
|
||||
EndDate *time.Time `db:"end_date" json:"end_date"`
|
||||
GrossValue float64 `db:"gross_value" json:"gross_value"`
|
||||
HasDocuments bool `db:"has_documents" json:"has_documents"`
|
||||
Source string `db:"source" json:"source"`
|
||||
LatestReleaseDate time.Time `db:"latest_release_date" json:"latest_release_date"`
|
||||
Releases []OpportunityRelease `db:"-" json:"releases"`
|
||||
Marks OpportunityMarks `db:"-" json:"marks"`
|
||||
}
|
||||
|
||||
// OpportunityRelease is one OCDS release of an opportunity. JSON holds the
|
||||
@@ -43,3 +50,30 @@ type OpportunityReleaseTag struct {
|
||||
ReleaseID string `db:"release_id" json:"release_id"`
|
||||
Tag string `db:"tag" json:"tag"`
|
||||
}
|
||||
|
||||
// ErrWonAndLost is returned by OpportunityMarks.Validate when both Won and
|
||||
// Lost are set.
|
||||
var ErrWonAndLost = errors.New("an opportunity cannot be both won and lost")
|
||||
|
||||
// OpportunityMarks are the user's own marks on an opportunity, kept apart
|
||||
// from the fetched data so saving a newer release never changes them. The
|
||||
// marks are independent except that Won and Lost exclude each other (see
|
||||
// Validate).
|
||||
type OpportunityMarks struct {
|
||||
UUID string `db:"uuid" json:"uuid"`
|
||||
Hidden bool `db:"hidden" json:"hidden"`
|
||||
Skipped bool `db:"skipped" json:"skipped"`
|
||||
Interested bool `db:"interested" json:"interested"`
|
||||
BidSubmitted bool `db:"bid_submitted" json:"bid_submitted"`
|
||||
Won bool `db:"won" json:"won"`
|
||||
Lost bool `db:"lost" json:"lost"`
|
||||
}
|
||||
|
||||
// Validate reports whether the marks can be stored together: Won and Lost
|
||||
// cannot both be set.
|
||||
func (m OpportunityMarks) Validate() error {
|
||||
if m.Won && m.Lost {
|
||||
return ErrWonAndLost
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user