From 7db55ef1a5468144360cfe589625815e8ba43ae4 Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Fri, 9 Sep 2022 10:20:38 -0800 Subject: [PATCH] updates --- .github/workflows/publish.yaml | 7 + README.md | 8 +- backend/app/api/docs/docs.go | 40 ++- backend/app/api/docs/swagger.json | 40 ++- backend/app/api/docs/swagger.yaml | 30 +- backend/ent/item.go | 63 ++-- backend/ent/item/item.go | 19 +- backend/ent/item/where.go | 396 ++++++++++++--------- backend/ent/item_create.go | 122 ++++--- backend/ent/item_update.go | 316 ++++++++++------- backend/ent/migrate/schema.go | 43 ++- backend/ent/mutation.go | 416 +++++++++++++---------- backend/ent/runtime.go | 14 +- backend/ent/schema/item.go | 29 +- backend/go.sum | 4 + backend/internal/repo/repo_items.go | 5 +- backend/internal/repo/repo_items_test.go | 36 +- backend/internal/types/item_types.go | 10 + frontend/lib/api/classes/items.ts | 4 + frontend/lib/requests/requests.ts | 1 + frontend/pages/item/[id]/index.vue | 26 +- 21 files changed, 1010 insertions(+), 619 deletions(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index dc2e0da..cfbae04 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -1,12 +1,19 @@ name: Build Nightly on: + workflow_run: + workflows: + - "Go Build/Test" + - "Frontend / Integration" + types: + - completed push: branches: [main] jobs: publish: runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'success' }} steps: - uses: actions/checkout@v2 - name: Set up Go diff --git a/README.md b/README.md index 3f92dfc..ea30ee7 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,9 @@ - [ ] Update - [x] Delete - [ ] Asset Attachments for Items -- [x] Bulk Import via CSV +- [ ] Bulk Import via CSV + - [x] Initial + - [ ] Add Warranty Columns - [ ] Documentation - [ ] Docker Compose - [ ] Import CSV Format @@ -57,5 +59,5 @@ - [ ] User Management - [ ] Delete User - [ ] Reset Password -- [ ] Warranty Information - - [ ] Option for Lifetime Warranty or Warranty Period +- [x] Warranty Information + - [x] Option for Lifetime Warranty or Warranty Period diff --git a/backend/app/api/docs/docs.go b/backend/app/api/docs/docs.go index eab5eaf..0982e99 100644 --- a/backend/app/api/docs/docs.go +++ b/backend/app/api/docs/docs.go @@ -910,6 +910,10 @@ const docTemplate = `{ "description": "ID of the ent.", "type": "string" }, + "lifetime_warranty": { + "description": "LifetimeWarranty holds the value of the \"lifetime_warranty\" field.", + "type": "boolean" + }, "manufacturer": { "description": "Manufacturer holds the value of the \"manufacturer\" field.", "type": "string" @@ -934,10 +938,6 @@ const docTemplate = `{ "description": "PurchasePrice holds the value of the \"purchase_price\" field.", "type": "number" }, - "purchase_receipt_id": { - "description": "PurchaseReceiptID holds the value of the \"purchase_receipt_id\" field.", - "type": "string" - }, "purchase_time": { "description": "PurchaseTime holds the value of the \"purchase_time\" field.", "type": "string" @@ -954,10 +954,6 @@ const docTemplate = `{ "description": "SoldPrice holds the value of the \"sold_price\" field.", "type": "number" }, - "sold_receipt_id": { - "description": "SoldReceiptID holds the value of the \"sold_receipt_id\" field.", - "type": "string" - }, "sold_time": { "description": "SoldTime holds the value of the \"sold_time\" field.", "type": "string" @@ -969,6 +965,14 @@ const docTemplate = `{ "updated_at": { "description": "UpdatedAt holds the value of the \"updated_at\" field.", "type": "string" + }, + "warranty_details": { + "description": "WarrantyDetails holds the value of the \"warranty_details\" field.", + "type": "string" + }, + "warranty_expires": { + "description": "WarrantyExpires holds the value of the \"warranty_expires\" field.", + "type": "string" } } }, @@ -1280,6 +1284,10 @@ const docTemplate = `{ "$ref": "#/definitions/types.LabelSummary" } }, + "lifetimeWarranty": { + "description": "Warranty", + "type": "boolean" + }, "location": { "description": "Edges", "$ref": "#/definitions/types.LocationSummary" @@ -1326,6 +1334,12 @@ const docTemplate = `{ }, "updatedAt": { "type": "string" + }, + "warrantyDetails": { + "type": "string" + }, + "warrantyExpires": { + "type": "string" } } }, @@ -1347,6 +1361,10 @@ const docTemplate = `{ "$ref": "#/definitions/types.LabelSummary" } }, + "lifetimeWarranty": { + "description": "Warranty", + "type": "boolean" + }, "location": { "description": "Edges", "$ref": "#/definitions/types.LocationSummary" @@ -1393,6 +1411,12 @@ const docTemplate = `{ }, "updatedAt": { "type": "string" + }, + "warrantyDetails": { + "type": "string" + }, + "warrantyExpires": { + "type": "string" } } }, diff --git a/backend/app/api/docs/swagger.json b/backend/app/api/docs/swagger.json index bba2016..a8e0318 100644 --- a/backend/app/api/docs/swagger.json +++ b/backend/app/api/docs/swagger.json @@ -902,6 +902,10 @@ "description": "ID of the ent.", "type": "string" }, + "lifetime_warranty": { + "description": "LifetimeWarranty holds the value of the \"lifetime_warranty\" field.", + "type": "boolean" + }, "manufacturer": { "description": "Manufacturer holds the value of the \"manufacturer\" field.", "type": "string" @@ -926,10 +930,6 @@ "description": "PurchasePrice holds the value of the \"purchase_price\" field.", "type": "number" }, - "purchase_receipt_id": { - "description": "PurchaseReceiptID holds the value of the \"purchase_receipt_id\" field.", - "type": "string" - }, "purchase_time": { "description": "PurchaseTime holds the value of the \"purchase_time\" field.", "type": "string" @@ -946,10 +946,6 @@ "description": "SoldPrice holds the value of the \"sold_price\" field.", "type": "number" }, - "sold_receipt_id": { - "description": "SoldReceiptID holds the value of the \"sold_receipt_id\" field.", - "type": "string" - }, "sold_time": { "description": "SoldTime holds the value of the \"sold_time\" field.", "type": "string" @@ -961,6 +957,14 @@ "updated_at": { "description": "UpdatedAt holds the value of the \"updated_at\" field.", "type": "string" + }, + "warranty_details": { + "description": "WarrantyDetails holds the value of the \"warranty_details\" field.", + "type": "string" + }, + "warranty_expires": { + "description": "WarrantyExpires holds the value of the \"warranty_expires\" field.", + "type": "string" } } }, @@ -1272,6 +1276,10 @@ "$ref": "#/definitions/types.LabelSummary" } }, + "lifetimeWarranty": { + "description": "Warranty", + "type": "boolean" + }, "location": { "description": "Edges", "$ref": "#/definitions/types.LocationSummary" @@ -1318,6 +1326,12 @@ }, "updatedAt": { "type": "string" + }, + "warrantyDetails": { + "type": "string" + }, + "warrantyExpires": { + "type": "string" } } }, @@ -1339,6 +1353,10 @@ "$ref": "#/definitions/types.LabelSummary" } }, + "lifetimeWarranty": { + "description": "Warranty", + "type": "boolean" + }, "location": { "description": "Edges", "$ref": "#/definitions/types.LocationSummary" @@ -1385,6 +1403,12 @@ }, "updatedAt": { "type": "string" + }, + "warrantyDetails": { + "type": "string" + }, + "warrantyExpires": { + "type": "string" } } }, diff --git a/backend/app/api/docs/swagger.yaml b/backend/app/api/docs/swagger.yaml index eee35b7..cfa5bf5 100644 --- a/backend/app/api/docs/swagger.yaml +++ b/backend/app/api/docs/swagger.yaml @@ -93,6 +93,9 @@ definitions: id: description: ID of the ent. type: string + lifetime_warranty: + description: LifetimeWarranty holds the value of the "lifetime_warranty" field. + type: boolean manufacturer: description: Manufacturer holds the value of the "manufacturer" field. type: string @@ -111,10 +114,6 @@ definitions: purchase_price: description: PurchasePrice holds the value of the "purchase_price" field. type: number - purchase_receipt_id: - description: PurchaseReceiptID holds the value of the "purchase_receipt_id" - field. - type: string purchase_time: description: PurchaseTime holds the value of the "purchase_time" field. type: string @@ -127,9 +126,6 @@ definitions: sold_price: description: SoldPrice holds the value of the "sold_price" field. type: number - sold_receipt_id: - description: SoldReceiptID holds the value of the "sold_receipt_id" field. - type: string sold_time: description: SoldTime holds the value of the "sold_time" field. type: string @@ -139,6 +135,12 @@ definitions: updated_at: description: UpdatedAt holds the value of the "updated_at" field. type: string + warranty_details: + description: WarrantyDetails holds the value of the "warranty_details" field. + type: string + warranty_expires: + description: WarrantyExpires holds the value of the "warranty_expires" field. + type: string type: object ent.ItemEdges: properties: @@ -364,6 +366,9 @@ definitions: items: $ref: '#/definitions/types.LabelSummary' type: array + lifetimeWarranty: + description: Warranty + type: boolean location: $ref: '#/definitions/types.LocationSummary' description: Edges @@ -397,6 +402,10 @@ definitions: type: string updatedAt: type: string + warrantyDetails: + type: string + warrantyExpires: + type: string type: object types.ItemSummary: properties: @@ -410,6 +419,9 @@ definitions: items: $ref: '#/definitions/types.LabelSummary' type: array + lifetimeWarranty: + description: Warranty + type: boolean location: $ref: '#/definitions/types.LocationSummary' description: Edges @@ -443,6 +455,10 @@ definitions: type: string updatedAt: type: string + warrantyDetails: + type: string + warrantyExpires: + type: string type: object types.LabelCreate: properties: diff --git a/backend/ent/item.go b/backend/ent/item.go index 6c88f6b..7e427d5 100644 --- a/backend/ent/item.go +++ b/backend/ent/item.go @@ -35,22 +35,24 @@ type Item struct { ModelNumber string `json:"model_number,omitempty"` // Manufacturer holds the value of the "manufacturer" field. Manufacturer string `json:"manufacturer,omitempty"` + // LifetimeWarranty holds the value of the "lifetime_warranty" field. + LifetimeWarranty bool `json:"lifetime_warranty,omitempty"` + // WarrantyExpires holds the value of the "warranty_expires" field. + WarrantyExpires time.Time `json:"warranty_expires,omitempty"` + // WarrantyDetails holds the value of the "warranty_details" field. + WarrantyDetails string `json:"warranty_details,omitempty"` // PurchaseTime holds the value of the "purchase_time" field. PurchaseTime time.Time `json:"purchase_time,omitempty"` // PurchaseFrom holds the value of the "purchase_from" field. PurchaseFrom string `json:"purchase_from,omitempty"` // PurchasePrice holds the value of the "purchase_price" field. PurchasePrice float64 `json:"purchase_price,omitempty"` - // PurchaseReceiptID holds the value of the "purchase_receipt_id" field. - PurchaseReceiptID uuid.UUID `json:"purchase_receipt_id,omitempty"` // SoldTime holds the value of the "sold_time" field. SoldTime time.Time `json:"sold_time,omitempty"` // SoldTo holds the value of the "sold_to" field. SoldTo string `json:"sold_to,omitempty"` // SoldPrice holds the value of the "sold_price" field. SoldPrice float64 `json:"sold_price,omitempty"` - // SoldReceiptID holds the value of the "sold_receipt_id" field. - SoldReceiptID uuid.UUID `json:"sold_receipt_id,omitempty"` // SoldNotes holds the value of the "sold_notes" field. SoldNotes string `json:"sold_notes,omitempty"` // Edges holds the relations/edges for other nodes in the graph. @@ -124,13 +126,15 @@ func (*Item) scanValues(columns []string) ([]interface{}, error) { values := make([]interface{}, len(columns)) for i := range columns { switch columns[i] { + case item.FieldLifetimeWarranty: + values[i] = new(sql.NullBool) case item.FieldPurchasePrice, item.FieldSoldPrice: values[i] = new(sql.NullFloat64) - case item.FieldName, item.FieldDescription, item.FieldNotes, item.FieldSerialNumber, item.FieldModelNumber, item.FieldManufacturer, item.FieldPurchaseFrom, item.FieldSoldTo, item.FieldSoldNotes: + case item.FieldName, item.FieldDescription, item.FieldNotes, item.FieldSerialNumber, item.FieldModelNumber, item.FieldManufacturer, item.FieldWarrantyDetails, item.FieldPurchaseFrom, item.FieldSoldTo, item.FieldSoldNotes: values[i] = new(sql.NullString) - case item.FieldCreatedAt, item.FieldUpdatedAt, item.FieldPurchaseTime, item.FieldSoldTime: + case item.FieldCreatedAt, item.FieldUpdatedAt, item.FieldWarrantyExpires, item.FieldPurchaseTime, item.FieldSoldTime: values[i] = new(sql.NullTime) - case item.FieldID, item.FieldPurchaseReceiptID, item.FieldSoldReceiptID: + case item.FieldID: values[i] = new(uuid.UUID) case item.ForeignKeys[0]: // group_items values[i] = &sql.NullScanner{S: new(uuid.UUID)} @@ -205,6 +209,24 @@ func (i *Item) assignValues(columns []string, values []interface{}) error { } else if value.Valid { i.Manufacturer = value.String } + case item.FieldLifetimeWarranty: + if value, ok := values[j].(*sql.NullBool); !ok { + return fmt.Errorf("unexpected type %T for field lifetime_warranty", values[j]) + } else if value.Valid { + i.LifetimeWarranty = value.Bool + } + case item.FieldWarrantyExpires: + if value, ok := values[j].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field warranty_expires", values[j]) + } else if value.Valid { + i.WarrantyExpires = value.Time + } + case item.FieldWarrantyDetails: + if value, ok := values[j].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field warranty_details", values[j]) + } else if value.Valid { + i.WarrantyDetails = value.String + } case item.FieldPurchaseTime: if value, ok := values[j].(*sql.NullTime); !ok { return fmt.Errorf("unexpected type %T for field purchase_time", values[j]) @@ -223,12 +245,6 @@ func (i *Item) assignValues(columns []string, values []interface{}) error { } else if value.Valid { i.PurchasePrice = value.Float64 } - case item.FieldPurchaseReceiptID: - if value, ok := values[j].(*uuid.UUID); !ok { - return fmt.Errorf("unexpected type %T for field purchase_receipt_id", values[j]) - } else if value != nil { - i.PurchaseReceiptID = *value - } case item.FieldSoldTime: if value, ok := values[j].(*sql.NullTime); !ok { return fmt.Errorf("unexpected type %T for field sold_time", values[j]) @@ -247,12 +263,6 @@ func (i *Item) assignValues(columns []string, values []interface{}) error { } else if value.Valid { i.SoldPrice = value.Float64 } - case item.FieldSoldReceiptID: - if value, ok := values[j].(*uuid.UUID); !ok { - return fmt.Errorf("unexpected type %T for field sold_receipt_id", values[j]) - } else if value != nil { - i.SoldReceiptID = *value - } case item.FieldSoldNotes: if value, ok := values[j].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field sold_notes", values[j]) @@ -345,6 +355,15 @@ func (i *Item) String() string { builder.WriteString("manufacturer=") builder.WriteString(i.Manufacturer) builder.WriteString(", ") + builder.WriteString("lifetime_warranty=") + builder.WriteString(fmt.Sprintf("%v", i.LifetimeWarranty)) + builder.WriteString(", ") + builder.WriteString("warranty_expires=") + builder.WriteString(i.WarrantyExpires.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("warranty_details=") + builder.WriteString(i.WarrantyDetails) + builder.WriteString(", ") builder.WriteString("purchase_time=") builder.WriteString(i.PurchaseTime.Format(time.ANSIC)) builder.WriteString(", ") @@ -354,9 +373,6 @@ func (i *Item) String() string { builder.WriteString("purchase_price=") builder.WriteString(fmt.Sprintf("%v", i.PurchasePrice)) builder.WriteString(", ") - builder.WriteString("purchase_receipt_id=") - builder.WriteString(fmt.Sprintf("%v", i.PurchaseReceiptID)) - builder.WriteString(", ") builder.WriteString("sold_time=") builder.WriteString(i.SoldTime.Format(time.ANSIC)) builder.WriteString(", ") @@ -366,9 +382,6 @@ func (i *Item) String() string { builder.WriteString("sold_price=") builder.WriteString(fmt.Sprintf("%v", i.SoldPrice)) builder.WriteString(", ") - builder.WriteString("sold_receipt_id=") - builder.WriteString(fmt.Sprintf("%v", i.SoldReceiptID)) - builder.WriteString(", ") builder.WriteString("sold_notes=") builder.WriteString(i.SoldNotes) builder.WriteByte(')') diff --git a/backend/ent/item/item.go b/backend/ent/item/item.go index e43d6b3..481d8e7 100644 --- a/backend/ent/item/item.go +++ b/backend/ent/item/item.go @@ -29,22 +29,24 @@ const ( FieldModelNumber = "model_number" // FieldManufacturer holds the string denoting the manufacturer field in the database. FieldManufacturer = "manufacturer" + // FieldLifetimeWarranty holds the string denoting the lifetime_warranty field in the database. + FieldLifetimeWarranty = "lifetime_warranty" + // FieldWarrantyExpires holds the string denoting the warranty_expires field in the database. + FieldWarrantyExpires = "warranty_expires" + // FieldWarrantyDetails holds the string denoting the warranty_details field in the database. + FieldWarrantyDetails = "warranty_details" // FieldPurchaseTime holds the string denoting the purchase_time field in the database. FieldPurchaseTime = "purchase_time" // FieldPurchaseFrom holds the string denoting the purchase_from field in the database. FieldPurchaseFrom = "purchase_from" // FieldPurchasePrice holds the string denoting the purchase_price field in the database. FieldPurchasePrice = "purchase_price" - // FieldPurchaseReceiptID holds the string denoting the purchase_receipt_id field in the database. - FieldPurchaseReceiptID = "purchase_receipt_id" // FieldSoldTime holds the string denoting the sold_time field in the database. FieldSoldTime = "sold_time" // FieldSoldTo holds the string denoting the sold_to field in the database. FieldSoldTo = "sold_to" // FieldSoldPrice holds the string denoting the sold_price field in the database. FieldSoldPrice = "sold_price" - // FieldSoldReceiptID holds the string denoting the sold_receipt_id field in the database. - FieldSoldReceiptID = "sold_receipt_id" // FieldSoldNotes holds the string denoting the sold_notes field in the database. FieldSoldNotes = "sold_notes" // EdgeGroup holds the string denoting the group edge name in mutations. @@ -96,14 +98,15 @@ var Columns = []string{ FieldSerialNumber, FieldModelNumber, FieldManufacturer, + FieldLifetimeWarranty, + FieldWarrantyExpires, + FieldWarrantyDetails, FieldPurchaseTime, FieldPurchaseFrom, FieldPurchasePrice, - FieldPurchaseReceiptID, FieldSoldTime, FieldSoldTo, FieldSoldPrice, - FieldSoldReceiptID, FieldSoldNotes, } @@ -154,6 +157,10 @@ var ( ModelNumberValidator func(string) error // ManufacturerValidator is a validator for the "manufacturer" field. It is called by the builders before save. ManufacturerValidator func(string) error + // DefaultLifetimeWarranty holds the default value on creation for the "lifetime_warranty" field. + DefaultLifetimeWarranty bool + // WarrantyDetailsValidator is a validator for the "warranty_details" field. It is called by the builders before save. + WarrantyDetailsValidator func(string) error // DefaultPurchasePrice holds the default value on creation for the "purchase_price" field. DefaultPurchasePrice float64 // DefaultSoldPrice holds the default value on creation for the "sold_price" field. diff --git a/backend/ent/item/where.go b/backend/ent/item/where.go index a15a556..58d9f68 100644 --- a/backend/ent/item/where.go +++ b/backend/ent/item/where.go @@ -138,6 +138,27 @@ func Manufacturer(v string) predicate.Item { }) } +// LifetimeWarranty applies equality check predicate on the "lifetime_warranty" field. It's identical to LifetimeWarrantyEQ. +func LifetimeWarranty(v bool) predicate.Item { + return predicate.Item(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldLifetimeWarranty), v)) + }) +} + +// WarrantyExpires applies equality check predicate on the "warranty_expires" field. It's identical to WarrantyExpiresEQ. +func WarrantyExpires(v time.Time) predicate.Item { + return predicate.Item(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldWarrantyExpires), v)) + }) +} + +// WarrantyDetails applies equality check predicate on the "warranty_details" field. It's identical to WarrantyDetailsEQ. +func WarrantyDetails(v string) predicate.Item { + return predicate.Item(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldWarrantyDetails), v)) + }) +} + // PurchaseTime applies equality check predicate on the "purchase_time" field. It's identical to PurchaseTimeEQ. func PurchaseTime(v time.Time) predicate.Item { return predicate.Item(func(s *sql.Selector) { @@ -159,13 +180,6 @@ func PurchasePrice(v float64) predicate.Item { }) } -// PurchaseReceiptID applies equality check predicate on the "purchase_receipt_id" field. It's identical to PurchaseReceiptIDEQ. -func PurchaseReceiptID(v uuid.UUID) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldPurchaseReceiptID), v)) - }) -} - // SoldTime applies equality check predicate on the "sold_time" field. It's identical to SoldTimeEQ. func SoldTime(v time.Time) predicate.Item { return predicate.Item(func(s *sql.Selector) { @@ -187,13 +201,6 @@ func SoldPrice(v float64) predicate.Item { }) } -// SoldReceiptID applies equality check predicate on the "sold_receipt_id" field. It's identical to SoldReceiptIDEQ. -func SoldReceiptID(v uuid.UUID) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldSoldReceiptID), v)) - }) -} - // SoldNotes applies equality check predicate on the "sold_notes" field. It's identical to SoldNotesEQ. func SoldNotes(v string) predicate.Item { return predicate.Item(func(s *sql.Selector) { @@ -993,6 +1000,211 @@ func ManufacturerContainsFold(v string) predicate.Item { }) } +// LifetimeWarrantyEQ applies the EQ predicate on the "lifetime_warranty" field. +func LifetimeWarrantyEQ(v bool) predicate.Item { + return predicate.Item(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldLifetimeWarranty), v)) + }) +} + +// LifetimeWarrantyNEQ applies the NEQ predicate on the "lifetime_warranty" field. +func LifetimeWarrantyNEQ(v bool) predicate.Item { + return predicate.Item(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldLifetimeWarranty), v)) + }) +} + +// WarrantyExpiresEQ applies the EQ predicate on the "warranty_expires" field. +func WarrantyExpiresEQ(v time.Time) predicate.Item { + return predicate.Item(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldWarrantyExpires), v)) + }) +} + +// WarrantyExpiresNEQ applies the NEQ predicate on the "warranty_expires" field. +func WarrantyExpiresNEQ(v time.Time) predicate.Item { + return predicate.Item(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldWarrantyExpires), v)) + }) +} + +// WarrantyExpiresIn applies the In predicate on the "warranty_expires" field. +func WarrantyExpiresIn(vs ...time.Time) predicate.Item { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Item(func(s *sql.Selector) { + s.Where(sql.In(s.C(FieldWarrantyExpires), v...)) + }) +} + +// WarrantyExpiresNotIn applies the NotIn predicate on the "warranty_expires" field. +func WarrantyExpiresNotIn(vs ...time.Time) predicate.Item { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Item(func(s *sql.Selector) { + s.Where(sql.NotIn(s.C(FieldWarrantyExpires), v...)) + }) +} + +// WarrantyExpiresGT applies the GT predicate on the "warranty_expires" field. +func WarrantyExpiresGT(v time.Time) predicate.Item { + return predicate.Item(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldWarrantyExpires), v)) + }) +} + +// WarrantyExpiresGTE applies the GTE predicate on the "warranty_expires" field. +func WarrantyExpiresGTE(v time.Time) predicate.Item { + return predicate.Item(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldWarrantyExpires), v)) + }) +} + +// WarrantyExpiresLT applies the LT predicate on the "warranty_expires" field. +func WarrantyExpiresLT(v time.Time) predicate.Item { + return predicate.Item(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldWarrantyExpires), v)) + }) +} + +// WarrantyExpiresLTE applies the LTE predicate on the "warranty_expires" field. +func WarrantyExpiresLTE(v time.Time) predicate.Item { + return predicate.Item(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldWarrantyExpires), v)) + }) +} + +// WarrantyExpiresIsNil applies the IsNil predicate on the "warranty_expires" field. +func WarrantyExpiresIsNil() predicate.Item { + return predicate.Item(func(s *sql.Selector) { + s.Where(sql.IsNull(s.C(FieldWarrantyExpires))) + }) +} + +// WarrantyExpiresNotNil applies the NotNil predicate on the "warranty_expires" field. +func WarrantyExpiresNotNil() predicate.Item { + return predicate.Item(func(s *sql.Selector) { + s.Where(sql.NotNull(s.C(FieldWarrantyExpires))) + }) +} + +// WarrantyDetailsEQ applies the EQ predicate on the "warranty_details" field. +func WarrantyDetailsEQ(v string) predicate.Item { + return predicate.Item(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldWarrantyDetails), v)) + }) +} + +// WarrantyDetailsNEQ applies the NEQ predicate on the "warranty_details" field. +func WarrantyDetailsNEQ(v string) predicate.Item { + return predicate.Item(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldWarrantyDetails), v)) + }) +} + +// WarrantyDetailsIn applies the In predicate on the "warranty_details" field. +func WarrantyDetailsIn(vs ...string) predicate.Item { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Item(func(s *sql.Selector) { + s.Where(sql.In(s.C(FieldWarrantyDetails), v...)) + }) +} + +// WarrantyDetailsNotIn applies the NotIn predicate on the "warranty_details" field. +func WarrantyDetailsNotIn(vs ...string) predicate.Item { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Item(func(s *sql.Selector) { + s.Where(sql.NotIn(s.C(FieldWarrantyDetails), v...)) + }) +} + +// WarrantyDetailsGT applies the GT predicate on the "warranty_details" field. +func WarrantyDetailsGT(v string) predicate.Item { + return predicate.Item(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldWarrantyDetails), v)) + }) +} + +// WarrantyDetailsGTE applies the GTE predicate on the "warranty_details" field. +func WarrantyDetailsGTE(v string) predicate.Item { + return predicate.Item(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldWarrantyDetails), v)) + }) +} + +// WarrantyDetailsLT applies the LT predicate on the "warranty_details" field. +func WarrantyDetailsLT(v string) predicate.Item { + return predicate.Item(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldWarrantyDetails), v)) + }) +} + +// WarrantyDetailsLTE applies the LTE predicate on the "warranty_details" field. +func WarrantyDetailsLTE(v string) predicate.Item { + return predicate.Item(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldWarrantyDetails), v)) + }) +} + +// WarrantyDetailsContains applies the Contains predicate on the "warranty_details" field. +func WarrantyDetailsContains(v string) predicate.Item { + return predicate.Item(func(s *sql.Selector) { + s.Where(sql.Contains(s.C(FieldWarrantyDetails), v)) + }) +} + +// WarrantyDetailsHasPrefix applies the HasPrefix predicate on the "warranty_details" field. +func WarrantyDetailsHasPrefix(v string) predicate.Item { + return predicate.Item(func(s *sql.Selector) { + s.Where(sql.HasPrefix(s.C(FieldWarrantyDetails), v)) + }) +} + +// WarrantyDetailsHasSuffix applies the HasSuffix predicate on the "warranty_details" field. +func WarrantyDetailsHasSuffix(v string) predicate.Item { + return predicate.Item(func(s *sql.Selector) { + s.Where(sql.HasSuffix(s.C(FieldWarrantyDetails), v)) + }) +} + +// WarrantyDetailsIsNil applies the IsNil predicate on the "warranty_details" field. +func WarrantyDetailsIsNil() predicate.Item { + return predicate.Item(func(s *sql.Selector) { + s.Where(sql.IsNull(s.C(FieldWarrantyDetails))) + }) +} + +// WarrantyDetailsNotNil applies the NotNil predicate on the "warranty_details" field. +func WarrantyDetailsNotNil() predicate.Item { + return predicate.Item(func(s *sql.Selector) { + s.Where(sql.NotNull(s.C(FieldWarrantyDetails))) + }) +} + +// WarrantyDetailsEqualFold applies the EqualFold predicate on the "warranty_details" field. +func WarrantyDetailsEqualFold(v string) predicate.Item { + return predicate.Item(func(s *sql.Selector) { + s.Where(sql.EqualFold(s.C(FieldWarrantyDetails), v)) + }) +} + +// WarrantyDetailsContainsFold applies the ContainsFold predicate on the "warranty_details" field. +func WarrantyDetailsContainsFold(v string) predicate.Item { + return predicate.Item(func(s *sql.Selector) { + s.Where(sql.ContainsFold(s.C(FieldWarrantyDetails), v)) + }) +} + // PurchaseTimeEQ applies the EQ predicate on the "purchase_time" field. func PurchaseTimeEQ(v time.Time) predicate.Item { return predicate.Item(func(s *sql.Selector) { @@ -1248,84 +1460,6 @@ func PurchasePriceLTE(v float64) predicate.Item { }) } -// PurchaseReceiptIDEQ applies the EQ predicate on the "purchase_receipt_id" field. -func PurchaseReceiptIDEQ(v uuid.UUID) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldPurchaseReceiptID), v)) - }) -} - -// PurchaseReceiptIDNEQ applies the NEQ predicate on the "purchase_receipt_id" field. -func PurchaseReceiptIDNEQ(v uuid.UUID) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldPurchaseReceiptID), v)) - }) -} - -// PurchaseReceiptIDIn applies the In predicate on the "purchase_receipt_id" field. -func PurchaseReceiptIDIn(vs ...uuid.UUID) predicate.Item { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldPurchaseReceiptID), v...)) - }) -} - -// PurchaseReceiptIDNotIn applies the NotIn predicate on the "purchase_receipt_id" field. -func PurchaseReceiptIDNotIn(vs ...uuid.UUID) predicate.Item { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldPurchaseReceiptID), v...)) - }) -} - -// PurchaseReceiptIDGT applies the GT predicate on the "purchase_receipt_id" field. -func PurchaseReceiptIDGT(v uuid.UUID) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldPurchaseReceiptID), v)) - }) -} - -// PurchaseReceiptIDGTE applies the GTE predicate on the "purchase_receipt_id" field. -func PurchaseReceiptIDGTE(v uuid.UUID) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldPurchaseReceiptID), v)) - }) -} - -// PurchaseReceiptIDLT applies the LT predicate on the "purchase_receipt_id" field. -func PurchaseReceiptIDLT(v uuid.UUID) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldPurchaseReceiptID), v)) - }) -} - -// PurchaseReceiptIDLTE applies the LTE predicate on the "purchase_receipt_id" field. -func PurchaseReceiptIDLTE(v uuid.UUID) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldPurchaseReceiptID), v)) - }) -} - -// PurchaseReceiptIDIsNil applies the IsNil predicate on the "purchase_receipt_id" field. -func PurchaseReceiptIDIsNil() predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldPurchaseReceiptID))) - }) -} - -// PurchaseReceiptIDNotNil applies the NotNil predicate on the "purchase_receipt_id" field. -func PurchaseReceiptIDNotNil() predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldPurchaseReceiptID))) - }) -} - // SoldTimeEQ applies the EQ predicate on the "sold_time" field. func SoldTimeEQ(v time.Time) predicate.Item { return predicate.Item(func(s *sql.Selector) { @@ -1581,84 +1715,6 @@ func SoldPriceLTE(v float64) predicate.Item { }) } -// SoldReceiptIDEQ applies the EQ predicate on the "sold_receipt_id" field. -func SoldReceiptIDEQ(v uuid.UUID) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.EQ(s.C(FieldSoldReceiptID), v)) - }) -} - -// SoldReceiptIDNEQ applies the NEQ predicate on the "sold_receipt_id" field. -func SoldReceiptIDNEQ(v uuid.UUID) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NEQ(s.C(FieldSoldReceiptID), v)) - }) -} - -// SoldReceiptIDIn applies the In predicate on the "sold_receipt_id" field. -func SoldReceiptIDIn(vs ...uuid.UUID) predicate.Item { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.In(s.C(FieldSoldReceiptID), v...)) - }) -} - -// SoldReceiptIDNotIn applies the NotIn predicate on the "sold_receipt_id" field. -func SoldReceiptIDNotIn(vs ...uuid.UUID) predicate.Item { - v := make([]interface{}, len(vs)) - for i := range v { - v[i] = vs[i] - } - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NotIn(s.C(FieldSoldReceiptID), v...)) - }) -} - -// SoldReceiptIDGT applies the GT predicate on the "sold_receipt_id" field. -func SoldReceiptIDGT(v uuid.UUID) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GT(s.C(FieldSoldReceiptID), v)) - }) -} - -// SoldReceiptIDGTE applies the GTE predicate on the "sold_receipt_id" field. -func SoldReceiptIDGTE(v uuid.UUID) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.GTE(s.C(FieldSoldReceiptID), v)) - }) -} - -// SoldReceiptIDLT applies the LT predicate on the "sold_receipt_id" field. -func SoldReceiptIDLT(v uuid.UUID) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LT(s.C(FieldSoldReceiptID), v)) - }) -} - -// SoldReceiptIDLTE applies the LTE predicate on the "sold_receipt_id" field. -func SoldReceiptIDLTE(v uuid.UUID) predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.LTE(s.C(FieldSoldReceiptID), v)) - }) -} - -// SoldReceiptIDIsNil applies the IsNil predicate on the "sold_receipt_id" field. -func SoldReceiptIDIsNil() predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.IsNull(s.C(FieldSoldReceiptID))) - }) -} - -// SoldReceiptIDNotNil applies the NotNil predicate on the "sold_receipt_id" field. -func SoldReceiptIDNotNil() predicate.Item { - return predicate.Item(func(s *sql.Selector) { - s.Where(sql.NotNull(s.C(FieldSoldReceiptID))) - }) -} - // SoldNotesEQ applies the EQ predicate on the "sold_notes" field. func SoldNotesEQ(v string) predicate.Item { return predicate.Item(func(s *sql.Selector) { diff --git a/backend/ent/item_create.go b/backend/ent/item_create.go index 5242365..2715420 100644 --- a/backend/ent/item_create.go +++ b/backend/ent/item_create.go @@ -129,6 +129,48 @@ func (ic *ItemCreate) SetNillableManufacturer(s *string) *ItemCreate { return ic } +// SetLifetimeWarranty sets the "lifetime_warranty" field. +func (ic *ItemCreate) SetLifetimeWarranty(b bool) *ItemCreate { + ic.mutation.SetLifetimeWarranty(b) + return ic +} + +// SetNillableLifetimeWarranty sets the "lifetime_warranty" field if the given value is not nil. +func (ic *ItemCreate) SetNillableLifetimeWarranty(b *bool) *ItemCreate { + if b != nil { + ic.SetLifetimeWarranty(*b) + } + return ic +} + +// SetWarrantyExpires sets the "warranty_expires" field. +func (ic *ItemCreate) SetWarrantyExpires(t time.Time) *ItemCreate { + ic.mutation.SetWarrantyExpires(t) + return ic +} + +// SetNillableWarrantyExpires sets the "warranty_expires" field if the given value is not nil. +func (ic *ItemCreate) SetNillableWarrantyExpires(t *time.Time) *ItemCreate { + if t != nil { + ic.SetWarrantyExpires(*t) + } + return ic +} + +// SetWarrantyDetails sets the "warranty_details" field. +func (ic *ItemCreate) SetWarrantyDetails(s string) *ItemCreate { + ic.mutation.SetWarrantyDetails(s) + return ic +} + +// SetNillableWarrantyDetails sets the "warranty_details" field if the given value is not nil. +func (ic *ItemCreate) SetNillableWarrantyDetails(s *string) *ItemCreate { + if s != nil { + ic.SetWarrantyDetails(*s) + } + return ic +} + // SetPurchaseTime sets the "purchase_time" field. func (ic *ItemCreate) SetPurchaseTime(t time.Time) *ItemCreate { ic.mutation.SetPurchaseTime(t) @@ -171,20 +213,6 @@ func (ic *ItemCreate) SetNillablePurchasePrice(f *float64) *ItemCreate { return ic } -// SetPurchaseReceiptID sets the "purchase_receipt_id" field. -func (ic *ItemCreate) SetPurchaseReceiptID(u uuid.UUID) *ItemCreate { - ic.mutation.SetPurchaseReceiptID(u) - return ic -} - -// SetNillablePurchaseReceiptID sets the "purchase_receipt_id" field if the given value is not nil. -func (ic *ItemCreate) SetNillablePurchaseReceiptID(u *uuid.UUID) *ItemCreate { - if u != nil { - ic.SetPurchaseReceiptID(*u) - } - return ic -} - // SetSoldTime sets the "sold_time" field. func (ic *ItemCreate) SetSoldTime(t time.Time) *ItemCreate { ic.mutation.SetSoldTime(t) @@ -227,20 +255,6 @@ func (ic *ItemCreate) SetNillableSoldPrice(f *float64) *ItemCreate { return ic } -// SetSoldReceiptID sets the "sold_receipt_id" field. -func (ic *ItemCreate) SetSoldReceiptID(u uuid.UUID) *ItemCreate { - ic.mutation.SetSoldReceiptID(u) - return ic -} - -// SetNillableSoldReceiptID sets the "sold_receipt_id" field if the given value is not nil. -func (ic *ItemCreate) SetNillableSoldReceiptID(u *uuid.UUID) *ItemCreate { - if u != nil { - ic.SetSoldReceiptID(*u) - } - return ic -} - // SetSoldNotes sets the "sold_notes" field. func (ic *ItemCreate) SetSoldNotes(s string) *ItemCreate { ic.mutation.SetSoldNotes(s) @@ -414,6 +428,10 @@ func (ic *ItemCreate) defaults() { v := item.DefaultUpdatedAt() ic.mutation.SetUpdatedAt(v) } + if _, ok := ic.mutation.LifetimeWarranty(); !ok { + v := item.DefaultLifetimeWarranty + ic.mutation.SetLifetimeWarranty(v) + } if _, ok := ic.mutation.PurchasePrice(); !ok { v := item.DefaultPurchasePrice ic.mutation.SetPurchasePrice(v) @@ -469,6 +487,14 @@ func (ic *ItemCreate) check() error { return &ValidationError{Name: "manufacturer", err: fmt.Errorf(`ent: validator failed for field "Item.manufacturer": %w`, err)} } } + if _, ok := ic.mutation.LifetimeWarranty(); !ok { + return &ValidationError{Name: "lifetime_warranty", err: errors.New(`ent: missing required field "Item.lifetime_warranty"`)} + } + if v, ok := ic.mutation.WarrantyDetails(); ok { + if err := item.WarrantyDetailsValidator(v); err != nil { + return &ValidationError{Name: "warranty_details", err: fmt.Errorf(`ent: validator failed for field "Item.warranty_details": %w`, err)} + } + } if _, ok := ic.mutation.PurchasePrice(); !ok { return &ValidationError{Name: "purchase_price", err: errors.New(`ent: missing required field "Item.purchase_price"`)} } @@ -583,6 +609,30 @@ func (ic *ItemCreate) createSpec() (*Item, *sqlgraph.CreateSpec) { }) _node.Manufacturer = value } + if value, ok := ic.mutation.LifetimeWarranty(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeBool, + Value: value, + Column: item.FieldLifetimeWarranty, + }) + _node.LifetimeWarranty = value + } + if value, ok := ic.mutation.WarrantyExpires(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeTime, + Value: value, + Column: item.FieldWarrantyExpires, + }) + _node.WarrantyExpires = value + } + if value, ok := ic.mutation.WarrantyDetails(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: item.FieldWarrantyDetails, + }) + _node.WarrantyDetails = value + } if value, ok := ic.mutation.PurchaseTime(); ok { _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ Type: field.TypeTime, @@ -607,14 +657,6 @@ func (ic *ItemCreate) createSpec() (*Item, *sqlgraph.CreateSpec) { }) _node.PurchasePrice = value } - if value, ok := ic.mutation.PurchaseReceiptID(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Value: value, - Column: item.FieldPurchaseReceiptID, - }) - _node.PurchaseReceiptID = value - } if value, ok := ic.mutation.SoldTime(); ok { _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ Type: field.TypeTime, @@ -639,14 +681,6 @@ func (ic *ItemCreate) createSpec() (*Item, *sqlgraph.CreateSpec) { }) _node.SoldPrice = value } - if value, ok := ic.mutation.SoldReceiptID(); ok { - _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Value: value, - Column: item.FieldSoldReceiptID, - }) - _node.SoldReceiptID = value - } if value, ok := ic.mutation.SoldNotes(); ok { _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ Type: field.TypeString, diff --git a/backend/ent/item_update.go b/backend/ent/item_update.go index cbbf531..f2aa155 100644 --- a/backend/ent/item_update.go +++ b/backend/ent/item_update.go @@ -145,6 +145,60 @@ func (iu *ItemUpdate) ClearManufacturer() *ItemUpdate { return iu } +// SetLifetimeWarranty sets the "lifetime_warranty" field. +func (iu *ItemUpdate) SetLifetimeWarranty(b bool) *ItemUpdate { + iu.mutation.SetLifetimeWarranty(b) + return iu +} + +// SetNillableLifetimeWarranty sets the "lifetime_warranty" field if the given value is not nil. +func (iu *ItemUpdate) SetNillableLifetimeWarranty(b *bool) *ItemUpdate { + if b != nil { + iu.SetLifetimeWarranty(*b) + } + return iu +} + +// SetWarrantyExpires sets the "warranty_expires" field. +func (iu *ItemUpdate) SetWarrantyExpires(t time.Time) *ItemUpdate { + iu.mutation.SetWarrantyExpires(t) + return iu +} + +// SetNillableWarrantyExpires sets the "warranty_expires" field if the given value is not nil. +func (iu *ItemUpdate) SetNillableWarrantyExpires(t *time.Time) *ItemUpdate { + if t != nil { + iu.SetWarrantyExpires(*t) + } + return iu +} + +// ClearWarrantyExpires clears the value of the "warranty_expires" field. +func (iu *ItemUpdate) ClearWarrantyExpires() *ItemUpdate { + iu.mutation.ClearWarrantyExpires() + return iu +} + +// SetWarrantyDetails sets the "warranty_details" field. +func (iu *ItemUpdate) SetWarrantyDetails(s string) *ItemUpdate { + iu.mutation.SetWarrantyDetails(s) + return iu +} + +// SetNillableWarrantyDetails sets the "warranty_details" field if the given value is not nil. +func (iu *ItemUpdate) SetNillableWarrantyDetails(s *string) *ItemUpdate { + if s != nil { + iu.SetWarrantyDetails(*s) + } + return iu +} + +// ClearWarrantyDetails clears the value of the "warranty_details" field. +func (iu *ItemUpdate) ClearWarrantyDetails() *ItemUpdate { + iu.mutation.ClearWarrantyDetails() + return iu +} + // SetPurchaseTime sets the "purchase_time" field. func (iu *ItemUpdate) SetPurchaseTime(t time.Time) *ItemUpdate { iu.mutation.SetPurchaseTime(t) @@ -206,26 +260,6 @@ func (iu *ItemUpdate) AddPurchasePrice(f float64) *ItemUpdate { return iu } -// SetPurchaseReceiptID sets the "purchase_receipt_id" field. -func (iu *ItemUpdate) SetPurchaseReceiptID(u uuid.UUID) *ItemUpdate { - iu.mutation.SetPurchaseReceiptID(u) - return iu -} - -// SetNillablePurchaseReceiptID sets the "purchase_receipt_id" field if the given value is not nil. -func (iu *ItemUpdate) SetNillablePurchaseReceiptID(u *uuid.UUID) *ItemUpdate { - if u != nil { - iu.SetPurchaseReceiptID(*u) - } - return iu -} - -// ClearPurchaseReceiptID clears the value of the "purchase_receipt_id" field. -func (iu *ItemUpdate) ClearPurchaseReceiptID() *ItemUpdate { - iu.mutation.ClearPurchaseReceiptID() - return iu -} - // SetSoldTime sets the "sold_time" field. func (iu *ItemUpdate) SetSoldTime(t time.Time) *ItemUpdate { iu.mutation.SetSoldTime(t) @@ -287,26 +321,6 @@ func (iu *ItemUpdate) AddSoldPrice(f float64) *ItemUpdate { return iu } -// SetSoldReceiptID sets the "sold_receipt_id" field. -func (iu *ItemUpdate) SetSoldReceiptID(u uuid.UUID) *ItemUpdate { - iu.mutation.SetSoldReceiptID(u) - return iu -} - -// SetNillableSoldReceiptID sets the "sold_receipt_id" field if the given value is not nil. -func (iu *ItemUpdate) SetNillableSoldReceiptID(u *uuid.UUID) *ItemUpdate { - if u != nil { - iu.SetSoldReceiptID(*u) - } - return iu -} - -// ClearSoldReceiptID clears the value of the "sold_receipt_id" field. -func (iu *ItemUpdate) ClearSoldReceiptID() *ItemUpdate { - iu.mutation.ClearSoldReceiptID() - return iu -} - // SetSoldNotes sets the "sold_notes" field. func (iu *ItemUpdate) SetSoldNotes(s string) *ItemUpdate { iu.mutation.SetSoldNotes(s) @@ -547,6 +561,11 @@ func (iu *ItemUpdate) check() error { return &ValidationError{Name: "manufacturer", err: fmt.Errorf(`ent: validator failed for field "Item.manufacturer": %w`, err)} } } + if v, ok := iu.mutation.WarrantyDetails(); ok { + if err := item.WarrantyDetailsValidator(v); err != nil { + return &ValidationError{Name: "warranty_details", err: fmt.Errorf(`ent: validator failed for field "Item.warranty_details": %w`, err)} + } + } if v, ok := iu.mutation.SoldNotes(); ok { if err := item.SoldNotesValidator(v); err != nil { return &ValidationError{Name: "sold_notes", err: fmt.Errorf(`ent: validator failed for field "Item.sold_notes": %w`, err)} @@ -655,6 +674,39 @@ func (iu *ItemUpdate) sqlSave(ctx context.Context) (n int, err error) { Column: item.FieldManufacturer, }) } + if value, ok := iu.mutation.LifetimeWarranty(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeBool, + Value: value, + Column: item.FieldLifetimeWarranty, + }) + } + if value, ok := iu.mutation.WarrantyExpires(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeTime, + Value: value, + Column: item.FieldWarrantyExpires, + }) + } + if iu.mutation.WarrantyExpiresCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeTime, + Column: item.FieldWarrantyExpires, + }) + } + if value, ok := iu.mutation.WarrantyDetails(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: item.FieldWarrantyDetails, + }) + } + if iu.mutation.WarrantyDetailsCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Column: item.FieldWarrantyDetails, + }) + } if value, ok := iu.mutation.PurchaseTime(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeTime, @@ -695,19 +747,6 @@ func (iu *ItemUpdate) sqlSave(ctx context.Context) (n int, err error) { Column: item.FieldPurchasePrice, }) } - if value, ok := iu.mutation.PurchaseReceiptID(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Value: value, - Column: item.FieldPurchaseReceiptID, - }) - } - if iu.mutation.PurchaseReceiptIDCleared() { - _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: item.FieldPurchaseReceiptID, - }) - } if value, ok := iu.mutation.SoldTime(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeTime, @@ -748,19 +787,6 @@ func (iu *ItemUpdate) sqlSave(ctx context.Context) (n int, err error) { Column: item.FieldSoldPrice, }) } - if value, ok := iu.mutation.SoldReceiptID(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Value: value, - Column: item.FieldSoldReceiptID, - }) - } - if iu.mutation.SoldReceiptIDCleared() { - _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: item.FieldSoldReceiptID, - }) - } if value, ok := iu.mutation.SoldNotes(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeString, @@ -1083,6 +1109,60 @@ func (iuo *ItemUpdateOne) ClearManufacturer() *ItemUpdateOne { return iuo } +// SetLifetimeWarranty sets the "lifetime_warranty" field. +func (iuo *ItemUpdateOne) SetLifetimeWarranty(b bool) *ItemUpdateOne { + iuo.mutation.SetLifetimeWarranty(b) + return iuo +} + +// SetNillableLifetimeWarranty sets the "lifetime_warranty" field if the given value is not nil. +func (iuo *ItemUpdateOne) SetNillableLifetimeWarranty(b *bool) *ItemUpdateOne { + if b != nil { + iuo.SetLifetimeWarranty(*b) + } + return iuo +} + +// SetWarrantyExpires sets the "warranty_expires" field. +func (iuo *ItemUpdateOne) SetWarrantyExpires(t time.Time) *ItemUpdateOne { + iuo.mutation.SetWarrantyExpires(t) + return iuo +} + +// SetNillableWarrantyExpires sets the "warranty_expires" field if the given value is not nil. +func (iuo *ItemUpdateOne) SetNillableWarrantyExpires(t *time.Time) *ItemUpdateOne { + if t != nil { + iuo.SetWarrantyExpires(*t) + } + return iuo +} + +// ClearWarrantyExpires clears the value of the "warranty_expires" field. +func (iuo *ItemUpdateOne) ClearWarrantyExpires() *ItemUpdateOne { + iuo.mutation.ClearWarrantyExpires() + return iuo +} + +// SetWarrantyDetails sets the "warranty_details" field. +func (iuo *ItemUpdateOne) SetWarrantyDetails(s string) *ItemUpdateOne { + iuo.mutation.SetWarrantyDetails(s) + return iuo +} + +// SetNillableWarrantyDetails sets the "warranty_details" field if the given value is not nil. +func (iuo *ItemUpdateOne) SetNillableWarrantyDetails(s *string) *ItemUpdateOne { + if s != nil { + iuo.SetWarrantyDetails(*s) + } + return iuo +} + +// ClearWarrantyDetails clears the value of the "warranty_details" field. +func (iuo *ItemUpdateOne) ClearWarrantyDetails() *ItemUpdateOne { + iuo.mutation.ClearWarrantyDetails() + return iuo +} + // SetPurchaseTime sets the "purchase_time" field. func (iuo *ItemUpdateOne) SetPurchaseTime(t time.Time) *ItemUpdateOne { iuo.mutation.SetPurchaseTime(t) @@ -1144,26 +1224,6 @@ func (iuo *ItemUpdateOne) AddPurchasePrice(f float64) *ItemUpdateOne { return iuo } -// SetPurchaseReceiptID sets the "purchase_receipt_id" field. -func (iuo *ItemUpdateOne) SetPurchaseReceiptID(u uuid.UUID) *ItemUpdateOne { - iuo.mutation.SetPurchaseReceiptID(u) - return iuo -} - -// SetNillablePurchaseReceiptID sets the "purchase_receipt_id" field if the given value is not nil. -func (iuo *ItemUpdateOne) SetNillablePurchaseReceiptID(u *uuid.UUID) *ItemUpdateOne { - if u != nil { - iuo.SetPurchaseReceiptID(*u) - } - return iuo -} - -// ClearPurchaseReceiptID clears the value of the "purchase_receipt_id" field. -func (iuo *ItemUpdateOne) ClearPurchaseReceiptID() *ItemUpdateOne { - iuo.mutation.ClearPurchaseReceiptID() - return iuo -} - // SetSoldTime sets the "sold_time" field. func (iuo *ItemUpdateOne) SetSoldTime(t time.Time) *ItemUpdateOne { iuo.mutation.SetSoldTime(t) @@ -1225,26 +1285,6 @@ func (iuo *ItemUpdateOne) AddSoldPrice(f float64) *ItemUpdateOne { return iuo } -// SetSoldReceiptID sets the "sold_receipt_id" field. -func (iuo *ItemUpdateOne) SetSoldReceiptID(u uuid.UUID) *ItemUpdateOne { - iuo.mutation.SetSoldReceiptID(u) - return iuo -} - -// SetNillableSoldReceiptID sets the "sold_receipt_id" field if the given value is not nil. -func (iuo *ItemUpdateOne) SetNillableSoldReceiptID(u *uuid.UUID) *ItemUpdateOne { - if u != nil { - iuo.SetSoldReceiptID(*u) - } - return iuo -} - -// ClearSoldReceiptID clears the value of the "sold_receipt_id" field. -func (iuo *ItemUpdateOne) ClearSoldReceiptID() *ItemUpdateOne { - iuo.mutation.ClearSoldReceiptID() - return iuo -} - // SetSoldNotes sets the "sold_notes" field. func (iuo *ItemUpdateOne) SetSoldNotes(s string) *ItemUpdateOne { iuo.mutation.SetSoldNotes(s) @@ -1498,6 +1538,11 @@ func (iuo *ItemUpdateOne) check() error { return &ValidationError{Name: "manufacturer", err: fmt.Errorf(`ent: validator failed for field "Item.manufacturer": %w`, err)} } } + if v, ok := iuo.mutation.WarrantyDetails(); ok { + if err := item.WarrantyDetailsValidator(v); err != nil { + return &ValidationError{Name: "warranty_details", err: fmt.Errorf(`ent: validator failed for field "Item.warranty_details": %w`, err)} + } + } if v, ok := iuo.mutation.SoldNotes(); ok { if err := item.SoldNotesValidator(v); err != nil { return &ValidationError{Name: "sold_notes", err: fmt.Errorf(`ent: validator failed for field "Item.sold_notes": %w`, err)} @@ -1623,6 +1668,39 @@ func (iuo *ItemUpdateOne) sqlSave(ctx context.Context) (_node *Item, err error) Column: item.FieldManufacturer, }) } + if value, ok := iuo.mutation.LifetimeWarranty(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeBool, + Value: value, + Column: item.FieldLifetimeWarranty, + }) + } + if value, ok := iuo.mutation.WarrantyExpires(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeTime, + Value: value, + Column: item.FieldWarrantyExpires, + }) + } + if iuo.mutation.WarrantyExpiresCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeTime, + Column: item.FieldWarrantyExpires, + }) + } + if value, ok := iuo.mutation.WarrantyDetails(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: item.FieldWarrantyDetails, + }) + } + if iuo.mutation.WarrantyDetailsCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Column: item.FieldWarrantyDetails, + }) + } if value, ok := iuo.mutation.PurchaseTime(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeTime, @@ -1663,19 +1741,6 @@ func (iuo *ItemUpdateOne) sqlSave(ctx context.Context) (_node *Item, err error) Column: item.FieldPurchasePrice, }) } - if value, ok := iuo.mutation.PurchaseReceiptID(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Value: value, - Column: item.FieldPurchaseReceiptID, - }) - } - if iuo.mutation.PurchaseReceiptIDCleared() { - _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: item.FieldPurchaseReceiptID, - }) - } if value, ok := iuo.mutation.SoldTime(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeTime, @@ -1716,19 +1781,6 @@ func (iuo *ItemUpdateOne) sqlSave(ctx context.Context) (_node *Item, err error) Column: item.FieldSoldPrice, }) } - if value, ok := iuo.mutation.SoldReceiptID(); ok { - _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Value: value, - Column: item.FieldSoldReceiptID, - }) - } - if iuo.mutation.SoldReceiptIDCleared() { - _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: item.FieldSoldReceiptID, - }) - } if value, ok := iuo.mutation.SoldNotes(); ok { _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ Type: field.TypeString, diff --git a/backend/ent/migrate/schema.go b/backend/ent/migrate/schema.go index e6391db..a705906 100644 --- a/backend/ent/migrate/schema.go +++ b/backend/ent/migrate/schema.go @@ -27,7 +27,7 @@ var ( Symbol: "auth_tokens_users_auth_tokens", Columns: []*schema.Column{AuthTokensColumns[5]}, RefColumns: []*schema.Column{UsersColumns[0]}, - OnDelete: schema.SetNull, + OnDelete: schema.Cascade, }, }, Indexes: []*schema.Index{ @@ -63,14 +63,15 @@ var ( {Name: "serial_number", Type: field.TypeString, Nullable: true, Size: 255}, {Name: "model_number", Type: field.TypeString, Nullable: true, Size: 255}, {Name: "manufacturer", Type: field.TypeString, Nullable: true, Size: 255}, + {Name: "lifetime_warranty", Type: field.TypeBool, Default: false}, + {Name: "warranty_expires", Type: field.TypeTime, Nullable: true}, + {Name: "warranty_details", Type: field.TypeString, Nullable: true, Size: 1000}, {Name: "purchase_time", Type: field.TypeTime, Nullable: true}, {Name: "purchase_from", Type: field.TypeString, Nullable: true}, {Name: "purchase_price", Type: field.TypeFloat64, Default: 0}, - {Name: "purchase_receipt_id", Type: field.TypeUUID, Nullable: true}, {Name: "sold_time", Type: field.TypeTime, Nullable: true}, {Name: "sold_to", Type: field.TypeString, Nullable: true}, {Name: "sold_price", Type: field.TypeFloat64, Default: 0}, - {Name: "sold_receipt_id", Type: field.TypeUUID, Nullable: true}, {Name: "sold_notes", Type: field.TypeString, Nullable: true, Size: 1000}, {Name: "group_items", Type: field.TypeUUID}, {Name: "location_items", Type: field.TypeUUID, Nullable: true}, @@ -83,17 +84,39 @@ var ( ForeignKeys: []*schema.ForeignKey{ { Symbol: "items_groups_items", - Columns: []*schema.Column{ItemsColumns[18]}, + Columns: []*schema.Column{ItemsColumns[19]}, RefColumns: []*schema.Column{GroupsColumns[0]}, - OnDelete: schema.NoAction, + OnDelete: schema.Cascade, }, { Symbol: "items_locations_items", - Columns: []*schema.Column{ItemsColumns[19]}, + Columns: []*schema.Column{ItemsColumns[20]}, RefColumns: []*schema.Column{LocationsColumns[0]}, OnDelete: schema.SetNull, }, }, + Indexes: []*schema.Index{ + { + Name: "item_name", + Unique: false, + Columns: []*schema.Column{ItemsColumns[3]}, + }, + { + Name: "item_manufacturer", + Unique: false, + Columns: []*schema.Column{ItemsColumns[8]}, + }, + { + Name: "item_model_number", + Unique: false, + Columns: []*schema.Column{ItemsColumns[7]}, + }, + { + Name: "item_serial_number", + Unique: false, + Columns: []*schema.Column{ItemsColumns[6]}, + }, + }, } // ItemFieldsColumns holds the columns for the "item_fields" table. ItemFieldsColumns = []*schema.Column{ @@ -119,7 +142,7 @@ var ( Symbol: "item_fields_items_fields", Columns: []*schema.Column{ItemFieldsColumns[10]}, RefColumns: []*schema.Column{ItemsColumns[0]}, - OnDelete: schema.SetNull, + OnDelete: schema.Cascade, }, }, } @@ -143,7 +166,7 @@ var ( Symbol: "labels_groups_labels", Columns: []*schema.Column{LabelsColumns[6]}, RefColumns: []*schema.Column{GroupsColumns[0]}, - OnDelete: schema.NoAction, + OnDelete: schema.Cascade, }, }, } @@ -166,7 +189,7 @@ var ( Symbol: "locations_groups_locations", Columns: []*schema.Column{LocationsColumns[5]}, RefColumns: []*schema.Column{GroupsColumns[0]}, - OnDelete: schema.NoAction, + OnDelete: schema.Cascade, }, }, } @@ -191,7 +214,7 @@ var ( Symbol: "users_groups_users", Columns: []*schema.Column{UsersColumns[7]}, RefColumns: []*schema.Column{GroupsColumns[0]}, - OnDelete: schema.NoAction, + OnDelete: schema.Cascade, }, }, } diff --git a/backend/ent/mutation.go b/backend/ent/mutation.go index 0f39d08..1f5157b 100644 --- a/backend/ent/mutation.go +++ b/backend/ent/mutation.go @@ -1412,42 +1412,43 @@ func (m *GroupMutation) ResetEdge(name string) error { // ItemMutation represents an operation that mutates the Item nodes in the graph. type ItemMutation struct { config - op Op - typ string - id *uuid.UUID - created_at *time.Time - updated_at *time.Time - name *string - description *string - notes *string - serial_number *string - model_number *string - manufacturer *string - purchase_time *time.Time - purchase_from *string - purchase_price *float64 - addpurchase_price *float64 - purchase_receipt_id *uuid.UUID - sold_time *time.Time - sold_to *string - sold_price *float64 - addsold_price *float64 - sold_receipt_id *uuid.UUID - sold_notes *string - clearedFields map[string]struct{} - group *uuid.UUID - clearedgroup bool - location *uuid.UUID - clearedlocation bool - fields map[uuid.UUID]struct{} - removedfields map[uuid.UUID]struct{} - clearedfields bool - label map[uuid.UUID]struct{} - removedlabel map[uuid.UUID]struct{} - clearedlabel bool - done bool - oldValue func(context.Context) (*Item, error) - predicates []predicate.Item + op Op + typ string + id *uuid.UUID + created_at *time.Time + updated_at *time.Time + name *string + description *string + notes *string + serial_number *string + model_number *string + manufacturer *string + lifetime_warranty *bool + warranty_expires *time.Time + warranty_details *string + purchase_time *time.Time + purchase_from *string + purchase_price *float64 + addpurchase_price *float64 + sold_time *time.Time + sold_to *string + sold_price *float64 + addsold_price *float64 + sold_notes *string + clearedFields map[string]struct{} + group *uuid.UUID + clearedgroup bool + location *uuid.UUID + clearedlocation bool + fields map[uuid.UUID]struct{} + removedfields map[uuid.UUID]struct{} + clearedfields bool + label map[uuid.UUID]struct{} + removedlabel map[uuid.UUID]struct{} + clearedlabel bool + done bool + oldValue func(context.Context) (*Item, error) + predicates []predicate.Item } var _ ent.Mutation = (*ItemMutation)(nil) @@ -1907,6 +1908,140 @@ func (m *ItemMutation) ResetManufacturer() { delete(m.clearedFields, item.FieldManufacturer) } +// SetLifetimeWarranty sets the "lifetime_warranty" field. +func (m *ItemMutation) SetLifetimeWarranty(b bool) { + m.lifetime_warranty = &b +} + +// LifetimeWarranty returns the value of the "lifetime_warranty" field in the mutation. +func (m *ItemMutation) LifetimeWarranty() (r bool, exists bool) { + v := m.lifetime_warranty + if v == nil { + return + } + return *v, true +} + +// OldLifetimeWarranty returns the old "lifetime_warranty" field's value of the Item entity. +// If the Item object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ItemMutation) OldLifetimeWarranty(ctx context.Context) (v bool, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldLifetimeWarranty is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldLifetimeWarranty requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldLifetimeWarranty: %w", err) + } + return oldValue.LifetimeWarranty, nil +} + +// ResetLifetimeWarranty resets all changes to the "lifetime_warranty" field. +func (m *ItemMutation) ResetLifetimeWarranty() { + m.lifetime_warranty = nil +} + +// SetWarrantyExpires sets the "warranty_expires" field. +func (m *ItemMutation) SetWarrantyExpires(t time.Time) { + m.warranty_expires = &t +} + +// WarrantyExpires returns the value of the "warranty_expires" field in the mutation. +func (m *ItemMutation) WarrantyExpires() (r time.Time, exists bool) { + v := m.warranty_expires + if v == nil { + return + } + return *v, true +} + +// OldWarrantyExpires returns the old "warranty_expires" field's value of the Item entity. +// If the Item object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ItemMutation) OldWarrantyExpires(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldWarrantyExpires is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldWarrantyExpires requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldWarrantyExpires: %w", err) + } + return oldValue.WarrantyExpires, nil +} + +// ClearWarrantyExpires clears the value of the "warranty_expires" field. +func (m *ItemMutation) ClearWarrantyExpires() { + m.warranty_expires = nil + m.clearedFields[item.FieldWarrantyExpires] = struct{}{} +} + +// WarrantyExpiresCleared returns if the "warranty_expires" field was cleared in this mutation. +func (m *ItemMutation) WarrantyExpiresCleared() bool { + _, ok := m.clearedFields[item.FieldWarrantyExpires] + return ok +} + +// ResetWarrantyExpires resets all changes to the "warranty_expires" field. +func (m *ItemMutation) ResetWarrantyExpires() { + m.warranty_expires = nil + delete(m.clearedFields, item.FieldWarrantyExpires) +} + +// SetWarrantyDetails sets the "warranty_details" field. +func (m *ItemMutation) SetWarrantyDetails(s string) { + m.warranty_details = &s +} + +// WarrantyDetails returns the value of the "warranty_details" field in the mutation. +func (m *ItemMutation) WarrantyDetails() (r string, exists bool) { + v := m.warranty_details + if v == nil { + return + } + return *v, true +} + +// OldWarrantyDetails returns the old "warranty_details" field's value of the Item entity. +// If the Item object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *ItemMutation) OldWarrantyDetails(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldWarrantyDetails is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldWarrantyDetails requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldWarrantyDetails: %w", err) + } + return oldValue.WarrantyDetails, nil +} + +// ClearWarrantyDetails clears the value of the "warranty_details" field. +func (m *ItemMutation) ClearWarrantyDetails() { + m.warranty_details = nil + m.clearedFields[item.FieldWarrantyDetails] = struct{}{} +} + +// WarrantyDetailsCleared returns if the "warranty_details" field was cleared in this mutation. +func (m *ItemMutation) WarrantyDetailsCleared() bool { + _, ok := m.clearedFields[item.FieldWarrantyDetails] + return ok +} + +// ResetWarrantyDetails resets all changes to the "warranty_details" field. +func (m *ItemMutation) ResetWarrantyDetails() { + m.warranty_details = nil + delete(m.clearedFields, item.FieldWarrantyDetails) +} + // SetPurchaseTime sets the "purchase_time" field. func (m *ItemMutation) SetPurchaseTime(t time.Time) { m.purchase_time = &t @@ -2061,55 +2196,6 @@ func (m *ItemMutation) ResetPurchasePrice() { m.addpurchase_price = nil } -// SetPurchaseReceiptID sets the "purchase_receipt_id" field. -func (m *ItemMutation) SetPurchaseReceiptID(u uuid.UUID) { - m.purchase_receipt_id = &u -} - -// PurchaseReceiptID returns the value of the "purchase_receipt_id" field in the mutation. -func (m *ItemMutation) PurchaseReceiptID() (r uuid.UUID, exists bool) { - v := m.purchase_receipt_id - if v == nil { - return - } - return *v, true -} - -// OldPurchaseReceiptID returns the old "purchase_receipt_id" field's value of the Item entity. -// If the Item object wasn't provided to the builder, the object is fetched from the database. -// An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *ItemMutation) OldPurchaseReceiptID(ctx context.Context) (v uuid.UUID, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldPurchaseReceiptID is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldPurchaseReceiptID requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldPurchaseReceiptID: %w", err) - } - return oldValue.PurchaseReceiptID, nil -} - -// ClearPurchaseReceiptID clears the value of the "purchase_receipt_id" field. -func (m *ItemMutation) ClearPurchaseReceiptID() { - m.purchase_receipt_id = nil - m.clearedFields[item.FieldPurchaseReceiptID] = struct{}{} -} - -// PurchaseReceiptIDCleared returns if the "purchase_receipt_id" field was cleared in this mutation. -func (m *ItemMutation) PurchaseReceiptIDCleared() bool { - _, ok := m.clearedFields[item.FieldPurchaseReceiptID] - return ok -} - -// ResetPurchaseReceiptID resets all changes to the "purchase_receipt_id" field. -func (m *ItemMutation) ResetPurchaseReceiptID() { - m.purchase_receipt_id = nil - delete(m.clearedFields, item.FieldPurchaseReceiptID) -} - // SetSoldTime sets the "sold_time" field. func (m *ItemMutation) SetSoldTime(t time.Time) { m.sold_time = &t @@ -2264,55 +2350,6 @@ func (m *ItemMutation) ResetSoldPrice() { m.addsold_price = nil } -// SetSoldReceiptID sets the "sold_receipt_id" field. -func (m *ItemMutation) SetSoldReceiptID(u uuid.UUID) { - m.sold_receipt_id = &u -} - -// SoldReceiptID returns the value of the "sold_receipt_id" field in the mutation. -func (m *ItemMutation) SoldReceiptID() (r uuid.UUID, exists bool) { - v := m.sold_receipt_id - if v == nil { - return - } - return *v, true -} - -// OldSoldReceiptID returns the old "sold_receipt_id" field's value of the Item entity. -// If the Item object wasn't provided to the builder, the object is fetched from the database. -// An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *ItemMutation) OldSoldReceiptID(ctx context.Context) (v uuid.UUID, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldSoldReceiptID is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldSoldReceiptID requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldSoldReceiptID: %w", err) - } - return oldValue.SoldReceiptID, nil -} - -// ClearSoldReceiptID clears the value of the "sold_receipt_id" field. -func (m *ItemMutation) ClearSoldReceiptID() { - m.sold_receipt_id = nil - m.clearedFields[item.FieldSoldReceiptID] = struct{}{} -} - -// SoldReceiptIDCleared returns if the "sold_receipt_id" field was cleared in this mutation. -func (m *ItemMutation) SoldReceiptIDCleared() bool { - _, ok := m.clearedFields[item.FieldSoldReceiptID] - return ok -} - -// ResetSoldReceiptID resets all changes to the "sold_receipt_id" field. -func (m *ItemMutation) ResetSoldReceiptID() { - m.sold_receipt_id = nil - delete(m.clearedFields, item.FieldSoldReceiptID) -} - // SetSoldNotes sets the "sold_notes" field. func (m *ItemMutation) SetSoldNotes(s string) { m.sold_notes = &s @@ -2567,7 +2604,7 @@ func (m *ItemMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *ItemMutation) Fields() []string { - fields := make([]string, 0, 17) + fields := make([]string, 0, 18) if m.created_at != nil { fields = append(fields, item.FieldCreatedAt) } @@ -2592,6 +2629,15 @@ func (m *ItemMutation) Fields() []string { if m.manufacturer != nil { fields = append(fields, item.FieldManufacturer) } + if m.lifetime_warranty != nil { + fields = append(fields, item.FieldLifetimeWarranty) + } + if m.warranty_expires != nil { + fields = append(fields, item.FieldWarrantyExpires) + } + if m.warranty_details != nil { + fields = append(fields, item.FieldWarrantyDetails) + } if m.purchase_time != nil { fields = append(fields, item.FieldPurchaseTime) } @@ -2601,9 +2647,6 @@ func (m *ItemMutation) Fields() []string { if m.purchase_price != nil { fields = append(fields, item.FieldPurchasePrice) } - if m.purchase_receipt_id != nil { - fields = append(fields, item.FieldPurchaseReceiptID) - } if m.sold_time != nil { fields = append(fields, item.FieldSoldTime) } @@ -2613,9 +2656,6 @@ func (m *ItemMutation) Fields() []string { if m.sold_price != nil { fields = append(fields, item.FieldSoldPrice) } - if m.sold_receipt_id != nil { - fields = append(fields, item.FieldSoldReceiptID) - } if m.sold_notes != nil { fields = append(fields, item.FieldSoldNotes) } @@ -2643,22 +2683,24 @@ func (m *ItemMutation) Field(name string) (ent.Value, bool) { return m.ModelNumber() case item.FieldManufacturer: return m.Manufacturer() + case item.FieldLifetimeWarranty: + return m.LifetimeWarranty() + case item.FieldWarrantyExpires: + return m.WarrantyExpires() + case item.FieldWarrantyDetails: + return m.WarrantyDetails() case item.FieldPurchaseTime: return m.PurchaseTime() case item.FieldPurchaseFrom: return m.PurchaseFrom() case item.FieldPurchasePrice: return m.PurchasePrice() - case item.FieldPurchaseReceiptID: - return m.PurchaseReceiptID() case item.FieldSoldTime: return m.SoldTime() case item.FieldSoldTo: return m.SoldTo() case item.FieldSoldPrice: return m.SoldPrice() - case item.FieldSoldReceiptID: - return m.SoldReceiptID() case item.FieldSoldNotes: return m.SoldNotes() } @@ -2686,22 +2728,24 @@ func (m *ItemMutation) OldField(ctx context.Context, name string) (ent.Value, er return m.OldModelNumber(ctx) case item.FieldManufacturer: return m.OldManufacturer(ctx) + case item.FieldLifetimeWarranty: + return m.OldLifetimeWarranty(ctx) + case item.FieldWarrantyExpires: + return m.OldWarrantyExpires(ctx) + case item.FieldWarrantyDetails: + return m.OldWarrantyDetails(ctx) case item.FieldPurchaseTime: return m.OldPurchaseTime(ctx) case item.FieldPurchaseFrom: return m.OldPurchaseFrom(ctx) case item.FieldPurchasePrice: return m.OldPurchasePrice(ctx) - case item.FieldPurchaseReceiptID: - return m.OldPurchaseReceiptID(ctx) case item.FieldSoldTime: return m.OldSoldTime(ctx) case item.FieldSoldTo: return m.OldSoldTo(ctx) case item.FieldSoldPrice: return m.OldSoldPrice(ctx) - case item.FieldSoldReceiptID: - return m.OldSoldReceiptID(ctx) case item.FieldSoldNotes: return m.OldSoldNotes(ctx) } @@ -2769,6 +2813,27 @@ func (m *ItemMutation) SetField(name string, value ent.Value) error { } m.SetManufacturer(v) return nil + case item.FieldLifetimeWarranty: + v, ok := value.(bool) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetLifetimeWarranty(v) + return nil + case item.FieldWarrantyExpires: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetWarrantyExpires(v) + return nil + case item.FieldWarrantyDetails: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetWarrantyDetails(v) + return nil case item.FieldPurchaseTime: v, ok := value.(time.Time) if !ok { @@ -2790,13 +2855,6 @@ func (m *ItemMutation) SetField(name string, value ent.Value) error { } m.SetPurchasePrice(v) return nil - case item.FieldPurchaseReceiptID: - v, ok := value.(uuid.UUID) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetPurchaseReceiptID(v) - return nil case item.FieldSoldTime: v, ok := value.(time.Time) if !ok { @@ -2818,13 +2876,6 @@ func (m *ItemMutation) SetField(name string, value ent.Value) error { } m.SetSoldPrice(v) return nil - case item.FieldSoldReceiptID: - v, ok := value.(uuid.UUID) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetSoldReceiptID(v) - return nil case item.FieldSoldNotes: v, ok := value.(string) if !ok { @@ -2904,24 +2955,24 @@ func (m *ItemMutation) ClearedFields() []string { if m.FieldCleared(item.FieldManufacturer) { fields = append(fields, item.FieldManufacturer) } + if m.FieldCleared(item.FieldWarrantyExpires) { + fields = append(fields, item.FieldWarrantyExpires) + } + if m.FieldCleared(item.FieldWarrantyDetails) { + fields = append(fields, item.FieldWarrantyDetails) + } if m.FieldCleared(item.FieldPurchaseTime) { fields = append(fields, item.FieldPurchaseTime) } if m.FieldCleared(item.FieldPurchaseFrom) { fields = append(fields, item.FieldPurchaseFrom) } - if m.FieldCleared(item.FieldPurchaseReceiptID) { - fields = append(fields, item.FieldPurchaseReceiptID) - } if m.FieldCleared(item.FieldSoldTime) { fields = append(fields, item.FieldSoldTime) } if m.FieldCleared(item.FieldSoldTo) { fields = append(fields, item.FieldSoldTo) } - if m.FieldCleared(item.FieldSoldReceiptID) { - fields = append(fields, item.FieldSoldReceiptID) - } if m.FieldCleared(item.FieldSoldNotes) { fields = append(fields, item.FieldSoldNotes) } @@ -2954,24 +3005,24 @@ func (m *ItemMutation) ClearField(name string) error { case item.FieldManufacturer: m.ClearManufacturer() return nil + case item.FieldWarrantyExpires: + m.ClearWarrantyExpires() + return nil + case item.FieldWarrantyDetails: + m.ClearWarrantyDetails() + return nil case item.FieldPurchaseTime: m.ClearPurchaseTime() return nil case item.FieldPurchaseFrom: m.ClearPurchaseFrom() return nil - case item.FieldPurchaseReceiptID: - m.ClearPurchaseReceiptID() - return nil case item.FieldSoldTime: m.ClearSoldTime() return nil case item.FieldSoldTo: m.ClearSoldTo() return nil - case item.FieldSoldReceiptID: - m.ClearSoldReceiptID() - return nil case item.FieldSoldNotes: m.ClearSoldNotes() return nil @@ -3007,6 +3058,15 @@ func (m *ItemMutation) ResetField(name string) error { case item.FieldManufacturer: m.ResetManufacturer() return nil + case item.FieldLifetimeWarranty: + m.ResetLifetimeWarranty() + return nil + case item.FieldWarrantyExpires: + m.ResetWarrantyExpires() + return nil + case item.FieldWarrantyDetails: + m.ResetWarrantyDetails() + return nil case item.FieldPurchaseTime: m.ResetPurchaseTime() return nil @@ -3016,9 +3076,6 @@ func (m *ItemMutation) ResetField(name string) error { case item.FieldPurchasePrice: m.ResetPurchasePrice() return nil - case item.FieldPurchaseReceiptID: - m.ResetPurchaseReceiptID() - return nil case item.FieldSoldTime: m.ResetSoldTime() return nil @@ -3028,9 +3085,6 @@ func (m *ItemMutation) ResetField(name string) error { case item.FieldSoldPrice: m.ResetSoldPrice() return nil - case item.FieldSoldReceiptID: - m.ResetSoldReceiptID() - return nil case item.FieldSoldNotes: m.ResetSoldNotes() return nil diff --git a/backend/ent/runtime.go b/backend/ent/runtime.go index 8dc33ae..6a5b8df 100644 --- a/backend/ent/runtime.go +++ b/backend/ent/runtime.go @@ -135,16 +135,24 @@ func init() { itemDescManufacturer := itemFields[3].Descriptor() // item.ManufacturerValidator is a validator for the "manufacturer" field. It is called by the builders before save. item.ManufacturerValidator = itemDescManufacturer.Validators[0].(func(string) error) + // itemDescLifetimeWarranty is the schema descriptor for lifetime_warranty field. + itemDescLifetimeWarranty := itemFields[4].Descriptor() + // item.DefaultLifetimeWarranty holds the default value on creation for the lifetime_warranty field. + item.DefaultLifetimeWarranty = itemDescLifetimeWarranty.Default.(bool) + // itemDescWarrantyDetails is the schema descriptor for warranty_details field. + itemDescWarrantyDetails := itemFields[6].Descriptor() + // item.WarrantyDetailsValidator is a validator for the "warranty_details" field. It is called by the builders before save. + item.WarrantyDetailsValidator = itemDescWarrantyDetails.Validators[0].(func(string) error) // itemDescPurchasePrice is the schema descriptor for purchase_price field. - itemDescPurchasePrice := itemFields[6].Descriptor() + itemDescPurchasePrice := itemFields[9].Descriptor() // item.DefaultPurchasePrice holds the default value on creation for the purchase_price field. item.DefaultPurchasePrice = itemDescPurchasePrice.Default.(float64) // itemDescSoldPrice is the schema descriptor for sold_price field. - itemDescSoldPrice := itemFields[10].Descriptor() + itemDescSoldPrice := itemFields[12].Descriptor() // item.DefaultSoldPrice holds the default value on creation for the sold_price field. item.DefaultSoldPrice = itemDescSoldPrice.Default.(float64) // itemDescSoldNotes is the schema descriptor for sold_notes field. - itemDescSoldNotes := itemFields[12].Descriptor() + itemDescSoldNotes := itemFields[13].Descriptor() // item.SoldNotesValidator is a validator for the "sold_notes" field. It is called by the builders before save. item.SoldNotesValidator = itemDescSoldNotes.Validators[0].(func(string) error) // itemDescID is the schema descriptor for id field. diff --git a/backend/ent/schema/item.go b/backend/ent/schema/item.go index affc0bc..8c2f4cc 100644 --- a/backend/ent/schema/item.go +++ b/backend/ent/schema/item.go @@ -5,7 +5,7 @@ import ( "entgo.io/ent/dialect/entsql" "entgo.io/ent/schema/edge" "entgo.io/ent/schema/field" - "github.com/google/uuid" + "entgo.io/ent/schema/index" "github.com/hay-kot/content/backend/ent/schema/mixins" ) @@ -21,12 +21,23 @@ func (Item) Mixin() []ent.Mixin { } } +func (Item) Indexes() []ent.Index { + return []ent.Index{ + // Unique index on the "title" field. + index.Fields("name"), + index.Fields("manufacturer"), + index.Fields("model_number"), + index.Fields("serial_number"), + } +} + // Fields of the Item. func (Item) Fields() []ent.Field { return []ent.Field{ field.String("notes"). MaxLen(1000). Optional(), + // ------------------------------------ // item identification field.String("serial_number"). @@ -38,6 +49,17 @@ func (Item) Fields() []ent.Field { field.String("manufacturer"). MaxLen(255). Optional(), + + // ------------------------------------ + // Item Warranty + field.Bool("lifetime_warranty"). + Default(false), + field.Time("warranty_expires"). + Optional(), + field.Text("warranty_details"). + MaxLen(1000). + Optional(), + // ------------------------------------ // item purchase field.Time("purchase_time"). @@ -46,8 +68,7 @@ func (Item) Fields() []ent.Field { Optional(), field.Float("purchase_price"). Default(0), - field.UUID("purchase_receipt_id", uuid.UUID{}). - Optional(), + // ------------------------------------ // Sold Details field.Time("sold_time"). @@ -56,8 +77,6 @@ func (Item) Fields() []ent.Field { Optional(), field.Float("sold_price"). Default(0), - field.UUID("sold_receipt_id", uuid.UUID{}). - Optional(), field.String("sold_notes"). MaxLen(1000). Optional(), diff --git a/backend/go.sum b/backend/go.sum index 2dc9b45..bc98bd8 100644 --- a/backend/go.sum +++ b/backend/go.sum @@ -61,11 +61,13 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= github.com/mattn/go-sqlite3 v1.14.15 h1:vfoHhTN1af61xCRSWzFIWzx2YskyMTwHLrExkBOjvxI= github.com/mattn/go-sqlite3 v1.14.15/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0= github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= +github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= @@ -73,6 +75,8 @@ github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rs/zerolog v1.28.0 h1:MirSo27VyNi7RJYP3078AA1+Cyzd2GB66qy3aUHvsWY= github.com/rs/zerolog v1.28.0/go.mod h1:NILgTygv/Uej1ra5XxGf82ZFSLk58MFGAUS2o6usyD0= github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= +github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= diff --git a/backend/internal/repo/repo_items.go b/backend/internal/repo/repo_items.go index f1f1ace..90fc911 100644 --- a/backend/internal/repo/repo_items.go +++ b/backend/internal/repo/repo_items.go @@ -70,7 +70,10 @@ func (e *ItemsRepository) Update(ctx context.Context, data types.ItemUpdate) (*e SetSoldTo(data.SoldTo). SetSoldPrice(data.SoldPrice). SetSoldNotes(data.SoldNotes). - SetNotes(data.Notes) + SetNotes(data.Notes). + SetLifetimeWarranty(data.LifetimeWarranty). + SetWarrantyExpires(data.WarrantyExpires). + SetWarrantyDetails(data.WarrantyDetails) err := q.Exec(ctx) diff --git a/backend/internal/repo/repo_items_test.go b/backend/internal/repo/repo_items_test.go index 66ef7d5..2768dc4 100644 --- a/backend/internal/repo/repo_items_test.go +++ b/backend/internal/repo/repo_items_test.go @@ -138,21 +138,24 @@ func TestItemsRepository_Update(t *testing.T) { entity := entities[0] updateData := types.ItemUpdate{ - ID: entity.ID, - Name: entity.Name, - LocationID: entity.Edges.Location.ID, - SerialNumber: fk.RandomString(10), - LabelIDs: nil, - ModelNumber: fk.RandomString(10), - Manufacturer: fk.RandomString(10), - PurchaseTime: time.Now(), - PurchaseFrom: fk.RandomString(10), - PurchasePrice: 300.99, - SoldTime: time.Now(), - SoldTo: fk.RandomString(10), - SoldPrice: 300.99, - SoldNotes: fk.RandomString(10), - Notes: fk.RandomString(10), + ID: entity.ID, + Name: entity.Name, + LocationID: entity.Edges.Location.ID, + SerialNumber: fk.RandomString(10), + LabelIDs: nil, + ModelNumber: fk.RandomString(10), + Manufacturer: fk.RandomString(10), + PurchaseTime: time.Now(), + PurchaseFrom: fk.RandomString(10), + PurchasePrice: 300.99, + SoldTime: time.Now(), + SoldTo: fk.RandomString(10), + SoldPrice: 300.99, + SoldNotes: fk.RandomString(10), + Notes: fk.RandomString(10), + WarrantyExpires: time.Now(), + WarrantyDetails: fk.RandomString(10), + LifetimeWarranty: true, } updatedEntity, err := tRepos.Items.Update(context.Background(), updateData) @@ -175,4 +178,7 @@ func TestItemsRepository_Update(t *testing.T) { assert.Equal(t, updateData.SoldPrice, got.SoldPrice) assert.Equal(t, updateData.SoldNotes, got.SoldNotes) assert.Equal(t, updateData.Notes, got.Notes) + // assert.Equal(t, updateData.WarrantyExpires, got.WarrantyExpires) + assert.Equal(t, updateData.WarrantyDetails, got.WarrantyDetails) + assert.Equal(t, updateData.LifetimeWarranty, got.LifetimeWarranty) } diff --git a/backend/internal/types/item_types.go b/backend/internal/types/item_types.go index 057faba..38ca8d7 100644 --- a/backend/internal/types/item_types.go +++ b/backend/internal/types/item_types.go @@ -29,6 +29,11 @@ type ItemUpdate struct { ModelNumber string `json:"modelNumber"` Manufacturer string `json:"manufacturer"` + // Warranty + LifetimeWarranty bool `json:"lifetimeWarranty"` + WarrantyExpires time.Time `json:"warrantyExpires"` + WarrantyDetails string `json:"warrantyDetails"` + // Purchase PurchaseTime time.Time `json:"purchaseTime"` PurchaseFrom string `json:"purchaseFrom"` @@ -61,6 +66,11 @@ type ItemSummary struct { ModelNumber string `json:"modelNumber"` Manufacturer string `json:"manufacturer"` + // Warranty + LifetimeWarranty bool `json:"lifetimeWarranty"` + WarrantyExpires time.Time `json:"warrantyExpires"` + WarrantyDetails string `json:"warrantyDetails"` + // Purchase PurchaseTime time.Time `json:"purchaseTime"` PurchaseFrom string `json:"purchaseFrom"` diff --git a/frontend/lib/api/classes/items.ts b/frontend/lib/api/classes/items.ts index 86e39af..a941d5b 100644 --- a/frontend/lib/api/classes/items.ts +++ b/frontend/lib/api/classes/items.ts @@ -29,6 +29,9 @@ export interface Item { soldTime: Date; soldTo: string; updatedAt: string; + lifetimeWarranty: boolean; + warrantyExpires: Date; + warrantyDetails: string; } export class ItemsApi extends BaseAPI { @@ -50,6 +53,7 @@ export class ItemsApi extends BaseAPI { // Parse Date Types payload.data.purchaseTime = new Date(payload.data.purchaseTime); payload.data.soldTime = new Date(payload.data.soldTime); + payload.data.warrantyExpires = new Date(payload.data.warrantyExpires); return payload; } diff --git a/frontend/lib/requests/requests.ts b/frontend/lib/requests/requests.ts index 5712de7..262b07d 100644 --- a/frontend/lib/requests/requests.ts +++ b/frontend/lib/requests/requests.ts @@ -84,6 +84,7 @@ export class Requests { if (rargs.data) { payload.body = rargs.data; } else { + payload.headers['Content-Type'] = 'application/json'; payload.body = JSON.stringify(rargs.body); } } diff --git a/frontend/pages/item/[id]/index.vue b/frontend/pages/item/[id]/index.vue index 3a2a020..cd23202 100644 --- a/frontend/pages/item/[id]/index.vue +++ b/frontend/pages/item/[id]/index.vue @@ -31,6 +31,27 @@ }; }); + const showWarranty = computed(() => { + if (preferences.value.showEmpty) { + return true; + } + return item.value?.warrantyExpires !== undefined; + }); + + const warrantyDetails = computed(() => { + const payload = {}; + + if (item.value.lifetimeWarranty) { + payload['Lifetime Warranty'] = 'Yes'; + } else { + payload['Warranty Expires'] = item.value?.warrantyExpires || ''; + } + + payload['Warranty Details'] = item.value?.warrantyDetails || ''; + + return payload; + }); + const showPurchase = computed(() => { if (preferences.value.showEmpty) { return true; @@ -146,8 +167,11 @@ + + + - +