-
Notifications
You must be signed in to change notification settings - Fork 1
/
existing_model_link.go
62 lines (51 loc) · 2.74 KB
/
existing_model_link.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
package models
import (
"github.com/google/uuid"
"github.com/lib/pq"
)
// ExistingModelLink represents a link between another current model, or an existing model from the existing model table.
type ExistingModelLink struct {
ExistingModelID *int `json:"existingModelID" db:"existing_model_id"`
CurrentModelPlanID *uuid.UUID `json:"currentModelPlanID" db:"current_model_plan_id"`
FieldName ExisitingModelLinkFieldType `json:"fieldName" db:"field_name"`
baseStruct
modelPlanRelation
}
// ExisitingModelLinkFieldType is used to distinguish what part of the model plan this link refers to.
type ExisitingModelLinkFieldType string
const (
// EMLFTGeneralCharacteristicsResemblesExistingModelWhich is used to denote the link is in reference to the ResemblesExistingModelWhich question on Plan_General_Characteristics
EMLFTGeneralCharacteristicsResemblesExistingModelWhich ExisitingModelLinkFieldType = "GEN_CHAR_RESEMBLES_EXISTING_MODEL_WHICH"
// EMLFTGeneralCharacteristicsParticipationExistingModelWhich is used to denote the link is in refernce to the Participation in an existing model which question on Plan_Genereal_Characteristics
EMLFTGeneralCharacteristicsParticipationExistingModelWhich ExisitingModelLinkFieldType = "GEN_CHAR_PARTICIPATION_EXISTING_MODEL_WHICH"
)
// LinkedExistingModel is an interface which is used to return a Union type for graphql.
// Specifically, it allows us to return either a model plan or an existing model.
type LinkedExistingModel interface {
isLinkedExistingModel()
}
// ExistingModelLinks is a wrapper for a collection of Existing Model Links
type ExistingModelLinks struct {
FieldName ExisitingModelLinkFieldType `json:"fieldName" db:"field_name"`
Links []*ExistingModelLink
modelPlanRelation
// Name array to store data when specifically requested from the database. It isn't specifcally returned from the database unless requested by GQL
NameArray pq.StringArray `json:"names_array_db" db:"name_array"`
}
// NewExistingModelLinks instantiates a new ExistingModelLinks
func NewExistingModelLinks(modelPlanID uuid.UUID, fieldName ExisitingModelLinkFieldType, links []*ExistingModelLink) *ExistingModelLinks {
return &ExistingModelLinks{
Links: links,
modelPlanRelation: NewModelPlanRelation(modelPlanID),
FieldName: fieldName,
}
}
// NewExistingModelLink instantiates a new Existing ModelLink
func NewExistingModelLink(createdBy uuid.UUID, modelPlanID uuid.UUID, existingModelID *int, currentModelPlanID *uuid.UUID) *ExistingModelLink {
return &ExistingModelLink{
modelPlanRelation: NewModelPlanRelation(modelPlanID),
baseStruct: NewBaseStruct(createdBy),
ExistingModelID: existingModelID,
CurrentModelPlanID: currentModelPlanID,
}
}