-
Notifications
You must be signed in to change notification settings - Fork 0
/
shipmenthistory.go
261 lines (241 loc) · 9.42 KB
/
shipmenthistory.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
// Code generated by ent, DO NOT EDIT.
package ent
import (
"fmt"
"strings"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"github.com/google/uuid"
"github.com/thaiha1607/foursquare_server/ent/person"
"github.com/thaiha1607/foursquare_server/ent/shipment"
"github.com/thaiha1607/foursquare_server/ent/shipmenthistory"
"github.com/thaiha1607/foursquare_server/ent/shipmentstatuscode"
)
// ShipmentHistory is the model entity for the ShipmentHistory schema.
type ShipmentHistory struct {
config `json:"-"`
// ID of the ent.
ID uuid.UUID `json:"id,omitempty"`
// CreatedAt holds the value of the "created_at" field.
CreatedAt *time.Time `json:"created_at,omitempty"`
// ShipmentID holds the value of the "shipment_id" field.
ShipmentID string `json:"shipment_id,omitempty"`
// PersonID holds the value of the "person_id" field.
PersonID uuid.UUID `json:"person_id,omitempty"`
// OldStatusCode holds the value of the "old_status_code" field.
OldStatusCode *int `json:"old_status_code,omitempty"`
// NewStatusCode holds the value of the "new_status_code" field.
NewStatusCode *int `json:"new_status_code,omitempty"`
// Description holds the value of the "description" field.
Description *string `json:"description,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the ShipmentHistoryQuery when eager-loading is set.
Edges ShipmentHistoryEdges `json:"edges"`
selectValues sql.SelectValues
}
// ShipmentHistoryEdges holds the relations/edges for other nodes in the graph.
type ShipmentHistoryEdges struct {
// Shipment holds the value of the shipment edge.
Shipment *Shipment `json:"shipment,omitempty"`
// Person holds the value of the person edge.
Person *Person `json:"person,omitempty"`
// OldStatus holds the value of the old_status edge.
OldStatus *ShipmentStatusCode `json:"old_status,omitempty"`
// NewStatus holds the value of the new_status edge.
NewStatus *ShipmentStatusCode `json:"new_status,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [4]bool
}
// ShipmentOrErr returns the Shipment value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e ShipmentHistoryEdges) ShipmentOrErr() (*Shipment, error) {
if e.Shipment != nil {
return e.Shipment, nil
} else if e.loadedTypes[0] {
return nil, &NotFoundError{label: shipment.Label}
}
return nil, &NotLoadedError{edge: "shipment"}
}
// PersonOrErr returns the Person value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e ShipmentHistoryEdges) PersonOrErr() (*Person, error) {
if e.Person != nil {
return e.Person, nil
} else if e.loadedTypes[1] {
return nil, &NotFoundError{label: person.Label}
}
return nil, &NotLoadedError{edge: "person"}
}
// OldStatusOrErr returns the OldStatus value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e ShipmentHistoryEdges) OldStatusOrErr() (*ShipmentStatusCode, error) {
if e.OldStatus != nil {
return e.OldStatus, nil
} else if e.loadedTypes[2] {
return nil, &NotFoundError{label: shipmentstatuscode.Label}
}
return nil, &NotLoadedError{edge: "old_status"}
}
// NewStatusOrErr returns the NewStatus value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e ShipmentHistoryEdges) NewStatusOrErr() (*ShipmentStatusCode, error) {
if e.NewStatus != nil {
return e.NewStatus, nil
} else if e.loadedTypes[3] {
return nil, &NotFoundError{label: shipmentstatuscode.Label}
}
return nil, &NotLoadedError{edge: "new_status"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*ShipmentHistory) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case shipmenthistory.FieldOldStatusCode, shipmenthistory.FieldNewStatusCode:
values[i] = new(sql.NullInt64)
case shipmenthistory.FieldShipmentID, shipmenthistory.FieldDescription:
values[i] = new(sql.NullString)
case shipmenthistory.FieldCreatedAt:
values[i] = new(sql.NullTime)
case shipmenthistory.FieldID, shipmenthistory.FieldPersonID:
values[i] = new(uuid.UUID)
default:
values[i] = new(sql.UnknownType)
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the ShipmentHistory fields.
func (sh *ShipmentHistory) assignValues(columns []string, values []any) error {
if m, n := len(values), len(columns); m < n {
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
}
for i := range columns {
switch columns[i] {
case shipmenthistory.FieldID:
if value, ok := values[i].(*uuid.UUID); !ok {
return fmt.Errorf("unexpected type %T for field id", values[i])
} else if value != nil {
sh.ID = *value
}
case shipmenthistory.FieldCreatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field created_at", values[i])
} else if value.Valid {
sh.CreatedAt = new(time.Time)
*sh.CreatedAt = value.Time
}
case shipmenthistory.FieldShipmentID:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field shipment_id", values[i])
} else if value.Valid {
sh.ShipmentID = value.String
}
case shipmenthistory.FieldPersonID:
if value, ok := values[i].(*uuid.UUID); !ok {
return fmt.Errorf("unexpected type %T for field person_id", values[i])
} else if value != nil {
sh.PersonID = *value
}
case shipmenthistory.FieldOldStatusCode:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field old_status_code", values[i])
} else if value.Valid {
sh.OldStatusCode = new(int)
*sh.OldStatusCode = int(value.Int64)
}
case shipmenthistory.FieldNewStatusCode:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field new_status_code", values[i])
} else if value.Valid {
sh.NewStatusCode = new(int)
*sh.NewStatusCode = int(value.Int64)
}
case shipmenthistory.FieldDescription:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field description", values[i])
} else if value.Valid {
sh.Description = new(string)
*sh.Description = value.String
}
default:
sh.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the ShipmentHistory.
// This includes values selected through modifiers, order, etc.
func (sh *ShipmentHistory) Value(name string) (ent.Value, error) {
return sh.selectValues.Get(name)
}
// QueryShipment queries the "shipment" edge of the ShipmentHistory entity.
func (sh *ShipmentHistory) QueryShipment() *ShipmentQuery {
return NewShipmentHistoryClient(sh.config).QueryShipment(sh)
}
// QueryPerson queries the "person" edge of the ShipmentHistory entity.
func (sh *ShipmentHistory) QueryPerson() *PersonQuery {
return NewShipmentHistoryClient(sh.config).QueryPerson(sh)
}
// QueryOldStatus queries the "old_status" edge of the ShipmentHistory entity.
func (sh *ShipmentHistory) QueryOldStatus() *ShipmentStatusCodeQuery {
return NewShipmentHistoryClient(sh.config).QueryOldStatus(sh)
}
// QueryNewStatus queries the "new_status" edge of the ShipmentHistory entity.
func (sh *ShipmentHistory) QueryNewStatus() *ShipmentStatusCodeQuery {
return NewShipmentHistoryClient(sh.config).QueryNewStatus(sh)
}
// Update returns a builder for updating this ShipmentHistory.
// Note that you need to call ShipmentHistory.Unwrap() before calling this method if this ShipmentHistory
// was returned from a transaction, and the transaction was committed or rolled back.
func (sh *ShipmentHistory) Update() *ShipmentHistoryUpdateOne {
return NewShipmentHistoryClient(sh.config).UpdateOne(sh)
}
// Unwrap unwraps the ShipmentHistory entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func (sh *ShipmentHistory) Unwrap() *ShipmentHistory {
_tx, ok := sh.config.driver.(*txDriver)
if !ok {
panic("ent: ShipmentHistory is not a transactional entity")
}
sh.config.driver = _tx.drv
return sh
}
// String implements the fmt.Stringer.
func (sh *ShipmentHistory) String() string {
var builder strings.Builder
builder.WriteString("ShipmentHistory(")
builder.WriteString(fmt.Sprintf("id=%v, ", sh.ID))
if v := sh.CreatedAt; v != nil {
builder.WriteString("created_at=")
builder.WriteString(v.Format(time.ANSIC))
}
builder.WriteString(", ")
builder.WriteString("shipment_id=")
builder.WriteString(sh.ShipmentID)
builder.WriteString(", ")
builder.WriteString("person_id=")
builder.WriteString(fmt.Sprintf("%v", sh.PersonID))
builder.WriteString(", ")
if v := sh.OldStatusCode; v != nil {
builder.WriteString("old_status_code=")
builder.WriteString(fmt.Sprintf("%v", *v))
}
builder.WriteString(", ")
if v := sh.NewStatusCode; v != nil {
builder.WriteString("new_status_code=")
builder.WriteString(fmt.Sprintf("%v", *v))
}
builder.WriteString(", ")
if v := sh.Description; v != nil {
builder.WriteString("description=")
builder.WriteString(*v)
}
builder.WriteByte(')')
return builder.String()
}
// ShipmentHistories is a parsable slice of ShipmentHistory.
type ShipmentHistories []*ShipmentHistory