mirror of
https://github.com/hay-kot/homebox.git
synced 2024-12-18 04:56:30 +00:00
feat: maintenance log (#170)
* remove repo for document tokens * remove schema for doc tokens * fix id template and generate cmd * schema updates * code gen * bump dependencies * fix broken migrations + add maintenance entry type * spelling * remove debug logger * implement repository layer * routes * API client * wip: maintenance log * remove depreciated call
This commit is contained in:
parent
d6da63187b
commit
5bbb969763
79 changed files with 6320 additions and 4957 deletions
125
backend/app/api/handlers/v1/v1_ctrl_maint_entry.go
Normal file
125
backend/app/api/handlers/v1/v1_ctrl_maint_entry.go
Normal file
|
@ -0,0 +1,125 @@
|
||||||
|
package v1
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/hay-kot/homebox/backend/internal/core/services"
|
||||||
|
"github.com/hay-kot/homebox/backend/internal/data/repo"
|
||||||
|
"github.com/hay-kot/homebox/backend/internal/sys/validate"
|
||||||
|
"github.com/hay-kot/homebox/backend/pkgs/server"
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
// HandleMaintenanceGetLog godoc
|
||||||
|
// @Summary Get Maintenance Log
|
||||||
|
// @Tags Maintenance
|
||||||
|
// @Produce json
|
||||||
|
// @Success 200 {object} repo.MaintenanceLog
|
||||||
|
// @Router /v1/items/{id}/maintenance [GET]
|
||||||
|
// @Security Bearer
|
||||||
|
func (ctrl *V1Controller) HandleMaintenanceLogGet() server.HandlerFunc {
|
||||||
|
return ctrl.handleMaintenanceLog()
|
||||||
|
}
|
||||||
|
|
||||||
|
// HandleMaintenanceEntryCreate godoc
|
||||||
|
// @Summary Create Maintenance Entry
|
||||||
|
// @Tags Maintenance
|
||||||
|
// @Produce json
|
||||||
|
// @Param payload body repo.MaintenanceEntryCreate true "Entry Data"
|
||||||
|
// @Success 200 {object} repo.MaintenanceEntry
|
||||||
|
// @Router /v1/items/{id}/maintenance [POST]
|
||||||
|
// @Security Bearer
|
||||||
|
func (ctrl *V1Controller) HandleMaintenanceEntryCreate() server.HandlerFunc {
|
||||||
|
return ctrl.handleMaintenanceLog()
|
||||||
|
}
|
||||||
|
|
||||||
|
// HandleMaintenanceEntryDelete godoc
|
||||||
|
// @Summary Delete Maintenance Entry
|
||||||
|
// @Tags Maintenance
|
||||||
|
// @Produce json
|
||||||
|
// @Success 204
|
||||||
|
// @Router /v1/items/{id}/maintenance/{entry_id} [DELETE]
|
||||||
|
// @Security Bearer
|
||||||
|
func (ctrl *V1Controller) HandleMaintenanceEntryDelete() server.HandlerFunc {
|
||||||
|
return ctrl.handleMaintenanceLog()
|
||||||
|
}
|
||||||
|
|
||||||
|
// HandleMaintenanceEntryUpdate godoc
|
||||||
|
// @Summary Update Maintenance Entry
|
||||||
|
// @Tags Maintenance
|
||||||
|
// @Produce json
|
||||||
|
// @Param payload body repo.MaintenanceEntryUpdate true "Entry Data"
|
||||||
|
// @Success 200 {object} repo.MaintenanceEntry
|
||||||
|
// @Router /v1/items/{id}/maintenance/{entry_id} [PUT]
|
||||||
|
// @Security Bearer
|
||||||
|
func (ctrl *V1Controller) HandleMaintenanceEntryUpdate() server.HandlerFunc {
|
||||||
|
return ctrl.handleMaintenanceLog()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ctrl *V1Controller) handleMaintenanceLog() server.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) error {
|
||||||
|
ctx := services.NewContext(r.Context())
|
||||||
|
itemID, err := ctrl.routeID(r)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
switch r.Method {
|
||||||
|
case http.MethodGet:
|
||||||
|
mlog, err := ctrl.repo.MaintEntry.GetLog(ctx, itemID)
|
||||||
|
if err != nil {
|
||||||
|
log.Err(err).Msg("failed to get items")
|
||||||
|
return validate.NewRequestError(err, http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
return server.Respond(w, http.StatusOK, mlog)
|
||||||
|
case http.MethodPost:
|
||||||
|
var create repo.MaintenanceEntryCreate
|
||||||
|
err := server.Decode(r, &create)
|
||||||
|
if err != nil {
|
||||||
|
return validate.NewRequestError(err, http.StatusBadRequest)
|
||||||
|
}
|
||||||
|
|
||||||
|
entry, err := ctrl.repo.MaintEntry.Create(ctx, itemID, create)
|
||||||
|
if err != nil {
|
||||||
|
log.Err(err).Msg("failed to create item")
|
||||||
|
return validate.NewRequestError(err, http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
|
||||||
|
return server.Respond(w, http.StatusCreated, entry)
|
||||||
|
case http.MethodPut:
|
||||||
|
entryID, err := ctrl.routeUUID(r, "entry_id")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var update repo.MaintenanceEntryUpdate
|
||||||
|
err = server.Decode(r, &update)
|
||||||
|
if err != nil {
|
||||||
|
return validate.NewRequestError(err, http.StatusBadRequest)
|
||||||
|
}
|
||||||
|
|
||||||
|
entry, err := ctrl.repo.MaintEntry.Update(ctx, entryID, update)
|
||||||
|
if err != nil {
|
||||||
|
log.Err(err).Msg("failed to update item")
|
||||||
|
return validate.NewRequestError(err, http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
|
||||||
|
return server.Respond(w, http.StatusOK, entry)
|
||||||
|
case http.MethodDelete:
|
||||||
|
entryID, err := ctrl.routeUUID(r, "entry_id")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = ctrl.repo.MaintEntry.Delete(ctx, entryID)
|
||||||
|
if err != nil {
|
||||||
|
log.Err(err).Msg("failed to delete item")
|
||||||
|
return validate.NewRequestError(err, http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
|
||||||
|
return server.Respond(w, http.StatusNoContent, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
|
@ -112,6 +112,11 @@ func (a *app) mountRoutes(repos *repo.AllRepos) {
|
||||||
a.server.Put(v1Base("/items/{id}/attachments/{attachment_id}"), v1Ctrl.HandleItemAttachmentUpdate(), userMW...)
|
a.server.Put(v1Base("/items/{id}/attachments/{attachment_id}"), v1Ctrl.HandleItemAttachmentUpdate(), userMW...)
|
||||||
a.server.Delete(v1Base("/items/{id}/attachments/{attachment_id}"), v1Ctrl.HandleItemAttachmentDelete(), userMW...)
|
a.server.Delete(v1Base("/items/{id}/attachments/{attachment_id}"), v1Ctrl.HandleItemAttachmentDelete(), userMW...)
|
||||||
|
|
||||||
|
a.server.Get(v1Base("/items/{id}/maintenance"), v1Ctrl.HandleMaintenanceEntryCreate(), userMW...)
|
||||||
|
a.server.Post(v1Base("/items/{id}/maintenance"), v1Ctrl.HandleMaintenanceEntryCreate(), userMW...)
|
||||||
|
a.server.Put(v1Base("/items/{id}/maintenance/{entry_id}"), v1Ctrl.HandleMaintenanceEntryUpdate(), userMW...)
|
||||||
|
a.server.Delete(v1Base("/items/{id}/maintenance/{entry_id}"), v1Ctrl.HandleMaintenanceEntryDelete(), userMW...)
|
||||||
|
|
||||||
a.server.Get(
|
a.server.Get(
|
||||||
v1Base("/items/{id}/attachments/{attachment_id}"),
|
v1Base("/items/{id}/attachments/{attachment_id}"),
|
||||||
v1Ctrl.HandleItemAttachmentGet(),
|
v1Ctrl.HandleItemAttachmentGet(),
|
||||||
|
|
|
@ -657,6 +657,117 @@ const docTemplate = `{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/v1/items/{id}/maintenance": {
|
||||||
|
"get": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"Bearer": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"Maintenance"
|
||||||
|
],
|
||||||
|
"summary": "Get Maintenance Log",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/repo.MaintenanceLog"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"post": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"Bearer": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"Maintenance"
|
||||||
|
],
|
||||||
|
"summary": "Create Maintenance Entry",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"description": "Entry Data",
|
||||||
|
"name": "payload",
|
||||||
|
"in": "body",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/repo.MaintenanceEntryCreate"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/repo.MaintenanceEntry"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/v1/items/{id}/maintenance/{entry_id}": {
|
||||||
|
"put": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"Bearer": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"Maintenance"
|
||||||
|
],
|
||||||
|
"summary": "Update Maintenance Entry",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"description": "Entry Data",
|
||||||
|
"name": "payload",
|
||||||
|
"in": "body",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/repo.MaintenanceEntryUpdate"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/repo.MaintenanceEntry"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"delete": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"Bearer": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"Maintenance"
|
||||||
|
],
|
||||||
|
"summary": "Delete Maintenance Entry",
|
||||||
|
"responses": {
|
||||||
|
"204": {
|
||||||
|
"description": "No Content"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/v1/labels": {
|
"/v1/labels": {
|
||||||
"get": {
|
"get": {
|
||||||
"security": [
|
"security": [
|
||||||
|
@ -1825,6 +1936,83 @@ const docTemplate = `{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"repo.MaintenanceEntry": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"cost": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "0"
|
||||||
|
},
|
||||||
|
"date": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"description": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"id": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"repo.MaintenanceEntryCreate": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"cost": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "0"
|
||||||
|
},
|
||||||
|
"date": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"description": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"repo.MaintenanceEntryUpdate": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"cost": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "0"
|
||||||
|
},
|
||||||
|
"date": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"description": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"repo.MaintenanceLog": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"costAverage": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"costTotal": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"entries": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/repo.MaintenanceEntry"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"itemId": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"repo.PaginationResult-repo_ItemSummary": {
|
"repo.PaginationResult-repo_ItemSummary": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
|
|
@ -649,6 +649,117 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/v1/items/{id}/maintenance": {
|
||||||
|
"get": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"Bearer": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"Maintenance"
|
||||||
|
],
|
||||||
|
"summary": "Get Maintenance Log",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/repo.MaintenanceLog"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"post": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"Bearer": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"Maintenance"
|
||||||
|
],
|
||||||
|
"summary": "Create Maintenance Entry",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"description": "Entry Data",
|
||||||
|
"name": "payload",
|
||||||
|
"in": "body",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/repo.MaintenanceEntryCreate"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/repo.MaintenanceEntry"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/v1/items/{id}/maintenance/{entry_id}": {
|
||||||
|
"put": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"Bearer": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"Maintenance"
|
||||||
|
],
|
||||||
|
"summary": "Update Maintenance Entry",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"description": "Entry Data",
|
||||||
|
"name": "payload",
|
||||||
|
"in": "body",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/repo.MaintenanceEntryUpdate"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/repo.MaintenanceEntry"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"delete": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"Bearer": []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"Maintenance"
|
||||||
|
],
|
||||||
|
"summary": "Delete Maintenance Entry",
|
||||||
|
"responses": {
|
||||||
|
"204": {
|
||||||
|
"description": "No Content"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/v1/labels": {
|
"/v1/labels": {
|
||||||
"get": {
|
"get": {
|
||||||
"security": [
|
"security": [
|
||||||
|
@ -1817,6 +1928,83 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"repo.MaintenanceEntry": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"cost": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "0"
|
||||||
|
},
|
||||||
|
"date": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"description": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"id": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"repo.MaintenanceEntryCreate": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"cost": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "0"
|
||||||
|
},
|
||||||
|
"date": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"description": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"repo.MaintenanceEntryUpdate": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"cost": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "0"
|
||||||
|
},
|
||||||
|
"date": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"description": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"repo.MaintenanceLog": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"costAverage": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"costTotal": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"entries": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/repo.MaintenanceEntry"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"itemId": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"repo.PaginationResult-repo_ItemSummary": {
|
"repo.PaginationResult-repo_ItemSummary": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
|
|
@ -383,6 +383,57 @@ definitions:
|
||||||
type: string
|
type: string
|
||||||
x-nullable: true
|
x-nullable: true
|
||||||
type: object
|
type: object
|
||||||
|
repo.MaintenanceEntry:
|
||||||
|
properties:
|
||||||
|
cost:
|
||||||
|
example: "0"
|
||||||
|
type: string
|
||||||
|
date:
|
||||||
|
type: string
|
||||||
|
description:
|
||||||
|
type: string
|
||||||
|
id:
|
||||||
|
type: string
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
|
repo.MaintenanceEntryCreate:
|
||||||
|
properties:
|
||||||
|
cost:
|
||||||
|
example: "0"
|
||||||
|
type: string
|
||||||
|
date:
|
||||||
|
type: string
|
||||||
|
description:
|
||||||
|
type: string
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
|
repo.MaintenanceEntryUpdate:
|
||||||
|
properties:
|
||||||
|
cost:
|
||||||
|
example: "0"
|
||||||
|
type: string
|
||||||
|
date:
|
||||||
|
type: string
|
||||||
|
description:
|
||||||
|
type: string
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
|
repo.MaintenanceLog:
|
||||||
|
properties:
|
||||||
|
costAverage:
|
||||||
|
type: number
|
||||||
|
costTotal:
|
||||||
|
type: number
|
||||||
|
entries:
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/repo.MaintenanceEntry'
|
||||||
|
type: array
|
||||||
|
itemId:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
repo.PaginationResult-repo_ItemSummary:
|
repo.PaginationResult-repo_ItemSummary:
|
||||||
properties:
|
properties:
|
||||||
items:
|
items:
|
||||||
|
@ -938,6 +989,72 @@ paths:
|
||||||
summary: retrieves an attachment for an item
|
summary: retrieves an attachment for an item
|
||||||
tags:
|
tags:
|
||||||
- Items Attachments
|
- Items Attachments
|
||||||
|
/v1/items/{id}/maintenance:
|
||||||
|
get:
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/repo.MaintenanceLog'
|
||||||
|
security:
|
||||||
|
- Bearer: []
|
||||||
|
summary: Get Maintenance Log
|
||||||
|
tags:
|
||||||
|
- Maintenance
|
||||||
|
post:
|
||||||
|
parameters:
|
||||||
|
- description: Entry Data
|
||||||
|
in: body
|
||||||
|
name: payload
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/repo.MaintenanceEntryCreate'
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/repo.MaintenanceEntry'
|
||||||
|
security:
|
||||||
|
- Bearer: []
|
||||||
|
summary: Create Maintenance Entry
|
||||||
|
tags:
|
||||||
|
- Maintenance
|
||||||
|
/v1/items/{id}/maintenance/{entry_id}:
|
||||||
|
delete:
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"204":
|
||||||
|
description: No Content
|
||||||
|
security:
|
||||||
|
- Bearer: []
|
||||||
|
summary: Delete Maintenance Entry
|
||||||
|
tags:
|
||||||
|
- Maintenance
|
||||||
|
put:
|
||||||
|
parameters:
|
||||||
|
- description: Entry Data
|
||||||
|
in: body
|
||||||
|
name: payload
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/repo.MaintenanceEntryUpdate'
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/repo.MaintenanceEntry'
|
||||||
|
security:
|
||||||
|
- Bearer: []
|
||||||
|
summary: Update Maintenance Entry
|
||||||
|
tags:
|
||||||
|
- Maintenance
|
||||||
/v1/items/import:
|
/v1/items/import:
|
||||||
post:
|
post:
|
||||||
parameters:
|
parameters:
|
||||||
|
|
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
@ -39,4 +40,6 @@ func main() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("failed generating migration file: %v", err)
|
log.Fatalf("failed generating migration file: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Println("Migration file generated successfully.")
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ module github.com/hay-kot/homebox/backend
|
||||||
go 1.19
|
go 1.19
|
||||||
|
|
||||||
require (
|
require (
|
||||||
ariga.io/atlas v0.7.3-0.20221011160332-3ca609863edd
|
ariga.io/atlas v0.8.3
|
||||||
entgo.io/ent v0.11.4
|
entgo.io/ent v0.11.4
|
||||||
github.com/ardanlabs/conf/v2 v2.2.0
|
github.com/ardanlabs/conf/v2 v2.2.0
|
||||||
github.com/go-chi/chi/v5 v5.0.7
|
github.com/go-chi/chi/v5 v5.0.7
|
||||||
|
@ -14,7 +14,7 @@ require (
|
||||||
github.com/stretchr/testify v1.8.1
|
github.com/stretchr/testify v1.8.1
|
||||||
github.com/swaggo/http-swagger v1.3.3
|
github.com/swaggo/http-swagger v1.3.3
|
||||||
github.com/swaggo/swag v1.8.8
|
github.com/swaggo/swag v1.8.8
|
||||||
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90
|
golang.org/x/crypto v0.3.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
@ -30,7 +30,7 @@ require (
|
||||||
github.com/go-playground/locales v0.14.0 // indirect
|
github.com/go-playground/locales v0.14.0 // indirect
|
||||||
github.com/go-playground/universal-translator v0.18.0 // indirect
|
github.com/go-playground/universal-translator v0.18.0 // indirect
|
||||||
github.com/google/go-cmp v0.5.9 // indirect
|
github.com/google/go-cmp v0.5.9 // indirect
|
||||||
github.com/hashicorp/hcl/v2 v2.14.1 // indirect
|
github.com/hashicorp/hcl/v2 v2.15.0 // indirect
|
||||||
github.com/josharian/intern v1.0.0 // indirect
|
github.com/josharian/intern v1.0.0 // indirect
|
||||||
github.com/leodido/go-urn v1.2.1 // indirect
|
github.com/leodido/go-urn v1.2.1 // indirect
|
||||||
github.com/mailru/easyjson v0.7.7 // indirect
|
github.com/mailru/easyjson v0.7.7 // indirect
|
||||||
|
@ -39,11 +39,11 @@ require (
|
||||||
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
|
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
github.com/swaggo/files v0.0.0-20220728132757-551d4a08d97a // indirect
|
github.com/swaggo/files v0.0.0-20220728132757-551d4a08d97a // indirect
|
||||||
github.com/zclconf/go-cty v1.11.0 // indirect
|
github.com/zclconf/go-cty v1.12.1 // indirect
|
||||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
|
golang.org/x/mod v0.7.0 // indirect
|
||||||
golang.org/x/net v0.0.0-20220923203811-8be639271d50 // indirect
|
golang.org/x/net v0.2.0 // indirect
|
||||||
golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8 // indirect
|
golang.org/x/sys v0.3.0 // indirect
|
||||||
golang.org/x/text v0.3.7 // indirect
|
golang.org/x/text v0.5.0 // indirect
|
||||||
golang.org/x/tools v0.1.13-0.20220804200503-81c7dc4e4efa // indirect
|
golang.org/x/tools v0.3.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
ariga.io/atlas v0.7.3-0.20221011160332-3ca609863edd h1:c3F2jvvEZzsoH/KUpDNhTsCVeUPnpXaF8kADZvUSiU0=
|
ariga.io/atlas v0.8.3 h1:nddOywkhr/62Cwa+UsGgO35lAhUYh52XGVsbFwGzWZM=
|
||||||
ariga.io/atlas v0.7.3-0.20221011160332-3ca609863edd/go.mod h1:ft47uSh5hWGDCmQC9DsztZg6Xk+KagM5Ts/mZYKb9JE=
|
ariga.io/atlas v0.8.3/go.mod h1:T230JFcENj4ZZzMkZrXFDSkv+2kXkUgpJ5FQQ5hMcKU=
|
||||||
entgo.io/ent v0.11.4 h1:grwVY0fp31BZ6oEo3YrXenAuv8VJmEw7F/Bi6WqeH3Q=
|
entgo.io/ent v0.11.4 h1:grwVY0fp31BZ6oEo3YrXenAuv8VJmEw7F/Bi6WqeH3Q=
|
||||||
entgo.io/ent v0.11.4/go.mod h1:fnQIXL36RYnCk/9nvG4aE7YHBFZhCycfh7wMjY5p7SE=
|
entgo.io/ent v0.11.4/go.mod h1:fnQIXL36RYnCk/9nvG4aE7YHBFZhCycfh7wMjY5p7SE=
|
||||||
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
|
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
|
||||||
|
@ -7,7 +7,6 @@ github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc
|
||||||
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
|
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
|
||||||
github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo=
|
github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo=
|
||||||
github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
|
github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
|
||||||
github.com/apparentlymart/go-dump v0.0.0-20180507223929-23540a00eaa3 h1:ZSTrOEhiM5J5RFxEaFvMZVEAM1KvT1YzbEOwB2EAGjA=
|
|
||||||
github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw=
|
github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw=
|
||||||
github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo=
|
github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo=
|
||||||
github.com/ardanlabs/conf/v2 v2.2.0 h1:ar1+TYIYAh2Tdeg2DQroh7ruR56/vJR8BDfzDIrXgtk=
|
github.com/ardanlabs/conf/v2 v2.2.0 h1:ar1+TYIYAh2Tdeg2DQroh7ruR56/vJR8BDfzDIrXgtk=
|
||||||
|
@ -47,8 +46,8 @@ github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||||
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/hashicorp/hcl/v2 v2.14.1 h1:x0BpjfZ+CYdbiz+8yZTQ+gdLO7IXvOut7Da+XJayx34=
|
github.com/hashicorp/hcl/v2 v2.15.0 h1:CPDXO6+uORPjKflkWCCwoWc9uRp+zSIPcCQ+BrxV7m8=
|
||||||
github.com/hashicorp/hcl/v2 v2.14.1/go.mod h1:e4z5nxYlWNPdDSNYX+ph14EvWYMFm3eP0zIUqPc2jr0=
|
github.com/hashicorp/hcl/v2 v2.15.0/go.mod h1:JRmR89jycNkrrqnMmvPDMd56n1rQJ2Q6KocSLCMCXng=
|
||||||
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
|
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
|
||||||
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
|
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
|
||||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||||
|
@ -109,17 +108,17 @@ github.com/swaggo/http-swagger v1.3.3 h1:Hu5Z0L9ssyBLofaama21iYaF2VbWyA8jdohaaCG
|
||||||
github.com/swaggo/http-swagger v1.3.3/go.mod h1:sE+4PjD89IxMPm77FnkDz0sdO+p5lbXzrVWT6OTVVGo=
|
github.com/swaggo/http-swagger v1.3.3/go.mod h1:sE+4PjD89IxMPm77FnkDz0sdO+p5lbXzrVWT6OTVVGo=
|
||||||
github.com/swaggo/swag v1.8.8 h1:/GgJmrJ8/c0z4R4hoEPZ5UeEhVGdvsII4JbVDLbR7Xc=
|
github.com/swaggo/swag v1.8.8 h1:/GgJmrJ8/c0z4R4hoEPZ5UeEhVGdvsII4JbVDLbR7Xc=
|
||||||
github.com/swaggo/swag v1.8.8/go.mod h1:ezQVUUhly8dludpVk+/PuwJWvLLanB13ygV5Pr9enSk=
|
github.com/swaggo/swag v1.8.8/go.mod h1:ezQVUUhly8dludpVk+/PuwJWvLLanB13ygV5Pr9enSk=
|
||||||
github.com/zclconf/go-cty v1.11.0 h1:726SxLdi2SDnjY+BStqB9J1hNp4+2WlzyXLuimibIe0=
|
github.com/zclconf/go-cty v1.12.1 h1:PcupnljUm9EIvbgSHQnHhUr3fO6oFmkOrvs2BAFNXXY=
|
||||||
github.com/zclconf/go-cty v1.11.0/go.mod h1:s9IfD1LK5ccNMSWCVFCE2rJfHiZgi7JijgeWIMfhLvA=
|
github.com/zclconf/go-cty v1.12.1/go.mod h1:s9IfD1LK5ccNMSWCVFCE2rJfHiZgi7JijgeWIMfhLvA=
|
||||||
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||||
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90 h1:Y/gsMcFOcR+6S6f3YeMKl5g+dZMEWqcz5Czj/GWYbkM=
|
golang.org/x/crypto v0.3.0 h1:a06MkbcxBrEFc0w0QIZWXrH/9cCX6KJyWbBOIwAn+7A=
|
||||||
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
|
||||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=
|
golang.org/x/mod v0.7.0 h1:LapD9S96VoQRhi/GrNTqeBJFrUjs5UHCAtTlgwA5oZA=
|
||||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||||
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||||
golang.org/x/net v0.0.0-20220923203811-8be639271d50 h1:vKyz8L3zkd+xrMeIaBsQ/MNVPVFSffdaU3ZyYlBGFnI=
|
golang.org/x/net v0.2.0 h1:sZfSu1wtKLGlWI4ZZayP0ck9Y73K1ynO6gqzTdBVdPU=
|
||||||
golang.org/x/net v0.0.0-20220923203811-8be639271d50/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
|
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
@ -127,15 +126,16 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBc
|
||||||
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8 h1:h+EGohizhe9XlX18rfpa8k8RAc5XyaeamM+0VHRd4lc=
|
golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
|
||||||
golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
|
|
||||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||||
|
golang.org/x/text v0.5.0 h1:OLmvp0KP+FVG99Ct/qFiL/Fhk4zp4QQnZ7b2U+5piUM=
|
||||||
|
golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/tools v0.1.13-0.20220804200503-81c7dc4e4efa h1:uKcci2q7Qtp6nMTC/AAvfNUAldFtJuHWV9/5QWiypts=
|
golang.org/x/tools v0.3.0 h1:SrNbZl6ECOS1qFzgTdQfWXZM9XBkiA6tkFrH9YSTPHM=
|
||||||
golang.org/x/tools v0.1.13-0.20220804200503-81c7dc4e4efa/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
golang.org/x/tools v0.3.0/go.mod h1:/rWhSS2+zyEVwoJf8YAX6L2f0ntZ7Kn/mGgAWcipA5k=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
|
|
@ -15,13 +15,13 @@ import (
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/authroles"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/authroles"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/authtokens"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/authtokens"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/document"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/document"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/documenttoken"
|
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/group"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/group"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/groupinvitationtoken"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/groupinvitationtoken"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/item"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/item"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/itemfield"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/itemfield"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/label"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/label"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/location"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/location"
|
||||||
|
"github.com/hay-kot/homebox/backend/internal/data/ent/maintenanceentry"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/user"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/user"
|
||||||
|
|
||||||
"entgo.io/ent/dialect"
|
"entgo.io/ent/dialect"
|
||||||
|
@ -42,8 +42,6 @@ type Client struct {
|
||||||
AuthTokens *AuthTokensClient
|
AuthTokens *AuthTokensClient
|
||||||
// Document is the client for interacting with the Document builders.
|
// Document is the client for interacting with the Document builders.
|
||||||
Document *DocumentClient
|
Document *DocumentClient
|
||||||
// DocumentToken is the client for interacting with the DocumentToken builders.
|
|
||||||
DocumentToken *DocumentTokenClient
|
|
||||||
// Group is the client for interacting with the Group builders.
|
// Group is the client for interacting with the Group builders.
|
||||||
Group *GroupClient
|
Group *GroupClient
|
||||||
// GroupInvitationToken is the client for interacting with the GroupInvitationToken builders.
|
// GroupInvitationToken is the client for interacting with the GroupInvitationToken builders.
|
||||||
|
@ -56,6 +54,8 @@ type Client struct {
|
||||||
Label *LabelClient
|
Label *LabelClient
|
||||||
// Location is the client for interacting with the Location builders.
|
// Location is the client for interacting with the Location builders.
|
||||||
Location *LocationClient
|
Location *LocationClient
|
||||||
|
// MaintenanceEntry is the client for interacting with the MaintenanceEntry builders.
|
||||||
|
MaintenanceEntry *MaintenanceEntryClient
|
||||||
// User is the client for interacting with the User builders.
|
// User is the client for interacting with the User builders.
|
||||||
User *UserClient
|
User *UserClient
|
||||||
}
|
}
|
||||||
|
@ -75,13 +75,13 @@ func (c *Client) init() {
|
||||||
c.AuthRoles = NewAuthRolesClient(c.config)
|
c.AuthRoles = NewAuthRolesClient(c.config)
|
||||||
c.AuthTokens = NewAuthTokensClient(c.config)
|
c.AuthTokens = NewAuthTokensClient(c.config)
|
||||||
c.Document = NewDocumentClient(c.config)
|
c.Document = NewDocumentClient(c.config)
|
||||||
c.DocumentToken = NewDocumentTokenClient(c.config)
|
|
||||||
c.Group = NewGroupClient(c.config)
|
c.Group = NewGroupClient(c.config)
|
||||||
c.GroupInvitationToken = NewGroupInvitationTokenClient(c.config)
|
c.GroupInvitationToken = NewGroupInvitationTokenClient(c.config)
|
||||||
c.Item = NewItemClient(c.config)
|
c.Item = NewItemClient(c.config)
|
||||||
c.ItemField = NewItemFieldClient(c.config)
|
c.ItemField = NewItemFieldClient(c.config)
|
||||||
c.Label = NewLabelClient(c.config)
|
c.Label = NewLabelClient(c.config)
|
||||||
c.Location = NewLocationClient(c.config)
|
c.Location = NewLocationClient(c.config)
|
||||||
|
c.MaintenanceEntry = NewMaintenanceEntryClient(c.config)
|
||||||
c.User = NewUserClient(c.config)
|
c.User = NewUserClient(c.config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,13 +120,13 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) {
|
||||||
AuthRoles: NewAuthRolesClient(cfg),
|
AuthRoles: NewAuthRolesClient(cfg),
|
||||||
AuthTokens: NewAuthTokensClient(cfg),
|
AuthTokens: NewAuthTokensClient(cfg),
|
||||||
Document: NewDocumentClient(cfg),
|
Document: NewDocumentClient(cfg),
|
||||||
DocumentToken: NewDocumentTokenClient(cfg),
|
|
||||||
Group: NewGroupClient(cfg),
|
Group: NewGroupClient(cfg),
|
||||||
GroupInvitationToken: NewGroupInvitationTokenClient(cfg),
|
GroupInvitationToken: NewGroupInvitationTokenClient(cfg),
|
||||||
Item: NewItemClient(cfg),
|
Item: NewItemClient(cfg),
|
||||||
ItemField: NewItemFieldClient(cfg),
|
ItemField: NewItemFieldClient(cfg),
|
||||||
Label: NewLabelClient(cfg),
|
Label: NewLabelClient(cfg),
|
||||||
Location: NewLocationClient(cfg),
|
Location: NewLocationClient(cfg),
|
||||||
|
MaintenanceEntry: NewMaintenanceEntryClient(cfg),
|
||||||
User: NewUserClient(cfg),
|
User: NewUserClient(cfg),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -151,13 +151,13 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
|
||||||
AuthRoles: NewAuthRolesClient(cfg),
|
AuthRoles: NewAuthRolesClient(cfg),
|
||||||
AuthTokens: NewAuthTokensClient(cfg),
|
AuthTokens: NewAuthTokensClient(cfg),
|
||||||
Document: NewDocumentClient(cfg),
|
Document: NewDocumentClient(cfg),
|
||||||
DocumentToken: NewDocumentTokenClient(cfg),
|
|
||||||
Group: NewGroupClient(cfg),
|
Group: NewGroupClient(cfg),
|
||||||
GroupInvitationToken: NewGroupInvitationTokenClient(cfg),
|
GroupInvitationToken: NewGroupInvitationTokenClient(cfg),
|
||||||
Item: NewItemClient(cfg),
|
Item: NewItemClient(cfg),
|
||||||
ItemField: NewItemFieldClient(cfg),
|
ItemField: NewItemFieldClient(cfg),
|
||||||
Label: NewLabelClient(cfg),
|
Label: NewLabelClient(cfg),
|
||||||
Location: NewLocationClient(cfg),
|
Location: NewLocationClient(cfg),
|
||||||
|
MaintenanceEntry: NewMaintenanceEntryClient(cfg),
|
||||||
User: NewUserClient(cfg),
|
User: NewUserClient(cfg),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -191,13 +191,13 @@ func (c *Client) Use(hooks ...Hook) {
|
||||||
c.AuthRoles.Use(hooks...)
|
c.AuthRoles.Use(hooks...)
|
||||||
c.AuthTokens.Use(hooks...)
|
c.AuthTokens.Use(hooks...)
|
||||||
c.Document.Use(hooks...)
|
c.Document.Use(hooks...)
|
||||||
c.DocumentToken.Use(hooks...)
|
|
||||||
c.Group.Use(hooks...)
|
c.Group.Use(hooks...)
|
||||||
c.GroupInvitationToken.Use(hooks...)
|
c.GroupInvitationToken.Use(hooks...)
|
||||||
c.Item.Use(hooks...)
|
c.Item.Use(hooks...)
|
||||||
c.ItemField.Use(hooks...)
|
c.ItemField.Use(hooks...)
|
||||||
c.Label.Use(hooks...)
|
c.Label.Use(hooks...)
|
||||||
c.Location.Use(hooks...)
|
c.Location.Use(hooks...)
|
||||||
|
c.MaintenanceEntry.Use(hooks...)
|
||||||
c.User.Use(hooks...)
|
c.User.Use(hooks...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -652,22 +652,6 @@ func (c *DocumentClient) QueryGroup(d *Document) *GroupQuery {
|
||||||
return query
|
return query
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryDocumentTokens queries the document_tokens edge of a Document.
|
|
||||||
func (c *DocumentClient) QueryDocumentTokens(d *Document) *DocumentTokenQuery {
|
|
||||||
query := &DocumentTokenQuery{config: c.config}
|
|
||||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
||||||
id := d.ID
|
|
||||||
step := sqlgraph.NewStep(
|
|
||||||
sqlgraph.From(document.Table, document.FieldID, id),
|
|
||||||
sqlgraph.To(documenttoken.Table, documenttoken.FieldID),
|
|
||||||
sqlgraph.Edge(sqlgraph.O2M, false, document.DocumentTokensTable, document.DocumentTokensColumn),
|
|
||||||
)
|
|
||||||
fromV = sqlgraph.Neighbors(d.driver.Dialect(), step)
|
|
||||||
return fromV, nil
|
|
||||||
}
|
|
||||||
return query
|
|
||||||
}
|
|
||||||
|
|
||||||
// QueryAttachments queries the attachments edge of a Document.
|
// QueryAttachments queries the attachments edge of a Document.
|
||||||
func (c *DocumentClient) QueryAttachments(d *Document) *AttachmentQuery {
|
func (c *DocumentClient) QueryAttachments(d *Document) *AttachmentQuery {
|
||||||
query := &AttachmentQuery{config: c.config}
|
query := &AttachmentQuery{config: c.config}
|
||||||
|
@ -689,112 +673,6 @@ func (c *DocumentClient) Hooks() []Hook {
|
||||||
return c.hooks.Document
|
return c.hooks.Document
|
||||||
}
|
}
|
||||||
|
|
||||||
// DocumentTokenClient is a client for the DocumentToken schema.
|
|
||||||
type DocumentTokenClient struct {
|
|
||||||
config
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewDocumentTokenClient returns a client for the DocumentToken from the given config.
|
|
||||||
func NewDocumentTokenClient(c config) *DocumentTokenClient {
|
|
||||||
return &DocumentTokenClient{config: c}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use adds a list of mutation hooks to the hooks stack.
|
|
||||||
// A call to `Use(f, g, h)` equals to `documenttoken.Hooks(f(g(h())))`.
|
|
||||||
func (c *DocumentTokenClient) Use(hooks ...Hook) {
|
|
||||||
c.hooks.DocumentToken = append(c.hooks.DocumentToken, hooks...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create returns a builder for creating a DocumentToken entity.
|
|
||||||
func (c *DocumentTokenClient) Create() *DocumentTokenCreate {
|
|
||||||
mutation := newDocumentTokenMutation(c.config, OpCreate)
|
|
||||||
return &DocumentTokenCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateBulk returns a builder for creating a bulk of DocumentToken entities.
|
|
||||||
func (c *DocumentTokenClient) CreateBulk(builders ...*DocumentTokenCreate) *DocumentTokenCreateBulk {
|
|
||||||
return &DocumentTokenCreateBulk{config: c.config, builders: builders}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update returns an update builder for DocumentToken.
|
|
||||||
func (c *DocumentTokenClient) Update() *DocumentTokenUpdate {
|
|
||||||
mutation := newDocumentTokenMutation(c.config, OpUpdate)
|
|
||||||
return &DocumentTokenUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdateOne returns an update builder for the given entity.
|
|
||||||
func (c *DocumentTokenClient) UpdateOne(dt *DocumentToken) *DocumentTokenUpdateOne {
|
|
||||||
mutation := newDocumentTokenMutation(c.config, OpUpdateOne, withDocumentToken(dt))
|
|
||||||
return &DocumentTokenUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdateOneID returns an update builder for the given id.
|
|
||||||
func (c *DocumentTokenClient) UpdateOneID(id uuid.UUID) *DocumentTokenUpdateOne {
|
|
||||||
mutation := newDocumentTokenMutation(c.config, OpUpdateOne, withDocumentTokenID(id))
|
|
||||||
return &DocumentTokenUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete returns a delete builder for DocumentToken.
|
|
||||||
func (c *DocumentTokenClient) Delete() *DocumentTokenDelete {
|
|
||||||
mutation := newDocumentTokenMutation(c.config, OpDelete)
|
|
||||||
return &DocumentTokenDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeleteOne returns a builder for deleting the given entity.
|
|
||||||
func (c *DocumentTokenClient) DeleteOne(dt *DocumentToken) *DocumentTokenDeleteOne {
|
|
||||||
return c.DeleteOneID(dt.ID)
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
|
||||||
func (c *DocumentTokenClient) DeleteOneID(id uuid.UUID) *DocumentTokenDeleteOne {
|
|
||||||
builder := c.Delete().Where(documenttoken.ID(id))
|
|
||||||
builder.mutation.id = &id
|
|
||||||
builder.mutation.op = OpDeleteOne
|
|
||||||
return &DocumentTokenDeleteOne{builder}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Query returns a query builder for DocumentToken.
|
|
||||||
func (c *DocumentTokenClient) Query() *DocumentTokenQuery {
|
|
||||||
return &DocumentTokenQuery{
|
|
||||||
config: c.config,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get returns a DocumentToken entity by its id.
|
|
||||||
func (c *DocumentTokenClient) Get(ctx context.Context, id uuid.UUID) (*DocumentToken, error) {
|
|
||||||
return c.Query().Where(documenttoken.ID(id)).Only(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetX is like Get, but panics if an error occurs.
|
|
||||||
func (c *DocumentTokenClient) GetX(ctx context.Context, id uuid.UUID) *DocumentToken {
|
|
||||||
obj, err := c.Get(ctx, id)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return obj
|
|
||||||
}
|
|
||||||
|
|
||||||
// QueryDocument queries the document edge of a DocumentToken.
|
|
||||||
func (c *DocumentTokenClient) QueryDocument(dt *DocumentToken) *DocumentQuery {
|
|
||||||
query := &DocumentQuery{config: c.config}
|
|
||||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
||||||
id := dt.ID
|
|
||||||
step := sqlgraph.NewStep(
|
|
||||||
sqlgraph.From(documenttoken.Table, documenttoken.FieldID, id),
|
|
||||||
sqlgraph.To(document.Table, document.FieldID),
|
|
||||||
sqlgraph.Edge(sqlgraph.M2O, true, documenttoken.DocumentTable, documenttoken.DocumentColumn),
|
|
||||||
)
|
|
||||||
fromV = sqlgraph.Neighbors(dt.driver.Dialect(), step)
|
|
||||||
return fromV, nil
|
|
||||||
}
|
|
||||||
return query
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hooks returns the client hooks.
|
|
||||||
func (c *DocumentTokenClient) Hooks() []Hook {
|
|
||||||
return c.hooks.DocumentToken
|
|
||||||
}
|
|
||||||
|
|
||||||
// GroupClient is a client for the Group schema.
|
// GroupClient is a client for the Group schema.
|
||||||
type GroupClient struct {
|
type GroupClient struct {
|
||||||
config
|
config
|
||||||
|
@ -1268,6 +1146,22 @@ func (c *ItemClient) QueryFields(i *Item) *ItemFieldQuery {
|
||||||
return query
|
return query
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// QueryMaintenanceEntries queries the maintenance_entries edge of a Item.
|
||||||
|
func (c *ItemClient) QueryMaintenanceEntries(i *Item) *MaintenanceEntryQuery {
|
||||||
|
query := &MaintenanceEntryQuery{config: c.config}
|
||||||
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||||
|
id := i.ID
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(item.Table, item.FieldID, id),
|
||||||
|
sqlgraph.To(maintenanceentry.Table, maintenanceentry.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2M, false, item.MaintenanceEntriesTable, item.MaintenanceEntriesColumn),
|
||||||
|
)
|
||||||
|
fromV = sqlgraph.Neighbors(i.driver.Dialect(), step)
|
||||||
|
return fromV, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
// QueryAttachments queries the attachments edge of a Item.
|
// QueryAttachments queries the attachments edge of a Item.
|
||||||
func (c *ItemClient) QueryAttachments(i *Item) *AttachmentQuery {
|
func (c *ItemClient) QueryAttachments(i *Item) *AttachmentQuery {
|
||||||
query := &AttachmentQuery{config: c.config}
|
query := &AttachmentQuery{config: c.config}
|
||||||
|
@ -1671,6 +1565,112 @@ func (c *LocationClient) Hooks() []Hook {
|
||||||
return c.hooks.Location
|
return c.hooks.Location
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MaintenanceEntryClient is a client for the MaintenanceEntry schema.
|
||||||
|
type MaintenanceEntryClient struct {
|
||||||
|
config
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewMaintenanceEntryClient returns a client for the MaintenanceEntry from the given config.
|
||||||
|
func NewMaintenanceEntryClient(c config) *MaintenanceEntryClient {
|
||||||
|
return &MaintenanceEntryClient{config: c}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use adds a list of mutation hooks to the hooks stack.
|
||||||
|
// A call to `Use(f, g, h)` equals to `maintenanceentry.Hooks(f(g(h())))`.
|
||||||
|
func (c *MaintenanceEntryClient) Use(hooks ...Hook) {
|
||||||
|
c.hooks.MaintenanceEntry = append(c.hooks.MaintenanceEntry, hooks...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create returns a builder for creating a MaintenanceEntry entity.
|
||||||
|
func (c *MaintenanceEntryClient) Create() *MaintenanceEntryCreate {
|
||||||
|
mutation := newMaintenanceEntryMutation(c.config, OpCreate)
|
||||||
|
return &MaintenanceEntryCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateBulk returns a builder for creating a bulk of MaintenanceEntry entities.
|
||||||
|
func (c *MaintenanceEntryClient) CreateBulk(builders ...*MaintenanceEntryCreate) *MaintenanceEntryCreateBulk {
|
||||||
|
return &MaintenanceEntryCreateBulk{config: c.config, builders: builders}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns an update builder for MaintenanceEntry.
|
||||||
|
func (c *MaintenanceEntryClient) Update() *MaintenanceEntryUpdate {
|
||||||
|
mutation := newMaintenanceEntryMutation(c.config, OpUpdate)
|
||||||
|
return &MaintenanceEntryUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOne returns an update builder for the given entity.
|
||||||
|
func (c *MaintenanceEntryClient) UpdateOne(me *MaintenanceEntry) *MaintenanceEntryUpdateOne {
|
||||||
|
mutation := newMaintenanceEntryMutation(c.config, OpUpdateOne, withMaintenanceEntry(me))
|
||||||
|
return &MaintenanceEntryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOneID returns an update builder for the given id.
|
||||||
|
func (c *MaintenanceEntryClient) UpdateOneID(id uuid.UUID) *MaintenanceEntryUpdateOne {
|
||||||
|
mutation := newMaintenanceEntryMutation(c.config, OpUpdateOne, withMaintenanceEntryID(id))
|
||||||
|
return &MaintenanceEntryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete returns a delete builder for MaintenanceEntry.
|
||||||
|
func (c *MaintenanceEntryClient) Delete() *MaintenanceEntryDelete {
|
||||||
|
mutation := newMaintenanceEntryMutation(c.config, OpDelete)
|
||||||
|
return &MaintenanceEntryDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOne returns a builder for deleting the given entity.
|
||||||
|
func (c *MaintenanceEntryClient) DeleteOne(me *MaintenanceEntry) *MaintenanceEntryDeleteOne {
|
||||||
|
return c.DeleteOneID(me.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||||
|
func (c *MaintenanceEntryClient) DeleteOneID(id uuid.UUID) *MaintenanceEntryDeleteOne {
|
||||||
|
builder := c.Delete().Where(maintenanceentry.ID(id))
|
||||||
|
builder.mutation.id = &id
|
||||||
|
builder.mutation.op = OpDeleteOne
|
||||||
|
return &MaintenanceEntryDeleteOne{builder}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query returns a query builder for MaintenanceEntry.
|
||||||
|
func (c *MaintenanceEntryClient) Query() *MaintenanceEntryQuery {
|
||||||
|
return &MaintenanceEntryQuery{
|
||||||
|
config: c.config,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get returns a MaintenanceEntry entity by its id.
|
||||||
|
func (c *MaintenanceEntryClient) Get(ctx context.Context, id uuid.UUID) (*MaintenanceEntry, error) {
|
||||||
|
return c.Query().Where(maintenanceentry.ID(id)).Only(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetX is like Get, but panics if an error occurs.
|
||||||
|
func (c *MaintenanceEntryClient) GetX(ctx context.Context, id uuid.UUID) *MaintenanceEntry {
|
||||||
|
obj, err := c.Get(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryItem queries the item edge of a MaintenanceEntry.
|
||||||
|
func (c *MaintenanceEntryClient) QueryItem(me *MaintenanceEntry) *ItemQuery {
|
||||||
|
query := &ItemQuery{config: c.config}
|
||||||
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||||
|
id := me.ID
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(maintenanceentry.Table, maintenanceentry.FieldID, id),
|
||||||
|
sqlgraph.To(item.Table, item.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, maintenanceentry.ItemTable, maintenanceentry.ItemColumn),
|
||||||
|
)
|
||||||
|
fromV = sqlgraph.Neighbors(me.driver.Dialect(), step)
|
||||||
|
return fromV, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hooks returns the client hooks.
|
||||||
|
func (c *MaintenanceEntryClient) Hooks() []Hook {
|
||||||
|
return c.hooks.MaintenanceEntry
|
||||||
|
}
|
||||||
|
|
||||||
// UserClient is a client for the User schema.
|
// UserClient is a client for the User schema.
|
||||||
type UserClient struct {
|
type UserClient struct {
|
||||||
config
|
config
|
||||||
|
|
|
@ -28,13 +28,13 @@ type hooks struct {
|
||||||
AuthRoles []ent.Hook
|
AuthRoles []ent.Hook
|
||||||
AuthTokens []ent.Hook
|
AuthTokens []ent.Hook
|
||||||
Document []ent.Hook
|
Document []ent.Hook
|
||||||
DocumentToken []ent.Hook
|
|
||||||
Group []ent.Hook
|
Group []ent.Hook
|
||||||
GroupInvitationToken []ent.Hook
|
GroupInvitationToken []ent.Hook
|
||||||
Item []ent.Hook
|
Item []ent.Hook
|
||||||
ItemField []ent.Hook
|
ItemField []ent.Hook
|
||||||
Label []ent.Hook
|
Label []ent.Hook
|
||||||
Location []ent.Hook
|
Location []ent.Hook
|
||||||
|
MaintenanceEntry []ent.Hook
|
||||||
User []ent.Hook
|
User []ent.Hook
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,13 +36,11 @@ type Document struct {
|
||||||
type DocumentEdges struct {
|
type DocumentEdges struct {
|
||||||
// Group holds the value of the group edge.
|
// Group holds the value of the group edge.
|
||||||
Group *Group `json:"group,omitempty"`
|
Group *Group `json:"group,omitempty"`
|
||||||
// DocumentTokens holds the value of the document_tokens edge.
|
|
||||||
DocumentTokens []*DocumentToken `json:"document_tokens,omitempty"`
|
|
||||||
// Attachments holds the value of the attachments edge.
|
// Attachments holds the value of the attachments edge.
|
||||||
Attachments []*Attachment `json:"attachments,omitempty"`
|
Attachments []*Attachment `json:"attachments,omitempty"`
|
||||||
// loadedTypes holds the information for reporting if a
|
// loadedTypes holds the information for reporting if a
|
||||||
// type was loaded (or requested) in eager-loading or not.
|
// type was loaded (or requested) in eager-loading or not.
|
||||||
loadedTypes [3]bool
|
loadedTypes [2]bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// GroupOrErr returns the Group value or an error if the edge
|
// GroupOrErr returns the Group value or an error if the edge
|
||||||
|
@ -58,19 +56,10 @@ func (e DocumentEdges) GroupOrErr() (*Group, error) {
|
||||||
return nil, &NotLoadedError{edge: "group"}
|
return nil, &NotLoadedError{edge: "group"}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DocumentTokensOrErr returns the DocumentTokens value or an error if the edge
|
|
||||||
// was not loaded in eager-loading.
|
|
||||||
func (e DocumentEdges) DocumentTokensOrErr() ([]*DocumentToken, error) {
|
|
||||||
if e.loadedTypes[1] {
|
|
||||||
return e.DocumentTokens, nil
|
|
||||||
}
|
|
||||||
return nil, &NotLoadedError{edge: "document_tokens"}
|
|
||||||
}
|
|
||||||
|
|
||||||
// AttachmentsOrErr returns the Attachments value or an error if the edge
|
// AttachmentsOrErr returns the Attachments value or an error if the edge
|
||||||
// was not loaded in eager-loading.
|
// was not loaded in eager-loading.
|
||||||
func (e DocumentEdges) AttachmentsOrErr() ([]*Attachment, error) {
|
func (e DocumentEdges) AttachmentsOrErr() ([]*Attachment, error) {
|
||||||
if e.loadedTypes[2] {
|
if e.loadedTypes[1] {
|
||||||
return e.Attachments, nil
|
return e.Attachments, nil
|
||||||
}
|
}
|
||||||
return nil, &NotLoadedError{edge: "attachments"}
|
return nil, &NotLoadedError{edge: "attachments"}
|
||||||
|
@ -151,11 +140,6 @@ func (d *Document) QueryGroup() *GroupQuery {
|
||||||
return (&DocumentClient{config: d.config}).QueryGroup(d)
|
return (&DocumentClient{config: d.config}).QueryGroup(d)
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryDocumentTokens queries the "document_tokens" edge of the Document entity.
|
|
||||||
func (d *Document) QueryDocumentTokens() *DocumentTokenQuery {
|
|
||||||
return (&DocumentClient{config: d.config}).QueryDocumentTokens(d)
|
|
||||||
}
|
|
||||||
|
|
||||||
// QueryAttachments queries the "attachments" edge of the Document entity.
|
// QueryAttachments queries the "attachments" edge of the Document entity.
|
||||||
func (d *Document) QueryAttachments() *AttachmentQuery {
|
func (d *Document) QueryAttachments() *AttachmentQuery {
|
||||||
return (&DocumentClient{config: d.config}).QueryAttachments(d)
|
return (&DocumentClient{config: d.config}).QueryAttachments(d)
|
||||||
|
|
|
@ -23,8 +23,6 @@ const (
|
||||||
FieldPath = "path"
|
FieldPath = "path"
|
||||||
// EdgeGroup holds the string denoting the group edge name in mutations.
|
// EdgeGroup holds the string denoting the group edge name in mutations.
|
||||||
EdgeGroup = "group"
|
EdgeGroup = "group"
|
||||||
// EdgeDocumentTokens holds the string denoting the document_tokens edge name in mutations.
|
|
||||||
EdgeDocumentTokens = "document_tokens"
|
|
||||||
// EdgeAttachments holds the string denoting the attachments edge name in mutations.
|
// EdgeAttachments holds the string denoting the attachments edge name in mutations.
|
||||||
EdgeAttachments = "attachments"
|
EdgeAttachments = "attachments"
|
||||||
// Table holds the table name of the document in the database.
|
// Table holds the table name of the document in the database.
|
||||||
|
@ -36,13 +34,6 @@ const (
|
||||||
GroupInverseTable = "groups"
|
GroupInverseTable = "groups"
|
||||||
// GroupColumn is the table column denoting the group relation/edge.
|
// GroupColumn is the table column denoting the group relation/edge.
|
||||||
GroupColumn = "group_documents"
|
GroupColumn = "group_documents"
|
||||||
// DocumentTokensTable is the table that holds the document_tokens relation/edge.
|
|
||||||
DocumentTokensTable = "document_tokens"
|
|
||||||
// DocumentTokensInverseTable is the table name for the DocumentToken entity.
|
|
||||||
// It exists in this package in order to avoid circular dependency with the "documenttoken" package.
|
|
||||||
DocumentTokensInverseTable = "document_tokens"
|
|
||||||
// DocumentTokensColumn is the table column denoting the document_tokens relation/edge.
|
|
||||||
DocumentTokensColumn = "document_document_tokens"
|
|
||||||
// AttachmentsTable is the table that holds the attachments relation/edge.
|
// AttachmentsTable is the table that holds the attachments relation/edge.
|
||||||
AttachmentsTable = "attachments"
|
AttachmentsTable = "attachments"
|
||||||
// AttachmentsInverseTable is the table name for the Attachment entity.
|
// AttachmentsInverseTable is the table name for the Attachment entity.
|
||||||
|
|
|
@ -464,34 +464,6 @@ func HasGroupWith(preds ...predicate.Group) predicate.Document {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// HasDocumentTokens applies the HasEdge predicate on the "document_tokens" edge.
|
|
||||||
func HasDocumentTokens() predicate.Document {
|
|
||||||
return predicate.Document(func(s *sql.Selector) {
|
|
||||||
step := sqlgraph.NewStep(
|
|
||||||
sqlgraph.From(Table, FieldID),
|
|
||||||
sqlgraph.To(DocumentTokensTable, FieldID),
|
|
||||||
sqlgraph.Edge(sqlgraph.O2M, false, DocumentTokensTable, DocumentTokensColumn),
|
|
||||||
)
|
|
||||||
sqlgraph.HasNeighbors(s, step)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// HasDocumentTokensWith applies the HasEdge predicate on the "document_tokens" edge with a given conditions (other predicates).
|
|
||||||
func HasDocumentTokensWith(preds ...predicate.DocumentToken) predicate.Document {
|
|
||||||
return predicate.Document(func(s *sql.Selector) {
|
|
||||||
step := sqlgraph.NewStep(
|
|
||||||
sqlgraph.From(Table, FieldID),
|
|
||||||
sqlgraph.To(DocumentTokensInverseTable, FieldID),
|
|
||||||
sqlgraph.Edge(sqlgraph.O2M, false, DocumentTokensTable, DocumentTokensColumn),
|
|
||||||
)
|
|
||||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
|
||||||
for _, p := range preds {
|
|
||||||
p(s)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// HasAttachments applies the HasEdge predicate on the "attachments" edge.
|
// HasAttachments applies the HasEdge predicate on the "attachments" edge.
|
||||||
func HasAttachments() predicate.Document {
|
func HasAttachments() predicate.Document {
|
||||||
return predicate.Document(func(s *sql.Selector) {
|
return predicate.Document(func(s *sql.Selector) {
|
||||||
|
|
|
@ -13,7 +13,6 @@ import (
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/attachment"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/attachment"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/document"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/document"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/documenttoken"
|
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/group"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/group"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -89,21 +88,6 @@ func (dc *DocumentCreate) SetGroup(g *Group) *DocumentCreate {
|
||||||
return dc.SetGroupID(g.ID)
|
return dc.SetGroupID(g.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddDocumentTokenIDs adds the "document_tokens" edge to the DocumentToken entity by IDs.
|
|
||||||
func (dc *DocumentCreate) AddDocumentTokenIDs(ids ...uuid.UUID) *DocumentCreate {
|
|
||||||
dc.mutation.AddDocumentTokenIDs(ids...)
|
|
||||||
return dc
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddDocumentTokens adds the "document_tokens" edges to the DocumentToken entity.
|
|
||||||
func (dc *DocumentCreate) AddDocumentTokens(d ...*DocumentToken) *DocumentCreate {
|
|
||||||
ids := make([]uuid.UUID, len(d))
|
|
||||||
for i := range d {
|
|
||||||
ids[i] = d[i].ID
|
|
||||||
}
|
|
||||||
return dc.AddDocumentTokenIDs(ids...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddAttachmentIDs adds the "attachments" edge to the Attachment entity by IDs.
|
// AddAttachmentIDs adds the "attachments" edge to the Attachment entity by IDs.
|
||||||
func (dc *DocumentCreate) AddAttachmentIDs(ids ...uuid.UUID) *DocumentCreate {
|
func (dc *DocumentCreate) AddAttachmentIDs(ids ...uuid.UUID) *DocumentCreate {
|
||||||
dc.mutation.AddAttachmentIDs(ids...)
|
dc.mutation.AddAttachmentIDs(ids...)
|
||||||
|
@ -309,25 +293,6 @@ func (dc *DocumentCreate) createSpec() (*Document, *sqlgraph.CreateSpec) {
|
||||||
_node.group_documents = &nodes[0]
|
_node.group_documents = &nodes[0]
|
||||||
_spec.Edges = append(_spec.Edges, edge)
|
_spec.Edges = append(_spec.Edges, edge)
|
||||||
}
|
}
|
||||||
if nodes := dc.mutation.DocumentTokensIDs(); len(nodes) > 0 {
|
|
||||||
edge := &sqlgraph.EdgeSpec{
|
|
||||||
Rel: sqlgraph.O2M,
|
|
||||||
Inverse: false,
|
|
||||||
Table: document.DocumentTokensTable,
|
|
||||||
Columns: []string{document.DocumentTokensColumn},
|
|
||||||
Bidi: false,
|
|
||||||
Target: &sqlgraph.EdgeTarget{
|
|
||||||
IDSpec: &sqlgraph.FieldSpec{
|
|
||||||
Type: field.TypeUUID,
|
|
||||||
Column: documenttoken.FieldID,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, k := range nodes {
|
|
||||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
||||||
}
|
|
||||||
_spec.Edges = append(_spec.Edges, edge)
|
|
||||||
}
|
|
||||||
if nodes := dc.mutation.AttachmentsIDs(); len(nodes) > 0 {
|
if nodes := dc.mutation.AttachmentsIDs(); len(nodes) > 0 {
|
||||||
edge := &sqlgraph.EdgeSpec{
|
edge := &sqlgraph.EdgeSpec{
|
||||||
Rel: sqlgraph.O2M,
|
Rel: sqlgraph.O2M,
|
||||||
|
|
|
@ -14,7 +14,6 @@ import (
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/attachment"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/attachment"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/document"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/document"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/documenttoken"
|
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/group"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/group"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/predicate"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/predicate"
|
||||||
)
|
)
|
||||||
|
@ -22,16 +21,15 @@ import (
|
||||||
// DocumentQuery is the builder for querying Document entities.
|
// DocumentQuery is the builder for querying Document entities.
|
||||||
type DocumentQuery struct {
|
type DocumentQuery struct {
|
||||||
config
|
config
|
||||||
limit *int
|
limit *int
|
||||||
offset *int
|
offset *int
|
||||||
unique *bool
|
unique *bool
|
||||||
order []OrderFunc
|
order []OrderFunc
|
||||||
fields []string
|
fields []string
|
||||||
predicates []predicate.Document
|
predicates []predicate.Document
|
||||||
withGroup *GroupQuery
|
withGroup *GroupQuery
|
||||||
withDocumentTokens *DocumentTokenQuery
|
withAttachments *AttachmentQuery
|
||||||
withAttachments *AttachmentQuery
|
withFKs bool
|
||||||
withFKs bool
|
|
||||||
// intermediate query (i.e. traversal path).
|
// intermediate query (i.e. traversal path).
|
||||||
sql *sql.Selector
|
sql *sql.Selector
|
||||||
path func(context.Context) (*sql.Selector, error)
|
path func(context.Context) (*sql.Selector, error)
|
||||||
|
@ -90,28 +88,6 @@ func (dq *DocumentQuery) QueryGroup() *GroupQuery {
|
||||||
return query
|
return query
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryDocumentTokens chains the current query on the "document_tokens" edge.
|
|
||||||
func (dq *DocumentQuery) QueryDocumentTokens() *DocumentTokenQuery {
|
|
||||||
query := &DocumentTokenQuery{config: dq.config}
|
|
||||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
|
||||||
if err := dq.prepareQuery(ctx); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
selector := dq.sqlQuery(ctx)
|
|
||||||
if err := selector.Err(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
step := sqlgraph.NewStep(
|
|
||||||
sqlgraph.From(document.Table, document.FieldID, selector),
|
|
||||||
sqlgraph.To(documenttoken.Table, documenttoken.FieldID),
|
|
||||||
sqlgraph.Edge(sqlgraph.O2M, false, document.DocumentTokensTable, document.DocumentTokensColumn),
|
|
||||||
)
|
|
||||||
fromU = sqlgraph.SetNeighbors(dq.driver.Dialect(), step)
|
|
||||||
return fromU, nil
|
|
||||||
}
|
|
||||||
return query
|
|
||||||
}
|
|
||||||
|
|
||||||
// QueryAttachments chains the current query on the "attachments" edge.
|
// QueryAttachments chains the current query on the "attachments" edge.
|
||||||
func (dq *DocumentQuery) QueryAttachments() *AttachmentQuery {
|
func (dq *DocumentQuery) QueryAttachments() *AttachmentQuery {
|
||||||
query := &AttachmentQuery{config: dq.config}
|
query := &AttachmentQuery{config: dq.config}
|
||||||
|
@ -310,14 +286,13 @@ func (dq *DocumentQuery) Clone() *DocumentQuery {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return &DocumentQuery{
|
return &DocumentQuery{
|
||||||
config: dq.config,
|
config: dq.config,
|
||||||
limit: dq.limit,
|
limit: dq.limit,
|
||||||
offset: dq.offset,
|
offset: dq.offset,
|
||||||
order: append([]OrderFunc{}, dq.order...),
|
order: append([]OrderFunc{}, dq.order...),
|
||||||
predicates: append([]predicate.Document{}, dq.predicates...),
|
predicates: append([]predicate.Document{}, dq.predicates...),
|
||||||
withGroup: dq.withGroup.Clone(),
|
withGroup: dq.withGroup.Clone(),
|
||||||
withDocumentTokens: dq.withDocumentTokens.Clone(),
|
withAttachments: dq.withAttachments.Clone(),
|
||||||
withAttachments: dq.withAttachments.Clone(),
|
|
||||||
// clone intermediate query.
|
// clone intermediate query.
|
||||||
sql: dq.sql.Clone(),
|
sql: dq.sql.Clone(),
|
||||||
path: dq.path,
|
path: dq.path,
|
||||||
|
@ -336,17 +311,6 @@ func (dq *DocumentQuery) WithGroup(opts ...func(*GroupQuery)) *DocumentQuery {
|
||||||
return dq
|
return dq
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithDocumentTokens tells the query-builder to eager-load the nodes that are connected to
|
|
||||||
// the "document_tokens" edge. The optional arguments are used to configure the query builder of the edge.
|
|
||||||
func (dq *DocumentQuery) WithDocumentTokens(opts ...func(*DocumentTokenQuery)) *DocumentQuery {
|
|
||||||
query := &DocumentTokenQuery{config: dq.config}
|
|
||||||
for _, opt := range opts {
|
|
||||||
opt(query)
|
|
||||||
}
|
|
||||||
dq.withDocumentTokens = query
|
|
||||||
return dq
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithAttachments tells the query-builder to eager-load the nodes that are connected to
|
// WithAttachments tells the query-builder to eager-load the nodes that are connected to
|
||||||
// the "attachments" edge. The optional arguments are used to configure the query builder of the edge.
|
// the "attachments" edge. The optional arguments are used to configure the query builder of the edge.
|
||||||
func (dq *DocumentQuery) WithAttachments(opts ...func(*AttachmentQuery)) *DocumentQuery {
|
func (dq *DocumentQuery) WithAttachments(opts ...func(*AttachmentQuery)) *DocumentQuery {
|
||||||
|
@ -432,9 +396,8 @@ func (dq *DocumentQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Doc
|
||||||
nodes = []*Document{}
|
nodes = []*Document{}
|
||||||
withFKs = dq.withFKs
|
withFKs = dq.withFKs
|
||||||
_spec = dq.querySpec()
|
_spec = dq.querySpec()
|
||||||
loadedTypes = [3]bool{
|
loadedTypes = [2]bool{
|
||||||
dq.withGroup != nil,
|
dq.withGroup != nil,
|
||||||
dq.withDocumentTokens != nil,
|
|
||||||
dq.withAttachments != nil,
|
dq.withAttachments != nil,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -468,13 +431,6 @@ func (dq *DocumentQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Doc
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if query := dq.withDocumentTokens; query != nil {
|
|
||||||
if err := dq.loadDocumentTokens(ctx, query, nodes,
|
|
||||||
func(n *Document) { n.Edges.DocumentTokens = []*DocumentToken{} },
|
|
||||||
func(n *Document, e *DocumentToken) { n.Edges.DocumentTokens = append(n.Edges.DocumentTokens, e) }); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if query := dq.withAttachments; query != nil {
|
if query := dq.withAttachments; query != nil {
|
||||||
if err := dq.loadAttachments(ctx, query, nodes,
|
if err := dq.loadAttachments(ctx, query, nodes,
|
||||||
func(n *Document) { n.Edges.Attachments = []*Attachment{} },
|
func(n *Document) { n.Edges.Attachments = []*Attachment{} },
|
||||||
|
@ -514,37 +470,6 @@ func (dq *DocumentQuery) loadGroup(ctx context.Context, query *GroupQuery, nodes
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (dq *DocumentQuery) loadDocumentTokens(ctx context.Context, query *DocumentTokenQuery, nodes []*Document, init func(*Document), assign func(*Document, *DocumentToken)) error {
|
|
||||||
fks := make([]driver.Value, 0, len(nodes))
|
|
||||||
nodeids := make(map[uuid.UUID]*Document)
|
|
||||||
for i := range nodes {
|
|
||||||
fks = append(fks, nodes[i].ID)
|
|
||||||
nodeids[nodes[i].ID] = nodes[i]
|
|
||||||
if init != nil {
|
|
||||||
init(nodes[i])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
query.withFKs = true
|
|
||||||
query.Where(predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.InValues(document.DocumentTokensColumn, fks...))
|
|
||||||
}))
|
|
||||||
neighbors, err := query.All(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
for _, n := range neighbors {
|
|
||||||
fk := n.document_document_tokens
|
|
||||||
if fk == nil {
|
|
||||||
return fmt.Errorf(`foreign-key "document_document_tokens" is nil for node %v`, n.ID)
|
|
||||||
}
|
|
||||||
node, ok := nodeids[*fk]
|
|
||||||
if !ok {
|
|
||||||
return fmt.Errorf(`unexpected foreign-key "document_document_tokens" returned %v for node %v`, *fk, n.ID)
|
|
||||||
}
|
|
||||||
assign(node, n)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (dq *DocumentQuery) loadAttachments(ctx context.Context, query *AttachmentQuery, nodes []*Document, init func(*Document), assign func(*Document, *Attachment)) error {
|
func (dq *DocumentQuery) loadAttachments(ctx context.Context, query *AttachmentQuery, nodes []*Document, init func(*Document), assign func(*Document, *Attachment)) error {
|
||||||
fks := make([]driver.Value, 0, len(nodes))
|
fks := make([]driver.Value, 0, len(nodes))
|
||||||
nodeids := make(map[uuid.UUID]*Document)
|
nodeids := make(map[uuid.UUID]*Document)
|
||||||
|
|
|
@ -14,7 +14,6 @@ import (
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/attachment"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/attachment"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/document"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/document"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/documenttoken"
|
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/group"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/group"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/predicate"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/predicate"
|
||||||
)
|
)
|
||||||
|
@ -61,21 +60,6 @@ func (du *DocumentUpdate) SetGroup(g *Group) *DocumentUpdate {
|
||||||
return du.SetGroupID(g.ID)
|
return du.SetGroupID(g.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddDocumentTokenIDs adds the "document_tokens" edge to the DocumentToken entity by IDs.
|
|
||||||
func (du *DocumentUpdate) AddDocumentTokenIDs(ids ...uuid.UUID) *DocumentUpdate {
|
|
||||||
du.mutation.AddDocumentTokenIDs(ids...)
|
|
||||||
return du
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddDocumentTokens adds the "document_tokens" edges to the DocumentToken entity.
|
|
||||||
func (du *DocumentUpdate) AddDocumentTokens(d ...*DocumentToken) *DocumentUpdate {
|
|
||||||
ids := make([]uuid.UUID, len(d))
|
|
||||||
for i := range d {
|
|
||||||
ids[i] = d[i].ID
|
|
||||||
}
|
|
||||||
return du.AddDocumentTokenIDs(ids...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddAttachmentIDs adds the "attachments" edge to the Attachment entity by IDs.
|
// AddAttachmentIDs adds the "attachments" edge to the Attachment entity by IDs.
|
||||||
func (du *DocumentUpdate) AddAttachmentIDs(ids ...uuid.UUID) *DocumentUpdate {
|
func (du *DocumentUpdate) AddAttachmentIDs(ids ...uuid.UUID) *DocumentUpdate {
|
||||||
du.mutation.AddAttachmentIDs(ids...)
|
du.mutation.AddAttachmentIDs(ids...)
|
||||||
|
@ -102,27 +86,6 @@ func (du *DocumentUpdate) ClearGroup() *DocumentUpdate {
|
||||||
return du
|
return du
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClearDocumentTokens clears all "document_tokens" edges to the DocumentToken entity.
|
|
||||||
func (du *DocumentUpdate) ClearDocumentTokens() *DocumentUpdate {
|
|
||||||
du.mutation.ClearDocumentTokens()
|
|
||||||
return du
|
|
||||||
}
|
|
||||||
|
|
||||||
// RemoveDocumentTokenIDs removes the "document_tokens" edge to DocumentToken entities by IDs.
|
|
||||||
func (du *DocumentUpdate) RemoveDocumentTokenIDs(ids ...uuid.UUID) *DocumentUpdate {
|
|
||||||
du.mutation.RemoveDocumentTokenIDs(ids...)
|
|
||||||
return du
|
|
||||||
}
|
|
||||||
|
|
||||||
// RemoveDocumentTokens removes "document_tokens" edges to DocumentToken entities.
|
|
||||||
func (du *DocumentUpdate) RemoveDocumentTokens(d ...*DocumentToken) *DocumentUpdate {
|
|
||||||
ids := make([]uuid.UUID, len(d))
|
|
||||||
for i := range d {
|
|
||||||
ids[i] = d[i].ID
|
|
||||||
}
|
|
||||||
return du.RemoveDocumentTokenIDs(ids...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ClearAttachments clears all "attachments" edges to the Attachment entity.
|
// ClearAttachments clears all "attachments" edges to the Attachment entity.
|
||||||
func (du *DocumentUpdate) ClearAttachments() *DocumentUpdate {
|
func (du *DocumentUpdate) ClearAttachments() *DocumentUpdate {
|
||||||
du.mutation.ClearAttachments()
|
du.mutation.ClearAttachments()
|
||||||
|
@ -293,60 +256,6 @@ func (du *DocumentUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||||
}
|
}
|
||||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
}
|
}
|
||||||
if du.mutation.DocumentTokensCleared() {
|
|
||||||
edge := &sqlgraph.EdgeSpec{
|
|
||||||
Rel: sqlgraph.O2M,
|
|
||||||
Inverse: false,
|
|
||||||
Table: document.DocumentTokensTable,
|
|
||||||
Columns: []string{document.DocumentTokensColumn},
|
|
||||||
Bidi: false,
|
|
||||||
Target: &sqlgraph.EdgeTarget{
|
|
||||||
IDSpec: &sqlgraph.FieldSpec{
|
|
||||||
Type: field.TypeUUID,
|
|
||||||
Column: documenttoken.FieldID,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
||||||
}
|
|
||||||
if nodes := du.mutation.RemovedDocumentTokensIDs(); len(nodes) > 0 && !du.mutation.DocumentTokensCleared() {
|
|
||||||
edge := &sqlgraph.EdgeSpec{
|
|
||||||
Rel: sqlgraph.O2M,
|
|
||||||
Inverse: false,
|
|
||||||
Table: document.DocumentTokensTable,
|
|
||||||
Columns: []string{document.DocumentTokensColumn},
|
|
||||||
Bidi: false,
|
|
||||||
Target: &sqlgraph.EdgeTarget{
|
|
||||||
IDSpec: &sqlgraph.FieldSpec{
|
|
||||||
Type: field.TypeUUID,
|
|
||||||
Column: documenttoken.FieldID,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, k := range nodes {
|
|
||||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
||||||
}
|
|
||||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
||||||
}
|
|
||||||
if nodes := du.mutation.DocumentTokensIDs(); len(nodes) > 0 {
|
|
||||||
edge := &sqlgraph.EdgeSpec{
|
|
||||||
Rel: sqlgraph.O2M,
|
|
||||||
Inverse: false,
|
|
||||||
Table: document.DocumentTokensTable,
|
|
||||||
Columns: []string{document.DocumentTokensColumn},
|
|
||||||
Bidi: false,
|
|
||||||
Target: &sqlgraph.EdgeTarget{
|
|
||||||
IDSpec: &sqlgraph.FieldSpec{
|
|
||||||
Type: field.TypeUUID,
|
|
||||||
Column: documenttoken.FieldID,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, k := range nodes {
|
|
||||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
||||||
}
|
|
||||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
||||||
}
|
|
||||||
if du.mutation.AttachmentsCleared() {
|
if du.mutation.AttachmentsCleared() {
|
||||||
edge := &sqlgraph.EdgeSpec{
|
edge := &sqlgraph.EdgeSpec{
|
||||||
Rel: sqlgraph.O2M,
|
Rel: sqlgraph.O2M,
|
||||||
|
@ -449,21 +358,6 @@ func (duo *DocumentUpdateOne) SetGroup(g *Group) *DocumentUpdateOne {
|
||||||
return duo.SetGroupID(g.ID)
|
return duo.SetGroupID(g.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddDocumentTokenIDs adds the "document_tokens" edge to the DocumentToken entity by IDs.
|
|
||||||
func (duo *DocumentUpdateOne) AddDocumentTokenIDs(ids ...uuid.UUID) *DocumentUpdateOne {
|
|
||||||
duo.mutation.AddDocumentTokenIDs(ids...)
|
|
||||||
return duo
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddDocumentTokens adds the "document_tokens" edges to the DocumentToken entity.
|
|
||||||
func (duo *DocumentUpdateOne) AddDocumentTokens(d ...*DocumentToken) *DocumentUpdateOne {
|
|
||||||
ids := make([]uuid.UUID, len(d))
|
|
||||||
for i := range d {
|
|
||||||
ids[i] = d[i].ID
|
|
||||||
}
|
|
||||||
return duo.AddDocumentTokenIDs(ids...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddAttachmentIDs adds the "attachments" edge to the Attachment entity by IDs.
|
// AddAttachmentIDs adds the "attachments" edge to the Attachment entity by IDs.
|
||||||
func (duo *DocumentUpdateOne) AddAttachmentIDs(ids ...uuid.UUID) *DocumentUpdateOne {
|
func (duo *DocumentUpdateOne) AddAttachmentIDs(ids ...uuid.UUID) *DocumentUpdateOne {
|
||||||
duo.mutation.AddAttachmentIDs(ids...)
|
duo.mutation.AddAttachmentIDs(ids...)
|
||||||
|
@ -490,27 +384,6 @@ func (duo *DocumentUpdateOne) ClearGroup() *DocumentUpdateOne {
|
||||||
return duo
|
return duo
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClearDocumentTokens clears all "document_tokens" edges to the DocumentToken entity.
|
|
||||||
func (duo *DocumentUpdateOne) ClearDocumentTokens() *DocumentUpdateOne {
|
|
||||||
duo.mutation.ClearDocumentTokens()
|
|
||||||
return duo
|
|
||||||
}
|
|
||||||
|
|
||||||
// RemoveDocumentTokenIDs removes the "document_tokens" edge to DocumentToken entities by IDs.
|
|
||||||
func (duo *DocumentUpdateOne) RemoveDocumentTokenIDs(ids ...uuid.UUID) *DocumentUpdateOne {
|
|
||||||
duo.mutation.RemoveDocumentTokenIDs(ids...)
|
|
||||||
return duo
|
|
||||||
}
|
|
||||||
|
|
||||||
// RemoveDocumentTokens removes "document_tokens" edges to DocumentToken entities.
|
|
||||||
func (duo *DocumentUpdateOne) RemoveDocumentTokens(d ...*DocumentToken) *DocumentUpdateOne {
|
|
||||||
ids := make([]uuid.UUID, len(d))
|
|
||||||
for i := range d {
|
|
||||||
ids[i] = d[i].ID
|
|
||||||
}
|
|
||||||
return duo.RemoveDocumentTokenIDs(ids...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ClearAttachments clears all "attachments" edges to the Attachment entity.
|
// ClearAttachments clears all "attachments" edges to the Attachment entity.
|
||||||
func (duo *DocumentUpdateOne) ClearAttachments() *DocumentUpdateOne {
|
func (duo *DocumentUpdateOne) ClearAttachments() *DocumentUpdateOne {
|
||||||
duo.mutation.ClearAttachments()
|
duo.mutation.ClearAttachments()
|
||||||
|
@ -711,60 +584,6 @@ func (duo *DocumentUpdateOne) sqlSave(ctx context.Context) (_node *Document, err
|
||||||
}
|
}
|
||||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
}
|
}
|
||||||
if duo.mutation.DocumentTokensCleared() {
|
|
||||||
edge := &sqlgraph.EdgeSpec{
|
|
||||||
Rel: sqlgraph.O2M,
|
|
||||||
Inverse: false,
|
|
||||||
Table: document.DocumentTokensTable,
|
|
||||||
Columns: []string{document.DocumentTokensColumn},
|
|
||||||
Bidi: false,
|
|
||||||
Target: &sqlgraph.EdgeTarget{
|
|
||||||
IDSpec: &sqlgraph.FieldSpec{
|
|
||||||
Type: field.TypeUUID,
|
|
||||||
Column: documenttoken.FieldID,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
||||||
}
|
|
||||||
if nodes := duo.mutation.RemovedDocumentTokensIDs(); len(nodes) > 0 && !duo.mutation.DocumentTokensCleared() {
|
|
||||||
edge := &sqlgraph.EdgeSpec{
|
|
||||||
Rel: sqlgraph.O2M,
|
|
||||||
Inverse: false,
|
|
||||||
Table: document.DocumentTokensTable,
|
|
||||||
Columns: []string{document.DocumentTokensColumn},
|
|
||||||
Bidi: false,
|
|
||||||
Target: &sqlgraph.EdgeTarget{
|
|
||||||
IDSpec: &sqlgraph.FieldSpec{
|
|
||||||
Type: field.TypeUUID,
|
|
||||||
Column: documenttoken.FieldID,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, k := range nodes {
|
|
||||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
||||||
}
|
|
||||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
||||||
}
|
|
||||||
if nodes := duo.mutation.DocumentTokensIDs(); len(nodes) > 0 {
|
|
||||||
edge := &sqlgraph.EdgeSpec{
|
|
||||||
Rel: sqlgraph.O2M,
|
|
||||||
Inverse: false,
|
|
||||||
Table: document.DocumentTokensTable,
|
|
||||||
Columns: []string{document.DocumentTokensColumn},
|
|
||||||
Bidi: false,
|
|
||||||
Target: &sqlgraph.EdgeTarget{
|
|
||||||
IDSpec: &sqlgraph.FieldSpec{
|
|
||||||
Type: field.TypeUUID,
|
|
||||||
Column: documenttoken.FieldID,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, k := range nodes {
|
|
||||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
||||||
}
|
|
||||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
||||||
}
|
|
||||||
if duo.mutation.AttachmentsCleared() {
|
if duo.mutation.AttachmentsCleared() {
|
||||||
edge := &sqlgraph.EdgeSpec{
|
edge := &sqlgraph.EdgeSpec{
|
||||||
Rel: sqlgraph.O2M,
|
Rel: sqlgraph.O2M,
|
||||||
|
|
|
@ -1,190 +0,0 @@
|
||||||
// Code generated by ent, DO NOT EDIT.
|
|
||||||
|
|
||||||
package ent
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"entgo.io/ent/dialect/sql"
|
|
||||||
"github.com/google/uuid"
|
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/document"
|
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/documenttoken"
|
|
||||||
)
|
|
||||||
|
|
||||||
// DocumentToken is the model entity for the DocumentToken schema.
|
|
||||||
type DocumentToken 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"`
|
|
||||||
// UpdatedAt holds the value of the "updated_at" field.
|
|
||||||
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
|
||||||
// Token holds the value of the "token" field.
|
|
||||||
Token []byte `json:"token,omitempty"`
|
|
||||||
// Uses holds the value of the "uses" field.
|
|
||||||
Uses int `json:"uses,omitempty"`
|
|
||||||
// ExpiresAt holds the value of the "expires_at" field.
|
|
||||||
ExpiresAt time.Time `json:"expires_at,omitempty"`
|
|
||||||
// Edges holds the relations/edges for other nodes in the graph.
|
|
||||||
// The values are being populated by the DocumentTokenQuery when eager-loading is set.
|
|
||||||
Edges DocumentTokenEdges `json:"edges"`
|
|
||||||
document_document_tokens *uuid.UUID
|
|
||||||
}
|
|
||||||
|
|
||||||
// DocumentTokenEdges holds the relations/edges for other nodes in the graph.
|
|
||||||
type DocumentTokenEdges struct {
|
|
||||||
// Document holds the value of the document edge.
|
|
||||||
Document *Document `json:"document,omitempty"`
|
|
||||||
// loadedTypes holds the information for reporting if a
|
|
||||||
// type was loaded (or requested) in eager-loading or not.
|
|
||||||
loadedTypes [1]bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// DocumentOrErr returns the Document value or an error if the edge
|
|
||||||
// was not loaded in eager-loading, or loaded but was not found.
|
|
||||||
func (e DocumentTokenEdges) DocumentOrErr() (*Document, error) {
|
|
||||||
if e.loadedTypes[0] {
|
|
||||||
if e.Document == nil {
|
|
||||||
// Edge was loaded but was not found.
|
|
||||||
return nil, &NotFoundError{label: document.Label}
|
|
||||||
}
|
|
||||||
return e.Document, nil
|
|
||||||
}
|
|
||||||
return nil, &NotLoadedError{edge: "document"}
|
|
||||||
}
|
|
||||||
|
|
||||||
// scanValues returns the types for scanning values from sql.Rows.
|
|
||||||
func (*DocumentToken) scanValues(columns []string) ([]any, error) {
|
|
||||||
values := make([]any, len(columns))
|
|
||||||
for i := range columns {
|
|
||||||
switch columns[i] {
|
|
||||||
case documenttoken.FieldToken:
|
|
||||||
values[i] = new([]byte)
|
|
||||||
case documenttoken.FieldUses:
|
|
||||||
values[i] = new(sql.NullInt64)
|
|
||||||
case documenttoken.FieldCreatedAt, documenttoken.FieldUpdatedAt, documenttoken.FieldExpiresAt:
|
|
||||||
values[i] = new(sql.NullTime)
|
|
||||||
case documenttoken.FieldID:
|
|
||||||
values[i] = new(uuid.UUID)
|
|
||||||
case documenttoken.ForeignKeys[0]: // document_document_tokens
|
|
||||||
values[i] = &sql.NullScanner{S: new(uuid.UUID)}
|
|
||||||
default:
|
|
||||||
return nil, fmt.Errorf("unexpected column %q for type DocumentToken", columns[i])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return values, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
|
||||||
// to the DocumentToken fields.
|
|
||||||
func (dt *DocumentToken) 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 documenttoken.FieldID:
|
|
||||||
if value, ok := values[i].(*uuid.UUID); !ok {
|
|
||||||
return fmt.Errorf("unexpected type %T for field id", values[i])
|
|
||||||
} else if value != nil {
|
|
||||||
dt.ID = *value
|
|
||||||
}
|
|
||||||
case documenttoken.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 {
|
|
||||||
dt.CreatedAt = value.Time
|
|
||||||
}
|
|
||||||
case documenttoken.FieldUpdatedAt:
|
|
||||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
|
||||||
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
|
|
||||||
} else if value.Valid {
|
|
||||||
dt.UpdatedAt = value.Time
|
|
||||||
}
|
|
||||||
case documenttoken.FieldToken:
|
|
||||||
if value, ok := values[i].(*[]byte); !ok {
|
|
||||||
return fmt.Errorf("unexpected type %T for field token", values[i])
|
|
||||||
} else if value != nil {
|
|
||||||
dt.Token = *value
|
|
||||||
}
|
|
||||||
case documenttoken.FieldUses:
|
|
||||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
|
||||||
return fmt.Errorf("unexpected type %T for field uses", values[i])
|
|
||||||
} else if value.Valid {
|
|
||||||
dt.Uses = int(value.Int64)
|
|
||||||
}
|
|
||||||
case documenttoken.FieldExpiresAt:
|
|
||||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
|
||||||
return fmt.Errorf("unexpected type %T for field expires_at", values[i])
|
|
||||||
} else if value.Valid {
|
|
||||||
dt.ExpiresAt = value.Time
|
|
||||||
}
|
|
||||||
case documenttoken.ForeignKeys[0]:
|
|
||||||
if value, ok := values[i].(*sql.NullScanner); !ok {
|
|
||||||
return fmt.Errorf("unexpected type %T for field document_document_tokens", values[i])
|
|
||||||
} else if value.Valid {
|
|
||||||
dt.document_document_tokens = new(uuid.UUID)
|
|
||||||
*dt.document_document_tokens = *value.S.(*uuid.UUID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// QueryDocument queries the "document" edge of the DocumentToken entity.
|
|
||||||
func (dt *DocumentToken) QueryDocument() *DocumentQuery {
|
|
||||||
return (&DocumentTokenClient{config: dt.config}).QueryDocument(dt)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update returns a builder for updating this DocumentToken.
|
|
||||||
// Note that you need to call DocumentToken.Unwrap() before calling this method if this DocumentToken
|
|
||||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
|
||||||
func (dt *DocumentToken) Update() *DocumentTokenUpdateOne {
|
|
||||||
return (&DocumentTokenClient{config: dt.config}).UpdateOne(dt)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unwrap unwraps the DocumentToken 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 (dt *DocumentToken) Unwrap() *DocumentToken {
|
|
||||||
_tx, ok := dt.config.driver.(*txDriver)
|
|
||||||
if !ok {
|
|
||||||
panic("ent: DocumentToken is not a transactional entity")
|
|
||||||
}
|
|
||||||
dt.config.driver = _tx.drv
|
|
||||||
return dt
|
|
||||||
}
|
|
||||||
|
|
||||||
// String implements the fmt.Stringer.
|
|
||||||
func (dt *DocumentToken) String() string {
|
|
||||||
var builder strings.Builder
|
|
||||||
builder.WriteString("DocumentToken(")
|
|
||||||
builder.WriteString(fmt.Sprintf("id=%v, ", dt.ID))
|
|
||||||
builder.WriteString("created_at=")
|
|
||||||
builder.WriteString(dt.CreatedAt.Format(time.ANSIC))
|
|
||||||
builder.WriteString(", ")
|
|
||||||
builder.WriteString("updated_at=")
|
|
||||||
builder.WriteString(dt.UpdatedAt.Format(time.ANSIC))
|
|
||||||
builder.WriteString(", ")
|
|
||||||
builder.WriteString("token=")
|
|
||||||
builder.WriteString(fmt.Sprintf("%v", dt.Token))
|
|
||||||
builder.WriteString(", ")
|
|
||||||
builder.WriteString("uses=")
|
|
||||||
builder.WriteString(fmt.Sprintf("%v", dt.Uses))
|
|
||||||
builder.WriteString(", ")
|
|
||||||
builder.WriteString("expires_at=")
|
|
||||||
builder.WriteString(dt.ExpiresAt.Format(time.ANSIC))
|
|
||||||
builder.WriteByte(')')
|
|
||||||
return builder.String()
|
|
||||||
}
|
|
||||||
|
|
||||||
// DocumentTokens is a parsable slice of DocumentToken.
|
|
||||||
type DocumentTokens []*DocumentToken
|
|
||||||
|
|
||||||
func (dt DocumentTokens) config(cfg config) {
|
|
||||||
for _i := range dt {
|
|
||||||
dt[_i].config = cfg
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,85 +0,0 @@
|
||||||
// Code generated by ent, DO NOT EDIT.
|
|
||||||
|
|
||||||
package documenttoken
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/google/uuid"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
// Label holds the string label denoting the documenttoken type in the database.
|
|
||||||
Label = "document_token"
|
|
||||||
// FieldID holds the string denoting the id field in the database.
|
|
||||||
FieldID = "id"
|
|
||||||
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
|
||||||
FieldCreatedAt = "created_at"
|
|
||||||
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
|
|
||||||
FieldUpdatedAt = "updated_at"
|
|
||||||
// FieldToken holds the string denoting the token field in the database.
|
|
||||||
FieldToken = "token"
|
|
||||||
// FieldUses holds the string denoting the uses field in the database.
|
|
||||||
FieldUses = "uses"
|
|
||||||
// FieldExpiresAt holds the string denoting the expires_at field in the database.
|
|
||||||
FieldExpiresAt = "expires_at"
|
|
||||||
// EdgeDocument holds the string denoting the document edge name in mutations.
|
|
||||||
EdgeDocument = "document"
|
|
||||||
// Table holds the table name of the documenttoken in the database.
|
|
||||||
Table = "document_tokens"
|
|
||||||
// DocumentTable is the table that holds the document relation/edge.
|
|
||||||
DocumentTable = "document_tokens"
|
|
||||||
// DocumentInverseTable is the table name for the Document entity.
|
|
||||||
// It exists in this package in order to avoid circular dependency with the "document" package.
|
|
||||||
DocumentInverseTable = "documents"
|
|
||||||
// DocumentColumn is the table column denoting the document relation/edge.
|
|
||||||
DocumentColumn = "document_document_tokens"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Columns holds all SQL columns for documenttoken fields.
|
|
||||||
var Columns = []string{
|
|
||||||
FieldID,
|
|
||||||
FieldCreatedAt,
|
|
||||||
FieldUpdatedAt,
|
|
||||||
FieldToken,
|
|
||||||
FieldUses,
|
|
||||||
FieldExpiresAt,
|
|
||||||
}
|
|
||||||
|
|
||||||
// ForeignKeys holds the SQL foreign-keys that are owned by the "document_tokens"
|
|
||||||
// table and are not defined as standalone fields in the schema.
|
|
||||||
var ForeignKeys = []string{
|
|
||||||
"document_document_tokens",
|
|
||||||
}
|
|
||||||
|
|
||||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
|
||||||
func ValidColumn(column string) bool {
|
|
||||||
for i := range Columns {
|
|
||||||
if column == Columns[i] {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for i := range ForeignKeys {
|
|
||||||
if column == ForeignKeys[i] {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
|
||||||
DefaultCreatedAt func() time.Time
|
|
||||||
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
|
||||||
DefaultUpdatedAt func() time.Time
|
|
||||||
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
|
|
||||||
UpdateDefaultUpdatedAt func() time.Time
|
|
||||||
// TokenValidator is a validator for the "token" field. It is called by the builders before save.
|
|
||||||
TokenValidator func([]byte) error
|
|
||||||
// DefaultUses holds the default value on creation for the "uses" field.
|
|
||||||
DefaultUses int
|
|
||||||
// DefaultExpiresAt holds the default value on creation for the "expires_at" field.
|
|
||||||
DefaultExpiresAt func() time.Time
|
|
||||||
// DefaultID holds the default value on creation for the "id" field.
|
|
||||||
DefaultID func() uuid.UUID
|
|
||||||
)
|
|
|
@ -1,498 +0,0 @@
|
||||||
// Code generated by ent, DO NOT EDIT.
|
|
||||||
|
|
||||||
package documenttoken
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"entgo.io/ent/dialect/sql"
|
|
||||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
||||||
"github.com/google/uuid"
|
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/predicate"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ID filters vertices based on their ID field.
|
|
||||||
func ID(id uuid.UUID) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.EQ(s.C(FieldID), id))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// IDEQ applies the EQ predicate on the ID field.
|
|
||||||
func IDEQ(id uuid.UUID) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.EQ(s.C(FieldID), id))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// IDNEQ applies the NEQ predicate on the ID field.
|
|
||||||
func IDNEQ(id uuid.UUID) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.NEQ(s.C(FieldID), id))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// IDIn applies the In predicate on the ID field.
|
|
||||||
func IDIn(ids ...uuid.UUID) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
v := make([]any, len(ids))
|
|
||||||
for i := range v {
|
|
||||||
v[i] = ids[i]
|
|
||||||
}
|
|
||||||
s.Where(sql.In(s.C(FieldID), v...))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// IDNotIn applies the NotIn predicate on the ID field.
|
|
||||||
func IDNotIn(ids ...uuid.UUID) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
v := make([]any, len(ids))
|
|
||||||
for i := range v {
|
|
||||||
v[i] = ids[i]
|
|
||||||
}
|
|
||||||
s.Where(sql.NotIn(s.C(FieldID), v...))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// IDGT applies the GT predicate on the ID field.
|
|
||||||
func IDGT(id uuid.UUID) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.GT(s.C(FieldID), id))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// IDGTE applies the GTE predicate on the ID field.
|
|
||||||
func IDGTE(id uuid.UUID) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.GTE(s.C(FieldID), id))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// IDLT applies the LT predicate on the ID field.
|
|
||||||
func IDLT(id uuid.UUID) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.LT(s.C(FieldID), id))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// IDLTE applies the LTE predicate on the ID field.
|
|
||||||
func IDLTE(id uuid.UUID) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.LTE(s.C(FieldID), id))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
|
||||||
func CreatedAt(v time.Time) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.EQ(s.C(FieldCreatedAt), v))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
|
|
||||||
func UpdatedAt(v time.Time) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.EQ(s.C(FieldUpdatedAt), v))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Token applies equality check predicate on the "token" field. It's identical to TokenEQ.
|
|
||||||
func Token(v []byte) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.EQ(s.C(FieldToken), v))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Uses applies equality check predicate on the "uses" field. It's identical to UsesEQ.
|
|
||||||
func Uses(v int) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.EQ(s.C(FieldUses), v))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExpiresAt applies equality check predicate on the "expires_at" field. It's identical to ExpiresAtEQ.
|
|
||||||
func ExpiresAt(v time.Time) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.EQ(s.C(FieldExpiresAt), v))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
|
|
||||||
func CreatedAtEQ(v time.Time) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.EQ(s.C(FieldCreatedAt), v))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
|
|
||||||
func CreatedAtNEQ(v time.Time) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.NEQ(s.C(FieldCreatedAt), v))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreatedAtIn applies the In predicate on the "created_at" field.
|
|
||||||
func CreatedAtIn(vs ...time.Time) predicate.DocumentToken {
|
|
||||||
v := make([]any, len(vs))
|
|
||||||
for i := range v {
|
|
||||||
v[i] = vs[i]
|
|
||||||
}
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.In(s.C(FieldCreatedAt), v...))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
|
|
||||||
func CreatedAtNotIn(vs ...time.Time) predicate.DocumentToken {
|
|
||||||
v := make([]any, len(vs))
|
|
||||||
for i := range v {
|
|
||||||
v[i] = vs[i]
|
|
||||||
}
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.NotIn(s.C(FieldCreatedAt), v...))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreatedAtGT applies the GT predicate on the "created_at" field.
|
|
||||||
func CreatedAtGT(v time.Time) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.GT(s.C(FieldCreatedAt), v))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
|
|
||||||
func CreatedAtGTE(v time.Time) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.GTE(s.C(FieldCreatedAt), v))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreatedAtLT applies the LT predicate on the "created_at" field.
|
|
||||||
func CreatedAtLT(v time.Time) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.LT(s.C(FieldCreatedAt), v))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
|
|
||||||
func CreatedAtLTE(v time.Time) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.LTE(s.C(FieldCreatedAt), v))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
|
|
||||||
func UpdatedAtEQ(v time.Time) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.EQ(s.C(FieldUpdatedAt), v))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
|
|
||||||
func UpdatedAtNEQ(v time.Time) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.NEQ(s.C(FieldUpdatedAt), v))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdatedAtIn applies the In predicate on the "updated_at" field.
|
|
||||||
func UpdatedAtIn(vs ...time.Time) predicate.DocumentToken {
|
|
||||||
v := make([]any, len(vs))
|
|
||||||
for i := range v {
|
|
||||||
v[i] = vs[i]
|
|
||||||
}
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.In(s.C(FieldUpdatedAt), v...))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
|
|
||||||
func UpdatedAtNotIn(vs ...time.Time) predicate.DocumentToken {
|
|
||||||
v := make([]any, len(vs))
|
|
||||||
for i := range v {
|
|
||||||
v[i] = vs[i]
|
|
||||||
}
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.NotIn(s.C(FieldUpdatedAt), v...))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
|
|
||||||
func UpdatedAtGT(v time.Time) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.GT(s.C(FieldUpdatedAt), v))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
|
|
||||||
func UpdatedAtGTE(v time.Time) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.GTE(s.C(FieldUpdatedAt), v))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
|
|
||||||
func UpdatedAtLT(v time.Time) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.LT(s.C(FieldUpdatedAt), v))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
|
|
||||||
func UpdatedAtLTE(v time.Time) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.LTE(s.C(FieldUpdatedAt), v))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// TokenEQ applies the EQ predicate on the "token" field.
|
|
||||||
func TokenEQ(v []byte) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.EQ(s.C(FieldToken), v))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// TokenNEQ applies the NEQ predicate on the "token" field.
|
|
||||||
func TokenNEQ(v []byte) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.NEQ(s.C(FieldToken), v))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// TokenIn applies the In predicate on the "token" field.
|
|
||||||
func TokenIn(vs ...[]byte) predicate.DocumentToken {
|
|
||||||
v := make([]any, len(vs))
|
|
||||||
for i := range v {
|
|
||||||
v[i] = vs[i]
|
|
||||||
}
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.In(s.C(FieldToken), v...))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// TokenNotIn applies the NotIn predicate on the "token" field.
|
|
||||||
func TokenNotIn(vs ...[]byte) predicate.DocumentToken {
|
|
||||||
v := make([]any, len(vs))
|
|
||||||
for i := range v {
|
|
||||||
v[i] = vs[i]
|
|
||||||
}
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.NotIn(s.C(FieldToken), v...))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// TokenGT applies the GT predicate on the "token" field.
|
|
||||||
func TokenGT(v []byte) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.GT(s.C(FieldToken), v))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// TokenGTE applies the GTE predicate on the "token" field.
|
|
||||||
func TokenGTE(v []byte) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.GTE(s.C(FieldToken), v))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// TokenLT applies the LT predicate on the "token" field.
|
|
||||||
func TokenLT(v []byte) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.LT(s.C(FieldToken), v))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// TokenLTE applies the LTE predicate on the "token" field.
|
|
||||||
func TokenLTE(v []byte) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.LTE(s.C(FieldToken), v))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// UsesEQ applies the EQ predicate on the "uses" field.
|
|
||||||
func UsesEQ(v int) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.EQ(s.C(FieldUses), v))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// UsesNEQ applies the NEQ predicate on the "uses" field.
|
|
||||||
func UsesNEQ(v int) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.NEQ(s.C(FieldUses), v))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// UsesIn applies the In predicate on the "uses" field.
|
|
||||||
func UsesIn(vs ...int) predicate.DocumentToken {
|
|
||||||
v := make([]any, len(vs))
|
|
||||||
for i := range v {
|
|
||||||
v[i] = vs[i]
|
|
||||||
}
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.In(s.C(FieldUses), v...))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// UsesNotIn applies the NotIn predicate on the "uses" field.
|
|
||||||
func UsesNotIn(vs ...int) predicate.DocumentToken {
|
|
||||||
v := make([]any, len(vs))
|
|
||||||
for i := range v {
|
|
||||||
v[i] = vs[i]
|
|
||||||
}
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.NotIn(s.C(FieldUses), v...))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// UsesGT applies the GT predicate on the "uses" field.
|
|
||||||
func UsesGT(v int) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.GT(s.C(FieldUses), v))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// UsesGTE applies the GTE predicate on the "uses" field.
|
|
||||||
func UsesGTE(v int) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.GTE(s.C(FieldUses), v))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// UsesLT applies the LT predicate on the "uses" field.
|
|
||||||
func UsesLT(v int) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.LT(s.C(FieldUses), v))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// UsesLTE applies the LTE predicate on the "uses" field.
|
|
||||||
func UsesLTE(v int) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.LTE(s.C(FieldUses), v))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExpiresAtEQ applies the EQ predicate on the "expires_at" field.
|
|
||||||
func ExpiresAtEQ(v time.Time) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.EQ(s.C(FieldExpiresAt), v))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExpiresAtNEQ applies the NEQ predicate on the "expires_at" field.
|
|
||||||
func ExpiresAtNEQ(v time.Time) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.NEQ(s.C(FieldExpiresAt), v))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExpiresAtIn applies the In predicate on the "expires_at" field.
|
|
||||||
func ExpiresAtIn(vs ...time.Time) predicate.DocumentToken {
|
|
||||||
v := make([]any, len(vs))
|
|
||||||
for i := range v {
|
|
||||||
v[i] = vs[i]
|
|
||||||
}
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.In(s.C(FieldExpiresAt), v...))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExpiresAtNotIn applies the NotIn predicate on the "expires_at" field.
|
|
||||||
func ExpiresAtNotIn(vs ...time.Time) predicate.DocumentToken {
|
|
||||||
v := make([]any, len(vs))
|
|
||||||
for i := range v {
|
|
||||||
v[i] = vs[i]
|
|
||||||
}
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.NotIn(s.C(FieldExpiresAt), v...))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExpiresAtGT applies the GT predicate on the "expires_at" field.
|
|
||||||
func ExpiresAtGT(v time.Time) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.GT(s.C(FieldExpiresAt), v))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExpiresAtGTE applies the GTE predicate on the "expires_at" field.
|
|
||||||
func ExpiresAtGTE(v time.Time) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.GTE(s.C(FieldExpiresAt), v))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExpiresAtLT applies the LT predicate on the "expires_at" field.
|
|
||||||
func ExpiresAtLT(v time.Time) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.LT(s.C(FieldExpiresAt), v))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExpiresAtLTE applies the LTE predicate on the "expires_at" field.
|
|
||||||
func ExpiresAtLTE(v time.Time) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.LTE(s.C(FieldExpiresAt), v))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// HasDocument applies the HasEdge predicate on the "document" edge.
|
|
||||||
func HasDocument() predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
step := sqlgraph.NewStep(
|
|
||||||
sqlgraph.From(Table, FieldID),
|
|
||||||
sqlgraph.To(DocumentTable, FieldID),
|
|
||||||
sqlgraph.Edge(sqlgraph.M2O, true, DocumentTable, DocumentColumn),
|
|
||||||
)
|
|
||||||
sqlgraph.HasNeighbors(s, step)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// HasDocumentWith applies the HasEdge predicate on the "document" edge with a given conditions (other predicates).
|
|
||||||
func HasDocumentWith(preds ...predicate.Document) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
step := sqlgraph.NewStep(
|
|
||||||
sqlgraph.From(Table, FieldID),
|
|
||||||
sqlgraph.To(DocumentInverseTable, FieldID),
|
|
||||||
sqlgraph.Edge(sqlgraph.M2O, true, DocumentTable, DocumentColumn),
|
|
||||||
)
|
|
||||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
|
||||||
for _, p := range preds {
|
|
||||||
p(s)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// And groups predicates with the AND operator between them.
|
|
||||||
func And(predicates ...predicate.DocumentToken) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s1 := s.Clone().SetP(nil)
|
|
||||||
for _, p := range predicates {
|
|
||||||
p(s1)
|
|
||||||
}
|
|
||||||
s.Where(s1.P())
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Or groups predicates with the OR operator between them.
|
|
||||||
func Or(predicates ...predicate.DocumentToken) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
s1 := s.Clone().SetP(nil)
|
|
||||||
for i, p := range predicates {
|
|
||||||
if i > 0 {
|
|
||||||
s1.Or()
|
|
||||||
}
|
|
||||||
p(s1)
|
|
||||||
}
|
|
||||||
s.Where(s1.P())
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Not applies the not operator on the given predicate.
|
|
||||||
func Not(p predicate.DocumentToken) predicate.DocumentToken {
|
|
||||||
return predicate.DocumentToken(func(s *sql.Selector) {
|
|
||||||
p(s.Not())
|
|
||||||
})
|
|
||||||
}
|
|
|
@ -1,398 +0,0 @@
|
||||||
// Code generated by ent, DO NOT EDIT.
|
|
||||||
|
|
||||||
package ent
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
||||||
"entgo.io/ent/schema/field"
|
|
||||||
"github.com/google/uuid"
|
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/document"
|
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/documenttoken"
|
|
||||||
)
|
|
||||||
|
|
||||||
// DocumentTokenCreate is the builder for creating a DocumentToken entity.
|
|
||||||
type DocumentTokenCreate struct {
|
|
||||||
config
|
|
||||||
mutation *DocumentTokenMutation
|
|
||||||
hooks []Hook
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetCreatedAt sets the "created_at" field.
|
|
||||||
func (dtc *DocumentTokenCreate) SetCreatedAt(t time.Time) *DocumentTokenCreate {
|
|
||||||
dtc.mutation.SetCreatedAt(t)
|
|
||||||
return dtc
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
||||||
func (dtc *DocumentTokenCreate) SetNillableCreatedAt(t *time.Time) *DocumentTokenCreate {
|
|
||||||
if t != nil {
|
|
||||||
dtc.SetCreatedAt(*t)
|
|
||||||
}
|
|
||||||
return dtc
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetUpdatedAt sets the "updated_at" field.
|
|
||||||
func (dtc *DocumentTokenCreate) SetUpdatedAt(t time.Time) *DocumentTokenCreate {
|
|
||||||
dtc.mutation.SetUpdatedAt(t)
|
|
||||||
return dtc
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
|
||||||
func (dtc *DocumentTokenCreate) SetNillableUpdatedAt(t *time.Time) *DocumentTokenCreate {
|
|
||||||
if t != nil {
|
|
||||||
dtc.SetUpdatedAt(*t)
|
|
||||||
}
|
|
||||||
return dtc
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetToken sets the "token" field.
|
|
||||||
func (dtc *DocumentTokenCreate) SetToken(b []byte) *DocumentTokenCreate {
|
|
||||||
dtc.mutation.SetToken(b)
|
|
||||||
return dtc
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetUses sets the "uses" field.
|
|
||||||
func (dtc *DocumentTokenCreate) SetUses(i int) *DocumentTokenCreate {
|
|
||||||
dtc.mutation.SetUses(i)
|
|
||||||
return dtc
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetNillableUses sets the "uses" field if the given value is not nil.
|
|
||||||
func (dtc *DocumentTokenCreate) SetNillableUses(i *int) *DocumentTokenCreate {
|
|
||||||
if i != nil {
|
|
||||||
dtc.SetUses(*i)
|
|
||||||
}
|
|
||||||
return dtc
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetExpiresAt sets the "expires_at" field.
|
|
||||||
func (dtc *DocumentTokenCreate) SetExpiresAt(t time.Time) *DocumentTokenCreate {
|
|
||||||
dtc.mutation.SetExpiresAt(t)
|
|
||||||
return dtc
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetNillableExpiresAt sets the "expires_at" field if the given value is not nil.
|
|
||||||
func (dtc *DocumentTokenCreate) SetNillableExpiresAt(t *time.Time) *DocumentTokenCreate {
|
|
||||||
if t != nil {
|
|
||||||
dtc.SetExpiresAt(*t)
|
|
||||||
}
|
|
||||||
return dtc
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetID sets the "id" field.
|
|
||||||
func (dtc *DocumentTokenCreate) SetID(u uuid.UUID) *DocumentTokenCreate {
|
|
||||||
dtc.mutation.SetID(u)
|
|
||||||
return dtc
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetNillableID sets the "id" field if the given value is not nil.
|
|
||||||
func (dtc *DocumentTokenCreate) SetNillableID(u *uuid.UUID) *DocumentTokenCreate {
|
|
||||||
if u != nil {
|
|
||||||
dtc.SetID(*u)
|
|
||||||
}
|
|
||||||
return dtc
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetDocumentID sets the "document" edge to the Document entity by ID.
|
|
||||||
func (dtc *DocumentTokenCreate) SetDocumentID(id uuid.UUID) *DocumentTokenCreate {
|
|
||||||
dtc.mutation.SetDocumentID(id)
|
|
||||||
return dtc
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetNillableDocumentID sets the "document" edge to the Document entity by ID if the given value is not nil.
|
|
||||||
func (dtc *DocumentTokenCreate) SetNillableDocumentID(id *uuid.UUID) *DocumentTokenCreate {
|
|
||||||
if id != nil {
|
|
||||||
dtc = dtc.SetDocumentID(*id)
|
|
||||||
}
|
|
||||||
return dtc
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetDocument sets the "document" edge to the Document entity.
|
|
||||||
func (dtc *DocumentTokenCreate) SetDocument(d *Document) *DocumentTokenCreate {
|
|
||||||
return dtc.SetDocumentID(d.ID)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mutation returns the DocumentTokenMutation object of the builder.
|
|
||||||
func (dtc *DocumentTokenCreate) Mutation() *DocumentTokenMutation {
|
|
||||||
return dtc.mutation
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save creates the DocumentToken in the database.
|
|
||||||
func (dtc *DocumentTokenCreate) Save(ctx context.Context) (*DocumentToken, error) {
|
|
||||||
var (
|
|
||||||
err error
|
|
||||||
node *DocumentToken
|
|
||||||
)
|
|
||||||
dtc.defaults()
|
|
||||||
if len(dtc.hooks) == 0 {
|
|
||||||
if err = dtc.check(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
node, err = dtc.sqlSave(ctx)
|
|
||||||
} else {
|
|
||||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
||||||
mutation, ok := m.(*DocumentTokenMutation)
|
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
|
||||||
}
|
|
||||||
if err = dtc.check(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
dtc.mutation = mutation
|
|
||||||
if node, err = dtc.sqlSave(ctx); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
mutation.id = &node.ID
|
|
||||||
mutation.done = true
|
|
||||||
return node, err
|
|
||||||
})
|
|
||||||
for i := len(dtc.hooks) - 1; i >= 0; i-- {
|
|
||||||
if dtc.hooks[i] == nil {
|
|
||||||
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
|
||||||
}
|
|
||||||
mut = dtc.hooks[i](mut)
|
|
||||||
}
|
|
||||||
v, err := mut.Mutate(ctx, dtc.mutation)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
nv, ok := v.(*DocumentToken)
|
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("unexpected node type %T returned from DocumentTokenMutation", v)
|
|
||||||
}
|
|
||||||
node = nv
|
|
||||||
}
|
|
||||||
return node, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// SaveX calls Save and panics if Save returns an error.
|
|
||||||
func (dtc *DocumentTokenCreate) SaveX(ctx context.Context) *DocumentToken {
|
|
||||||
v, err := dtc.Save(ctx)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
|
|
||||||
// Exec executes the query.
|
|
||||||
func (dtc *DocumentTokenCreate) Exec(ctx context.Context) error {
|
|
||||||
_, err := dtc.Save(ctx)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExecX is like Exec, but panics if an error occurs.
|
|
||||||
func (dtc *DocumentTokenCreate) ExecX(ctx context.Context) {
|
|
||||||
if err := dtc.Exec(ctx); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// defaults sets the default values of the builder before save.
|
|
||||||
func (dtc *DocumentTokenCreate) defaults() {
|
|
||||||
if _, ok := dtc.mutation.CreatedAt(); !ok {
|
|
||||||
v := documenttoken.DefaultCreatedAt()
|
|
||||||
dtc.mutation.SetCreatedAt(v)
|
|
||||||
}
|
|
||||||
if _, ok := dtc.mutation.UpdatedAt(); !ok {
|
|
||||||
v := documenttoken.DefaultUpdatedAt()
|
|
||||||
dtc.mutation.SetUpdatedAt(v)
|
|
||||||
}
|
|
||||||
if _, ok := dtc.mutation.Uses(); !ok {
|
|
||||||
v := documenttoken.DefaultUses
|
|
||||||
dtc.mutation.SetUses(v)
|
|
||||||
}
|
|
||||||
if _, ok := dtc.mutation.ExpiresAt(); !ok {
|
|
||||||
v := documenttoken.DefaultExpiresAt()
|
|
||||||
dtc.mutation.SetExpiresAt(v)
|
|
||||||
}
|
|
||||||
if _, ok := dtc.mutation.ID(); !ok {
|
|
||||||
v := documenttoken.DefaultID()
|
|
||||||
dtc.mutation.SetID(v)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// check runs all checks and user-defined validators on the builder.
|
|
||||||
func (dtc *DocumentTokenCreate) check() error {
|
|
||||||
if _, ok := dtc.mutation.CreatedAt(); !ok {
|
|
||||||
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "DocumentToken.created_at"`)}
|
|
||||||
}
|
|
||||||
if _, ok := dtc.mutation.UpdatedAt(); !ok {
|
|
||||||
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "DocumentToken.updated_at"`)}
|
|
||||||
}
|
|
||||||
if _, ok := dtc.mutation.Token(); !ok {
|
|
||||||
return &ValidationError{Name: "token", err: errors.New(`ent: missing required field "DocumentToken.token"`)}
|
|
||||||
}
|
|
||||||
if v, ok := dtc.mutation.Token(); ok {
|
|
||||||
if err := documenttoken.TokenValidator(v); err != nil {
|
|
||||||
return &ValidationError{Name: "token", err: fmt.Errorf(`ent: validator failed for field "DocumentToken.token": %w`, err)}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if _, ok := dtc.mutation.Uses(); !ok {
|
|
||||||
return &ValidationError{Name: "uses", err: errors.New(`ent: missing required field "DocumentToken.uses"`)}
|
|
||||||
}
|
|
||||||
if _, ok := dtc.mutation.ExpiresAt(); !ok {
|
|
||||||
return &ValidationError{Name: "expires_at", err: errors.New(`ent: missing required field "DocumentToken.expires_at"`)}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dtc *DocumentTokenCreate) sqlSave(ctx context.Context) (*DocumentToken, error) {
|
|
||||||
_node, _spec := dtc.createSpec()
|
|
||||||
if err := sqlgraph.CreateNode(ctx, dtc.driver, _spec); err != nil {
|
|
||||||
if sqlgraph.IsConstraintError(err) {
|
|
||||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
||||||
}
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if _spec.ID.Value != nil {
|
|
||||||
if id, ok := _spec.ID.Value.(*uuid.UUID); ok {
|
|
||||||
_node.ID = *id
|
|
||||||
} else if err := _node.ID.Scan(_spec.ID.Value); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return _node, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dtc *DocumentTokenCreate) createSpec() (*DocumentToken, *sqlgraph.CreateSpec) {
|
|
||||||
var (
|
|
||||||
_node = &DocumentToken{config: dtc.config}
|
|
||||||
_spec = &sqlgraph.CreateSpec{
|
|
||||||
Table: documenttoken.Table,
|
|
||||||
ID: &sqlgraph.FieldSpec{
|
|
||||||
Type: field.TypeUUID,
|
|
||||||
Column: documenttoken.FieldID,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
if id, ok := dtc.mutation.ID(); ok {
|
|
||||||
_node.ID = id
|
|
||||||
_spec.ID.Value = &id
|
|
||||||
}
|
|
||||||
if value, ok := dtc.mutation.CreatedAt(); ok {
|
|
||||||
_spec.SetField(documenttoken.FieldCreatedAt, field.TypeTime, value)
|
|
||||||
_node.CreatedAt = value
|
|
||||||
}
|
|
||||||
if value, ok := dtc.mutation.UpdatedAt(); ok {
|
|
||||||
_spec.SetField(documenttoken.FieldUpdatedAt, field.TypeTime, value)
|
|
||||||
_node.UpdatedAt = value
|
|
||||||
}
|
|
||||||
if value, ok := dtc.mutation.Token(); ok {
|
|
||||||
_spec.SetField(documenttoken.FieldToken, field.TypeBytes, value)
|
|
||||||
_node.Token = value
|
|
||||||
}
|
|
||||||
if value, ok := dtc.mutation.Uses(); ok {
|
|
||||||
_spec.SetField(documenttoken.FieldUses, field.TypeInt, value)
|
|
||||||
_node.Uses = value
|
|
||||||
}
|
|
||||||
if value, ok := dtc.mutation.ExpiresAt(); ok {
|
|
||||||
_spec.SetField(documenttoken.FieldExpiresAt, field.TypeTime, value)
|
|
||||||
_node.ExpiresAt = value
|
|
||||||
}
|
|
||||||
if nodes := dtc.mutation.DocumentIDs(); len(nodes) > 0 {
|
|
||||||
edge := &sqlgraph.EdgeSpec{
|
|
||||||
Rel: sqlgraph.M2O,
|
|
||||||
Inverse: true,
|
|
||||||
Table: documenttoken.DocumentTable,
|
|
||||||
Columns: []string{documenttoken.DocumentColumn},
|
|
||||||
Bidi: false,
|
|
||||||
Target: &sqlgraph.EdgeTarget{
|
|
||||||
IDSpec: &sqlgraph.FieldSpec{
|
|
||||||
Type: field.TypeUUID,
|
|
||||||
Column: document.FieldID,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, k := range nodes {
|
|
||||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
||||||
}
|
|
||||||
_node.document_document_tokens = &nodes[0]
|
|
||||||
_spec.Edges = append(_spec.Edges, edge)
|
|
||||||
}
|
|
||||||
return _node, _spec
|
|
||||||
}
|
|
||||||
|
|
||||||
// DocumentTokenCreateBulk is the builder for creating many DocumentToken entities in bulk.
|
|
||||||
type DocumentTokenCreateBulk struct {
|
|
||||||
config
|
|
||||||
builders []*DocumentTokenCreate
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save creates the DocumentToken entities in the database.
|
|
||||||
func (dtcb *DocumentTokenCreateBulk) Save(ctx context.Context) ([]*DocumentToken, error) {
|
|
||||||
specs := make([]*sqlgraph.CreateSpec, len(dtcb.builders))
|
|
||||||
nodes := make([]*DocumentToken, len(dtcb.builders))
|
|
||||||
mutators := make([]Mutator, len(dtcb.builders))
|
|
||||||
for i := range dtcb.builders {
|
|
||||||
func(i int, root context.Context) {
|
|
||||||
builder := dtcb.builders[i]
|
|
||||||
builder.defaults()
|
|
||||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
||||||
mutation, ok := m.(*DocumentTokenMutation)
|
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
|
||||||
}
|
|
||||||
if err := builder.check(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
builder.mutation = mutation
|
|
||||||
nodes[i], specs[i] = builder.createSpec()
|
|
||||||
var err error
|
|
||||||
if i < len(mutators)-1 {
|
|
||||||
_, err = mutators[i+1].Mutate(root, dtcb.builders[i+1].mutation)
|
|
||||||
} else {
|
|
||||||
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
|
||||||
// Invoke the actual operation on the latest mutation in the chain.
|
|
||||||
if err = sqlgraph.BatchCreate(ctx, dtcb.driver, spec); err != nil {
|
|
||||||
if sqlgraph.IsConstraintError(err) {
|
|
||||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
mutation.id = &nodes[i].ID
|
|
||||||
mutation.done = true
|
|
||||||
return nodes[i], nil
|
|
||||||
})
|
|
||||||
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
|
||||||
mut = builder.hooks[i](mut)
|
|
||||||
}
|
|
||||||
mutators[i] = mut
|
|
||||||
}(i, ctx)
|
|
||||||
}
|
|
||||||
if len(mutators) > 0 {
|
|
||||||
if _, err := mutators[0].Mutate(ctx, dtcb.builders[0].mutation); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nodes, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// SaveX is like Save, but panics if an error occurs.
|
|
||||||
func (dtcb *DocumentTokenCreateBulk) SaveX(ctx context.Context) []*DocumentToken {
|
|
||||||
v, err := dtcb.Save(ctx)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
|
|
||||||
// Exec executes the query.
|
|
||||||
func (dtcb *DocumentTokenCreateBulk) Exec(ctx context.Context) error {
|
|
||||||
_, err := dtcb.Save(ctx)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExecX is like Exec, but panics if an error occurs.
|
|
||||||
func (dtcb *DocumentTokenCreateBulk) ExecX(ctx context.Context) {
|
|
||||||
if err := dtcb.Exec(ctx); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,115 +0,0 @@
|
||||||
// Code generated by ent, DO NOT EDIT.
|
|
||||||
|
|
||||||
package ent
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"entgo.io/ent/dialect/sql"
|
|
||||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
||||||
"entgo.io/ent/schema/field"
|
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/documenttoken"
|
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/predicate"
|
|
||||||
)
|
|
||||||
|
|
||||||
// DocumentTokenDelete is the builder for deleting a DocumentToken entity.
|
|
||||||
type DocumentTokenDelete struct {
|
|
||||||
config
|
|
||||||
hooks []Hook
|
|
||||||
mutation *DocumentTokenMutation
|
|
||||||
}
|
|
||||||
|
|
||||||
// Where appends a list predicates to the DocumentTokenDelete builder.
|
|
||||||
func (dtd *DocumentTokenDelete) Where(ps ...predicate.DocumentToken) *DocumentTokenDelete {
|
|
||||||
dtd.mutation.Where(ps...)
|
|
||||||
return dtd
|
|
||||||
}
|
|
||||||
|
|
||||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
|
||||||
func (dtd *DocumentTokenDelete) Exec(ctx context.Context) (int, error) {
|
|
||||||
var (
|
|
||||||
err error
|
|
||||||
affected int
|
|
||||||
)
|
|
||||||
if len(dtd.hooks) == 0 {
|
|
||||||
affected, err = dtd.sqlExec(ctx)
|
|
||||||
} else {
|
|
||||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
||||||
mutation, ok := m.(*DocumentTokenMutation)
|
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
|
||||||
}
|
|
||||||
dtd.mutation = mutation
|
|
||||||
affected, err = dtd.sqlExec(ctx)
|
|
||||||
mutation.done = true
|
|
||||||
return affected, err
|
|
||||||
})
|
|
||||||
for i := len(dtd.hooks) - 1; i >= 0; i-- {
|
|
||||||
if dtd.hooks[i] == nil {
|
|
||||||
return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
|
||||||
}
|
|
||||||
mut = dtd.hooks[i](mut)
|
|
||||||
}
|
|
||||||
if _, err := mut.Mutate(ctx, dtd.mutation); err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return affected, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExecX is like Exec, but panics if an error occurs.
|
|
||||||
func (dtd *DocumentTokenDelete) ExecX(ctx context.Context) int {
|
|
||||||
n, err := dtd.Exec(ctx)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return n
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dtd *DocumentTokenDelete) sqlExec(ctx context.Context) (int, error) {
|
|
||||||
_spec := &sqlgraph.DeleteSpec{
|
|
||||||
Node: &sqlgraph.NodeSpec{
|
|
||||||
Table: documenttoken.Table,
|
|
||||||
ID: &sqlgraph.FieldSpec{
|
|
||||||
Type: field.TypeUUID,
|
|
||||||
Column: documenttoken.FieldID,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
if ps := dtd.mutation.predicates; len(ps) > 0 {
|
|
||||||
_spec.Predicate = func(selector *sql.Selector) {
|
|
||||||
for i := range ps {
|
|
||||||
ps[i](selector)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
affected, err := sqlgraph.DeleteNodes(ctx, dtd.driver, _spec)
|
|
||||||
if err != nil && sqlgraph.IsConstraintError(err) {
|
|
||||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
||||||
}
|
|
||||||
return affected, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// DocumentTokenDeleteOne is the builder for deleting a single DocumentToken entity.
|
|
||||||
type DocumentTokenDeleteOne struct {
|
|
||||||
dtd *DocumentTokenDelete
|
|
||||||
}
|
|
||||||
|
|
||||||
// Exec executes the deletion query.
|
|
||||||
func (dtdo *DocumentTokenDeleteOne) Exec(ctx context.Context) error {
|
|
||||||
n, err := dtdo.dtd.Exec(ctx)
|
|
||||||
switch {
|
|
||||||
case err != nil:
|
|
||||||
return err
|
|
||||||
case n == 0:
|
|
||||||
return &NotFoundError{documenttoken.Label}
|
|
||||||
default:
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExecX is like Exec, but panics if an error occurs.
|
|
||||||
func (dtdo *DocumentTokenDeleteOne) ExecX(ctx context.Context) {
|
|
||||||
dtdo.dtd.ExecX(ctx)
|
|
||||||
}
|
|
|
@ -1,633 +0,0 @@
|
||||||
// Code generated by ent, DO NOT EDIT.
|
|
||||||
|
|
||||||
package ent
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
"math"
|
|
||||||
|
|
||||||
"entgo.io/ent/dialect/sql"
|
|
||||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
||||||
"entgo.io/ent/schema/field"
|
|
||||||
"github.com/google/uuid"
|
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/document"
|
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/documenttoken"
|
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/predicate"
|
|
||||||
)
|
|
||||||
|
|
||||||
// DocumentTokenQuery is the builder for querying DocumentToken entities.
|
|
||||||
type DocumentTokenQuery struct {
|
|
||||||
config
|
|
||||||
limit *int
|
|
||||||
offset *int
|
|
||||||
unique *bool
|
|
||||||
order []OrderFunc
|
|
||||||
fields []string
|
|
||||||
predicates []predicate.DocumentToken
|
|
||||||
withDocument *DocumentQuery
|
|
||||||
withFKs bool
|
|
||||||
// intermediate query (i.e. traversal path).
|
|
||||||
sql *sql.Selector
|
|
||||||
path func(context.Context) (*sql.Selector, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Where adds a new predicate for the DocumentTokenQuery builder.
|
|
||||||
func (dtq *DocumentTokenQuery) Where(ps ...predicate.DocumentToken) *DocumentTokenQuery {
|
|
||||||
dtq.predicates = append(dtq.predicates, ps...)
|
|
||||||
return dtq
|
|
||||||
}
|
|
||||||
|
|
||||||
// Limit adds a limit step to the query.
|
|
||||||
func (dtq *DocumentTokenQuery) Limit(limit int) *DocumentTokenQuery {
|
|
||||||
dtq.limit = &limit
|
|
||||||
return dtq
|
|
||||||
}
|
|
||||||
|
|
||||||
// Offset adds an offset step to the query.
|
|
||||||
func (dtq *DocumentTokenQuery) Offset(offset int) *DocumentTokenQuery {
|
|
||||||
dtq.offset = &offset
|
|
||||||
return dtq
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unique configures the query builder to filter duplicate records on query.
|
|
||||||
// By default, unique is set to true, and can be disabled using this method.
|
|
||||||
func (dtq *DocumentTokenQuery) Unique(unique bool) *DocumentTokenQuery {
|
|
||||||
dtq.unique = &unique
|
|
||||||
return dtq
|
|
||||||
}
|
|
||||||
|
|
||||||
// Order adds an order step to the query.
|
|
||||||
func (dtq *DocumentTokenQuery) Order(o ...OrderFunc) *DocumentTokenQuery {
|
|
||||||
dtq.order = append(dtq.order, o...)
|
|
||||||
return dtq
|
|
||||||
}
|
|
||||||
|
|
||||||
// QueryDocument chains the current query on the "document" edge.
|
|
||||||
func (dtq *DocumentTokenQuery) QueryDocument() *DocumentQuery {
|
|
||||||
query := &DocumentQuery{config: dtq.config}
|
|
||||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
|
||||||
if err := dtq.prepareQuery(ctx); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
selector := dtq.sqlQuery(ctx)
|
|
||||||
if err := selector.Err(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
step := sqlgraph.NewStep(
|
|
||||||
sqlgraph.From(documenttoken.Table, documenttoken.FieldID, selector),
|
|
||||||
sqlgraph.To(document.Table, document.FieldID),
|
|
||||||
sqlgraph.Edge(sqlgraph.M2O, true, documenttoken.DocumentTable, documenttoken.DocumentColumn),
|
|
||||||
)
|
|
||||||
fromU = sqlgraph.SetNeighbors(dtq.driver.Dialect(), step)
|
|
||||||
return fromU, nil
|
|
||||||
}
|
|
||||||
return query
|
|
||||||
}
|
|
||||||
|
|
||||||
// First returns the first DocumentToken entity from the query.
|
|
||||||
// Returns a *NotFoundError when no DocumentToken was found.
|
|
||||||
func (dtq *DocumentTokenQuery) First(ctx context.Context) (*DocumentToken, error) {
|
|
||||||
nodes, err := dtq.Limit(1).All(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if len(nodes) == 0 {
|
|
||||||
return nil, &NotFoundError{documenttoken.Label}
|
|
||||||
}
|
|
||||||
return nodes[0], nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// FirstX is like First, but panics if an error occurs.
|
|
||||||
func (dtq *DocumentTokenQuery) FirstX(ctx context.Context) *DocumentToken {
|
|
||||||
node, err := dtq.First(ctx)
|
|
||||||
if err != nil && !IsNotFound(err) {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return node
|
|
||||||
}
|
|
||||||
|
|
||||||
// FirstID returns the first DocumentToken ID from the query.
|
|
||||||
// Returns a *NotFoundError when no DocumentToken ID was found.
|
|
||||||
func (dtq *DocumentTokenQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) {
|
|
||||||
var ids []uuid.UUID
|
|
||||||
if ids, err = dtq.Limit(1).IDs(ctx); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if len(ids) == 0 {
|
|
||||||
err = &NotFoundError{documenttoken.Label}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return ids[0], nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
|
||||||
func (dtq *DocumentTokenQuery) FirstIDX(ctx context.Context) uuid.UUID {
|
|
||||||
id, err := dtq.FirstID(ctx)
|
|
||||||
if err != nil && !IsNotFound(err) {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return id
|
|
||||||
}
|
|
||||||
|
|
||||||
// Only returns a single DocumentToken entity found by the query, ensuring it only returns one.
|
|
||||||
// Returns a *NotSingularError when more than one DocumentToken entity is found.
|
|
||||||
// Returns a *NotFoundError when no DocumentToken entities are found.
|
|
||||||
func (dtq *DocumentTokenQuery) Only(ctx context.Context) (*DocumentToken, error) {
|
|
||||||
nodes, err := dtq.Limit(2).All(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
switch len(nodes) {
|
|
||||||
case 1:
|
|
||||||
return nodes[0], nil
|
|
||||||
case 0:
|
|
||||||
return nil, &NotFoundError{documenttoken.Label}
|
|
||||||
default:
|
|
||||||
return nil, &NotSingularError{documenttoken.Label}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// OnlyX is like Only, but panics if an error occurs.
|
|
||||||
func (dtq *DocumentTokenQuery) OnlyX(ctx context.Context) *DocumentToken {
|
|
||||||
node, err := dtq.Only(ctx)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return node
|
|
||||||
}
|
|
||||||
|
|
||||||
// OnlyID is like Only, but returns the only DocumentToken ID in the query.
|
|
||||||
// Returns a *NotSingularError when more than one DocumentToken ID is found.
|
|
||||||
// Returns a *NotFoundError when no entities are found.
|
|
||||||
func (dtq *DocumentTokenQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) {
|
|
||||||
var ids []uuid.UUID
|
|
||||||
if ids, err = dtq.Limit(2).IDs(ctx); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
switch len(ids) {
|
|
||||||
case 1:
|
|
||||||
id = ids[0]
|
|
||||||
case 0:
|
|
||||||
err = &NotFoundError{documenttoken.Label}
|
|
||||||
default:
|
|
||||||
err = &NotSingularError{documenttoken.Label}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
|
||||||
func (dtq *DocumentTokenQuery) OnlyIDX(ctx context.Context) uuid.UUID {
|
|
||||||
id, err := dtq.OnlyID(ctx)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return id
|
|
||||||
}
|
|
||||||
|
|
||||||
// All executes the query and returns a list of DocumentTokens.
|
|
||||||
func (dtq *DocumentTokenQuery) All(ctx context.Context) ([]*DocumentToken, error) {
|
|
||||||
if err := dtq.prepareQuery(ctx); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return dtq.sqlAll(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
// AllX is like All, but panics if an error occurs.
|
|
||||||
func (dtq *DocumentTokenQuery) AllX(ctx context.Context) []*DocumentToken {
|
|
||||||
nodes, err := dtq.All(ctx)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return nodes
|
|
||||||
}
|
|
||||||
|
|
||||||
// IDs executes the query and returns a list of DocumentToken IDs.
|
|
||||||
func (dtq *DocumentTokenQuery) IDs(ctx context.Context) ([]uuid.UUID, error) {
|
|
||||||
var ids []uuid.UUID
|
|
||||||
if err := dtq.Select(documenttoken.FieldID).Scan(ctx, &ids); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return ids, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// IDsX is like IDs, but panics if an error occurs.
|
|
||||||
func (dtq *DocumentTokenQuery) IDsX(ctx context.Context) []uuid.UUID {
|
|
||||||
ids, err := dtq.IDs(ctx)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return ids
|
|
||||||
}
|
|
||||||
|
|
||||||
// Count returns the count of the given query.
|
|
||||||
func (dtq *DocumentTokenQuery) Count(ctx context.Context) (int, error) {
|
|
||||||
if err := dtq.prepareQuery(ctx); err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
return dtq.sqlCount(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
// CountX is like Count, but panics if an error occurs.
|
|
||||||
func (dtq *DocumentTokenQuery) CountX(ctx context.Context) int {
|
|
||||||
count, err := dtq.Count(ctx)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return count
|
|
||||||
}
|
|
||||||
|
|
||||||
// Exist returns true if the query has elements in the graph.
|
|
||||||
func (dtq *DocumentTokenQuery) Exist(ctx context.Context) (bool, error) {
|
|
||||||
if err := dtq.prepareQuery(ctx); err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
return dtq.sqlExist(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExistX is like Exist, but panics if an error occurs.
|
|
||||||
func (dtq *DocumentTokenQuery) ExistX(ctx context.Context) bool {
|
|
||||||
exist, err := dtq.Exist(ctx)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return exist
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clone returns a duplicate of the DocumentTokenQuery builder, including all associated steps. It can be
|
|
||||||
// used to prepare common query builders and use them differently after the clone is made.
|
|
||||||
func (dtq *DocumentTokenQuery) Clone() *DocumentTokenQuery {
|
|
||||||
if dtq == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return &DocumentTokenQuery{
|
|
||||||
config: dtq.config,
|
|
||||||
limit: dtq.limit,
|
|
||||||
offset: dtq.offset,
|
|
||||||
order: append([]OrderFunc{}, dtq.order...),
|
|
||||||
predicates: append([]predicate.DocumentToken{}, dtq.predicates...),
|
|
||||||
withDocument: dtq.withDocument.Clone(),
|
|
||||||
// clone intermediate query.
|
|
||||||
sql: dtq.sql.Clone(),
|
|
||||||
path: dtq.path,
|
|
||||||
unique: dtq.unique,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithDocument tells the query-builder to eager-load the nodes that are connected to
|
|
||||||
// the "document" edge. The optional arguments are used to configure the query builder of the edge.
|
|
||||||
func (dtq *DocumentTokenQuery) WithDocument(opts ...func(*DocumentQuery)) *DocumentTokenQuery {
|
|
||||||
query := &DocumentQuery{config: dtq.config}
|
|
||||||
for _, opt := range opts {
|
|
||||||
opt(query)
|
|
||||||
}
|
|
||||||
dtq.withDocument = query
|
|
||||||
return dtq
|
|
||||||
}
|
|
||||||
|
|
||||||
// GroupBy is used to group vertices by one or more fields/columns.
|
|
||||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
|
||||||
//
|
|
||||||
// Example:
|
|
||||||
//
|
|
||||||
// var v []struct {
|
|
||||||
// CreatedAt time.Time `json:"created_at,omitempty"`
|
|
||||||
// Count int `json:"count,omitempty"`
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// client.DocumentToken.Query().
|
|
||||||
// GroupBy(documenttoken.FieldCreatedAt).
|
|
||||||
// Aggregate(ent.Count()).
|
|
||||||
// Scan(ctx, &v)
|
|
||||||
func (dtq *DocumentTokenQuery) GroupBy(field string, fields ...string) *DocumentTokenGroupBy {
|
|
||||||
grbuild := &DocumentTokenGroupBy{config: dtq.config}
|
|
||||||
grbuild.fields = append([]string{field}, fields...)
|
|
||||||
grbuild.path = func(ctx context.Context) (prev *sql.Selector, err error) {
|
|
||||||
if err := dtq.prepareQuery(ctx); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return dtq.sqlQuery(ctx), nil
|
|
||||||
}
|
|
||||||
grbuild.label = documenttoken.Label
|
|
||||||
grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan
|
|
||||||
return grbuild
|
|
||||||
}
|
|
||||||
|
|
||||||
// Select allows the selection one or more fields/columns for the given query,
|
|
||||||
// instead of selecting all fields in the entity.
|
|
||||||
//
|
|
||||||
// Example:
|
|
||||||
//
|
|
||||||
// var v []struct {
|
|
||||||
// CreatedAt time.Time `json:"created_at,omitempty"`
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// client.DocumentToken.Query().
|
|
||||||
// Select(documenttoken.FieldCreatedAt).
|
|
||||||
// Scan(ctx, &v)
|
|
||||||
func (dtq *DocumentTokenQuery) Select(fields ...string) *DocumentTokenSelect {
|
|
||||||
dtq.fields = append(dtq.fields, fields...)
|
|
||||||
selbuild := &DocumentTokenSelect{DocumentTokenQuery: dtq}
|
|
||||||
selbuild.label = documenttoken.Label
|
|
||||||
selbuild.flds, selbuild.scan = &dtq.fields, selbuild.Scan
|
|
||||||
return selbuild
|
|
||||||
}
|
|
||||||
|
|
||||||
// Aggregate returns a DocumentTokenSelect configured with the given aggregations.
|
|
||||||
func (dtq *DocumentTokenQuery) Aggregate(fns ...AggregateFunc) *DocumentTokenSelect {
|
|
||||||
return dtq.Select().Aggregate(fns...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dtq *DocumentTokenQuery) prepareQuery(ctx context.Context) error {
|
|
||||||
for _, f := range dtq.fields {
|
|
||||||
if !documenttoken.ValidColumn(f) {
|
|
||||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if dtq.path != nil {
|
|
||||||
prev, err := dtq.path(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
dtq.sql = prev
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dtq *DocumentTokenQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*DocumentToken, error) {
|
|
||||||
var (
|
|
||||||
nodes = []*DocumentToken{}
|
|
||||||
withFKs = dtq.withFKs
|
|
||||||
_spec = dtq.querySpec()
|
|
||||||
loadedTypes = [1]bool{
|
|
||||||
dtq.withDocument != nil,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
if dtq.withDocument != nil {
|
|
||||||
withFKs = true
|
|
||||||
}
|
|
||||||
if withFKs {
|
|
||||||
_spec.Node.Columns = append(_spec.Node.Columns, documenttoken.ForeignKeys...)
|
|
||||||
}
|
|
||||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
|
||||||
return (*DocumentToken).scanValues(nil, columns)
|
|
||||||
}
|
|
||||||
_spec.Assign = func(columns []string, values []any) error {
|
|
||||||
node := &DocumentToken{config: dtq.config}
|
|
||||||
nodes = append(nodes, node)
|
|
||||||
node.Edges.loadedTypes = loadedTypes
|
|
||||||
return node.assignValues(columns, values)
|
|
||||||
}
|
|
||||||
for i := range hooks {
|
|
||||||
hooks[i](ctx, _spec)
|
|
||||||
}
|
|
||||||
if err := sqlgraph.QueryNodes(ctx, dtq.driver, _spec); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if len(nodes) == 0 {
|
|
||||||
return nodes, nil
|
|
||||||
}
|
|
||||||
if query := dtq.withDocument; query != nil {
|
|
||||||
if err := dtq.loadDocument(ctx, query, nodes, nil,
|
|
||||||
func(n *DocumentToken, e *Document) { n.Edges.Document = e }); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nodes, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dtq *DocumentTokenQuery) loadDocument(ctx context.Context, query *DocumentQuery, nodes []*DocumentToken, init func(*DocumentToken), assign func(*DocumentToken, *Document)) error {
|
|
||||||
ids := make([]uuid.UUID, 0, len(nodes))
|
|
||||||
nodeids := make(map[uuid.UUID][]*DocumentToken)
|
|
||||||
for i := range nodes {
|
|
||||||
if nodes[i].document_document_tokens == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
fk := *nodes[i].document_document_tokens
|
|
||||||
if _, ok := nodeids[fk]; !ok {
|
|
||||||
ids = append(ids, fk)
|
|
||||||
}
|
|
||||||
nodeids[fk] = append(nodeids[fk], nodes[i])
|
|
||||||
}
|
|
||||||
query.Where(document.IDIn(ids...))
|
|
||||||
neighbors, err := query.All(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
for _, n := range neighbors {
|
|
||||||
nodes, ok := nodeids[n.ID]
|
|
||||||
if !ok {
|
|
||||||
return fmt.Errorf(`unexpected foreign-key "document_document_tokens" returned %v`, n.ID)
|
|
||||||
}
|
|
||||||
for i := range nodes {
|
|
||||||
assign(nodes[i], n)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dtq *DocumentTokenQuery) sqlCount(ctx context.Context) (int, error) {
|
|
||||||
_spec := dtq.querySpec()
|
|
||||||
_spec.Node.Columns = dtq.fields
|
|
||||||
if len(dtq.fields) > 0 {
|
|
||||||
_spec.Unique = dtq.unique != nil && *dtq.unique
|
|
||||||
}
|
|
||||||
return sqlgraph.CountNodes(ctx, dtq.driver, _spec)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dtq *DocumentTokenQuery) sqlExist(ctx context.Context) (bool, error) {
|
|
||||||
switch _, err := dtq.FirstID(ctx); {
|
|
||||||
case IsNotFound(err):
|
|
||||||
return false, nil
|
|
||||||
case err != nil:
|
|
||||||
return false, fmt.Errorf("ent: check existence: %w", err)
|
|
||||||
default:
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dtq *DocumentTokenQuery) querySpec() *sqlgraph.QuerySpec {
|
|
||||||
_spec := &sqlgraph.QuerySpec{
|
|
||||||
Node: &sqlgraph.NodeSpec{
|
|
||||||
Table: documenttoken.Table,
|
|
||||||
Columns: documenttoken.Columns,
|
|
||||||
ID: &sqlgraph.FieldSpec{
|
|
||||||
Type: field.TypeUUID,
|
|
||||||
Column: documenttoken.FieldID,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
From: dtq.sql,
|
|
||||||
Unique: true,
|
|
||||||
}
|
|
||||||
if unique := dtq.unique; unique != nil {
|
|
||||||
_spec.Unique = *unique
|
|
||||||
}
|
|
||||||
if fields := dtq.fields; len(fields) > 0 {
|
|
||||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
|
||||||
_spec.Node.Columns = append(_spec.Node.Columns, documenttoken.FieldID)
|
|
||||||
for i := range fields {
|
|
||||||
if fields[i] != documenttoken.FieldID {
|
|
||||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ps := dtq.predicates; len(ps) > 0 {
|
|
||||||
_spec.Predicate = func(selector *sql.Selector) {
|
|
||||||
for i := range ps {
|
|
||||||
ps[i](selector)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if limit := dtq.limit; limit != nil {
|
|
||||||
_spec.Limit = *limit
|
|
||||||
}
|
|
||||||
if offset := dtq.offset; offset != nil {
|
|
||||||
_spec.Offset = *offset
|
|
||||||
}
|
|
||||||
if ps := dtq.order; len(ps) > 0 {
|
|
||||||
_spec.Order = func(selector *sql.Selector) {
|
|
||||||
for i := range ps {
|
|
||||||
ps[i](selector)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return _spec
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dtq *DocumentTokenQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
|
||||||
builder := sql.Dialect(dtq.driver.Dialect())
|
|
||||||
t1 := builder.Table(documenttoken.Table)
|
|
||||||
columns := dtq.fields
|
|
||||||
if len(columns) == 0 {
|
|
||||||
columns = documenttoken.Columns
|
|
||||||
}
|
|
||||||
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
|
||||||
if dtq.sql != nil {
|
|
||||||
selector = dtq.sql
|
|
||||||
selector.Select(selector.Columns(columns...)...)
|
|
||||||
}
|
|
||||||
if dtq.unique != nil && *dtq.unique {
|
|
||||||
selector.Distinct()
|
|
||||||
}
|
|
||||||
for _, p := range dtq.predicates {
|
|
||||||
p(selector)
|
|
||||||
}
|
|
||||||
for _, p := range dtq.order {
|
|
||||||
p(selector)
|
|
||||||
}
|
|
||||||
if offset := dtq.offset; offset != nil {
|
|
||||||
// limit is mandatory for offset clause. We start
|
|
||||||
// with default value, and override it below if needed.
|
|
||||||
selector.Offset(*offset).Limit(math.MaxInt32)
|
|
||||||
}
|
|
||||||
if limit := dtq.limit; limit != nil {
|
|
||||||
selector.Limit(*limit)
|
|
||||||
}
|
|
||||||
return selector
|
|
||||||
}
|
|
||||||
|
|
||||||
// DocumentTokenGroupBy is the group-by builder for DocumentToken entities.
|
|
||||||
type DocumentTokenGroupBy struct {
|
|
||||||
config
|
|
||||||
selector
|
|
||||||
fields []string
|
|
||||||
fns []AggregateFunc
|
|
||||||
// intermediate query (i.e. traversal path).
|
|
||||||
sql *sql.Selector
|
|
||||||
path func(context.Context) (*sql.Selector, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Aggregate adds the given aggregation functions to the group-by query.
|
|
||||||
func (dtgb *DocumentTokenGroupBy) Aggregate(fns ...AggregateFunc) *DocumentTokenGroupBy {
|
|
||||||
dtgb.fns = append(dtgb.fns, fns...)
|
|
||||||
return dtgb
|
|
||||||
}
|
|
||||||
|
|
||||||
// Scan applies the group-by query and scans the result into the given value.
|
|
||||||
func (dtgb *DocumentTokenGroupBy) Scan(ctx context.Context, v any) error {
|
|
||||||
query, err := dtgb.path(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
dtgb.sql = query
|
|
||||||
return dtgb.sqlScan(ctx, v)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dtgb *DocumentTokenGroupBy) sqlScan(ctx context.Context, v any) error {
|
|
||||||
for _, f := range dtgb.fields {
|
|
||||||
if !documenttoken.ValidColumn(f) {
|
|
||||||
return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
selector := dtgb.sqlQuery()
|
|
||||||
if err := selector.Err(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
rows := &sql.Rows{}
|
|
||||||
query, args := selector.Query()
|
|
||||||
if err := dtgb.driver.Query(ctx, query, args, rows); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer rows.Close()
|
|
||||||
return sql.ScanSlice(rows, v)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dtgb *DocumentTokenGroupBy) sqlQuery() *sql.Selector {
|
|
||||||
selector := dtgb.sql.Select()
|
|
||||||
aggregation := make([]string, 0, len(dtgb.fns))
|
|
||||||
for _, fn := range dtgb.fns {
|
|
||||||
aggregation = append(aggregation, fn(selector))
|
|
||||||
}
|
|
||||||
if len(selector.SelectedColumns()) == 0 {
|
|
||||||
columns := make([]string, 0, len(dtgb.fields)+len(dtgb.fns))
|
|
||||||
for _, f := range dtgb.fields {
|
|
||||||
columns = append(columns, selector.C(f))
|
|
||||||
}
|
|
||||||
columns = append(columns, aggregation...)
|
|
||||||
selector.Select(columns...)
|
|
||||||
}
|
|
||||||
return selector.GroupBy(selector.Columns(dtgb.fields...)...)
|
|
||||||
}
|
|
||||||
|
|
||||||
// DocumentTokenSelect is the builder for selecting fields of DocumentToken entities.
|
|
||||||
type DocumentTokenSelect struct {
|
|
||||||
*DocumentTokenQuery
|
|
||||||
selector
|
|
||||||
// intermediate query (i.e. traversal path).
|
|
||||||
sql *sql.Selector
|
|
||||||
}
|
|
||||||
|
|
||||||
// Aggregate adds the given aggregation functions to the selector query.
|
|
||||||
func (dts *DocumentTokenSelect) Aggregate(fns ...AggregateFunc) *DocumentTokenSelect {
|
|
||||||
dts.fns = append(dts.fns, fns...)
|
|
||||||
return dts
|
|
||||||
}
|
|
||||||
|
|
||||||
// Scan applies the selector query and scans the result into the given value.
|
|
||||||
func (dts *DocumentTokenSelect) Scan(ctx context.Context, v any) error {
|
|
||||||
if err := dts.prepareQuery(ctx); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
dts.sql = dts.DocumentTokenQuery.sqlQuery(ctx)
|
|
||||||
return dts.sqlScan(ctx, v)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dts *DocumentTokenSelect) sqlScan(ctx context.Context, v any) error {
|
|
||||||
aggregation := make([]string, 0, len(dts.fns))
|
|
||||||
for _, fn := range dts.fns {
|
|
||||||
aggregation = append(aggregation, fn(dts.sql))
|
|
||||||
}
|
|
||||||
switch n := len(*dts.selector.flds); {
|
|
||||||
case n == 0 && len(aggregation) > 0:
|
|
||||||
dts.sql.Select(aggregation...)
|
|
||||||
case n != 0 && len(aggregation) > 0:
|
|
||||||
dts.sql.AppendSelect(aggregation...)
|
|
||||||
}
|
|
||||||
rows := &sql.Rows{}
|
|
||||||
query, args := dts.sql.Query()
|
|
||||||
if err := dts.driver.Query(ctx, query, args, rows); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer rows.Close()
|
|
||||||
return sql.ScanSlice(rows, v)
|
|
||||||
}
|
|
|
@ -1,542 +0,0 @@
|
||||||
// Code generated by ent, DO NOT EDIT.
|
|
||||||
|
|
||||||
package ent
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"entgo.io/ent/dialect/sql"
|
|
||||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
||||||
"entgo.io/ent/schema/field"
|
|
||||||
"github.com/google/uuid"
|
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/document"
|
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/documenttoken"
|
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/predicate"
|
|
||||||
)
|
|
||||||
|
|
||||||
// DocumentTokenUpdate is the builder for updating DocumentToken entities.
|
|
||||||
type DocumentTokenUpdate struct {
|
|
||||||
config
|
|
||||||
hooks []Hook
|
|
||||||
mutation *DocumentTokenMutation
|
|
||||||
}
|
|
||||||
|
|
||||||
// Where appends a list predicates to the DocumentTokenUpdate builder.
|
|
||||||
func (dtu *DocumentTokenUpdate) Where(ps ...predicate.DocumentToken) *DocumentTokenUpdate {
|
|
||||||
dtu.mutation.Where(ps...)
|
|
||||||
return dtu
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetUpdatedAt sets the "updated_at" field.
|
|
||||||
func (dtu *DocumentTokenUpdate) SetUpdatedAt(t time.Time) *DocumentTokenUpdate {
|
|
||||||
dtu.mutation.SetUpdatedAt(t)
|
|
||||||
return dtu
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetToken sets the "token" field.
|
|
||||||
func (dtu *DocumentTokenUpdate) SetToken(b []byte) *DocumentTokenUpdate {
|
|
||||||
dtu.mutation.SetToken(b)
|
|
||||||
return dtu
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetUses sets the "uses" field.
|
|
||||||
func (dtu *DocumentTokenUpdate) SetUses(i int) *DocumentTokenUpdate {
|
|
||||||
dtu.mutation.ResetUses()
|
|
||||||
dtu.mutation.SetUses(i)
|
|
||||||
return dtu
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetNillableUses sets the "uses" field if the given value is not nil.
|
|
||||||
func (dtu *DocumentTokenUpdate) SetNillableUses(i *int) *DocumentTokenUpdate {
|
|
||||||
if i != nil {
|
|
||||||
dtu.SetUses(*i)
|
|
||||||
}
|
|
||||||
return dtu
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddUses adds i to the "uses" field.
|
|
||||||
func (dtu *DocumentTokenUpdate) AddUses(i int) *DocumentTokenUpdate {
|
|
||||||
dtu.mutation.AddUses(i)
|
|
||||||
return dtu
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetExpiresAt sets the "expires_at" field.
|
|
||||||
func (dtu *DocumentTokenUpdate) SetExpiresAt(t time.Time) *DocumentTokenUpdate {
|
|
||||||
dtu.mutation.SetExpiresAt(t)
|
|
||||||
return dtu
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetNillableExpiresAt sets the "expires_at" field if the given value is not nil.
|
|
||||||
func (dtu *DocumentTokenUpdate) SetNillableExpiresAt(t *time.Time) *DocumentTokenUpdate {
|
|
||||||
if t != nil {
|
|
||||||
dtu.SetExpiresAt(*t)
|
|
||||||
}
|
|
||||||
return dtu
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetDocumentID sets the "document" edge to the Document entity by ID.
|
|
||||||
func (dtu *DocumentTokenUpdate) SetDocumentID(id uuid.UUID) *DocumentTokenUpdate {
|
|
||||||
dtu.mutation.SetDocumentID(id)
|
|
||||||
return dtu
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetNillableDocumentID sets the "document" edge to the Document entity by ID if the given value is not nil.
|
|
||||||
func (dtu *DocumentTokenUpdate) SetNillableDocumentID(id *uuid.UUID) *DocumentTokenUpdate {
|
|
||||||
if id != nil {
|
|
||||||
dtu = dtu.SetDocumentID(*id)
|
|
||||||
}
|
|
||||||
return dtu
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetDocument sets the "document" edge to the Document entity.
|
|
||||||
func (dtu *DocumentTokenUpdate) SetDocument(d *Document) *DocumentTokenUpdate {
|
|
||||||
return dtu.SetDocumentID(d.ID)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mutation returns the DocumentTokenMutation object of the builder.
|
|
||||||
func (dtu *DocumentTokenUpdate) Mutation() *DocumentTokenMutation {
|
|
||||||
return dtu.mutation
|
|
||||||
}
|
|
||||||
|
|
||||||
// ClearDocument clears the "document" edge to the Document entity.
|
|
||||||
func (dtu *DocumentTokenUpdate) ClearDocument() *DocumentTokenUpdate {
|
|
||||||
dtu.mutation.ClearDocument()
|
|
||||||
return dtu
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
||||||
func (dtu *DocumentTokenUpdate) Save(ctx context.Context) (int, error) {
|
|
||||||
var (
|
|
||||||
err error
|
|
||||||
affected int
|
|
||||||
)
|
|
||||||
dtu.defaults()
|
|
||||||
if len(dtu.hooks) == 0 {
|
|
||||||
if err = dtu.check(); err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
affected, err = dtu.sqlSave(ctx)
|
|
||||||
} else {
|
|
||||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
||||||
mutation, ok := m.(*DocumentTokenMutation)
|
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
|
||||||
}
|
|
||||||
if err = dtu.check(); err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
dtu.mutation = mutation
|
|
||||||
affected, err = dtu.sqlSave(ctx)
|
|
||||||
mutation.done = true
|
|
||||||
return affected, err
|
|
||||||
})
|
|
||||||
for i := len(dtu.hooks) - 1; i >= 0; i-- {
|
|
||||||
if dtu.hooks[i] == nil {
|
|
||||||
return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
|
||||||
}
|
|
||||||
mut = dtu.hooks[i](mut)
|
|
||||||
}
|
|
||||||
if _, err := mut.Mutate(ctx, dtu.mutation); err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return affected, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// SaveX is like Save, but panics if an error occurs.
|
|
||||||
func (dtu *DocumentTokenUpdate) SaveX(ctx context.Context) int {
|
|
||||||
affected, err := dtu.Save(ctx)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return affected
|
|
||||||
}
|
|
||||||
|
|
||||||
// Exec executes the query.
|
|
||||||
func (dtu *DocumentTokenUpdate) Exec(ctx context.Context) error {
|
|
||||||
_, err := dtu.Save(ctx)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExecX is like Exec, but panics if an error occurs.
|
|
||||||
func (dtu *DocumentTokenUpdate) ExecX(ctx context.Context) {
|
|
||||||
if err := dtu.Exec(ctx); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// defaults sets the default values of the builder before save.
|
|
||||||
func (dtu *DocumentTokenUpdate) defaults() {
|
|
||||||
if _, ok := dtu.mutation.UpdatedAt(); !ok {
|
|
||||||
v := documenttoken.UpdateDefaultUpdatedAt()
|
|
||||||
dtu.mutation.SetUpdatedAt(v)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// check runs all checks and user-defined validators on the builder.
|
|
||||||
func (dtu *DocumentTokenUpdate) check() error {
|
|
||||||
if v, ok := dtu.mutation.Token(); ok {
|
|
||||||
if err := documenttoken.TokenValidator(v); err != nil {
|
|
||||||
return &ValidationError{Name: "token", err: fmt.Errorf(`ent: validator failed for field "DocumentToken.token": %w`, err)}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dtu *DocumentTokenUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|
||||||
_spec := &sqlgraph.UpdateSpec{
|
|
||||||
Node: &sqlgraph.NodeSpec{
|
|
||||||
Table: documenttoken.Table,
|
|
||||||
Columns: documenttoken.Columns,
|
|
||||||
ID: &sqlgraph.FieldSpec{
|
|
||||||
Type: field.TypeUUID,
|
|
||||||
Column: documenttoken.FieldID,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
if ps := dtu.mutation.predicates; len(ps) > 0 {
|
|
||||||
_spec.Predicate = func(selector *sql.Selector) {
|
|
||||||
for i := range ps {
|
|
||||||
ps[i](selector)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if value, ok := dtu.mutation.UpdatedAt(); ok {
|
|
||||||
_spec.SetField(documenttoken.FieldUpdatedAt, field.TypeTime, value)
|
|
||||||
}
|
|
||||||
if value, ok := dtu.mutation.Token(); ok {
|
|
||||||
_spec.SetField(documenttoken.FieldToken, field.TypeBytes, value)
|
|
||||||
}
|
|
||||||
if value, ok := dtu.mutation.Uses(); ok {
|
|
||||||
_spec.SetField(documenttoken.FieldUses, field.TypeInt, value)
|
|
||||||
}
|
|
||||||
if value, ok := dtu.mutation.AddedUses(); ok {
|
|
||||||
_spec.AddField(documenttoken.FieldUses, field.TypeInt, value)
|
|
||||||
}
|
|
||||||
if value, ok := dtu.mutation.ExpiresAt(); ok {
|
|
||||||
_spec.SetField(documenttoken.FieldExpiresAt, field.TypeTime, value)
|
|
||||||
}
|
|
||||||
if dtu.mutation.DocumentCleared() {
|
|
||||||
edge := &sqlgraph.EdgeSpec{
|
|
||||||
Rel: sqlgraph.M2O,
|
|
||||||
Inverse: true,
|
|
||||||
Table: documenttoken.DocumentTable,
|
|
||||||
Columns: []string{documenttoken.DocumentColumn},
|
|
||||||
Bidi: false,
|
|
||||||
Target: &sqlgraph.EdgeTarget{
|
|
||||||
IDSpec: &sqlgraph.FieldSpec{
|
|
||||||
Type: field.TypeUUID,
|
|
||||||
Column: document.FieldID,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
||||||
}
|
|
||||||
if nodes := dtu.mutation.DocumentIDs(); len(nodes) > 0 {
|
|
||||||
edge := &sqlgraph.EdgeSpec{
|
|
||||||
Rel: sqlgraph.M2O,
|
|
||||||
Inverse: true,
|
|
||||||
Table: documenttoken.DocumentTable,
|
|
||||||
Columns: []string{documenttoken.DocumentColumn},
|
|
||||||
Bidi: false,
|
|
||||||
Target: &sqlgraph.EdgeTarget{
|
|
||||||
IDSpec: &sqlgraph.FieldSpec{
|
|
||||||
Type: field.TypeUUID,
|
|
||||||
Column: document.FieldID,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, k := range nodes {
|
|
||||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
||||||
}
|
|
||||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
||||||
}
|
|
||||||
if n, err = sqlgraph.UpdateNodes(ctx, dtu.driver, _spec); err != nil {
|
|
||||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
||||||
err = &NotFoundError{documenttoken.Label}
|
|
||||||
} else if sqlgraph.IsConstraintError(err) {
|
|
||||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
||||||
}
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
return n, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// DocumentTokenUpdateOne is the builder for updating a single DocumentToken entity.
|
|
||||||
type DocumentTokenUpdateOne struct {
|
|
||||||
config
|
|
||||||
fields []string
|
|
||||||
hooks []Hook
|
|
||||||
mutation *DocumentTokenMutation
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetUpdatedAt sets the "updated_at" field.
|
|
||||||
func (dtuo *DocumentTokenUpdateOne) SetUpdatedAt(t time.Time) *DocumentTokenUpdateOne {
|
|
||||||
dtuo.mutation.SetUpdatedAt(t)
|
|
||||||
return dtuo
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetToken sets the "token" field.
|
|
||||||
func (dtuo *DocumentTokenUpdateOne) SetToken(b []byte) *DocumentTokenUpdateOne {
|
|
||||||
dtuo.mutation.SetToken(b)
|
|
||||||
return dtuo
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetUses sets the "uses" field.
|
|
||||||
func (dtuo *DocumentTokenUpdateOne) SetUses(i int) *DocumentTokenUpdateOne {
|
|
||||||
dtuo.mutation.ResetUses()
|
|
||||||
dtuo.mutation.SetUses(i)
|
|
||||||
return dtuo
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetNillableUses sets the "uses" field if the given value is not nil.
|
|
||||||
func (dtuo *DocumentTokenUpdateOne) SetNillableUses(i *int) *DocumentTokenUpdateOne {
|
|
||||||
if i != nil {
|
|
||||||
dtuo.SetUses(*i)
|
|
||||||
}
|
|
||||||
return dtuo
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddUses adds i to the "uses" field.
|
|
||||||
func (dtuo *DocumentTokenUpdateOne) AddUses(i int) *DocumentTokenUpdateOne {
|
|
||||||
dtuo.mutation.AddUses(i)
|
|
||||||
return dtuo
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetExpiresAt sets the "expires_at" field.
|
|
||||||
func (dtuo *DocumentTokenUpdateOne) SetExpiresAt(t time.Time) *DocumentTokenUpdateOne {
|
|
||||||
dtuo.mutation.SetExpiresAt(t)
|
|
||||||
return dtuo
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetNillableExpiresAt sets the "expires_at" field if the given value is not nil.
|
|
||||||
func (dtuo *DocumentTokenUpdateOne) SetNillableExpiresAt(t *time.Time) *DocumentTokenUpdateOne {
|
|
||||||
if t != nil {
|
|
||||||
dtuo.SetExpiresAt(*t)
|
|
||||||
}
|
|
||||||
return dtuo
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetDocumentID sets the "document" edge to the Document entity by ID.
|
|
||||||
func (dtuo *DocumentTokenUpdateOne) SetDocumentID(id uuid.UUID) *DocumentTokenUpdateOne {
|
|
||||||
dtuo.mutation.SetDocumentID(id)
|
|
||||||
return dtuo
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetNillableDocumentID sets the "document" edge to the Document entity by ID if the given value is not nil.
|
|
||||||
func (dtuo *DocumentTokenUpdateOne) SetNillableDocumentID(id *uuid.UUID) *DocumentTokenUpdateOne {
|
|
||||||
if id != nil {
|
|
||||||
dtuo = dtuo.SetDocumentID(*id)
|
|
||||||
}
|
|
||||||
return dtuo
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetDocument sets the "document" edge to the Document entity.
|
|
||||||
func (dtuo *DocumentTokenUpdateOne) SetDocument(d *Document) *DocumentTokenUpdateOne {
|
|
||||||
return dtuo.SetDocumentID(d.ID)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mutation returns the DocumentTokenMutation object of the builder.
|
|
||||||
func (dtuo *DocumentTokenUpdateOne) Mutation() *DocumentTokenMutation {
|
|
||||||
return dtuo.mutation
|
|
||||||
}
|
|
||||||
|
|
||||||
// ClearDocument clears the "document" edge to the Document entity.
|
|
||||||
func (dtuo *DocumentTokenUpdateOne) ClearDocument() *DocumentTokenUpdateOne {
|
|
||||||
dtuo.mutation.ClearDocument()
|
|
||||||
return dtuo
|
|
||||||
}
|
|
||||||
|
|
||||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
|
||||||
// The default is selecting all fields defined in the entity schema.
|
|
||||||
func (dtuo *DocumentTokenUpdateOne) Select(field string, fields ...string) *DocumentTokenUpdateOne {
|
|
||||||
dtuo.fields = append([]string{field}, fields...)
|
|
||||||
return dtuo
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save executes the query and returns the updated DocumentToken entity.
|
|
||||||
func (dtuo *DocumentTokenUpdateOne) Save(ctx context.Context) (*DocumentToken, error) {
|
|
||||||
var (
|
|
||||||
err error
|
|
||||||
node *DocumentToken
|
|
||||||
)
|
|
||||||
dtuo.defaults()
|
|
||||||
if len(dtuo.hooks) == 0 {
|
|
||||||
if err = dtuo.check(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
node, err = dtuo.sqlSave(ctx)
|
|
||||||
} else {
|
|
||||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
||||||
mutation, ok := m.(*DocumentTokenMutation)
|
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
|
||||||
}
|
|
||||||
if err = dtuo.check(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
dtuo.mutation = mutation
|
|
||||||
node, err = dtuo.sqlSave(ctx)
|
|
||||||
mutation.done = true
|
|
||||||
return node, err
|
|
||||||
})
|
|
||||||
for i := len(dtuo.hooks) - 1; i >= 0; i-- {
|
|
||||||
if dtuo.hooks[i] == nil {
|
|
||||||
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
|
||||||
}
|
|
||||||
mut = dtuo.hooks[i](mut)
|
|
||||||
}
|
|
||||||
v, err := mut.Mutate(ctx, dtuo.mutation)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
nv, ok := v.(*DocumentToken)
|
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("unexpected node type %T returned from DocumentTokenMutation", v)
|
|
||||||
}
|
|
||||||
node = nv
|
|
||||||
}
|
|
||||||
return node, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// SaveX is like Save, but panics if an error occurs.
|
|
||||||
func (dtuo *DocumentTokenUpdateOne) SaveX(ctx context.Context) *DocumentToken {
|
|
||||||
node, err := dtuo.Save(ctx)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return node
|
|
||||||
}
|
|
||||||
|
|
||||||
// Exec executes the query on the entity.
|
|
||||||
func (dtuo *DocumentTokenUpdateOne) Exec(ctx context.Context) error {
|
|
||||||
_, err := dtuo.Save(ctx)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExecX is like Exec, but panics if an error occurs.
|
|
||||||
func (dtuo *DocumentTokenUpdateOne) ExecX(ctx context.Context) {
|
|
||||||
if err := dtuo.Exec(ctx); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// defaults sets the default values of the builder before save.
|
|
||||||
func (dtuo *DocumentTokenUpdateOne) defaults() {
|
|
||||||
if _, ok := dtuo.mutation.UpdatedAt(); !ok {
|
|
||||||
v := documenttoken.UpdateDefaultUpdatedAt()
|
|
||||||
dtuo.mutation.SetUpdatedAt(v)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// check runs all checks and user-defined validators on the builder.
|
|
||||||
func (dtuo *DocumentTokenUpdateOne) check() error {
|
|
||||||
if v, ok := dtuo.mutation.Token(); ok {
|
|
||||||
if err := documenttoken.TokenValidator(v); err != nil {
|
|
||||||
return &ValidationError{Name: "token", err: fmt.Errorf(`ent: validator failed for field "DocumentToken.token": %w`, err)}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dtuo *DocumentTokenUpdateOne) sqlSave(ctx context.Context) (_node *DocumentToken, err error) {
|
|
||||||
_spec := &sqlgraph.UpdateSpec{
|
|
||||||
Node: &sqlgraph.NodeSpec{
|
|
||||||
Table: documenttoken.Table,
|
|
||||||
Columns: documenttoken.Columns,
|
|
||||||
ID: &sqlgraph.FieldSpec{
|
|
||||||
Type: field.TypeUUID,
|
|
||||||
Column: documenttoken.FieldID,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
id, ok := dtuo.mutation.ID()
|
|
||||||
if !ok {
|
|
||||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "DocumentToken.id" for update`)}
|
|
||||||
}
|
|
||||||
_spec.Node.ID.Value = id
|
|
||||||
if fields := dtuo.fields; len(fields) > 0 {
|
|
||||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
|
||||||
_spec.Node.Columns = append(_spec.Node.Columns, documenttoken.FieldID)
|
|
||||||
for _, f := range fields {
|
|
||||||
if !documenttoken.ValidColumn(f) {
|
|
||||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
||||||
}
|
|
||||||
if f != documenttoken.FieldID {
|
|
||||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ps := dtuo.mutation.predicates; len(ps) > 0 {
|
|
||||||
_spec.Predicate = func(selector *sql.Selector) {
|
|
||||||
for i := range ps {
|
|
||||||
ps[i](selector)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if value, ok := dtuo.mutation.UpdatedAt(); ok {
|
|
||||||
_spec.SetField(documenttoken.FieldUpdatedAt, field.TypeTime, value)
|
|
||||||
}
|
|
||||||
if value, ok := dtuo.mutation.Token(); ok {
|
|
||||||
_spec.SetField(documenttoken.FieldToken, field.TypeBytes, value)
|
|
||||||
}
|
|
||||||
if value, ok := dtuo.mutation.Uses(); ok {
|
|
||||||
_spec.SetField(documenttoken.FieldUses, field.TypeInt, value)
|
|
||||||
}
|
|
||||||
if value, ok := dtuo.mutation.AddedUses(); ok {
|
|
||||||
_spec.AddField(documenttoken.FieldUses, field.TypeInt, value)
|
|
||||||
}
|
|
||||||
if value, ok := dtuo.mutation.ExpiresAt(); ok {
|
|
||||||
_spec.SetField(documenttoken.FieldExpiresAt, field.TypeTime, value)
|
|
||||||
}
|
|
||||||
if dtuo.mutation.DocumentCleared() {
|
|
||||||
edge := &sqlgraph.EdgeSpec{
|
|
||||||
Rel: sqlgraph.M2O,
|
|
||||||
Inverse: true,
|
|
||||||
Table: documenttoken.DocumentTable,
|
|
||||||
Columns: []string{documenttoken.DocumentColumn},
|
|
||||||
Bidi: false,
|
|
||||||
Target: &sqlgraph.EdgeTarget{
|
|
||||||
IDSpec: &sqlgraph.FieldSpec{
|
|
||||||
Type: field.TypeUUID,
|
|
||||||
Column: document.FieldID,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
|
||||||
}
|
|
||||||
if nodes := dtuo.mutation.DocumentIDs(); len(nodes) > 0 {
|
|
||||||
edge := &sqlgraph.EdgeSpec{
|
|
||||||
Rel: sqlgraph.M2O,
|
|
||||||
Inverse: true,
|
|
||||||
Table: documenttoken.DocumentTable,
|
|
||||||
Columns: []string{documenttoken.DocumentColumn},
|
|
||||||
Bidi: false,
|
|
||||||
Target: &sqlgraph.EdgeTarget{
|
|
||||||
IDSpec: &sqlgraph.FieldSpec{
|
|
||||||
Type: field.TypeUUID,
|
|
||||||
Column: document.FieldID,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, k := range nodes {
|
|
||||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
||||||
}
|
|
||||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
|
||||||
}
|
|
||||||
_node = &DocumentToken{config: dtuo.config}
|
|
||||||
_spec.Assign = _node.assignValues
|
|
||||||
_spec.ScanValues = _node.scanValues
|
|
||||||
if err = sqlgraph.UpdateNode(ctx, dtuo.driver, _spec); err != nil {
|
|
||||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
||||||
err = &NotFoundError{documenttoken.Label}
|
|
||||||
} else if sqlgraph.IsConstraintError(err) {
|
|
||||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
||||||
}
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return _node, nil
|
|
||||||
}
|
|
|
@ -14,13 +14,13 @@ import (
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/authroles"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/authroles"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/authtokens"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/authtokens"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/document"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/document"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/documenttoken"
|
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/group"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/group"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/groupinvitationtoken"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/groupinvitationtoken"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/item"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/item"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/itemfield"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/itemfield"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/label"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/label"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/location"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/location"
|
||||||
|
"github.com/hay-kot/homebox/backend/internal/data/ent/maintenanceentry"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/user"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/user"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -46,13 +46,13 @@ func columnChecker(table string) func(string) error {
|
||||||
authroles.Table: authroles.ValidColumn,
|
authroles.Table: authroles.ValidColumn,
|
||||||
authtokens.Table: authtokens.ValidColumn,
|
authtokens.Table: authtokens.ValidColumn,
|
||||||
document.Table: document.ValidColumn,
|
document.Table: document.ValidColumn,
|
||||||
documenttoken.Table: documenttoken.ValidColumn,
|
|
||||||
group.Table: group.ValidColumn,
|
group.Table: group.ValidColumn,
|
||||||
groupinvitationtoken.Table: groupinvitationtoken.ValidColumn,
|
groupinvitationtoken.Table: groupinvitationtoken.ValidColumn,
|
||||||
item.Table: item.ValidColumn,
|
item.Table: item.ValidColumn,
|
||||||
itemfield.Table: itemfield.ValidColumn,
|
itemfield.Table: itemfield.ValidColumn,
|
||||||
label.Table: label.ValidColumn,
|
label.Table: label.ValidColumn,
|
||||||
location.Table: location.ValidColumn,
|
location.Table: location.ValidColumn,
|
||||||
|
maintenanceentry.Table: maintenanceentry.ValidColumn,
|
||||||
user.Table: user.ValidColumn,
|
user.Table: user.ValidColumn,
|
||||||
}
|
}
|
||||||
check, ok := checks[table]
|
check, ok := checks[table]
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
package ent
|
package ent
|
||||||
|
|
||||||
//go:generate go run -mod=mod entgo.io/ent/cmd/ent generate --feature sql/versioned-migration ./schema
|
//go:generate go run -mod=mod entgo.io/ent/cmd/ent generate --feature sql/versioned-migration ./schema --template=./schema/templates/has_id.tmpl
|
||||||
|
|
|
@ -8,6 +8,10 @@ func (a *Attachment) GetID() uuid.UUID {
|
||||||
return a.ID
|
return a.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ar *AuthRoles) GetID() int {
|
||||||
|
return ar.ID
|
||||||
|
}
|
||||||
|
|
||||||
func (at *AuthTokens) GetID() uuid.UUID {
|
func (at *AuthTokens) GetID() uuid.UUID {
|
||||||
return at.ID
|
return at.ID
|
||||||
}
|
}
|
||||||
|
@ -16,14 +20,14 @@ func (d *Document) GetID() uuid.UUID {
|
||||||
return d.ID
|
return d.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dt *DocumentToken) GetID() uuid.UUID {
|
|
||||||
return dt.ID
|
|
||||||
}
|
|
||||||
|
|
||||||
func (gr *Group) GetID() uuid.UUID {
|
func (gr *Group) GetID() uuid.UUID {
|
||||||
return gr.ID
|
return gr.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (git *GroupInvitationToken) GetID() uuid.UUID {
|
||||||
|
return git.ID
|
||||||
|
}
|
||||||
|
|
||||||
func (i *Item) GetID() uuid.UUID {
|
func (i *Item) GetID() uuid.UUID {
|
||||||
return i.ID
|
return i.ID
|
||||||
}
|
}
|
||||||
|
@ -40,6 +44,10 @@ func (l *Location) GetID() uuid.UUID {
|
||||||
return l.ID
|
return l.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (me *MaintenanceEntry) GetID() uuid.UUID {
|
||||||
|
return me.ID
|
||||||
|
}
|
||||||
|
|
||||||
func (u *User) GetID() uuid.UUID {
|
func (u *User) GetID() uuid.UUID {
|
||||||
return u.ID
|
return u.ID
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,19 +61,6 @@ func (f DocumentFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, er
|
||||||
return f(ctx, mv)
|
return f(ctx, mv)
|
||||||
}
|
}
|
||||||
|
|
||||||
// The DocumentTokenFunc type is an adapter to allow the use of ordinary
|
|
||||||
// function as DocumentToken mutator.
|
|
||||||
type DocumentTokenFunc func(context.Context, *ent.DocumentTokenMutation) (ent.Value, error)
|
|
||||||
|
|
||||||
// Mutate calls f(ctx, m).
|
|
||||||
func (f DocumentTokenFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
|
||||||
mv, ok := m.(*ent.DocumentTokenMutation)
|
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.DocumentTokenMutation", m)
|
|
||||||
}
|
|
||||||
return f(ctx, mv)
|
|
||||||
}
|
|
||||||
|
|
||||||
// The GroupFunc type is an adapter to allow the use of ordinary
|
// The GroupFunc type is an adapter to allow the use of ordinary
|
||||||
// function as Group mutator.
|
// function as Group mutator.
|
||||||
type GroupFunc func(context.Context, *ent.GroupMutation) (ent.Value, error)
|
type GroupFunc func(context.Context, *ent.GroupMutation) (ent.Value, error)
|
||||||
|
@ -152,6 +139,19 @@ func (f LocationFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, er
|
||||||
return f(ctx, mv)
|
return f(ctx, mv)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The MaintenanceEntryFunc type is an adapter to allow the use of ordinary
|
||||||
|
// function as MaintenanceEntry mutator.
|
||||||
|
type MaintenanceEntryFunc func(context.Context, *ent.MaintenanceEntryMutation) (ent.Value, error)
|
||||||
|
|
||||||
|
// Mutate calls f(ctx, m).
|
||||||
|
func (f MaintenanceEntryFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||||
|
mv, ok := m.(*ent.MaintenanceEntryMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.MaintenanceEntryMutation", m)
|
||||||
|
}
|
||||||
|
return f(ctx, mv)
|
||||||
|
}
|
||||||
|
|
||||||
// The UserFunc type is an adapter to allow the use of ordinary
|
// The UserFunc type is an adapter to allow the use of ordinary
|
||||||
// function as User mutator.
|
// function as User mutator.
|
||||||
type UserFunc func(context.Context, *ent.UserMutation) (ent.Value, error)
|
type UserFunc func(context.Context, *ent.UserMutation) (ent.Value, error)
|
||||||
|
|
|
@ -87,11 +87,13 @@ type ItemEdges struct {
|
||||||
Location *Location `json:"location,omitempty"`
|
Location *Location `json:"location,omitempty"`
|
||||||
// Fields holds the value of the fields edge.
|
// Fields holds the value of the fields edge.
|
||||||
Fields []*ItemField `json:"fields,omitempty"`
|
Fields []*ItemField `json:"fields,omitempty"`
|
||||||
|
// MaintenanceEntries holds the value of the maintenance_entries edge.
|
||||||
|
MaintenanceEntries []*MaintenanceEntry `json:"maintenance_entries,omitempty"`
|
||||||
// Attachments holds the value of the attachments edge.
|
// Attachments holds the value of the attachments edge.
|
||||||
Attachments []*Attachment `json:"attachments,omitempty"`
|
Attachments []*Attachment `json:"attachments,omitempty"`
|
||||||
// loadedTypes holds the information for reporting if a
|
// loadedTypes holds the information for reporting if a
|
||||||
// type was loaded (or requested) in eager-loading or not.
|
// type was loaded (or requested) in eager-loading or not.
|
||||||
loadedTypes [7]bool
|
loadedTypes [8]bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParentOrErr returns the Parent value or an error if the edge
|
// ParentOrErr returns the Parent value or an error if the edge
|
||||||
|
@ -160,10 +162,19 @@ func (e ItemEdges) FieldsOrErr() ([]*ItemField, error) {
|
||||||
return nil, &NotLoadedError{edge: "fields"}
|
return nil, &NotLoadedError{edge: "fields"}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MaintenanceEntriesOrErr returns the MaintenanceEntries value or an error if the edge
|
||||||
|
// was not loaded in eager-loading.
|
||||||
|
func (e ItemEdges) MaintenanceEntriesOrErr() ([]*MaintenanceEntry, error) {
|
||||||
|
if e.loadedTypes[6] {
|
||||||
|
return e.MaintenanceEntries, nil
|
||||||
|
}
|
||||||
|
return nil, &NotLoadedError{edge: "maintenance_entries"}
|
||||||
|
}
|
||||||
|
|
||||||
// AttachmentsOrErr returns the Attachments value or an error if the edge
|
// AttachmentsOrErr returns the Attachments value or an error if the edge
|
||||||
// was not loaded in eager-loading.
|
// was not loaded in eager-loading.
|
||||||
func (e ItemEdges) AttachmentsOrErr() ([]*Attachment, error) {
|
func (e ItemEdges) AttachmentsOrErr() ([]*Attachment, error) {
|
||||||
if e.loadedTypes[6] {
|
if e.loadedTypes[7] {
|
||||||
return e.Attachments, nil
|
return e.Attachments, nil
|
||||||
}
|
}
|
||||||
return nil, &NotLoadedError{edge: "attachments"}
|
return nil, &NotLoadedError{edge: "attachments"}
|
||||||
|
@ -407,6 +418,11 @@ func (i *Item) QueryFields() *ItemFieldQuery {
|
||||||
return (&ItemClient{config: i.config}).QueryFields(i)
|
return (&ItemClient{config: i.config}).QueryFields(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// QueryMaintenanceEntries queries the "maintenance_entries" edge of the Item entity.
|
||||||
|
func (i *Item) QueryMaintenanceEntries() *MaintenanceEntryQuery {
|
||||||
|
return (&ItemClient{config: i.config}).QueryMaintenanceEntries(i)
|
||||||
|
}
|
||||||
|
|
||||||
// QueryAttachments queries the "attachments" edge of the Item entity.
|
// QueryAttachments queries the "attachments" edge of the Item entity.
|
||||||
func (i *Item) QueryAttachments() *AttachmentQuery {
|
func (i *Item) QueryAttachments() *AttachmentQuery {
|
||||||
return (&ItemClient{config: i.config}).QueryAttachments(i)
|
return (&ItemClient{config: i.config}).QueryAttachments(i)
|
||||||
|
|
|
@ -71,6 +71,8 @@ const (
|
||||||
EdgeLocation = "location"
|
EdgeLocation = "location"
|
||||||
// EdgeFields holds the string denoting the fields edge name in mutations.
|
// EdgeFields holds the string denoting the fields edge name in mutations.
|
||||||
EdgeFields = "fields"
|
EdgeFields = "fields"
|
||||||
|
// EdgeMaintenanceEntries holds the string denoting the maintenance_entries edge name in mutations.
|
||||||
|
EdgeMaintenanceEntries = "maintenance_entries"
|
||||||
// EdgeAttachments holds the string denoting the attachments edge name in mutations.
|
// EdgeAttachments holds the string denoting the attachments edge name in mutations.
|
||||||
EdgeAttachments = "attachments"
|
EdgeAttachments = "attachments"
|
||||||
// Table holds the table name of the item in the database.
|
// Table holds the table name of the item in the database.
|
||||||
|
@ -109,6 +111,13 @@ const (
|
||||||
FieldsInverseTable = "item_fields"
|
FieldsInverseTable = "item_fields"
|
||||||
// FieldsColumn is the table column denoting the fields relation/edge.
|
// FieldsColumn is the table column denoting the fields relation/edge.
|
||||||
FieldsColumn = "item_fields"
|
FieldsColumn = "item_fields"
|
||||||
|
// MaintenanceEntriesTable is the table that holds the maintenance_entries relation/edge.
|
||||||
|
MaintenanceEntriesTable = "maintenance_entries"
|
||||||
|
// MaintenanceEntriesInverseTable is the table name for the MaintenanceEntry entity.
|
||||||
|
// It exists in this package in order to avoid circular dependency with the "maintenanceentry" package.
|
||||||
|
MaintenanceEntriesInverseTable = "maintenance_entries"
|
||||||
|
// MaintenanceEntriesColumn is the table column denoting the maintenance_entries relation/edge.
|
||||||
|
MaintenanceEntriesColumn = "item_id"
|
||||||
// AttachmentsTable is the table that holds the attachments relation/edge.
|
// AttachmentsTable is the table that holds the attachments relation/edge.
|
||||||
AttachmentsTable = "attachments"
|
AttachmentsTable = "attachments"
|
||||||
// AttachmentsInverseTable is the table name for the Attachment entity.
|
// AttachmentsInverseTable is the table name for the Attachment entity.
|
||||||
|
|
|
@ -2300,6 +2300,34 @@ func HasFieldsWith(preds ...predicate.ItemField) predicate.Item {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HasMaintenanceEntries applies the HasEdge predicate on the "maintenance_entries" edge.
|
||||||
|
func HasMaintenanceEntries() predicate.Item {
|
||||||
|
return predicate.Item(func(s *sql.Selector) {
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.To(MaintenanceEntriesTable, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2M, false, MaintenanceEntriesTable, MaintenanceEntriesColumn),
|
||||||
|
)
|
||||||
|
sqlgraph.HasNeighbors(s, step)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasMaintenanceEntriesWith applies the HasEdge predicate on the "maintenance_entries" edge with a given conditions (other predicates).
|
||||||
|
func HasMaintenanceEntriesWith(preds ...predicate.MaintenanceEntry) predicate.Item {
|
||||||
|
return predicate.Item(func(s *sql.Selector) {
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.To(MaintenanceEntriesInverseTable, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2M, false, MaintenanceEntriesTable, MaintenanceEntriesColumn),
|
||||||
|
)
|
||||||
|
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||||
|
for _, p := range preds {
|
||||||
|
p(s)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// HasAttachments applies the HasEdge predicate on the "attachments" edge.
|
// HasAttachments applies the HasEdge predicate on the "attachments" edge.
|
||||||
func HasAttachments() predicate.Item {
|
func HasAttachments() predicate.Item {
|
||||||
return predicate.Item(func(s *sql.Selector) {
|
return predicate.Item(func(s *sql.Selector) {
|
||||||
|
|
|
@ -17,6 +17,7 @@ import (
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/itemfield"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/itemfield"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/label"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/label"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/location"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/location"
|
||||||
|
"github.com/hay-kot/homebox/backend/internal/data/ent/maintenanceentry"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ItemCreate is the builder for creating a Item entity.
|
// ItemCreate is the builder for creating a Item entity.
|
||||||
|
@ -448,6 +449,21 @@ func (ic *ItemCreate) AddFields(i ...*ItemField) *ItemCreate {
|
||||||
return ic.AddFieldIDs(ids...)
|
return ic.AddFieldIDs(ids...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddMaintenanceEntryIDs adds the "maintenance_entries" edge to the MaintenanceEntry entity by IDs.
|
||||||
|
func (ic *ItemCreate) AddMaintenanceEntryIDs(ids ...uuid.UUID) *ItemCreate {
|
||||||
|
ic.mutation.AddMaintenanceEntryIDs(ids...)
|
||||||
|
return ic
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddMaintenanceEntries adds the "maintenance_entries" edges to the MaintenanceEntry entity.
|
||||||
|
func (ic *ItemCreate) AddMaintenanceEntries(m ...*MaintenanceEntry) *ItemCreate {
|
||||||
|
ids := make([]uuid.UUID, len(m))
|
||||||
|
for i := range m {
|
||||||
|
ids[i] = m[i].ID
|
||||||
|
}
|
||||||
|
return ic.AddMaintenanceEntryIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
// AddAttachmentIDs adds the "attachments" edge to the Attachment entity by IDs.
|
// AddAttachmentIDs adds the "attachments" edge to the Attachment entity by IDs.
|
||||||
func (ic *ItemCreate) AddAttachmentIDs(ids ...uuid.UUID) *ItemCreate {
|
func (ic *ItemCreate) AddAttachmentIDs(ids ...uuid.UUID) *ItemCreate {
|
||||||
ic.mutation.AddAttachmentIDs(ids...)
|
ic.mutation.AddAttachmentIDs(ids...)
|
||||||
|
@ -907,6 +923,25 @@ func (ic *ItemCreate) createSpec() (*Item, *sqlgraph.CreateSpec) {
|
||||||
}
|
}
|
||||||
_spec.Edges = append(_spec.Edges, edge)
|
_spec.Edges = append(_spec.Edges, edge)
|
||||||
}
|
}
|
||||||
|
if nodes := ic.mutation.MaintenanceEntriesIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: item.MaintenanceEntriesTable,
|
||||||
|
Columns: []string{item.MaintenanceEntriesColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeUUID,
|
||||||
|
Column: maintenanceentry.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges = append(_spec.Edges, edge)
|
||||||
|
}
|
||||||
if nodes := ic.mutation.AttachmentsIDs(); len(nodes) > 0 {
|
if nodes := ic.mutation.AttachmentsIDs(); len(nodes) > 0 {
|
||||||
edge := &sqlgraph.EdgeSpec{
|
edge := &sqlgraph.EdgeSpec{
|
||||||
Rel: sqlgraph.O2M,
|
Rel: sqlgraph.O2M,
|
||||||
|
|
|
@ -18,26 +18,28 @@ import (
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/itemfield"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/itemfield"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/label"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/label"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/location"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/location"
|
||||||
|
"github.com/hay-kot/homebox/backend/internal/data/ent/maintenanceentry"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/predicate"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/predicate"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ItemQuery is the builder for querying Item entities.
|
// ItemQuery is the builder for querying Item entities.
|
||||||
type ItemQuery struct {
|
type ItemQuery struct {
|
||||||
config
|
config
|
||||||
limit *int
|
limit *int
|
||||||
offset *int
|
offset *int
|
||||||
unique *bool
|
unique *bool
|
||||||
order []OrderFunc
|
order []OrderFunc
|
||||||
fields []string
|
fields []string
|
||||||
predicates []predicate.Item
|
predicates []predicate.Item
|
||||||
withParent *ItemQuery
|
withParent *ItemQuery
|
||||||
withChildren *ItemQuery
|
withChildren *ItemQuery
|
||||||
withGroup *GroupQuery
|
withGroup *GroupQuery
|
||||||
withLabel *LabelQuery
|
withLabel *LabelQuery
|
||||||
withLocation *LocationQuery
|
withLocation *LocationQuery
|
||||||
withFields *ItemFieldQuery
|
withFields *ItemFieldQuery
|
||||||
withAttachments *AttachmentQuery
|
withMaintenanceEntries *MaintenanceEntryQuery
|
||||||
withFKs bool
|
withAttachments *AttachmentQuery
|
||||||
|
withFKs bool
|
||||||
// intermediate query (i.e. traversal path).
|
// intermediate query (i.e. traversal path).
|
||||||
sql *sql.Selector
|
sql *sql.Selector
|
||||||
path func(context.Context) (*sql.Selector, error)
|
path func(context.Context) (*sql.Selector, error)
|
||||||
|
@ -206,6 +208,28 @@ func (iq *ItemQuery) QueryFields() *ItemFieldQuery {
|
||||||
return query
|
return query
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// QueryMaintenanceEntries chains the current query on the "maintenance_entries" edge.
|
||||||
|
func (iq *ItemQuery) QueryMaintenanceEntries() *MaintenanceEntryQuery {
|
||||||
|
query := &MaintenanceEntryQuery{config: iq.config}
|
||||||
|
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||||
|
if err := iq.prepareQuery(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
selector := iq.sqlQuery(ctx)
|
||||||
|
if err := selector.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(item.Table, item.FieldID, selector),
|
||||||
|
sqlgraph.To(maintenanceentry.Table, maintenanceentry.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2M, false, item.MaintenanceEntriesTable, item.MaintenanceEntriesColumn),
|
||||||
|
)
|
||||||
|
fromU = sqlgraph.SetNeighbors(iq.driver.Dialect(), step)
|
||||||
|
return fromU, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
// QueryAttachments chains the current query on the "attachments" edge.
|
// QueryAttachments chains the current query on the "attachments" edge.
|
||||||
func (iq *ItemQuery) QueryAttachments() *AttachmentQuery {
|
func (iq *ItemQuery) QueryAttachments() *AttachmentQuery {
|
||||||
query := &AttachmentQuery{config: iq.config}
|
query := &AttachmentQuery{config: iq.config}
|
||||||
|
@ -404,18 +428,19 @@ func (iq *ItemQuery) Clone() *ItemQuery {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return &ItemQuery{
|
return &ItemQuery{
|
||||||
config: iq.config,
|
config: iq.config,
|
||||||
limit: iq.limit,
|
limit: iq.limit,
|
||||||
offset: iq.offset,
|
offset: iq.offset,
|
||||||
order: append([]OrderFunc{}, iq.order...),
|
order: append([]OrderFunc{}, iq.order...),
|
||||||
predicates: append([]predicate.Item{}, iq.predicates...),
|
predicates: append([]predicate.Item{}, iq.predicates...),
|
||||||
withParent: iq.withParent.Clone(),
|
withParent: iq.withParent.Clone(),
|
||||||
withChildren: iq.withChildren.Clone(),
|
withChildren: iq.withChildren.Clone(),
|
||||||
withGroup: iq.withGroup.Clone(),
|
withGroup: iq.withGroup.Clone(),
|
||||||
withLabel: iq.withLabel.Clone(),
|
withLabel: iq.withLabel.Clone(),
|
||||||
withLocation: iq.withLocation.Clone(),
|
withLocation: iq.withLocation.Clone(),
|
||||||
withFields: iq.withFields.Clone(),
|
withFields: iq.withFields.Clone(),
|
||||||
withAttachments: iq.withAttachments.Clone(),
|
withMaintenanceEntries: iq.withMaintenanceEntries.Clone(),
|
||||||
|
withAttachments: iq.withAttachments.Clone(),
|
||||||
// clone intermediate query.
|
// clone intermediate query.
|
||||||
sql: iq.sql.Clone(),
|
sql: iq.sql.Clone(),
|
||||||
path: iq.path,
|
path: iq.path,
|
||||||
|
@ -489,6 +514,17 @@ func (iq *ItemQuery) WithFields(opts ...func(*ItemFieldQuery)) *ItemQuery {
|
||||||
return iq
|
return iq
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithMaintenanceEntries tells the query-builder to eager-load the nodes that are connected to
|
||||||
|
// the "maintenance_entries" edge. The optional arguments are used to configure the query builder of the edge.
|
||||||
|
func (iq *ItemQuery) WithMaintenanceEntries(opts ...func(*MaintenanceEntryQuery)) *ItemQuery {
|
||||||
|
query := &MaintenanceEntryQuery{config: iq.config}
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(query)
|
||||||
|
}
|
||||||
|
iq.withMaintenanceEntries = query
|
||||||
|
return iq
|
||||||
|
}
|
||||||
|
|
||||||
// WithAttachments tells the query-builder to eager-load the nodes that are connected to
|
// WithAttachments tells the query-builder to eager-load the nodes that are connected to
|
||||||
// the "attachments" edge. The optional arguments are used to configure the query builder of the edge.
|
// the "attachments" edge. The optional arguments are used to configure the query builder of the edge.
|
||||||
func (iq *ItemQuery) WithAttachments(opts ...func(*AttachmentQuery)) *ItemQuery {
|
func (iq *ItemQuery) WithAttachments(opts ...func(*AttachmentQuery)) *ItemQuery {
|
||||||
|
@ -574,13 +610,14 @@ func (iq *ItemQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Item, e
|
||||||
nodes = []*Item{}
|
nodes = []*Item{}
|
||||||
withFKs = iq.withFKs
|
withFKs = iq.withFKs
|
||||||
_spec = iq.querySpec()
|
_spec = iq.querySpec()
|
||||||
loadedTypes = [7]bool{
|
loadedTypes = [8]bool{
|
||||||
iq.withParent != nil,
|
iq.withParent != nil,
|
||||||
iq.withChildren != nil,
|
iq.withChildren != nil,
|
||||||
iq.withGroup != nil,
|
iq.withGroup != nil,
|
||||||
iq.withLabel != nil,
|
iq.withLabel != nil,
|
||||||
iq.withLocation != nil,
|
iq.withLocation != nil,
|
||||||
iq.withFields != nil,
|
iq.withFields != nil,
|
||||||
|
iq.withMaintenanceEntries != nil,
|
||||||
iq.withAttachments != nil,
|
iq.withAttachments != nil,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -647,6 +684,13 @@ func (iq *ItemQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Item, e
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if query := iq.withMaintenanceEntries; query != nil {
|
||||||
|
if err := iq.loadMaintenanceEntries(ctx, query, nodes,
|
||||||
|
func(n *Item) { n.Edges.MaintenanceEntries = []*MaintenanceEntry{} },
|
||||||
|
func(n *Item, e *MaintenanceEntry) { n.Edges.MaintenanceEntries = append(n.Edges.MaintenanceEntries, e) }); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
if query := iq.withAttachments; query != nil {
|
if query := iq.withAttachments; query != nil {
|
||||||
if err := iq.loadAttachments(ctx, query, nodes,
|
if err := iq.loadAttachments(ctx, query, nodes,
|
||||||
func(n *Item) { n.Edges.Attachments = []*Attachment{} },
|
func(n *Item) { n.Edges.Attachments = []*Attachment{} },
|
||||||
|
@ -864,6 +908,33 @@ func (iq *ItemQuery) loadFields(ctx context.Context, query *ItemFieldQuery, node
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
func (iq *ItemQuery) loadMaintenanceEntries(ctx context.Context, query *MaintenanceEntryQuery, nodes []*Item, init func(*Item), assign func(*Item, *MaintenanceEntry)) error {
|
||||||
|
fks := make([]driver.Value, 0, len(nodes))
|
||||||
|
nodeids := make(map[uuid.UUID]*Item)
|
||||||
|
for i := range nodes {
|
||||||
|
fks = append(fks, nodes[i].ID)
|
||||||
|
nodeids[nodes[i].ID] = nodes[i]
|
||||||
|
if init != nil {
|
||||||
|
init(nodes[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
query.Where(predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.InValues(item.MaintenanceEntriesColumn, fks...))
|
||||||
|
}))
|
||||||
|
neighbors, err := query.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, n := range neighbors {
|
||||||
|
fk := n.ItemID
|
||||||
|
node, ok := nodeids[fk]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf(`unexpected foreign-key "item_id" returned %v for node %v`, fk, n.ID)
|
||||||
|
}
|
||||||
|
assign(node, n)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
func (iq *ItemQuery) loadAttachments(ctx context.Context, query *AttachmentQuery, nodes []*Item, init func(*Item), assign func(*Item, *Attachment)) error {
|
func (iq *ItemQuery) loadAttachments(ctx context.Context, query *AttachmentQuery, nodes []*Item, init func(*Item), assign func(*Item, *Attachment)) error {
|
||||||
fks := make([]driver.Value, 0, len(nodes))
|
fks := make([]driver.Value, 0, len(nodes))
|
||||||
nodeids := make(map[uuid.UUID]*Item)
|
nodeids := make(map[uuid.UUID]*Item)
|
||||||
|
|
|
@ -18,6 +18,7 @@ import (
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/itemfield"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/itemfield"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/label"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/label"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/location"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/location"
|
||||||
|
"github.com/hay-kot/homebox/backend/internal/data/ent/maintenanceentry"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/predicate"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/predicate"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -506,6 +507,21 @@ func (iu *ItemUpdate) AddFields(i ...*ItemField) *ItemUpdate {
|
||||||
return iu.AddFieldIDs(ids...)
|
return iu.AddFieldIDs(ids...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddMaintenanceEntryIDs adds the "maintenance_entries" edge to the MaintenanceEntry entity by IDs.
|
||||||
|
func (iu *ItemUpdate) AddMaintenanceEntryIDs(ids ...uuid.UUID) *ItemUpdate {
|
||||||
|
iu.mutation.AddMaintenanceEntryIDs(ids...)
|
||||||
|
return iu
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddMaintenanceEntries adds the "maintenance_entries" edges to the MaintenanceEntry entity.
|
||||||
|
func (iu *ItemUpdate) AddMaintenanceEntries(m ...*MaintenanceEntry) *ItemUpdate {
|
||||||
|
ids := make([]uuid.UUID, len(m))
|
||||||
|
for i := range m {
|
||||||
|
ids[i] = m[i].ID
|
||||||
|
}
|
||||||
|
return iu.AddMaintenanceEntryIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
// AddAttachmentIDs adds the "attachments" edge to the Attachment entity by IDs.
|
// AddAttachmentIDs adds the "attachments" edge to the Attachment entity by IDs.
|
||||||
func (iu *ItemUpdate) AddAttachmentIDs(ids ...uuid.UUID) *ItemUpdate {
|
func (iu *ItemUpdate) AddAttachmentIDs(ids ...uuid.UUID) *ItemUpdate {
|
||||||
iu.mutation.AddAttachmentIDs(ids...)
|
iu.mutation.AddAttachmentIDs(ids...)
|
||||||
|
@ -607,6 +623,27 @@ func (iu *ItemUpdate) RemoveFields(i ...*ItemField) *ItemUpdate {
|
||||||
return iu.RemoveFieldIDs(ids...)
|
return iu.RemoveFieldIDs(ids...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ClearMaintenanceEntries clears all "maintenance_entries" edges to the MaintenanceEntry entity.
|
||||||
|
func (iu *ItemUpdate) ClearMaintenanceEntries() *ItemUpdate {
|
||||||
|
iu.mutation.ClearMaintenanceEntries()
|
||||||
|
return iu
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveMaintenanceEntryIDs removes the "maintenance_entries" edge to MaintenanceEntry entities by IDs.
|
||||||
|
func (iu *ItemUpdate) RemoveMaintenanceEntryIDs(ids ...uuid.UUID) *ItemUpdate {
|
||||||
|
iu.mutation.RemoveMaintenanceEntryIDs(ids...)
|
||||||
|
return iu
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveMaintenanceEntries removes "maintenance_entries" edges to MaintenanceEntry entities.
|
||||||
|
func (iu *ItemUpdate) RemoveMaintenanceEntries(m ...*MaintenanceEntry) *ItemUpdate {
|
||||||
|
ids := make([]uuid.UUID, len(m))
|
||||||
|
for i := range m {
|
||||||
|
ids[i] = m[i].ID
|
||||||
|
}
|
||||||
|
return iu.RemoveMaintenanceEntryIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
// ClearAttachments clears all "attachments" edges to the Attachment entity.
|
// ClearAttachments clears all "attachments" edges to the Attachment entity.
|
||||||
func (iu *ItemUpdate) ClearAttachments() *ItemUpdate {
|
func (iu *ItemUpdate) ClearAttachments() *ItemUpdate {
|
||||||
iu.mutation.ClearAttachments()
|
iu.mutation.ClearAttachments()
|
||||||
|
@ -1144,6 +1181,60 @@ func (iu *ItemUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||||
}
|
}
|
||||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
}
|
}
|
||||||
|
if iu.mutation.MaintenanceEntriesCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: item.MaintenanceEntriesTable,
|
||||||
|
Columns: []string{item.MaintenanceEntriesColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeUUID,
|
||||||
|
Column: maintenanceentry.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := iu.mutation.RemovedMaintenanceEntriesIDs(); len(nodes) > 0 && !iu.mutation.MaintenanceEntriesCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: item.MaintenanceEntriesTable,
|
||||||
|
Columns: []string{item.MaintenanceEntriesColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeUUID,
|
||||||
|
Column: maintenanceentry.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := iu.mutation.MaintenanceEntriesIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: item.MaintenanceEntriesTable,
|
||||||
|
Columns: []string{item.MaintenanceEntriesColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeUUID,
|
||||||
|
Column: maintenanceentry.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
if iu.mutation.AttachmentsCleared() {
|
if iu.mutation.AttachmentsCleared() {
|
||||||
edge := &sqlgraph.EdgeSpec{
|
edge := &sqlgraph.EdgeSpec{
|
||||||
Rel: sqlgraph.O2M,
|
Rel: sqlgraph.O2M,
|
||||||
|
@ -1689,6 +1780,21 @@ func (iuo *ItemUpdateOne) AddFields(i ...*ItemField) *ItemUpdateOne {
|
||||||
return iuo.AddFieldIDs(ids...)
|
return iuo.AddFieldIDs(ids...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddMaintenanceEntryIDs adds the "maintenance_entries" edge to the MaintenanceEntry entity by IDs.
|
||||||
|
func (iuo *ItemUpdateOne) AddMaintenanceEntryIDs(ids ...uuid.UUID) *ItemUpdateOne {
|
||||||
|
iuo.mutation.AddMaintenanceEntryIDs(ids...)
|
||||||
|
return iuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddMaintenanceEntries adds the "maintenance_entries" edges to the MaintenanceEntry entity.
|
||||||
|
func (iuo *ItemUpdateOne) AddMaintenanceEntries(m ...*MaintenanceEntry) *ItemUpdateOne {
|
||||||
|
ids := make([]uuid.UUID, len(m))
|
||||||
|
for i := range m {
|
||||||
|
ids[i] = m[i].ID
|
||||||
|
}
|
||||||
|
return iuo.AddMaintenanceEntryIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
// AddAttachmentIDs adds the "attachments" edge to the Attachment entity by IDs.
|
// AddAttachmentIDs adds the "attachments" edge to the Attachment entity by IDs.
|
||||||
func (iuo *ItemUpdateOne) AddAttachmentIDs(ids ...uuid.UUID) *ItemUpdateOne {
|
func (iuo *ItemUpdateOne) AddAttachmentIDs(ids ...uuid.UUID) *ItemUpdateOne {
|
||||||
iuo.mutation.AddAttachmentIDs(ids...)
|
iuo.mutation.AddAttachmentIDs(ids...)
|
||||||
|
@ -1790,6 +1896,27 @@ func (iuo *ItemUpdateOne) RemoveFields(i ...*ItemField) *ItemUpdateOne {
|
||||||
return iuo.RemoveFieldIDs(ids...)
|
return iuo.RemoveFieldIDs(ids...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ClearMaintenanceEntries clears all "maintenance_entries" edges to the MaintenanceEntry entity.
|
||||||
|
func (iuo *ItemUpdateOne) ClearMaintenanceEntries() *ItemUpdateOne {
|
||||||
|
iuo.mutation.ClearMaintenanceEntries()
|
||||||
|
return iuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveMaintenanceEntryIDs removes the "maintenance_entries" edge to MaintenanceEntry entities by IDs.
|
||||||
|
func (iuo *ItemUpdateOne) RemoveMaintenanceEntryIDs(ids ...uuid.UUID) *ItemUpdateOne {
|
||||||
|
iuo.mutation.RemoveMaintenanceEntryIDs(ids...)
|
||||||
|
return iuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveMaintenanceEntries removes "maintenance_entries" edges to MaintenanceEntry entities.
|
||||||
|
func (iuo *ItemUpdateOne) RemoveMaintenanceEntries(m ...*MaintenanceEntry) *ItemUpdateOne {
|
||||||
|
ids := make([]uuid.UUID, len(m))
|
||||||
|
for i := range m {
|
||||||
|
ids[i] = m[i].ID
|
||||||
|
}
|
||||||
|
return iuo.RemoveMaintenanceEntryIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
// ClearAttachments clears all "attachments" edges to the Attachment entity.
|
// ClearAttachments clears all "attachments" edges to the Attachment entity.
|
||||||
func (iuo *ItemUpdateOne) ClearAttachments() *ItemUpdateOne {
|
func (iuo *ItemUpdateOne) ClearAttachments() *ItemUpdateOne {
|
||||||
iuo.mutation.ClearAttachments()
|
iuo.mutation.ClearAttachments()
|
||||||
|
@ -2357,6 +2484,60 @@ func (iuo *ItemUpdateOne) sqlSave(ctx context.Context) (_node *Item, err error)
|
||||||
}
|
}
|
||||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
}
|
}
|
||||||
|
if iuo.mutation.MaintenanceEntriesCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: item.MaintenanceEntriesTable,
|
||||||
|
Columns: []string{item.MaintenanceEntriesColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeUUID,
|
||||||
|
Column: maintenanceentry.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := iuo.mutation.RemovedMaintenanceEntriesIDs(); len(nodes) > 0 && !iuo.mutation.MaintenanceEntriesCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: item.MaintenanceEntriesTable,
|
||||||
|
Columns: []string{item.MaintenanceEntriesColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeUUID,
|
||||||
|
Column: maintenanceentry.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := iuo.mutation.MaintenanceEntriesIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: item.MaintenanceEntriesTable,
|
||||||
|
Columns: []string{item.MaintenanceEntriesColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeUUID,
|
||||||
|
Column: maintenanceentry.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
if iuo.mutation.AttachmentsCleared() {
|
if iuo.mutation.AttachmentsCleared() {
|
||||||
edge := &sqlgraph.EdgeSpec{
|
edge := &sqlgraph.EdgeSpec{
|
||||||
Rel: sqlgraph.O2M,
|
Rel: sqlgraph.O2M,
|
||||||
|
|
202
backend/internal/data/ent/maintenanceentry.go
Normal file
202
backend/internal/data/ent/maintenanceentry.go
Normal file
|
@ -0,0 +1,202 @@
|
||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"github.com/hay-kot/homebox/backend/internal/data/ent/item"
|
||||||
|
"github.com/hay-kot/homebox/backend/internal/data/ent/maintenanceentry"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MaintenanceEntry is the model entity for the MaintenanceEntry schema.
|
||||||
|
type MaintenanceEntry 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"`
|
||||||
|
// UpdatedAt holds the value of the "updated_at" field.
|
||||||
|
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||||
|
// ItemID holds the value of the "item_id" field.
|
||||||
|
ItemID uuid.UUID `json:"item_id,omitempty"`
|
||||||
|
// Date holds the value of the "date" field.
|
||||||
|
Date time.Time `json:"date,omitempty"`
|
||||||
|
// Name holds the value of the "name" field.
|
||||||
|
Name string `json:"name,omitempty"`
|
||||||
|
// Description holds the value of the "description" field.
|
||||||
|
Description string `json:"description,omitempty"`
|
||||||
|
// Cost holds the value of the "cost" field.
|
||||||
|
Cost float64 `json:"cost,omitempty"`
|
||||||
|
// Edges holds the relations/edges for other nodes in the graph.
|
||||||
|
// The values are being populated by the MaintenanceEntryQuery when eager-loading is set.
|
||||||
|
Edges MaintenanceEntryEdges `json:"edges"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// MaintenanceEntryEdges holds the relations/edges for other nodes in the graph.
|
||||||
|
type MaintenanceEntryEdges struct {
|
||||||
|
// Item holds the value of the item edge.
|
||||||
|
Item *Item `json:"item,omitempty"`
|
||||||
|
// loadedTypes holds the information for reporting if a
|
||||||
|
// type was loaded (or requested) in eager-loading or not.
|
||||||
|
loadedTypes [1]bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// ItemOrErr returns the Item value or an error if the edge
|
||||||
|
// was not loaded in eager-loading, or loaded but was not found.
|
||||||
|
func (e MaintenanceEntryEdges) ItemOrErr() (*Item, error) {
|
||||||
|
if e.loadedTypes[0] {
|
||||||
|
if e.Item == nil {
|
||||||
|
// Edge was loaded but was not found.
|
||||||
|
return nil, &NotFoundError{label: item.Label}
|
||||||
|
}
|
||||||
|
return e.Item, nil
|
||||||
|
}
|
||||||
|
return nil, &NotLoadedError{edge: "item"}
|
||||||
|
}
|
||||||
|
|
||||||
|
// scanValues returns the types for scanning values from sql.Rows.
|
||||||
|
func (*MaintenanceEntry) scanValues(columns []string) ([]any, error) {
|
||||||
|
values := make([]any, len(columns))
|
||||||
|
for i := range columns {
|
||||||
|
switch columns[i] {
|
||||||
|
case maintenanceentry.FieldCost:
|
||||||
|
values[i] = new(sql.NullFloat64)
|
||||||
|
case maintenanceentry.FieldName, maintenanceentry.FieldDescription:
|
||||||
|
values[i] = new(sql.NullString)
|
||||||
|
case maintenanceentry.FieldCreatedAt, maintenanceentry.FieldUpdatedAt, maintenanceentry.FieldDate:
|
||||||
|
values[i] = new(sql.NullTime)
|
||||||
|
case maintenanceentry.FieldID, maintenanceentry.FieldItemID:
|
||||||
|
values[i] = new(uuid.UUID)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("unexpected column %q for type MaintenanceEntry", columns[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return values, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||||
|
// to the MaintenanceEntry fields.
|
||||||
|
func (me *MaintenanceEntry) 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 maintenanceentry.FieldID:
|
||||||
|
if value, ok := values[i].(*uuid.UUID); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field id", values[i])
|
||||||
|
} else if value != nil {
|
||||||
|
me.ID = *value
|
||||||
|
}
|
||||||
|
case maintenanceentry.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 {
|
||||||
|
me.CreatedAt = value.Time
|
||||||
|
}
|
||||||
|
case maintenanceentry.FieldUpdatedAt:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
me.UpdatedAt = value.Time
|
||||||
|
}
|
||||||
|
case maintenanceentry.FieldItemID:
|
||||||
|
if value, ok := values[i].(*uuid.UUID); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field item_id", values[i])
|
||||||
|
} else if value != nil {
|
||||||
|
me.ItemID = *value
|
||||||
|
}
|
||||||
|
case maintenanceentry.FieldDate:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field date", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
me.Date = value.Time
|
||||||
|
}
|
||||||
|
case maintenanceentry.FieldName:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field name", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
me.Name = value.String
|
||||||
|
}
|
||||||
|
case maintenanceentry.FieldDescription:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field description", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
me.Description = value.String
|
||||||
|
}
|
||||||
|
case maintenanceentry.FieldCost:
|
||||||
|
if value, ok := values[i].(*sql.NullFloat64); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field cost", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
me.Cost = value.Float64
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryItem queries the "item" edge of the MaintenanceEntry entity.
|
||||||
|
func (me *MaintenanceEntry) QueryItem() *ItemQuery {
|
||||||
|
return (&MaintenanceEntryClient{config: me.config}).QueryItem(me)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns a builder for updating this MaintenanceEntry.
|
||||||
|
// Note that you need to call MaintenanceEntry.Unwrap() before calling this method if this MaintenanceEntry
|
||||||
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||||
|
func (me *MaintenanceEntry) Update() *MaintenanceEntryUpdateOne {
|
||||||
|
return (&MaintenanceEntryClient{config: me.config}).UpdateOne(me)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unwrap unwraps the MaintenanceEntry 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 (me *MaintenanceEntry) Unwrap() *MaintenanceEntry {
|
||||||
|
_tx, ok := me.config.driver.(*txDriver)
|
||||||
|
if !ok {
|
||||||
|
panic("ent: MaintenanceEntry is not a transactional entity")
|
||||||
|
}
|
||||||
|
me.config.driver = _tx.drv
|
||||||
|
return me
|
||||||
|
}
|
||||||
|
|
||||||
|
// String implements the fmt.Stringer.
|
||||||
|
func (me *MaintenanceEntry) String() string {
|
||||||
|
var builder strings.Builder
|
||||||
|
builder.WriteString("MaintenanceEntry(")
|
||||||
|
builder.WriteString(fmt.Sprintf("id=%v, ", me.ID))
|
||||||
|
builder.WriteString("created_at=")
|
||||||
|
builder.WriteString(me.CreatedAt.Format(time.ANSIC))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("updated_at=")
|
||||||
|
builder.WriteString(me.UpdatedAt.Format(time.ANSIC))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("item_id=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", me.ItemID))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("date=")
|
||||||
|
builder.WriteString(me.Date.Format(time.ANSIC))
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("name=")
|
||||||
|
builder.WriteString(me.Name)
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("description=")
|
||||||
|
builder.WriteString(me.Description)
|
||||||
|
builder.WriteString(", ")
|
||||||
|
builder.WriteString("cost=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", me.Cost))
|
||||||
|
builder.WriteByte(')')
|
||||||
|
return builder.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// MaintenanceEntries is a parsable slice of MaintenanceEntry.
|
||||||
|
type MaintenanceEntries []*MaintenanceEntry
|
||||||
|
|
||||||
|
func (me MaintenanceEntries) config(cfg config) {
|
||||||
|
for _i := range me {
|
||||||
|
me[_i].config = cfg
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,82 @@
|
||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package maintenanceentry
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Label holds the string label denoting the maintenanceentry type in the database.
|
||||||
|
Label = "maintenance_entry"
|
||||||
|
// FieldID holds the string denoting the id field in the database.
|
||||||
|
FieldID = "id"
|
||||||
|
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||||
|
FieldCreatedAt = "created_at"
|
||||||
|
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
|
||||||
|
FieldUpdatedAt = "updated_at"
|
||||||
|
// FieldItemID holds the string denoting the item_id field in the database.
|
||||||
|
FieldItemID = "item_id"
|
||||||
|
// FieldDate holds the string denoting the date field in the database.
|
||||||
|
FieldDate = "date"
|
||||||
|
// FieldName holds the string denoting the name field in the database.
|
||||||
|
FieldName = "name"
|
||||||
|
// FieldDescription holds the string denoting the description field in the database.
|
||||||
|
FieldDescription = "description"
|
||||||
|
// FieldCost holds the string denoting the cost field in the database.
|
||||||
|
FieldCost = "cost"
|
||||||
|
// EdgeItem holds the string denoting the item edge name in mutations.
|
||||||
|
EdgeItem = "item"
|
||||||
|
// Table holds the table name of the maintenanceentry in the database.
|
||||||
|
Table = "maintenance_entries"
|
||||||
|
// ItemTable is the table that holds the item relation/edge.
|
||||||
|
ItemTable = "maintenance_entries"
|
||||||
|
// ItemInverseTable is the table name for the Item entity.
|
||||||
|
// It exists in this package in order to avoid circular dependency with the "item" package.
|
||||||
|
ItemInverseTable = "items"
|
||||||
|
// ItemColumn is the table column denoting the item relation/edge.
|
||||||
|
ItemColumn = "item_id"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Columns holds all SQL columns for maintenanceentry fields.
|
||||||
|
var Columns = []string{
|
||||||
|
FieldID,
|
||||||
|
FieldCreatedAt,
|
||||||
|
FieldUpdatedAt,
|
||||||
|
FieldItemID,
|
||||||
|
FieldDate,
|
||||||
|
FieldName,
|
||||||
|
FieldDescription,
|
||||||
|
FieldCost,
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||||
|
func ValidColumn(column string) bool {
|
||||||
|
for i := range Columns {
|
||||||
|
if column == Columns[i] {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||||
|
DefaultCreatedAt func() time.Time
|
||||||
|
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||||
|
DefaultUpdatedAt func() time.Time
|
||||||
|
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
|
||||||
|
UpdateDefaultUpdatedAt func() time.Time
|
||||||
|
// DefaultDate holds the default value on creation for the "date" field.
|
||||||
|
DefaultDate func() time.Time
|
||||||
|
// NameValidator is a validator for the "name" field. It is called by the builders before save.
|
||||||
|
NameValidator func(string) error
|
||||||
|
// DescriptionValidator is a validator for the "description" field. It is called by the builders before save.
|
||||||
|
DescriptionValidator func(string) error
|
||||||
|
// DefaultCost holds the default value on creation for the "cost" field.
|
||||||
|
DefaultCost float64
|
||||||
|
// DefaultID holds the default value on creation for the "id" field.
|
||||||
|
DefaultID func() uuid.UUID
|
||||||
|
)
|
696
backend/internal/data/ent/maintenanceentry/where.go
Normal file
696
backend/internal/data/ent/maintenanceentry/where.go
Normal file
|
@ -0,0 +1,696 @@
|
||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package maintenanceentry
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"github.com/hay-kot/homebox/backend/internal/data/ent/predicate"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ID filters vertices based on their ID field.
|
||||||
|
func ID(id uuid.UUID) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldID), id))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDEQ applies the EQ predicate on the ID field.
|
||||||
|
func IDEQ(id uuid.UUID) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldID), id))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNEQ applies the NEQ predicate on the ID field.
|
||||||
|
func IDNEQ(id uuid.UUID) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.NEQ(s.C(FieldID), id))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDIn applies the In predicate on the ID field.
|
||||||
|
func IDIn(ids ...uuid.UUID) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
v := make([]any, len(ids))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = ids[i]
|
||||||
|
}
|
||||||
|
s.Where(sql.In(s.C(FieldID), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNotIn applies the NotIn predicate on the ID field.
|
||||||
|
func IDNotIn(ids ...uuid.UUID) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
v := make([]any, len(ids))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = ids[i]
|
||||||
|
}
|
||||||
|
s.Where(sql.NotIn(s.C(FieldID), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGT applies the GT predicate on the ID field.
|
||||||
|
func IDGT(id uuid.UUID) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.GT(s.C(FieldID), id))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGTE applies the GTE predicate on the ID field.
|
||||||
|
func IDGTE(id uuid.UUID) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.GTE(s.C(FieldID), id))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLT applies the LT predicate on the ID field.
|
||||||
|
func IDLT(id uuid.UUID) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.LT(s.C(FieldID), id))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLTE applies the LTE predicate on the ID field.
|
||||||
|
func IDLTE(id uuid.UUID) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.LTE(s.C(FieldID), id))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
||||||
|
func CreatedAt(v time.Time) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldCreatedAt), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
|
||||||
|
func UpdatedAt(v time.Time) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldUpdatedAt), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ItemID applies equality check predicate on the "item_id" field. It's identical to ItemIDEQ.
|
||||||
|
func ItemID(v uuid.UUID) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldItemID), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Date applies equality check predicate on the "date" field. It's identical to DateEQ.
|
||||||
|
func Date(v time.Time) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldDate), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
|
||||||
|
func Name(v string) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldName), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Description applies equality check predicate on the "description" field. It's identical to DescriptionEQ.
|
||||||
|
func Description(v string) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldDescription), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cost applies equality check predicate on the "cost" field. It's identical to CostEQ.
|
||||||
|
func Cost(v float64) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldCost), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
|
||||||
|
func CreatedAtEQ(v time.Time) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldCreatedAt), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
|
||||||
|
func CreatedAtNEQ(v time.Time) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.NEQ(s.C(FieldCreatedAt), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtIn applies the In predicate on the "created_at" field.
|
||||||
|
func CreatedAtIn(vs ...time.Time) predicate.MaintenanceEntry {
|
||||||
|
v := make([]any, len(vs))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = vs[i]
|
||||||
|
}
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.In(s.C(FieldCreatedAt), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
|
||||||
|
func CreatedAtNotIn(vs ...time.Time) predicate.MaintenanceEntry {
|
||||||
|
v := make([]any, len(vs))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = vs[i]
|
||||||
|
}
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.NotIn(s.C(FieldCreatedAt), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtGT applies the GT predicate on the "created_at" field.
|
||||||
|
func CreatedAtGT(v time.Time) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.GT(s.C(FieldCreatedAt), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
|
||||||
|
func CreatedAtGTE(v time.Time) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.GTE(s.C(FieldCreatedAt), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtLT applies the LT predicate on the "created_at" field.
|
||||||
|
func CreatedAtLT(v time.Time) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.LT(s.C(FieldCreatedAt), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
|
||||||
|
func CreatedAtLTE(v time.Time) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.LTE(s.C(FieldCreatedAt), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtEQ(v time.Time) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldUpdatedAt), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtNEQ(v time.Time) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.NEQ(s.C(FieldUpdatedAt), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtIn applies the In predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtIn(vs ...time.Time) predicate.MaintenanceEntry {
|
||||||
|
v := make([]any, len(vs))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = vs[i]
|
||||||
|
}
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.In(s.C(FieldUpdatedAt), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtNotIn(vs ...time.Time) predicate.MaintenanceEntry {
|
||||||
|
v := make([]any, len(vs))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = vs[i]
|
||||||
|
}
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.NotIn(s.C(FieldUpdatedAt), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtGT(v time.Time) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.GT(s.C(FieldUpdatedAt), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtGTE(v time.Time) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.GTE(s.C(FieldUpdatedAt), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtLT(v time.Time) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.LT(s.C(FieldUpdatedAt), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
|
||||||
|
func UpdatedAtLTE(v time.Time) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.LTE(s.C(FieldUpdatedAt), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ItemIDEQ applies the EQ predicate on the "item_id" field.
|
||||||
|
func ItemIDEQ(v uuid.UUID) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldItemID), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ItemIDNEQ applies the NEQ predicate on the "item_id" field.
|
||||||
|
func ItemIDNEQ(v uuid.UUID) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.NEQ(s.C(FieldItemID), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ItemIDIn applies the In predicate on the "item_id" field.
|
||||||
|
func ItemIDIn(vs ...uuid.UUID) predicate.MaintenanceEntry {
|
||||||
|
v := make([]any, len(vs))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = vs[i]
|
||||||
|
}
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.In(s.C(FieldItemID), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ItemIDNotIn applies the NotIn predicate on the "item_id" field.
|
||||||
|
func ItemIDNotIn(vs ...uuid.UUID) predicate.MaintenanceEntry {
|
||||||
|
v := make([]any, len(vs))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = vs[i]
|
||||||
|
}
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.NotIn(s.C(FieldItemID), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DateEQ applies the EQ predicate on the "date" field.
|
||||||
|
func DateEQ(v time.Time) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldDate), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DateNEQ applies the NEQ predicate on the "date" field.
|
||||||
|
func DateNEQ(v time.Time) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.NEQ(s.C(FieldDate), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DateIn applies the In predicate on the "date" field.
|
||||||
|
func DateIn(vs ...time.Time) predicate.MaintenanceEntry {
|
||||||
|
v := make([]any, len(vs))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = vs[i]
|
||||||
|
}
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.In(s.C(FieldDate), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DateNotIn applies the NotIn predicate on the "date" field.
|
||||||
|
func DateNotIn(vs ...time.Time) predicate.MaintenanceEntry {
|
||||||
|
v := make([]any, len(vs))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = vs[i]
|
||||||
|
}
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.NotIn(s.C(FieldDate), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DateGT applies the GT predicate on the "date" field.
|
||||||
|
func DateGT(v time.Time) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.GT(s.C(FieldDate), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DateGTE applies the GTE predicate on the "date" field.
|
||||||
|
func DateGTE(v time.Time) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.GTE(s.C(FieldDate), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DateLT applies the LT predicate on the "date" field.
|
||||||
|
func DateLT(v time.Time) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.LT(s.C(FieldDate), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DateLTE applies the LTE predicate on the "date" field.
|
||||||
|
func DateLTE(v time.Time) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.LTE(s.C(FieldDate), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameEQ applies the EQ predicate on the "name" field.
|
||||||
|
func NameEQ(v string) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldName), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameNEQ applies the NEQ predicate on the "name" field.
|
||||||
|
func NameNEQ(v string) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.NEQ(s.C(FieldName), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameIn applies the In predicate on the "name" field.
|
||||||
|
func NameIn(vs ...string) predicate.MaintenanceEntry {
|
||||||
|
v := make([]any, len(vs))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = vs[i]
|
||||||
|
}
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.In(s.C(FieldName), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameNotIn applies the NotIn predicate on the "name" field.
|
||||||
|
func NameNotIn(vs ...string) predicate.MaintenanceEntry {
|
||||||
|
v := make([]any, len(vs))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = vs[i]
|
||||||
|
}
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.NotIn(s.C(FieldName), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameGT applies the GT predicate on the "name" field.
|
||||||
|
func NameGT(v string) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.GT(s.C(FieldName), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameGTE applies the GTE predicate on the "name" field.
|
||||||
|
func NameGTE(v string) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.GTE(s.C(FieldName), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameLT applies the LT predicate on the "name" field.
|
||||||
|
func NameLT(v string) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.LT(s.C(FieldName), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameLTE applies the LTE predicate on the "name" field.
|
||||||
|
func NameLTE(v string) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.LTE(s.C(FieldName), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameContains applies the Contains predicate on the "name" field.
|
||||||
|
func NameContains(v string) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.Contains(s.C(FieldName), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameHasPrefix applies the HasPrefix predicate on the "name" field.
|
||||||
|
func NameHasPrefix(v string) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.HasPrefix(s.C(FieldName), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameHasSuffix applies the HasSuffix predicate on the "name" field.
|
||||||
|
func NameHasSuffix(v string) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.HasSuffix(s.C(FieldName), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameEqualFold applies the EqualFold predicate on the "name" field.
|
||||||
|
func NameEqualFold(v string) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EqualFold(s.C(FieldName), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// NameContainsFold applies the ContainsFold predicate on the "name" field.
|
||||||
|
func NameContainsFold(v string) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.ContainsFold(s.C(FieldName), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionEQ applies the EQ predicate on the "description" field.
|
||||||
|
func DescriptionEQ(v string) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldDescription), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionNEQ applies the NEQ predicate on the "description" field.
|
||||||
|
func DescriptionNEQ(v string) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.NEQ(s.C(FieldDescription), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionIn applies the In predicate on the "description" field.
|
||||||
|
func DescriptionIn(vs ...string) predicate.MaintenanceEntry {
|
||||||
|
v := make([]any, len(vs))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = vs[i]
|
||||||
|
}
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.In(s.C(FieldDescription), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionNotIn applies the NotIn predicate on the "description" field.
|
||||||
|
func DescriptionNotIn(vs ...string) predicate.MaintenanceEntry {
|
||||||
|
v := make([]any, len(vs))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = vs[i]
|
||||||
|
}
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.NotIn(s.C(FieldDescription), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionGT applies the GT predicate on the "description" field.
|
||||||
|
func DescriptionGT(v string) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.GT(s.C(FieldDescription), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionGTE applies the GTE predicate on the "description" field.
|
||||||
|
func DescriptionGTE(v string) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.GTE(s.C(FieldDescription), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionLT applies the LT predicate on the "description" field.
|
||||||
|
func DescriptionLT(v string) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.LT(s.C(FieldDescription), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionLTE applies the LTE predicate on the "description" field.
|
||||||
|
func DescriptionLTE(v string) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.LTE(s.C(FieldDescription), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionContains applies the Contains predicate on the "description" field.
|
||||||
|
func DescriptionContains(v string) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.Contains(s.C(FieldDescription), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionHasPrefix applies the HasPrefix predicate on the "description" field.
|
||||||
|
func DescriptionHasPrefix(v string) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.HasPrefix(s.C(FieldDescription), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionHasSuffix applies the HasSuffix predicate on the "description" field.
|
||||||
|
func DescriptionHasSuffix(v string) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.HasSuffix(s.C(FieldDescription), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionIsNil applies the IsNil predicate on the "description" field.
|
||||||
|
func DescriptionIsNil() predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.IsNull(s.C(FieldDescription)))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionNotNil applies the NotNil predicate on the "description" field.
|
||||||
|
func DescriptionNotNil() predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.NotNull(s.C(FieldDescription)))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionEqualFold applies the EqualFold predicate on the "description" field.
|
||||||
|
func DescriptionEqualFold(v string) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EqualFold(s.C(FieldDescription), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DescriptionContainsFold applies the ContainsFold predicate on the "description" field.
|
||||||
|
func DescriptionContainsFold(v string) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.ContainsFold(s.C(FieldDescription), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// CostEQ applies the EQ predicate on the "cost" field.
|
||||||
|
func CostEQ(v float64) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldCost), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// CostNEQ applies the NEQ predicate on the "cost" field.
|
||||||
|
func CostNEQ(v float64) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.NEQ(s.C(FieldCost), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// CostIn applies the In predicate on the "cost" field.
|
||||||
|
func CostIn(vs ...float64) predicate.MaintenanceEntry {
|
||||||
|
v := make([]any, len(vs))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = vs[i]
|
||||||
|
}
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.In(s.C(FieldCost), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// CostNotIn applies the NotIn predicate on the "cost" field.
|
||||||
|
func CostNotIn(vs ...float64) predicate.MaintenanceEntry {
|
||||||
|
v := make([]any, len(vs))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = vs[i]
|
||||||
|
}
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.NotIn(s.C(FieldCost), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// CostGT applies the GT predicate on the "cost" field.
|
||||||
|
func CostGT(v float64) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.GT(s.C(FieldCost), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// CostGTE applies the GTE predicate on the "cost" field.
|
||||||
|
func CostGTE(v float64) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.GTE(s.C(FieldCost), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// CostLT applies the LT predicate on the "cost" field.
|
||||||
|
func CostLT(v float64) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.LT(s.C(FieldCost), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// CostLTE applies the LTE predicate on the "cost" field.
|
||||||
|
func CostLTE(v float64) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.LTE(s.C(FieldCost), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasItem applies the HasEdge predicate on the "item" edge.
|
||||||
|
func HasItem() predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.To(ItemTable, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, ItemTable, ItemColumn),
|
||||||
|
)
|
||||||
|
sqlgraph.HasNeighbors(s, step)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasItemWith applies the HasEdge predicate on the "item" edge with a given conditions (other predicates).
|
||||||
|
func HasItemWith(preds ...predicate.Item) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.To(ItemInverseTable, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, ItemTable, ItemColumn),
|
||||||
|
)
|
||||||
|
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||||
|
for _, p := range preds {
|
||||||
|
p(s)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// And groups predicates with the AND operator between them.
|
||||||
|
func And(predicates ...predicate.MaintenanceEntry) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s1 := s.Clone().SetP(nil)
|
||||||
|
for _, p := range predicates {
|
||||||
|
p(s1)
|
||||||
|
}
|
||||||
|
s.Where(s1.P())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Or groups predicates with the OR operator between them.
|
||||||
|
func Or(predicates ...predicate.MaintenanceEntry) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
s1 := s.Clone().SetP(nil)
|
||||||
|
for i, p := range predicates {
|
||||||
|
if i > 0 {
|
||||||
|
s1.Or()
|
||||||
|
}
|
||||||
|
p(s1)
|
||||||
|
}
|
||||||
|
s.Where(s1.P())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not applies the not operator on the given predicate.
|
||||||
|
func Not(p predicate.MaintenanceEntry) predicate.MaintenanceEntry {
|
||||||
|
return predicate.MaintenanceEntry(func(s *sql.Selector) {
|
||||||
|
p(s.Not())
|
||||||
|
})
|
||||||
|
}
|
419
backend/internal/data/ent/maintenanceentry_create.go
Normal file
419
backend/internal/data/ent/maintenanceentry_create.go
Normal file
|
@ -0,0 +1,419 @@
|
||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"github.com/hay-kot/homebox/backend/internal/data/ent/item"
|
||||||
|
"github.com/hay-kot/homebox/backend/internal/data/ent/maintenanceentry"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MaintenanceEntryCreate is the builder for creating a MaintenanceEntry entity.
|
||||||
|
type MaintenanceEntryCreate struct {
|
||||||
|
config
|
||||||
|
mutation *MaintenanceEntryMutation
|
||||||
|
hooks []Hook
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCreatedAt sets the "created_at" field.
|
||||||
|
func (mec *MaintenanceEntryCreate) SetCreatedAt(t time.Time) *MaintenanceEntryCreate {
|
||||||
|
mec.mutation.SetCreatedAt(t)
|
||||||
|
return mec
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||||
|
func (mec *MaintenanceEntryCreate) SetNillableCreatedAt(t *time.Time) *MaintenanceEntryCreate {
|
||||||
|
if t != nil {
|
||||||
|
mec.SetCreatedAt(*t)
|
||||||
|
}
|
||||||
|
return mec
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (mec *MaintenanceEntryCreate) SetUpdatedAt(t time.Time) *MaintenanceEntryCreate {
|
||||||
|
mec.mutation.SetUpdatedAt(t)
|
||||||
|
return mec
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||||
|
func (mec *MaintenanceEntryCreate) SetNillableUpdatedAt(t *time.Time) *MaintenanceEntryCreate {
|
||||||
|
if t != nil {
|
||||||
|
mec.SetUpdatedAt(*t)
|
||||||
|
}
|
||||||
|
return mec
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetItemID sets the "item_id" field.
|
||||||
|
func (mec *MaintenanceEntryCreate) SetItemID(u uuid.UUID) *MaintenanceEntryCreate {
|
||||||
|
mec.mutation.SetItemID(u)
|
||||||
|
return mec
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDate sets the "date" field.
|
||||||
|
func (mec *MaintenanceEntryCreate) SetDate(t time.Time) *MaintenanceEntryCreate {
|
||||||
|
mec.mutation.SetDate(t)
|
||||||
|
return mec
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableDate sets the "date" field if the given value is not nil.
|
||||||
|
func (mec *MaintenanceEntryCreate) SetNillableDate(t *time.Time) *MaintenanceEntryCreate {
|
||||||
|
if t != nil {
|
||||||
|
mec.SetDate(*t)
|
||||||
|
}
|
||||||
|
return mec
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetName sets the "name" field.
|
||||||
|
func (mec *MaintenanceEntryCreate) SetName(s string) *MaintenanceEntryCreate {
|
||||||
|
mec.mutation.SetName(s)
|
||||||
|
return mec
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDescription sets the "description" field.
|
||||||
|
func (mec *MaintenanceEntryCreate) SetDescription(s string) *MaintenanceEntryCreate {
|
||||||
|
mec.mutation.SetDescription(s)
|
||||||
|
return mec
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
||||||
|
func (mec *MaintenanceEntryCreate) SetNillableDescription(s *string) *MaintenanceEntryCreate {
|
||||||
|
if s != nil {
|
||||||
|
mec.SetDescription(*s)
|
||||||
|
}
|
||||||
|
return mec
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCost sets the "cost" field.
|
||||||
|
func (mec *MaintenanceEntryCreate) SetCost(f float64) *MaintenanceEntryCreate {
|
||||||
|
mec.mutation.SetCost(f)
|
||||||
|
return mec
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableCost sets the "cost" field if the given value is not nil.
|
||||||
|
func (mec *MaintenanceEntryCreate) SetNillableCost(f *float64) *MaintenanceEntryCreate {
|
||||||
|
if f != nil {
|
||||||
|
mec.SetCost(*f)
|
||||||
|
}
|
||||||
|
return mec
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetID sets the "id" field.
|
||||||
|
func (mec *MaintenanceEntryCreate) SetID(u uuid.UUID) *MaintenanceEntryCreate {
|
||||||
|
mec.mutation.SetID(u)
|
||||||
|
return mec
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableID sets the "id" field if the given value is not nil.
|
||||||
|
func (mec *MaintenanceEntryCreate) SetNillableID(u *uuid.UUID) *MaintenanceEntryCreate {
|
||||||
|
if u != nil {
|
||||||
|
mec.SetID(*u)
|
||||||
|
}
|
||||||
|
return mec
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetItem sets the "item" edge to the Item entity.
|
||||||
|
func (mec *MaintenanceEntryCreate) SetItem(i *Item) *MaintenanceEntryCreate {
|
||||||
|
return mec.SetItemID(i.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the MaintenanceEntryMutation object of the builder.
|
||||||
|
func (mec *MaintenanceEntryCreate) Mutation() *MaintenanceEntryMutation {
|
||||||
|
return mec.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the MaintenanceEntry in the database.
|
||||||
|
func (mec *MaintenanceEntryCreate) Save(ctx context.Context) (*MaintenanceEntry, error) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
node *MaintenanceEntry
|
||||||
|
)
|
||||||
|
mec.defaults()
|
||||||
|
if len(mec.hooks) == 0 {
|
||||||
|
if err = mec.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
node, err = mec.sqlSave(ctx)
|
||||||
|
} else {
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutation, ok := m.(*MaintenanceEntryMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
if err = mec.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
mec.mutation = mutation
|
||||||
|
if node, err = mec.sqlSave(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
mutation.id = &node.ID
|
||||||
|
mutation.done = true
|
||||||
|
return node, err
|
||||||
|
})
|
||||||
|
for i := len(mec.hooks) - 1; i >= 0; i-- {
|
||||||
|
if mec.hooks[i] == nil {
|
||||||
|
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||||
|
}
|
||||||
|
mut = mec.hooks[i](mut)
|
||||||
|
}
|
||||||
|
v, err := mut.Mutate(ctx, mec.mutation)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
nv, ok := v.(*MaintenanceEntry)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected node type %T returned from MaintenanceEntryMutation", v)
|
||||||
|
}
|
||||||
|
node = nv
|
||||||
|
}
|
||||||
|
return node, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX calls Save and panics if Save returns an error.
|
||||||
|
func (mec *MaintenanceEntryCreate) SaveX(ctx context.Context) *MaintenanceEntry {
|
||||||
|
v, err := mec.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (mec *MaintenanceEntryCreate) Exec(ctx context.Context) error {
|
||||||
|
_, err := mec.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (mec *MaintenanceEntryCreate) ExecX(ctx context.Context) {
|
||||||
|
if err := mec.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (mec *MaintenanceEntryCreate) defaults() {
|
||||||
|
if _, ok := mec.mutation.CreatedAt(); !ok {
|
||||||
|
v := maintenanceentry.DefaultCreatedAt()
|
||||||
|
mec.mutation.SetCreatedAt(v)
|
||||||
|
}
|
||||||
|
if _, ok := mec.mutation.UpdatedAt(); !ok {
|
||||||
|
v := maintenanceentry.DefaultUpdatedAt()
|
||||||
|
mec.mutation.SetUpdatedAt(v)
|
||||||
|
}
|
||||||
|
if _, ok := mec.mutation.Date(); !ok {
|
||||||
|
v := maintenanceentry.DefaultDate()
|
||||||
|
mec.mutation.SetDate(v)
|
||||||
|
}
|
||||||
|
if _, ok := mec.mutation.Cost(); !ok {
|
||||||
|
v := maintenanceentry.DefaultCost
|
||||||
|
mec.mutation.SetCost(v)
|
||||||
|
}
|
||||||
|
if _, ok := mec.mutation.ID(); !ok {
|
||||||
|
v := maintenanceentry.DefaultID()
|
||||||
|
mec.mutation.SetID(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (mec *MaintenanceEntryCreate) check() error {
|
||||||
|
if _, ok := mec.mutation.CreatedAt(); !ok {
|
||||||
|
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "MaintenanceEntry.created_at"`)}
|
||||||
|
}
|
||||||
|
if _, ok := mec.mutation.UpdatedAt(); !ok {
|
||||||
|
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "MaintenanceEntry.updated_at"`)}
|
||||||
|
}
|
||||||
|
if _, ok := mec.mutation.ItemID(); !ok {
|
||||||
|
return &ValidationError{Name: "item_id", err: errors.New(`ent: missing required field "MaintenanceEntry.item_id"`)}
|
||||||
|
}
|
||||||
|
if _, ok := mec.mutation.Date(); !ok {
|
||||||
|
return &ValidationError{Name: "date", err: errors.New(`ent: missing required field "MaintenanceEntry.date"`)}
|
||||||
|
}
|
||||||
|
if _, ok := mec.mutation.Name(); !ok {
|
||||||
|
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "MaintenanceEntry.name"`)}
|
||||||
|
}
|
||||||
|
if v, ok := mec.mutation.Name(); ok {
|
||||||
|
if err := maintenanceentry.NameValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "MaintenanceEntry.name": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := mec.mutation.Description(); ok {
|
||||||
|
if err := maintenanceentry.DescriptionValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "MaintenanceEntry.description": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, ok := mec.mutation.Cost(); !ok {
|
||||||
|
return &ValidationError{Name: "cost", err: errors.New(`ent: missing required field "MaintenanceEntry.cost"`)}
|
||||||
|
}
|
||||||
|
if _, ok := mec.mutation.ItemID(); !ok {
|
||||||
|
return &ValidationError{Name: "item", err: errors.New(`ent: missing required edge "MaintenanceEntry.item"`)}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mec *MaintenanceEntryCreate) sqlSave(ctx context.Context) (*MaintenanceEntry, error) {
|
||||||
|
_node, _spec := mec.createSpec()
|
||||||
|
if err := sqlgraph.CreateNode(ctx, mec.driver, _spec); err != nil {
|
||||||
|
if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if _spec.ID.Value != nil {
|
||||||
|
if id, ok := _spec.ID.Value.(*uuid.UUID); ok {
|
||||||
|
_node.ID = *id
|
||||||
|
} else if err := _node.ID.Scan(_spec.ID.Value); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return _node, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mec *MaintenanceEntryCreate) createSpec() (*MaintenanceEntry, *sqlgraph.CreateSpec) {
|
||||||
|
var (
|
||||||
|
_node = &MaintenanceEntry{config: mec.config}
|
||||||
|
_spec = &sqlgraph.CreateSpec{
|
||||||
|
Table: maintenanceentry.Table,
|
||||||
|
ID: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeUUID,
|
||||||
|
Column: maintenanceentry.FieldID,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
if id, ok := mec.mutation.ID(); ok {
|
||||||
|
_node.ID = id
|
||||||
|
_spec.ID.Value = &id
|
||||||
|
}
|
||||||
|
if value, ok := mec.mutation.CreatedAt(); ok {
|
||||||
|
_spec.SetField(maintenanceentry.FieldCreatedAt, field.TypeTime, value)
|
||||||
|
_node.CreatedAt = value
|
||||||
|
}
|
||||||
|
if value, ok := mec.mutation.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(maintenanceentry.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
_node.UpdatedAt = value
|
||||||
|
}
|
||||||
|
if value, ok := mec.mutation.Date(); ok {
|
||||||
|
_spec.SetField(maintenanceentry.FieldDate, field.TypeTime, value)
|
||||||
|
_node.Date = value
|
||||||
|
}
|
||||||
|
if value, ok := mec.mutation.Name(); ok {
|
||||||
|
_spec.SetField(maintenanceentry.FieldName, field.TypeString, value)
|
||||||
|
_node.Name = value
|
||||||
|
}
|
||||||
|
if value, ok := mec.mutation.Description(); ok {
|
||||||
|
_spec.SetField(maintenanceentry.FieldDescription, field.TypeString, value)
|
||||||
|
_node.Description = value
|
||||||
|
}
|
||||||
|
if value, ok := mec.mutation.Cost(); ok {
|
||||||
|
_spec.SetField(maintenanceentry.FieldCost, field.TypeFloat64, value)
|
||||||
|
_node.Cost = value
|
||||||
|
}
|
||||||
|
if nodes := mec.mutation.ItemIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: maintenanceentry.ItemTable,
|
||||||
|
Columns: []string{maintenanceentry.ItemColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeUUID,
|
||||||
|
Column: item.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_node.ItemID = nodes[0]
|
||||||
|
_spec.Edges = append(_spec.Edges, edge)
|
||||||
|
}
|
||||||
|
return _node, _spec
|
||||||
|
}
|
||||||
|
|
||||||
|
// MaintenanceEntryCreateBulk is the builder for creating many MaintenanceEntry entities in bulk.
|
||||||
|
type MaintenanceEntryCreateBulk struct {
|
||||||
|
config
|
||||||
|
builders []*MaintenanceEntryCreate
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the MaintenanceEntry entities in the database.
|
||||||
|
func (mecb *MaintenanceEntryCreateBulk) Save(ctx context.Context) ([]*MaintenanceEntry, error) {
|
||||||
|
specs := make([]*sqlgraph.CreateSpec, len(mecb.builders))
|
||||||
|
nodes := make([]*MaintenanceEntry, len(mecb.builders))
|
||||||
|
mutators := make([]Mutator, len(mecb.builders))
|
||||||
|
for i := range mecb.builders {
|
||||||
|
func(i int, root context.Context) {
|
||||||
|
builder := mecb.builders[i]
|
||||||
|
builder.defaults()
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutation, ok := m.(*MaintenanceEntryMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
if err := builder.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
builder.mutation = mutation
|
||||||
|
nodes[i], specs[i] = builder.createSpec()
|
||||||
|
var err error
|
||||||
|
if i < len(mutators)-1 {
|
||||||
|
_, err = mutators[i+1].Mutate(root, mecb.builders[i+1].mutation)
|
||||||
|
} else {
|
||||||
|
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||||
|
// Invoke the actual operation on the latest mutation in the chain.
|
||||||
|
if err = sqlgraph.BatchCreate(ctx, mecb.driver, spec); err != nil {
|
||||||
|
if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
mutation.id = &nodes[i].ID
|
||||||
|
mutation.done = true
|
||||||
|
return nodes[i], nil
|
||||||
|
})
|
||||||
|
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
||||||
|
mut = builder.hooks[i](mut)
|
||||||
|
}
|
||||||
|
mutators[i] = mut
|
||||||
|
}(i, ctx)
|
||||||
|
}
|
||||||
|
if len(mutators) > 0 {
|
||||||
|
if _, err := mutators[0].Mutate(ctx, mecb.builders[0].mutation); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (mecb *MaintenanceEntryCreateBulk) SaveX(ctx context.Context) []*MaintenanceEntry {
|
||||||
|
v, err := mecb.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (mecb *MaintenanceEntryCreateBulk) Exec(ctx context.Context) error {
|
||||||
|
_, err := mecb.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (mecb *MaintenanceEntryCreateBulk) ExecX(ctx context.Context) {
|
||||||
|
if err := mecb.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
115
backend/internal/data/ent/maintenanceentry_delete.go
Normal file
115
backend/internal/data/ent/maintenanceentry_delete.go
Normal file
|
@ -0,0 +1,115 @@
|
||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
"github.com/hay-kot/homebox/backend/internal/data/ent/maintenanceentry"
|
||||||
|
"github.com/hay-kot/homebox/backend/internal/data/ent/predicate"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MaintenanceEntryDelete is the builder for deleting a MaintenanceEntry entity.
|
||||||
|
type MaintenanceEntryDelete struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *MaintenanceEntryMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the MaintenanceEntryDelete builder.
|
||||||
|
func (med *MaintenanceEntryDelete) Where(ps ...predicate.MaintenanceEntry) *MaintenanceEntryDelete {
|
||||||
|
med.mutation.Where(ps...)
|
||||||
|
return med
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||||
|
func (med *MaintenanceEntryDelete) Exec(ctx context.Context) (int, error) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
affected int
|
||||||
|
)
|
||||||
|
if len(med.hooks) == 0 {
|
||||||
|
affected, err = med.sqlExec(ctx)
|
||||||
|
} else {
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutation, ok := m.(*MaintenanceEntryMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
med.mutation = mutation
|
||||||
|
affected, err = med.sqlExec(ctx)
|
||||||
|
mutation.done = true
|
||||||
|
return affected, err
|
||||||
|
})
|
||||||
|
for i := len(med.hooks) - 1; i >= 0; i-- {
|
||||||
|
if med.hooks[i] == nil {
|
||||||
|
return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||||
|
}
|
||||||
|
mut = med.hooks[i](mut)
|
||||||
|
}
|
||||||
|
if _, err := mut.Mutate(ctx, med.mutation); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return affected, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (med *MaintenanceEntryDelete) ExecX(ctx context.Context) int {
|
||||||
|
n, err := med.Exec(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (med *MaintenanceEntryDelete) sqlExec(ctx context.Context) (int, error) {
|
||||||
|
_spec := &sqlgraph.DeleteSpec{
|
||||||
|
Node: &sqlgraph.NodeSpec{
|
||||||
|
Table: maintenanceentry.Table,
|
||||||
|
ID: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeUUID,
|
||||||
|
Column: maintenanceentry.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if ps := med.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
affected, err := sqlgraph.DeleteNodes(ctx, med.driver, _spec)
|
||||||
|
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return affected, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// MaintenanceEntryDeleteOne is the builder for deleting a single MaintenanceEntry entity.
|
||||||
|
type MaintenanceEntryDeleteOne struct {
|
||||||
|
med *MaintenanceEntryDelete
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query.
|
||||||
|
func (medo *MaintenanceEntryDeleteOne) Exec(ctx context.Context) error {
|
||||||
|
n, err := medo.med.Exec(ctx)
|
||||||
|
switch {
|
||||||
|
case err != nil:
|
||||||
|
return err
|
||||||
|
case n == 0:
|
||||||
|
return &NotFoundError{maintenanceentry.Label}
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (medo *MaintenanceEntryDeleteOne) ExecX(ctx context.Context) {
|
||||||
|
medo.med.ExecX(ctx)
|
||||||
|
}
|
622
backend/internal/data/ent/maintenanceentry_query.go
Normal file
622
backend/internal/data/ent/maintenanceentry_query.go
Normal file
|
@ -0,0 +1,622 @@
|
||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"math"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"github.com/hay-kot/homebox/backend/internal/data/ent/item"
|
||||||
|
"github.com/hay-kot/homebox/backend/internal/data/ent/maintenanceentry"
|
||||||
|
"github.com/hay-kot/homebox/backend/internal/data/ent/predicate"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MaintenanceEntryQuery is the builder for querying MaintenanceEntry entities.
|
||||||
|
type MaintenanceEntryQuery struct {
|
||||||
|
config
|
||||||
|
limit *int
|
||||||
|
offset *int
|
||||||
|
unique *bool
|
||||||
|
order []OrderFunc
|
||||||
|
fields []string
|
||||||
|
predicates []predicate.MaintenanceEntry
|
||||||
|
withItem *ItemQuery
|
||||||
|
// intermediate query (i.e. traversal path).
|
||||||
|
sql *sql.Selector
|
||||||
|
path func(context.Context) (*sql.Selector, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where adds a new predicate for the MaintenanceEntryQuery builder.
|
||||||
|
func (meq *MaintenanceEntryQuery) Where(ps ...predicate.MaintenanceEntry) *MaintenanceEntryQuery {
|
||||||
|
meq.predicates = append(meq.predicates, ps...)
|
||||||
|
return meq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Limit adds a limit step to the query.
|
||||||
|
func (meq *MaintenanceEntryQuery) Limit(limit int) *MaintenanceEntryQuery {
|
||||||
|
meq.limit = &limit
|
||||||
|
return meq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Offset adds an offset step to the query.
|
||||||
|
func (meq *MaintenanceEntryQuery) Offset(offset int) *MaintenanceEntryQuery {
|
||||||
|
meq.offset = &offset
|
||||||
|
return meq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unique configures the query builder to filter duplicate records on query.
|
||||||
|
// By default, unique is set to true, and can be disabled using this method.
|
||||||
|
func (meq *MaintenanceEntryQuery) Unique(unique bool) *MaintenanceEntryQuery {
|
||||||
|
meq.unique = &unique
|
||||||
|
return meq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Order adds an order step to the query.
|
||||||
|
func (meq *MaintenanceEntryQuery) Order(o ...OrderFunc) *MaintenanceEntryQuery {
|
||||||
|
meq.order = append(meq.order, o...)
|
||||||
|
return meq
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryItem chains the current query on the "item" edge.
|
||||||
|
func (meq *MaintenanceEntryQuery) QueryItem() *ItemQuery {
|
||||||
|
query := &ItemQuery{config: meq.config}
|
||||||
|
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||||
|
if err := meq.prepareQuery(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
selector := meq.sqlQuery(ctx)
|
||||||
|
if err := selector.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(maintenanceentry.Table, maintenanceentry.FieldID, selector),
|
||||||
|
sqlgraph.To(item.Table, item.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, maintenanceentry.ItemTable, maintenanceentry.ItemColumn),
|
||||||
|
)
|
||||||
|
fromU = sqlgraph.SetNeighbors(meq.driver.Dialect(), step)
|
||||||
|
return fromU, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// First returns the first MaintenanceEntry entity from the query.
|
||||||
|
// Returns a *NotFoundError when no MaintenanceEntry was found.
|
||||||
|
func (meq *MaintenanceEntryQuery) First(ctx context.Context) (*MaintenanceEntry, error) {
|
||||||
|
nodes, err := meq.Limit(1).All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(nodes) == 0 {
|
||||||
|
return nil, &NotFoundError{maintenanceentry.Label}
|
||||||
|
}
|
||||||
|
return nodes[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstX is like First, but panics if an error occurs.
|
||||||
|
func (meq *MaintenanceEntryQuery) FirstX(ctx context.Context) *MaintenanceEntry {
|
||||||
|
node, err := meq.First(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstID returns the first MaintenanceEntry ID from the query.
|
||||||
|
// Returns a *NotFoundError when no MaintenanceEntry ID was found.
|
||||||
|
func (meq *MaintenanceEntryQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) {
|
||||||
|
var ids []uuid.UUID
|
||||||
|
if ids, err = meq.Limit(1).IDs(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(ids) == 0 {
|
||||||
|
err = &NotFoundError{maintenanceentry.Label}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return ids[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||||
|
func (meq *MaintenanceEntryQuery) FirstIDX(ctx context.Context) uuid.UUID {
|
||||||
|
id, err := meq.FirstID(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only returns a single MaintenanceEntry entity found by the query, ensuring it only returns one.
|
||||||
|
// Returns a *NotSingularError when more than one MaintenanceEntry entity is found.
|
||||||
|
// Returns a *NotFoundError when no MaintenanceEntry entities are found.
|
||||||
|
func (meq *MaintenanceEntryQuery) Only(ctx context.Context) (*MaintenanceEntry, error) {
|
||||||
|
nodes, err := meq.Limit(2).All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
switch len(nodes) {
|
||||||
|
case 1:
|
||||||
|
return nodes[0], nil
|
||||||
|
case 0:
|
||||||
|
return nil, &NotFoundError{maintenanceentry.Label}
|
||||||
|
default:
|
||||||
|
return nil, &NotSingularError{maintenanceentry.Label}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyX is like Only, but panics if an error occurs.
|
||||||
|
func (meq *MaintenanceEntryQuery) OnlyX(ctx context.Context) *MaintenanceEntry {
|
||||||
|
node, err := meq.Only(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyID is like Only, but returns the only MaintenanceEntry ID in the query.
|
||||||
|
// Returns a *NotSingularError when more than one MaintenanceEntry ID is found.
|
||||||
|
// Returns a *NotFoundError when no entities are found.
|
||||||
|
func (meq *MaintenanceEntryQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) {
|
||||||
|
var ids []uuid.UUID
|
||||||
|
if ids, err = meq.Limit(2).IDs(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(ids) {
|
||||||
|
case 1:
|
||||||
|
id = ids[0]
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{maintenanceentry.Label}
|
||||||
|
default:
|
||||||
|
err = &NotSingularError{maintenanceentry.Label}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||||
|
func (meq *MaintenanceEntryQuery) OnlyIDX(ctx context.Context) uuid.UUID {
|
||||||
|
id, err := meq.OnlyID(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// All executes the query and returns a list of MaintenanceEntries.
|
||||||
|
func (meq *MaintenanceEntryQuery) All(ctx context.Context) ([]*MaintenanceEntry, error) {
|
||||||
|
if err := meq.prepareQuery(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return meq.sqlAll(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AllX is like All, but panics if an error occurs.
|
||||||
|
func (meq *MaintenanceEntryQuery) AllX(ctx context.Context) []*MaintenanceEntry {
|
||||||
|
nodes, err := meq.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return nodes
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDs executes the query and returns a list of MaintenanceEntry IDs.
|
||||||
|
func (meq *MaintenanceEntryQuery) IDs(ctx context.Context) ([]uuid.UUID, error) {
|
||||||
|
var ids []uuid.UUID
|
||||||
|
if err := meq.Select(maintenanceentry.FieldID).Scan(ctx, &ids); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return ids, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDsX is like IDs, but panics if an error occurs.
|
||||||
|
func (meq *MaintenanceEntryQuery) IDsX(ctx context.Context) []uuid.UUID {
|
||||||
|
ids, err := meq.IDs(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return ids
|
||||||
|
}
|
||||||
|
|
||||||
|
// Count returns the count of the given query.
|
||||||
|
func (meq *MaintenanceEntryQuery) Count(ctx context.Context) (int, error) {
|
||||||
|
if err := meq.prepareQuery(ctx); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return meq.sqlCount(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CountX is like Count, but panics if an error occurs.
|
||||||
|
func (meq *MaintenanceEntryQuery) CountX(ctx context.Context) int {
|
||||||
|
count, err := meq.Count(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exist returns true if the query has elements in the graph.
|
||||||
|
func (meq *MaintenanceEntryQuery) Exist(ctx context.Context) (bool, error) {
|
||||||
|
if err := meq.prepareQuery(ctx); err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
return meq.sqlExist(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExistX is like Exist, but panics if an error occurs.
|
||||||
|
func (meq *MaintenanceEntryQuery) ExistX(ctx context.Context) bool {
|
||||||
|
exist, err := meq.Exist(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return exist
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clone returns a duplicate of the MaintenanceEntryQuery builder, including all associated steps. It can be
|
||||||
|
// used to prepare common query builders and use them differently after the clone is made.
|
||||||
|
func (meq *MaintenanceEntryQuery) Clone() *MaintenanceEntryQuery {
|
||||||
|
if meq == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &MaintenanceEntryQuery{
|
||||||
|
config: meq.config,
|
||||||
|
limit: meq.limit,
|
||||||
|
offset: meq.offset,
|
||||||
|
order: append([]OrderFunc{}, meq.order...),
|
||||||
|
predicates: append([]predicate.MaintenanceEntry{}, meq.predicates...),
|
||||||
|
withItem: meq.withItem.Clone(),
|
||||||
|
// clone intermediate query.
|
||||||
|
sql: meq.sql.Clone(),
|
||||||
|
path: meq.path,
|
||||||
|
unique: meq.unique,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithItem tells the query-builder to eager-load the nodes that are connected to
|
||||||
|
// the "item" edge. The optional arguments are used to configure the query builder of the edge.
|
||||||
|
func (meq *MaintenanceEntryQuery) WithItem(opts ...func(*ItemQuery)) *MaintenanceEntryQuery {
|
||||||
|
query := &ItemQuery{config: meq.config}
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(query)
|
||||||
|
}
|
||||||
|
meq.withItem = query
|
||||||
|
return meq
|
||||||
|
}
|
||||||
|
|
||||||
|
// GroupBy is used to group vertices by one or more fields/columns.
|
||||||
|
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// var v []struct {
|
||||||
|
// CreatedAt time.Time `json:"created_at,omitempty"`
|
||||||
|
// Count int `json:"count,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.MaintenanceEntry.Query().
|
||||||
|
// GroupBy(maintenanceentry.FieldCreatedAt).
|
||||||
|
// Aggregate(ent.Count()).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func (meq *MaintenanceEntryQuery) GroupBy(field string, fields ...string) *MaintenanceEntryGroupBy {
|
||||||
|
grbuild := &MaintenanceEntryGroupBy{config: meq.config}
|
||||||
|
grbuild.fields = append([]string{field}, fields...)
|
||||||
|
grbuild.path = func(ctx context.Context) (prev *sql.Selector, err error) {
|
||||||
|
if err := meq.prepareQuery(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return meq.sqlQuery(ctx), nil
|
||||||
|
}
|
||||||
|
grbuild.label = maintenanceentry.Label
|
||||||
|
grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan
|
||||||
|
return grbuild
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select allows the selection one or more fields/columns for the given query,
|
||||||
|
// instead of selecting all fields in the entity.
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// var v []struct {
|
||||||
|
// CreatedAt time.Time `json:"created_at,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.MaintenanceEntry.Query().
|
||||||
|
// Select(maintenanceentry.FieldCreatedAt).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
func (meq *MaintenanceEntryQuery) Select(fields ...string) *MaintenanceEntrySelect {
|
||||||
|
meq.fields = append(meq.fields, fields...)
|
||||||
|
selbuild := &MaintenanceEntrySelect{MaintenanceEntryQuery: meq}
|
||||||
|
selbuild.label = maintenanceentry.Label
|
||||||
|
selbuild.flds, selbuild.scan = &meq.fields, selbuild.Scan
|
||||||
|
return selbuild
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate returns a MaintenanceEntrySelect configured with the given aggregations.
|
||||||
|
func (meq *MaintenanceEntryQuery) Aggregate(fns ...AggregateFunc) *MaintenanceEntrySelect {
|
||||||
|
return meq.Select().Aggregate(fns...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (meq *MaintenanceEntryQuery) prepareQuery(ctx context.Context) error {
|
||||||
|
for _, f := range meq.fields {
|
||||||
|
if !maintenanceentry.ValidColumn(f) {
|
||||||
|
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if meq.path != nil {
|
||||||
|
prev, err := meq.path(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
meq.sql = prev
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (meq *MaintenanceEntryQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*MaintenanceEntry, error) {
|
||||||
|
var (
|
||||||
|
nodes = []*MaintenanceEntry{}
|
||||||
|
_spec = meq.querySpec()
|
||||||
|
loadedTypes = [1]bool{
|
||||||
|
meq.withItem != nil,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||||
|
return (*MaintenanceEntry).scanValues(nil, columns)
|
||||||
|
}
|
||||||
|
_spec.Assign = func(columns []string, values []any) error {
|
||||||
|
node := &MaintenanceEntry{config: meq.config}
|
||||||
|
nodes = append(nodes, node)
|
||||||
|
node.Edges.loadedTypes = loadedTypes
|
||||||
|
return node.assignValues(columns, values)
|
||||||
|
}
|
||||||
|
for i := range hooks {
|
||||||
|
hooks[i](ctx, _spec)
|
||||||
|
}
|
||||||
|
if err := sqlgraph.QueryNodes(ctx, meq.driver, _spec); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(nodes) == 0 {
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
if query := meq.withItem; query != nil {
|
||||||
|
if err := meq.loadItem(ctx, query, nodes, nil,
|
||||||
|
func(n *MaintenanceEntry, e *Item) { n.Edges.Item = e }); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (meq *MaintenanceEntryQuery) loadItem(ctx context.Context, query *ItemQuery, nodes []*MaintenanceEntry, init func(*MaintenanceEntry), assign func(*MaintenanceEntry, *Item)) error {
|
||||||
|
ids := make([]uuid.UUID, 0, len(nodes))
|
||||||
|
nodeids := make(map[uuid.UUID][]*MaintenanceEntry)
|
||||||
|
for i := range nodes {
|
||||||
|
fk := nodes[i].ItemID
|
||||||
|
if _, ok := nodeids[fk]; !ok {
|
||||||
|
ids = append(ids, fk)
|
||||||
|
}
|
||||||
|
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||||
|
}
|
||||||
|
query.Where(item.IDIn(ids...))
|
||||||
|
neighbors, err := query.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, n := range neighbors {
|
||||||
|
nodes, ok := nodeids[n.ID]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf(`unexpected foreign-key "item_id" returned %v`, n.ID)
|
||||||
|
}
|
||||||
|
for i := range nodes {
|
||||||
|
assign(nodes[i], n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (meq *MaintenanceEntryQuery) sqlCount(ctx context.Context) (int, error) {
|
||||||
|
_spec := meq.querySpec()
|
||||||
|
_spec.Node.Columns = meq.fields
|
||||||
|
if len(meq.fields) > 0 {
|
||||||
|
_spec.Unique = meq.unique != nil && *meq.unique
|
||||||
|
}
|
||||||
|
return sqlgraph.CountNodes(ctx, meq.driver, _spec)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (meq *MaintenanceEntryQuery) sqlExist(ctx context.Context) (bool, error) {
|
||||||
|
switch _, err := meq.FirstID(ctx); {
|
||||||
|
case IsNotFound(err):
|
||||||
|
return false, nil
|
||||||
|
case err != nil:
|
||||||
|
return false, fmt.Errorf("ent: check existence: %w", err)
|
||||||
|
default:
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (meq *MaintenanceEntryQuery) querySpec() *sqlgraph.QuerySpec {
|
||||||
|
_spec := &sqlgraph.QuerySpec{
|
||||||
|
Node: &sqlgraph.NodeSpec{
|
||||||
|
Table: maintenanceentry.Table,
|
||||||
|
Columns: maintenanceentry.Columns,
|
||||||
|
ID: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeUUID,
|
||||||
|
Column: maintenanceentry.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
From: meq.sql,
|
||||||
|
Unique: true,
|
||||||
|
}
|
||||||
|
if unique := meq.unique; unique != nil {
|
||||||
|
_spec.Unique = *unique
|
||||||
|
}
|
||||||
|
if fields := meq.fields; len(fields) > 0 {
|
||||||
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, maintenanceentry.FieldID)
|
||||||
|
for i := range fields {
|
||||||
|
if fields[i] != maintenanceentry.FieldID {
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ps := meq.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if limit := meq.limit; limit != nil {
|
||||||
|
_spec.Limit = *limit
|
||||||
|
}
|
||||||
|
if offset := meq.offset; offset != nil {
|
||||||
|
_spec.Offset = *offset
|
||||||
|
}
|
||||||
|
if ps := meq.order; len(ps) > 0 {
|
||||||
|
_spec.Order = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return _spec
|
||||||
|
}
|
||||||
|
|
||||||
|
func (meq *MaintenanceEntryQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||||
|
builder := sql.Dialect(meq.driver.Dialect())
|
||||||
|
t1 := builder.Table(maintenanceentry.Table)
|
||||||
|
columns := meq.fields
|
||||||
|
if len(columns) == 0 {
|
||||||
|
columns = maintenanceentry.Columns
|
||||||
|
}
|
||||||
|
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||||
|
if meq.sql != nil {
|
||||||
|
selector = meq.sql
|
||||||
|
selector.Select(selector.Columns(columns...)...)
|
||||||
|
}
|
||||||
|
if meq.unique != nil && *meq.unique {
|
||||||
|
selector.Distinct()
|
||||||
|
}
|
||||||
|
for _, p := range meq.predicates {
|
||||||
|
p(selector)
|
||||||
|
}
|
||||||
|
for _, p := range meq.order {
|
||||||
|
p(selector)
|
||||||
|
}
|
||||||
|
if offset := meq.offset; offset != nil {
|
||||||
|
// limit is mandatory for offset clause. We start
|
||||||
|
// with default value, and override it below if needed.
|
||||||
|
selector.Offset(*offset).Limit(math.MaxInt32)
|
||||||
|
}
|
||||||
|
if limit := meq.limit; limit != nil {
|
||||||
|
selector.Limit(*limit)
|
||||||
|
}
|
||||||
|
return selector
|
||||||
|
}
|
||||||
|
|
||||||
|
// MaintenanceEntryGroupBy is the group-by builder for MaintenanceEntry entities.
|
||||||
|
type MaintenanceEntryGroupBy struct {
|
||||||
|
config
|
||||||
|
selector
|
||||||
|
fields []string
|
||||||
|
fns []AggregateFunc
|
||||||
|
// intermediate query (i.e. traversal path).
|
||||||
|
sql *sql.Selector
|
||||||
|
path func(context.Context) (*sql.Selector, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the group-by query.
|
||||||
|
func (megb *MaintenanceEntryGroupBy) Aggregate(fns ...AggregateFunc) *MaintenanceEntryGroupBy {
|
||||||
|
megb.fns = append(megb.fns, fns...)
|
||||||
|
return megb
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the group-by query and scans the result into the given value.
|
||||||
|
func (megb *MaintenanceEntryGroupBy) Scan(ctx context.Context, v any) error {
|
||||||
|
query, err := megb.path(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
megb.sql = query
|
||||||
|
return megb.sqlScan(ctx, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (megb *MaintenanceEntryGroupBy) sqlScan(ctx context.Context, v any) error {
|
||||||
|
for _, f := range megb.fields {
|
||||||
|
if !maintenanceentry.ValidColumn(f) {
|
||||||
|
return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
selector := megb.sqlQuery()
|
||||||
|
if err := selector.Err(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
rows := &sql.Rows{}
|
||||||
|
query, args := selector.Query()
|
||||||
|
if err := megb.driver.Query(ctx, query, args, rows); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
return sql.ScanSlice(rows, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (megb *MaintenanceEntryGroupBy) sqlQuery() *sql.Selector {
|
||||||
|
selector := megb.sql.Select()
|
||||||
|
aggregation := make([]string, 0, len(megb.fns))
|
||||||
|
for _, fn := range megb.fns {
|
||||||
|
aggregation = append(aggregation, fn(selector))
|
||||||
|
}
|
||||||
|
if len(selector.SelectedColumns()) == 0 {
|
||||||
|
columns := make([]string, 0, len(megb.fields)+len(megb.fns))
|
||||||
|
for _, f := range megb.fields {
|
||||||
|
columns = append(columns, selector.C(f))
|
||||||
|
}
|
||||||
|
columns = append(columns, aggregation...)
|
||||||
|
selector.Select(columns...)
|
||||||
|
}
|
||||||
|
return selector.GroupBy(selector.Columns(megb.fields...)...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MaintenanceEntrySelect is the builder for selecting fields of MaintenanceEntry entities.
|
||||||
|
type MaintenanceEntrySelect struct {
|
||||||
|
*MaintenanceEntryQuery
|
||||||
|
selector
|
||||||
|
// intermediate query (i.e. traversal path).
|
||||||
|
sql *sql.Selector
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the selector query.
|
||||||
|
func (mes *MaintenanceEntrySelect) Aggregate(fns ...AggregateFunc) *MaintenanceEntrySelect {
|
||||||
|
mes.fns = append(mes.fns, fns...)
|
||||||
|
return mes
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the selector query and scans the result into the given value.
|
||||||
|
func (mes *MaintenanceEntrySelect) Scan(ctx context.Context, v any) error {
|
||||||
|
if err := mes.prepareQuery(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
mes.sql = mes.MaintenanceEntryQuery.sqlQuery(ctx)
|
||||||
|
return mes.sqlScan(ctx, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mes *MaintenanceEntrySelect) sqlScan(ctx context.Context, v any) error {
|
||||||
|
aggregation := make([]string, 0, len(mes.fns))
|
||||||
|
for _, fn := range mes.fns {
|
||||||
|
aggregation = append(aggregation, fn(mes.sql))
|
||||||
|
}
|
||||||
|
switch n := len(*mes.selector.flds); {
|
||||||
|
case n == 0 && len(aggregation) > 0:
|
||||||
|
mes.sql.Select(aggregation...)
|
||||||
|
case n != 0 && len(aggregation) > 0:
|
||||||
|
mes.sql.AppendSelect(aggregation...)
|
||||||
|
}
|
||||||
|
rows := &sql.Rows{}
|
||||||
|
query, args := mes.sql.Query()
|
||||||
|
if err := mes.driver.Query(ctx, query, args, rows); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
return sql.ScanSlice(rows, v)
|
||||||
|
}
|
594
backend/internal/data/ent/maintenanceentry_update.go
Normal file
594
backend/internal/data/ent/maintenanceentry_update.go
Normal file
|
@ -0,0 +1,594 @@
|
||||||
|
// Code generated by ent, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"github.com/hay-kot/homebox/backend/internal/data/ent/item"
|
||||||
|
"github.com/hay-kot/homebox/backend/internal/data/ent/maintenanceentry"
|
||||||
|
"github.com/hay-kot/homebox/backend/internal/data/ent/predicate"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MaintenanceEntryUpdate is the builder for updating MaintenanceEntry entities.
|
||||||
|
type MaintenanceEntryUpdate struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *MaintenanceEntryMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the MaintenanceEntryUpdate builder.
|
||||||
|
func (meu *MaintenanceEntryUpdate) Where(ps ...predicate.MaintenanceEntry) *MaintenanceEntryUpdate {
|
||||||
|
meu.mutation.Where(ps...)
|
||||||
|
return meu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (meu *MaintenanceEntryUpdate) SetUpdatedAt(t time.Time) *MaintenanceEntryUpdate {
|
||||||
|
meu.mutation.SetUpdatedAt(t)
|
||||||
|
return meu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetItemID sets the "item_id" field.
|
||||||
|
func (meu *MaintenanceEntryUpdate) SetItemID(u uuid.UUID) *MaintenanceEntryUpdate {
|
||||||
|
meu.mutation.SetItemID(u)
|
||||||
|
return meu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDate sets the "date" field.
|
||||||
|
func (meu *MaintenanceEntryUpdate) SetDate(t time.Time) *MaintenanceEntryUpdate {
|
||||||
|
meu.mutation.SetDate(t)
|
||||||
|
return meu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableDate sets the "date" field if the given value is not nil.
|
||||||
|
func (meu *MaintenanceEntryUpdate) SetNillableDate(t *time.Time) *MaintenanceEntryUpdate {
|
||||||
|
if t != nil {
|
||||||
|
meu.SetDate(*t)
|
||||||
|
}
|
||||||
|
return meu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetName sets the "name" field.
|
||||||
|
func (meu *MaintenanceEntryUpdate) SetName(s string) *MaintenanceEntryUpdate {
|
||||||
|
meu.mutation.SetName(s)
|
||||||
|
return meu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDescription sets the "description" field.
|
||||||
|
func (meu *MaintenanceEntryUpdate) SetDescription(s string) *MaintenanceEntryUpdate {
|
||||||
|
meu.mutation.SetDescription(s)
|
||||||
|
return meu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
||||||
|
func (meu *MaintenanceEntryUpdate) SetNillableDescription(s *string) *MaintenanceEntryUpdate {
|
||||||
|
if s != nil {
|
||||||
|
meu.SetDescription(*s)
|
||||||
|
}
|
||||||
|
return meu
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearDescription clears the value of the "description" field.
|
||||||
|
func (meu *MaintenanceEntryUpdate) ClearDescription() *MaintenanceEntryUpdate {
|
||||||
|
meu.mutation.ClearDescription()
|
||||||
|
return meu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCost sets the "cost" field.
|
||||||
|
func (meu *MaintenanceEntryUpdate) SetCost(f float64) *MaintenanceEntryUpdate {
|
||||||
|
meu.mutation.ResetCost()
|
||||||
|
meu.mutation.SetCost(f)
|
||||||
|
return meu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableCost sets the "cost" field if the given value is not nil.
|
||||||
|
func (meu *MaintenanceEntryUpdate) SetNillableCost(f *float64) *MaintenanceEntryUpdate {
|
||||||
|
if f != nil {
|
||||||
|
meu.SetCost(*f)
|
||||||
|
}
|
||||||
|
return meu
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddCost adds f to the "cost" field.
|
||||||
|
func (meu *MaintenanceEntryUpdate) AddCost(f float64) *MaintenanceEntryUpdate {
|
||||||
|
meu.mutation.AddCost(f)
|
||||||
|
return meu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetItem sets the "item" edge to the Item entity.
|
||||||
|
func (meu *MaintenanceEntryUpdate) SetItem(i *Item) *MaintenanceEntryUpdate {
|
||||||
|
return meu.SetItemID(i.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the MaintenanceEntryMutation object of the builder.
|
||||||
|
func (meu *MaintenanceEntryUpdate) Mutation() *MaintenanceEntryMutation {
|
||||||
|
return meu.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearItem clears the "item" edge to the Item entity.
|
||||||
|
func (meu *MaintenanceEntryUpdate) ClearItem() *MaintenanceEntryUpdate {
|
||||||
|
meu.mutation.ClearItem()
|
||||||
|
return meu
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||||
|
func (meu *MaintenanceEntryUpdate) Save(ctx context.Context) (int, error) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
affected int
|
||||||
|
)
|
||||||
|
meu.defaults()
|
||||||
|
if len(meu.hooks) == 0 {
|
||||||
|
if err = meu.check(); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
affected, err = meu.sqlSave(ctx)
|
||||||
|
} else {
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutation, ok := m.(*MaintenanceEntryMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
if err = meu.check(); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
meu.mutation = mutation
|
||||||
|
affected, err = meu.sqlSave(ctx)
|
||||||
|
mutation.done = true
|
||||||
|
return affected, err
|
||||||
|
})
|
||||||
|
for i := len(meu.hooks) - 1; i >= 0; i-- {
|
||||||
|
if meu.hooks[i] == nil {
|
||||||
|
return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||||
|
}
|
||||||
|
mut = meu.hooks[i](mut)
|
||||||
|
}
|
||||||
|
if _, err := mut.Mutate(ctx, meu.mutation); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return affected, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (meu *MaintenanceEntryUpdate) SaveX(ctx context.Context) int {
|
||||||
|
affected, err := meu.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return affected
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (meu *MaintenanceEntryUpdate) Exec(ctx context.Context) error {
|
||||||
|
_, err := meu.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (meu *MaintenanceEntryUpdate) ExecX(ctx context.Context) {
|
||||||
|
if err := meu.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (meu *MaintenanceEntryUpdate) defaults() {
|
||||||
|
if _, ok := meu.mutation.UpdatedAt(); !ok {
|
||||||
|
v := maintenanceentry.UpdateDefaultUpdatedAt()
|
||||||
|
meu.mutation.SetUpdatedAt(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (meu *MaintenanceEntryUpdate) check() error {
|
||||||
|
if v, ok := meu.mutation.Name(); ok {
|
||||||
|
if err := maintenanceentry.NameValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "MaintenanceEntry.name": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := meu.mutation.Description(); ok {
|
||||||
|
if err := maintenanceentry.DescriptionValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "MaintenanceEntry.description": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, ok := meu.mutation.ItemID(); meu.mutation.ItemCleared() && !ok {
|
||||||
|
return errors.New(`ent: clearing a required unique edge "MaintenanceEntry.item"`)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (meu *MaintenanceEntryUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||||
|
_spec := &sqlgraph.UpdateSpec{
|
||||||
|
Node: &sqlgraph.NodeSpec{
|
||||||
|
Table: maintenanceentry.Table,
|
||||||
|
Columns: maintenanceentry.Columns,
|
||||||
|
ID: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeUUID,
|
||||||
|
Column: maintenanceentry.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if ps := meu.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if value, ok := meu.mutation.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(maintenanceentry.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if value, ok := meu.mutation.Date(); ok {
|
||||||
|
_spec.SetField(maintenanceentry.FieldDate, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if value, ok := meu.mutation.Name(); ok {
|
||||||
|
_spec.SetField(maintenanceentry.FieldName, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := meu.mutation.Description(); ok {
|
||||||
|
_spec.SetField(maintenanceentry.FieldDescription, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if meu.mutation.DescriptionCleared() {
|
||||||
|
_spec.ClearField(maintenanceentry.FieldDescription, field.TypeString)
|
||||||
|
}
|
||||||
|
if value, ok := meu.mutation.Cost(); ok {
|
||||||
|
_spec.SetField(maintenanceentry.FieldCost, field.TypeFloat64, value)
|
||||||
|
}
|
||||||
|
if value, ok := meu.mutation.AddedCost(); ok {
|
||||||
|
_spec.AddField(maintenanceentry.FieldCost, field.TypeFloat64, value)
|
||||||
|
}
|
||||||
|
if meu.mutation.ItemCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: maintenanceentry.ItemTable,
|
||||||
|
Columns: []string{maintenanceentry.ItemColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeUUID,
|
||||||
|
Column: item.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := meu.mutation.ItemIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: maintenanceentry.ItemTable,
|
||||||
|
Columns: []string{maintenanceentry.ItemColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeUUID,
|
||||||
|
Column: item.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
if n, err = sqlgraph.UpdateNodes(ctx, meu.driver, _spec); err != nil {
|
||||||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||||
|
err = &NotFoundError{maintenanceentry.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return n, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// MaintenanceEntryUpdateOne is the builder for updating a single MaintenanceEntry entity.
|
||||||
|
type MaintenanceEntryUpdateOne struct {
|
||||||
|
config
|
||||||
|
fields []string
|
||||||
|
hooks []Hook
|
||||||
|
mutation *MaintenanceEntryMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUpdatedAt sets the "updated_at" field.
|
||||||
|
func (meuo *MaintenanceEntryUpdateOne) SetUpdatedAt(t time.Time) *MaintenanceEntryUpdateOne {
|
||||||
|
meuo.mutation.SetUpdatedAt(t)
|
||||||
|
return meuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetItemID sets the "item_id" field.
|
||||||
|
func (meuo *MaintenanceEntryUpdateOne) SetItemID(u uuid.UUID) *MaintenanceEntryUpdateOne {
|
||||||
|
meuo.mutation.SetItemID(u)
|
||||||
|
return meuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDate sets the "date" field.
|
||||||
|
func (meuo *MaintenanceEntryUpdateOne) SetDate(t time.Time) *MaintenanceEntryUpdateOne {
|
||||||
|
meuo.mutation.SetDate(t)
|
||||||
|
return meuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableDate sets the "date" field if the given value is not nil.
|
||||||
|
func (meuo *MaintenanceEntryUpdateOne) SetNillableDate(t *time.Time) *MaintenanceEntryUpdateOne {
|
||||||
|
if t != nil {
|
||||||
|
meuo.SetDate(*t)
|
||||||
|
}
|
||||||
|
return meuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetName sets the "name" field.
|
||||||
|
func (meuo *MaintenanceEntryUpdateOne) SetName(s string) *MaintenanceEntryUpdateOne {
|
||||||
|
meuo.mutation.SetName(s)
|
||||||
|
return meuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDescription sets the "description" field.
|
||||||
|
func (meuo *MaintenanceEntryUpdateOne) SetDescription(s string) *MaintenanceEntryUpdateOne {
|
||||||
|
meuo.mutation.SetDescription(s)
|
||||||
|
return meuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
||||||
|
func (meuo *MaintenanceEntryUpdateOne) SetNillableDescription(s *string) *MaintenanceEntryUpdateOne {
|
||||||
|
if s != nil {
|
||||||
|
meuo.SetDescription(*s)
|
||||||
|
}
|
||||||
|
return meuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearDescription clears the value of the "description" field.
|
||||||
|
func (meuo *MaintenanceEntryUpdateOne) ClearDescription() *MaintenanceEntryUpdateOne {
|
||||||
|
meuo.mutation.ClearDescription()
|
||||||
|
return meuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCost sets the "cost" field.
|
||||||
|
func (meuo *MaintenanceEntryUpdateOne) SetCost(f float64) *MaintenanceEntryUpdateOne {
|
||||||
|
meuo.mutation.ResetCost()
|
||||||
|
meuo.mutation.SetCost(f)
|
||||||
|
return meuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableCost sets the "cost" field if the given value is not nil.
|
||||||
|
func (meuo *MaintenanceEntryUpdateOne) SetNillableCost(f *float64) *MaintenanceEntryUpdateOne {
|
||||||
|
if f != nil {
|
||||||
|
meuo.SetCost(*f)
|
||||||
|
}
|
||||||
|
return meuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddCost adds f to the "cost" field.
|
||||||
|
func (meuo *MaintenanceEntryUpdateOne) AddCost(f float64) *MaintenanceEntryUpdateOne {
|
||||||
|
meuo.mutation.AddCost(f)
|
||||||
|
return meuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetItem sets the "item" edge to the Item entity.
|
||||||
|
func (meuo *MaintenanceEntryUpdateOne) SetItem(i *Item) *MaintenanceEntryUpdateOne {
|
||||||
|
return meuo.SetItemID(i.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the MaintenanceEntryMutation object of the builder.
|
||||||
|
func (meuo *MaintenanceEntryUpdateOne) Mutation() *MaintenanceEntryMutation {
|
||||||
|
return meuo.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearItem clears the "item" edge to the Item entity.
|
||||||
|
func (meuo *MaintenanceEntryUpdateOne) ClearItem() *MaintenanceEntryUpdateOne {
|
||||||
|
meuo.mutation.ClearItem()
|
||||||
|
return meuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||||
|
// The default is selecting all fields defined in the entity schema.
|
||||||
|
func (meuo *MaintenanceEntryUpdateOne) Select(field string, fields ...string) *MaintenanceEntryUpdateOne {
|
||||||
|
meuo.fields = append([]string{field}, fields...)
|
||||||
|
return meuo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the updated MaintenanceEntry entity.
|
||||||
|
func (meuo *MaintenanceEntryUpdateOne) Save(ctx context.Context) (*MaintenanceEntry, error) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
node *MaintenanceEntry
|
||||||
|
)
|
||||||
|
meuo.defaults()
|
||||||
|
if len(meuo.hooks) == 0 {
|
||||||
|
if err = meuo.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
node, err = meuo.sqlSave(ctx)
|
||||||
|
} else {
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutation, ok := m.(*MaintenanceEntryMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
if err = meuo.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
meuo.mutation = mutation
|
||||||
|
node, err = meuo.sqlSave(ctx)
|
||||||
|
mutation.done = true
|
||||||
|
return node, err
|
||||||
|
})
|
||||||
|
for i := len(meuo.hooks) - 1; i >= 0; i-- {
|
||||||
|
if meuo.hooks[i] == nil {
|
||||||
|
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||||
|
}
|
||||||
|
mut = meuo.hooks[i](mut)
|
||||||
|
}
|
||||||
|
v, err := mut.Mutate(ctx, meuo.mutation)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
nv, ok := v.(*MaintenanceEntry)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected node type %T returned from MaintenanceEntryMutation", v)
|
||||||
|
}
|
||||||
|
node = nv
|
||||||
|
}
|
||||||
|
return node, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (meuo *MaintenanceEntryUpdateOne) SaveX(ctx context.Context) *MaintenanceEntry {
|
||||||
|
node, err := meuo.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query on the entity.
|
||||||
|
func (meuo *MaintenanceEntryUpdateOne) Exec(ctx context.Context) error {
|
||||||
|
_, err := meuo.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (meuo *MaintenanceEntryUpdateOne) ExecX(ctx context.Context) {
|
||||||
|
if err := meuo.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (meuo *MaintenanceEntryUpdateOne) defaults() {
|
||||||
|
if _, ok := meuo.mutation.UpdatedAt(); !ok {
|
||||||
|
v := maintenanceentry.UpdateDefaultUpdatedAt()
|
||||||
|
meuo.mutation.SetUpdatedAt(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (meuo *MaintenanceEntryUpdateOne) check() error {
|
||||||
|
if v, ok := meuo.mutation.Name(); ok {
|
||||||
|
if err := maintenanceentry.NameValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "MaintenanceEntry.name": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := meuo.mutation.Description(); ok {
|
||||||
|
if err := maintenanceentry.DescriptionValidator(v); err != nil {
|
||||||
|
return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "MaintenanceEntry.description": %w`, err)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, ok := meuo.mutation.ItemID(); meuo.mutation.ItemCleared() && !ok {
|
||||||
|
return errors.New(`ent: clearing a required unique edge "MaintenanceEntry.item"`)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (meuo *MaintenanceEntryUpdateOne) sqlSave(ctx context.Context) (_node *MaintenanceEntry, err error) {
|
||||||
|
_spec := &sqlgraph.UpdateSpec{
|
||||||
|
Node: &sqlgraph.NodeSpec{
|
||||||
|
Table: maintenanceentry.Table,
|
||||||
|
Columns: maintenanceentry.Columns,
|
||||||
|
ID: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeUUID,
|
||||||
|
Column: maintenanceentry.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
id, ok := meuo.mutation.ID()
|
||||||
|
if !ok {
|
||||||
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "MaintenanceEntry.id" for update`)}
|
||||||
|
}
|
||||||
|
_spec.Node.ID.Value = id
|
||||||
|
if fields := meuo.fields; len(fields) > 0 {
|
||||||
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, maintenanceentry.FieldID)
|
||||||
|
for _, f := range fields {
|
||||||
|
if !maintenanceentry.ValidColumn(f) {
|
||||||
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||||
|
}
|
||||||
|
if f != maintenanceentry.FieldID {
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ps := meuo.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if value, ok := meuo.mutation.UpdatedAt(); ok {
|
||||||
|
_spec.SetField(maintenanceentry.FieldUpdatedAt, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if value, ok := meuo.mutation.Date(); ok {
|
||||||
|
_spec.SetField(maintenanceentry.FieldDate, field.TypeTime, value)
|
||||||
|
}
|
||||||
|
if value, ok := meuo.mutation.Name(); ok {
|
||||||
|
_spec.SetField(maintenanceentry.FieldName, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if value, ok := meuo.mutation.Description(); ok {
|
||||||
|
_spec.SetField(maintenanceentry.FieldDescription, field.TypeString, value)
|
||||||
|
}
|
||||||
|
if meuo.mutation.DescriptionCleared() {
|
||||||
|
_spec.ClearField(maintenanceentry.FieldDescription, field.TypeString)
|
||||||
|
}
|
||||||
|
if value, ok := meuo.mutation.Cost(); ok {
|
||||||
|
_spec.SetField(maintenanceentry.FieldCost, field.TypeFloat64, value)
|
||||||
|
}
|
||||||
|
if value, ok := meuo.mutation.AddedCost(); ok {
|
||||||
|
_spec.AddField(maintenanceentry.FieldCost, field.TypeFloat64, value)
|
||||||
|
}
|
||||||
|
if meuo.mutation.ItemCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: maintenanceentry.ItemTable,
|
||||||
|
Columns: []string{maintenanceentry.ItemColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeUUID,
|
||||||
|
Column: item.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := meuo.mutation.ItemIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: maintenanceentry.ItemTable,
|
||||||
|
Columns: []string{maintenanceentry.ItemColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeUUID,
|
||||||
|
Column: item.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
_node = &MaintenanceEntry{config: meuo.config}
|
||||||
|
_spec.Assign = _node.assignValues
|
||||||
|
_spec.ScanValues = _node.scanValues
|
||||||
|
if err = sqlgraph.UpdateNode(ctx, meuo.driver, _spec); err != nil {
|
||||||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||||
|
err = &NotFoundError{maintenanceentry.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return _node, nil
|
||||||
|
}
|
|
@ -53,7 +53,7 @@ var (
|
||||||
Symbol: "auth_roles_auth_tokens_roles",
|
Symbol: "auth_roles_auth_tokens_roles",
|
||||||
Columns: []*schema.Column{AuthRolesColumns[2]},
|
Columns: []*schema.Column{AuthRolesColumns[2]},
|
||||||
RefColumns: []*schema.Column{AuthTokensColumns[0]},
|
RefColumns: []*schema.Column{AuthTokensColumns[0]},
|
||||||
OnDelete: schema.SetNull,
|
OnDelete: schema.Cascade,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -110,37 +110,6 @@ var (
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
// DocumentTokensColumns holds the columns for the "document_tokens" table.
|
|
||||||
DocumentTokensColumns = []*schema.Column{
|
|
||||||
{Name: "id", Type: field.TypeUUID},
|
|
||||||
{Name: "created_at", Type: field.TypeTime},
|
|
||||||
{Name: "updated_at", Type: field.TypeTime},
|
|
||||||
{Name: "token", Type: field.TypeBytes, Unique: true},
|
|
||||||
{Name: "uses", Type: field.TypeInt, Default: 1},
|
|
||||||
{Name: "expires_at", Type: field.TypeTime},
|
|
||||||
{Name: "document_document_tokens", Type: field.TypeUUID, Nullable: true},
|
|
||||||
}
|
|
||||||
// DocumentTokensTable holds the schema information for the "document_tokens" table.
|
|
||||||
DocumentTokensTable = &schema.Table{
|
|
||||||
Name: "document_tokens",
|
|
||||||
Columns: DocumentTokensColumns,
|
|
||||||
PrimaryKey: []*schema.Column{DocumentTokensColumns[0]},
|
|
||||||
ForeignKeys: []*schema.ForeignKey{
|
|
||||||
{
|
|
||||||
Symbol: "document_tokens_documents_document_tokens",
|
|
||||||
Columns: []*schema.Column{DocumentTokensColumns[6]},
|
|
||||||
RefColumns: []*schema.Column{DocumentsColumns[0]},
|
|
||||||
OnDelete: schema.Cascade,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Indexes: []*schema.Index{
|
|
||||||
{
|
|
||||||
Name: "documenttoken_token",
|
|
||||||
Unique: false,
|
|
||||||
Columns: []*schema.Column{DocumentTokensColumns[3]},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
// GroupsColumns holds the columns for the "groups" table.
|
// GroupsColumns holds the columns for the "groups" table.
|
||||||
GroupsColumns = []*schema.Column{
|
GroupsColumns = []*schema.Column{
|
||||||
{Name: "id", Type: field.TypeUUID},
|
{Name: "id", Type: field.TypeUUID},
|
||||||
|
@ -349,6 +318,31 @@ var (
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
// MaintenanceEntriesColumns holds the columns for the "maintenance_entries" table.
|
||||||
|
MaintenanceEntriesColumns = []*schema.Column{
|
||||||
|
{Name: "id", Type: field.TypeUUID},
|
||||||
|
{Name: "created_at", Type: field.TypeTime},
|
||||||
|
{Name: "updated_at", Type: field.TypeTime},
|
||||||
|
{Name: "date", Type: field.TypeTime},
|
||||||
|
{Name: "name", Type: field.TypeString, Size: 255},
|
||||||
|
{Name: "description", Type: field.TypeString, Nullable: true, Size: 2500},
|
||||||
|
{Name: "cost", Type: field.TypeFloat64, Default: 0},
|
||||||
|
{Name: "item_id", Type: field.TypeUUID},
|
||||||
|
}
|
||||||
|
// MaintenanceEntriesTable holds the schema information for the "maintenance_entries" table.
|
||||||
|
MaintenanceEntriesTable = &schema.Table{
|
||||||
|
Name: "maintenance_entries",
|
||||||
|
Columns: MaintenanceEntriesColumns,
|
||||||
|
PrimaryKey: []*schema.Column{MaintenanceEntriesColumns[0]},
|
||||||
|
ForeignKeys: []*schema.ForeignKey{
|
||||||
|
{
|
||||||
|
Symbol: "maintenance_entries_items_maintenance_entries",
|
||||||
|
Columns: []*schema.Column{MaintenanceEntriesColumns[7]},
|
||||||
|
RefColumns: []*schema.Column{ItemsColumns[0]},
|
||||||
|
OnDelete: schema.Cascade,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
// UsersColumns holds the columns for the "users" table.
|
// UsersColumns holds the columns for the "users" table.
|
||||||
UsersColumns = []*schema.Column{
|
UsersColumns = []*schema.Column{
|
||||||
{Name: "id", Type: field.TypeUUID},
|
{Name: "id", Type: field.TypeUUID},
|
||||||
|
@ -408,13 +402,13 @@ var (
|
||||||
AuthRolesTable,
|
AuthRolesTable,
|
||||||
AuthTokensTable,
|
AuthTokensTable,
|
||||||
DocumentsTable,
|
DocumentsTable,
|
||||||
DocumentTokensTable,
|
|
||||||
GroupsTable,
|
GroupsTable,
|
||||||
GroupInvitationTokensTable,
|
GroupInvitationTokensTable,
|
||||||
ItemsTable,
|
ItemsTable,
|
||||||
ItemFieldsTable,
|
ItemFieldsTable,
|
||||||
LabelsTable,
|
LabelsTable,
|
||||||
LocationsTable,
|
LocationsTable,
|
||||||
|
MaintenanceEntriesTable,
|
||||||
UsersTable,
|
UsersTable,
|
||||||
LabelItemsTable,
|
LabelItemsTable,
|
||||||
}
|
}
|
||||||
|
@ -426,7 +420,6 @@ func init() {
|
||||||
AuthRolesTable.ForeignKeys[0].RefTable = AuthTokensTable
|
AuthRolesTable.ForeignKeys[0].RefTable = AuthTokensTable
|
||||||
AuthTokensTable.ForeignKeys[0].RefTable = UsersTable
|
AuthTokensTable.ForeignKeys[0].RefTable = UsersTable
|
||||||
DocumentsTable.ForeignKeys[0].RefTable = GroupsTable
|
DocumentsTable.ForeignKeys[0].RefTable = GroupsTable
|
||||||
DocumentTokensTable.ForeignKeys[0].RefTable = DocumentsTable
|
|
||||||
GroupInvitationTokensTable.ForeignKeys[0].RefTable = GroupsTable
|
GroupInvitationTokensTable.ForeignKeys[0].RefTable = GroupsTable
|
||||||
ItemsTable.ForeignKeys[0].RefTable = GroupsTable
|
ItemsTable.ForeignKeys[0].RefTable = GroupsTable
|
||||||
ItemsTable.ForeignKeys[1].RefTable = ItemsTable
|
ItemsTable.ForeignKeys[1].RefTable = ItemsTable
|
||||||
|
@ -435,6 +428,7 @@ func init() {
|
||||||
LabelsTable.ForeignKeys[0].RefTable = GroupsTable
|
LabelsTable.ForeignKeys[0].RefTable = GroupsTable
|
||||||
LocationsTable.ForeignKeys[0].RefTable = GroupsTable
|
LocationsTable.ForeignKeys[0].RefTable = GroupsTable
|
||||||
LocationsTable.ForeignKeys[1].RefTable = LocationsTable
|
LocationsTable.ForeignKeys[1].RefTable = LocationsTable
|
||||||
|
MaintenanceEntriesTable.ForeignKeys[0].RefTable = ItemsTable
|
||||||
UsersTable.ForeignKeys[0].RefTable = GroupsTable
|
UsersTable.ForeignKeys[0].RefTable = GroupsTable
|
||||||
LabelItemsTable.ForeignKeys[0].RefTable = LabelsTable
|
LabelItemsTable.ForeignKeys[0].RefTable = LabelsTable
|
||||||
LabelItemsTable.ForeignKeys[1].RefTable = ItemsTable
|
LabelItemsTable.ForeignKeys[1].RefTable = ItemsTable
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -18,9 +18,6 @@ type AuthTokens func(*sql.Selector)
|
||||||
// Document is the predicate function for document builders.
|
// Document is the predicate function for document builders.
|
||||||
type Document func(*sql.Selector)
|
type Document func(*sql.Selector)
|
||||||
|
|
||||||
// DocumentToken is the predicate function for documenttoken builders.
|
|
||||||
type DocumentToken func(*sql.Selector)
|
|
||||||
|
|
||||||
// Group is the predicate function for group builders.
|
// Group is the predicate function for group builders.
|
||||||
type Group func(*sql.Selector)
|
type Group func(*sql.Selector)
|
||||||
|
|
||||||
|
@ -39,5 +36,8 @@ type Label func(*sql.Selector)
|
||||||
// Location is the predicate function for location builders.
|
// Location is the predicate function for location builders.
|
||||||
type Location func(*sql.Selector)
|
type Location func(*sql.Selector)
|
||||||
|
|
||||||
|
// MaintenanceEntry is the predicate function for maintenanceentry builders.
|
||||||
|
type MaintenanceEntry func(*sql.Selector)
|
||||||
|
|
||||||
// User is the predicate function for user builders.
|
// User is the predicate function for user builders.
|
||||||
type User func(*sql.Selector)
|
type User func(*sql.Selector)
|
||||||
|
|
|
@ -9,13 +9,13 @@ import (
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/attachment"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/attachment"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/authtokens"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/authtokens"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/document"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/document"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/documenttoken"
|
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/group"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/group"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/groupinvitationtoken"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/groupinvitationtoken"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/item"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/item"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/itemfield"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/itemfield"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/label"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/label"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/location"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/location"
|
||||||
|
"github.com/hay-kot/homebox/backend/internal/data/ent/maintenanceentry"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/schema"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/schema"
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/user"
|
"github.com/hay-kot/homebox/backend/internal/data/ent/user"
|
||||||
)
|
)
|
||||||
|
@ -123,37 +123,6 @@ func init() {
|
||||||
documentDescID := documentMixinFields0[0].Descriptor()
|
documentDescID := documentMixinFields0[0].Descriptor()
|
||||||
// document.DefaultID holds the default value on creation for the id field.
|
// document.DefaultID holds the default value on creation for the id field.
|
||||||
document.DefaultID = documentDescID.Default.(func() uuid.UUID)
|
document.DefaultID = documentDescID.Default.(func() uuid.UUID)
|
||||||
documenttokenMixin := schema.DocumentToken{}.Mixin()
|
|
||||||
documenttokenMixinFields0 := documenttokenMixin[0].Fields()
|
|
||||||
_ = documenttokenMixinFields0
|
|
||||||
documenttokenFields := schema.DocumentToken{}.Fields()
|
|
||||||
_ = documenttokenFields
|
|
||||||
// documenttokenDescCreatedAt is the schema descriptor for created_at field.
|
|
||||||
documenttokenDescCreatedAt := documenttokenMixinFields0[1].Descriptor()
|
|
||||||
// documenttoken.DefaultCreatedAt holds the default value on creation for the created_at field.
|
|
||||||
documenttoken.DefaultCreatedAt = documenttokenDescCreatedAt.Default.(func() time.Time)
|
|
||||||
// documenttokenDescUpdatedAt is the schema descriptor for updated_at field.
|
|
||||||
documenttokenDescUpdatedAt := documenttokenMixinFields0[2].Descriptor()
|
|
||||||
// documenttoken.DefaultUpdatedAt holds the default value on creation for the updated_at field.
|
|
||||||
documenttoken.DefaultUpdatedAt = documenttokenDescUpdatedAt.Default.(func() time.Time)
|
|
||||||
// documenttoken.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
|
|
||||||
documenttoken.UpdateDefaultUpdatedAt = documenttokenDescUpdatedAt.UpdateDefault.(func() time.Time)
|
|
||||||
// documenttokenDescToken is the schema descriptor for token field.
|
|
||||||
documenttokenDescToken := documenttokenFields[0].Descriptor()
|
|
||||||
// documenttoken.TokenValidator is a validator for the "token" field. It is called by the builders before save.
|
|
||||||
documenttoken.TokenValidator = documenttokenDescToken.Validators[0].(func([]byte) error)
|
|
||||||
// documenttokenDescUses is the schema descriptor for uses field.
|
|
||||||
documenttokenDescUses := documenttokenFields[1].Descriptor()
|
|
||||||
// documenttoken.DefaultUses holds the default value on creation for the uses field.
|
|
||||||
documenttoken.DefaultUses = documenttokenDescUses.Default.(int)
|
|
||||||
// documenttokenDescExpiresAt is the schema descriptor for expires_at field.
|
|
||||||
documenttokenDescExpiresAt := documenttokenFields[2].Descriptor()
|
|
||||||
// documenttoken.DefaultExpiresAt holds the default value on creation for the expires_at field.
|
|
||||||
documenttoken.DefaultExpiresAt = documenttokenDescExpiresAt.Default.(func() time.Time)
|
|
||||||
// documenttokenDescID is the schema descriptor for id field.
|
|
||||||
documenttokenDescID := documenttokenMixinFields0[0].Descriptor()
|
|
||||||
// documenttoken.DefaultID holds the default value on creation for the id field.
|
|
||||||
documenttoken.DefaultID = documenttokenDescID.Default.(func() uuid.UUID)
|
|
||||||
groupMixin := schema.Group{}.Mixin()
|
groupMixin := schema.Group{}.Mixin()
|
||||||
groupMixinFields0 := groupMixin[0].Fields()
|
groupMixinFields0 := groupMixin[0].Fields()
|
||||||
_ = groupMixinFields0
|
_ = groupMixinFields0
|
||||||
|
@ -462,6 +431,55 @@ func init() {
|
||||||
locationDescID := locationMixinFields0[0].Descriptor()
|
locationDescID := locationMixinFields0[0].Descriptor()
|
||||||
// location.DefaultID holds the default value on creation for the id field.
|
// location.DefaultID holds the default value on creation for the id field.
|
||||||
location.DefaultID = locationDescID.Default.(func() uuid.UUID)
|
location.DefaultID = locationDescID.Default.(func() uuid.UUID)
|
||||||
|
maintenanceentryMixin := schema.MaintenanceEntry{}.Mixin()
|
||||||
|
maintenanceentryMixinFields0 := maintenanceentryMixin[0].Fields()
|
||||||
|
_ = maintenanceentryMixinFields0
|
||||||
|
maintenanceentryFields := schema.MaintenanceEntry{}.Fields()
|
||||||
|
_ = maintenanceentryFields
|
||||||
|
// maintenanceentryDescCreatedAt is the schema descriptor for created_at field.
|
||||||
|
maintenanceentryDescCreatedAt := maintenanceentryMixinFields0[1].Descriptor()
|
||||||
|
// maintenanceentry.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||||
|
maintenanceentry.DefaultCreatedAt = maintenanceentryDescCreatedAt.Default.(func() time.Time)
|
||||||
|
// maintenanceentryDescUpdatedAt is the schema descriptor for updated_at field.
|
||||||
|
maintenanceentryDescUpdatedAt := maintenanceentryMixinFields0[2].Descriptor()
|
||||||
|
// maintenanceentry.DefaultUpdatedAt holds the default value on creation for the updated_at field.
|
||||||
|
maintenanceentry.DefaultUpdatedAt = maintenanceentryDescUpdatedAt.Default.(func() time.Time)
|
||||||
|
// maintenanceentry.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
|
||||||
|
maintenanceentry.UpdateDefaultUpdatedAt = maintenanceentryDescUpdatedAt.UpdateDefault.(func() time.Time)
|
||||||
|
// maintenanceentryDescDate is the schema descriptor for date field.
|
||||||
|
maintenanceentryDescDate := maintenanceentryFields[1].Descriptor()
|
||||||
|
// maintenanceentry.DefaultDate holds the default value on creation for the date field.
|
||||||
|
maintenanceentry.DefaultDate = maintenanceentryDescDate.Default.(func() time.Time)
|
||||||
|
// maintenanceentryDescName is the schema descriptor for name field.
|
||||||
|
maintenanceentryDescName := maintenanceentryFields[2].Descriptor()
|
||||||
|
// maintenanceentry.NameValidator is a validator for the "name" field. It is called by the builders before save.
|
||||||
|
maintenanceentry.NameValidator = func() func(string) error {
|
||||||
|
validators := maintenanceentryDescName.Validators
|
||||||
|
fns := [...]func(string) error{
|
||||||
|
validators[0].(func(string) error),
|
||||||
|
validators[1].(func(string) error),
|
||||||
|
}
|
||||||
|
return func(name string) error {
|
||||||
|
for _, fn := range fns {
|
||||||
|
if err := fn(name); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
// maintenanceentryDescDescription is the schema descriptor for description field.
|
||||||
|
maintenanceentryDescDescription := maintenanceentryFields[3].Descriptor()
|
||||||
|
// maintenanceentry.DescriptionValidator is a validator for the "description" field. It is called by the builders before save.
|
||||||
|
maintenanceentry.DescriptionValidator = maintenanceentryDescDescription.Validators[0].(func(string) error)
|
||||||
|
// maintenanceentryDescCost is the schema descriptor for cost field.
|
||||||
|
maintenanceentryDescCost := maintenanceentryFields[4].Descriptor()
|
||||||
|
// maintenanceentry.DefaultCost holds the default value on creation for the cost field.
|
||||||
|
maintenanceentry.DefaultCost = maintenanceentryDescCost.Default.(float64)
|
||||||
|
// maintenanceentryDescID is the schema descriptor for id field.
|
||||||
|
maintenanceentryDescID := maintenanceentryMixinFields0[0].Descriptor()
|
||||||
|
// maintenanceentry.DefaultID holds the default value on creation for the id field.
|
||||||
|
maintenanceentry.DefaultID = maintenanceentryDescID.Default.(func() uuid.UUID)
|
||||||
userMixin := schema.User{}.Mixin()
|
userMixin := schema.User{}.Mixin()
|
||||||
userMixinFields0 := userMixin[0].Fields()
|
userMixinFields0 := userMixin[0].Fields()
|
||||||
_ = userMixinFields0
|
_ = userMixinFields0
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"entgo.io/ent"
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/entsql"
|
||||||
"entgo.io/ent/schema/edge"
|
"entgo.io/ent/schema/edge"
|
||||||
"entgo.io/ent/schema/field"
|
"entgo.io/ent/schema/field"
|
||||||
"entgo.io/ent/schema/index"
|
"entgo.io/ent/schema/index"
|
||||||
|
@ -38,7 +39,10 @@ func (AuthTokens) Edges() []ent.Edge {
|
||||||
Ref("auth_tokens").
|
Ref("auth_tokens").
|
||||||
Unique(),
|
Unique(),
|
||||||
edge.To("roles", AuthRoles.Type).
|
edge.To("roles", AuthRoles.Type).
|
||||||
Unique(),
|
Unique().
|
||||||
|
Annotations(entsql.Annotation{
|
||||||
|
OnDelete: entsql.Cascade,
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,10 +38,6 @@ func (Document) Edges() []ent.Edge {
|
||||||
Ref("documents").
|
Ref("documents").
|
||||||
Required().
|
Required().
|
||||||
Unique(),
|
Unique(),
|
||||||
edge.To("document_tokens", DocumentToken.Type).
|
|
||||||
Annotations(entsql.Annotation{
|
|
||||||
OnDelete: entsql.Cascade,
|
|
||||||
}),
|
|
||||||
edge.To("attachments", Attachment.Type).
|
edge.To("attachments", Attachment.Type).
|
||||||
Annotations(entsql.Annotation{
|
Annotations(entsql.Annotation{
|
||||||
OnDelete: entsql.Cascade,
|
OnDelete: entsql.Cascade,
|
||||||
|
|
|
@ -1,50 +0,0 @@
|
||||||
package schema
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"entgo.io/ent"
|
|
||||||
"entgo.io/ent/schema/edge"
|
|
||||||
"entgo.io/ent/schema/field"
|
|
||||||
"entgo.io/ent/schema/index"
|
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/schema/mixins"
|
|
||||||
)
|
|
||||||
|
|
||||||
// DocumentToken holds the schema definition for the DocumentToken entity.
|
|
||||||
type DocumentToken struct {
|
|
||||||
ent.Schema
|
|
||||||
}
|
|
||||||
|
|
||||||
func (DocumentToken) Mixin() []ent.Mixin {
|
|
||||||
return []ent.Mixin{
|
|
||||||
mixins.BaseMixin{},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fields of the DocumentToken.
|
|
||||||
func (DocumentToken) Fields() []ent.Field {
|
|
||||||
return []ent.Field{
|
|
||||||
field.Bytes("token").
|
|
||||||
NotEmpty().
|
|
||||||
Unique(),
|
|
||||||
field.Int("uses").
|
|
||||||
Default(1),
|
|
||||||
field.Time("expires_at").
|
|
||||||
Default(func() time.Time { return time.Now().Add(time.Minute * 10) }),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Edges of the DocumentToken.
|
|
||||||
func (DocumentToken) Edges() []ent.Edge {
|
|
||||||
return []ent.Edge{
|
|
||||||
edge.From("document", Document.Type).
|
|
||||||
Ref("document_tokens").
|
|
||||||
Unique(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (DocumentToken) Indexes() []ent.Index {
|
|
||||||
return []ent.Index{
|
|
||||||
index.Fields("token"),
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -116,6 +116,10 @@ func (Item) Edges() []ent.Edge {
|
||||||
Annotations(entsql.Annotation{
|
Annotations(entsql.Annotation{
|
||||||
OnDelete: entsql.Cascade,
|
OnDelete: entsql.Cascade,
|
||||||
}),
|
}),
|
||||||
|
edge.To("maintenance_entries", MaintenanceEntry.Type).
|
||||||
|
Annotations(entsql.Annotation{
|
||||||
|
OnDelete: entsql.Cascade,
|
||||||
|
}),
|
||||||
edge.To("attachments", Attachment.Type).
|
edge.To("attachments", Attachment.Type).
|
||||||
Annotations(entsql.Annotation{
|
Annotations(entsql.Annotation{
|
||||||
OnDelete: entsql.Cascade,
|
OnDelete: entsql.Cascade,
|
||||||
|
|
48
backend/internal/data/ent/schema/maintenance_entry.go
Normal file
48
backend/internal/data/ent/schema/maintenance_entry.go
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
package schema
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/schema/edge"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"github.com/hay-kot/homebox/backend/internal/data/ent/schema/mixins"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MaintenanceEntry struct {
|
||||||
|
ent.Schema
|
||||||
|
}
|
||||||
|
|
||||||
|
func (MaintenanceEntry) Mixin() []ent.Mixin {
|
||||||
|
return []ent.Mixin{
|
||||||
|
mixins.BaseMixin{},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (MaintenanceEntry) Fields() []ent.Field {
|
||||||
|
return []ent.Field{
|
||||||
|
field.UUID("item_id", uuid.UUID{}),
|
||||||
|
field.Time("date").
|
||||||
|
Default(time.Now),
|
||||||
|
field.String("name").
|
||||||
|
MaxLen(255).
|
||||||
|
NotEmpty(),
|
||||||
|
field.String("description").
|
||||||
|
MaxLen(2500).
|
||||||
|
Optional(),
|
||||||
|
field.Float("cost").
|
||||||
|
Default(0.0),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Edges of the ItemField.
|
||||||
|
func (MaintenanceEntry) Edges() []ent.Edge {
|
||||||
|
return []ent.Edge{
|
||||||
|
edge.From("item", Item.Type).
|
||||||
|
Field("item_id").
|
||||||
|
Ref("maintenance_entries").
|
||||||
|
Required().
|
||||||
|
Unique(),
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,8 +9,13 @@
|
||||||
import "github.com/google/uuid"
|
import "github.com/google/uuid"
|
||||||
{{/* Loop over all nodes and implement the "HasID" interface */}}
|
{{/* Loop over all nodes and implement the "HasID" interface */}}
|
||||||
{{ range $n := $.Nodes }}
|
{{ range $n := $.Nodes }}
|
||||||
|
{{ if not $n.ID }}
|
||||||
|
{{/* If the node doesn't have an ID field, we skip it. */}}
|
||||||
|
{{ continue }}
|
||||||
|
{{ end }}
|
||||||
|
{{/* The "HasID" interface is implemented by the "ID" method. */}}
|
||||||
{{ $receiver := $n.Receiver }}
|
{{ $receiver := $n.Receiver }}
|
||||||
func ({{ $receiver }} *{{ $n.Name }}) GetID() uuid.UUID {
|
func ({{ $receiver }} *{{ $n.Name }}) GetID() {{ $n.ID.Type }} {
|
||||||
return {{ $receiver }}.ID
|
return {{ $receiver }}.ID
|
||||||
}
|
}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
|
@ -20,8 +20,6 @@ type Tx struct {
|
||||||
AuthTokens *AuthTokensClient
|
AuthTokens *AuthTokensClient
|
||||||
// Document is the client for interacting with the Document builders.
|
// Document is the client for interacting with the Document builders.
|
||||||
Document *DocumentClient
|
Document *DocumentClient
|
||||||
// DocumentToken is the client for interacting with the DocumentToken builders.
|
|
||||||
DocumentToken *DocumentTokenClient
|
|
||||||
// Group is the client for interacting with the Group builders.
|
// Group is the client for interacting with the Group builders.
|
||||||
Group *GroupClient
|
Group *GroupClient
|
||||||
// GroupInvitationToken is the client for interacting with the GroupInvitationToken builders.
|
// GroupInvitationToken is the client for interacting with the GroupInvitationToken builders.
|
||||||
|
@ -34,6 +32,8 @@ type Tx struct {
|
||||||
Label *LabelClient
|
Label *LabelClient
|
||||||
// Location is the client for interacting with the Location builders.
|
// Location is the client for interacting with the Location builders.
|
||||||
Location *LocationClient
|
Location *LocationClient
|
||||||
|
// MaintenanceEntry is the client for interacting with the MaintenanceEntry builders.
|
||||||
|
MaintenanceEntry *MaintenanceEntryClient
|
||||||
// User is the client for interacting with the User builders.
|
// User is the client for interacting with the User builders.
|
||||||
User *UserClient
|
User *UserClient
|
||||||
|
|
||||||
|
@ -171,13 +171,13 @@ func (tx *Tx) init() {
|
||||||
tx.AuthRoles = NewAuthRolesClient(tx.config)
|
tx.AuthRoles = NewAuthRolesClient(tx.config)
|
||||||
tx.AuthTokens = NewAuthTokensClient(tx.config)
|
tx.AuthTokens = NewAuthTokensClient(tx.config)
|
||||||
tx.Document = NewDocumentClient(tx.config)
|
tx.Document = NewDocumentClient(tx.config)
|
||||||
tx.DocumentToken = NewDocumentTokenClient(tx.config)
|
|
||||||
tx.Group = NewGroupClient(tx.config)
|
tx.Group = NewGroupClient(tx.config)
|
||||||
tx.GroupInvitationToken = NewGroupInvitationTokenClient(tx.config)
|
tx.GroupInvitationToken = NewGroupInvitationTokenClient(tx.config)
|
||||||
tx.Item = NewItemClient(tx.config)
|
tx.Item = NewItemClient(tx.config)
|
||||||
tx.ItemField = NewItemFieldClient(tx.config)
|
tx.ItemField = NewItemFieldClient(tx.config)
|
||||||
tx.Label = NewLabelClient(tx.config)
|
tx.Label = NewLabelClient(tx.config)
|
||||||
tx.Location = NewLocationClient(tx.config)
|
tx.Location = NewLocationClient(tx.config)
|
||||||
|
tx.MaintenanceEntry = NewMaintenanceEntryClient(tx.config)
|
||||||
tx.User = NewUserClient(tx.config)
|
tx.User = NewUserClient(tx.config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
// go:embed all:migrations
|
//go:embed all:migrations
|
||||||
var Files embed.FS
|
var Files embed.FS
|
||||||
|
|
||||||
// Write writes the embedded migrations to a temporary directory.
|
// Write writes the embedded migrations to a temporary directory.
|
||||||
|
@ -18,7 +18,7 @@ func Write(temp string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
fsDir, err := Files.ReadDir(".")
|
fsDir, err := Files.ReadDir("migrations")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
-- disable the enforcement of foreign-keys constraints
|
||||||
|
PRAGMA foreign_keys = off;
|
||||||
|
DROP TABLE `document_tokens`;
|
||||||
|
-- enable back the enforcement of foreign-keys constraints
|
||||||
|
PRAGMA foreign_keys = on;
|
|
@ -0,0 +1,2 @@
|
||||||
|
-- create "maintenance_entries" table
|
||||||
|
CREATE TABLE `maintenance_entries` (`id` uuid NOT NULL, `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL, `date` datetime NOT NULL, `name` text NOT NULL, `description` text NULL, `cost` real NOT NULL DEFAULT 0, `item_id` uuid NOT NULL, PRIMARY KEY (`id`), CONSTRAINT `maintenance_entries_items_maintenance_entries` FOREIGN KEY (`item_id`) REFERENCES `items` (`id`) ON DELETE CASCADE);
|
|
@ -0,0 +1,16 @@
|
||||||
|
-- disable the enforcement of foreign-keys constraints
|
||||||
|
PRAGMA foreign_keys = off;
|
||||||
|
-- create "new_auth_roles" table
|
||||||
|
CREATE TABLE `new_auth_roles` (`id` integer NOT NULL PRIMARY KEY AUTOINCREMENT, `role` text NOT NULL DEFAULT 'user', `auth_tokens_roles` uuid NULL, CONSTRAINT `auth_roles_auth_tokens_roles` FOREIGN KEY (`auth_tokens_roles`) REFERENCES `auth_tokens` (`id`) ON DELETE CASCADE);
|
||||||
|
-- copy rows from old table "auth_roles" to new temporary table "new_auth_roles"
|
||||||
|
INSERT INTO `new_auth_roles` (`id`, `role`, `auth_tokens_roles`) SELECT `id`, `role`, `auth_tokens_roles` FROM `auth_roles`;
|
||||||
|
-- drop "auth_roles" table after copying rows
|
||||||
|
DROP TABLE `auth_roles`;
|
||||||
|
-- rename temporary table "new_auth_roles" to "auth_roles"
|
||||||
|
ALTER TABLE `new_auth_roles` RENAME TO `auth_roles`;
|
||||||
|
-- create index "auth_roles_auth_tokens_roles_key" to table: "auth_roles"
|
||||||
|
CREATE UNIQUE INDEX `auth_roles_auth_tokens_roles_key` ON `auth_roles` (`auth_tokens_roles`);
|
||||||
|
-- delete where tokens is null
|
||||||
|
DELETE FROM `auth_roles` WHERE `auth_tokens_roles` IS NULL;
|
||||||
|
-- enable back the enforcement of foreign-keys constraints
|
||||||
|
PRAGMA foreign_keys = on;
|
|
@ -1,4 +1,4 @@
|
||||||
h1:oo2QbYbKkbf4oTfkRXqo9XGPp8S76j33WQvDZITv5s8=
|
h1:dn3XsqwgjCxEtpLXmHlt2ALRwg2cZB6m8lg2faxeLXM=
|
||||||
20220929052825_init.sql h1:ZlCqm1wzjDmofeAcSX3jE4h4VcdTNGpRg2eabztDy9Q=
|
20220929052825_init.sql h1:ZlCqm1wzjDmofeAcSX3jE4h4VcdTNGpRg2eabztDy9Q=
|
||||||
20221001210956_group_invitations.sql h1:YQKJFtE39wFOcRNbZQ/d+ZlHwrcfcsZlcv/pLEYdpjw=
|
20221001210956_group_invitations.sql h1:YQKJFtE39wFOcRNbZQ/d+ZlHwrcfcsZlcv/pLEYdpjw=
|
||||||
20221009173029_add_user_roles.sql h1:vWmzAfgEWQeGk0Vn70zfVPCcfEZth3E0JcvyKTjpYyU=
|
20221009173029_add_user_roles.sql h1:vWmzAfgEWQeGk0Vn70zfVPCcfEZth3E0JcvyKTjpYyU=
|
||||||
|
@ -6,3 +6,6 @@ h1:oo2QbYbKkbf4oTfkRXqo9XGPp8S76j33WQvDZITv5s8=
|
||||||
20221101041931_add_archived_field.sql h1:L2WxiOh1svRn817cNURgqnEQg6DIcodZ1twK4tvxW94=
|
20221101041931_add_archived_field.sql h1:L2WxiOh1svRn817cNURgqnEQg6DIcodZ1twK4tvxW94=
|
||||||
20221113012312_add_asset_id_field.sql h1:DjD7e1PS8OfxGBWic8h0nO/X6CNnHEMqQjDCaaQ3M3Q=
|
20221113012312_add_asset_id_field.sql h1:DjD7e1PS8OfxGBWic8h0nO/X6CNnHEMqQjDCaaQ3M3Q=
|
||||||
20221203053132_add_token_roles.sql h1:wFTIh+KBoHfLfy/L0ZmJz4cNXKHdACG9ZK/yvVKjF0M=
|
20221203053132_add_token_roles.sql h1:wFTIh+KBoHfLfy/L0ZmJz4cNXKHdACG9ZK/yvVKjF0M=
|
||||||
|
20221205230404_drop_document_tokens.sql h1:9dCbNFcjtsT6lEhkxCn/vYaGRmQrl1LefdEJgvkfhGg=
|
||||||
|
20221205234214_add_maintenance_entries.sql h1:B56VzCuDsed1k3/sYUoKlOkP90DcdLufxFK0qYvoafU=
|
||||||
|
20221205234812_cascade_delete_roles.sql h1:VIiaImR48nCHF3uFbOYOX1E79Ta5HsUBetGaSAbh9Gk=
|
||||||
|
|
|
@ -16,17 +16,16 @@ func mapTErrFunc[T any, Y any](fn func(T) Y) func(T, error) (Y, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Future Usage
|
func mapTEachFunc[T any, Y any](fn func(T) Y) func([]T) []Y {
|
||||||
// func mapEachFunc[T any, Y any](fn func(T) Y) func([]T) []Y {
|
return func(items []T) []Y {
|
||||||
// return func(items []T) []Y {
|
result := make([]Y, len(items))
|
||||||
// result := make([]Y, len(items))
|
for i, item := range items {
|
||||||
// for i, item := range items {
|
result[i] = fn(item)
|
||||||
// result[i] = fn(item)
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// return result
|
return result
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
func mapTEachErrFunc[T any, Y any](fn func(T) Y) func([]T, error) ([]Y, error) {
|
func mapTEachErrFunc[T any, Y any](fn func(T) Y) func([]T, error) ([]Y, error) {
|
||||||
return func(items []T, err error) ([]Y, error) {
|
return func(items []T, err error) ([]Y, error) {
|
||||||
|
|
|
@ -1,68 +0,0 @@
|
||||||
package repo
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/google/uuid"
|
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent"
|
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/documenttoken"
|
|
||||||
)
|
|
||||||
|
|
||||||
// DocumentTokensRepository is a repository for Document entity
|
|
||||||
type DocumentTokensRepository struct {
|
|
||||||
db *ent.Client
|
|
||||||
}
|
|
||||||
|
|
||||||
type (
|
|
||||||
DocumentToken struct {
|
|
||||||
ID uuid.UUID `json:"-"`
|
|
||||||
TokenHash []byte `json:"tokenHash"`
|
|
||||||
ExpiresAt time.Time `json:"expiresAt"`
|
|
||||||
DocumentID uuid.UUID `json:"documentId"`
|
|
||||||
}
|
|
||||||
|
|
||||||
DocumentTokenCreate struct {
|
|
||||||
TokenHash []byte `json:"tokenHash"`
|
|
||||||
DocumentID uuid.UUID `json:"documentId"`
|
|
||||||
ExpiresAt time.Time `json:"expiresAt"`
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
mapDocumentTokenErr = mapTErrFunc(mapDocumentToken)
|
|
||||||
)
|
|
||||||
|
|
||||||
func mapDocumentToken(e *ent.DocumentToken) DocumentToken {
|
|
||||||
return DocumentToken{
|
|
||||||
ID: e.ID,
|
|
||||||
TokenHash: e.Token,
|
|
||||||
ExpiresAt: e.ExpiresAt,
|
|
||||||
DocumentID: e.Edges.Document.ID,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *DocumentTokensRepository) Create(ctx context.Context, data DocumentTokenCreate) (DocumentToken, error) {
|
|
||||||
result, err := r.db.DocumentToken.Create().
|
|
||||||
SetDocumentID(data.DocumentID).
|
|
||||||
SetToken(data.TokenHash).
|
|
||||||
SetExpiresAt(data.ExpiresAt).
|
|
||||||
Save(ctx)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return DocumentToken{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return mapDocumentTokenErr(r.db.DocumentToken.Query().
|
|
||||||
Where(documenttoken.ID(result.ID)).
|
|
||||||
WithDocument().
|
|
||||||
Only(ctx))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *DocumentTokensRepository) PurgeExpiredTokens(ctx context.Context) (int, error) {
|
|
||||||
return r.db.DocumentToken.Delete().Where(documenttoken.ExpiresAtLT(time.Now())).Exec(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *DocumentTokensRepository) Delete(ctx context.Context, id uuid.UUID) error {
|
|
||||||
return r.db.DocumentToken.DeleteOneID(id).Exec(ctx)
|
|
||||||
}
|
|
|
@ -1,150 +0,0 @@
|
||||||
package repo
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"testing"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/google/uuid"
|
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent"
|
|
||||||
"github.com/hay-kot/homebox/backend/internal/data/ent/documenttoken"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestDocumentTokensRepository_Create(t *testing.T) {
|
|
||||||
entities := useDocs(t, 1)
|
|
||||||
doc := entities[0]
|
|
||||||
expires := fk.Time()
|
|
||||||
|
|
||||||
type args struct {
|
|
||||||
ctx context.Context
|
|
||||||
data DocumentTokenCreate
|
|
||||||
}
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
args args
|
|
||||||
want *ent.DocumentToken
|
|
||||||
wantErr bool
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "create document token",
|
|
||||||
args: args{
|
|
||||||
ctx: context.Background(),
|
|
||||||
data: DocumentTokenCreate{
|
|
||||||
DocumentID: doc.ID,
|
|
||||||
TokenHash: []byte("token"),
|
|
||||||
ExpiresAt: expires,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
want: &ent.DocumentToken{
|
|
||||||
Edges: ent.DocumentTokenEdges{
|
|
||||||
Document: &ent.Document{
|
|
||||||
ID: doc.ID,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Token: []byte("token"),
|
|
||||||
ExpiresAt: expires,
|
|
||||||
},
|
|
||||||
wantErr: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "create document token with empty token",
|
|
||||||
args: args{
|
|
||||||
ctx: context.Background(),
|
|
||||||
data: DocumentTokenCreate{
|
|
||||||
DocumentID: doc.ID,
|
|
||||||
TokenHash: []byte(""),
|
|
||||||
ExpiresAt: expires,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
want: nil,
|
|
||||||
wantErr: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "create document token with empty document id",
|
|
||||||
args: args{
|
|
||||||
ctx: context.Background(),
|
|
||||||
data: DocumentTokenCreate{
|
|
||||||
DocumentID: uuid.Nil,
|
|
||||||
TokenHash: []byte("token"),
|
|
||||||
ExpiresAt: expires,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
want: nil,
|
|
||||||
wantErr: true,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
ids := make([]uuid.UUID, 0, len(tests))
|
|
||||||
|
|
||||||
t.Cleanup(func() {
|
|
||||||
for _, id := range ids {
|
|
||||||
_ = tRepos.DocTokens.Delete(context.Background(), id)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
for _, tt := range tests {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
|
||||||
|
|
||||||
got, err := tRepos.DocTokens.Create(tt.args.ctx, tt.args.data)
|
|
||||||
if (err != nil) != tt.wantErr {
|
|
||||||
t.Errorf("DocumentTokensRepository.Create() error = %v, wantErr %v", err, tt.wantErr)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if tt.wantErr {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
assert.Equal(t, tt.want.Token, got.TokenHash)
|
|
||||||
assert.WithinDuration(t, tt.want.ExpiresAt, got.ExpiresAt, time.Duration(1)*time.Second)
|
|
||||||
assert.Equal(t, tt.want.Edges.Document.ID, got.DocumentID)
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func useDocTokens(t *testing.T, num int) []DocumentToken {
|
|
||||||
entity := useDocs(t, 1)[0]
|
|
||||||
|
|
||||||
results := make([]DocumentToken, 0, num)
|
|
||||||
|
|
||||||
ids := make([]uuid.UUID, 0, num)
|
|
||||||
t.Cleanup(func() {
|
|
||||||
for _, id := range ids {
|
|
||||||
_ = tRepos.DocTokens.Delete(context.Background(), id)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
for i := 0; i < num; i++ {
|
|
||||||
e, err := tRepos.DocTokens.Create(context.Background(), DocumentTokenCreate{
|
|
||||||
DocumentID: entity.ID,
|
|
||||||
TokenHash: []byte(fk.Str(10)),
|
|
||||||
ExpiresAt: fk.Time(),
|
|
||||||
})
|
|
||||||
|
|
||||||
assert.NoError(t, err)
|
|
||||||
results = append(results, e)
|
|
||||||
ids = append(ids, e.ID)
|
|
||||||
}
|
|
||||||
|
|
||||||
return results
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDocumentTokensRepository_PurgeExpiredTokens(t *testing.T) {
|
|
||||||
entities := useDocTokens(t, 2)
|
|
||||||
|
|
||||||
// set expired token
|
|
||||||
tRepos.DocTokens.db.DocumentToken.Update().
|
|
||||||
Where(documenttoken.ID(entities[0].ID)).
|
|
||||||
SetExpiresAt(time.Now().Add(-time.Hour)).
|
|
||||||
ExecX(context.Background())
|
|
||||||
|
|
||||||
count, err := tRepos.DocTokens.PurgeExpiredTokens(context.Background())
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.Equal(t, 1, count)
|
|
||||||
|
|
||||||
all, err := tRepos.DocTokens.db.DocumentToken.Query().All(context.Background())
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.Len(t, all, 1)
|
|
||||||
assert.Equal(t, entities[1].ID, all[0].ID)
|
|
||||||
}
|
|
136
backend/internal/data/repo/repo_maintenance_entry.go
Normal file
136
backend/internal/data/repo/repo_maintenance_entry.go
Normal file
|
@ -0,0 +1,136 @@
|
||||||
|
package repo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"github.com/hay-kot/homebox/backend/internal/data/ent"
|
||||||
|
"github.com/hay-kot/homebox/backend/internal/data/ent/maintenanceentry"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MaintenanceEntryRepository is a repository for maintenance entries that are
|
||||||
|
// associated with an item in the database. An entry represents a maintenance event
|
||||||
|
// that has been performed on an item.
|
||||||
|
type MaintenanceEntryRepository struct {
|
||||||
|
db *ent.Client
|
||||||
|
}
|
||||||
|
type (
|
||||||
|
MaintenanceEntryCreate struct {
|
||||||
|
Date time.Time `json:"date"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
Cost float64 `json:"cost,string"`
|
||||||
|
}
|
||||||
|
|
||||||
|
MaintenanceEntry struct {
|
||||||
|
ID uuid.UUID `json:"id"`
|
||||||
|
Date time.Time `json:"date"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
Cost float64 `json:"cost,string"`
|
||||||
|
}
|
||||||
|
|
||||||
|
MaintenanceEntryUpdate struct {
|
||||||
|
Date time.Time `json:"date"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
Cost float64 `json:"cost,string"`
|
||||||
|
}
|
||||||
|
|
||||||
|
MaintenanceLog struct {
|
||||||
|
ItemID uuid.UUID `json:"itemId"`
|
||||||
|
CostAverage float64 `json:"costAverage"`
|
||||||
|
CostTotal float64 `json:"costTotal"`
|
||||||
|
Entries []MaintenanceEntry `json:"entries"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
mapMaintenanceEntryErr = mapTErrFunc(mapMaintenanceEntry)
|
||||||
|
mapEachMaintenanceEntry = mapTEachFunc(mapMaintenanceEntry)
|
||||||
|
)
|
||||||
|
|
||||||
|
func mapMaintenanceEntry(entry *ent.MaintenanceEntry) MaintenanceEntry {
|
||||||
|
return MaintenanceEntry{
|
||||||
|
ID: entry.ID,
|
||||||
|
Date: entry.Date,
|
||||||
|
Name: entry.Name,
|
||||||
|
Description: entry.Description,
|
||||||
|
Cost: entry.Cost,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *MaintenanceEntryRepository) Create(ctx context.Context, itemID uuid.UUID, input MaintenanceEntryCreate) (MaintenanceEntry, error) {
|
||||||
|
item, err := r.db.MaintenanceEntry.Create().
|
||||||
|
SetItemID(itemID).
|
||||||
|
SetDate(input.Date).
|
||||||
|
SetName(input.Name).
|
||||||
|
SetDescription(input.Description).
|
||||||
|
SetCost(input.Cost).
|
||||||
|
Save(ctx)
|
||||||
|
|
||||||
|
return mapMaintenanceEntryErr(item, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *MaintenanceEntryRepository) Update(ctx context.Context, ID uuid.UUID, input MaintenanceEntryUpdate) (MaintenanceEntry, error) {
|
||||||
|
item, err := r.db.MaintenanceEntry.UpdateOneID(ID).
|
||||||
|
SetDate(input.Date).
|
||||||
|
SetName(input.Name).
|
||||||
|
SetDescription(input.Description).
|
||||||
|
SetCost(input.Cost).
|
||||||
|
Save(ctx)
|
||||||
|
|
||||||
|
return mapMaintenanceEntryErr(item, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *MaintenanceEntryRepository) GetLog(ctx context.Context, itemID uuid.UUID) (MaintenanceLog, error) {
|
||||||
|
log := MaintenanceLog{
|
||||||
|
ItemID: itemID,
|
||||||
|
}
|
||||||
|
|
||||||
|
entries, err := r.db.MaintenanceEntry.Query().
|
||||||
|
Where(maintenanceentry.ItemID(itemID)).
|
||||||
|
Order(ent.Desc(maintenanceentry.FieldDate)).
|
||||||
|
All(ctx)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return MaintenanceLog{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Entries = mapEachMaintenanceEntry(entries)
|
||||||
|
|
||||||
|
var maybeTotal *float64
|
||||||
|
var maybeAverage *float64
|
||||||
|
|
||||||
|
q := `
|
||||||
|
SELECT
|
||||||
|
SUM(cost_total) AS total_of_totals,
|
||||||
|
AVG(cost_total) AS avg_of_averages
|
||||||
|
FROM
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
strftime('%m-%Y', date) AS my,
|
||||||
|
SUM(cost) AS cost_total
|
||||||
|
FROM
|
||||||
|
maintenance_entries
|
||||||
|
WHERE
|
||||||
|
item_id = ?
|
||||||
|
GROUP BY
|
||||||
|
my
|
||||||
|
)`
|
||||||
|
|
||||||
|
row := r.db.Sql().QueryRowContext(ctx, q, itemID)
|
||||||
|
err = row.Scan(&maybeTotal, &maybeAverage)
|
||||||
|
if err != nil {
|
||||||
|
return MaintenanceLog{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
log.CostAverage = orDefault(maybeAverage, 0)
|
||||||
|
log.CostTotal = orDefault(maybeTotal, 0)
|
||||||
|
return log, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *MaintenanceEntryRepository) Delete(ctx context.Context, ID uuid.UUID) error {
|
||||||
|
return r.db.MaintenanceEntry.DeleteOneID(ID).Exec(ctx)
|
||||||
|
}
|
65
backend/internal/data/repo/repo_maintenance_entry_test.go
Normal file
65
backend/internal/data/repo/repo_maintenance_entry_test.go
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
package repo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestMaintenanceEntryRepository_GetLog(t *testing.T) {
|
||||||
|
item := useItems(t, 1)[0]
|
||||||
|
|
||||||
|
// Create 10 maintenance entries for the item
|
||||||
|
created := make([]MaintenanceEntryCreate, 10)
|
||||||
|
|
||||||
|
lastMonth := time.Now().AddDate(0, -1, 0)
|
||||||
|
thisMonth := time.Now()
|
||||||
|
|
||||||
|
for i := 0; i < 10; i++ {
|
||||||
|
dt := lastMonth
|
||||||
|
if i%2 == 0 {
|
||||||
|
dt = thisMonth
|
||||||
|
}
|
||||||
|
|
||||||
|
created[i] = MaintenanceEntryCreate{
|
||||||
|
Date: dt,
|
||||||
|
Name: "Maintenance",
|
||||||
|
Description: "Maintenance description",
|
||||||
|
Cost: 10,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, entry := range created {
|
||||||
|
_, err := tRepos.MaintEntry.Create(context.Background(), item.ID, entry)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create maintenance entry: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the log for the item
|
||||||
|
log, err := tRepos.MaintEntry.GetLog(context.Background(), item.ID)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to get maintenance log: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.Equal(t, item.ID, log.ItemID)
|
||||||
|
assert.Equal(t, 10, len(log.Entries))
|
||||||
|
|
||||||
|
// Calculate the average cost
|
||||||
|
var total float64
|
||||||
|
|
||||||
|
for _, entry := range log.Entries {
|
||||||
|
total += entry.Cost
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.Equal(t, total, log.CostTotal, "total cost should be equal to the sum of all entries")
|
||||||
|
assert.Equal(t, total/2, log.CostAverage, "average cost should be the average of the two months")
|
||||||
|
|
||||||
|
for _, entry := range log.Entries {
|
||||||
|
err := tRepos.MaintEntry.Delete(context.Background(), entry.ID)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,8 +11,8 @@ type AllRepos struct {
|
||||||
Labels *LabelRepository
|
Labels *LabelRepository
|
||||||
Items *ItemsRepository
|
Items *ItemsRepository
|
||||||
Docs *DocumentRepository
|
Docs *DocumentRepository
|
||||||
DocTokens *DocumentTokensRepository
|
|
||||||
Attachments *AttachmentRepo
|
Attachments *AttachmentRepo
|
||||||
|
MaintEntry *MaintenanceEntryRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(db *ent.Client, root string) *AllRepos {
|
func New(db *ent.Client, root string) *AllRepos {
|
||||||
|
@ -24,7 +24,7 @@ func New(db *ent.Client, root string) *AllRepos {
|
||||||
Labels: &LabelRepository{db},
|
Labels: &LabelRepository{db},
|
||||||
Items: &ItemsRepository{db},
|
Items: &ItemsRepository{db},
|
||||||
Docs: &DocumentRepository{db, root},
|
Docs: &DocumentRepository{db, root},
|
||||||
DocTokens: &DocumentTokensRepository{db},
|
|
||||||
Attachments: &AttachmentRepo{db},
|
Attachments: &AttachmentRepo{db},
|
||||||
|
MaintEntry: &MaintenanceEntryRepository{db},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ func init() {
|
||||||
disableHas := os.Getenv("UNSAFE_DISABLE_PASSWORD_PROJECTION") == "yes_i_am_sure"
|
disableHas := os.Getenv("UNSAFE_DISABLE_PASSWORD_PROJECTION") == "yes_i_am_sure"
|
||||||
|
|
||||||
if disableHas {
|
if disableHas {
|
||||||
fmt.Println("WARNING: Password projection is disabled. This is unsafe in production.")
|
fmt.Println("WARNING: Password protection is disabled. This is unsafe in production.")
|
||||||
enabled = false
|
enabled = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
'btn-sm': size === 'sm',
|
'btn-sm': size === 'sm',
|
||||||
'btn-lg': size === 'lg',
|
'btn-lg': size === 'lg',
|
||||||
}"
|
}"
|
||||||
|
:style="upper ? '' : 'text-transform: none'"
|
||||||
>
|
>
|
||||||
<label v-if="$slots.icon" class="swap swap-rotate mr-2" :class="{ 'swap-active': isHover }">
|
<label v-if="$slots.icon" class="swap swap-rotate mr-2" :class="{ 'swap-active': isHover }">
|
||||||
<slot name="icon" />
|
<slot name="icon" />
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="card bg-base-100 shadow-xl sm:rounded-lg">
|
<div class="card bg-base-100 shadow-xl sm:rounded-lg">
|
||||||
<div class="px-4 py-5 sm:px-6">
|
<div v-if="$slots.title" class="px-4 py-5 sm:px-6">
|
||||||
<h3 class="text-lg font-medium leading-6">
|
<h3 class="text-lg font-medium leading-6">
|
||||||
<slot name="title"></slot>
|
<slot name="title"></slot>
|
||||||
</h3>
|
</h3>
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
<button
|
<button
|
||||||
v-if="day.number != ''"
|
v-if="day.number != ''"
|
||||||
:key="day.number"
|
:key="day.number"
|
||||||
|
type="button"
|
||||||
class="text-center btn-xs btn btn-outline"
|
class="text-center btn-xs btn btn-outline"
|
||||||
@click="select($event, day.date)"
|
@click="select($event, day.date)"
|
||||||
>
|
>
|
||||||
|
@ -22,11 +23,11 @@
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex justify-between mt-1 items-center">
|
<div class="flex justify-between mt-1 items-center">
|
||||||
<button class="btn btn-xs" @click="prevMonth">
|
<button type="button" class="btn btn-xs" @click="prevMonth">
|
||||||
<Icon class="h-5 w-5" name="mdi-arrow-left"></Icon>
|
<Icon class="h-5 w-5" name="mdi-arrow-left"></Icon>
|
||||||
</button>
|
</button>
|
||||||
<p class="text-center">{{ month }} {{ year }}</p>
|
<p class="text-center">{{ month }} {{ year }}</p>
|
||||||
<button class="btn btn-xs" @click="nextMonth">
|
<button type="button" class="btn btn-xs" @click="nextMonth">
|
||||||
<Icon class="h-5 w-5" name="mdi-arrow-right"></Icon>
|
<Icon class="h-5 w-5" name="mdi-arrow-right"></Icon>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -3,12 +3,37 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
enum DateTimeFormat {
|
type DateTimeFormat = "relative" | "long" | "short" | "human";
|
||||||
RELATIVE = "relative",
|
|
||||||
LONG = "long",
|
function ordinalIndicator(num: number) {
|
||||||
SHORT = "short",
|
if (num > 3 && num < 21) return "th";
|
||||||
|
switch (num % 10) {
|
||||||
|
case 1:
|
||||||
|
return "st";
|
||||||
|
case 2:
|
||||||
|
return "nd";
|
||||||
|
case 3:
|
||||||
|
return "rd";
|
||||||
|
default:
|
||||||
|
return "th";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const months = [
|
||||||
|
"January",
|
||||||
|
"February",
|
||||||
|
"March",
|
||||||
|
"April",
|
||||||
|
"May",
|
||||||
|
"June",
|
||||||
|
"July",
|
||||||
|
"August",
|
||||||
|
"September",
|
||||||
|
"October",
|
||||||
|
"November",
|
||||||
|
"December",
|
||||||
|
];
|
||||||
|
|
||||||
const value = computed(() => {
|
const value = computed(() => {
|
||||||
if (!props.date) {
|
if (!props.date) {
|
||||||
return "";
|
return "";
|
||||||
|
@ -24,12 +49,15 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (props.format) {
|
switch (props.format) {
|
||||||
case DateTimeFormat.RELATIVE:
|
case "relative":
|
||||||
return useTimeAgo(dt).value + useDateFormat(dt, " (MM-DD-YYYY)").value;
|
return useTimeAgo(dt).value + useDateFormat(dt, " (MM-DD-YYYY)").value;
|
||||||
case DateTimeFormat.LONG:
|
case "long":
|
||||||
return useDateFormat(dt, "MM-DD-YYYY (dddd)").value;
|
return useDateFormat(dt, "MM-DD-YYYY (dddd)").value;
|
||||||
case DateTimeFormat.SHORT:
|
case "short":
|
||||||
return useDateFormat(dt, "MM-DD-YYYY").value;
|
return useDateFormat(dt, "MM-DD-YYYY").value;
|
||||||
|
case "human":
|
||||||
|
// January 1st, 2021
|
||||||
|
return `${months[dt.getMonth()]} ${dt.getDate()}${ordinalIndicator(dt.getDate())}, ${dt.getFullYear()}`;
|
||||||
default:
|
default:
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,12 @@
|
||||||
import DOMPurify from "dompurify";
|
import DOMPurify from "dompurify";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
source: string;
|
source: string | null | undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
const props = withDefaults(defineProps<Props>(), {});
|
const props = withDefaults(defineProps<Props>(), {
|
||||||
|
source: null,
|
||||||
|
});
|
||||||
|
|
||||||
const md = new MarkdownIt({
|
const md = new MarkdownIt({
|
||||||
html: true,
|
html: true,
|
||||||
|
@ -15,7 +17,7 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
const raw = computed(() => {
|
const raw = computed(() => {
|
||||||
const html = md.render(props.source);
|
const html = md.render(props.source || "");
|
||||||
return DOMPurify.sanitize(html);
|
return DOMPurify.sanitize(html);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -33,6 +33,7 @@ describe("user should be able to create an item and add an attachment", () => {
|
||||||
const [location, cleanup] = await useLocation(api);
|
const [location, cleanup] = await useLocation(api);
|
||||||
|
|
||||||
const { response, data: item } = await api.items.create({
|
const { response, data: item } = await api.items.create({
|
||||||
|
parentId: null,
|
||||||
name: "test-item",
|
name: "test-item",
|
||||||
labelIds: [],
|
labelIds: [],
|
||||||
description: "test-description",
|
description: "test-description",
|
||||||
|
@ -43,7 +44,7 @@ describe("user should be able to create an item and add an attachment", () => {
|
||||||
// Add attachment
|
// Add attachment
|
||||||
{
|
{
|
||||||
const testFile = new Blob(["test"], { type: "text/plain" });
|
const testFile = new Blob(["test"], { type: "text/plain" });
|
||||||
const { response } = await api.items.addAttachment(item.id, testFile, "test.txt", AttachmentTypes.Attachment);
|
const { response } = await api.items.attachments.add(item.id, testFile, "test.txt", AttachmentTypes.Attachment);
|
||||||
expect(response.status).toBe(201);
|
expect(response.status).toBe(201);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +55,7 @@ describe("user should be able to create an item and add an attachment", () => {
|
||||||
expect(data.attachments).toHaveLength(1);
|
expect(data.attachments).toHaveLength(1);
|
||||||
expect(data.attachments[0].document.title).toBe("test.txt");
|
expect(data.attachments[0].document.title).toBe("test.txt");
|
||||||
|
|
||||||
const resp = await api.items.deleteAttachment(data.id, data.attachments[0].id);
|
const resp = await api.items.attachments.delete(data.id, data.attachments[0].id);
|
||||||
expect(resp.response.status).toBe(204);
|
expect(resp.response.status).toBe(204);
|
||||||
|
|
||||||
api.items.delete(item.id);
|
api.items.delete(item.id);
|
||||||
|
@ -66,6 +67,7 @@ describe("user should be able to create an item and add an attachment", () => {
|
||||||
const [location, cleanup] = await useLocation(api);
|
const [location, cleanup] = await useLocation(api);
|
||||||
|
|
||||||
const { response, data: item } = await api.items.create({
|
const { response, data: item } = await api.items.create({
|
||||||
|
parentId: null,
|
||||||
name: faker.vehicle.model(),
|
name: faker.vehicle.model(),
|
||||||
labelIds: [],
|
labelIds: [],
|
||||||
description: faker.lorem.paragraph(1),
|
description: faker.lorem.paragraph(1),
|
||||||
|
@ -82,6 +84,7 @@ describe("user should be able to create an item and add an attachment", () => {
|
||||||
|
|
||||||
// Add fields
|
// Add fields
|
||||||
const itemUpdate = {
|
const itemUpdate = {
|
||||||
|
parentId: null,
|
||||||
...item,
|
...item,
|
||||||
locationId: item.location.id,
|
locationId: item.location.id,
|
||||||
labelIds: item.labels.map(l => l.id),
|
labelIds: item.labels.map(l => l.id),
|
||||||
|
@ -113,4 +116,41 @@ describe("user should be able to create an item and add an attachment", () => {
|
||||||
|
|
||||||
cleanup();
|
cleanup();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("users should be able to create and few maintenance logs for an item", async () => {
|
||||||
|
const api = await sharedUserClient();
|
||||||
|
const [location, cleanup] = await useLocation(api);
|
||||||
|
const { response, data: item } = await api.items.create({
|
||||||
|
parentId: null,
|
||||||
|
name: faker.vehicle.model(),
|
||||||
|
labelIds: [],
|
||||||
|
description: faker.lorem.paragraph(1),
|
||||||
|
locationId: location.id,
|
||||||
|
});
|
||||||
|
expect(response.status).toBe(201);
|
||||||
|
|
||||||
|
const maintenanceEntries = [];
|
||||||
|
for (let i = 0; i < 5; i++) {
|
||||||
|
const { response, data } = await api.items.maintenance.create(item.id, {
|
||||||
|
name: faker.vehicle.model(),
|
||||||
|
description: faker.lorem.paragraph(1),
|
||||||
|
date: faker.date.past(1),
|
||||||
|
cost: faker.datatype.number(100).toString(),
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(response.status).toBe(201);
|
||||||
|
maintenanceEntries.push(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Log
|
||||||
|
{
|
||||||
|
const { response, data } = await api.items.maintenance.getLog(item.id);
|
||||||
|
expect(response.status).toBe(200);
|
||||||
|
expect(data.entries).toHaveLength(maintenanceEntries.length);
|
||||||
|
expect(data.costAverage).toBeGreaterThan(0);
|
||||||
|
expect(data.costTotal).toBeGreaterThan(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanup();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,7 +1,18 @@
|
||||||
import { BaseAPI, route } from "../base";
|
import { BaseAPI, route } from "../base";
|
||||||
import { parseDate } from "../base/base-api";
|
import { parseDate } from "../base/base-api";
|
||||||
import { ItemAttachmentUpdate, ItemCreate, ItemOut, ItemSummary, ItemUpdate } from "../types/data-contracts";
|
import {
|
||||||
|
ItemAttachmentUpdate,
|
||||||
|
ItemCreate,
|
||||||
|
ItemOut,
|
||||||
|
ItemSummary,
|
||||||
|
ItemUpdate,
|
||||||
|
MaintenanceEntry,
|
||||||
|
MaintenanceEntryCreate,
|
||||||
|
MaintenanceEntryUpdate,
|
||||||
|
MaintenanceLog,
|
||||||
|
} from "../types/data-contracts";
|
||||||
import { AttachmentTypes, PaginationResult } from "../types/non-generated";
|
import { AttachmentTypes, PaginationResult } from "../types/non-generated";
|
||||||
|
import { Requests } from "~~/lib/requests";
|
||||||
|
|
||||||
export type ItemsQuery = {
|
export type ItemsQuery = {
|
||||||
includeArchived?: boolean;
|
includeArchived?: boolean;
|
||||||
|
@ -12,7 +23,65 @@ export type ItemsQuery = {
|
||||||
q?: string;
|
q?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export class AttachmentsAPI extends BaseAPI {
|
||||||
|
add(id: string, file: File | Blob, filename: string, type: AttachmentTypes) {
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append("file", file);
|
||||||
|
formData.append("type", type);
|
||||||
|
formData.append("name", filename);
|
||||||
|
|
||||||
|
return this.http.post<FormData, ItemOut>({
|
||||||
|
url: route(`/items/${id}/attachments`),
|
||||||
|
data: formData,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
delete(id: string, attachmentId: string) {
|
||||||
|
return this.http.delete<void>({ url: route(`/items/${id}/attachments/${attachmentId}`) });
|
||||||
|
}
|
||||||
|
|
||||||
|
update(id: string, attachmentId: string, data: ItemAttachmentUpdate) {
|
||||||
|
return this.http.put<ItemAttachmentUpdate, ItemOut>({
|
||||||
|
url: route(`/items/${id}/attachments/${attachmentId}`),
|
||||||
|
body: data,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class MaintenanceAPI extends BaseAPI {
|
||||||
|
getLog(itemId: string) {
|
||||||
|
return this.http.get<MaintenanceLog>({ url: route(`/items/${itemId}/maintenance`) });
|
||||||
|
}
|
||||||
|
|
||||||
|
create(itemId: string, data: MaintenanceEntryCreate) {
|
||||||
|
return this.http.post<MaintenanceEntryCreate, MaintenanceEntry>({
|
||||||
|
url: route(`/items/${itemId}/maintenance`),
|
||||||
|
body: data,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
delete(itemId: string, entryId: string) {
|
||||||
|
return this.http.delete<void>({ url: route(`/items/${itemId}/maintenance/${entryId}`) });
|
||||||
|
}
|
||||||
|
|
||||||
|
update(itemId: string, entryId: string, data: MaintenanceEntryUpdate) {
|
||||||
|
return this.http.put<MaintenanceEntryUpdate, MaintenanceEntry>({
|
||||||
|
url: route(`/items/${itemId}/maintenance/${entryId}`),
|
||||||
|
body: data,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export class ItemsApi extends BaseAPI {
|
export class ItemsApi extends BaseAPI {
|
||||||
|
attachments: AttachmentsAPI;
|
||||||
|
maintenance: MaintenanceAPI;
|
||||||
|
|
||||||
|
constructor(http: Requests, token: string) {
|
||||||
|
super(http, token);
|
||||||
|
this.attachments = new AttachmentsAPI(http);
|
||||||
|
this.maintenance = new MaintenanceAPI(http);
|
||||||
|
}
|
||||||
|
|
||||||
getAll(q: ItemsQuery = {}) {
|
getAll(q: ItemsQuery = {}) {
|
||||||
return this.http.get<PaginationResult<ItemSummary>>({ url: route("/items", q) });
|
return this.http.get<PaginationResult<ItemSummary>>({ url: route("/items", q) });
|
||||||
}
|
}
|
||||||
|
@ -59,27 +128,4 @@ export class ItemsApi extends BaseAPI {
|
||||||
data: formData,
|
data: formData,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
addAttachment(id: string, file: File | Blob, filename: string, type: AttachmentTypes) {
|
|
||||||
const formData = new FormData();
|
|
||||||
formData.append("file", file);
|
|
||||||
formData.append("type", type);
|
|
||||||
formData.append("name", filename);
|
|
||||||
|
|
||||||
return this.http.post<FormData, ItemOut>({
|
|
||||||
url: route(`/items/${id}/attachments`),
|
|
||||||
data: formData,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async deleteAttachment(id: string, attachmentId: string) {
|
|
||||||
return await this.http.delete<void>({ url: route(`/items/${id}/attachments/${attachmentId}`) });
|
|
||||||
}
|
|
||||||
|
|
||||||
async updateAttachment(id: string, attachmentId: string, data: ItemAttachmentUpdate) {
|
|
||||||
return await this.http.put<ItemAttachmentUpdate, ItemOut>({
|
|
||||||
url: route(`/items/${id}/attachments/${attachmentId}`),
|
|
||||||
body: data,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,6 @@ export interface ItemAttachmentUpdate {
|
||||||
export interface ItemCreate {
|
export interface ItemCreate {
|
||||||
description: string;
|
description: string;
|
||||||
labelIds: string[];
|
labelIds: string[];
|
||||||
|
|
||||||
/** Edges */
|
/** Edges */
|
||||||
locationId: string;
|
locationId: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
@ -73,8 +72,7 @@ export interface ItemField {
|
||||||
|
|
||||||
export interface ItemOut {
|
export interface ItemOut {
|
||||||
archived: boolean;
|
archived: boolean;
|
||||||
|
/** @example "0" */
|
||||||
/** @example 0 */
|
|
||||||
assetId: string;
|
assetId: string;
|
||||||
attachments: ItemAttachment[];
|
attachments: ItemAttachment[];
|
||||||
children: ItemSummary[];
|
children: ItemSummary[];
|
||||||
|
@ -84,33 +82,26 @@ export interface ItemOut {
|
||||||
id: string;
|
id: string;
|
||||||
insured: boolean;
|
insured: boolean;
|
||||||
labels: LabelSummary[];
|
labels: LabelSummary[];
|
||||||
|
|
||||||
/** Warranty */
|
/** Warranty */
|
||||||
lifetimeWarranty: boolean;
|
lifetimeWarranty: boolean;
|
||||||
|
|
||||||
/** Edges */
|
/** Edges */
|
||||||
location: LocationSummary | null;
|
location: LocationSummary | null;
|
||||||
manufacturer: string;
|
manufacturer: string;
|
||||||
modelNumber: string;
|
modelNumber: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
/** Extras */
|
/** Extras */
|
||||||
notes: string;
|
notes: string;
|
||||||
parent: ItemSummary | null;
|
parent: ItemSummary | null;
|
||||||
purchaseFrom: string;
|
purchaseFrom: string;
|
||||||
|
/** @example "0" */
|
||||||
/** @example 0 */
|
|
||||||
purchasePrice: string;
|
purchasePrice: string;
|
||||||
|
|
||||||
/** Purchase */
|
/** Purchase */
|
||||||
purchaseTime: Date;
|
purchaseTime: Date;
|
||||||
quantity: number;
|
quantity: number;
|
||||||
serialNumber: string;
|
serialNumber: string;
|
||||||
soldNotes: string;
|
soldNotes: string;
|
||||||
|
/** @example "0" */
|
||||||
/** @example 0 */
|
|
||||||
soldPrice: string;
|
soldPrice: string;
|
||||||
|
|
||||||
/** Sold */
|
/** Sold */
|
||||||
soldTime: Date;
|
soldTime: Date;
|
||||||
soldTo: string;
|
soldTo: string;
|
||||||
|
@ -126,7 +117,6 @@ export interface ItemSummary {
|
||||||
id: string;
|
id: string;
|
||||||
insured: boolean;
|
insured: boolean;
|
||||||
labels: LabelSummary[];
|
labels: LabelSummary[];
|
||||||
|
|
||||||
/** Edges */
|
/** Edges */
|
||||||
location: LocationSummary | null;
|
location: LocationSummary | null;
|
||||||
name: string;
|
name: string;
|
||||||
|
@ -142,35 +132,27 @@ export interface ItemUpdate {
|
||||||
id: string;
|
id: string;
|
||||||
insured: boolean;
|
insured: boolean;
|
||||||
labelIds: string[];
|
labelIds: string[];
|
||||||
|
|
||||||
/** Warranty */
|
/** Warranty */
|
||||||
lifetimeWarranty: boolean;
|
lifetimeWarranty: boolean;
|
||||||
|
|
||||||
/** Edges */
|
/** Edges */
|
||||||
locationId: string;
|
locationId: string;
|
||||||
manufacturer: string;
|
manufacturer: string;
|
||||||
modelNumber: string;
|
modelNumber: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
/** Extras */
|
/** Extras */
|
||||||
notes: string;
|
notes: string;
|
||||||
parentId: string | null;
|
parentId: string | null;
|
||||||
purchaseFrom: string;
|
purchaseFrom: string;
|
||||||
|
/** @example "0" */
|
||||||
/** @example 0 */
|
|
||||||
purchasePrice: string;
|
purchasePrice: string;
|
||||||
|
|
||||||
/** Purchase */
|
/** Purchase */
|
||||||
purchaseTime: Date;
|
purchaseTime: Date;
|
||||||
quantity: number;
|
quantity: number;
|
||||||
|
|
||||||
/** Identifications */
|
/** Identifications */
|
||||||
serialNumber: string;
|
serialNumber: string;
|
||||||
soldNotes: string;
|
soldNotes: string;
|
||||||
|
/** @example "0" */
|
||||||
/** @example 0 */
|
|
||||||
soldPrice: string;
|
soldPrice: string;
|
||||||
|
|
||||||
/** Sold */
|
/** Sold */
|
||||||
soldTime: Date;
|
soldTime: Date;
|
||||||
soldTo: string;
|
soldTo: string;
|
||||||
|
@ -241,6 +223,38 @@ export interface LocationUpdate {
|
||||||
parentId: string | null;
|
parentId: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface MaintenanceEntry {
|
||||||
|
/** @example "0" */
|
||||||
|
cost: string;
|
||||||
|
date: Date;
|
||||||
|
description: string;
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface MaintenanceEntryCreate {
|
||||||
|
/** @example "0" */
|
||||||
|
cost: string;
|
||||||
|
date: Date;
|
||||||
|
description: string;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface MaintenanceEntryUpdate {
|
||||||
|
/** @example "0" */
|
||||||
|
cost: string;
|
||||||
|
date: Date;
|
||||||
|
description: string;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface MaintenanceLog {
|
||||||
|
costAverage: number;
|
||||||
|
costTotal: number;
|
||||||
|
entries: MaintenanceEntry[];
|
||||||
|
itemId: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface PaginationResultRepoItemSummary {
|
export interface PaginationResultRepoItemSummary {
|
||||||
items: ItemSummary[];
|
items: ItemSummary[];
|
||||||
page: number;
|
page: number;
|
||||||
|
@ -278,7 +292,7 @@ export interface ValueOverTime {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ValueOverTimeEntry {
|
export interface ValueOverTimeEntry {
|
||||||
date: string;
|
date: Date;
|
||||||
name: string;
|
name: string;
|
||||||
value: number;
|
value: number;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,16 @@
|
||||||
import { defineNuxtConfig } from "nuxt";
|
import { defineNuxtConfig } from "nuxt/config";
|
||||||
|
|
||||||
// https://v3.nuxtjs.org/api/configuration/nuxt.config
|
// https://v3.nuxtjs.org/api/configuration/nuxt.config
|
||||||
export default defineNuxtConfig({
|
export default defineNuxtConfig({
|
||||||
target: "static",
|
|
||||||
ssr: false,
|
ssr: false,
|
||||||
modules: ["@nuxtjs/tailwindcss", "@pinia/nuxt", "@vueuse/nuxt"],
|
modules: ["@nuxtjs/tailwindcss", "@pinia/nuxt", "@vueuse/nuxt"],
|
||||||
meta: {
|
nitro: {
|
||||||
title: "Homebox",
|
devProxy: {
|
||||||
link: [{ rel: "icon", type: "image/x-icon", href: "/favicon.svg" }],
|
"/api": {
|
||||||
},
|
target: "http://localhost:7745/api",
|
||||||
vite: {
|
changeOrigin: true,
|
||||||
server: {
|
}
|
||||||
proxy: {
|
|
||||||
"/api": "http://localhost:7745",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
plugins: [],
|
|
||||||
},
|
},
|
||||||
|
plugins: [],
|
||||||
});
|
});
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
"eslint-plugin-prettier": "^4.2.1",
|
"eslint-plugin-prettier": "^4.2.1",
|
||||||
"eslint-plugin-vue": "^9.4.0",
|
"eslint-plugin-vue": "^9.4.0",
|
||||||
"isomorphic-fetch": "^3.0.0",
|
"isomorphic-fetch": "^3.0.0",
|
||||||
"nuxt": "3.0.0-rc.11",
|
"nuxt": "3.0.0",
|
||||||
"prettier": "^2.7.1",
|
"prettier": "^2.7.1",
|
||||||
"typescript": "^4.8.3",
|
"typescript": "^4.8.3",
|
||||||
"vite-plugin-eslint": "^1.8.1",
|
"vite-plugin-eslint": "^1.8.1",
|
||||||
|
@ -29,7 +29,7 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@iconify/vue": "^3.2.1",
|
"@iconify/vue": "^3.2.1",
|
||||||
"@nuxtjs/tailwindcss": "^5.3.2",
|
"@nuxtjs/tailwindcss": "^6.1.3",
|
||||||
"@pinia/nuxt": "^0.4.1",
|
"@pinia/nuxt": "^0.4.1",
|
||||||
"@tailwindcss/aspect-ratio": "^0.4.0",
|
"@tailwindcss/aspect-ratio": "^0.4.0",
|
||||||
"@tailwindcss/forms": "^0.5.2",
|
"@tailwindcss/forms": "^0.5.2",
|
||||||
|
|
|
@ -46,7 +46,7 @@
|
||||||
const importDialog = ref(false);
|
const importDialog = ref(false);
|
||||||
const importCsv = ref(null);
|
const importCsv = ref(null);
|
||||||
const importLoading = ref(false);
|
const importLoading = ref(false);
|
||||||
const importRef = ref<HTMLInputElement>(null);
|
const importRef = ref<HTMLInputElement>();
|
||||||
whenever(
|
whenever(
|
||||||
() => !importDialog.value,
|
() => !importDialog.value,
|
||||||
() => {
|
() => {
|
||||||
|
@ -120,7 +120,7 @@
|
||||||
<section>
|
<section>
|
||||||
<BaseCard>
|
<BaseCard>
|
||||||
<template #title> Welcome Back, {{ auth.self ? auth.self.name : "Username" }} </template>
|
<template #title> Welcome Back, {{ auth.self ? auth.self.name : "Username" }} </template>
|
||||||
<template #subtitle> {{ auth.self.isSuperuser ? "Admin" : "User" }} </template>
|
<!-- <template #subtitle> {{ auth.self.isSuperuser ? "Admin" : "User" }} </template> -->
|
||||||
<template #title-actions>
|
<template #title-actions>
|
||||||
<div class="flex justify-end gap-2">
|
<div class="flex justify-end gap-2">
|
||||||
<div class="tooltip" data-tip="Import CSV File">
|
<div class="tooltip" data-tip="Import CSV File">
|
||||||
|
|
|
@ -214,7 +214,7 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { data, error } = await api.items.addAttachment(itemId.value, files[0], files[0].name, type);
|
const { data, error } = await api.items.attachments.add(itemId.value, files[0], files[0].name, type);
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
toast.error("Failed to upload attachment");
|
toast.error("Failed to upload attachment");
|
||||||
|
@ -235,7 +235,7 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { error } = await api.items.deleteAttachment(itemId.value, attachmentId);
|
const { error } = await api.items.attachments.delete(itemId.value, attachmentId);
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
toast.error("Failed to delete attachment");
|
toast.error("Failed to delete attachment");
|
||||||
|
@ -273,7 +273,7 @@
|
||||||
|
|
||||||
async function updateAttachment() {
|
async function updateAttachment() {
|
||||||
editState.loading = true;
|
editState.loading = true;
|
||||||
const { error, data } = await api.items.updateAttachment(itemId.value, editState.id, {
|
const { error, data } = await api.items.attachments.update(itemId.value, editState.id, {
|
||||||
title: editState.title,
|
title: editState.title,
|
||||||
type: editState.type,
|
type: editState.type,
|
||||||
});
|
});
|
||||||
|
|
|
@ -13,6 +13,10 @@
|
||||||
const itemId = computed<string>(() => route.params.id as string);
|
const itemId = computed<string>(() => route.params.id as string);
|
||||||
const preferences = useViewPreferences();
|
const preferences = useViewPreferences();
|
||||||
|
|
||||||
|
const hasNested = computed<boolean>(() => {
|
||||||
|
return route.fullPath.split("/").at(-1) !== itemId.value;
|
||||||
|
});
|
||||||
|
|
||||||
const { data: item, refresh } = useAsyncData(itemId.value, async () => {
|
const { data: item, refresh } = useAsyncData(itemId.value, async () => {
|
||||||
const { data, error } = await api.items.get(itemId.value);
|
const { data, error } = await api.items.get(itemId.value);
|
||||||
if (error) {
|
if (error) {
|
||||||
|
@ -219,7 +223,7 @@
|
||||||
} else {
|
} else {
|
||||||
details.push({
|
details.push({
|
||||||
name: "Warranty Expires",
|
name: "Warranty Expires",
|
||||||
text: item.value?.warrantyExpires,
|
text: item.value?.warrantyExpires || "",
|
||||||
type: "date",
|
type: "date",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -253,7 +257,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Purchase Date",
|
name: "Purchase Date",
|
||||||
text: item.value.purchaseTime,
|
text: item.value?.purchaseTime || "",
|
||||||
type: "date",
|
type: "date",
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
@ -309,12 +313,12 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
function openDialog(img: Photo) {
|
function openDialog(img: Photo) {
|
||||||
refDialog.value.showModal();
|
refDialog.value?.showModal();
|
||||||
dialoged.src = img.src;
|
dialoged.src = img.src;
|
||||||
}
|
}
|
||||||
|
|
||||||
function closeDialog() {
|
function closeDialog() {
|
||||||
refDialog.value.close();
|
refDialog.value?.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
const refDialogBody = ref<HTMLDivElement>();
|
const refDialogBody = ref<HTMLDivElement>();
|
||||||
|
@ -340,10 +344,7 @@
|
||||||
</div>
|
</div>
|
||||||
</dialog>
|
</dialog>
|
||||||
<section class="px-3">
|
<section class="px-3">
|
||||||
<div class="flex justify-between items-center">
|
<div class="space-y-3">
|
||||||
<div class="form-control"></div>
|
|
||||||
</div>
|
|
||||||
<div class="grid grid-cols-1 gap-3">
|
|
||||||
<BaseCard>
|
<BaseCard>
|
||||||
<template #title>
|
<template #title>
|
||||||
<BaseSectionHeader>
|
<BaseSectionHeader>
|
||||||
|
@ -374,10 +375,16 @@
|
||||||
</template>
|
</template>
|
||||||
<template #title-actions>
|
<template #title-actions>
|
||||||
<div class="modal-action mt-0">
|
<div class="modal-action mt-0">
|
||||||
<label class="label cursor-pointer mr-auto">
|
<label v-if="!hasNested" class="label cursor-pointer mr-auto">
|
||||||
<input v-model="preferences.showEmpty" type="checkbox" class="toggle toggle-primary" />
|
<input v-model="preferences.showEmpty" type="checkbox" class="toggle toggle-primary" />
|
||||||
<span class="label-text ml-4"> Show Empty </span>
|
<span class="label-text ml-4"> Show Empty </span>
|
||||||
</label>
|
</label>
|
||||||
|
<BaseButton v-else class="mr-auto" size="sm" @click="$router.go(-1)">
|
||||||
|
<template #icon>
|
||||||
|
<Icon name="mdi-arrow-left" class="h-5 w-5" />
|
||||||
|
</template>
|
||||||
|
Back
|
||||||
|
</BaseButton>
|
||||||
<BaseButton size="sm" :to="`/item/${itemId}/edit`">
|
<BaseButton size="sm" :to="`/item/${itemId}/edit`">
|
||||||
<template #icon>
|
<template #icon>
|
||||||
<Icon name="mdi-pencil" />
|
<Icon name="mdi-pencil" />
|
||||||
|
@ -390,75 +397,84 @@
|
||||||
</template>
|
</template>
|
||||||
Delete
|
Delete
|
||||||
</BaseButton>
|
</BaseButton>
|
||||||
|
<BaseButton size="sm" :to="`/item/${itemId}/log`">
|
||||||
|
<template #icon>
|
||||||
|
<Icon name="mdi-post" />
|
||||||
|
</template>
|
||||||
|
Log
|
||||||
|
</BaseButton>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<DetailsSection :details="itemDetails" />
|
<DetailsSection v-if="!hasNested" :details="itemDetails" />
|
||||||
</BaseCard>
|
</BaseCard>
|
||||||
|
|
||||||
<BaseCard v-if="photos && photos.length > 0">
|
<NuxtPage :item="item" :page-key="itemId" />
|
||||||
<template #title> Photos </template>
|
<div v-if="!hasNested">
|
||||||
<div
|
<BaseCard v-if="photos && photos.length > 0">
|
||||||
class="container border-t border-gray-300 p-4 flex flex-wrap gap-2 mx-auto max-h-[500px] overflow-y-scroll scroll-bg"
|
<template #title> Photos </template>
|
||||||
>
|
<div
|
||||||
<button v-for="(img, i) in photos" :key="i" @click="openDialog(img)">
|
class="container border-t border-gray-300 p-4 flex flex-wrap gap-2 mx-auto max-h-[500px] overflow-y-scroll scroll-bg"
|
||||||
<img class="rounded max-h-[200px]" :src="img.src" />
|
>
|
||||||
</button>
|
<button v-for="(img, i) in photos" :key="i" @click="openDialog(img)">
|
||||||
</div>
|
<img class="rounded max-h-[200px]" :src="img.src" />
|
||||||
</BaseCard>
|
</button>
|
||||||
|
</div>
|
||||||
|
</BaseCard>
|
||||||
|
|
||||||
<BaseCard v-if="showAttachments">
|
<BaseCard v-if="showAttachments">
|
||||||
<template #title> Attachments </template>
|
<template #title> Attachments </template>
|
||||||
<DetailsSection :details="attachmentDetails">
|
<DetailsSection :details="attachmentDetails">
|
||||||
<template #manuals>
|
<template #manuals>
|
||||||
<ItemAttachmentsList
|
<ItemAttachmentsList
|
||||||
v-if="attachments.manuals.length > 0"
|
v-if="attachments.manuals.length > 0"
|
||||||
:attachments="attachments.manuals"
|
:attachments="attachments.manuals"
|
||||||
:item-id="item.id"
|
:item-id="item.id"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
<template #attachments>
|
<template #attachments>
|
||||||
<ItemAttachmentsList
|
<ItemAttachmentsList
|
||||||
v-if="attachments.attachments.length > 0"
|
v-if="attachments.attachments.length > 0"
|
||||||
:attachments="attachments.attachments"
|
:attachments="attachments.attachments"
|
||||||
:item-id="item.id"
|
:item-id="item.id"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
<template #warranty>
|
<template #warranty>
|
||||||
<ItemAttachmentsList
|
<ItemAttachmentsList
|
||||||
v-if="attachments.warranty.length > 0"
|
v-if="attachments.warranty.length > 0"
|
||||||
:attachments="attachments.warranty"
|
:attachments="attachments.warranty"
|
||||||
:item-id="item.id"
|
:item-id="item.id"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
<template #receipts>
|
<template #receipts>
|
||||||
<ItemAttachmentsList
|
<ItemAttachmentsList
|
||||||
v-if="attachments.receipts.length > 0"
|
v-if="attachments.receipts.length > 0"
|
||||||
:attachments="attachments.receipts"
|
:attachments="attachments.receipts"
|
||||||
:item-id="item.id"
|
:item-id="item.id"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
</DetailsSection>
|
</DetailsSection>
|
||||||
</BaseCard>
|
</BaseCard>
|
||||||
|
|
||||||
<BaseCard v-if="showPurchase">
|
<BaseCard v-if="showPurchase">
|
||||||
<template #title> Purchase Details </template>
|
<template #title> Purchase Details </template>
|
||||||
<DetailsSection :details="purchaseDetails" />
|
<DetailsSection :details="purchaseDetails" />
|
||||||
</BaseCard>
|
</BaseCard>
|
||||||
|
|
||||||
<BaseCard v-if="showWarranty">
|
<BaseCard v-if="showWarranty">
|
||||||
<template #title> Warranty Details </template>
|
<template #title> Warranty Details </template>
|
||||||
<DetailsSection :details="warrantyDetails" />
|
<DetailsSection :details="warrantyDetails" />
|
||||||
</BaseCard>
|
</BaseCard>
|
||||||
|
|
||||||
<BaseCard v-if="showSold">
|
<BaseCard v-if="showSold">
|
||||||
<template #title> Sold Details </template>
|
<template #title> Sold Details </template>
|
||||||
<DetailsSection :details="soldDetails" />
|
<DetailsSection :details="soldDetails" />
|
||||||
</BaseCard>
|
</BaseCard>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="my-6 px-3">
|
<section v-if="!hasNested" class="my-6 px-3">
|
||||||
<BaseSectionHeader v-if="item && item.children && item.children.length > 0"> Child Items </BaseSectionHeader>
|
<BaseSectionHeader v-if="item && item.children && item.children.length > 0"> Child Items </BaseSectionHeader>
|
||||||
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||||
<ItemCard v-for="child in item.children" :key="child.id" :item="child" />
|
<ItemCard v-for="child in item.children" :key="child.id" :item="child" />
|
||||||
|
|
173
frontend/pages/item/[id]/index/log.vue
Normal file
173
frontend/pages/item/[id]/index/log.vue
Normal file
|
@ -0,0 +1,173 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
import DatePicker from "~~/components/Form/DatePicker.vue";
|
||||||
|
import { ItemOut } from "~~/lib/api/types/data-contracts";
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
item: ItemOut;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const api = useUserApi();
|
||||||
|
const toast = useNotifier();
|
||||||
|
|
||||||
|
const { data: log, refresh: refreshLog } = useAsyncData(async () => {
|
||||||
|
const { data } = await api.items.maintenance.getLog(props.item.id);
|
||||||
|
return data;
|
||||||
|
});
|
||||||
|
|
||||||
|
const stats = computed(() => {
|
||||||
|
if (!log.value) return [];
|
||||||
|
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
id: "total",
|
||||||
|
title: "Total Cost",
|
||||||
|
subtitle: "Sum over all entries",
|
||||||
|
value: fmtCurrency(log.value.costTotal),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "average",
|
||||||
|
title: "Monthly Average",
|
||||||
|
subtitle: "Average over all entries",
|
||||||
|
value: fmtCurrency(log.value.costAverage),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
});
|
||||||
|
|
||||||
|
const entry = reactive({
|
||||||
|
modal: false,
|
||||||
|
name: "",
|
||||||
|
date: new Date(),
|
||||||
|
description: "",
|
||||||
|
cost: "",
|
||||||
|
});
|
||||||
|
|
||||||
|
function newEntry() {
|
||||||
|
entry.modal = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createEntry() {
|
||||||
|
const { error } = await api.items.maintenance.create(props.item.id, {
|
||||||
|
name: entry.name,
|
||||||
|
date: entry.date,
|
||||||
|
description: entry.description,
|
||||||
|
cost: entry.cost,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
toast.error("Failed to create entry");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
entry.modal = false;
|
||||||
|
|
||||||
|
refreshLog();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deleteEntry(id: string) {
|
||||||
|
const { error } = await api.items.maintenance.delete(props.item.id, id);
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
toast.error("Failed to delete entry");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
refreshLog();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div v-if="log">
|
||||||
|
<BaseModal v-model="entry.modal">
|
||||||
|
<template #title> Create Entry </template>
|
||||||
|
<form @submit.prevent="createEntry">
|
||||||
|
<FormTextField v-model="entry.name" autofocus label="Entry Name" />
|
||||||
|
<DatePicker v-model="entry.date" label="Date" />
|
||||||
|
<FormTextArea v-model="entry.description" label="Notes" />
|
||||||
|
<FormTextField v-model="entry.cost" autofocus label="Cost" />
|
||||||
|
<div class="py-2 flex justify-end">
|
||||||
|
<BaseButton type="submit" class="ml-2">
|
||||||
|
<template #icon>
|
||||||
|
<Icon name="mdi-post" />
|
||||||
|
</template>
|
||||||
|
Create
|
||||||
|
</BaseButton>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</BaseModal>
|
||||||
|
|
||||||
|
<div class="flex">
|
||||||
|
<BaseButton class="ml-auto" size="sm" @click="newEntry()">
|
||||||
|
<template #icon>
|
||||||
|
<Icon name="mdi-post" />
|
||||||
|
</template>
|
||||||
|
Log Maintenance
|
||||||
|
</BaseButton>
|
||||||
|
</div>
|
||||||
|
<section class="page-layout my-6">
|
||||||
|
<div class="main-slot container space-y-6">
|
||||||
|
<BaseCard v-for="e in log.entries" :key="e.id">
|
||||||
|
<BaseSectionHeader class="p-6 border-b border-b-gray-300">
|
||||||
|
<span class="text-base-content">
|
||||||
|
{{ e.name }}
|
||||||
|
</span>
|
||||||
|
<template #description>
|
||||||
|
<div class="flex gap-2">
|
||||||
|
<div class="badge p-3">
|
||||||
|
<Icon name="mdi-calendar" class="mr-2" />
|
||||||
|
<DateTime :date="e.date" format="human" />
|
||||||
|
</div>
|
||||||
|
<div class="tooltip tooltip-primary" data-tip="Cost">
|
||||||
|
<div class="badge badge-primary p-3">
|
||||||
|
<Currency :amount="e.cost" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</BaseSectionHeader>
|
||||||
|
<div class="p-6">
|
||||||
|
<Markdown :source="e.description" />
|
||||||
|
</div>
|
||||||
|
<div class="flex justify-end p-4">
|
||||||
|
<BaseButton size="sm" @click="deleteEntry(e.id)">
|
||||||
|
<template #icon>
|
||||||
|
<Icon name="mdi-delete" />
|
||||||
|
</template>
|
||||||
|
Delete
|
||||||
|
</BaseButton>
|
||||||
|
</div>
|
||||||
|
</BaseCard>
|
||||||
|
</div>
|
||||||
|
<div class="side-slot space-y-6">
|
||||||
|
<div v-for="stat in stats" :key="stat.id" class="stats block shadow-xl border-l-primary">
|
||||||
|
<div class="stat">
|
||||||
|
<div class="stat-title">{{ stat.title }}</div>
|
||||||
|
<div class="stat-value text-primary">{{ stat.value }}</div>
|
||||||
|
<div class="stat-desc">{{ stat.subtitle }}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.page-layout {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: auto minmax(0, 1fr);
|
||||||
|
grid-template-rows: auto;
|
||||||
|
grid-template-areas: "side main";
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.side-slot {
|
||||||
|
grid-area: side;
|
||||||
|
}
|
||||||
|
|
||||||
|
.main-slot {
|
||||||
|
grid-area: main;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid {
|
||||||
|
display: grid;
|
||||||
|
}
|
||||||
|
</style>
|
File diff suppressed because it is too large
Load diff
|
@ -34,6 +34,7 @@ regex_replace: dict[re.Pattern, str] = {
|
||||||
"purchaseTime",
|
"purchaseTime",
|
||||||
"warrantyExpires",
|
"warrantyExpires",
|
||||||
"expiresAt",
|
"expiresAt",
|
||||||
|
"date",
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue