mirror of
https://github.com/sysadminsmedia/homebox.git
synced 2026-01-03 03:27:23 +01:00
Compare commits
31 Commits
fix/missin
...
feat/new-c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7c240a563b | ||
|
|
59ebf0af73 | ||
|
|
25e01d9606 | ||
|
|
b5b65af6b4 | ||
|
|
412977ea6c | ||
|
|
9f0b09be52 | ||
|
|
824a1d0bc4 | ||
|
|
c379a73a63 | ||
|
|
188bd054e5 | ||
|
|
d26118a515 | ||
|
|
149f16a600 | ||
|
|
58d6f9a28c | ||
|
|
6a8a25e3f8 | ||
|
|
a3954dab0f | ||
|
|
08d483d907 | ||
|
|
a53f89ceac | ||
|
|
5bbb969763 | ||
|
|
d6da63187b | ||
|
|
de419dc37d | ||
|
|
974d6914a2 | ||
|
|
d2aa022347 | ||
|
|
6af048dc93 | ||
|
|
73c42f4784 | ||
|
|
f42a917390 | ||
|
|
f149c3e4ab | ||
|
|
1dc1ee54e2 | ||
|
|
e8f215ce34 | ||
|
|
1aafbcd201 | ||
|
|
6dc2ae1bea | ||
|
|
976f68252d | ||
|
|
8e1947d971 |
15
.vscode/settings.json
vendored
15
.vscode/settings.json
vendored
@@ -1,7 +1,4 @@
|
||||
{
|
||||
"editor.codeActionsOnSave": {
|
||||
"source.fixAll.eslint": true
|
||||
},
|
||||
"yaml.schemas": {
|
||||
"https://squidfunk.github.io/mkdocs-material/schema.json": "mkdocs.yml"
|
||||
},
|
||||
@@ -13,5 +10,15 @@
|
||||
},
|
||||
"cSpell.words": [
|
||||
"debughandlers"
|
||||
]
|
||||
],
|
||||
// use ESLint to format code on save
|
||||
"editor.formatOnSave": true,
|
||||
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
|
||||
"editor.codeActionsOnSave": {
|
||||
"source.fixAll.eslint": true
|
||||
},
|
||||
"[typescript]": {
|
||||
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
|
||||
},
|
||||
"eslint.format.enable": true,
|
||||
}
|
||||
|
||||
35
backend/app/api/handlers/v1/v1_ctrl_actions.go
Normal file
35
backend/app/api/handlers/v1/v1_ctrl_actions.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/hay-kot/homebox/backend/internal/core/services"
|
||||
"github.com/hay-kot/homebox/backend/internal/sys/validate"
|
||||
"github.com/hay-kot/homebox/backend/pkgs/server"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type EnsureAssetIDResult struct {
|
||||
Completed int `json:"completed"`
|
||||
}
|
||||
|
||||
// HandleGroupInvitationsCreate godoc
|
||||
// @Summary Get the current user
|
||||
// @Tags Group
|
||||
// @Produce json
|
||||
// @Success 200 {object} EnsureAssetIDResult
|
||||
// @Router /v1/actions/ensure-asset-ids [Post]
|
||||
// @Security Bearer
|
||||
func (ctrl *V1Controller) HandleEnsureAssetID() server.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) error {
|
||||
ctx := services.NewContext(r.Context())
|
||||
|
||||
totalCompleted, err := ctrl.svc.Items.EnsureAssetID(ctx, ctx.GID)
|
||||
if err != nil {
|
||||
log.Err(err).Msg("failed to ensure asset id")
|
||||
return validate.NewRequestError(err, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return server.Respond(w, http.StatusOK, EnsureAssetIDResult{Completed: totalCompleted})
|
||||
}
|
||||
}
|
||||
@@ -13,8 +13,9 @@ import (
|
||||
|
||||
type (
|
||||
TokenResponse struct {
|
||||
Token string `json:"token"`
|
||||
ExpiresAt time.Time `json:"expiresAt"`
|
||||
Token string `json:"token"`
|
||||
ExpiresAt time.Time `json:"expiresAt"`
|
||||
AttachmentToken string `json:"attachmentToken"`
|
||||
}
|
||||
|
||||
LoginForm struct {
|
||||
@@ -76,8 +77,9 @@ func (ctrl *V1Controller) HandleAuthLogin() server.HandlerFunc {
|
||||
}
|
||||
|
||||
return server.Respond(w, http.StatusOK, TokenResponse{
|
||||
Token: "Bearer " + newToken.Raw,
|
||||
ExpiresAt: newToken.ExpiresAt,
|
||||
Token: "Bearer " + newToken.Raw,
|
||||
ExpiresAt: newToken.ExpiresAt,
|
||||
AttachmentToken: newToken.AttachmentToken,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,26 +24,6 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
// HandleGroupGet godoc
|
||||
// @Summary Get the current user's group
|
||||
// @Tags Group
|
||||
// @Produce json
|
||||
// @Success 200 {object} repo.GroupStatistics
|
||||
// @Router /v1/groups/statistics [Get]
|
||||
// @Security Bearer
|
||||
func (ctrl *V1Controller) HandleGroupStatistics() server.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) error {
|
||||
ctx := services.NewContext(r.Context())
|
||||
|
||||
stats, err := ctrl.repo.Groups.GroupStatistics(ctx, ctx.GID)
|
||||
if err != nil {
|
||||
return validate.NewRequestError(err, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return server.Respond(w, http.StatusOK, stats)
|
||||
}
|
||||
}
|
||||
|
||||
// HandleGroupGet godoc
|
||||
// @Summary Get the current user's group
|
||||
// @Tags Group
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"encoding/csv"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/hay-kot/homebox/backend/internal/core/services"
|
||||
@@ -30,7 +31,7 @@ func (ctrl *V1Controller) HandleItemsGetAll() server.HandlerFunc {
|
||||
|
||||
return repo.ItemQuery{
|
||||
Page: queryIntOrNegativeOne(params.Get("page")),
|
||||
PageSize: queryIntOrNegativeOne(params.Get("perPage")),
|
||||
PageSize: queryIntOrNegativeOne(params.Get("pageSize")),
|
||||
Search: params.Get("q"),
|
||||
LocationIDs: queryUUIDList(params, "locations"),
|
||||
LabelIDs: queryUUIDList(params, "labels"),
|
||||
@@ -42,6 +43,11 @@ func (ctrl *V1Controller) HandleItemsGetAll() server.HandlerFunc {
|
||||
ctx := services.NewContext(r.Context())
|
||||
items, err := ctrl.repo.Items.QueryByGroup(ctx, ctx.GID, extractQuery(r))
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return server.Respond(w, http.StatusOK, repo.PaginationResult[repo.ItemSummary]{
|
||||
Items: []repo.ItemSummary{},
|
||||
})
|
||||
}
|
||||
log.Err(err).Msg("failed to get items")
|
||||
return validate.NewRequestError(err, http.StatusInternalServerError)
|
||||
}
|
||||
@@ -65,8 +71,8 @@ func (ctrl *V1Controller) HandleItemsCreate() server.HandlerFunc {
|
||||
return validate.NewRequestError(err, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
user := services.UseUserCtx(r.Context())
|
||||
item, err := ctrl.repo.Items.Create(r.Context(), user.GroupID, createData)
|
||||
ctx := services.NewContext(r.Context())
|
||||
item, err := ctrl.svc.Items.Create(ctx, createData)
|
||||
if err != nil {
|
||||
log.Err(err).Msg("failed to create item")
|
||||
return validate.NewRequestError(err, http.StatusInternalServerError)
|
||||
@@ -178,8 +184,7 @@ func (ctrl *V1Controller) HandleItemsImport() server.HandlerFunc {
|
||||
return validate.NewRequestError(err, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
reader := csv.NewReader(file)
|
||||
data, err := reader.ReadAll()
|
||||
data, err := services.ReadCsv(file)
|
||||
if err != nil {
|
||||
log.Err(err).Msg("failed to read csv")
|
||||
return validate.NewRequestError(err, http.StatusInternalServerError)
|
||||
|
||||
@@ -2,7 +2,6 @@ package v1
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/hay-kot/homebox/backend/internal/core/services"
|
||||
@@ -97,39 +96,12 @@ func (ctrl *V1Controller) HandleItemAttachmentCreate() server.HandlerFunc {
|
||||
// @Summary retrieves an attachment for an item
|
||||
// @Tags Items Attachments
|
||||
// @Produce application/octet-stream
|
||||
// @Param id path string true "Item ID"
|
||||
// @Param token query string true "Attachment token"
|
||||
// @Success 200
|
||||
// @Router /v1/items/{id}/attachments/download [GET]
|
||||
// @Security Bearer
|
||||
func (ctrl *V1Controller) HandleItemAttachmentDownload() server.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) error {
|
||||
token := server.GetParam(r, "token", "")
|
||||
|
||||
doc, err := ctrl.svc.Items.AttachmentPath(r.Context(), token)
|
||||
|
||||
if err != nil {
|
||||
log.Err(err).Msg("failed to get attachment")
|
||||
return validate.NewRequestError(err, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", doc.Title))
|
||||
w.Header().Set("Content-Type", "application/octet-stream")
|
||||
http.ServeFile(w, r, doc.Path)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// HandleItemAttachmentToken godocs
|
||||
// @Summary retrieves an attachment for an item
|
||||
// @Tags Items Attachments
|
||||
// @Produce application/octet-stream
|
||||
// @Param id path string true "Item ID"
|
||||
// @Param attachment_id path string true "Attachment ID"
|
||||
// @Success 200 {object} ItemAttachmentToken
|
||||
// @Router /v1/items/{id}/attachments/{attachment_id} [GET]
|
||||
// @Security Bearer
|
||||
func (ctrl *V1Controller) HandleItemAttachmentToken() server.HandlerFunc {
|
||||
func (ctrl *V1Controller) HandleItemAttachmentGet() server.HandlerFunc {
|
||||
return ctrl.handleItemAttachmentsHandler
|
||||
}
|
||||
|
||||
@@ -171,33 +143,15 @@ func (ctrl *V1Controller) handleItemAttachmentsHandler(w http.ResponseWriter, r
|
||||
|
||||
ctx := services.NewContext(r.Context())
|
||||
switch r.Method {
|
||||
// Token Handler
|
||||
case http.MethodGet:
|
||||
token, err := ctrl.svc.Items.AttachmentToken(ctx, ID, attachmentID)
|
||||
doc, err := ctrl.svc.Items.AttachmentPath(r.Context(), attachmentID)
|
||||
if err != nil {
|
||||
switch err {
|
||||
case services.ErrNotFound:
|
||||
log.Err(err).
|
||||
Str("id", attachmentID.String()).
|
||||
Msg("failed to find attachment with id")
|
||||
|
||||
return validate.NewRequestError(err, http.StatusNotFound)
|
||||
|
||||
case services.ErrFileNotFound:
|
||||
log.Err(err).
|
||||
Str("id", attachmentID.String()).
|
||||
Msg("failed to find file path for attachment with id")
|
||||
log.Warn().Msg("attachment with no file path removed from database")
|
||||
|
||||
return validate.NewRequestError(err, http.StatusNotFound)
|
||||
|
||||
default:
|
||||
log.Err(err).Msg("failed to get attachment")
|
||||
return validate.NewRequestError(err, http.StatusInternalServerError)
|
||||
}
|
||||
log.Err(err).Msg("failed to get attachment path")
|
||||
return validate.NewRequestError(err, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return server.Respond(w, http.StatusOK, ItemAttachmentToken{Token: token})
|
||||
http.ServeFile(w, r, doc.Path)
|
||||
return nil
|
||||
|
||||
// Delete Attachment Handler
|
||||
case http.MethodDelete:
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
109
backend/app/api/handlers/v1/v1_ctrl_statistics.go
Normal file
109
backend/app/api/handlers/v1/v1_ctrl_statistics.go
Normal file
@@ -0,0 +1,109 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/hay-kot/homebox/backend/internal/core/services"
|
||||
"github.com/hay-kot/homebox/backend/internal/sys/validate"
|
||||
"github.com/hay-kot/homebox/backend/pkgs/server"
|
||||
)
|
||||
|
||||
// HandleGroupGet godoc
|
||||
// @Summary Get the current user's group statistics
|
||||
// @Tags Statistics
|
||||
// @Produce json
|
||||
// @Success 200 {object} []repo.TotalsByOrganizer
|
||||
// @Router /v1/groups/statistics/locations [GET]
|
||||
// @Security Bearer
|
||||
func (ctrl *V1Controller) HandleGroupStatisticsLocations() server.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) error {
|
||||
ctx := services.NewContext(r.Context())
|
||||
|
||||
stats, err := ctrl.repo.Groups.StatsLocationsByPurchasePrice(ctx, ctx.GID)
|
||||
if err != nil {
|
||||
return validate.NewRequestError(err, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return server.Respond(w, http.StatusOK, stats)
|
||||
}
|
||||
}
|
||||
|
||||
// HandleGroupGet godoc
|
||||
// @Summary Get the current user's group statistics
|
||||
// @Tags Statistics
|
||||
// @Produce json
|
||||
// @Success 200 {object} []repo.TotalsByOrganizer
|
||||
// @Router /v1/groups/statistics/labels [GET]
|
||||
// @Security Bearer
|
||||
func (ctrl *V1Controller) HandleGroupStatisticsLabels() server.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) error {
|
||||
ctx := services.NewContext(r.Context())
|
||||
|
||||
stats, err := ctrl.repo.Groups.StatsLabelsByPurchasePrice(ctx, ctx.GID)
|
||||
if err != nil {
|
||||
return validate.NewRequestError(err, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return server.Respond(w, http.StatusOK, stats)
|
||||
}
|
||||
}
|
||||
|
||||
// HandleGroupGet godoc
|
||||
// @Summary Get the current user's group statistics
|
||||
// @Tags Statistics
|
||||
// @Produce json
|
||||
// @Success 200 {object} repo.GroupStatistics
|
||||
// @Router /v1/groups/statistics [GET]
|
||||
// @Security Bearer
|
||||
func (ctrl *V1Controller) HandleGroupStatistics() server.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) error {
|
||||
ctx := services.NewContext(r.Context())
|
||||
|
||||
stats, err := ctrl.repo.Groups.StatsGroup(ctx, ctx.GID)
|
||||
if err != nil {
|
||||
return validate.NewRequestError(err, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return server.Respond(w, http.StatusOK, stats)
|
||||
}
|
||||
}
|
||||
|
||||
// HandleGroupGet godoc
|
||||
// @Summary Queries the changes overtime of the purchase price over time
|
||||
// @Tags Statistics
|
||||
// @Produce json
|
||||
// @Success 200 {object} repo.ValueOverTime
|
||||
// @Param start query string false "start date"
|
||||
// @Param end query string false "end date"
|
||||
// @Router /v1/groups/statistics/purchase-price [GET]
|
||||
// @Security Bearer
|
||||
func (ctrl *V1Controller) HandleGroupStatisticsPriceOverTime() server.HandlerFunc {
|
||||
parseDate := func(datestr string, defaultDate time.Time) (time.Time, error) {
|
||||
if datestr == "" {
|
||||
return defaultDate, nil
|
||||
}
|
||||
return time.Parse("2006-01-02", datestr)
|
||||
}
|
||||
|
||||
return func(w http.ResponseWriter, r *http.Request) error {
|
||||
ctx := services.NewContext(r.Context())
|
||||
|
||||
startDate, err := parseDate(r.URL.Query().Get("start"), time.Now().AddDate(0, -1, 0))
|
||||
if err != nil {
|
||||
return validate.NewRequestError(err, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
endDate, err := parseDate(r.URL.Query().Get("end"), time.Now())
|
||||
if err != nil {
|
||||
return validate.NewRequestError(err, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
stats, err := ctrl.repo.Groups.StatsPurchasePrice(ctx, ctx.GID, startDate, endDate)
|
||||
if err != nil {
|
||||
return validate.NewRequestError(err, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return server.Respond(w, http.StatusOK, stats)
|
||||
}
|
||||
}
|
||||
@@ -112,7 +112,10 @@ func run(cfg *config.Config) error {
|
||||
|
||||
app.db = c
|
||||
app.repos = repo.New(c, cfg.Storage.Data)
|
||||
app.services = services.New(app.repos)
|
||||
app.services = services.New(
|
||||
app.repos,
|
||||
services.WithAutoIncrementAssetID(cfg.Options.AutoIncrementAssetID),
|
||||
)
|
||||
|
||||
// =========================================================================
|
||||
// Start Server\
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
@@ -10,17 +11,87 @@ import (
|
||||
"github.com/hay-kot/homebox/backend/pkgs/server"
|
||||
)
|
||||
|
||||
type tokenHasKey struct {
|
||||
key string
|
||||
}
|
||||
|
||||
var (
|
||||
hashedToken = tokenHasKey{key: "hashedToken"}
|
||||
)
|
||||
|
||||
type RoleMode int
|
||||
|
||||
const (
|
||||
RoleModeOr RoleMode = 0
|
||||
RoleModeAnd RoleMode = 1
|
||||
)
|
||||
|
||||
// mwRoles is a middleware that will validate the required roles are met. All roles
|
||||
// are required to be met for the request to be allowed. If the user does not have
|
||||
// the required roles, a 403 Forbidden will be returned.
|
||||
//
|
||||
// WARNING: This middleware _MUST_ be called after mwAuthToken or else it will panic
|
||||
func (a *app) mwRoles(rm RoleMode, required ...string) server.Middleware {
|
||||
return func(next server.Handler) server.Handler {
|
||||
return server.HandlerFunc(func(w http.ResponseWriter, r *http.Request) error {
|
||||
ctx := r.Context()
|
||||
|
||||
maybeToken := ctx.Value(hashedToken)
|
||||
if maybeToken == nil {
|
||||
panic("mwRoles: token not found in context, you must call mwAuthToken before mwRoles")
|
||||
}
|
||||
|
||||
token := maybeToken.(string)
|
||||
|
||||
roles, err := a.repos.AuthTokens.GetRoles(r.Context(), token)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
outer:
|
||||
switch rm {
|
||||
case RoleModeOr:
|
||||
for _, role := range required {
|
||||
if roles.Contains(role) {
|
||||
break outer
|
||||
}
|
||||
}
|
||||
return validate.NewRequestError(errors.New("Forbidden"), http.StatusForbidden)
|
||||
case RoleModeAnd:
|
||||
for _, req := range required {
|
||||
if !roles.Contains(req) {
|
||||
return validate.NewRequestError(errors.New("Unauthorized"), http.StatusForbidden)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// mwAuthToken is a middleware that will check the database for a stateful token
|
||||
// and attach it to the request context with the user, or return a 401 if it doesn't exist.
|
||||
// and attach it's user to the request context, or return an appropriate error.
|
||||
// Authorization support is by token via Headers or Query Parameter
|
||||
//
|
||||
// Example:
|
||||
// - header = "Bearer 1234567890"
|
||||
// - query = "?access_token=1234567890"
|
||||
func (a *app) mwAuthToken(next server.Handler) server.Handler {
|
||||
return server.HandlerFunc(func(w http.ResponseWriter, r *http.Request) error {
|
||||
requestToken := r.Header.Get("Authorization")
|
||||
|
||||
if requestToken == "" {
|
||||
return validate.NewRequestError(errors.New("Authorization header is required"), http.StatusUnauthorized)
|
||||
// check for query param
|
||||
requestToken = r.URL.Query().Get("access_token")
|
||||
if requestToken == "" {
|
||||
return validate.NewRequestError(errors.New("Authorization header or query is required"), http.StatusUnauthorized)
|
||||
}
|
||||
}
|
||||
|
||||
requestToken = strings.TrimPrefix(requestToken, "Bearer ")
|
||||
|
||||
r = r.WithContext(context.WithValue(r.Context(), hashedToken, requestToken))
|
||||
|
||||
usr, err := a.services.User.GetSelf(r.Context(), requestToken)
|
||||
|
||||
// Check the database for the token
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/hay-kot/homebox/backend/app/api/handlers/debughandlers"
|
||||
v1 "github.com/hay-kot/homebox/backend/app/api/handlers/v1"
|
||||
_ "github.com/hay-kot/homebox/backend/app/api/static/docs"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/authroles"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/repo"
|
||||
"github.com/hay-kot/homebox/backend/pkgs/server"
|
||||
httpSwagger "github.com/swaggo/http-swagger" // http-swagger middleware
|
||||
@@ -51,7 +52,7 @@ func (a *app) mountRoutes(repos *repo.AllRepos) {
|
||||
a.services,
|
||||
a.repos,
|
||||
v1.WithMaxUploadSize(a.conf.Web.MaxUploadSize),
|
||||
v1.WithRegistration(a.conf.AllowRegistration),
|
||||
v1.WithRegistration(a.conf.Options.AllowRegistration),
|
||||
v1.WithDemoStatus(a.conf.Demo), // Disable Password Change in Demo Mode
|
||||
)
|
||||
|
||||
@@ -64,47 +65,63 @@ func (a *app) mountRoutes(repos *repo.AllRepos) {
|
||||
a.server.Post(v1Base("/users/register"), v1Ctrl.HandleUserRegistration())
|
||||
a.server.Post(v1Base("/users/login"), v1Ctrl.HandleAuthLogin())
|
||||
|
||||
// Attachment download URl needs a `token` query param to be passed in the request.
|
||||
// and also needs to be outside of the `auth` middleware.
|
||||
a.server.Get(v1Base("/items/{id}/attachments/download"), v1Ctrl.HandleItemAttachmentDownload())
|
||||
userMW := []server.Middleware{
|
||||
a.mwAuthToken,
|
||||
a.mwRoles(RoleModeOr, authroles.RoleUser.String()),
|
||||
}
|
||||
|
||||
a.server.Get(v1Base("/users/self"), v1Ctrl.HandleUserSelf(), a.mwAuthToken)
|
||||
a.server.Put(v1Base("/users/self"), v1Ctrl.HandleUserSelfUpdate(), a.mwAuthToken)
|
||||
a.server.Delete(v1Base("/users/self"), v1Ctrl.HandleUserSelfDelete(), a.mwAuthToken)
|
||||
a.server.Post(v1Base("/users/logout"), v1Ctrl.HandleAuthLogout(), a.mwAuthToken)
|
||||
a.server.Get(v1Base("/users/refresh"), v1Ctrl.HandleAuthRefresh(), a.mwAuthToken)
|
||||
a.server.Put(v1Base("/users/self/change-password"), v1Ctrl.HandleUserSelfChangePassword(), a.mwAuthToken)
|
||||
a.server.Get(v1Base("/users/self"), v1Ctrl.HandleUserSelf(), userMW...)
|
||||
a.server.Put(v1Base("/users/self"), v1Ctrl.HandleUserSelfUpdate(), userMW...)
|
||||
a.server.Delete(v1Base("/users/self"), v1Ctrl.HandleUserSelfDelete(), userMW...)
|
||||
a.server.Post(v1Base("/users/logout"), v1Ctrl.HandleAuthLogout(), userMW...)
|
||||
a.server.Get(v1Base("/users/refresh"), v1Ctrl.HandleAuthRefresh(), userMW...)
|
||||
a.server.Put(v1Base("/users/self/change-password"), v1Ctrl.HandleUserSelfChangePassword(), userMW...)
|
||||
|
||||
a.server.Post(v1Base("/groups/invitations"), v1Ctrl.HandleGroupInvitationsCreate(), a.mwAuthToken)
|
||||
a.server.Get(v1Base("/groups/statistics"), v1Ctrl.HandleGroupStatistics(), a.mwAuthToken)
|
||||
a.server.Post(v1Base("/groups/invitations"), v1Ctrl.HandleGroupInvitationsCreate(), userMW...)
|
||||
a.server.Get(v1Base("/groups/statistics"), v1Ctrl.HandleGroupStatistics(), userMW...)
|
||||
a.server.Get(v1Base("/groups/statistics/purchase-price"), v1Ctrl.HandleGroupStatisticsPriceOverTime(), userMW...)
|
||||
a.server.Get(v1Base("/groups/statistics/locations"), v1Ctrl.HandleGroupStatisticsLocations(), userMW...)
|
||||
a.server.Get(v1Base("/groups/statistics/labels"), v1Ctrl.HandleGroupStatisticsLabels(), userMW...)
|
||||
|
||||
// TODO: I don't like /groups being the URL for users
|
||||
a.server.Get(v1Base("/groups"), v1Ctrl.HandleGroupGet(), a.mwAuthToken)
|
||||
a.server.Put(v1Base("/groups"), v1Ctrl.HandleGroupUpdate(), a.mwAuthToken)
|
||||
a.server.Get(v1Base("/groups"), v1Ctrl.HandleGroupGet(), userMW...)
|
||||
a.server.Put(v1Base("/groups"), v1Ctrl.HandleGroupUpdate(), userMW...)
|
||||
|
||||
a.server.Get(v1Base("/locations"), v1Ctrl.HandleLocationGetAll(), a.mwAuthToken)
|
||||
a.server.Post(v1Base("/locations"), v1Ctrl.HandleLocationCreate(), a.mwAuthToken)
|
||||
a.server.Get(v1Base("/locations/{id}"), v1Ctrl.HandleLocationGet(), a.mwAuthToken)
|
||||
a.server.Put(v1Base("/locations/{id}"), v1Ctrl.HandleLocationUpdate(), a.mwAuthToken)
|
||||
a.server.Delete(v1Base("/locations/{id}"), v1Ctrl.HandleLocationDelete(), a.mwAuthToken)
|
||||
a.server.Post(v1Base("/actions/ensure-asset-ids"), v1Ctrl.HandleEnsureAssetID(), userMW...)
|
||||
|
||||
a.server.Get(v1Base("/labels"), v1Ctrl.HandleLabelsGetAll(), a.mwAuthToken)
|
||||
a.server.Post(v1Base("/labels"), v1Ctrl.HandleLabelsCreate(), a.mwAuthToken)
|
||||
a.server.Get(v1Base("/labels/{id}"), v1Ctrl.HandleLabelGet(), a.mwAuthToken)
|
||||
a.server.Put(v1Base("/labels/{id}"), v1Ctrl.HandleLabelUpdate(), a.mwAuthToken)
|
||||
a.server.Delete(v1Base("/labels/{id}"), v1Ctrl.HandleLabelDelete(), a.mwAuthToken)
|
||||
a.server.Get(v1Base("/locations"), v1Ctrl.HandleLocationGetAll(), userMW...)
|
||||
a.server.Post(v1Base("/locations"), v1Ctrl.HandleLocationCreate(), userMW...)
|
||||
a.server.Get(v1Base("/locations/{id}"), v1Ctrl.HandleLocationGet(), userMW...)
|
||||
a.server.Put(v1Base("/locations/{id}"), v1Ctrl.HandleLocationUpdate(), userMW...)
|
||||
a.server.Delete(v1Base("/locations/{id}"), v1Ctrl.HandleLocationDelete(), userMW...)
|
||||
|
||||
a.server.Get(v1Base("/items"), v1Ctrl.HandleItemsGetAll(), a.mwAuthToken)
|
||||
a.server.Post(v1Base("/items/import"), v1Ctrl.HandleItemsImport(), a.mwAuthToken)
|
||||
a.server.Post(v1Base("/items"), v1Ctrl.HandleItemsCreate(), a.mwAuthToken)
|
||||
a.server.Get(v1Base("/items/{id}"), v1Ctrl.HandleItemGet(), a.mwAuthToken)
|
||||
a.server.Put(v1Base("/items/{id}"), v1Ctrl.HandleItemUpdate(), a.mwAuthToken)
|
||||
a.server.Delete(v1Base("/items/{id}"), v1Ctrl.HandleItemDelete(), a.mwAuthToken)
|
||||
a.server.Get(v1Base("/labels"), v1Ctrl.HandleLabelsGetAll(), userMW...)
|
||||
a.server.Post(v1Base("/labels"), v1Ctrl.HandleLabelsCreate(), userMW...)
|
||||
a.server.Get(v1Base("/labels/{id}"), v1Ctrl.HandleLabelGet(), userMW...)
|
||||
a.server.Put(v1Base("/labels/{id}"), v1Ctrl.HandleLabelUpdate(), userMW...)
|
||||
a.server.Delete(v1Base("/labels/{id}"), v1Ctrl.HandleLabelDelete(), userMW...)
|
||||
|
||||
a.server.Post(v1Base("/items/{id}/attachments"), v1Ctrl.HandleItemAttachmentCreate(), a.mwAuthToken)
|
||||
a.server.Get(v1Base("/items/{id}/attachments/{attachment_id}"), v1Ctrl.HandleItemAttachmentToken(), a.mwAuthToken)
|
||||
a.server.Put(v1Base("/items/{id}/attachments/{attachment_id}"), v1Ctrl.HandleItemAttachmentUpdate(), a.mwAuthToken)
|
||||
a.server.Delete(v1Base("/items/{id}/attachments/{attachment_id}"), v1Ctrl.HandleItemAttachmentDelete(), a.mwAuthToken)
|
||||
a.server.Get(v1Base("/items"), v1Ctrl.HandleItemsGetAll(), userMW...)
|
||||
a.server.Post(v1Base("/items/import"), v1Ctrl.HandleItemsImport(), userMW...)
|
||||
a.server.Post(v1Base("/items"), v1Ctrl.HandleItemsCreate(), userMW...)
|
||||
a.server.Get(v1Base("/items/{id}"), v1Ctrl.HandleItemGet(), userMW...)
|
||||
a.server.Put(v1Base("/items/{id}"), v1Ctrl.HandleItemUpdate(), userMW...)
|
||||
a.server.Delete(v1Base("/items/{id}"), v1Ctrl.HandleItemDelete(), userMW...)
|
||||
|
||||
a.server.Post(v1Base("/items/{id}/attachments"), v1Ctrl.HandleItemAttachmentCreate(), 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.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(
|
||||
v1Base("/items/{id}/attachments/{attachment_id}"),
|
||||
v1Ctrl.HandleItemAttachmentGet(),
|
||||
a.mwAuthToken, a.mwRoles(RoleModeOr, authroles.RoleUser.String(), authroles.RoleAttachments.String()),
|
||||
)
|
||||
|
||||
a.server.NotFound(notFoundHandler())
|
||||
}
|
||||
|
||||
@@ -21,6 +21,30 @@ const docTemplate = `{
|
||||
"host": "{{.Host}}",
|
||||
"basePath": "{{.BasePath}}",
|
||||
"paths": {
|
||||
"/v1/actions/ensure-asset-ids": {
|
||||
"post": {
|
||||
"security": [
|
||||
{
|
||||
"Bearer": []
|
||||
}
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Group"
|
||||
],
|
||||
"summary": "Get the current user",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/v1.EnsureAssetIDResult"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/groups": {
|
||||
"get": {
|
||||
"security": [
|
||||
@@ -124,9 +148,9 @@ const docTemplate = `{
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Group"
|
||||
"Statistics"
|
||||
],
|
||||
"summary": "Get the current user's group",
|
||||
"summary": "Get the current user's group statistics",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
@@ -137,6 +161,98 @@ const docTemplate = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/groups/statistics/labels": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"Bearer": []
|
||||
}
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Statistics"
|
||||
],
|
||||
"summary": "Get the current user's group statistics",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/repo.TotalsByOrganizer"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/groups/statistics/locations": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"Bearer": []
|
||||
}
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Statistics"
|
||||
],
|
||||
"summary": "Get the current user's group statistics",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/repo.TotalsByOrganizer"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/groups/statistics/purchase-price": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"Bearer": []
|
||||
}
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Statistics"
|
||||
],
|
||||
"summary": "Queries the changes overtime of the purchase price over time",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "start date",
|
||||
"name": "start",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "end date",
|
||||
"name": "end",
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/repo.ValueOverTime"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/items": {
|
||||
"get": {
|
||||
"security": [
|
||||
@@ -425,43 +541,6 @@ const docTemplate = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/items/{id}/attachments/download": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"Bearer": []
|
||||
}
|
||||
],
|
||||
"produces": [
|
||||
"application/octet-stream"
|
||||
],
|
||||
"tags": [
|
||||
"Items Attachments"
|
||||
],
|
||||
"summary": "retrieves an attachment for an item",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Item ID",
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Attachment token",
|
||||
"name": "token",
|
||||
"in": "query",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/items/{id}/attachments/{attachment_id}": {
|
||||
"get": {
|
||||
"security": [
|
||||
@@ -578,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": {
|
||||
"get": {
|
||||
"security": [
|
||||
@@ -1213,6 +1403,9 @@ const docTemplate = `{
|
||||
"repo.GroupStatistics": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"totalItemPrice": {
|
||||
"type": "number"
|
||||
},
|
||||
"totalItems": {
|
||||
"type": "integer"
|
||||
},
|
||||
@@ -1224,6 +1417,9 @@ const docTemplate = `{
|
||||
},
|
||||
"totalUsers": {
|
||||
"type": "integer"
|
||||
},
|
||||
"totalWithWarranty": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -1326,6 +1522,10 @@ const docTemplate = `{
|
||||
"archived": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"assetId": {
|
||||
"type": "string",
|
||||
"example": "0"
|
||||
},
|
||||
"attachments": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
@@ -1465,6 +1665,10 @@ const docTemplate = `{
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"purchasePrice": {
|
||||
"type": "string",
|
||||
"example": "0"
|
||||
},
|
||||
"quantity": {
|
||||
"type": "integer"
|
||||
},
|
||||
@@ -1479,6 +1683,9 @@ const docTemplate = `{
|
||||
"archived": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"assetId": {
|
||||
"type": "string"
|
||||
},
|
||||
"description": {
|
||||
"type": "string"
|
||||
},
|
||||
@@ -1733,6 +1940,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": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -1753,6 +2037,20 @@ const docTemplate = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"repo.TotalsByOrganizer": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"total": {
|
||||
"type": "number"
|
||||
}
|
||||
}
|
||||
},
|
||||
"repo.UserOut": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -1790,6 +2088,43 @@ const docTemplate = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"repo.ValueOverTime": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"end": {
|
||||
"type": "string"
|
||||
},
|
||||
"entries": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/repo.ValueOverTimeEntry"
|
||||
}
|
||||
},
|
||||
"start": {
|
||||
"type": "string"
|
||||
},
|
||||
"valueAtEnd": {
|
||||
"type": "number"
|
||||
},
|
||||
"valueAtStart": {
|
||||
"type": "number"
|
||||
}
|
||||
}
|
||||
},
|
||||
"repo.ValueOverTimeEntry": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"date": {
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"value": {
|
||||
"type": "number"
|
||||
}
|
||||
}
|
||||
},
|
||||
"server.ErrorResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -1891,6 +2226,14 @@ const docTemplate = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"v1.EnsureAssetIDResult": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"completed": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"v1.GroupInvitation": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -1927,6 +2270,9 @@ const docTemplate = `{
|
||||
"v1.TokenResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"attachmentToken": {
|
||||
"type": "string"
|
||||
},
|
||||
"expiresAt": {
|
||||
"type": "string"
|
||||
},
|
||||
|
||||
@@ -13,6 +13,30 @@
|
||||
},
|
||||
"basePath": "/api",
|
||||
"paths": {
|
||||
"/v1/actions/ensure-asset-ids": {
|
||||
"post": {
|
||||
"security": [
|
||||
{
|
||||
"Bearer": []
|
||||
}
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Group"
|
||||
],
|
||||
"summary": "Get the current user",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/v1.EnsureAssetIDResult"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/groups": {
|
||||
"get": {
|
||||
"security": [
|
||||
@@ -116,9 +140,9 @@
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Group"
|
||||
"Statistics"
|
||||
],
|
||||
"summary": "Get the current user's group",
|
||||
"summary": "Get the current user's group statistics",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
@@ -129,6 +153,98 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/groups/statistics/labels": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"Bearer": []
|
||||
}
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Statistics"
|
||||
],
|
||||
"summary": "Get the current user's group statistics",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/repo.TotalsByOrganizer"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/groups/statistics/locations": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"Bearer": []
|
||||
}
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Statistics"
|
||||
],
|
||||
"summary": "Get the current user's group statistics",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/repo.TotalsByOrganizer"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/groups/statistics/purchase-price": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"Bearer": []
|
||||
}
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Statistics"
|
||||
],
|
||||
"summary": "Queries the changes overtime of the purchase price over time",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "start date",
|
||||
"name": "start",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "end date",
|
||||
"name": "end",
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/repo.ValueOverTime"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/items": {
|
||||
"get": {
|
||||
"security": [
|
||||
@@ -417,43 +533,6 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/items/{id}/attachments/download": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"Bearer": []
|
||||
}
|
||||
],
|
||||
"produces": [
|
||||
"application/octet-stream"
|
||||
],
|
||||
"tags": [
|
||||
"Items Attachments"
|
||||
],
|
||||
"summary": "retrieves an attachment for an item",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Item ID",
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Attachment token",
|
||||
"name": "token",
|
||||
"in": "query",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/items/{id}/attachments/{attachment_id}": {
|
||||
"get": {
|
||||
"security": [
|
||||
@@ -570,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": {
|
||||
"get": {
|
||||
"security": [
|
||||
@@ -1205,6 +1395,9 @@
|
||||
"repo.GroupStatistics": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"totalItemPrice": {
|
||||
"type": "number"
|
||||
},
|
||||
"totalItems": {
|
||||
"type": "integer"
|
||||
},
|
||||
@@ -1216,6 +1409,9 @@
|
||||
},
|
||||
"totalUsers": {
|
||||
"type": "integer"
|
||||
},
|
||||
"totalWithWarranty": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -1318,6 +1514,10 @@
|
||||
"archived": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"assetId": {
|
||||
"type": "string",
|
||||
"example": "0"
|
||||
},
|
||||
"attachments": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
@@ -1457,6 +1657,10 @@
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"purchasePrice": {
|
||||
"type": "string",
|
||||
"example": "0"
|
||||
},
|
||||
"quantity": {
|
||||
"type": "integer"
|
||||
},
|
||||
@@ -1471,6 +1675,9 @@
|
||||
"archived": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"assetId": {
|
||||
"type": "string"
|
||||
},
|
||||
"description": {
|
||||
"type": "string"
|
||||
},
|
||||
@@ -1725,6 +1932,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": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -1745,6 +2029,20 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"repo.TotalsByOrganizer": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"total": {
|
||||
"type": "number"
|
||||
}
|
||||
}
|
||||
},
|
||||
"repo.UserOut": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -1782,6 +2080,43 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"repo.ValueOverTime": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"end": {
|
||||
"type": "string"
|
||||
},
|
||||
"entries": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/repo.ValueOverTimeEntry"
|
||||
}
|
||||
},
|
||||
"start": {
|
||||
"type": "string"
|
||||
},
|
||||
"valueAtEnd": {
|
||||
"type": "number"
|
||||
},
|
||||
"valueAtStart": {
|
||||
"type": "number"
|
||||
}
|
||||
}
|
||||
},
|
||||
"repo.ValueOverTimeEntry": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"date": {
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"value": {
|
||||
"type": "number"
|
||||
}
|
||||
}
|
||||
},
|
||||
"server.ErrorResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -1883,6 +2218,14 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"v1.EnsureAssetIDResult": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"completed": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"v1.GroupInvitation": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -1919,6 +2262,9 @@
|
||||
"v1.TokenResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"attachmentToken": {
|
||||
"type": "string"
|
||||
},
|
||||
"expiresAt": {
|
||||
"type": "string"
|
||||
},
|
||||
|
||||
@@ -24,6 +24,8 @@ definitions:
|
||||
type: object
|
||||
repo.GroupStatistics:
|
||||
properties:
|
||||
totalItemPrice:
|
||||
type: number
|
||||
totalItems:
|
||||
type: integer
|
||||
totalLabels:
|
||||
@@ -32,6 +34,8 @@ definitions:
|
||||
type: integer
|
||||
totalUsers:
|
||||
type: integer
|
||||
totalWithWarranty:
|
||||
type: integer
|
||||
type: object
|
||||
repo.GroupUpdate:
|
||||
properties:
|
||||
@@ -98,6 +102,9 @@ definitions:
|
||||
properties:
|
||||
archived:
|
||||
type: boolean
|
||||
assetId:
|
||||
example: "0"
|
||||
type: string
|
||||
attachments:
|
||||
items:
|
||||
$ref: '#/definitions/repo.ItemAttachment'
|
||||
@@ -195,6 +202,9 @@ definitions:
|
||||
x-omitempty: true
|
||||
name:
|
||||
type: string
|
||||
purchasePrice:
|
||||
example: "0"
|
||||
type: string
|
||||
quantity:
|
||||
type: integer
|
||||
updatedAt:
|
||||
@@ -204,6 +214,8 @@ definitions:
|
||||
properties:
|
||||
archived:
|
||||
type: boolean
|
||||
assetId:
|
||||
type: string
|
||||
description:
|
||||
type: string
|
||||
fields:
|
||||
@@ -374,6 +386,57 @@ definitions:
|
||||
type: string
|
||||
x-nullable: true
|
||||
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:
|
||||
properties:
|
||||
items:
|
||||
@@ -387,6 +450,15 @@ definitions:
|
||||
total:
|
||||
type: integer
|
||||
type: object
|
||||
repo.TotalsByOrganizer:
|
||||
properties:
|
||||
id:
|
||||
type: string
|
||||
name:
|
||||
type: string
|
||||
total:
|
||||
type: number
|
||||
type: object
|
||||
repo.UserOut:
|
||||
properties:
|
||||
email:
|
||||
@@ -411,6 +483,30 @@ definitions:
|
||||
name:
|
||||
type: string
|
||||
type: object
|
||||
repo.ValueOverTime:
|
||||
properties:
|
||||
end:
|
||||
type: string
|
||||
entries:
|
||||
items:
|
||||
$ref: '#/definitions/repo.ValueOverTimeEntry'
|
||||
type: array
|
||||
start:
|
||||
type: string
|
||||
valueAtEnd:
|
||||
type: number
|
||||
valueAtStart:
|
||||
type: number
|
||||
type: object
|
||||
repo.ValueOverTimeEntry:
|
||||
properties:
|
||||
date:
|
||||
type: string
|
||||
name:
|
||||
type: string
|
||||
value:
|
||||
type: number
|
||||
type: object
|
||||
server.ErrorResponse:
|
||||
properties:
|
||||
error:
|
||||
@@ -477,6 +573,11 @@ definitions:
|
||||
new:
|
||||
type: string
|
||||
type: object
|
||||
v1.EnsureAssetIDResult:
|
||||
properties:
|
||||
completed:
|
||||
type: integer
|
||||
type: object
|
||||
v1.GroupInvitation:
|
||||
properties:
|
||||
expiresAt:
|
||||
@@ -500,6 +601,8 @@ definitions:
|
||||
type: object
|
||||
v1.TokenResponse:
|
||||
properties:
|
||||
attachmentToken:
|
||||
type: string
|
||||
expiresAt:
|
||||
type: string
|
||||
token:
|
||||
@@ -516,6 +619,20 @@ info:
|
||||
title: Go API Templates
|
||||
version: "1.0"
|
||||
paths:
|
||||
/v1/actions/ensure-asset-ids:
|
||||
post:
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/v1.EnsureAssetIDResult'
|
||||
security:
|
||||
- Bearer: []
|
||||
summary: Get the current user
|
||||
tags:
|
||||
- Group
|
||||
/v1/groups:
|
||||
get:
|
||||
produces:
|
||||
@@ -582,9 +699,64 @@ paths:
|
||||
$ref: '#/definitions/repo.GroupStatistics'
|
||||
security:
|
||||
- Bearer: []
|
||||
summary: Get the current user's group
|
||||
summary: Get the current user's group statistics
|
||||
tags:
|
||||
- Group
|
||||
- Statistics
|
||||
/v1/groups/statistics/labels:
|
||||
get:
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
items:
|
||||
$ref: '#/definitions/repo.TotalsByOrganizer'
|
||||
type: array
|
||||
security:
|
||||
- Bearer: []
|
||||
summary: Get the current user's group statistics
|
||||
tags:
|
||||
- Statistics
|
||||
/v1/groups/statistics/locations:
|
||||
get:
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
items:
|
||||
$ref: '#/definitions/repo.TotalsByOrganizer'
|
||||
type: array
|
||||
security:
|
||||
- Bearer: []
|
||||
summary: Get the current user's group statistics
|
||||
tags:
|
||||
- Statistics
|
||||
/v1/groups/statistics/purchase-price:
|
||||
get:
|
||||
parameters:
|
||||
- description: start date
|
||||
in: query
|
||||
name: start
|
||||
type: string
|
||||
- description: end date
|
||||
in: query
|
||||
name: end
|
||||
type: string
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/repo.ValueOverTime'
|
||||
security:
|
||||
- Bearer: []
|
||||
summary: Queries the changes overtime of the purchase price over time
|
||||
tags:
|
||||
- Statistics
|
||||
/v1/items:
|
||||
get:
|
||||
parameters:
|
||||
@@ -820,29 +992,72 @@ paths:
|
||||
summary: retrieves an attachment for an item
|
||||
tags:
|
||||
- Items Attachments
|
||||
/v1/items/{id}/attachments/download:
|
||||
/v1/items/{id}/maintenance:
|
||||
get:
|
||||
parameters:
|
||||
- description: Item ID
|
||||
in: path
|
||||
name: id
|
||||
required: true
|
||||
type: string
|
||||
- description: Attachment token
|
||||
in: query
|
||||
name: token
|
||||
required: true
|
||||
type: string
|
||||
produces:
|
||||
- application/octet-stream
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/repo.MaintenanceLog'
|
||||
security:
|
||||
- Bearer: []
|
||||
summary: retrieves an attachment for an item
|
||||
summary: Get Maintenance Log
|
||||
tags:
|
||||
- Items Attachments
|
||||
- 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:
|
||||
post:
|
||||
parameters:
|
||||
|
||||
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
@@ -39,4 +40,6 @@ func main() {
|
||||
if err != nil {
|
||||
log.Fatalf("failed generating migration file: %v", err)
|
||||
}
|
||||
|
||||
fmt.Println("Migration file generated successfully.")
|
||||
}
|
||||
|
||||
@@ -3,18 +3,18 @@ module github.com/hay-kot/homebox/backend
|
||||
go 1.19
|
||||
|
||||
require (
|
||||
ariga.io/atlas v0.7.2-0.20220927111110-867ee0cca56a
|
||||
entgo.io/ent v0.11.3
|
||||
ariga.io/atlas v0.8.3
|
||||
entgo.io/ent v0.11.4
|
||||
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.8
|
||||
github.com/go-playground/validator/v10 v10.11.1
|
||||
github.com/google/uuid v1.3.0
|
||||
github.com/mattn/go-sqlite3 v1.14.16
|
||||
github.com/rs/zerolog v1.28.0
|
||||
github.com/stretchr/testify v1.8.1
|
||||
github.com/swaggo/http-swagger v1.3.3
|
||||
github.com/swaggo/swag v1.8.7
|
||||
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90
|
||||
github.com/swaggo/swag v1.8.9
|
||||
golang.org/x/crypto v0.4.0
|
||||
)
|
||||
|
||||
require (
|
||||
@@ -30,20 +30,20 @@ require (
|
||||
github.com/go-playground/locales v0.14.0 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.0 // 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/leodido/go-urn v1.2.1 // indirect
|
||||
github.com/mailru/easyjson v0.7.7 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.16 // indirect
|
||||
github.com/mattn/go-isatty v0.0.17 // indirect
|
||||
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/swaggo/files v0.0.0-20220728132757-551d4a08d97a // indirect
|
||||
github.com/zclconf/go-cty v1.11.0 // indirect
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
|
||||
golang.org/x/net v0.0.0-20220923203811-8be639271d50 // indirect
|
||||
golang.org/x/sys v0.0.0-20220919091848-fb04ddd9f9c8 // indirect
|
||||
golang.org/x/text v0.3.7 // indirect
|
||||
golang.org/x/tools v0.1.13-0.20220804200503-81c7dc4e4efa // indirect
|
||||
github.com/swaggo/files v1.0.0 // indirect
|
||||
github.com/zclconf/go-cty v1.12.1 // indirect
|
||||
golang.org/x/mod v0.7.0 // indirect
|
||||
golang.org/x/net v0.4.0 // indirect
|
||||
golang.org/x/sys v0.3.0 // indirect
|
||||
golang.org/x/text v0.5.0 // indirect
|
||||
golang.org/x/tools v0.4.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
ariga.io/atlas v0.7.2-0.20220927111110-867ee0cca56a h1:6/nt4DODfgxzHTTg3tYy7YkVzruGQGZ/kRvXpA45KUo=
|
||||
ariga.io/atlas v0.7.2-0.20220927111110-867ee0cca56a/go.mod h1:ft47uSh5hWGDCmQC9DsztZg6Xk+KagM5Ts/mZYKb9JE=
|
||||
entgo.io/ent v0.11.3 h1:F5FBGAWiDCGder7YT+lqMnyzXl6d0xU3xMBM/SO3CMc=
|
||||
entgo.io/ent v0.11.3/go.mod h1:mvDhvynOzAsOe7anH7ynPPtMjA/eeXP96kAfweevyxc=
|
||||
ariga.io/atlas v0.8.3 h1:nddOywkhr/62Cwa+UsGgO35lAhUYh52XGVsbFwGzWZM=
|
||||
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/go.mod h1:fnQIXL36RYnCk/9nvG4aE7YHBFZhCycfh7wMjY5p7SE=
|
||||
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
|
||||
github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=
|
||||
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
|
||||
@@ -16,8 +16,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/go-chi/chi/v5 v5.0.7 h1:rDTPXLDHGATaeHvVlLcR4Qe0zftYethFucbjVQ1PxU8=
|
||||
github.com/go-chi/chi/v5 v5.0.7/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
|
||||
github.com/go-chi/chi/v5 v5.0.8 h1:lD+NLqFcAi1ovnVZpsnObHGW4xb4J8lNmoYVfECH1Y0=
|
||||
github.com/go-chi/chi/v5 v5.0.8/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
|
||||
github.com/go-openapi/inflect v0.19.0 h1:9jCH9scKIbHeV9m12SmPilScz6krDxKRasNNSNPXu/4=
|
||||
github.com/go-openapi/inflect v0.19.0/go.mod h1:lHpZVlpIQqLyKwJ4N+YSc9hchQy/i12fJykb83CRBH4=
|
||||
github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
|
||||
@@ -46,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/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||
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.14.1/go.mod h1:e4z5nxYlWNPdDSNYX+ph14EvWYMFm3eP0zIUqPc2jr0=
|
||||
github.com/hashicorp/hcl/v2 v2.15.0 h1:CPDXO6+uORPjKflkWCCwoWc9uRp+zSIPcCQ+BrxV7m8=
|
||||
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/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
@@ -70,8 +70,9 @@ github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
||||
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
|
||||
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
|
||||
github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y=
|
||||
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
|
||||
@@ -90,7 +91,7 @@ github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
|
||||
github.com/rs/zerolog v1.28.0 h1:MirSo27VyNi7RJYP3078AA1+Cyzd2GB66qy3aUHvsWY=
|
||||
github.com/rs/zerolog v1.28.0/go.mod h1:NILgTygv/Uej1ra5XxGf82ZFSLk58MFGAUS2o6usyD0=
|
||||
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
|
||||
github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU=
|
||||
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=
|
||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
@@ -102,39 +103,61 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
|
||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/swaggo/files v0.0.0-20220728132757-551d4a08d97a h1:kAe4YSu0O0UFn1DowNo2MY5p6xzqtJ/wQ7LZynSvGaY=
|
||||
github.com/swaggo/files v0.0.0-20220728132757-551d4a08d97a/go.mod h1:lKJPbtWzJ9JhsTN1k1gZgleJWY/cqq0psdoMmaThG3w=
|
||||
github.com/swaggo/files v1.0.0 h1:1gGXVIeUFCS/dta17rnP0iOpr6CXFwKD7EO5ID233e4=
|
||||
github.com/swaggo/files v1.0.0/go.mod h1:N59U6URJLyU1PQgFqPM7wXLMhJx7QAolnvfQkqO13kc=
|
||||
github.com/swaggo/http-swagger v1.3.3 h1:Hu5Z0L9ssyBLofaama21iYaF2VbWyA8jdohaaCGpHsc=
|
||||
github.com/swaggo/http-swagger v1.3.3/go.mod h1:sE+4PjD89IxMPm77FnkDz0sdO+p5lbXzrVWT6OTVVGo=
|
||||
github.com/swaggo/swag v1.8.7 h1:2K9ivTD3teEO+2fXV6zrZKDqk5IuU2aJtBDo8U7omWU=
|
||||
github.com/swaggo/swag v1.8.7/go.mod h1:ezQVUUhly8dludpVk+/PuwJWvLLanB13ygV5Pr9enSk=
|
||||
github.com/zclconf/go-cty v1.11.0 h1:726SxLdi2SDnjY+BStqB9J1hNp4+2WlzyXLuimibIe0=
|
||||
github.com/zclconf/go-cty v1.11.0/go.mod h1:s9IfD1LK5ccNMSWCVFCE2rJfHiZgi7JijgeWIMfhLvA=
|
||||
github.com/swaggo/swag v1.8.9 h1:kHtaBe/Ob9AZzAANfcn5c6RyCke9gG9QpH0jky0I/sA=
|
||||
github.com/swaggo/swag v1.8.9/go.mod h1:ezQVUUhly8dludpVk+/PuwJWvLLanB13ygV5Pr9enSk=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
github.com/zclconf/go-cty v1.12.1 h1:PcupnljUm9EIvbgSHQnHhUr3fO6oFmkOrvs2BAFNXXY=
|
||||
github.com/zclconf/go-cty v1.12.1/go.mod h1:s9IfD1LK5ccNMSWCVFCE2rJfHiZgi7JijgeWIMfhLvA=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
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.0.0-20220829220503-c86fa9a7ed90/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=
|
||||
golang.org/x/crypto v0.4.0 h1:UVQgzMY87xqpKNgb+kDsll2Igd33HszWHFLmpaRMq/8=
|
||||
golang.org/x/crypto v0.4.0/go.mod h1:3quD/ATkf6oY+rnes5c3ExXTbLc8mueNue5/DoinL80=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/mod v0.7.0 h1:LapD9S96VoQRhi/GrNTqeBJFrUjs5UHCAtTlgwA5oZA=
|
||||
golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
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.0.0-20220923203811-8be639271d50/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
|
||||
golang.org/x/net v0.4.0 h1:Q5QPcMlvfxFTAPV0+07Xz/MpK9NTXu2VDUuy0FeMfaU=
|
||||
golang.org/x/net v0.4.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
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-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/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-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/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.0.0-20220919091848-fb04ddd9f9c8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
|
||||
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-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/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.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
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.1.13-0.20220804200503-81c7dc4e4efa h1:uKcci2q7Qtp6nMTC/AAvfNUAldFtJuHWV9/5QWiypts=
|
||||
golang.org/x/tools v0.1.13-0.20220804200503-81c7dc4e4efa/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/tools v0.4.0 h1:7mTAgkunk3fr4GAloyyCasadO6h9zSsQZbwvcaIciV4=
|
||||
golang.org/x/tools v0.4.0/go.mod h1:UE5sM2OK9E/d67R0ANs2xJizIymRP5gJU295PvKXxjQ=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
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-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
|
||||
@@ -8,17 +8,37 @@ type AllServices struct {
|
||||
Items *ItemService
|
||||
}
|
||||
|
||||
func New(repos *repo.AllRepos) *AllServices {
|
||||
type OptionsFunc func(*options)
|
||||
|
||||
type options struct {
|
||||
autoIncrementAssetID bool
|
||||
}
|
||||
|
||||
func WithAutoIncrementAssetID(v bool) func(*options) {
|
||||
return func(o *options) {
|
||||
o.autoIncrementAssetID = v
|
||||
}
|
||||
}
|
||||
|
||||
func New(repos *repo.AllRepos, opts ...OptionsFunc) *AllServices {
|
||||
if repos == nil {
|
||||
panic("repos cannot be nil")
|
||||
}
|
||||
|
||||
options := &options{
|
||||
autoIncrementAssetID: true,
|
||||
}
|
||||
|
||||
for _, opt := range opts {
|
||||
opt(options)
|
||||
}
|
||||
|
||||
return &AllServices{
|
||||
User: &UserService{repos},
|
||||
Group: &GroupService{repos},
|
||||
Items: &ItemService{
|
||||
repo: repos,
|
||||
at: attachmentTokens{},
|
||||
repo: repos,
|
||||
autoIncrementAssetID: options.autoIncrementAssetID,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,11 +18,49 @@ type ItemService struct {
|
||||
repo *repo.AllRepos
|
||||
|
||||
filepath string
|
||||
// at is a map of tokens to attachment IDs. This is used to store the attachment ID
|
||||
// for issued URLs
|
||||
at attachmentTokens
|
||||
|
||||
autoIncrementAssetID bool
|
||||
}
|
||||
|
||||
func (svc *ItemService) Create(ctx Context, item repo.ItemCreate) (repo.ItemOut, error) {
|
||||
if svc.autoIncrementAssetID {
|
||||
highest, err := svc.repo.Items.GetHighestAssetID(ctx, ctx.GID)
|
||||
if err != nil {
|
||||
return repo.ItemOut{}, err
|
||||
}
|
||||
|
||||
item.AssetID = repo.AssetID(highest + 1)
|
||||
}
|
||||
|
||||
return svc.repo.Items.Create(ctx, ctx.GID, item)
|
||||
}
|
||||
|
||||
func (svc *ItemService) EnsureAssetID(ctx context.Context, GID uuid.UUID) (int, error) {
|
||||
items, err := svc.repo.Items.GetAllZeroAssetID(ctx, GID)
|
||||
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
highest, err := svc.repo.Items.GetHighestAssetID(ctx, GID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
finished := 0
|
||||
for _, item := range items {
|
||||
highest++
|
||||
|
||||
err = svc.repo.Items.SetAssetID(ctx, GID, item.ID, repo.AssetID(highest))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
finished++
|
||||
}
|
||||
|
||||
return finished, nil
|
||||
}
|
||||
func (svc *ItemService) CsvImport(ctx context.Context, GID uuid.UUID, data [][]string) (int, error) {
|
||||
loaded := []csvRow{}
|
||||
|
||||
@@ -114,6 +152,14 @@ func (svc *ItemService) CsvImport(ctx context.Context, GID uuid.UUID, data [][]s
|
||||
}
|
||||
}
|
||||
|
||||
highest := repo.AssetID(-1)
|
||||
if svc.autoIncrementAssetID {
|
||||
highest, err = svc.repo.Items.GetHighestAssetID(ctx, GID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
// Create the items
|
||||
var count int
|
||||
for _, row := range loaded {
|
||||
@@ -139,13 +185,20 @@ func (svc *ItemService) CsvImport(ctx context.Context, GID uuid.UUID, data [][]s
|
||||
Str("location", row.Location).
|
||||
Msgf("Creating Item: %s", row.Item.Name)
|
||||
|
||||
result, err := svc.repo.Items.Create(ctx, GID, repo.ItemCreate{
|
||||
data := repo.ItemCreate{
|
||||
ImportRef: row.Item.ImportRef,
|
||||
Name: row.Item.Name,
|
||||
Description: row.Item.Description,
|
||||
LabelIDs: labelIDs,
|
||||
LocationID: locationID,
|
||||
})
|
||||
}
|
||||
|
||||
if svc.autoIncrementAssetID {
|
||||
highest++
|
||||
data.AssetID = highest
|
||||
}
|
||||
|
||||
result, err := svc.repo.Items.Create(ctx, GID, data)
|
||||
|
||||
if err != nil {
|
||||
return count, err
|
||||
@@ -156,6 +209,7 @@ func (svc *ItemService) CsvImport(ctx context.Context, GID uuid.UUID, data [][]s
|
||||
// Edges
|
||||
LocationID: locationID,
|
||||
LabelIDs: labelIDs,
|
||||
AssetID: data.AssetID,
|
||||
|
||||
// General Fields
|
||||
ID: result.ID,
|
||||
|
||||
@@ -4,71 +4,15 @@ import (
|
||||
"context"
|
||||
"io"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/attachment"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/repo"
|
||||
"github.com/hay-kot/homebox/backend/pkgs/hasher"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
// TODO: this isn't a scalable solution, tokens should be stored in the database
|
||||
type attachmentTokens map[string]uuid.UUID
|
||||
|
||||
func (at attachmentTokens) Add(token string, id uuid.UUID) {
|
||||
at[token] = id
|
||||
|
||||
log.Debug().Str("token", token).Str("uuid", id.String()).Msg("added token")
|
||||
|
||||
go func() {
|
||||
ch := time.After(1 * time.Minute)
|
||||
<-ch
|
||||
at.Delete(token)
|
||||
log.Debug().Str("token", token).Msg("deleted token")
|
||||
}()
|
||||
}
|
||||
|
||||
func (at attachmentTokens) Get(token string) (uuid.UUID, bool) {
|
||||
id, ok := at[token]
|
||||
return id, ok
|
||||
}
|
||||
|
||||
func (at attachmentTokens) Delete(token string) {
|
||||
delete(at, token)
|
||||
}
|
||||
|
||||
func (svc *ItemService) AttachmentToken(ctx Context, itemId, attachmentId uuid.UUID) (string, error) {
|
||||
_, err := svc.repo.Items.GetOneByGroup(ctx, ctx.GID, itemId)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
token := hasher.GenerateToken()
|
||||
|
||||
// Ensure that the file exists
|
||||
attachment, err := svc.repo.Attachments.Get(ctx, attachmentId)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if _, err := os.Stat(attachment.Edges.Document.Path); os.IsNotExist(err) {
|
||||
_ = svc.AttachmentDelete(ctx, ctx.GID, itemId, attachmentId)
|
||||
return "", ErrNotFound
|
||||
}
|
||||
|
||||
svc.at.Add(token.Raw, attachmentId)
|
||||
|
||||
return token.Raw, nil
|
||||
}
|
||||
|
||||
func (svc *ItemService) AttachmentPath(ctx context.Context, token string) (*ent.Document, error) {
|
||||
attachmentId, ok := svc.at.Get(token)
|
||||
if !ok {
|
||||
return nil, ErrNotFound
|
||||
}
|
||||
|
||||
func (svc *ItemService) AttachmentPath(ctx context.Context, attachmentId uuid.UUID) (*ent.Document, error) {
|
||||
attachment, err := svc.repo.Attachments.Get(ctx, attachmentId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/csv"
|
||||
"errors"
|
||||
"io"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -9,6 +12,44 @@ import (
|
||||
"github.com/hay-kot/homebox/backend/internal/data/repo"
|
||||
)
|
||||
|
||||
func determineSeparator(data []byte) (rune, error) {
|
||||
// First row
|
||||
firstRow := bytes.Split(data, []byte("\n"))[0]
|
||||
|
||||
// find first comma or /t
|
||||
comma := bytes.IndexByte(firstRow, ',')
|
||||
tab := bytes.IndexByte(firstRow, '\t')
|
||||
|
||||
switch {
|
||||
case comma == -1 && tab == -1:
|
||||
return 0, errors.New("could not determine separator")
|
||||
case tab > comma:
|
||||
return '\t', nil
|
||||
default:
|
||||
return ',', nil
|
||||
}
|
||||
}
|
||||
|
||||
func ReadCsv(r io.Reader) ([][]string, error) {
|
||||
data, err := io.ReadAll(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
reader := csv.NewReader(bytes.NewReader(data))
|
||||
|
||||
// Determine separator
|
||||
sep, err := determineSeparator(data)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
reader.Comma = sep
|
||||
|
||||
return reader.ReadAll()
|
||||
}
|
||||
|
||||
var ErrInvalidCsv = errors.New("invalid csv")
|
||||
|
||||
const NumOfCols = 21
|
||||
@@ -56,18 +97,18 @@ func newCsvRow(row []string) csvRow {
|
||||
LabelStr: row[2],
|
||||
Item: repo.ItemOut{
|
||||
ItemSummary: repo.ItemSummary{
|
||||
ImportRef: row[0],
|
||||
Quantity: parseInt(row[3]),
|
||||
Name: row[4],
|
||||
Description: row[5],
|
||||
Insured: parseBool(row[6]),
|
||||
ImportRef: row[0],
|
||||
Quantity: parseInt(row[3]),
|
||||
Name: row[4],
|
||||
Description: row[5],
|
||||
Insured: parseBool(row[6]),
|
||||
PurchasePrice: parseFloat(row[12]),
|
||||
},
|
||||
SerialNumber: row[7],
|
||||
ModelNumber: row[8],
|
||||
Manufacturer: row[9],
|
||||
Notes: row[10],
|
||||
PurchaseFrom: row[11],
|
||||
PurchasePrice: parseFloat(row[12]),
|
||||
PurchaseTime: parseDate(row[13]),
|
||||
LifetimeWarranty: parseBool(row[14]),
|
||||
WarrantyExpires: parseDate(row[15]),
|
||||
|
||||
@@ -2,6 +2,7 @@ package services
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
_ "embed"
|
||||
"encoding/csv"
|
||||
"fmt"
|
||||
"reflect"
|
||||
@@ -11,17 +12,14 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
const CSV_DATA = `
|
||||
Import Ref,Location,Labels,Quantity,Name,Description,Insured,Serial Number,Mode Number,Manufacturer,Notes,Purchase From,Purchased Price,Purchased Time,Lifetime Warranty,Warranty Expires,Warranty Details,Sold To,Sold Price,Sold Time,Sold Notes
|
||||
A,Garage,IOT;Home Assistant; Z-Wave,1,Zooz Universal Relay ZEN17,Description 1,TRUE,,ZEN17,Zooz,,Amazon,39.95,10/13/2021,,10/13/2021,,,,10/13/2021,
|
||||
B,Living Room,IOT;Home Assistant; Z-Wave,1,Zooz Motion Sensor,Description 2,FALSE,,ZSE18,Zooz,,Amazon,29.95,10/15/2021,,10/15/2021,,,,10/15/2021,
|
||||
C,Office,IOT;Home Assistant; Z-Wave,1,Zooz 110v Power Switch,Description 3,TRUE,,ZEN15,Zooz,,Amazon,39.95,10/13/2021,,10/13/2021,,,,10/13/2021,
|
||||
D,Downstairs,IOT;Home Assistant; Z-Wave,1,Ecolink Z-Wave PIR Motion Sensor,Description 4,FALSE,,PIRZWAVE2.5-ECO,Ecolink,,Amazon,35.58,10/21/2020,,10/21/2020,,,,10/21/2020,
|
||||
E,Entry,IOT;Home Assistant; Z-Wave,1,Yale Security Touchscreen Deadbolt,Description 5,TRUE,,YRD226ZW2619,Yale,,Amazon,120.39,10/14/2020,,10/14/2020,,,,10/14/2020,
|
||||
F,Kitchen,IOT;Home Assistant; Z-Wave,1,Smart Rocker Light Dimmer,Description 6,FALSE,,39351,Honeywell,,Amazon,65.98,09/30/2020,,09/30/2020,,,,09/30/2020,`
|
||||
//go:embed testdata/import.csv
|
||||
var CSVData_Comma []byte
|
||||
|
||||
//go:embed testdata/import.tsv
|
||||
var CSVData_Tab []byte
|
||||
|
||||
func loadcsv() [][]string {
|
||||
reader := csv.NewReader(bytes.NewBuffer([]byte(CSV_DATA)))
|
||||
reader := csv.NewReader(bytes.NewReader(CSVData_Comma))
|
||||
|
||||
records, err := reader.ReadAll()
|
||||
if err != nil {
|
||||
@@ -115,3 +113,52 @@ func Test_csvRow_getLabels(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_determineSeparator(t *testing.T) {
|
||||
type args struct {
|
||||
data []byte
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want rune
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "comma",
|
||||
args: args{
|
||||
data: CSVData_Comma,
|
||||
},
|
||||
want: ',',
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "tab",
|
||||
args: args{
|
||||
data: CSVData_Tab,
|
||||
},
|
||||
want: '\t',
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "invalid",
|
||||
args: args{
|
||||
data: []byte("a;b;c"),
|
||||
},
|
||||
want: 0,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := determineSeparator(tt.args.data)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("determineSeparator() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if got != tt.want {
|
||||
t.Errorf("determineSeparator() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/authroles"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/repo"
|
||||
"github.com/hay-kot/homebox/backend/pkgs/hasher"
|
||||
"github.com/rs/zerolog/log"
|
||||
@@ -30,8 +31,9 @@ type (
|
||||
Password string `json:"password"`
|
||||
}
|
||||
UserAuthTokenDetail struct {
|
||||
Raw string `json:"raw"`
|
||||
ExpiresAt time.Time `json:"expiresAt"`
|
||||
Raw string `json:"raw"`
|
||||
AttachmentToken string `json:"attachmentToken"`
|
||||
ExpiresAt time.Time `json:"expiresAt"`
|
||||
}
|
||||
LoginForm struct {
|
||||
Username string `json:"username"`
|
||||
@@ -131,16 +133,37 @@ func (svc *UserService) UpdateSelf(ctx context.Context, ID uuid.UUID, data repo.
|
||||
// ============================================================================
|
||||
// User Authentication
|
||||
|
||||
func (svc *UserService) createToken(ctx context.Context, userId uuid.UUID) (UserAuthTokenDetail, error) {
|
||||
newToken := hasher.GenerateToken()
|
||||
func (svc *UserService) createSessionToken(ctx context.Context, userId uuid.UUID) (UserAuthTokenDetail, error) {
|
||||
|
||||
created, err := svc.repos.AuthTokens.CreateToken(ctx, repo.UserAuthTokenCreate{
|
||||
attachmentToken := hasher.GenerateToken()
|
||||
attachmentData := repo.UserAuthTokenCreate{
|
||||
UserID: userId,
|
||||
TokenHash: newToken.Hash,
|
||||
TokenHash: attachmentToken.Hash,
|
||||
ExpiresAt: time.Now().Add(oneWeek),
|
||||
})
|
||||
}
|
||||
|
||||
return UserAuthTokenDetail{Raw: newToken.Raw, ExpiresAt: created.ExpiresAt}, err
|
||||
_, err := svc.repos.AuthTokens.CreateToken(ctx, attachmentData, authroles.RoleAttachments)
|
||||
if err != nil {
|
||||
return UserAuthTokenDetail{}, err
|
||||
}
|
||||
|
||||
userToken := hasher.GenerateToken()
|
||||
data := repo.UserAuthTokenCreate{
|
||||
UserID: userId,
|
||||
TokenHash: userToken.Hash,
|
||||
ExpiresAt: time.Now().Add(oneWeek),
|
||||
}
|
||||
|
||||
created, err := svc.repos.AuthTokens.CreateToken(ctx, data, authroles.RoleUser)
|
||||
if err != nil {
|
||||
return UserAuthTokenDetail{}, err
|
||||
}
|
||||
|
||||
return UserAuthTokenDetail{
|
||||
Raw: userToken.Raw,
|
||||
ExpiresAt: created.ExpiresAt,
|
||||
AttachmentToken: attachmentToken.Raw,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (svc *UserService) Login(ctx context.Context, username, password string) (UserAuthTokenDetail, error) {
|
||||
@@ -156,7 +179,7 @@ func (svc *UserService) Login(ctx context.Context, username, password string) (U
|
||||
return UserAuthTokenDetail{}, ErrorInvalidLogin
|
||||
}
|
||||
|
||||
return svc.createToken(ctx, usr.ID)
|
||||
return svc.createSessionToken(ctx, usr.ID)
|
||||
}
|
||||
|
||||
func (svc *UserService) Logout(ctx context.Context, token string) error {
|
||||
@@ -174,9 +197,7 @@ func (svc *UserService) RenewToken(ctx context.Context, token string) (UserAuthT
|
||||
return UserAuthTokenDetail{}, ErrorInvalidToken
|
||||
}
|
||||
|
||||
newToken, _ := svc.createToken(ctx, dbToken.ID)
|
||||
|
||||
return newToken, nil
|
||||
return svc.createSessionToken(ctx, dbToken.ID)
|
||||
}
|
||||
|
||||
// DeleteSelf deletes the user that is currently logged based of the provided UUID
|
||||
|
||||
7
backend/internal/core/services/testdata/import.csv
vendored
Normal file
7
backend/internal/core/services/testdata/import.csv
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
Import Ref,Location,Labels,Quantity,Name,Description,Insured,Serial Number,Mode Number,Manufacturer,Notes,Purchase From,Purchased Price,Purchased Time,Lifetime Warranty,Warranty Expires,Warranty Details,Sold To,Sold Price,Sold Time,Sold Notes
|
||||
A,Garage,IOT;Home Assistant; Z-Wave,1,Zooz Universal Relay ZEN17,Description 1,TRUE,,ZEN17,Zooz,,Amazon,39.95,10/13/2021,,10/13/2021,,,,10/13/2021,
|
||||
B,Living Room,IOT;Home Assistant; Z-Wave,1,Zooz Motion Sensor,Description 2,FALSE,,ZSE18,Zooz,,Amazon,29.95,10/15/2021,,10/15/2021,,,,10/15/2021,
|
||||
C,Office,IOT;Home Assistant; Z-Wave,1,Zooz 110v Power Switch,Description 3,TRUE,,ZEN15,Zooz,,Amazon,39.95,10/13/2021,,10/13/2021,,,,10/13/2021,
|
||||
D,Downstairs,IOT;Home Assistant; Z-Wave,1,Ecolink Z-Wave PIR Motion Sensor,Description 4,FALSE,,PIRZWAVE2.5-ECO,Ecolink,,Amazon,35.58,10/21/2020,,10/21/2020,,,,10/21/2020,
|
||||
E,Entry,IOT;Home Assistant; Z-Wave,1,Yale Security Touchscreen Deadbolt,Description 5,TRUE,,YRD226ZW2619,Yale,,Amazon,120.39,10/14/2020,,10/14/2020,,,,10/14/2020,
|
||||
F,Kitchen,IOT;Home Assistant; Z-Wave,1,Smart Rocker Light Dimmer,Description 6,FALSE,,39351,Honeywell,,Amazon,65.98,09/30/2020,,09/30/2020,,,,09/30/2020,
|
||||
|
7
backend/internal/core/services/testdata/import.tsv
vendored
Normal file
7
backend/internal/core/services/testdata/import.tsv
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
Import Ref Location Labels Quantity Name Description Insured Serial Number Mode Number Manufacturer Notes Purchase From Purchased Price Purchased Time Lifetime Warranty Warranty Expires Warranty Details Sold To Sold Price Sold Time Sold Notes
|
||||
A Garage IOT;Home Assistant; Z-Wave 1 Zooz Universal Relay ZEN17 Description 1 TRUE ZEN17 Zooz Amazon 39.95 10/13/2021 10/13/2021 10/13/2021
|
||||
B Living Room IOT;Home Assistant; Z-Wave 1 Zooz Motion Sensor Description 2 FALSE ZSE18 Zooz Amazon 29.95 10/15/2021 10/15/2021 10/15/2021
|
||||
C Office IOT;Home Assistant; Z-Wave 1 Zooz 110v Power Switch Description 3 TRUE ZEN15 Zooz Amazon 39.95 10/13/2021 10/13/2021 10/13/2021
|
||||
D Downstairs IOT;Home Assistant; Z-Wave 1 Ecolink Z-Wave PIR Motion Sensor Description 4 FALSE PIRZWAVE2.5-ECO Ecolink Amazon 35.58 10/21/2020 10/21/2020 10/21/2020
|
||||
E Entry IOT;Home Assistant; Z-Wave 1 Yale Security Touchscreen Deadbolt Description 5 TRUE YRD226ZW2619 Yale Amazon 120.39 10/14/2020 10/14/2020 10/14/2020
|
||||
F Kitchen IOT;Home Assistant; Z-Wave 1 Smart Rocker Light Dimmer Description 6 FALSE 39351 Honeywell Amazon 65.98 09/30/2020 09/30/2020 09/30/2020
|
||||
|
@@ -255,27 +255,15 @@ func (ac *AttachmentCreate) createSpec() (*Attachment, *sqlgraph.CreateSpec) {
|
||||
_spec.ID.Value = &id
|
||||
}
|
||||
if value, ok := ac.mutation.CreatedAt(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: attachment.FieldCreatedAt,
|
||||
})
|
||||
_spec.SetField(attachment.FieldCreatedAt, field.TypeTime, value)
|
||||
_node.CreatedAt = value
|
||||
}
|
||||
if value, ok := ac.mutation.UpdatedAt(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: attachment.FieldUpdatedAt,
|
||||
})
|
||||
_spec.SetField(attachment.FieldUpdatedAt, field.TypeTime, value)
|
||||
_node.UpdatedAt = value
|
||||
}
|
||||
if value, ok := ac.mutation.GetType(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeEnum,
|
||||
Value: value,
|
||||
Column: attachment.FieldType,
|
||||
})
|
||||
_spec.SetField(attachment.FieldType, field.TypeEnum, value)
|
||||
_node.Type = value
|
||||
}
|
||||
if nodes := ac.mutation.ItemIDs(); len(nodes) > 0 {
|
||||
|
||||
@@ -369,6 +369,11 @@ func (aq *AttachmentQuery) Select(fields ...string) *AttachmentSelect {
|
||||
return selbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a AttachmentSelect configured with the given aggregations.
|
||||
func (aq *AttachmentQuery) Aggregate(fns ...AggregateFunc) *AttachmentSelect {
|
||||
return aq.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (aq *AttachmentQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, f := range aq.fields {
|
||||
if !attachment.ValidColumn(f) {
|
||||
@@ -645,8 +650,6 @@ func (agb *AttachmentGroupBy) sqlQuery() *sql.Selector {
|
||||
for _, fn := range agb.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
// If no columns were selected in a custom aggregation function, the default
|
||||
// selection is the fields used for "group-by", and the aggregation functions.
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(agb.fields)+len(agb.fns))
|
||||
for _, f := range agb.fields {
|
||||
@@ -666,6 +669,12 @@ type AttachmentSelect struct {
|
||||
sql *sql.Selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (as *AttachmentSelect) Aggregate(fns ...AggregateFunc) *AttachmentSelect {
|
||||
as.fns = append(as.fns, fns...)
|
||||
return as
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (as *AttachmentSelect) Scan(ctx context.Context, v any) error {
|
||||
if err := as.prepareQuery(ctx); err != nil {
|
||||
@@ -676,6 +685,16 @@ func (as *AttachmentSelect) Scan(ctx context.Context, v any) error {
|
||||
}
|
||||
|
||||
func (as *AttachmentSelect) sqlScan(ctx context.Context, v any) error {
|
||||
aggregation := make([]string, 0, len(as.fns))
|
||||
for _, fn := range as.fns {
|
||||
aggregation = append(aggregation, fn(as.sql))
|
||||
}
|
||||
switch n := len(*as.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
as.sql.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
as.sql.AppendSelect(aggregation...)
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := as.sql.Query()
|
||||
if err := as.driver.Query(ctx, query, args, rows); err != nil {
|
||||
|
||||
@@ -194,18 +194,10 @@ func (au *AttachmentUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
}
|
||||
}
|
||||
if value, ok := au.mutation.UpdatedAt(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: attachment.FieldUpdatedAt,
|
||||
})
|
||||
_spec.SetField(attachment.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := au.mutation.GetType(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeEnum,
|
||||
Value: value,
|
||||
Column: attachment.FieldType,
|
||||
})
|
||||
_spec.SetField(attachment.FieldType, field.TypeEnum, value)
|
||||
}
|
||||
if au.mutation.ItemCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
@@ -489,18 +481,10 @@ func (auo *AttachmentUpdateOne) sqlSave(ctx context.Context) (_node *Attachment,
|
||||
}
|
||||
}
|
||||
if value, ok := auo.mutation.UpdatedAt(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: attachment.FieldUpdatedAt,
|
||||
})
|
||||
_spec.SetField(attachment.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := auo.mutation.GetType(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeEnum,
|
||||
Value: value,
|
||||
Column: attachment.FieldType,
|
||||
})
|
||||
_spec.SetField(attachment.FieldType, field.TypeEnum, value)
|
||||
}
|
||||
if auo.mutation.ItemCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
|
||||
141
backend/internal/data/ent/authroles.go
Normal file
141
backend/internal/data/ent/authroles.go
Normal file
@@ -0,0 +1,141 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"github.com/google/uuid"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/authroles"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/authtokens"
|
||||
)
|
||||
|
||||
// AuthRoles is the model entity for the AuthRoles schema.
|
||||
type AuthRoles struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// Role holds the value of the "role" field.
|
||||
Role authroles.Role `json:"role,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the AuthRolesQuery when eager-loading is set.
|
||||
Edges AuthRolesEdges `json:"edges"`
|
||||
auth_tokens_roles *uuid.UUID
|
||||
}
|
||||
|
||||
// AuthRolesEdges holds the relations/edges for other nodes in the graph.
|
||||
type AuthRolesEdges struct {
|
||||
// Token holds the value of the token edge.
|
||||
Token *AuthTokens `json:"token,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [1]bool
|
||||
}
|
||||
|
||||
// TokenOrErr returns the Token value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e AuthRolesEdges) TokenOrErr() (*AuthTokens, error) {
|
||||
if e.loadedTypes[0] {
|
||||
if e.Token == nil {
|
||||
// Edge was loaded but was not found.
|
||||
return nil, &NotFoundError{label: authtokens.Label}
|
||||
}
|
||||
return e.Token, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "token"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*AuthRoles) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case authroles.FieldID:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case authroles.FieldRole:
|
||||
values[i] = new(sql.NullString)
|
||||
case authroles.ForeignKeys[0]: // auth_tokens_roles
|
||||
values[i] = &sql.NullScanner{S: new(uuid.UUID)}
|
||||
default:
|
||||
return nil, fmt.Errorf("unexpected column %q for type AuthRoles", columns[i])
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the AuthRoles fields.
|
||||
func (ar *AuthRoles) 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 authroles.FieldID:
|
||||
value, ok := values[i].(*sql.NullInt64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", value)
|
||||
}
|
||||
ar.ID = int(value.Int64)
|
||||
case authroles.FieldRole:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field role", values[i])
|
||||
} else if value.Valid {
|
||||
ar.Role = authroles.Role(value.String)
|
||||
}
|
||||
case authroles.ForeignKeys[0]:
|
||||
if value, ok := values[i].(*sql.NullScanner); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field auth_tokens_roles", values[i])
|
||||
} else if value.Valid {
|
||||
ar.auth_tokens_roles = new(uuid.UUID)
|
||||
*ar.auth_tokens_roles = *value.S.(*uuid.UUID)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// QueryToken queries the "token" edge of the AuthRoles entity.
|
||||
func (ar *AuthRoles) QueryToken() *AuthTokensQuery {
|
||||
return (&AuthRolesClient{config: ar.config}).QueryToken(ar)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this AuthRoles.
|
||||
// Note that you need to call AuthRoles.Unwrap() before calling this method if this AuthRoles
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (ar *AuthRoles) Update() *AuthRolesUpdateOne {
|
||||
return (&AuthRolesClient{config: ar.config}).UpdateOne(ar)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the AuthRoles 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 (ar *AuthRoles) Unwrap() *AuthRoles {
|
||||
_tx, ok := ar.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: AuthRoles is not a transactional entity")
|
||||
}
|
||||
ar.config.driver = _tx.drv
|
||||
return ar
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (ar *AuthRoles) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("AuthRoles(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", ar.ID))
|
||||
builder.WriteString("role=")
|
||||
builder.WriteString(fmt.Sprintf("%v", ar.Role))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// AuthRolesSlice is a parsable slice of AuthRoles.
|
||||
type AuthRolesSlice []*AuthRoles
|
||||
|
||||
func (ar AuthRolesSlice) config(cfg config) {
|
||||
for _i := range ar {
|
||||
ar[_i].config = cfg
|
||||
}
|
||||
}
|
||||
81
backend/internal/data/ent/authroles/authroles.go
Normal file
81
backend/internal/data/ent/authroles/authroles.go
Normal file
@@ -0,0 +1,81 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package authroles
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the authroles type in the database.
|
||||
Label = "auth_roles"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldRole holds the string denoting the role field in the database.
|
||||
FieldRole = "role"
|
||||
// EdgeToken holds the string denoting the token edge name in mutations.
|
||||
EdgeToken = "token"
|
||||
// Table holds the table name of the authroles in the database.
|
||||
Table = "auth_roles"
|
||||
// TokenTable is the table that holds the token relation/edge.
|
||||
TokenTable = "auth_roles"
|
||||
// TokenInverseTable is the table name for the AuthTokens entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "authtokens" package.
|
||||
TokenInverseTable = "auth_tokens"
|
||||
// TokenColumn is the table column denoting the token relation/edge.
|
||||
TokenColumn = "auth_tokens_roles"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for authroles fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldRole,
|
||||
}
|
||||
|
||||
// ForeignKeys holds the SQL foreign-keys that are owned by the "auth_roles"
|
||||
// table and are not defined as standalone fields in the schema.
|
||||
var ForeignKeys = []string{
|
||||
"auth_tokens_roles",
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
// Role defines the type for the "role" enum field.
|
||||
type Role string
|
||||
|
||||
// RoleUser is the default value of the Role enum.
|
||||
const DefaultRole = RoleUser
|
||||
|
||||
// Role values.
|
||||
const (
|
||||
RoleAdmin Role = "admin"
|
||||
RoleUser Role = "user"
|
||||
RoleAttachments Role = "attachments"
|
||||
)
|
||||
|
||||
func (r Role) String() string {
|
||||
return string(r)
|
||||
}
|
||||
|
||||
// RoleValidator is a validator for the "role" field enum values. It is called by the builders before save.
|
||||
func RoleValidator(r Role) error {
|
||||
switch r {
|
||||
case RoleAdmin, RoleUser, RoleAttachments:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("authroles: invalid enum value for role field: %q", r)
|
||||
}
|
||||
}
|
||||
176
backend/internal/data/ent/authroles/where.go
Normal file
176
backend/internal/data/ent/authroles/where.go
Normal file
@@ -0,0 +1,176 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package authroles
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/predicate"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int) predicate.AuthRoles {
|
||||
return predicate.AuthRoles(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.AuthRoles {
|
||||
return predicate.AuthRoles(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.AuthRoles {
|
||||
return predicate.AuthRoles(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.AuthRoles {
|
||||
return predicate.AuthRoles(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 ...int) predicate.AuthRoles {
|
||||
return predicate.AuthRoles(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 int) predicate.AuthRoles {
|
||||
return predicate.AuthRoles(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.AuthRoles {
|
||||
return predicate.AuthRoles(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.AuthRoles {
|
||||
return predicate.AuthRoles(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.AuthRoles {
|
||||
return predicate.AuthRoles(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldID), id))
|
||||
})
|
||||
}
|
||||
|
||||
// RoleEQ applies the EQ predicate on the "role" field.
|
||||
func RoleEQ(v Role) predicate.AuthRoles {
|
||||
return predicate.AuthRoles(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldRole), v))
|
||||
})
|
||||
}
|
||||
|
||||
// RoleNEQ applies the NEQ predicate on the "role" field.
|
||||
func RoleNEQ(v Role) predicate.AuthRoles {
|
||||
return predicate.AuthRoles(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldRole), v))
|
||||
})
|
||||
}
|
||||
|
||||
// RoleIn applies the In predicate on the "role" field.
|
||||
func RoleIn(vs ...Role) predicate.AuthRoles {
|
||||
v := make([]any, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.AuthRoles(func(s *sql.Selector) {
|
||||
s.Where(sql.In(s.C(FieldRole), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// RoleNotIn applies the NotIn predicate on the "role" field.
|
||||
func RoleNotIn(vs ...Role) predicate.AuthRoles {
|
||||
v := make([]any, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.AuthRoles(func(s *sql.Selector) {
|
||||
s.Where(sql.NotIn(s.C(FieldRole), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// HasToken applies the HasEdge predicate on the "token" edge.
|
||||
func HasToken() predicate.AuthRoles {
|
||||
return predicate.AuthRoles(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(TokenTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, true, TokenTable, TokenColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasTokenWith applies the HasEdge predicate on the "token" edge with a given conditions (other predicates).
|
||||
func HasTokenWith(preds ...predicate.AuthTokens) predicate.AuthRoles {
|
||||
return predicate.AuthRoles(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(TokenInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, true, TokenTable, TokenColumn),
|
||||
)
|
||||
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.AuthRoles) predicate.AuthRoles {
|
||||
return predicate.AuthRoles(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.AuthRoles) predicate.AuthRoles {
|
||||
return predicate.AuthRoles(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.AuthRoles) predicate.AuthRoles {
|
||||
return predicate.AuthRoles(func(s *sql.Selector) {
|
||||
p(s.Not())
|
||||
})
|
||||
}
|
||||
286
backend/internal/data/ent/authroles_create.go
Normal file
286
backend/internal/data/ent/authroles_create.go
Normal file
@@ -0,0 +1,286 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/google/uuid"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/authroles"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/authtokens"
|
||||
)
|
||||
|
||||
// AuthRolesCreate is the builder for creating a AuthRoles entity.
|
||||
type AuthRolesCreate struct {
|
||||
config
|
||||
mutation *AuthRolesMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetRole sets the "role" field.
|
||||
func (arc *AuthRolesCreate) SetRole(a authroles.Role) *AuthRolesCreate {
|
||||
arc.mutation.SetRole(a)
|
||||
return arc
|
||||
}
|
||||
|
||||
// SetNillableRole sets the "role" field if the given value is not nil.
|
||||
func (arc *AuthRolesCreate) SetNillableRole(a *authroles.Role) *AuthRolesCreate {
|
||||
if a != nil {
|
||||
arc.SetRole(*a)
|
||||
}
|
||||
return arc
|
||||
}
|
||||
|
||||
// SetTokenID sets the "token" edge to the AuthTokens entity by ID.
|
||||
func (arc *AuthRolesCreate) SetTokenID(id uuid.UUID) *AuthRolesCreate {
|
||||
arc.mutation.SetTokenID(id)
|
||||
return arc
|
||||
}
|
||||
|
||||
// SetNillableTokenID sets the "token" edge to the AuthTokens entity by ID if the given value is not nil.
|
||||
func (arc *AuthRolesCreate) SetNillableTokenID(id *uuid.UUID) *AuthRolesCreate {
|
||||
if id != nil {
|
||||
arc = arc.SetTokenID(*id)
|
||||
}
|
||||
return arc
|
||||
}
|
||||
|
||||
// SetToken sets the "token" edge to the AuthTokens entity.
|
||||
func (arc *AuthRolesCreate) SetToken(a *AuthTokens) *AuthRolesCreate {
|
||||
return arc.SetTokenID(a.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the AuthRolesMutation object of the builder.
|
||||
func (arc *AuthRolesCreate) Mutation() *AuthRolesMutation {
|
||||
return arc.mutation
|
||||
}
|
||||
|
||||
// Save creates the AuthRoles in the database.
|
||||
func (arc *AuthRolesCreate) Save(ctx context.Context) (*AuthRoles, error) {
|
||||
var (
|
||||
err error
|
||||
node *AuthRoles
|
||||
)
|
||||
arc.defaults()
|
||||
if len(arc.hooks) == 0 {
|
||||
if err = arc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
node, err = arc.sqlSave(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*AuthRolesMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err = arc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
arc.mutation = mutation
|
||||
if node, err = arc.sqlSave(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mutation.id = &node.ID
|
||||
mutation.done = true
|
||||
return node, err
|
||||
})
|
||||
for i := len(arc.hooks) - 1; i >= 0; i-- {
|
||||
if arc.hooks[i] == nil {
|
||||
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||
}
|
||||
mut = arc.hooks[i](mut)
|
||||
}
|
||||
v, err := mut.Mutate(ctx, arc.mutation)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
nv, ok := v.(*AuthRoles)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected node type %T returned from AuthRolesMutation", v)
|
||||
}
|
||||
node = nv
|
||||
}
|
||||
return node, err
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (arc *AuthRolesCreate) SaveX(ctx context.Context) *AuthRoles {
|
||||
v, err := arc.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (arc *AuthRolesCreate) Exec(ctx context.Context) error {
|
||||
_, err := arc.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (arc *AuthRolesCreate) ExecX(ctx context.Context) {
|
||||
if err := arc.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (arc *AuthRolesCreate) defaults() {
|
||||
if _, ok := arc.mutation.Role(); !ok {
|
||||
v := authroles.DefaultRole
|
||||
arc.mutation.SetRole(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (arc *AuthRolesCreate) check() error {
|
||||
if _, ok := arc.mutation.Role(); !ok {
|
||||
return &ValidationError{Name: "role", err: errors.New(`ent: missing required field "AuthRoles.role"`)}
|
||||
}
|
||||
if v, ok := arc.mutation.Role(); ok {
|
||||
if err := authroles.RoleValidator(v); err != nil {
|
||||
return &ValidationError{Name: "role", err: fmt.Errorf(`ent: validator failed for field "AuthRoles.role": %w`, err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (arc *AuthRolesCreate) sqlSave(ctx context.Context) (*AuthRoles, error) {
|
||||
_node, _spec := arc.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, arc.driver, _spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
id := _spec.ID.Value.(int64)
|
||||
_node.ID = int(id)
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (arc *AuthRolesCreate) createSpec() (*AuthRoles, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &AuthRoles{config: arc.config}
|
||||
_spec = &sqlgraph.CreateSpec{
|
||||
Table: authroles.Table,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: authroles.FieldID,
|
||||
},
|
||||
}
|
||||
)
|
||||
if value, ok := arc.mutation.Role(); ok {
|
||||
_spec.SetField(authroles.FieldRole, field.TypeEnum, value)
|
||||
_node.Role = value
|
||||
}
|
||||
if nodes := arc.mutation.TokenIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2O,
|
||||
Inverse: true,
|
||||
Table: authroles.TokenTable,
|
||||
Columns: []string{authroles.TokenColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeUUID,
|
||||
Column: authtokens.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_node.auth_tokens_roles = &nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// AuthRolesCreateBulk is the builder for creating many AuthRoles entities in bulk.
|
||||
type AuthRolesCreateBulk struct {
|
||||
config
|
||||
builders []*AuthRolesCreate
|
||||
}
|
||||
|
||||
// Save creates the AuthRoles entities in the database.
|
||||
func (arcb *AuthRolesCreateBulk) Save(ctx context.Context) ([]*AuthRoles, error) {
|
||||
specs := make([]*sqlgraph.CreateSpec, len(arcb.builders))
|
||||
nodes := make([]*AuthRoles, len(arcb.builders))
|
||||
mutators := make([]Mutator, len(arcb.builders))
|
||||
for i := range arcb.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := arcb.builders[i]
|
||||
builder.defaults()
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*AuthRolesMutation)
|
||||
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, arcb.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, arcb.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
|
||||
if specs[i].ID.Value != nil {
|
||||
id := specs[i].ID.Value.(int64)
|
||||
nodes[i].ID = int(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, arcb.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (arcb *AuthRolesCreateBulk) SaveX(ctx context.Context) []*AuthRoles {
|
||||
v, err := arcb.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (arcb *AuthRolesCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := arcb.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (arcb *AuthRolesCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := arcb.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
115
backend/internal/data/ent/authroles_delete.go
Normal file
115
backend/internal/data/ent/authroles_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/authroles"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/predicate"
|
||||
)
|
||||
|
||||
// AuthRolesDelete is the builder for deleting a AuthRoles entity.
|
||||
type AuthRolesDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *AuthRolesMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the AuthRolesDelete builder.
|
||||
func (ard *AuthRolesDelete) Where(ps ...predicate.AuthRoles) *AuthRolesDelete {
|
||||
ard.mutation.Where(ps...)
|
||||
return ard
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (ard *AuthRolesDelete) Exec(ctx context.Context) (int, error) {
|
||||
var (
|
||||
err error
|
||||
affected int
|
||||
)
|
||||
if len(ard.hooks) == 0 {
|
||||
affected, err = ard.sqlExec(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*AuthRolesMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
ard.mutation = mutation
|
||||
affected, err = ard.sqlExec(ctx)
|
||||
mutation.done = true
|
||||
return affected, err
|
||||
})
|
||||
for i := len(ard.hooks) - 1; i >= 0; i-- {
|
||||
if ard.hooks[i] == nil {
|
||||
return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||
}
|
||||
mut = ard.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, ard.mutation); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (ard *AuthRolesDelete) ExecX(ctx context.Context) int {
|
||||
n, err := ard.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (ard *AuthRolesDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := &sqlgraph.DeleteSpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: authroles.Table,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: authroles.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
if ps := ard.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
affected, err := sqlgraph.DeleteNodes(ctx, ard.driver, _spec)
|
||||
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// AuthRolesDeleteOne is the builder for deleting a single AuthRoles entity.
|
||||
type AuthRolesDeleteOne struct {
|
||||
ard *AuthRolesDelete
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (ardo *AuthRolesDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := ardo.ard.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{authroles.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (ardo *AuthRolesDeleteOne) ExecX(ctx context.Context) {
|
||||
ardo.ard.ExecX(ctx)
|
||||
}
|
||||
633
backend/internal/data/ent/authroles_query.go
Normal file
633
backend/internal/data/ent/authroles_query.go
Normal file
@@ -0,0 +1,633 @@
|
||||
// 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/authroles"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/authtokens"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/predicate"
|
||||
)
|
||||
|
||||
// AuthRolesQuery is the builder for querying AuthRoles entities.
|
||||
type AuthRolesQuery struct {
|
||||
config
|
||||
limit *int
|
||||
offset *int
|
||||
unique *bool
|
||||
order []OrderFunc
|
||||
fields []string
|
||||
predicates []predicate.AuthRoles
|
||||
withToken *AuthTokensQuery
|
||||
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 AuthRolesQuery builder.
|
||||
func (arq *AuthRolesQuery) Where(ps ...predicate.AuthRoles) *AuthRolesQuery {
|
||||
arq.predicates = append(arq.predicates, ps...)
|
||||
return arq
|
||||
}
|
||||
|
||||
// Limit adds a limit step to the query.
|
||||
func (arq *AuthRolesQuery) Limit(limit int) *AuthRolesQuery {
|
||||
arq.limit = &limit
|
||||
return arq
|
||||
}
|
||||
|
||||
// Offset adds an offset step to the query.
|
||||
func (arq *AuthRolesQuery) Offset(offset int) *AuthRolesQuery {
|
||||
arq.offset = &offset
|
||||
return arq
|
||||
}
|
||||
|
||||
// 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 (arq *AuthRolesQuery) Unique(unique bool) *AuthRolesQuery {
|
||||
arq.unique = &unique
|
||||
return arq
|
||||
}
|
||||
|
||||
// Order adds an order step to the query.
|
||||
func (arq *AuthRolesQuery) Order(o ...OrderFunc) *AuthRolesQuery {
|
||||
arq.order = append(arq.order, o...)
|
||||
return arq
|
||||
}
|
||||
|
||||
// QueryToken chains the current query on the "token" edge.
|
||||
func (arq *AuthRolesQuery) QueryToken() *AuthTokensQuery {
|
||||
query := &AuthTokensQuery{config: arq.config}
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := arq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := arq.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(authroles.Table, authroles.FieldID, selector),
|
||||
sqlgraph.To(authtokens.Table, authtokens.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, true, authroles.TokenTable, authroles.TokenColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(arq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first AuthRoles entity from the query.
|
||||
// Returns a *NotFoundError when no AuthRoles was found.
|
||||
func (arq *AuthRolesQuery) First(ctx context.Context) (*AuthRoles, error) {
|
||||
nodes, err := arq.Limit(1).All(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nil, &NotFoundError{authroles.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (arq *AuthRolesQuery) FirstX(ctx context.Context) *AuthRoles {
|
||||
node, err := arq.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first AuthRoles ID from the query.
|
||||
// Returns a *NotFoundError when no AuthRoles ID was found.
|
||||
func (arq *AuthRolesQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = arq.Limit(1).IDs(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{authroles.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (arq *AuthRolesQuery) FirstIDX(ctx context.Context) int {
|
||||
id, err := arq.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single AuthRoles entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one AuthRoles entity is found.
|
||||
// Returns a *NotFoundError when no AuthRoles entities are found.
|
||||
func (arq *AuthRolesQuery) Only(ctx context.Context) (*AuthRoles, error) {
|
||||
nodes, err := arq.Limit(2).All(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(nodes) {
|
||||
case 1:
|
||||
return nodes[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{authroles.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{authroles.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (arq *AuthRolesQuery) OnlyX(ctx context.Context) *AuthRoles {
|
||||
node, err := arq.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only AuthRoles ID in the query.
|
||||
// Returns a *NotSingularError when more than one AuthRoles ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (arq *AuthRolesQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = arq.Limit(2).IDs(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{authroles.Label}
|
||||
default:
|
||||
err = &NotSingularError{authroles.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (arq *AuthRolesQuery) OnlyIDX(ctx context.Context) int {
|
||||
id, err := arq.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of AuthRolesSlice.
|
||||
func (arq *AuthRolesQuery) All(ctx context.Context) ([]*AuthRoles, error) {
|
||||
if err := arq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return arq.sqlAll(ctx)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (arq *AuthRolesQuery) AllX(ctx context.Context) []*AuthRoles {
|
||||
nodes, err := arq.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of AuthRoles IDs.
|
||||
func (arq *AuthRolesQuery) IDs(ctx context.Context) ([]int, error) {
|
||||
var ids []int
|
||||
if err := arq.Select(authroles.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (arq *AuthRolesQuery) IDsX(ctx context.Context) []int {
|
||||
ids, err := arq.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (arq *AuthRolesQuery) Count(ctx context.Context) (int, error) {
|
||||
if err := arq.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return arq.sqlCount(ctx)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (arq *AuthRolesQuery) CountX(ctx context.Context) int {
|
||||
count, err := arq.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (arq *AuthRolesQuery) Exist(ctx context.Context) (bool, error) {
|
||||
if err := arq.prepareQuery(ctx); err != nil {
|
||||
return false, err
|
||||
}
|
||||
return arq.sqlExist(ctx)
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (arq *AuthRolesQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := arq.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the AuthRolesQuery builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (arq *AuthRolesQuery) Clone() *AuthRolesQuery {
|
||||
if arq == nil {
|
||||
return nil
|
||||
}
|
||||
return &AuthRolesQuery{
|
||||
config: arq.config,
|
||||
limit: arq.limit,
|
||||
offset: arq.offset,
|
||||
order: append([]OrderFunc{}, arq.order...),
|
||||
predicates: append([]predicate.AuthRoles{}, arq.predicates...),
|
||||
withToken: arq.withToken.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: arq.sql.Clone(),
|
||||
path: arq.path,
|
||||
unique: arq.unique,
|
||||
}
|
||||
}
|
||||
|
||||
// WithToken tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "token" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (arq *AuthRolesQuery) WithToken(opts ...func(*AuthTokensQuery)) *AuthRolesQuery {
|
||||
query := &AuthTokensQuery{config: arq.config}
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
arq.withToken = query
|
||||
return arq
|
||||
}
|
||||
|
||||
// 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 {
|
||||
// Role authroles.Role `json:"role,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.AuthRoles.Query().
|
||||
// GroupBy(authroles.FieldRole).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (arq *AuthRolesQuery) GroupBy(field string, fields ...string) *AuthRolesGroupBy {
|
||||
grbuild := &AuthRolesGroupBy{config: arq.config}
|
||||
grbuild.fields = append([]string{field}, fields...)
|
||||
grbuild.path = func(ctx context.Context) (prev *sql.Selector, err error) {
|
||||
if err := arq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return arq.sqlQuery(ctx), nil
|
||||
}
|
||||
grbuild.label = authroles.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 {
|
||||
// Role authroles.Role `json:"role,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.AuthRoles.Query().
|
||||
// Select(authroles.FieldRole).
|
||||
// Scan(ctx, &v)
|
||||
func (arq *AuthRolesQuery) Select(fields ...string) *AuthRolesSelect {
|
||||
arq.fields = append(arq.fields, fields...)
|
||||
selbuild := &AuthRolesSelect{AuthRolesQuery: arq}
|
||||
selbuild.label = authroles.Label
|
||||
selbuild.flds, selbuild.scan = &arq.fields, selbuild.Scan
|
||||
return selbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a AuthRolesSelect configured with the given aggregations.
|
||||
func (arq *AuthRolesQuery) Aggregate(fns ...AggregateFunc) *AuthRolesSelect {
|
||||
return arq.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (arq *AuthRolesQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, f := range arq.fields {
|
||||
if !authroles.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
}
|
||||
if arq.path != nil {
|
||||
prev, err := arq.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
arq.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (arq *AuthRolesQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*AuthRoles, error) {
|
||||
var (
|
||||
nodes = []*AuthRoles{}
|
||||
withFKs = arq.withFKs
|
||||
_spec = arq.querySpec()
|
||||
loadedTypes = [1]bool{
|
||||
arq.withToken != nil,
|
||||
}
|
||||
)
|
||||
if arq.withToken != nil {
|
||||
withFKs = true
|
||||
}
|
||||
if withFKs {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, authroles.ForeignKeys...)
|
||||
}
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*AuthRoles).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &AuthRoles{config: arq.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, arq.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
if query := arq.withToken; query != nil {
|
||||
if err := arq.loadToken(ctx, query, nodes, nil,
|
||||
func(n *AuthRoles, e *AuthTokens) { n.Edges.Token = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (arq *AuthRolesQuery) loadToken(ctx context.Context, query *AuthTokensQuery, nodes []*AuthRoles, init func(*AuthRoles), assign func(*AuthRoles, *AuthTokens)) error {
|
||||
ids := make([]uuid.UUID, 0, len(nodes))
|
||||
nodeids := make(map[uuid.UUID][]*AuthRoles)
|
||||
for i := range nodes {
|
||||
if nodes[i].auth_tokens_roles == nil {
|
||||
continue
|
||||
}
|
||||
fk := *nodes[i].auth_tokens_roles
|
||||
if _, ok := nodeids[fk]; !ok {
|
||||
ids = append(ids, fk)
|
||||
}
|
||||
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||
}
|
||||
query.Where(authtokens.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 "auth_tokens_roles" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
assign(nodes[i], n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (arq *AuthRolesQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := arq.querySpec()
|
||||
_spec.Node.Columns = arq.fields
|
||||
if len(arq.fields) > 0 {
|
||||
_spec.Unique = arq.unique != nil && *arq.unique
|
||||
}
|
||||
return sqlgraph.CountNodes(ctx, arq.driver, _spec)
|
||||
}
|
||||
|
||||
func (arq *AuthRolesQuery) sqlExist(ctx context.Context) (bool, error) {
|
||||
switch _, err := arq.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 (arq *AuthRolesQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := &sqlgraph.QuerySpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: authroles.Table,
|
||||
Columns: authroles.Columns,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: authroles.FieldID,
|
||||
},
|
||||
},
|
||||
From: arq.sql,
|
||||
Unique: true,
|
||||
}
|
||||
if unique := arq.unique; unique != nil {
|
||||
_spec.Unique = *unique
|
||||
}
|
||||
if fields := arq.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, authroles.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != authroles.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := arq.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := arq.limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := arq.offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := arq.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (arq *AuthRolesQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(arq.driver.Dialect())
|
||||
t1 := builder.Table(authroles.Table)
|
||||
columns := arq.fields
|
||||
if len(columns) == 0 {
|
||||
columns = authroles.Columns
|
||||
}
|
||||
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||
if arq.sql != nil {
|
||||
selector = arq.sql
|
||||
selector.Select(selector.Columns(columns...)...)
|
||||
}
|
||||
if arq.unique != nil && *arq.unique {
|
||||
selector.Distinct()
|
||||
}
|
||||
for _, p := range arq.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range arq.order {
|
||||
p(selector)
|
||||
}
|
||||
if offset := arq.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 := arq.limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
// AuthRolesGroupBy is the group-by builder for AuthRoles entities.
|
||||
type AuthRolesGroupBy 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 (argb *AuthRolesGroupBy) Aggregate(fns ...AggregateFunc) *AuthRolesGroupBy {
|
||||
argb.fns = append(argb.fns, fns...)
|
||||
return argb
|
||||
}
|
||||
|
||||
// Scan applies the group-by query and scans the result into the given value.
|
||||
func (argb *AuthRolesGroupBy) Scan(ctx context.Context, v any) error {
|
||||
query, err := argb.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
argb.sql = query
|
||||
return argb.sqlScan(ctx, v)
|
||||
}
|
||||
|
||||
func (argb *AuthRolesGroupBy) sqlScan(ctx context.Context, v any) error {
|
||||
for _, f := range argb.fields {
|
||||
if !authroles.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)}
|
||||
}
|
||||
}
|
||||
selector := argb.sqlQuery()
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := argb.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
func (argb *AuthRolesGroupBy) sqlQuery() *sql.Selector {
|
||||
selector := argb.sql.Select()
|
||||
aggregation := make([]string, 0, len(argb.fns))
|
||||
for _, fn := range argb.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(argb.fields)+len(argb.fns))
|
||||
for _, f := range argb.fields {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
return selector.GroupBy(selector.Columns(argb.fields...)...)
|
||||
}
|
||||
|
||||
// AuthRolesSelect is the builder for selecting fields of AuthRoles entities.
|
||||
type AuthRolesSelect struct {
|
||||
*AuthRolesQuery
|
||||
selector
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (ars *AuthRolesSelect) Aggregate(fns ...AggregateFunc) *AuthRolesSelect {
|
||||
ars.fns = append(ars.fns, fns...)
|
||||
return ars
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (ars *AuthRolesSelect) Scan(ctx context.Context, v any) error {
|
||||
if err := ars.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
ars.sql = ars.AuthRolesQuery.sqlQuery(ctx)
|
||||
return ars.sqlScan(ctx, v)
|
||||
}
|
||||
|
||||
func (ars *AuthRolesSelect) sqlScan(ctx context.Context, v any) error {
|
||||
aggregation := make([]string, 0, len(ars.fns))
|
||||
for _, fn := range ars.fns {
|
||||
aggregation = append(aggregation, fn(ars.sql))
|
||||
}
|
||||
switch n := len(*ars.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
ars.sql.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
ars.sql.AppendSelect(aggregation...)
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := ars.sql.Query()
|
||||
if err := ars.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
433
backend/internal/data/ent/authroles_update.go
Normal file
433
backend/internal/data/ent/authroles_update.go
Normal file
@@ -0,0 +1,433 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"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/authroles"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/authtokens"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/predicate"
|
||||
)
|
||||
|
||||
// AuthRolesUpdate is the builder for updating AuthRoles entities.
|
||||
type AuthRolesUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *AuthRolesMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the AuthRolesUpdate builder.
|
||||
func (aru *AuthRolesUpdate) Where(ps ...predicate.AuthRoles) *AuthRolesUpdate {
|
||||
aru.mutation.Where(ps...)
|
||||
return aru
|
||||
}
|
||||
|
||||
// SetRole sets the "role" field.
|
||||
func (aru *AuthRolesUpdate) SetRole(a authroles.Role) *AuthRolesUpdate {
|
||||
aru.mutation.SetRole(a)
|
||||
return aru
|
||||
}
|
||||
|
||||
// SetNillableRole sets the "role" field if the given value is not nil.
|
||||
func (aru *AuthRolesUpdate) SetNillableRole(a *authroles.Role) *AuthRolesUpdate {
|
||||
if a != nil {
|
||||
aru.SetRole(*a)
|
||||
}
|
||||
return aru
|
||||
}
|
||||
|
||||
// SetTokenID sets the "token" edge to the AuthTokens entity by ID.
|
||||
func (aru *AuthRolesUpdate) SetTokenID(id uuid.UUID) *AuthRolesUpdate {
|
||||
aru.mutation.SetTokenID(id)
|
||||
return aru
|
||||
}
|
||||
|
||||
// SetNillableTokenID sets the "token" edge to the AuthTokens entity by ID if the given value is not nil.
|
||||
func (aru *AuthRolesUpdate) SetNillableTokenID(id *uuid.UUID) *AuthRolesUpdate {
|
||||
if id != nil {
|
||||
aru = aru.SetTokenID(*id)
|
||||
}
|
||||
return aru
|
||||
}
|
||||
|
||||
// SetToken sets the "token" edge to the AuthTokens entity.
|
||||
func (aru *AuthRolesUpdate) SetToken(a *AuthTokens) *AuthRolesUpdate {
|
||||
return aru.SetTokenID(a.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the AuthRolesMutation object of the builder.
|
||||
func (aru *AuthRolesUpdate) Mutation() *AuthRolesMutation {
|
||||
return aru.mutation
|
||||
}
|
||||
|
||||
// ClearToken clears the "token" edge to the AuthTokens entity.
|
||||
func (aru *AuthRolesUpdate) ClearToken() *AuthRolesUpdate {
|
||||
aru.mutation.ClearToken()
|
||||
return aru
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (aru *AuthRolesUpdate) Save(ctx context.Context) (int, error) {
|
||||
var (
|
||||
err error
|
||||
affected int
|
||||
)
|
||||
if len(aru.hooks) == 0 {
|
||||
if err = aru.check(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
affected, err = aru.sqlSave(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*AuthRolesMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err = aru.check(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
aru.mutation = mutation
|
||||
affected, err = aru.sqlSave(ctx)
|
||||
mutation.done = true
|
||||
return affected, err
|
||||
})
|
||||
for i := len(aru.hooks) - 1; i >= 0; i-- {
|
||||
if aru.hooks[i] == nil {
|
||||
return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||
}
|
||||
mut = aru.hooks[i](mut)
|
||||
}
|
||||
if _, err := mut.Mutate(ctx, aru.mutation); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (aru *AuthRolesUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := aru.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (aru *AuthRolesUpdate) Exec(ctx context.Context) error {
|
||||
_, err := aru.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (aru *AuthRolesUpdate) ExecX(ctx context.Context) {
|
||||
if err := aru.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (aru *AuthRolesUpdate) check() error {
|
||||
if v, ok := aru.mutation.Role(); ok {
|
||||
if err := authroles.RoleValidator(v); err != nil {
|
||||
return &ValidationError{Name: "role", err: fmt.Errorf(`ent: validator failed for field "AuthRoles.role": %w`, err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (aru *AuthRolesUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
_spec := &sqlgraph.UpdateSpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: authroles.Table,
|
||||
Columns: authroles.Columns,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: authroles.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
if ps := aru.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := aru.mutation.Role(); ok {
|
||||
_spec.SetField(authroles.FieldRole, field.TypeEnum, value)
|
||||
}
|
||||
if aru.mutation.TokenCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2O,
|
||||
Inverse: true,
|
||||
Table: authroles.TokenTable,
|
||||
Columns: []string{authroles.TokenColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeUUID,
|
||||
Column: authtokens.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := aru.mutation.TokenIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2O,
|
||||
Inverse: true,
|
||||
Table: authroles.TokenTable,
|
||||
Columns: []string{authroles.TokenColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeUUID,
|
||||
Column: authtokens.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, aru.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{authroles.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// AuthRolesUpdateOne is the builder for updating a single AuthRoles entity.
|
||||
type AuthRolesUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *AuthRolesMutation
|
||||
}
|
||||
|
||||
// SetRole sets the "role" field.
|
||||
func (aruo *AuthRolesUpdateOne) SetRole(a authroles.Role) *AuthRolesUpdateOne {
|
||||
aruo.mutation.SetRole(a)
|
||||
return aruo
|
||||
}
|
||||
|
||||
// SetNillableRole sets the "role" field if the given value is not nil.
|
||||
func (aruo *AuthRolesUpdateOne) SetNillableRole(a *authroles.Role) *AuthRolesUpdateOne {
|
||||
if a != nil {
|
||||
aruo.SetRole(*a)
|
||||
}
|
||||
return aruo
|
||||
}
|
||||
|
||||
// SetTokenID sets the "token" edge to the AuthTokens entity by ID.
|
||||
func (aruo *AuthRolesUpdateOne) SetTokenID(id uuid.UUID) *AuthRolesUpdateOne {
|
||||
aruo.mutation.SetTokenID(id)
|
||||
return aruo
|
||||
}
|
||||
|
||||
// SetNillableTokenID sets the "token" edge to the AuthTokens entity by ID if the given value is not nil.
|
||||
func (aruo *AuthRolesUpdateOne) SetNillableTokenID(id *uuid.UUID) *AuthRolesUpdateOne {
|
||||
if id != nil {
|
||||
aruo = aruo.SetTokenID(*id)
|
||||
}
|
||||
return aruo
|
||||
}
|
||||
|
||||
// SetToken sets the "token" edge to the AuthTokens entity.
|
||||
func (aruo *AuthRolesUpdateOne) SetToken(a *AuthTokens) *AuthRolesUpdateOne {
|
||||
return aruo.SetTokenID(a.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the AuthRolesMutation object of the builder.
|
||||
func (aruo *AuthRolesUpdateOne) Mutation() *AuthRolesMutation {
|
||||
return aruo.mutation
|
||||
}
|
||||
|
||||
// ClearToken clears the "token" edge to the AuthTokens entity.
|
||||
func (aruo *AuthRolesUpdateOne) ClearToken() *AuthRolesUpdateOne {
|
||||
aruo.mutation.ClearToken()
|
||||
return aruo
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (aruo *AuthRolesUpdateOne) Select(field string, fields ...string) *AuthRolesUpdateOne {
|
||||
aruo.fields = append([]string{field}, fields...)
|
||||
return aruo
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated AuthRoles entity.
|
||||
func (aruo *AuthRolesUpdateOne) Save(ctx context.Context) (*AuthRoles, error) {
|
||||
var (
|
||||
err error
|
||||
node *AuthRoles
|
||||
)
|
||||
if len(aruo.hooks) == 0 {
|
||||
if err = aruo.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
node, err = aruo.sqlSave(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*AuthRolesMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err = aruo.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
aruo.mutation = mutation
|
||||
node, err = aruo.sqlSave(ctx)
|
||||
mutation.done = true
|
||||
return node, err
|
||||
})
|
||||
for i := len(aruo.hooks) - 1; i >= 0; i-- {
|
||||
if aruo.hooks[i] == nil {
|
||||
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||
}
|
||||
mut = aruo.hooks[i](mut)
|
||||
}
|
||||
v, err := mut.Mutate(ctx, aruo.mutation)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
nv, ok := v.(*AuthRoles)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected node type %T returned from AuthRolesMutation", v)
|
||||
}
|
||||
node = nv
|
||||
}
|
||||
return node, err
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (aruo *AuthRolesUpdateOne) SaveX(ctx context.Context) *AuthRoles {
|
||||
node, err := aruo.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (aruo *AuthRolesUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := aruo.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (aruo *AuthRolesUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := aruo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (aruo *AuthRolesUpdateOne) check() error {
|
||||
if v, ok := aruo.mutation.Role(); ok {
|
||||
if err := authroles.RoleValidator(v); err != nil {
|
||||
return &ValidationError{Name: "role", err: fmt.Errorf(`ent: validator failed for field "AuthRoles.role": %w`, err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (aruo *AuthRolesUpdateOne) sqlSave(ctx context.Context) (_node *AuthRoles, err error) {
|
||||
_spec := &sqlgraph.UpdateSpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: authroles.Table,
|
||||
Columns: authroles.Columns,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: authroles.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
id, ok := aruo.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "AuthRoles.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := aruo.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, authroles.FieldID)
|
||||
for _, f := range fields {
|
||||
if !authroles.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != authroles.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := aruo.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := aruo.mutation.Role(); ok {
|
||||
_spec.SetField(authroles.FieldRole, field.TypeEnum, value)
|
||||
}
|
||||
if aruo.mutation.TokenCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2O,
|
||||
Inverse: true,
|
||||
Table: authroles.TokenTable,
|
||||
Columns: []string{authroles.TokenColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeUUID,
|
||||
Column: authtokens.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := aruo.mutation.TokenIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2O,
|
||||
Inverse: true,
|
||||
Table: authroles.TokenTable,
|
||||
Columns: []string{authroles.TokenColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeUUID,
|
||||
Column: authtokens.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_node = &AuthRoles{config: aruo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, aruo.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{authroles.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return _node, nil
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"github.com/google/uuid"
|
||||
"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/user"
|
||||
)
|
||||
@@ -36,9 +37,11 @@ type AuthTokens struct {
|
||||
type AuthTokensEdges struct {
|
||||
// User holds the value of the user edge.
|
||||
User *User `json:"user,omitempty"`
|
||||
// Roles holds the value of the roles edge.
|
||||
Roles *AuthRoles `json:"roles,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [1]bool
|
||||
loadedTypes [2]bool
|
||||
}
|
||||
|
||||
// UserOrErr returns the User value or an error if the edge
|
||||
@@ -54,6 +57,19 @@ func (e AuthTokensEdges) UserOrErr() (*User, error) {
|
||||
return nil, &NotLoadedError{edge: "user"}
|
||||
}
|
||||
|
||||
// RolesOrErr returns the Roles value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e AuthTokensEdges) RolesOrErr() (*AuthRoles, error) {
|
||||
if e.loadedTypes[1] {
|
||||
if e.Roles == nil {
|
||||
// Edge was loaded but was not found.
|
||||
return nil, &NotFoundError{label: authroles.Label}
|
||||
}
|
||||
return e.Roles, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "roles"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*AuthTokens) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
@@ -129,6 +145,11 @@ func (at *AuthTokens) QueryUser() *UserQuery {
|
||||
return (&AuthTokensClient{config: at.config}).QueryUser(at)
|
||||
}
|
||||
|
||||
// QueryRoles queries the "roles" edge of the AuthTokens entity.
|
||||
func (at *AuthTokens) QueryRoles() *AuthRolesQuery {
|
||||
return (&AuthTokensClient{config: at.config}).QueryRoles(at)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this AuthTokens.
|
||||
// Note that you need to call AuthTokens.Unwrap() before calling this method if this AuthTokens
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
|
||||
@@ -23,6 +23,8 @@ const (
|
||||
FieldExpiresAt = "expires_at"
|
||||
// EdgeUser holds the string denoting the user edge name in mutations.
|
||||
EdgeUser = "user"
|
||||
// EdgeRoles holds the string denoting the roles edge name in mutations.
|
||||
EdgeRoles = "roles"
|
||||
// Table holds the table name of the authtokens in the database.
|
||||
Table = "auth_tokens"
|
||||
// UserTable is the table that holds the user relation/edge.
|
||||
@@ -32,6 +34,13 @@ const (
|
||||
UserInverseTable = "users"
|
||||
// UserColumn is the table column denoting the user relation/edge.
|
||||
UserColumn = "user_auth_tokens"
|
||||
// RolesTable is the table that holds the roles relation/edge.
|
||||
RolesTable = "auth_roles"
|
||||
// RolesInverseTable is the table name for the AuthRoles entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "authroles" package.
|
||||
RolesInverseTable = "auth_roles"
|
||||
// RolesColumn is the table column denoting the roles relation/edge.
|
||||
RolesColumn = "auth_tokens_roles"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for authtokens fields.
|
||||
|
||||
@@ -394,6 +394,34 @@ func HasUserWith(preds ...predicate.User) predicate.AuthTokens {
|
||||
})
|
||||
}
|
||||
|
||||
// HasRoles applies the HasEdge predicate on the "roles" edge.
|
||||
func HasRoles() predicate.AuthTokens {
|
||||
return predicate.AuthTokens(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(RolesTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, false, RolesTable, RolesColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasRolesWith applies the HasEdge predicate on the "roles" edge with a given conditions (other predicates).
|
||||
func HasRolesWith(preds ...predicate.AuthRoles) predicate.AuthTokens {
|
||||
return predicate.AuthTokens(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(RolesInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, false, RolesTable, RolesColumn),
|
||||
)
|
||||
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.AuthTokens) predicate.AuthTokens {
|
||||
return predicate.AuthTokens(func(s *sql.Selector) {
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/google/uuid"
|
||||
"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/user"
|
||||
)
|
||||
@@ -103,6 +104,25 @@ func (atc *AuthTokensCreate) SetUser(u *User) *AuthTokensCreate {
|
||||
return atc.SetUserID(u.ID)
|
||||
}
|
||||
|
||||
// SetRolesID sets the "roles" edge to the AuthRoles entity by ID.
|
||||
func (atc *AuthTokensCreate) SetRolesID(id int) *AuthTokensCreate {
|
||||
atc.mutation.SetRolesID(id)
|
||||
return atc
|
||||
}
|
||||
|
||||
// SetNillableRolesID sets the "roles" edge to the AuthRoles entity by ID if the given value is not nil.
|
||||
func (atc *AuthTokensCreate) SetNillableRolesID(id *int) *AuthTokensCreate {
|
||||
if id != nil {
|
||||
atc = atc.SetRolesID(*id)
|
||||
}
|
||||
return atc
|
||||
}
|
||||
|
||||
// SetRoles sets the "roles" edge to the AuthRoles entity.
|
||||
func (atc *AuthTokensCreate) SetRoles(a *AuthRoles) *AuthTokensCreate {
|
||||
return atc.SetRolesID(a.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the AuthTokensMutation object of the builder.
|
||||
func (atc *AuthTokensCreate) Mutation() *AuthTokensMutation {
|
||||
return atc.mutation
|
||||
@@ -249,35 +269,19 @@ func (atc *AuthTokensCreate) createSpec() (*AuthTokens, *sqlgraph.CreateSpec) {
|
||||
_spec.ID.Value = &id
|
||||
}
|
||||
if value, ok := atc.mutation.CreatedAt(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: authtokens.FieldCreatedAt,
|
||||
})
|
||||
_spec.SetField(authtokens.FieldCreatedAt, field.TypeTime, value)
|
||||
_node.CreatedAt = value
|
||||
}
|
||||
if value, ok := atc.mutation.UpdatedAt(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: authtokens.FieldUpdatedAt,
|
||||
})
|
||||
_spec.SetField(authtokens.FieldUpdatedAt, field.TypeTime, value)
|
||||
_node.UpdatedAt = value
|
||||
}
|
||||
if value, ok := atc.mutation.Token(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeBytes,
|
||||
Value: value,
|
||||
Column: authtokens.FieldToken,
|
||||
})
|
||||
_spec.SetField(authtokens.FieldToken, field.TypeBytes, value)
|
||||
_node.Token = value
|
||||
}
|
||||
if value, ok := atc.mutation.ExpiresAt(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: authtokens.FieldExpiresAt,
|
||||
})
|
||||
_spec.SetField(authtokens.FieldExpiresAt, field.TypeTime, value)
|
||||
_node.ExpiresAt = value
|
||||
}
|
||||
if nodes := atc.mutation.UserIDs(); len(nodes) > 0 {
|
||||
@@ -300,6 +304,25 @@ func (atc *AuthTokensCreate) createSpec() (*AuthTokens, *sqlgraph.CreateSpec) {
|
||||
_node.user_auth_tokens = &nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
if nodes := atc.mutation.RolesIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2O,
|
||||
Inverse: false,
|
||||
Table: authtokens.RolesTable,
|
||||
Columns: []string{authtokens.RolesColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: authroles.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
@@ -11,6 +12,7 @@ import (
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/google/uuid"
|
||||
"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/predicate"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/user"
|
||||
@@ -26,6 +28,7 @@ type AuthTokensQuery struct {
|
||||
fields []string
|
||||
predicates []predicate.AuthTokens
|
||||
withUser *UserQuery
|
||||
withRoles *AuthRolesQuery
|
||||
withFKs bool
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
@@ -85,6 +88,28 @@ func (atq *AuthTokensQuery) QueryUser() *UserQuery {
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryRoles chains the current query on the "roles" edge.
|
||||
func (atq *AuthTokensQuery) QueryRoles() *AuthRolesQuery {
|
||||
query := &AuthRolesQuery{config: atq.config}
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := atq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := atq.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(authtokens.Table, authtokens.FieldID, selector),
|
||||
sqlgraph.To(authroles.Table, authroles.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, false, authtokens.RolesTable, authtokens.RolesColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(atq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first AuthTokens entity from the query.
|
||||
// Returns a *NotFoundError when no AuthTokens was found.
|
||||
func (atq *AuthTokensQuery) First(ctx context.Context) (*AuthTokens, error) {
|
||||
@@ -267,6 +292,7 @@ func (atq *AuthTokensQuery) Clone() *AuthTokensQuery {
|
||||
order: append([]OrderFunc{}, atq.order...),
|
||||
predicates: append([]predicate.AuthTokens{}, atq.predicates...),
|
||||
withUser: atq.withUser.Clone(),
|
||||
withRoles: atq.withRoles.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: atq.sql.Clone(),
|
||||
path: atq.path,
|
||||
@@ -285,6 +311,17 @@ func (atq *AuthTokensQuery) WithUser(opts ...func(*UserQuery)) *AuthTokensQuery
|
||||
return atq
|
||||
}
|
||||
|
||||
// WithRoles tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "roles" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (atq *AuthTokensQuery) WithRoles(opts ...func(*AuthRolesQuery)) *AuthTokensQuery {
|
||||
query := &AuthRolesQuery{config: atq.config}
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
atq.withRoles = query
|
||||
return atq
|
||||
}
|
||||
|
||||
// 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.
|
||||
//
|
||||
@@ -333,6 +370,11 @@ func (atq *AuthTokensQuery) Select(fields ...string) *AuthTokensSelect {
|
||||
return selbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a AuthTokensSelect configured with the given aggregations.
|
||||
func (atq *AuthTokensQuery) Aggregate(fns ...AggregateFunc) *AuthTokensSelect {
|
||||
return atq.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (atq *AuthTokensQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, f := range atq.fields {
|
||||
if !authtokens.ValidColumn(f) {
|
||||
@@ -354,8 +396,9 @@ func (atq *AuthTokensQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*
|
||||
nodes = []*AuthTokens{}
|
||||
withFKs = atq.withFKs
|
||||
_spec = atq.querySpec()
|
||||
loadedTypes = [1]bool{
|
||||
loadedTypes = [2]bool{
|
||||
atq.withUser != nil,
|
||||
atq.withRoles != nil,
|
||||
}
|
||||
)
|
||||
if atq.withUser != nil {
|
||||
@@ -388,6 +431,12 @@ func (atq *AuthTokensQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if query := atq.withRoles; query != nil {
|
||||
if err := atq.loadRoles(ctx, query, nodes, nil,
|
||||
func(n *AuthTokens, e *AuthRoles) { n.Edges.Roles = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
@@ -420,6 +469,34 @@ func (atq *AuthTokensQuery) loadUser(ctx context.Context, query *UserQuery, node
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (atq *AuthTokensQuery) loadRoles(ctx context.Context, query *AuthRolesQuery, nodes []*AuthTokens, init func(*AuthTokens), assign func(*AuthTokens, *AuthRoles)) error {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
nodeids := make(map[uuid.UUID]*AuthTokens)
|
||||
for i := range nodes {
|
||||
fks = append(fks, nodes[i].ID)
|
||||
nodeids[nodes[i].ID] = nodes[i]
|
||||
}
|
||||
query.withFKs = true
|
||||
query.Where(predicate.AuthRoles(func(s *sql.Selector) {
|
||||
s.Where(sql.InValues(authtokens.RolesColumn, fks...))
|
||||
}))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
fk := n.auth_tokens_roles
|
||||
if fk == nil {
|
||||
return fmt.Errorf(`foreign-key "auth_tokens_roles" is nil for node %v`, n.ID)
|
||||
}
|
||||
node, ok := nodeids[*fk]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected foreign-key "auth_tokens_roles" returned %v for node %v`, *fk, n.ID)
|
||||
}
|
||||
assign(node, n)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (atq *AuthTokensQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := atq.querySpec()
|
||||
@@ -573,8 +650,6 @@ func (atgb *AuthTokensGroupBy) sqlQuery() *sql.Selector {
|
||||
for _, fn := range atgb.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
// If no columns were selected in a custom aggregation function, the default
|
||||
// selection is the fields used for "group-by", and the aggregation functions.
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(atgb.fields)+len(atgb.fns))
|
||||
for _, f := range atgb.fields {
|
||||
@@ -594,6 +669,12 @@ type AuthTokensSelect struct {
|
||||
sql *sql.Selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (ats *AuthTokensSelect) Aggregate(fns ...AggregateFunc) *AuthTokensSelect {
|
||||
ats.fns = append(ats.fns, fns...)
|
||||
return ats
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (ats *AuthTokensSelect) Scan(ctx context.Context, v any) error {
|
||||
if err := ats.prepareQuery(ctx); err != nil {
|
||||
@@ -604,6 +685,16 @@ func (ats *AuthTokensSelect) Scan(ctx context.Context, v any) error {
|
||||
}
|
||||
|
||||
func (ats *AuthTokensSelect) sqlScan(ctx context.Context, v any) error {
|
||||
aggregation := make([]string, 0, len(ats.fns))
|
||||
for _, fn := range ats.fns {
|
||||
aggregation = append(aggregation, fn(ats.sql))
|
||||
}
|
||||
switch n := len(*ats.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
ats.sql.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
ats.sql.AppendSelect(aggregation...)
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := ats.sql.Query()
|
||||
if err := ats.driver.Query(ctx, query, args, rows); err != nil {
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/google/uuid"
|
||||
"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/predicate"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/user"
|
||||
@@ -75,6 +76,25 @@ func (atu *AuthTokensUpdate) SetUser(u *User) *AuthTokensUpdate {
|
||||
return atu.SetUserID(u.ID)
|
||||
}
|
||||
|
||||
// SetRolesID sets the "roles" edge to the AuthRoles entity by ID.
|
||||
func (atu *AuthTokensUpdate) SetRolesID(id int) *AuthTokensUpdate {
|
||||
atu.mutation.SetRolesID(id)
|
||||
return atu
|
||||
}
|
||||
|
||||
// SetNillableRolesID sets the "roles" edge to the AuthRoles entity by ID if the given value is not nil.
|
||||
func (atu *AuthTokensUpdate) SetNillableRolesID(id *int) *AuthTokensUpdate {
|
||||
if id != nil {
|
||||
atu = atu.SetRolesID(*id)
|
||||
}
|
||||
return atu
|
||||
}
|
||||
|
||||
// SetRoles sets the "roles" edge to the AuthRoles entity.
|
||||
func (atu *AuthTokensUpdate) SetRoles(a *AuthRoles) *AuthTokensUpdate {
|
||||
return atu.SetRolesID(a.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the AuthTokensMutation object of the builder.
|
||||
func (atu *AuthTokensUpdate) Mutation() *AuthTokensMutation {
|
||||
return atu.mutation
|
||||
@@ -86,6 +106,12 @@ func (atu *AuthTokensUpdate) ClearUser() *AuthTokensUpdate {
|
||||
return atu
|
||||
}
|
||||
|
||||
// ClearRoles clears the "roles" edge to the AuthRoles entity.
|
||||
func (atu *AuthTokensUpdate) ClearRoles() *AuthTokensUpdate {
|
||||
atu.mutation.ClearRoles()
|
||||
return atu
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (atu *AuthTokensUpdate) Save(ctx context.Context) (int, error) {
|
||||
var (
|
||||
@@ -168,25 +194,13 @@ func (atu *AuthTokensUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
}
|
||||
}
|
||||
if value, ok := atu.mutation.UpdatedAt(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: authtokens.FieldUpdatedAt,
|
||||
})
|
||||
_spec.SetField(authtokens.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := atu.mutation.Token(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeBytes,
|
||||
Value: value,
|
||||
Column: authtokens.FieldToken,
|
||||
})
|
||||
_spec.SetField(authtokens.FieldToken, field.TypeBytes, value)
|
||||
}
|
||||
if value, ok := atu.mutation.ExpiresAt(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: authtokens.FieldExpiresAt,
|
||||
})
|
||||
_spec.SetField(authtokens.FieldExpiresAt, field.TypeTime, value)
|
||||
}
|
||||
if atu.mutation.UserCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
@@ -223,6 +237,41 @@ func (atu *AuthTokensUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if atu.mutation.RolesCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2O,
|
||||
Inverse: false,
|
||||
Table: authtokens.RolesTable,
|
||||
Columns: []string{authtokens.RolesColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: authroles.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := atu.mutation.RolesIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2O,
|
||||
Inverse: false,
|
||||
Table: authtokens.RolesTable,
|
||||
Columns: []string{authtokens.RolesColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: authroles.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, atu.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{authtokens.Label}
|
||||
@@ -287,6 +336,25 @@ func (atuo *AuthTokensUpdateOne) SetUser(u *User) *AuthTokensUpdateOne {
|
||||
return atuo.SetUserID(u.ID)
|
||||
}
|
||||
|
||||
// SetRolesID sets the "roles" edge to the AuthRoles entity by ID.
|
||||
func (atuo *AuthTokensUpdateOne) SetRolesID(id int) *AuthTokensUpdateOne {
|
||||
atuo.mutation.SetRolesID(id)
|
||||
return atuo
|
||||
}
|
||||
|
||||
// SetNillableRolesID sets the "roles" edge to the AuthRoles entity by ID if the given value is not nil.
|
||||
func (atuo *AuthTokensUpdateOne) SetNillableRolesID(id *int) *AuthTokensUpdateOne {
|
||||
if id != nil {
|
||||
atuo = atuo.SetRolesID(*id)
|
||||
}
|
||||
return atuo
|
||||
}
|
||||
|
||||
// SetRoles sets the "roles" edge to the AuthRoles entity.
|
||||
func (atuo *AuthTokensUpdateOne) SetRoles(a *AuthRoles) *AuthTokensUpdateOne {
|
||||
return atuo.SetRolesID(a.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the AuthTokensMutation object of the builder.
|
||||
func (atuo *AuthTokensUpdateOne) Mutation() *AuthTokensMutation {
|
||||
return atuo.mutation
|
||||
@@ -298,6 +366,12 @@ func (atuo *AuthTokensUpdateOne) ClearUser() *AuthTokensUpdateOne {
|
||||
return atuo
|
||||
}
|
||||
|
||||
// ClearRoles clears the "roles" edge to the AuthRoles entity.
|
||||
func (atuo *AuthTokensUpdateOne) ClearRoles() *AuthTokensUpdateOne {
|
||||
atuo.mutation.ClearRoles()
|
||||
return atuo
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (atuo *AuthTokensUpdateOne) Select(field string, fields ...string) *AuthTokensUpdateOne {
|
||||
@@ -410,25 +484,13 @@ func (atuo *AuthTokensUpdateOne) sqlSave(ctx context.Context) (_node *AuthTokens
|
||||
}
|
||||
}
|
||||
if value, ok := atuo.mutation.UpdatedAt(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: authtokens.FieldUpdatedAt,
|
||||
})
|
||||
_spec.SetField(authtokens.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := atuo.mutation.Token(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeBytes,
|
||||
Value: value,
|
||||
Column: authtokens.FieldToken,
|
||||
})
|
||||
_spec.SetField(authtokens.FieldToken, field.TypeBytes, value)
|
||||
}
|
||||
if value, ok := atuo.mutation.ExpiresAt(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: authtokens.FieldExpiresAt,
|
||||
})
|
||||
_spec.SetField(authtokens.FieldExpiresAt, field.TypeTime, value)
|
||||
}
|
||||
if atuo.mutation.UserCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
@@ -465,6 +527,41 @@ func (atuo *AuthTokensUpdateOne) sqlSave(ctx context.Context) (_node *AuthTokens
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if atuo.mutation.RolesCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2O,
|
||||
Inverse: false,
|
||||
Table: authtokens.RolesTable,
|
||||
Columns: []string{authtokens.RolesColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: authroles.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := atuo.mutation.RolesIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2O,
|
||||
Inverse: false,
|
||||
Table: authtokens.RolesTable,
|
||||
Columns: []string{authtokens.RolesColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: authroles.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_node = &AuthTokens{config: atuo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
|
||||
@@ -12,15 +12,16 @@ import (
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/migrate"
|
||||
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/attachment"
|
||||
"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/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/groupinvitationtoken"
|
||||
"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/label"
|
||||
"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"
|
||||
|
||||
"entgo.io/ent/dialect"
|
||||
@@ -35,12 +36,12 @@ type Client struct {
|
||||
Schema *migrate.Schema
|
||||
// Attachment is the client for interacting with the Attachment builders.
|
||||
Attachment *AttachmentClient
|
||||
// AuthRoles is the client for interacting with the AuthRoles builders.
|
||||
AuthRoles *AuthRolesClient
|
||||
// AuthTokens is the client for interacting with the AuthTokens builders.
|
||||
AuthTokens *AuthTokensClient
|
||||
// Document is the client for interacting with the Document builders.
|
||||
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 *GroupClient
|
||||
// GroupInvitationToken is the client for interacting with the GroupInvitationToken builders.
|
||||
@@ -53,6 +54,8 @@ type Client struct {
|
||||
Label *LabelClient
|
||||
// Location is the client for interacting with the Location builders.
|
||||
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 *UserClient
|
||||
}
|
||||
@@ -69,15 +72,16 @@ func NewClient(opts ...Option) *Client {
|
||||
func (c *Client) init() {
|
||||
c.Schema = migrate.NewSchema(c.driver)
|
||||
c.Attachment = NewAttachmentClient(c.config)
|
||||
c.AuthRoles = NewAuthRolesClient(c.config)
|
||||
c.AuthTokens = NewAuthTokensClient(c.config)
|
||||
c.Document = NewDocumentClient(c.config)
|
||||
c.DocumentToken = NewDocumentTokenClient(c.config)
|
||||
c.Group = NewGroupClient(c.config)
|
||||
c.GroupInvitationToken = NewGroupInvitationTokenClient(c.config)
|
||||
c.Item = NewItemClient(c.config)
|
||||
c.ItemField = NewItemFieldClient(c.config)
|
||||
c.Label = NewLabelClient(c.config)
|
||||
c.Location = NewLocationClient(c.config)
|
||||
c.MaintenanceEntry = NewMaintenanceEntryClient(c.config)
|
||||
c.User = NewUserClient(c.config)
|
||||
}
|
||||
|
||||
@@ -113,15 +117,16 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) {
|
||||
ctx: ctx,
|
||||
config: cfg,
|
||||
Attachment: NewAttachmentClient(cfg),
|
||||
AuthRoles: NewAuthRolesClient(cfg),
|
||||
AuthTokens: NewAuthTokensClient(cfg),
|
||||
Document: NewDocumentClient(cfg),
|
||||
DocumentToken: NewDocumentTokenClient(cfg),
|
||||
Group: NewGroupClient(cfg),
|
||||
GroupInvitationToken: NewGroupInvitationTokenClient(cfg),
|
||||
Item: NewItemClient(cfg),
|
||||
ItemField: NewItemFieldClient(cfg),
|
||||
Label: NewLabelClient(cfg),
|
||||
Location: NewLocationClient(cfg),
|
||||
MaintenanceEntry: NewMaintenanceEntryClient(cfg),
|
||||
User: NewUserClient(cfg),
|
||||
}, nil
|
||||
}
|
||||
@@ -143,15 +148,16 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
|
||||
ctx: ctx,
|
||||
config: cfg,
|
||||
Attachment: NewAttachmentClient(cfg),
|
||||
AuthRoles: NewAuthRolesClient(cfg),
|
||||
AuthTokens: NewAuthTokensClient(cfg),
|
||||
Document: NewDocumentClient(cfg),
|
||||
DocumentToken: NewDocumentTokenClient(cfg),
|
||||
Group: NewGroupClient(cfg),
|
||||
GroupInvitationToken: NewGroupInvitationTokenClient(cfg),
|
||||
Item: NewItemClient(cfg),
|
||||
ItemField: NewItemFieldClient(cfg),
|
||||
Label: NewLabelClient(cfg),
|
||||
Location: NewLocationClient(cfg),
|
||||
MaintenanceEntry: NewMaintenanceEntryClient(cfg),
|
||||
User: NewUserClient(cfg),
|
||||
}, nil
|
||||
}
|
||||
@@ -182,15 +188,16 @@ func (c *Client) Close() error {
|
||||
// In order to add hooks to a specific client, call: `client.Node.Use(...)`.
|
||||
func (c *Client) Use(hooks ...Hook) {
|
||||
c.Attachment.Use(hooks...)
|
||||
c.AuthRoles.Use(hooks...)
|
||||
c.AuthTokens.Use(hooks...)
|
||||
c.Document.Use(hooks...)
|
||||
c.DocumentToken.Use(hooks...)
|
||||
c.Group.Use(hooks...)
|
||||
c.GroupInvitationToken.Use(hooks...)
|
||||
c.Item.Use(hooks...)
|
||||
c.ItemField.Use(hooks...)
|
||||
c.Label.Use(hooks...)
|
||||
c.Location.Use(hooks...)
|
||||
c.MaintenanceEntry.Use(hooks...)
|
||||
c.User.Use(hooks...)
|
||||
}
|
||||
|
||||
@@ -250,7 +257,7 @@ func (c *AttachmentClient) DeleteOne(a *Attachment) *AttachmentDeleteOne {
|
||||
return c.DeleteOneID(a.ID)
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity by its id.
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *AttachmentClient) DeleteOneID(id uuid.UUID) *AttachmentDeleteOne {
|
||||
builder := c.Delete().Where(attachment.ID(id))
|
||||
builder.mutation.id = &id
|
||||
@@ -282,7 +289,7 @@ func (c *AttachmentClient) GetX(ctx context.Context, id uuid.UUID) *Attachment {
|
||||
// QueryItem queries the item edge of a Attachment.
|
||||
func (c *AttachmentClient) QueryItem(a *Attachment) *ItemQuery {
|
||||
query := &ItemQuery{config: c.config}
|
||||
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := a.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(attachment.Table, attachment.FieldID, id),
|
||||
@@ -298,7 +305,7 @@ func (c *AttachmentClient) QueryItem(a *Attachment) *ItemQuery {
|
||||
// QueryDocument queries the document edge of a Attachment.
|
||||
func (c *AttachmentClient) QueryDocument(a *Attachment) *DocumentQuery {
|
||||
query := &DocumentQuery{config: c.config}
|
||||
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := a.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(attachment.Table, attachment.FieldID, id),
|
||||
@@ -316,6 +323,112 @@ func (c *AttachmentClient) Hooks() []Hook {
|
||||
return c.hooks.Attachment
|
||||
}
|
||||
|
||||
// AuthRolesClient is a client for the AuthRoles schema.
|
||||
type AuthRolesClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewAuthRolesClient returns a client for the AuthRoles from the given config.
|
||||
func NewAuthRolesClient(c config) *AuthRolesClient {
|
||||
return &AuthRolesClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `authroles.Hooks(f(g(h())))`.
|
||||
func (c *AuthRolesClient) Use(hooks ...Hook) {
|
||||
c.hooks.AuthRoles = append(c.hooks.AuthRoles, hooks...)
|
||||
}
|
||||
|
||||
// Create returns a builder for creating a AuthRoles entity.
|
||||
func (c *AuthRolesClient) Create() *AuthRolesCreate {
|
||||
mutation := newAuthRolesMutation(c.config, OpCreate)
|
||||
return &AuthRolesCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// CreateBulk returns a builder for creating a bulk of AuthRoles entities.
|
||||
func (c *AuthRolesClient) CreateBulk(builders ...*AuthRolesCreate) *AuthRolesCreateBulk {
|
||||
return &AuthRolesCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for AuthRoles.
|
||||
func (c *AuthRolesClient) Update() *AuthRolesUpdate {
|
||||
mutation := newAuthRolesMutation(c.config, OpUpdate)
|
||||
return &AuthRolesUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *AuthRolesClient) UpdateOne(ar *AuthRoles) *AuthRolesUpdateOne {
|
||||
mutation := newAuthRolesMutation(c.config, OpUpdateOne, withAuthRoles(ar))
|
||||
return &AuthRolesUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *AuthRolesClient) UpdateOneID(id int) *AuthRolesUpdateOne {
|
||||
mutation := newAuthRolesMutation(c.config, OpUpdateOne, withAuthRolesID(id))
|
||||
return &AuthRolesUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for AuthRoles.
|
||||
func (c *AuthRolesClient) Delete() *AuthRolesDelete {
|
||||
mutation := newAuthRolesMutation(c.config, OpDelete)
|
||||
return &AuthRolesDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *AuthRolesClient) DeleteOne(ar *AuthRoles) *AuthRolesDeleteOne {
|
||||
return c.DeleteOneID(ar.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *AuthRolesClient) DeleteOneID(id int) *AuthRolesDeleteOne {
|
||||
builder := c.Delete().Where(authroles.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &AuthRolesDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for AuthRoles.
|
||||
func (c *AuthRolesClient) Query() *AuthRolesQuery {
|
||||
return &AuthRolesQuery{
|
||||
config: c.config,
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns a AuthRoles entity by its id.
|
||||
func (c *AuthRolesClient) Get(ctx context.Context, id int) (*AuthRoles, error) {
|
||||
return c.Query().Where(authroles.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *AuthRolesClient) GetX(ctx context.Context, id int) *AuthRoles {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// QueryToken queries the token edge of a AuthRoles.
|
||||
func (c *AuthRolesClient) QueryToken(ar *AuthRoles) *AuthTokensQuery {
|
||||
query := &AuthTokensQuery{config: c.config}
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := ar.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(authroles.Table, authroles.FieldID, id),
|
||||
sqlgraph.To(authtokens.Table, authtokens.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, true, authroles.TokenTable, authroles.TokenColumn),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(ar.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *AuthRolesClient) Hooks() []Hook {
|
||||
return c.hooks.AuthRoles
|
||||
}
|
||||
|
||||
// AuthTokensClient is a client for the AuthTokens schema.
|
||||
type AuthTokensClient struct {
|
||||
config
|
||||
@@ -372,7 +485,7 @@ func (c *AuthTokensClient) DeleteOne(at *AuthTokens) *AuthTokensDeleteOne {
|
||||
return c.DeleteOneID(at.ID)
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity by its id.
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *AuthTokensClient) DeleteOneID(id uuid.UUID) *AuthTokensDeleteOne {
|
||||
builder := c.Delete().Where(authtokens.ID(id))
|
||||
builder.mutation.id = &id
|
||||
@@ -404,7 +517,7 @@ func (c *AuthTokensClient) GetX(ctx context.Context, id uuid.UUID) *AuthTokens {
|
||||
// QueryUser queries the user edge of a AuthTokens.
|
||||
func (c *AuthTokensClient) QueryUser(at *AuthTokens) *UserQuery {
|
||||
query := &UserQuery{config: c.config}
|
||||
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := at.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(authtokens.Table, authtokens.FieldID, id),
|
||||
@@ -417,6 +530,22 @@ func (c *AuthTokensClient) QueryUser(at *AuthTokens) *UserQuery {
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryRoles queries the roles edge of a AuthTokens.
|
||||
func (c *AuthTokensClient) QueryRoles(at *AuthTokens) *AuthRolesQuery {
|
||||
query := &AuthRolesQuery{config: c.config}
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := at.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(authtokens.Table, authtokens.FieldID, id),
|
||||
sqlgraph.To(authroles.Table, authroles.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, false, authtokens.RolesTable, authtokens.RolesColumn),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(at.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *AuthTokensClient) Hooks() []Hook {
|
||||
return c.hooks.AuthTokens
|
||||
@@ -478,7 +607,7 @@ func (c *DocumentClient) DeleteOne(d *Document) *DocumentDeleteOne {
|
||||
return c.DeleteOneID(d.ID)
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity by its id.
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *DocumentClient) DeleteOneID(id uuid.UUID) *DocumentDeleteOne {
|
||||
builder := c.Delete().Where(document.ID(id))
|
||||
builder.mutation.id = &id
|
||||
@@ -510,7 +639,7 @@ func (c *DocumentClient) GetX(ctx context.Context, id uuid.UUID) *Document {
|
||||
// QueryGroup queries the group edge of a Document.
|
||||
func (c *DocumentClient) QueryGroup(d *Document) *GroupQuery {
|
||||
query := &GroupQuery{config: c.config}
|
||||
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := d.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(document.Table, document.FieldID, id),
|
||||
@@ -523,26 +652,10 @@ func (c *DocumentClient) QueryGroup(d *Document) *GroupQuery {
|
||||
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(ctx 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.
|
||||
func (c *DocumentClient) QueryAttachments(d *Document) *AttachmentQuery {
|
||||
query := &AttachmentQuery{config: c.config}
|
||||
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := d.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(document.Table, document.FieldID, id),
|
||||
@@ -560,112 +673,6 @@ func (c *DocumentClient) Hooks() []Hook {
|
||||
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)
|
||||
}
|
||||
|
||||
// DeleteOne 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(ctx 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.
|
||||
type GroupClient struct {
|
||||
config
|
||||
@@ -722,7 +729,7 @@ func (c *GroupClient) DeleteOne(gr *Group) *GroupDeleteOne {
|
||||
return c.DeleteOneID(gr.ID)
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity by its id.
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *GroupClient) DeleteOneID(id uuid.UUID) *GroupDeleteOne {
|
||||
builder := c.Delete().Where(group.ID(id))
|
||||
builder.mutation.id = &id
|
||||
@@ -754,7 +761,7 @@ func (c *GroupClient) GetX(ctx context.Context, id uuid.UUID) *Group {
|
||||
// QueryUsers queries the users edge of a Group.
|
||||
func (c *GroupClient) QueryUsers(gr *Group) *UserQuery {
|
||||
query := &UserQuery{config: c.config}
|
||||
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := gr.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(group.Table, group.FieldID, id),
|
||||
@@ -770,7 +777,7 @@ func (c *GroupClient) QueryUsers(gr *Group) *UserQuery {
|
||||
// QueryLocations queries the locations edge of a Group.
|
||||
func (c *GroupClient) QueryLocations(gr *Group) *LocationQuery {
|
||||
query := &LocationQuery{config: c.config}
|
||||
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := gr.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(group.Table, group.FieldID, id),
|
||||
@@ -786,7 +793,7 @@ func (c *GroupClient) QueryLocations(gr *Group) *LocationQuery {
|
||||
// QueryItems queries the items edge of a Group.
|
||||
func (c *GroupClient) QueryItems(gr *Group) *ItemQuery {
|
||||
query := &ItemQuery{config: c.config}
|
||||
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := gr.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(group.Table, group.FieldID, id),
|
||||
@@ -802,7 +809,7 @@ func (c *GroupClient) QueryItems(gr *Group) *ItemQuery {
|
||||
// QueryLabels queries the labels edge of a Group.
|
||||
func (c *GroupClient) QueryLabels(gr *Group) *LabelQuery {
|
||||
query := &LabelQuery{config: c.config}
|
||||
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := gr.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(group.Table, group.FieldID, id),
|
||||
@@ -818,7 +825,7 @@ func (c *GroupClient) QueryLabels(gr *Group) *LabelQuery {
|
||||
// QueryDocuments queries the documents edge of a Group.
|
||||
func (c *GroupClient) QueryDocuments(gr *Group) *DocumentQuery {
|
||||
query := &DocumentQuery{config: c.config}
|
||||
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := gr.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(group.Table, group.FieldID, id),
|
||||
@@ -834,7 +841,7 @@ func (c *GroupClient) QueryDocuments(gr *Group) *DocumentQuery {
|
||||
// QueryInvitationTokens queries the invitation_tokens edge of a Group.
|
||||
func (c *GroupClient) QueryInvitationTokens(gr *Group) *GroupInvitationTokenQuery {
|
||||
query := &GroupInvitationTokenQuery{config: c.config}
|
||||
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := gr.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(group.Table, group.FieldID, id),
|
||||
@@ -908,7 +915,7 @@ func (c *GroupInvitationTokenClient) DeleteOne(git *GroupInvitationToken) *Group
|
||||
return c.DeleteOneID(git.ID)
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity by its id.
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *GroupInvitationTokenClient) DeleteOneID(id uuid.UUID) *GroupInvitationTokenDeleteOne {
|
||||
builder := c.Delete().Where(groupinvitationtoken.ID(id))
|
||||
builder.mutation.id = &id
|
||||
@@ -940,7 +947,7 @@ func (c *GroupInvitationTokenClient) GetX(ctx context.Context, id uuid.UUID) *Gr
|
||||
// QueryGroup queries the group edge of a GroupInvitationToken.
|
||||
func (c *GroupInvitationTokenClient) QueryGroup(git *GroupInvitationToken) *GroupQuery {
|
||||
query := &GroupQuery{config: c.config}
|
||||
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := git.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(groupinvitationtoken.Table, groupinvitationtoken.FieldID, id),
|
||||
@@ -1014,7 +1021,7 @@ func (c *ItemClient) DeleteOne(i *Item) *ItemDeleteOne {
|
||||
return c.DeleteOneID(i.ID)
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity by its id.
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *ItemClient) DeleteOneID(id uuid.UUID) *ItemDeleteOne {
|
||||
builder := c.Delete().Where(item.ID(id))
|
||||
builder.mutation.id = &id
|
||||
@@ -1046,7 +1053,7 @@ func (c *ItemClient) GetX(ctx context.Context, id uuid.UUID) *Item {
|
||||
// QueryParent queries the parent edge of a Item.
|
||||
func (c *ItemClient) QueryParent(i *Item) *ItemQuery {
|
||||
query := &ItemQuery{config: c.config}
|
||||
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := i.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(item.Table, item.FieldID, id),
|
||||
@@ -1062,7 +1069,7 @@ func (c *ItemClient) QueryParent(i *Item) *ItemQuery {
|
||||
// QueryChildren queries the children edge of a Item.
|
||||
func (c *ItemClient) QueryChildren(i *Item) *ItemQuery {
|
||||
query := &ItemQuery{config: c.config}
|
||||
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := i.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(item.Table, item.FieldID, id),
|
||||
@@ -1078,7 +1085,7 @@ func (c *ItemClient) QueryChildren(i *Item) *ItemQuery {
|
||||
// QueryGroup queries the group edge of a Item.
|
||||
func (c *ItemClient) QueryGroup(i *Item) *GroupQuery {
|
||||
query := &GroupQuery{config: c.config}
|
||||
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := i.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(item.Table, item.FieldID, id),
|
||||
@@ -1094,7 +1101,7 @@ func (c *ItemClient) QueryGroup(i *Item) *GroupQuery {
|
||||
// QueryLabel queries the label edge of a Item.
|
||||
func (c *ItemClient) QueryLabel(i *Item) *LabelQuery {
|
||||
query := &LabelQuery{config: c.config}
|
||||
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := i.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(item.Table, item.FieldID, id),
|
||||
@@ -1110,7 +1117,7 @@ func (c *ItemClient) QueryLabel(i *Item) *LabelQuery {
|
||||
// QueryLocation queries the location edge of a Item.
|
||||
func (c *ItemClient) QueryLocation(i *Item) *LocationQuery {
|
||||
query := &LocationQuery{config: c.config}
|
||||
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := i.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(item.Table, item.FieldID, id),
|
||||
@@ -1126,7 +1133,7 @@ func (c *ItemClient) QueryLocation(i *Item) *LocationQuery {
|
||||
// QueryFields queries the fields edge of a Item.
|
||||
func (c *ItemClient) QueryFields(i *Item) *ItemFieldQuery {
|
||||
query := &ItemFieldQuery{config: c.config}
|
||||
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := i.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(item.Table, item.FieldID, id),
|
||||
@@ -1139,10 +1146,26 @@ func (c *ItemClient) QueryFields(i *Item) *ItemFieldQuery {
|
||||
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.
|
||||
func (c *ItemClient) QueryAttachments(i *Item) *AttachmentQuery {
|
||||
query := &AttachmentQuery{config: c.config}
|
||||
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := i.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(item.Table, item.FieldID, id),
|
||||
@@ -1216,7 +1239,7 @@ func (c *ItemFieldClient) DeleteOne(_if *ItemField) *ItemFieldDeleteOne {
|
||||
return c.DeleteOneID(_if.ID)
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity by its id.
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *ItemFieldClient) DeleteOneID(id uuid.UUID) *ItemFieldDeleteOne {
|
||||
builder := c.Delete().Where(itemfield.ID(id))
|
||||
builder.mutation.id = &id
|
||||
@@ -1248,7 +1271,7 @@ func (c *ItemFieldClient) GetX(ctx context.Context, id uuid.UUID) *ItemField {
|
||||
// QueryItem queries the item edge of a ItemField.
|
||||
func (c *ItemFieldClient) QueryItem(_if *ItemField) *ItemQuery {
|
||||
query := &ItemQuery{config: c.config}
|
||||
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := _if.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(itemfield.Table, itemfield.FieldID, id),
|
||||
@@ -1322,7 +1345,7 @@ func (c *LabelClient) DeleteOne(l *Label) *LabelDeleteOne {
|
||||
return c.DeleteOneID(l.ID)
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity by its id.
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *LabelClient) DeleteOneID(id uuid.UUID) *LabelDeleteOne {
|
||||
builder := c.Delete().Where(label.ID(id))
|
||||
builder.mutation.id = &id
|
||||
@@ -1354,7 +1377,7 @@ func (c *LabelClient) GetX(ctx context.Context, id uuid.UUID) *Label {
|
||||
// QueryGroup queries the group edge of a Label.
|
||||
func (c *LabelClient) QueryGroup(l *Label) *GroupQuery {
|
||||
query := &GroupQuery{config: c.config}
|
||||
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := l.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(label.Table, label.FieldID, id),
|
||||
@@ -1370,7 +1393,7 @@ func (c *LabelClient) QueryGroup(l *Label) *GroupQuery {
|
||||
// QueryItems queries the items edge of a Label.
|
||||
func (c *LabelClient) QueryItems(l *Label) *ItemQuery {
|
||||
query := &ItemQuery{config: c.config}
|
||||
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := l.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(label.Table, label.FieldID, id),
|
||||
@@ -1444,7 +1467,7 @@ func (c *LocationClient) DeleteOne(l *Location) *LocationDeleteOne {
|
||||
return c.DeleteOneID(l.ID)
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity by its id.
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *LocationClient) DeleteOneID(id uuid.UUID) *LocationDeleteOne {
|
||||
builder := c.Delete().Where(location.ID(id))
|
||||
builder.mutation.id = &id
|
||||
@@ -1476,7 +1499,7 @@ func (c *LocationClient) GetX(ctx context.Context, id uuid.UUID) *Location {
|
||||
// QueryParent queries the parent edge of a Location.
|
||||
func (c *LocationClient) QueryParent(l *Location) *LocationQuery {
|
||||
query := &LocationQuery{config: c.config}
|
||||
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := l.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(location.Table, location.FieldID, id),
|
||||
@@ -1492,7 +1515,7 @@ func (c *LocationClient) QueryParent(l *Location) *LocationQuery {
|
||||
// QueryChildren queries the children edge of a Location.
|
||||
func (c *LocationClient) QueryChildren(l *Location) *LocationQuery {
|
||||
query := &LocationQuery{config: c.config}
|
||||
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := l.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(location.Table, location.FieldID, id),
|
||||
@@ -1508,7 +1531,7 @@ func (c *LocationClient) QueryChildren(l *Location) *LocationQuery {
|
||||
// QueryGroup queries the group edge of a Location.
|
||||
func (c *LocationClient) QueryGroup(l *Location) *GroupQuery {
|
||||
query := &GroupQuery{config: c.config}
|
||||
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := l.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(location.Table, location.FieldID, id),
|
||||
@@ -1524,7 +1547,7 @@ func (c *LocationClient) QueryGroup(l *Location) *GroupQuery {
|
||||
// QueryItems queries the items edge of a Location.
|
||||
func (c *LocationClient) QueryItems(l *Location) *ItemQuery {
|
||||
query := &ItemQuery{config: c.config}
|
||||
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := l.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(location.Table, location.FieldID, id),
|
||||
@@ -1542,6 +1565,112 @@ func (c *LocationClient) Hooks() []Hook {
|
||||
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.
|
||||
type UserClient struct {
|
||||
config
|
||||
@@ -1598,7 +1727,7 @@ func (c *UserClient) DeleteOne(u *User) *UserDeleteOne {
|
||||
return c.DeleteOneID(u.ID)
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity by its id.
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *UserClient) DeleteOneID(id uuid.UUID) *UserDeleteOne {
|
||||
builder := c.Delete().Where(user.ID(id))
|
||||
builder.mutation.id = &id
|
||||
@@ -1630,7 +1759,7 @@ func (c *UserClient) GetX(ctx context.Context, id uuid.UUID) *User {
|
||||
// QueryGroup queries the group edge of a User.
|
||||
func (c *UserClient) QueryGroup(u *User) *GroupQuery {
|
||||
query := &GroupQuery{config: c.config}
|
||||
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := u.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, id),
|
||||
@@ -1646,7 +1775,7 @@ func (c *UserClient) QueryGroup(u *User) *GroupQuery {
|
||||
// QueryAuthTokens queries the auth_tokens edge of a User.
|
||||
func (c *UserClient) QueryAuthTokens(u *User) *AuthTokensQuery {
|
||||
query := &AuthTokensQuery{config: c.config}
|
||||
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := u.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, id),
|
||||
|
||||
@@ -25,15 +25,16 @@ type config struct {
|
||||
// hooks per client, for fast access.
|
||||
type hooks struct {
|
||||
Attachment []ent.Hook
|
||||
AuthRoles []ent.Hook
|
||||
AuthTokens []ent.Hook
|
||||
Document []ent.Hook
|
||||
DocumentToken []ent.Hook
|
||||
Group []ent.Hook
|
||||
GroupInvitationToken []ent.Hook
|
||||
Item []ent.Hook
|
||||
ItemField []ent.Hook
|
||||
Label []ent.Hook
|
||||
Location []ent.Hook
|
||||
MaintenanceEntry []ent.Hook
|
||||
User []ent.Hook
|
||||
}
|
||||
|
||||
|
||||
@@ -36,13 +36,11 @@ type Document struct {
|
||||
type DocumentEdges struct {
|
||||
// Group holds the value of the group edge.
|
||||
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 []*Attachment `json:"attachments,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// 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
|
||||
@@ -58,19 +56,10 @@ func (e DocumentEdges) GroupOrErr() (*Group, error) {
|
||||
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
|
||||
// was not loaded in eager-loading.
|
||||
func (e DocumentEdges) AttachmentsOrErr() ([]*Attachment, error) {
|
||||
if e.loadedTypes[2] {
|
||||
if e.loadedTypes[1] {
|
||||
return e.Attachments, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "attachments"}
|
||||
@@ -151,11 +140,6 @@ func (d *Document) QueryGroup() *GroupQuery {
|
||||
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.
|
||||
func (d *Document) QueryAttachments() *AttachmentQuery {
|
||||
return (&DocumentClient{config: d.config}).QueryAttachments(d)
|
||||
|
||||
@@ -23,8 +23,6 @@ const (
|
||||
FieldPath = "path"
|
||||
// EdgeGroup holds the string denoting the group edge name in mutations.
|
||||
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 = "attachments"
|
||||
// Table holds the table name of the document in the database.
|
||||
@@ -36,13 +34,6 @@ const (
|
||||
GroupInverseTable = "groups"
|
||||
// GroupColumn is the table column denoting the group relation/edge.
|
||||
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 = "attachments"
|
||||
// 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.
|
||||
func HasAttachments() predicate.Document {
|
||||
return predicate.Document(func(s *sql.Selector) {
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
"github.com/google/uuid"
|
||||
"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/documenttoken"
|
||||
"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)
|
||||
}
|
||||
|
||||
// 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.
|
||||
func (dc *DocumentCreate) AddAttachmentIDs(ids ...uuid.UUID) *DocumentCreate {
|
||||
dc.mutation.AddAttachmentIDs(ids...)
|
||||
@@ -274,35 +258,19 @@ func (dc *DocumentCreate) createSpec() (*Document, *sqlgraph.CreateSpec) {
|
||||
_spec.ID.Value = &id
|
||||
}
|
||||
if value, ok := dc.mutation.CreatedAt(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: document.FieldCreatedAt,
|
||||
})
|
||||
_spec.SetField(document.FieldCreatedAt, field.TypeTime, value)
|
||||
_node.CreatedAt = value
|
||||
}
|
||||
if value, ok := dc.mutation.UpdatedAt(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: document.FieldUpdatedAt,
|
||||
})
|
||||
_spec.SetField(document.FieldUpdatedAt, field.TypeTime, value)
|
||||
_node.UpdatedAt = value
|
||||
}
|
||||
if value, ok := dc.mutation.Title(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: document.FieldTitle,
|
||||
})
|
||||
_spec.SetField(document.FieldTitle, field.TypeString, value)
|
||||
_node.Title = value
|
||||
}
|
||||
if value, ok := dc.mutation.Path(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: document.FieldPath,
|
||||
})
|
||||
_spec.SetField(document.FieldPath, field.TypeString, value)
|
||||
_node.Path = value
|
||||
}
|
||||
if nodes := dc.mutation.GroupIDs(); len(nodes) > 0 {
|
||||
@@ -325,25 +293,6 @@ func (dc *DocumentCreate) createSpec() (*Document, *sqlgraph.CreateSpec) {
|
||||
_node.group_documents = &nodes[0]
|
||||
_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 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
"github.com/google/uuid"
|
||||
"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/documenttoken"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/group"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/predicate"
|
||||
)
|
||||
@@ -22,16 +21,15 @@ import (
|
||||
// DocumentQuery is the builder for querying Document entities.
|
||||
type DocumentQuery struct {
|
||||
config
|
||||
limit *int
|
||||
offset *int
|
||||
unique *bool
|
||||
order []OrderFunc
|
||||
fields []string
|
||||
predicates []predicate.Document
|
||||
withGroup *GroupQuery
|
||||
withDocumentTokens *DocumentTokenQuery
|
||||
withAttachments *AttachmentQuery
|
||||
withFKs bool
|
||||
limit *int
|
||||
offset *int
|
||||
unique *bool
|
||||
order []OrderFunc
|
||||
fields []string
|
||||
predicates []predicate.Document
|
||||
withGroup *GroupQuery
|
||||
withAttachments *AttachmentQuery
|
||||
withFKs bool
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
@@ -90,28 +88,6 @@ func (dq *DocumentQuery) QueryGroup() *GroupQuery {
|
||||
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.
|
||||
func (dq *DocumentQuery) QueryAttachments() *AttachmentQuery {
|
||||
query := &AttachmentQuery{config: dq.config}
|
||||
@@ -310,14 +286,13 @@ func (dq *DocumentQuery) Clone() *DocumentQuery {
|
||||
return nil
|
||||
}
|
||||
return &DocumentQuery{
|
||||
config: dq.config,
|
||||
limit: dq.limit,
|
||||
offset: dq.offset,
|
||||
order: append([]OrderFunc{}, dq.order...),
|
||||
predicates: append([]predicate.Document{}, dq.predicates...),
|
||||
withGroup: dq.withGroup.Clone(),
|
||||
withDocumentTokens: dq.withDocumentTokens.Clone(),
|
||||
withAttachments: dq.withAttachments.Clone(),
|
||||
config: dq.config,
|
||||
limit: dq.limit,
|
||||
offset: dq.offset,
|
||||
order: append([]OrderFunc{}, dq.order...),
|
||||
predicates: append([]predicate.Document{}, dq.predicates...),
|
||||
withGroup: dq.withGroup.Clone(),
|
||||
withAttachments: dq.withAttachments.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: dq.sql.Clone(),
|
||||
path: dq.path,
|
||||
@@ -336,17 +311,6 @@ func (dq *DocumentQuery) WithGroup(opts ...func(*GroupQuery)) *DocumentQuery {
|
||||
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
|
||||
// the "attachments" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (dq *DocumentQuery) WithAttachments(opts ...func(*AttachmentQuery)) *DocumentQuery {
|
||||
@@ -406,6 +370,11 @@ func (dq *DocumentQuery) Select(fields ...string) *DocumentSelect {
|
||||
return selbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a DocumentSelect configured with the given aggregations.
|
||||
func (dq *DocumentQuery) Aggregate(fns ...AggregateFunc) *DocumentSelect {
|
||||
return dq.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (dq *DocumentQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, f := range dq.fields {
|
||||
if !document.ValidColumn(f) {
|
||||
@@ -427,9 +396,8 @@ func (dq *DocumentQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Doc
|
||||
nodes = []*Document{}
|
||||
withFKs = dq.withFKs
|
||||
_spec = dq.querySpec()
|
||||
loadedTypes = [3]bool{
|
||||
loadedTypes = [2]bool{
|
||||
dq.withGroup != nil,
|
||||
dq.withDocumentTokens != nil,
|
||||
dq.withAttachments != nil,
|
||||
}
|
||||
)
|
||||
@@ -463,13 +431,6 @@ func (dq *DocumentQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Doc
|
||||
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 err := dq.loadAttachments(ctx, query, nodes,
|
||||
func(n *Document) { n.Edges.Attachments = []*Attachment{} },
|
||||
@@ -509,37 +470,6 @@ func (dq *DocumentQuery) loadGroup(ctx context.Context, query *GroupQuery, nodes
|
||||
}
|
||||
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 {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
nodeids := make(map[uuid.UUID]*Document)
|
||||
@@ -724,8 +654,6 @@ func (dgb *DocumentGroupBy) sqlQuery() *sql.Selector {
|
||||
for _, fn := range dgb.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
// If no columns were selected in a custom aggregation function, the default
|
||||
// selection is the fields used for "group-by", and the aggregation functions.
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(dgb.fields)+len(dgb.fns))
|
||||
for _, f := range dgb.fields {
|
||||
@@ -745,6 +673,12 @@ type DocumentSelect struct {
|
||||
sql *sql.Selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (ds *DocumentSelect) Aggregate(fns ...AggregateFunc) *DocumentSelect {
|
||||
ds.fns = append(ds.fns, fns...)
|
||||
return ds
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (ds *DocumentSelect) Scan(ctx context.Context, v any) error {
|
||||
if err := ds.prepareQuery(ctx); err != nil {
|
||||
@@ -755,6 +689,16 @@ func (ds *DocumentSelect) Scan(ctx context.Context, v any) error {
|
||||
}
|
||||
|
||||
func (ds *DocumentSelect) sqlScan(ctx context.Context, v any) error {
|
||||
aggregation := make([]string, 0, len(ds.fns))
|
||||
for _, fn := range ds.fns {
|
||||
aggregation = append(aggregation, fn(ds.sql))
|
||||
}
|
||||
switch n := len(*ds.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
ds.sql.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
ds.sql.AppendSelect(aggregation...)
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := ds.sql.Query()
|
||||
if err := ds.driver.Query(ctx, query, args, rows); err != nil {
|
||||
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
"github.com/google/uuid"
|
||||
"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/documenttoken"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/group"
|
||||
"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)
|
||||
}
|
||||
|
||||
// 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.
|
||||
func (du *DocumentUpdate) AddAttachmentIDs(ids ...uuid.UUID) *DocumentUpdate {
|
||||
du.mutation.AddAttachmentIDs(ids...)
|
||||
@@ -102,27 +86,6 @@ func (du *DocumentUpdate) ClearGroup() *DocumentUpdate {
|
||||
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.
|
||||
func (du *DocumentUpdate) ClearAttachments() *DocumentUpdate {
|
||||
du.mutation.ClearAttachments()
|
||||
@@ -250,25 +213,13 @@ func (du *DocumentUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
}
|
||||
}
|
||||
if value, ok := du.mutation.UpdatedAt(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: document.FieldUpdatedAt,
|
||||
})
|
||||
_spec.SetField(document.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := du.mutation.Title(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: document.FieldTitle,
|
||||
})
|
||||
_spec.SetField(document.FieldTitle, field.TypeString, value)
|
||||
}
|
||||
if value, ok := du.mutation.Path(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: document.FieldPath,
|
||||
})
|
||||
_spec.SetField(document.FieldPath, field.TypeString, value)
|
||||
}
|
||||
if du.mutation.GroupCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
@@ -305,60 +256,6 @@ func (du *DocumentUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
}
|
||||
_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() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
@@ -461,21 +358,6 @@ func (duo *DocumentUpdateOne) SetGroup(g *Group) *DocumentUpdateOne {
|
||||
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.
|
||||
func (duo *DocumentUpdateOne) AddAttachmentIDs(ids ...uuid.UUID) *DocumentUpdateOne {
|
||||
duo.mutation.AddAttachmentIDs(ids...)
|
||||
@@ -502,27 +384,6 @@ func (duo *DocumentUpdateOne) ClearGroup() *DocumentUpdateOne {
|
||||
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.
|
||||
func (duo *DocumentUpdateOne) ClearAttachments() *DocumentUpdateOne {
|
||||
duo.mutation.ClearAttachments()
|
||||
@@ -680,25 +541,13 @@ func (duo *DocumentUpdateOne) sqlSave(ctx context.Context) (_node *Document, err
|
||||
}
|
||||
}
|
||||
if value, ok := duo.mutation.UpdatedAt(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: document.FieldUpdatedAt,
|
||||
})
|
||||
_spec.SetField(document.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := duo.mutation.Title(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: document.FieldTitle,
|
||||
})
|
||||
_spec.SetField(document.FieldTitle, field.TypeString, value)
|
||||
}
|
||||
if value, ok := duo.mutation.Path(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: document.FieldPath,
|
||||
})
|
||||
_spec.SetField(document.FieldPath, field.TypeString, value)
|
||||
}
|
||||
if duo.mutation.GroupCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
@@ -735,60 +584,6 @@ func (duo *DocumentUpdateOne) sqlSave(ctx context.Context) (_node *Document, err
|
||||
}
|
||||
_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() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
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,418 +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.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: documenttoken.FieldCreatedAt,
|
||||
})
|
||||
_node.CreatedAt = value
|
||||
}
|
||||
if value, ok := dtc.mutation.UpdatedAt(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: documenttoken.FieldUpdatedAt,
|
||||
})
|
||||
_node.UpdatedAt = value
|
||||
}
|
||||
if value, ok := dtc.mutation.Token(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeBytes,
|
||||
Value: value,
|
||||
Column: documenttoken.FieldToken,
|
||||
})
|
||||
_node.Token = value
|
||||
}
|
||||
if value, ok := dtc.mutation.Uses(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: value,
|
||||
Column: documenttoken.FieldUses,
|
||||
})
|
||||
_node.Uses = value
|
||||
}
|
||||
if value, ok := dtc.mutation.ExpiresAt(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: documenttoken.FieldExpiresAt,
|
||||
})
|
||||
_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,614 +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
|
||||
}
|
||||
|
||||
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 no columns were selected in a custom aggregation function, the default
|
||||
// selection is the fields used for "group-by", and the aggregation functions.
|
||||
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
|
||||
}
|
||||
|
||||
// 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 {
|
||||
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,582 +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.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: documenttoken.FieldUpdatedAt,
|
||||
})
|
||||
}
|
||||
if value, ok := dtu.mutation.Token(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeBytes,
|
||||
Value: value,
|
||||
Column: documenttoken.FieldToken,
|
||||
})
|
||||
}
|
||||
if value, ok := dtu.mutation.Uses(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: value,
|
||||
Column: documenttoken.FieldUses,
|
||||
})
|
||||
}
|
||||
if value, ok := dtu.mutation.AddedUses(); ok {
|
||||
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: value,
|
||||
Column: documenttoken.FieldUses,
|
||||
})
|
||||
}
|
||||
if value, ok := dtu.mutation.ExpiresAt(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: documenttoken.FieldExpiresAt,
|
||||
})
|
||||
}
|
||||
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.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: documenttoken.FieldUpdatedAt,
|
||||
})
|
||||
}
|
||||
if value, ok := dtuo.mutation.Token(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeBytes,
|
||||
Value: value,
|
||||
Column: documenttoken.FieldToken,
|
||||
})
|
||||
}
|
||||
if value, ok := dtuo.mutation.Uses(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: value,
|
||||
Column: documenttoken.FieldUses,
|
||||
})
|
||||
}
|
||||
if value, ok := dtuo.mutation.AddedUses(); ok {
|
||||
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: value,
|
||||
Column: documenttoken.FieldUses,
|
||||
})
|
||||
}
|
||||
if value, ok := dtuo.mutation.ExpiresAt(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: documenttoken.FieldExpiresAt,
|
||||
})
|
||||
}
|
||||
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
|
||||
}
|
||||
@@ -11,15 +11,16 @@ import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/attachment"
|
||||
"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/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/groupinvitationtoken"
|
||||
"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/label"
|
||||
"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"
|
||||
)
|
||||
|
||||
@@ -42,15 +43,16 @@ type OrderFunc func(*sql.Selector)
|
||||
func columnChecker(table string) func(string) error {
|
||||
checks := map[string]func(string) bool{
|
||||
attachment.Table: attachment.ValidColumn,
|
||||
authroles.Table: authroles.ValidColumn,
|
||||
authtokens.Table: authtokens.ValidColumn,
|
||||
document.Table: document.ValidColumn,
|
||||
documenttoken.Table: documenttoken.ValidColumn,
|
||||
group.Table: group.ValidColumn,
|
||||
groupinvitationtoken.Table: groupinvitationtoken.ValidColumn,
|
||||
item.Table: item.ValidColumn,
|
||||
itemfield.Table: itemfield.ValidColumn,
|
||||
label.Table: label.ValidColumn,
|
||||
location.Table: location.ValidColumn,
|
||||
maintenanceentry.Table: maintenanceentry.ValidColumn,
|
||||
user.Table: user.ValidColumn,
|
||||
}
|
||||
check, ok := checks[table]
|
||||
@@ -283,6 +285,7 @@ func IsConstraintError(err error) bool {
|
||||
type selector struct {
|
||||
label string
|
||||
flds *[]string
|
||||
fns []AggregateFunc
|
||||
scan func(context.Context, any) error
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
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
|
||||
|
||||
@@ -129,6 +129,8 @@ const (
|
||||
CurrencyNok Currency = "nok"
|
||||
CurrencySek Currency = "sek"
|
||||
CurrencyDkk Currency = "dkk"
|
||||
CurrencyInr Currency = "inr"
|
||||
CurrencyRmb Currency = "rmb"
|
||||
)
|
||||
|
||||
func (c Currency) String() string {
|
||||
@@ -138,7 +140,7 @@ func (c Currency) String() string {
|
||||
// CurrencyValidator is a validator for the "currency" field enum values. It is called by the builders before save.
|
||||
func CurrencyValidator(c Currency) error {
|
||||
switch c {
|
||||
case CurrencyUsd, CurrencyEur, CurrencyGbp, CurrencyJpy, CurrencyZar, CurrencyAud, CurrencyNok, CurrencySek, CurrencyDkk:
|
||||
case CurrencyUsd, CurrencyEur, CurrencyGbp, CurrencyJpy, CurrencyZar, CurrencyAud, CurrencyNok, CurrencySek, CurrencyDkk, CurrencyInr, CurrencyRmb:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("group: invalid enum value for currency field: %q", c)
|
||||
|
||||
@@ -335,35 +335,19 @@ func (gc *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) {
|
||||
_spec.ID.Value = &id
|
||||
}
|
||||
if value, ok := gc.mutation.CreatedAt(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: group.FieldCreatedAt,
|
||||
})
|
||||
_spec.SetField(group.FieldCreatedAt, field.TypeTime, value)
|
||||
_node.CreatedAt = value
|
||||
}
|
||||
if value, ok := gc.mutation.UpdatedAt(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: group.FieldUpdatedAt,
|
||||
})
|
||||
_spec.SetField(group.FieldUpdatedAt, field.TypeTime, value)
|
||||
_node.UpdatedAt = value
|
||||
}
|
||||
if value, ok := gc.mutation.Name(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: group.FieldName,
|
||||
})
|
||||
_spec.SetField(group.FieldName, field.TypeString, value)
|
||||
_node.Name = value
|
||||
}
|
||||
if value, ok := gc.mutation.Currency(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeEnum,
|
||||
Value: value,
|
||||
Column: group.FieldCurrency,
|
||||
})
|
||||
_spec.SetField(group.FieldCurrency, field.TypeEnum, value)
|
||||
_node.Currency = value
|
||||
}
|
||||
if nodes := gc.mutation.UsersIDs(); len(nodes) > 0 {
|
||||
|
||||
@@ -513,6 +513,11 @@ func (gq *GroupQuery) Select(fields ...string) *GroupSelect {
|
||||
return selbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a GroupSelect configured with the given aggregations.
|
||||
func (gq *GroupQuery) Aggregate(fns ...AggregateFunc) *GroupSelect {
|
||||
return gq.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (gq *GroupQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, f := range gq.fields {
|
||||
if !group.ValidColumn(f) {
|
||||
@@ -946,8 +951,6 @@ func (ggb *GroupGroupBy) sqlQuery() *sql.Selector {
|
||||
for _, fn := range ggb.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
// If no columns were selected in a custom aggregation function, the default
|
||||
// selection is the fields used for "group-by", and the aggregation functions.
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(ggb.fields)+len(ggb.fns))
|
||||
for _, f := range ggb.fields {
|
||||
@@ -967,6 +970,12 @@ type GroupSelect struct {
|
||||
sql *sql.Selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (gs *GroupSelect) Aggregate(fns ...AggregateFunc) *GroupSelect {
|
||||
gs.fns = append(gs.fns, fns...)
|
||||
return gs
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (gs *GroupSelect) Scan(ctx context.Context, v any) error {
|
||||
if err := gs.prepareQuery(ctx); err != nil {
|
||||
@@ -977,6 +986,16 @@ func (gs *GroupSelect) Scan(ctx context.Context, v any) error {
|
||||
}
|
||||
|
||||
func (gs *GroupSelect) sqlScan(ctx context.Context, v any) error {
|
||||
aggregation := make([]string, 0, len(gs.fns))
|
||||
for _, fn := range gs.fns {
|
||||
aggregation = append(aggregation, fn(gs.sql))
|
||||
}
|
||||
switch n := len(*gs.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
gs.sql.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
gs.sql.AppendSelect(aggregation...)
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := gs.sql.Query()
|
||||
if err := gs.driver.Query(ctx, query, args, rows); err != nil {
|
||||
|
||||
@@ -385,25 +385,13 @@ func (gu *GroupUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
}
|
||||
}
|
||||
if value, ok := gu.mutation.UpdatedAt(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: group.FieldUpdatedAt,
|
||||
})
|
||||
_spec.SetField(group.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := gu.mutation.Name(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: group.FieldName,
|
||||
})
|
||||
_spec.SetField(group.FieldName, field.TypeString, value)
|
||||
}
|
||||
if value, ok := gu.mutation.Currency(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeEnum,
|
||||
Value: value,
|
||||
Column: group.FieldCurrency,
|
||||
})
|
||||
_spec.SetField(group.FieldCurrency, field.TypeEnum, value)
|
||||
}
|
||||
if gu.mutation.UsersCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
@@ -1128,25 +1116,13 @@ func (guo *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error
|
||||
}
|
||||
}
|
||||
if value, ok := guo.mutation.UpdatedAt(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: group.FieldUpdatedAt,
|
||||
})
|
||||
_spec.SetField(group.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := guo.mutation.Name(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: group.FieldName,
|
||||
})
|
||||
_spec.SetField(group.FieldName, field.TypeString, value)
|
||||
}
|
||||
if value, ok := guo.mutation.Currency(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeEnum,
|
||||
Value: value,
|
||||
Column: group.FieldCurrency,
|
||||
})
|
||||
_spec.SetField(group.FieldCurrency, field.TypeEnum, value)
|
||||
}
|
||||
if guo.mutation.UsersCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
|
||||
@@ -270,43 +270,23 @@ func (gitc *GroupInvitationTokenCreate) createSpec() (*GroupInvitationToken, *sq
|
||||
_spec.ID.Value = &id
|
||||
}
|
||||
if value, ok := gitc.mutation.CreatedAt(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: groupinvitationtoken.FieldCreatedAt,
|
||||
})
|
||||
_spec.SetField(groupinvitationtoken.FieldCreatedAt, field.TypeTime, value)
|
||||
_node.CreatedAt = value
|
||||
}
|
||||
if value, ok := gitc.mutation.UpdatedAt(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: groupinvitationtoken.FieldUpdatedAt,
|
||||
})
|
||||
_spec.SetField(groupinvitationtoken.FieldUpdatedAt, field.TypeTime, value)
|
||||
_node.UpdatedAt = value
|
||||
}
|
||||
if value, ok := gitc.mutation.Token(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeBytes,
|
||||
Value: value,
|
||||
Column: groupinvitationtoken.FieldToken,
|
||||
})
|
||||
_spec.SetField(groupinvitationtoken.FieldToken, field.TypeBytes, value)
|
||||
_node.Token = value
|
||||
}
|
||||
if value, ok := gitc.mutation.ExpiresAt(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: groupinvitationtoken.FieldExpiresAt,
|
||||
})
|
||||
_spec.SetField(groupinvitationtoken.FieldExpiresAt, field.TypeTime, value)
|
||||
_node.ExpiresAt = value
|
||||
}
|
||||
if value, ok := gitc.mutation.Uses(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: value,
|
||||
Column: groupinvitationtoken.FieldUses,
|
||||
})
|
||||
_spec.SetField(groupinvitationtoken.FieldUses, field.TypeInt, value)
|
||||
_node.Uses = value
|
||||
}
|
||||
if nodes := gitc.mutation.GroupIDs(); len(nodes) > 0 {
|
||||
|
||||
@@ -333,6 +333,11 @@ func (gitq *GroupInvitationTokenQuery) Select(fields ...string) *GroupInvitation
|
||||
return selbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a GroupInvitationTokenSelect configured with the given aggregations.
|
||||
func (gitq *GroupInvitationTokenQuery) Aggregate(fns ...AggregateFunc) *GroupInvitationTokenSelect {
|
||||
return gitq.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (gitq *GroupInvitationTokenQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, f := range gitq.fields {
|
||||
if !groupinvitationtoken.ValidColumn(f) {
|
||||
@@ -573,8 +578,6 @@ func (gitgb *GroupInvitationTokenGroupBy) sqlQuery() *sql.Selector {
|
||||
for _, fn := range gitgb.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
// If no columns were selected in a custom aggregation function, the default
|
||||
// selection is the fields used for "group-by", and the aggregation functions.
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(gitgb.fields)+len(gitgb.fns))
|
||||
for _, f := range gitgb.fields {
|
||||
@@ -594,6 +597,12 @@ type GroupInvitationTokenSelect struct {
|
||||
sql *sql.Selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (gits *GroupInvitationTokenSelect) Aggregate(fns ...AggregateFunc) *GroupInvitationTokenSelect {
|
||||
gits.fns = append(gits.fns, fns...)
|
||||
return gits
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (gits *GroupInvitationTokenSelect) Scan(ctx context.Context, v any) error {
|
||||
if err := gits.prepareQuery(ctx); err != nil {
|
||||
@@ -604,6 +613,16 @@ func (gits *GroupInvitationTokenSelect) Scan(ctx context.Context, v any) error {
|
||||
}
|
||||
|
||||
func (gits *GroupInvitationTokenSelect) sqlScan(ctx context.Context, v any) error {
|
||||
aggregation := make([]string, 0, len(gits.fns))
|
||||
for _, fn := range gits.fns {
|
||||
aggregation = append(aggregation, fn(gits.sql))
|
||||
}
|
||||
switch n := len(*gits.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
gits.sql.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
gits.sql.AppendSelect(aggregation...)
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := gits.sql.Query()
|
||||
if err := gits.driver.Query(ctx, query, args, rows); err != nil {
|
||||
|
||||
@@ -189,39 +189,19 @@ func (gitu *GroupInvitationTokenUpdate) sqlSave(ctx context.Context) (n int, err
|
||||
}
|
||||
}
|
||||
if value, ok := gitu.mutation.UpdatedAt(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: groupinvitationtoken.FieldUpdatedAt,
|
||||
})
|
||||
_spec.SetField(groupinvitationtoken.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := gitu.mutation.Token(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeBytes,
|
||||
Value: value,
|
||||
Column: groupinvitationtoken.FieldToken,
|
||||
})
|
||||
_spec.SetField(groupinvitationtoken.FieldToken, field.TypeBytes, value)
|
||||
}
|
||||
if value, ok := gitu.mutation.ExpiresAt(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: groupinvitationtoken.FieldExpiresAt,
|
||||
})
|
||||
_spec.SetField(groupinvitationtoken.FieldExpiresAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := gitu.mutation.Uses(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: value,
|
||||
Column: groupinvitationtoken.FieldUses,
|
||||
})
|
||||
_spec.SetField(groupinvitationtoken.FieldUses, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := gitu.mutation.AddedUses(); ok {
|
||||
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: value,
|
||||
Column: groupinvitationtoken.FieldUses,
|
||||
})
|
||||
_spec.AddField(groupinvitationtoken.FieldUses, field.TypeInt, value)
|
||||
}
|
||||
if gitu.mutation.GroupCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
@@ -466,39 +446,19 @@ func (gituo *GroupInvitationTokenUpdateOne) sqlSave(ctx context.Context) (_node
|
||||
}
|
||||
}
|
||||
if value, ok := gituo.mutation.UpdatedAt(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: groupinvitationtoken.FieldUpdatedAt,
|
||||
})
|
||||
_spec.SetField(groupinvitationtoken.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := gituo.mutation.Token(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeBytes,
|
||||
Value: value,
|
||||
Column: groupinvitationtoken.FieldToken,
|
||||
})
|
||||
_spec.SetField(groupinvitationtoken.FieldToken, field.TypeBytes, value)
|
||||
}
|
||||
if value, ok := gituo.mutation.ExpiresAt(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: groupinvitationtoken.FieldExpiresAt,
|
||||
})
|
||||
_spec.SetField(groupinvitationtoken.FieldExpiresAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := gituo.mutation.Uses(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: value,
|
||||
Column: groupinvitationtoken.FieldUses,
|
||||
})
|
||||
_spec.SetField(groupinvitationtoken.FieldUses, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := gituo.mutation.AddedUses(); ok {
|
||||
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: value,
|
||||
Column: groupinvitationtoken.FieldUses,
|
||||
})
|
||||
_spec.AddField(groupinvitationtoken.FieldUses, field.TypeInt, value)
|
||||
}
|
||||
if gituo.mutation.GroupCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
|
||||
@@ -8,6 +8,10 @@ func (a *Attachment) GetID() uuid.UUID {
|
||||
return a.ID
|
||||
}
|
||||
|
||||
func (ar *AuthRoles) GetID() int {
|
||||
return ar.ID
|
||||
}
|
||||
|
||||
func (at *AuthTokens) GetID() uuid.UUID {
|
||||
return at.ID
|
||||
}
|
||||
@@ -16,14 +20,14 @@ func (d *Document) GetID() uuid.UUID {
|
||||
return d.ID
|
||||
}
|
||||
|
||||
func (dt *DocumentToken) GetID() uuid.UUID {
|
||||
return dt.ID
|
||||
}
|
||||
|
||||
func (gr *Group) GetID() uuid.UUID {
|
||||
return gr.ID
|
||||
}
|
||||
|
||||
func (git *GroupInvitationToken) GetID() uuid.UUID {
|
||||
return git.ID
|
||||
}
|
||||
|
||||
func (i *Item) GetID() uuid.UUID {
|
||||
return i.ID
|
||||
}
|
||||
@@ -40,6 +44,10 @@ func (l *Location) GetID() uuid.UUID {
|
||||
return l.ID
|
||||
}
|
||||
|
||||
func (me *MaintenanceEntry) GetID() uuid.UUID {
|
||||
return me.ID
|
||||
}
|
||||
|
||||
func (u *User) GetID() uuid.UUID {
|
||||
return u.ID
|
||||
}
|
||||
|
||||
@@ -22,6 +22,19 @@ func (f AttachmentFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value,
|
||||
return f(ctx, mv)
|
||||
}
|
||||
|
||||
// The AuthRolesFunc type is an adapter to allow the use of ordinary
|
||||
// function as AuthRoles mutator.
|
||||
type AuthRolesFunc func(context.Context, *ent.AuthRolesMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f AuthRolesFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
mv, ok := m.(*ent.AuthRolesMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.AuthRolesMutation", m)
|
||||
}
|
||||
return f(ctx, mv)
|
||||
}
|
||||
|
||||
// The AuthTokensFunc type is an adapter to allow the use of ordinary
|
||||
// function as AuthTokens mutator.
|
||||
type AuthTokensFunc func(context.Context, *ent.AuthTokensMutation) (ent.Value, error)
|
||||
@@ -48,19 +61,6 @@ func (f DocumentFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, er
|
||||
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
|
||||
// function as Group mutator.
|
||||
type GroupFunc func(context.Context, *ent.GroupMutation) (ent.Value, error)
|
||||
@@ -139,6 +139,19 @@ func (f LocationFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, er
|
||||
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
|
||||
// function as User mutator.
|
||||
type UserFunc func(context.Context, *ent.UserMutation) (ent.Value, error)
|
||||
|
||||
@@ -37,6 +37,8 @@ type Item struct {
|
||||
Insured bool `json:"insured,omitempty"`
|
||||
// Archived holds the value of the "archived" field.
|
||||
Archived bool `json:"archived,omitempty"`
|
||||
// AssetID holds the value of the "asset_id" field.
|
||||
AssetID int `json:"asset_id,omitempty"`
|
||||
// SerialNumber holds the value of the "serial_number" field.
|
||||
SerialNumber string `json:"serial_number,omitempty"`
|
||||
// ModelNumber holds the value of the "model_number" field.
|
||||
@@ -85,11 +87,13 @@ type ItemEdges struct {
|
||||
Location *Location `json:"location,omitempty"`
|
||||
// Fields holds the value of the fields edge.
|
||||
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 []*Attachment `json:"attachments,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// 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
|
||||
@@ -158,10 +162,19 @@ func (e ItemEdges) FieldsOrErr() ([]*ItemField, error) {
|
||||
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
|
||||
// was not loaded in eager-loading.
|
||||
func (e ItemEdges) AttachmentsOrErr() ([]*Attachment, error) {
|
||||
if e.loadedTypes[6] {
|
||||
if e.loadedTypes[7] {
|
||||
return e.Attachments, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "attachments"}
|
||||
@@ -176,7 +189,7 @@ func (*Item) scanValues(columns []string) ([]any, error) {
|
||||
values[i] = new(sql.NullBool)
|
||||
case item.FieldPurchasePrice, item.FieldSoldPrice:
|
||||
values[i] = new(sql.NullFloat64)
|
||||
case item.FieldQuantity:
|
||||
case item.FieldQuantity, item.FieldAssetID:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case item.FieldName, item.FieldDescription, item.FieldImportRef, item.FieldNotes, item.FieldSerialNumber, item.FieldModelNumber, item.FieldManufacturer, item.FieldWarrantyDetails, item.FieldPurchaseFrom, item.FieldSoldTo, item.FieldSoldNotes:
|
||||
values[i] = new(sql.NullString)
|
||||
@@ -265,6 +278,12 @@ func (i *Item) assignValues(columns []string, values []any) error {
|
||||
} else if value.Valid {
|
||||
i.Archived = value.Bool
|
||||
}
|
||||
case item.FieldAssetID:
|
||||
if value, ok := values[j].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field asset_id", values[j])
|
||||
} else if value.Valid {
|
||||
i.AssetID = int(value.Int64)
|
||||
}
|
||||
case item.FieldSerialNumber:
|
||||
if value, ok := values[j].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field serial_number", values[j])
|
||||
@@ -399,6 +418,11 @@ func (i *Item) QueryFields() *ItemFieldQuery {
|
||||
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.
|
||||
func (i *Item) QueryAttachments() *AttachmentQuery {
|
||||
return (&ItemClient{config: i.config}).QueryAttachments(i)
|
||||
@@ -454,6 +478,9 @@ func (i *Item) String() string {
|
||||
builder.WriteString("archived=")
|
||||
builder.WriteString(fmt.Sprintf("%v", i.Archived))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("asset_id=")
|
||||
builder.WriteString(fmt.Sprintf("%v", i.AssetID))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("serial_number=")
|
||||
builder.WriteString(i.SerialNumber)
|
||||
builder.WriteString(", ")
|
||||
|
||||
@@ -31,6 +31,8 @@ const (
|
||||
FieldInsured = "insured"
|
||||
// FieldArchived holds the string denoting the archived field in the database.
|
||||
FieldArchived = "archived"
|
||||
// FieldAssetID holds the string denoting the asset_id field in the database.
|
||||
FieldAssetID = "asset_id"
|
||||
// FieldSerialNumber holds the string denoting the serial_number field in the database.
|
||||
FieldSerialNumber = "serial_number"
|
||||
// FieldModelNumber holds the string denoting the model_number field in the database.
|
||||
@@ -69,6 +71,8 @@ const (
|
||||
EdgeLocation = "location"
|
||||
// EdgeFields holds the string denoting the fields edge name in mutations.
|
||||
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 = "attachments"
|
||||
// Table holds the table name of the item in the database.
|
||||
@@ -107,6 +111,13 @@ const (
|
||||
FieldsInverseTable = "item_fields"
|
||||
// FieldsColumn is the table column denoting the fields relation/edge.
|
||||
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 = "attachments"
|
||||
// AttachmentsInverseTable is the table name for the Attachment entity.
|
||||
@@ -128,6 +139,7 @@ var Columns = []string{
|
||||
FieldQuantity,
|
||||
FieldInsured,
|
||||
FieldArchived,
|
||||
FieldAssetID,
|
||||
FieldSerialNumber,
|
||||
FieldModelNumber,
|
||||
FieldManufacturer,
|
||||
@@ -193,6 +205,8 @@ var (
|
||||
DefaultInsured bool
|
||||
// DefaultArchived holds the default value on creation for the "archived" field.
|
||||
DefaultArchived bool
|
||||
// DefaultAssetID holds the default value on creation for the "asset_id" field.
|
||||
DefaultAssetID int
|
||||
// SerialNumberValidator is a validator for the "serial_number" field. It is called by the builders before save.
|
||||
SerialNumberValidator func(string) error
|
||||
// ModelNumberValidator is a validator for the "model_number" field. It is called by the builders before save.
|
||||
|
||||
@@ -145,6 +145,13 @@ func Archived(v bool) predicate.Item {
|
||||
})
|
||||
}
|
||||
|
||||
// AssetID applies equality check predicate on the "asset_id" field. It's identical to AssetIDEQ.
|
||||
func AssetID(v int) predicate.Item {
|
||||
return predicate.Item(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldAssetID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// SerialNumber applies equality check predicate on the "serial_number" field. It's identical to SerialNumberEQ.
|
||||
func SerialNumber(v string) predicate.Item {
|
||||
return predicate.Item(func(s *sql.Selector) {
|
||||
@@ -894,6 +901,70 @@ func ArchivedNEQ(v bool) predicate.Item {
|
||||
})
|
||||
}
|
||||
|
||||
// AssetIDEQ applies the EQ predicate on the "asset_id" field.
|
||||
func AssetIDEQ(v int) predicate.Item {
|
||||
return predicate.Item(func(s *sql.Selector) {
|
||||
s.Where(sql.EQ(s.C(FieldAssetID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// AssetIDNEQ applies the NEQ predicate on the "asset_id" field.
|
||||
func AssetIDNEQ(v int) predicate.Item {
|
||||
return predicate.Item(func(s *sql.Selector) {
|
||||
s.Where(sql.NEQ(s.C(FieldAssetID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// AssetIDIn applies the In predicate on the "asset_id" field.
|
||||
func AssetIDIn(vs ...int) predicate.Item {
|
||||
v := make([]any, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.Item(func(s *sql.Selector) {
|
||||
s.Where(sql.In(s.C(FieldAssetID), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// AssetIDNotIn applies the NotIn predicate on the "asset_id" field.
|
||||
func AssetIDNotIn(vs ...int) predicate.Item {
|
||||
v := make([]any, len(vs))
|
||||
for i := range v {
|
||||
v[i] = vs[i]
|
||||
}
|
||||
return predicate.Item(func(s *sql.Selector) {
|
||||
s.Where(sql.NotIn(s.C(FieldAssetID), v...))
|
||||
})
|
||||
}
|
||||
|
||||
// AssetIDGT applies the GT predicate on the "asset_id" field.
|
||||
func AssetIDGT(v int) predicate.Item {
|
||||
return predicate.Item(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C(FieldAssetID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// AssetIDGTE applies the GTE predicate on the "asset_id" field.
|
||||
func AssetIDGTE(v int) predicate.Item {
|
||||
return predicate.Item(func(s *sql.Selector) {
|
||||
s.Where(sql.GTE(s.C(FieldAssetID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// AssetIDLT applies the LT predicate on the "asset_id" field.
|
||||
func AssetIDLT(v int) predicate.Item {
|
||||
return predicate.Item(func(s *sql.Selector) {
|
||||
s.Where(sql.LT(s.C(FieldAssetID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// AssetIDLTE applies the LTE predicate on the "asset_id" field.
|
||||
func AssetIDLTE(v int) predicate.Item {
|
||||
return predicate.Item(func(s *sql.Selector) {
|
||||
s.Where(sql.LTE(s.C(FieldAssetID), v))
|
||||
})
|
||||
}
|
||||
|
||||
// SerialNumberEQ applies the EQ predicate on the "serial_number" field.
|
||||
func SerialNumberEQ(v string) predicate.Item {
|
||||
return predicate.Item(func(s *sql.Selector) {
|
||||
@@ -2229,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.
|
||||
func HasAttachments() predicate.Item {
|
||||
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/label"
|
||||
"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.
|
||||
@@ -144,6 +145,20 @@ func (ic *ItemCreate) SetNillableArchived(b *bool) *ItemCreate {
|
||||
return ic
|
||||
}
|
||||
|
||||
// SetAssetID sets the "asset_id" field.
|
||||
func (ic *ItemCreate) SetAssetID(i int) *ItemCreate {
|
||||
ic.mutation.SetAssetID(i)
|
||||
return ic
|
||||
}
|
||||
|
||||
// SetNillableAssetID sets the "asset_id" field if the given value is not nil.
|
||||
func (ic *ItemCreate) SetNillableAssetID(i *int) *ItemCreate {
|
||||
if i != nil {
|
||||
ic.SetAssetID(*i)
|
||||
}
|
||||
return ic
|
||||
}
|
||||
|
||||
// SetSerialNumber sets the "serial_number" field.
|
||||
func (ic *ItemCreate) SetSerialNumber(s string) *ItemCreate {
|
||||
ic.mutation.SetSerialNumber(s)
|
||||
@@ -434,6 +449,21 @@ func (ic *ItemCreate) AddFields(i ...*ItemField) *ItemCreate {
|
||||
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.
|
||||
func (ic *ItemCreate) AddAttachmentIDs(ids ...uuid.UUID) *ItemCreate {
|
||||
ic.mutation.AddAttachmentIDs(ids...)
|
||||
@@ -546,6 +576,10 @@ func (ic *ItemCreate) defaults() {
|
||||
v := item.DefaultArchived
|
||||
ic.mutation.SetArchived(v)
|
||||
}
|
||||
if _, ok := ic.mutation.AssetID(); !ok {
|
||||
v := item.DefaultAssetID
|
||||
ic.mutation.SetAssetID(v)
|
||||
}
|
||||
if _, ok := ic.mutation.LifetimeWarranty(); !ok {
|
||||
v := item.DefaultLifetimeWarranty
|
||||
ic.mutation.SetLifetimeWarranty(v)
|
||||
@@ -604,6 +638,9 @@ func (ic *ItemCreate) check() error {
|
||||
if _, ok := ic.mutation.Archived(); !ok {
|
||||
return &ValidationError{Name: "archived", err: errors.New(`ent: missing required field "Item.archived"`)}
|
||||
}
|
||||
if _, ok := ic.mutation.AssetID(); !ok {
|
||||
return &ValidationError{Name: "asset_id", err: errors.New(`ent: missing required field "Item.asset_id"`)}
|
||||
}
|
||||
if v, ok := ic.mutation.SerialNumber(); ok {
|
||||
if err := item.SerialNumberValidator(v); err != nil {
|
||||
return &ValidationError{Name: "serial_number", err: fmt.Errorf(`ent: validator failed for field "Item.serial_number": %w`, err)}
|
||||
@@ -678,179 +715,95 @@ func (ic *ItemCreate) createSpec() (*Item, *sqlgraph.CreateSpec) {
|
||||
_spec.ID.Value = &id
|
||||
}
|
||||
if value, ok := ic.mutation.CreatedAt(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: item.FieldCreatedAt,
|
||||
})
|
||||
_spec.SetField(item.FieldCreatedAt, field.TypeTime, value)
|
||||
_node.CreatedAt = value
|
||||
}
|
||||
if value, ok := ic.mutation.UpdatedAt(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: item.FieldUpdatedAt,
|
||||
})
|
||||
_spec.SetField(item.FieldUpdatedAt, field.TypeTime, value)
|
||||
_node.UpdatedAt = value
|
||||
}
|
||||
if value, ok := ic.mutation.Name(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: item.FieldName,
|
||||
})
|
||||
_spec.SetField(item.FieldName, field.TypeString, value)
|
||||
_node.Name = value
|
||||
}
|
||||
if value, ok := ic.mutation.Description(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: item.FieldDescription,
|
||||
})
|
||||
_spec.SetField(item.FieldDescription, field.TypeString, value)
|
||||
_node.Description = value
|
||||
}
|
||||
if value, ok := ic.mutation.ImportRef(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: item.FieldImportRef,
|
||||
})
|
||||
_spec.SetField(item.FieldImportRef, field.TypeString, value)
|
||||
_node.ImportRef = value
|
||||
}
|
||||
if value, ok := ic.mutation.Notes(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: item.FieldNotes,
|
||||
})
|
||||
_spec.SetField(item.FieldNotes, field.TypeString, value)
|
||||
_node.Notes = value
|
||||
}
|
||||
if value, ok := ic.mutation.Quantity(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: value,
|
||||
Column: item.FieldQuantity,
|
||||
})
|
||||
_spec.SetField(item.FieldQuantity, field.TypeInt, value)
|
||||
_node.Quantity = value
|
||||
}
|
||||
if value, ok := ic.mutation.Insured(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeBool,
|
||||
Value: value,
|
||||
Column: item.FieldInsured,
|
||||
})
|
||||
_spec.SetField(item.FieldInsured, field.TypeBool, value)
|
||||
_node.Insured = value
|
||||
}
|
||||
if value, ok := ic.mutation.Archived(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeBool,
|
||||
Value: value,
|
||||
Column: item.FieldArchived,
|
||||
})
|
||||
_spec.SetField(item.FieldArchived, field.TypeBool, value)
|
||||
_node.Archived = value
|
||||
}
|
||||
if value, ok := ic.mutation.AssetID(); ok {
|
||||
_spec.SetField(item.FieldAssetID, field.TypeInt, value)
|
||||
_node.AssetID = value
|
||||
}
|
||||
if value, ok := ic.mutation.SerialNumber(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: item.FieldSerialNumber,
|
||||
})
|
||||
_spec.SetField(item.FieldSerialNumber, field.TypeString, value)
|
||||
_node.SerialNumber = value
|
||||
}
|
||||
if value, ok := ic.mutation.ModelNumber(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: item.FieldModelNumber,
|
||||
})
|
||||
_spec.SetField(item.FieldModelNumber, field.TypeString, value)
|
||||
_node.ModelNumber = value
|
||||
}
|
||||
if value, ok := ic.mutation.Manufacturer(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: item.FieldManufacturer,
|
||||
})
|
||||
_spec.SetField(item.FieldManufacturer, field.TypeString, value)
|
||||
_node.Manufacturer = value
|
||||
}
|
||||
if value, ok := ic.mutation.LifetimeWarranty(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeBool,
|
||||
Value: value,
|
||||
Column: item.FieldLifetimeWarranty,
|
||||
})
|
||||
_spec.SetField(item.FieldLifetimeWarranty, field.TypeBool, value)
|
||||
_node.LifetimeWarranty = value
|
||||
}
|
||||
if value, ok := ic.mutation.WarrantyExpires(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: item.FieldWarrantyExpires,
|
||||
})
|
||||
_spec.SetField(item.FieldWarrantyExpires, field.TypeTime, value)
|
||||
_node.WarrantyExpires = value
|
||||
}
|
||||
if value, ok := ic.mutation.WarrantyDetails(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: item.FieldWarrantyDetails,
|
||||
})
|
||||
_spec.SetField(item.FieldWarrantyDetails, field.TypeString, value)
|
||||
_node.WarrantyDetails = value
|
||||
}
|
||||
if value, ok := ic.mutation.PurchaseTime(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: item.FieldPurchaseTime,
|
||||
})
|
||||
_spec.SetField(item.FieldPurchaseTime, field.TypeTime, value)
|
||||
_node.PurchaseTime = value
|
||||
}
|
||||
if value, ok := ic.mutation.PurchaseFrom(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: item.FieldPurchaseFrom,
|
||||
})
|
||||
_spec.SetField(item.FieldPurchaseFrom, field.TypeString, value)
|
||||
_node.PurchaseFrom = value
|
||||
}
|
||||
if value, ok := ic.mutation.PurchasePrice(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeFloat64,
|
||||
Value: value,
|
||||
Column: item.FieldPurchasePrice,
|
||||
})
|
||||
_spec.SetField(item.FieldPurchasePrice, field.TypeFloat64, value)
|
||||
_node.PurchasePrice = value
|
||||
}
|
||||
if value, ok := ic.mutation.SoldTime(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: item.FieldSoldTime,
|
||||
})
|
||||
_spec.SetField(item.FieldSoldTime, field.TypeTime, value)
|
||||
_node.SoldTime = value
|
||||
}
|
||||
if value, ok := ic.mutation.SoldTo(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: item.FieldSoldTo,
|
||||
})
|
||||
_spec.SetField(item.FieldSoldTo, field.TypeString, value)
|
||||
_node.SoldTo = value
|
||||
}
|
||||
if value, ok := ic.mutation.SoldPrice(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeFloat64,
|
||||
Value: value,
|
||||
Column: item.FieldSoldPrice,
|
||||
})
|
||||
_spec.SetField(item.FieldSoldPrice, field.TypeFloat64, value)
|
||||
_node.SoldPrice = value
|
||||
}
|
||||
if value, ok := ic.mutation.SoldNotes(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: item.FieldSoldNotes,
|
||||
})
|
||||
_spec.SetField(item.FieldSoldNotes, field.TypeString, value)
|
||||
_node.SoldNotes = value
|
||||
}
|
||||
if nodes := ic.mutation.ParentIDs(); len(nodes) > 0 {
|
||||
@@ -970,6 +923,25 @@ func (ic *ItemCreate) createSpec() (*Item, *sqlgraph.CreateSpec) {
|
||||
}
|
||||
_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 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
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/label"
|
||||
"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"
|
||||
)
|
||||
|
||||
// ItemQuery is the builder for querying Item entities.
|
||||
type ItemQuery struct {
|
||||
config
|
||||
limit *int
|
||||
offset *int
|
||||
unique *bool
|
||||
order []OrderFunc
|
||||
fields []string
|
||||
predicates []predicate.Item
|
||||
withParent *ItemQuery
|
||||
withChildren *ItemQuery
|
||||
withGroup *GroupQuery
|
||||
withLabel *LabelQuery
|
||||
withLocation *LocationQuery
|
||||
withFields *ItemFieldQuery
|
||||
withAttachments *AttachmentQuery
|
||||
withFKs bool
|
||||
limit *int
|
||||
offset *int
|
||||
unique *bool
|
||||
order []OrderFunc
|
||||
fields []string
|
||||
predicates []predicate.Item
|
||||
withParent *ItemQuery
|
||||
withChildren *ItemQuery
|
||||
withGroup *GroupQuery
|
||||
withLabel *LabelQuery
|
||||
withLocation *LocationQuery
|
||||
withFields *ItemFieldQuery
|
||||
withMaintenanceEntries *MaintenanceEntryQuery
|
||||
withAttachments *AttachmentQuery
|
||||
withFKs bool
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
@@ -206,6 +208,28 @@ func (iq *ItemQuery) QueryFields() *ItemFieldQuery {
|
||||
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.
|
||||
func (iq *ItemQuery) QueryAttachments() *AttachmentQuery {
|
||||
query := &AttachmentQuery{config: iq.config}
|
||||
@@ -404,18 +428,19 @@ func (iq *ItemQuery) Clone() *ItemQuery {
|
||||
return nil
|
||||
}
|
||||
return &ItemQuery{
|
||||
config: iq.config,
|
||||
limit: iq.limit,
|
||||
offset: iq.offset,
|
||||
order: append([]OrderFunc{}, iq.order...),
|
||||
predicates: append([]predicate.Item{}, iq.predicates...),
|
||||
withParent: iq.withParent.Clone(),
|
||||
withChildren: iq.withChildren.Clone(),
|
||||
withGroup: iq.withGroup.Clone(),
|
||||
withLabel: iq.withLabel.Clone(),
|
||||
withLocation: iq.withLocation.Clone(),
|
||||
withFields: iq.withFields.Clone(),
|
||||
withAttachments: iq.withAttachments.Clone(),
|
||||
config: iq.config,
|
||||
limit: iq.limit,
|
||||
offset: iq.offset,
|
||||
order: append([]OrderFunc{}, iq.order...),
|
||||
predicates: append([]predicate.Item{}, iq.predicates...),
|
||||
withParent: iq.withParent.Clone(),
|
||||
withChildren: iq.withChildren.Clone(),
|
||||
withGroup: iq.withGroup.Clone(),
|
||||
withLabel: iq.withLabel.Clone(),
|
||||
withLocation: iq.withLocation.Clone(),
|
||||
withFields: iq.withFields.Clone(),
|
||||
withMaintenanceEntries: iq.withMaintenanceEntries.Clone(),
|
||||
withAttachments: iq.withAttachments.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: iq.sql.Clone(),
|
||||
path: iq.path,
|
||||
@@ -489,6 +514,17 @@ func (iq *ItemQuery) WithFields(opts ...func(*ItemFieldQuery)) *ItemQuery {
|
||||
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
|
||||
// the "attachments" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (iq *ItemQuery) WithAttachments(opts ...func(*AttachmentQuery)) *ItemQuery {
|
||||
@@ -548,6 +584,11 @@ func (iq *ItemQuery) Select(fields ...string) *ItemSelect {
|
||||
return selbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a ItemSelect configured with the given aggregations.
|
||||
func (iq *ItemQuery) Aggregate(fns ...AggregateFunc) *ItemSelect {
|
||||
return iq.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (iq *ItemQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, f := range iq.fields {
|
||||
if !item.ValidColumn(f) {
|
||||
@@ -569,13 +610,14 @@ func (iq *ItemQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Item, e
|
||||
nodes = []*Item{}
|
||||
withFKs = iq.withFKs
|
||||
_spec = iq.querySpec()
|
||||
loadedTypes = [7]bool{
|
||||
loadedTypes = [8]bool{
|
||||
iq.withParent != nil,
|
||||
iq.withChildren != nil,
|
||||
iq.withGroup != nil,
|
||||
iq.withLabel != nil,
|
||||
iq.withLocation != nil,
|
||||
iq.withFields != nil,
|
||||
iq.withMaintenanceEntries != nil,
|
||||
iq.withAttachments != nil,
|
||||
}
|
||||
)
|
||||
@@ -642,6 +684,13 @@ func (iq *ItemQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Item, e
|
||||
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 err := iq.loadAttachments(ctx, query, nodes,
|
||||
func(n *Item) { n.Edges.Attachments = []*Attachment{} },
|
||||
@@ -778,7 +827,7 @@ func (iq *ItemQuery) loadLabel(ctx context.Context, query *LabelQuery, nodes []*
|
||||
outValue := *values[0].(*uuid.UUID)
|
||||
inValue := *values[1].(*uuid.UUID)
|
||||
if nids[inValue] == nil {
|
||||
nids[inValue] = map[*Item]struct{}{byID[outValue]: struct{}{}}
|
||||
nids[inValue] = map[*Item]struct{}{byID[outValue]: {}}
|
||||
return assign(columns[1:], values[1:])
|
||||
}
|
||||
nids[inValue][byID[outValue]] = struct{}{}
|
||||
@@ -859,6 +908,33 @@ func (iq *ItemQuery) loadFields(ctx context.Context, query *ItemFieldQuery, node
|
||||
}
|
||||
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 {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
nodeids := make(map[uuid.UUID]*Item)
|
||||
@@ -1043,8 +1119,6 @@ func (igb *ItemGroupBy) sqlQuery() *sql.Selector {
|
||||
for _, fn := range igb.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
// If no columns were selected in a custom aggregation function, the default
|
||||
// selection is the fields used for "group-by", and the aggregation functions.
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(igb.fields)+len(igb.fns))
|
||||
for _, f := range igb.fields {
|
||||
@@ -1064,6 +1138,12 @@ type ItemSelect struct {
|
||||
sql *sql.Selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (is *ItemSelect) Aggregate(fns ...AggregateFunc) *ItemSelect {
|
||||
is.fns = append(is.fns, fns...)
|
||||
return is
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (is *ItemSelect) Scan(ctx context.Context, v any) error {
|
||||
if err := is.prepareQuery(ctx); err != nil {
|
||||
@@ -1074,6 +1154,16 @@ func (is *ItemSelect) Scan(ctx context.Context, v any) error {
|
||||
}
|
||||
|
||||
func (is *ItemSelect) sqlScan(ctx context.Context, v any) error {
|
||||
aggregation := make([]string, 0, len(is.fns))
|
||||
for _, fn := range is.fns {
|
||||
aggregation = append(aggregation, fn(is.sql))
|
||||
}
|
||||
switch n := len(*is.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
is.sql.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
is.sql.AppendSelect(aggregation...)
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := is.sql.Query()
|
||||
if err := is.driver.Query(ctx, query, args, rows); err != nil {
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"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/location"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/maintenanceentry"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/predicate"
|
||||
)
|
||||
|
||||
@@ -135,6 +136,27 @@ func (iu *ItemUpdate) SetNillableArchived(b *bool) *ItemUpdate {
|
||||
return iu
|
||||
}
|
||||
|
||||
// SetAssetID sets the "asset_id" field.
|
||||
func (iu *ItemUpdate) SetAssetID(i int) *ItemUpdate {
|
||||
iu.mutation.ResetAssetID()
|
||||
iu.mutation.SetAssetID(i)
|
||||
return iu
|
||||
}
|
||||
|
||||
// SetNillableAssetID sets the "asset_id" field if the given value is not nil.
|
||||
func (iu *ItemUpdate) SetNillableAssetID(i *int) *ItemUpdate {
|
||||
if i != nil {
|
||||
iu.SetAssetID(*i)
|
||||
}
|
||||
return iu
|
||||
}
|
||||
|
||||
// AddAssetID adds i to the "asset_id" field.
|
||||
func (iu *ItemUpdate) AddAssetID(i int) *ItemUpdate {
|
||||
iu.mutation.AddAssetID(i)
|
||||
return iu
|
||||
}
|
||||
|
||||
// SetSerialNumber sets the "serial_number" field.
|
||||
func (iu *ItemUpdate) SetSerialNumber(s string) *ItemUpdate {
|
||||
iu.mutation.SetSerialNumber(s)
|
||||
@@ -485,6 +507,21 @@ func (iu *ItemUpdate) AddFields(i ...*ItemField) *ItemUpdate {
|
||||
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.
|
||||
func (iu *ItemUpdate) AddAttachmentIDs(ids ...uuid.UUID) *ItemUpdate {
|
||||
iu.mutation.AddAttachmentIDs(ids...)
|
||||
@@ -586,6 +623,27 @@ func (iu *ItemUpdate) RemoveFields(i ...*ItemField) *ItemUpdate {
|
||||
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.
|
||||
func (iu *ItemUpdate) ClearAttachments() *ItemUpdate {
|
||||
iu.mutation.ClearAttachments()
|
||||
@@ -743,243 +801,118 @@ func (iu *ItemUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
}
|
||||
}
|
||||
if value, ok := iu.mutation.UpdatedAt(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: item.FieldUpdatedAt,
|
||||
})
|
||||
_spec.SetField(item.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := iu.mutation.Name(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: item.FieldName,
|
||||
})
|
||||
_spec.SetField(item.FieldName, field.TypeString, value)
|
||||
}
|
||||
if value, ok := iu.mutation.Description(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: item.FieldDescription,
|
||||
})
|
||||
_spec.SetField(item.FieldDescription, field.TypeString, value)
|
||||
}
|
||||
if iu.mutation.DescriptionCleared() {
|
||||
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Column: item.FieldDescription,
|
||||
})
|
||||
_spec.ClearField(item.FieldDescription, field.TypeString)
|
||||
}
|
||||
if iu.mutation.ImportRefCleared() {
|
||||
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Column: item.FieldImportRef,
|
||||
})
|
||||
_spec.ClearField(item.FieldImportRef, field.TypeString)
|
||||
}
|
||||
if value, ok := iu.mutation.Notes(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: item.FieldNotes,
|
||||
})
|
||||
_spec.SetField(item.FieldNotes, field.TypeString, value)
|
||||
}
|
||||
if iu.mutation.NotesCleared() {
|
||||
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Column: item.FieldNotes,
|
||||
})
|
||||
_spec.ClearField(item.FieldNotes, field.TypeString)
|
||||
}
|
||||
if value, ok := iu.mutation.Quantity(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: value,
|
||||
Column: item.FieldQuantity,
|
||||
})
|
||||
_spec.SetField(item.FieldQuantity, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := iu.mutation.AddedQuantity(); ok {
|
||||
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: value,
|
||||
Column: item.FieldQuantity,
|
||||
})
|
||||
_spec.AddField(item.FieldQuantity, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := iu.mutation.Insured(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeBool,
|
||||
Value: value,
|
||||
Column: item.FieldInsured,
|
||||
})
|
||||
_spec.SetField(item.FieldInsured, field.TypeBool, value)
|
||||
}
|
||||
if value, ok := iu.mutation.Archived(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeBool,
|
||||
Value: value,
|
||||
Column: item.FieldArchived,
|
||||
})
|
||||
_spec.SetField(item.FieldArchived, field.TypeBool, value)
|
||||
}
|
||||
if value, ok := iu.mutation.AssetID(); ok {
|
||||
_spec.SetField(item.FieldAssetID, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := iu.mutation.AddedAssetID(); ok {
|
||||
_spec.AddField(item.FieldAssetID, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := iu.mutation.SerialNumber(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: item.FieldSerialNumber,
|
||||
})
|
||||
_spec.SetField(item.FieldSerialNumber, field.TypeString, value)
|
||||
}
|
||||
if iu.mutation.SerialNumberCleared() {
|
||||
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Column: item.FieldSerialNumber,
|
||||
})
|
||||
_spec.ClearField(item.FieldSerialNumber, field.TypeString)
|
||||
}
|
||||
if value, ok := iu.mutation.ModelNumber(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: item.FieldModelNumber,
|
||||
})
|
||||
_spec.SetField(item.FieldModelNumber, field.TypeString, value)
|
||||
}
|
||||
if iu.mutation.ModelNumberCleared() {
|
||||
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Column: item.FieldModelNumber,
|
||||
})
|
||||
_spec.ClearField(item.FieldModelNumber, field.TypeString)
|
||||
}
|
||||
if value, ok := iu.mutation.Manufacturer(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: item.FieldManufacturer,
|
||||
})
|
||||
_spec.SetField(item.FieldManufacturer, field.TypeString, value)
|
||||
}
|
||||
if iu.mutation.ManufacturerCleared() {
|
||||
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Column: item.FieldManufacturer,
|
||||
})
|
||||
_spec.ClearField(item.FieldManufacturer, field.TypeString)
|
||||
}
|
||||
if value, ok := iu.mutation.LifetimeWarranty(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeBool,
|
||||
Value: value,
|
||||
Column: item.FieldLifetimeWarranty,
|
||||
})
|
||||
_spec.SetField(item.FieldLifetimeWarranty, field.TypeBool, value)
|
||||
}
|
||||
if value, ok := iu.mutation.WarrantyExpires(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: item.FieldWarrantyExpires,
|
||||
})
|
||||
_spec.SetField(item.FieldWarrantyExpires, field.TypeTime, value)
|
||||
}
|
||||
if iu.mutation.WarrantyExpiresCleared() {
|
||||
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Column: item.FieldWarrantyExpires,
|
||||
})
|
||||
_spec.ClearField(item.FieldWarrantyExpires, field.TypeTime)
|
||||
}
|
||||
if value, ok := iu.mutation.WarrantyDetails(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: item.FieldWarrantyDetails,
|
||||
})
|
||||
_spec.SetField(item.FieldWarrantyDetails, field.TypeString, value)
|
||||
}
|
||||
if iu.mutation.WarrantyDetailsCleared() {
|
||||
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Column: item.FieldWarrantyDetails,
|
||||
})
|
||||
_spec.ClearField(item.FieldWarrantyDetails, field.TypeString)
|
||||
}
|
||||
if value, ok := iu.mutation.PurchaseTime(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: item.FieldPurchaseTime,
|
||||
})
|
||||
_spec.SetField(item.FieldPurchaseTime, field.TypeTime, value)
|
||||
}
|
||||
if iu.mutation.PurchaseTimeCleared() {
|
||||
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Column: item.FieldPurchaseTime,
|
||||
})
|
||||
_spec.ClearField(item.FieldPurchaseTime, field.TypeTime)
|
||||
}
|
||||
if value, ok := iu.mutation.PurchaseFrom(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: item.FieldPurchaseFrom,
|
||||
})
|
||||
_spec.SetField(item.FieldPurchaseFrom, field.TypeString, value)
|
||||
}
|
||||
if iu.mutation.PurchaseFromCleared() {
|
||||
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Column: item.FieldPurchaseFrom,
|
||||
})
|
||||
_spec.ClearField(item.FieldPurchaseFrom, field.TypeString)
|
||||
}
|
||||
if value, ok := iu.mutation.PurchasePrice(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeFloat64,
|
||||
Value: value,
|
||||
Column: item.FieldPurchasePrice,
|
||||
})
|
||||
_spec.SetField(item.FieldPurchasePrice, field.TypeFloat64, value)
|
||||
}
|
||||
if value, ok := iu.mutation.AddedPurchasePrice(); ok {
|
||||
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeFloat64,
|
||||
Value: value,
|
||||
Column: item.FieldPurchasePrice,
|
||||
})
|
||||
_spec.AddField(item.FieldPurchasePrice, field.TypeFloat64, value)
|
||||
}
|
||||
if value, ok := iu.mutation.SoldTime(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: item.FieldSoldTime,
|
||||
})
|
||||
_spec.SetField(item.FieldSoldTime, field.TypeTime, value)
|
||||
}
|
||||
if iu.mutation.SoldTimeCleared() {
|
||||
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Column: item.FieldSoldTime,
|
||||
})
|
||||
_spec.ClearField(item.FieldSoldTime, field.TypeTime)
|
||||
}
|
||||
if value, ok := iu.mutation.SoldTo(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: item.FieldSoldTo,
|
||||
})
|
||||
_spec.SetField(item.FieldSoldTo, field.TypeString, value)
|
||||
}
|
||||
if iu.mutation.SoldToCleared() {
|
||||
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Column: item.FieldSoldTo,
|
||||
})
|
||||
_spec.ClearField(item.FieldSoldTo, field.TypeString)
|
||||
}
|
||||
if value, ok := iu.mutation.SoldPrice(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeFloat64,
|
||||
Value: value,
|
||||
Column: item.FieldSoldPrice,
|
||||
})
|
||||
_spec.SetField(item.FieldSoldPrice, field.TypeFloat64, value)
|
||||
}
|
||||
if value, ok := iu.mutation.AddedSoldPrice(); ok {
|
||||
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeFloat64,
|
||||
Value: value,
|
||||
Column: item.FieldSoldPrice,
|
||||
})
|
||||
_spec.AddField(item.FieldSoldPrice, field.TypeFloat64, value)
|
||||
}
|
||||
if value, ok := iu.mutation.SoldNotes(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: item.FieldSoldNotes,
|
||||
})
|
||||
_spec.SetField(item.FieldSoldNotes, field.TypeString, value)
|
||||
}
|
||||
if iu.mutation.SoldNotesCleared() {
|
||||
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Column: item.FieldSoldNotes,
|
||||
})
|
||||
_spec.ClearField(item.FieldSoldNotes, field.TypeString)
|
||||
}
|
||||
if iu.mutation.ParentCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
@@ -1248,6 +1181,60 @@ func (iu *ItemUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
}
|
||||
_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() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
@@ -1422,6 +1409,27 @@ func (iuo *ItemUpdateOne) SetNillableArchived(b *bool) *ItemUpdateOne {
|
||||
return iuo
|
||||
}
|
||||
|
||||
// SetAssetID sets the "asset_id" field.
|
||||
func (iuo *ItemUpdateOne) SetAssetID(i int) *ItemUpdateOne {
|
||||
iuo.mutation.ResetAssetID()
|
||||
iuo.mutation.SetAssetID(i)
|
||||
return iuo
|
||||
}
|
||||
|
||||
// SetNillableAssetID sets the "asset_id" field if the given value is not nil.
|
||||
func (iuo *ItemUpdateOne) SetNillableAssetID(i *int) *ItemUpdateOne {
|
||||
if i != nil {
|
||||
iuo.SetAssetID(*i)
|
||||
}
|
||||
return iuo
|
||||
}
|
||||
|
||||
// AddAssetID adds i to the "asset_id" field.
|
||||
func (iuo *ItemUpdateOne) AddAssetID(i int) *ItemUpdateOne {
|
||||
iuo.mutation.AddAssetID(i)
|
||||
return iuo
|
||||
}
|
||||
|
||||
// SetSerialNumber sets the "serial_number" field.
|
||||
func (iuo *ItemUpdateOne) SetSerialNumber(s string) *ItemUpdateOne {
|
||||
iuo.mutation.SetSerialNumber(s)
|
||||
@@ -1772,6 +1780,21 @@ func (iuo *ItemUpdateOne) AddFields(i ...*ItemField) *ItemUpdateOne {
|
||||
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.
|
||||
func (iuo *ItemUpdateOne) AddAttachmentIDs(ids ...uuid.UUID) *ItemUpdateOne {
|
||||
iuo.mutation.AddAttachmentIDs(ids...)
|
||||
@@ -1873,6 +1896,27 @@ func (iuo *ItemUpdateOne) RemoveFields(i ...*ItemField) *ItemUpdateOne {
|
||||
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.
|
||||
func (iuo *ItemUpdateOne) ClearAttachments() *ItemUpdateOne {
|
||||
iuo.mutation.ClearAttachments()
|
||||
@@ -2060,243 +2104,118 @@ func (iuo *ItemUpdateOne) sqlSave(ctx context.Context) (_node *Item, err error)
|
||||
}
|
||||
}
|
||||
if value, ok := iuo.mutation.UpdatedAt(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: item.FieldUpdatedAt,
|
||||
})
|
||||
_spec.SetField(item.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := iuo.mutation.Name(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: item.FieldName,
|
||||
})
|
||||
_spec.SetField(item.FieldName, field.TypeString, value)
|
||||
}
|
||||
if value, ok := iuo.mutation.Description(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: item.FieldDescription,
|
||||
})
|
||||
_spec.SetField(item.FieldDescription, field.TypeString, value)
|
||||
}
|
||||
if iuo.mutation.DescriptionCleared() {
|
||||
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Column: item.FieldDescription,
|
||||
})
|
||||
_spec.ClearField(item.FieldDescription, field.TypeString)
|
||||
}
|
||||
if iuo.mutation.ImportRefCleared() {
|
||||
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Column: item.FieldImportRef,
|
||||
})
|
||||
_spec.ClearField(item.FieldImportRef, field.TypeString)
|
||||
}
|
||||
if value, ok := iuo.mutation.Notes(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: item.FieldNotes,
|
||||
})
|
||||
_spec.SetField(item.FieldNotes, field.TypeString, value)
|
||||
}
|
||||
if iuo.mutation.NotesCleared() {
|
||||
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Column: item.FieldNotes,
|
||||
})
|
||||
_spec.ClearField(item.FieldNotes, field.TypeString)
|
||||
}
|
||||
if value, ok := iuo.mutation.Quantity(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: value,
|
||||
Column: item.FieldQuantity,
|
||||
})
|
||||
_spec.SetField(item.FieldQuantity, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := iuo.mutation.AddedQuantity(); ok {
|
||||
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: value,
|
||||
Column: item.FieldQuantity,
|
||||
})
|
||||
_spec.AddField(item.FieldQuantity, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := iuo.mutation.Insured(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeBool,
|
||||
Value: value,
|
||||
Column: item.FieldInsured,
|
||||
})
|
||||
_spec.SetField(item.FieldInsured, field.TypeBool, value)
|
||||
}
|
||||
if value, ok := iuo.mutation.Archived(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeBool,
|
||||
Value: value,
|
||||
Column: item.FieldArchived,
|
||||
})
|
||||
_spec.SetField(item.FieldArchived, field.TypeBool, value)
|
||||
}
|
||||
if value, ok := iuo.mutation.AssetID(); ok {
|
||||
_spec.SetField(item.FieldAssetID, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := iuo.mutation.AddedAssetID(); ok {
|
||||
_spec.AddField(item.FieldAssetID, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := iuo.mutation.SerialNumber(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: item.FieldSerialNumber,
|
||||
})
|
||||
_spec.SetField(item.FieldSerialNumber, field.TypeString, value)
|
||||
}
|
||||
if iuo.mutation.SerialNumberCleared() {
|
||||
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Column: item.FieldSerialNumber,
|
||||
})
|
||||
_spec.ClearField(item.FieldSerialNumber, field.TypeString)
|
||||
}
|
||||
if value, ok := iuo.mutation.ModelNumber(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: item.FieldModelNumber,
|
||||
})
|
||||
_spec.SetField(item.FieldModelNumber, field.TypeString, value)
|
||||
}
|
||||
if iuo.mutation.ModelNumberCleared() {
|
||||
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Column: item.FieldModelNumber,
|
||||
})
|
||||
_spec.ClearField(item.FieldModelNumber, field.TypeString)
|
||||
}
|
||||
if value, ok := iuo.mutation.Manufacturer(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: item.FieldManufacturer,
|
||||
})
|
||||
_spec.SetField(item.FieldManufacturer, field.TypeString, value)
|
||||
}
|
||||
if iuo.mutation.ManufacturerCleared() {
|
||||
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Column: item.FieldManufacturer,
|
||||
})
|
||||
_spec.ClearField(item.FieldManufacturer, field.TypeString)
|
||||
}
|
||||
if value, ok := iuo.mutation.LifetimeWarranty(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeBool,
|
||||
Value: value,
|
||||
Column: item.FieldLifetimeWarranty,
|
||||
})
|
||||
_spec.SetField(item.FieldLifetimeWarranty, field.TypeBool, value)
|
||||
}
|
||||
if value, ok := iuo.mutation.WarrantyExpires(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: item.FieldWarrantyExpires,
|
||||
})
|
||||
_spec.SetField(item.FieldWarrantyExpires, field.TypeTime, value)
|
||||
}
|
||||
if iuo.mutation.WarrantyExpiresCleared() {
|
||||
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Column: item.FieldWarrantyExpires,
|
||||
})
|
||||
_spec.ClearField(item.FieldWarrantyExpires, field.TypeTime)
|
||||
}
|
||||
if value, ok := iuo.mutation.WarrantyDetails(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: item.FieldWarrantyDetails,
|
||||
})
|
||||
_spec.SetField(item.FieldWarrantyDetails, field.TypeString, value)
|
||||
}
|
||||
if iuo.mutation.WarrantyDetailsCleared() {
|
||||
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Column: item.FieldWarrantyDetails,
|
||||
})
|
||||
_spec.ClearField(item.FieldWarrantyDetails, field.TypeString)
|
||||
}
|
||||
if value, ok := iuo.mutation.PurchaseTime(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: item.FieldPurchaseTime,
|
||||
})
|
||||
_spec.SetField(item.FieldPurchaseTime, field.TypeTime, value)
|
||||
}
|
||||
if iuo.mutation.PurchaseTimeCleared() {
|
||||
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Column: item.FieldPurchaseTime,
|
||||
})
|
||||
_spec.ClearField(item.FieldPurchaseTime, field.TypeTime)
|
||||
}
|
||||
if value, ok := iuo.mutation.PurchaseFrom(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: item.FieldPurchaseFrom,
|
||||
})
|
||||
_spec.SetField(item.FieldPurchaseFrom, field.TypeString, value)
|
||||
}
|
||||
if iuo.mutation.PurchaseFromCleared() {
|
||||
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Column: item.FieldPurchaseFrom,
|
||||
})
|
||||
_spec.ClearField(item.FieldPurchaseFrom, field.TypeString)
|
||||
}
|
||||
if value, ok := iuo.mutation.PurchasePrice(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeFloat64,
|
||||
Value: value,
|
||||
Column: item.FieldPurchasePrice,
|
||||
})
|
||||
_spec.SetField(item.FieldPurchasePrice, field.TypeFloat64, value)
|
||||
}
|
||||
if value, ok := iuo.mutation.AddedPurchasePrice(); ok {
|
||||
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeFloat64,
|
||||
Value: value,
|
||||
Column: item.FieldPurchasePrice,
|
||||
})
|
||||
_spec.AddField(item.FieldPurchasePrice, field.TypeFloat64, value)
|
||||
}
|
||||
if value, ok := iuo.mutation.SoldTime(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: item.FieldSoldTime,
|
||||
})
|
||||
_spec.SetField(item.FieldSoldTime, field.TypeTime, value)
|
||||
}
|
||||
if iuo.mutation.SoldTimeCleared() {
|
||||
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Column: item.FieldSoldTime,
|
||||
})
|
||||
_spec.ClearField(item.FieldSoldTime, field.TypeTime)
|
||||
}
|
||||
if value, ok := iuo.mutation.SoldTo(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: item.FieldSoldTo,
|
||||
})
|
||||
_spec.SetField(item.FieldSoldTo, field.TypeString, value)
|
||||
}
|
||||
if iuo.mutation.SoldToCleared() {
|
||||
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Column: item.FieldSoldTo,
|
||||
})
|
||||
_spec.ClearField(item.FieldSoldTo, field.TypeString)
|
||||
}
|
||||
if value, ok := iuo.mutation.SoldPrice(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeFloat64,
|
||||
Value: value,
|
||||
Column: item.FieldSoldPrice,
|
||||
})
|
||||
_spec.SetField(item.FieldSoldPrice, field.TypeFloat64, value)
|
||||
}
|
||||
if value, ok := iuo.mutation.AddedSoldPrice(); ok {
|
||||
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeFloat64,
|
||||
Value: value,
|
||||
Column: item.FieldSoldPrice,
|
||||
})
|
||||
_spec.AddField(item.FieldSoldPrice, field.TypeFloat64, value)
|
||||
}
|
||||
if value, ok := iuo.mutation.SoldNotes(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: item.FieldSoldNotes,
|
||||
})
|
||||
_spec.SetField(item.FieldSoldNotes, field.TypeString, value)
|
||||
}
|
||||
if iuo.mutation.SoldNotesCleared() {
|
||||
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Column: item.FieldSoldNotes,
|
||||
})
|
||||
_spec.ClearField(item.FieldSoldNotes, field.TypeString)
|
||||
}
|
||||
if iuo.mutation.ParentCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
@@ -2565,6 +2484,60 @@ func (iuo *ItemUpdateOne) sqlSave(ctx context.Context) (_node *Item, err error)
|
||||
}
|
||||
_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() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
|
||||
@@ -341,75 +341,39 @@ func (ifc *ItemFieldCreate) createSpec() (*ItemField, *sqlgraph.CreateSpec) {
|
||||
_spec.ID.Value = &id
|
||||
}
|
||||
if value, ok := ifc.mutation.CreatedAt(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: itemfield.FieldCreatedAt,
|
||||
})
|
||||
_spec.SetField(itemfield.FieldCreatedAt, field.TypeTime, value)
|
||||
_node.CreatedAt = value
|
||||
}
|
||||
if value, ok := ifc.mutation.UpdatedAt(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: itemfield.FieldUpdatedAt,
|
||||
})
|
||||
_spec.SetField(itemfield.FieldUpdatedAt, field.TypeTime, value)
|
||||
_node.UpdatedAt = value
|
||||
}
|
||||
if value, ok := ifc.mutation.Name(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: itemfield.FieldName,
|
||||
})
|
||||
_spec.SetField(itemfield.FieldName, field.TypeString, value)
|
||||
_node.Name = value
|
||||
}
|
||||
if value, ok := ifc.mutation.Description(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: itemfield.FieldDescription,
|
||||
})
|
||||
_spec.SetField(itemfield.FieldDescription, field.TypeString, value)
|
||||
_node.Description = value
|
||||
}
|
||||
if value, ok := ifc.mutation.GetType(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeEnum,
|
||||
Value: value,
|
||||
Column: itemfield.FieldType,
|
||||
})
|
||||
_spec.SetField(itemfield.FieldType, field.TypeEnum, value)
|
||||
_node.Type = value
|
||||
}
|
||||
if value, ok := ifc.mutation.TextValue(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: itemfield.FieldTextValue,
|
||||
})
|
||||
_spec.SetField(itemfield.FieldTextValue, field.TypeString, value)
|
||||
_node.TextValue = value
|
||||
}
|
||||
if value, ok := ifc.mutation.NumberValue(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: value,
|
||||
Column: itemfield.FieldNumberValue,
|
||||
})
|
||||
_spec.SetField(itemfield.FieldNumberValue, field.TypeInt, value)
|
||||
_node.NumberValue = value
|
||||
}
|
||||
if value, ok := ifc.mutation.BooleanValue(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeBool,
|
||||
Value: value,
|
||||
Column: itemfield.FieldBooleanValue,
|
||||
})
|
||||
_spec.SetField(itemfield.FieldBooleanValue, field.TypeBool, value)
|
||||
_node.BooleanValue = value
|
||||
}
|
||||
if value, ok := ifc.mutation.TimeValue(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: itemfield.FieldTimeValue,
|
||||
})
|
||||
_spec.SetField(itemfield.FieldTimeValue, field.TypeTime, value)
|
||||
_node.TimeValue = value
|
||||
}
|
||||
if nodes := ifc.mutation.ItemIDs(); len(nodes) > 0 {
|
||||
|
||||
@@ -333,6 +333,11 @@ func (ifq *ItemFieldQuery) Select(fields ...string) *ItemFieldSelect {
|
||||
return selbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a ItemFieldSelect configured with the given aggregations.
|
||||
func (ifq *ItemFieldQuery) Aggregate(fns ...AggregateFunc) *ItemFieldSelect {
|
||||
return ifq.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (ifq *ItemFieldQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, f := range ifq.fields {
|
||||
if !itemfield.ValidColumn(f) {
|
||||
@@ -573,8 +578,6 @@ func (ifgb *ItemFieldGroupBy) sqlQuery() *sql.Selector {
|
||||
for _, fn := range ifgb.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
// If no columns were selected in a custom aggregation function, the default
|
||||
// selection is the fields used for "group-by", and the aggregation functions.
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(ifgb.fields)+len(ifgb.fns))
|
||||
for _, f := range ifgb.fields {
|
||||
@@ -594,6 +597,12 @@ type ItemFieldSelect struct {
|
||||
sql *sql.Selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (ifs *ItemFieldSelect) Aggregate(fns ...AggregateFunc) *ItemFieldSelect {
|
||||
ifs.fns = append(ifs.fns, fns...)
|
||||
return ifs
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (ifs *ItemFieldSelect) Scan(ctx context.Context, v any) error {
|
||||
if err := ifs.prepareQuery(ctx); err != nil {
|
||||
@@ -604,6 +613,16 @@ func (ifs *ItemFieldSelect) Scan(ctx context.Context, v any) error {
|
||||
}
|
||||
|
||||
func (ifs *ItemFieldSelect) sqlScan(ctx context.Context, v any) error {
|
||||
aggregation := make([]string, 0, len(ifs.fns))
|
||||
for _, fn := range ifs.fns {
|
||||
aggregation = append(aggregation, fn(ifs.sql))
|
||||
}
|
||||
switch n := len(*ifs.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
ifs.sql.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
ifs.sql.AppendSelect(aggregation...)
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := ifs.sql.Query()
|
||||
if err := ifs.driver.Query(ctx, query, args, rows); err != nil {
|
||||
|
||||
@@ -286,85 +286,40 @@ func (ifu *ItemFieldUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
}
|
||||
}
|
||||
if value, ok := ifu.mutation.UpdatedAt(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: itemfield.FieldUpdatedAt,
|
||||
})
|
||||
_spec.SetField(itemfield.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := ifu.mutation.Name(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: itemfield.FieldName,
|
||||
})
|
||||
_spec.SetField(itemfield.FieldName, field.TypeString, value)
|
||||
}
|
||||
if value, ok := ifu.mutation.Description(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: itemfield.FieldDescription,
|
||||
})
|
||||
_spec.SetField(itemfield.FieldDescription, field.TypeString, value)
|
||||
}
|
||||
if ifu.mutation.DescriptionCleared() {
|
||||
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Column: itemfield.FieldDescription,
|
||||
})
|
||||
_spec.ClearField(itemfield.FieldDescription, field.TypeString)
|
||||
}
|
||||
if value, ok := ifu.mutation.GetType(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeEnum,
|
||||
Value: value,
|
||||
Column: itemfield.FieldType,
|
||||
})
|
||||
_spec.SetField(itemfield.FieldType, field.TypeEnum, value)
|
||||
}
|
||||
if value, ok := ifu.mutation.TextValue(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: itemfield.FieldTextValue,
|
||||
})
|
||||
_spec.SetField(itemfield.FieldTextValue, field.TypeString, value)
|
||||
}
|
||||
if ifu.mutation.TextValueCleared() {
|
||||
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Column: itemfield.FieldTextValue,
|
||||
})
|
||||
_spec.ClearField(itemfield.FieldTextValue, field.TypeString)
|
||||
}
|
||||
if value, ok := ifu.mutation.NumberValue(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: value,
|
||||
Column: itemfield.FieldNumberValue,
|
||||
})
|
||||
_spec.SetField(itemfield.FieldNumberValue, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := ifu.mutation.AddedNumberValue(); ok {
|
||||
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: value,
|
||||
Column: itemfield.FieldNumberValue,
|
||||
})
|
||||
_spec.AddField(itemfield.FieldNumberValue, field.TypeInt, value)
|
||||
}
|
||||
if ifu.mutation.NumberValueCleared() {
|
||||
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: itemfield.FieldNumberValue,
|
||||
})
|
||||
_spec.ClearField(itemfield.FieldNumberValue, field.TypeInt)
|
||||
}
|
||||
if value, ok := ifu.mutation.BooleanValue(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeBool,
|
||||
Value: value,
|
||||
Column: itemfield.FieldBooleanValue,
|
||||
})
|
||||
_spec.SetField(itemfield.FieldBooleanValue, field.TypeBool, value)
|
||||
}
|
||||
if value, ok := ifu.mutation.TimeValue(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: itemfield.FieldTimeValue,
|
||||
})
|
||||
_spec.SetField(itemfield.FieldTimeValue, field.TypeTime, value)
|
||||
}
|
||||
if ifu.mutation.ItemCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
@@ -706,85 +661,40 @@ func (ifuo *ItemFieldUpdateOne) sqlSave(ctx context.Context) (_node *ItemField,
|
||||
}
|
||||
}
|
||||
if value, ok := ifuo.mutation.UpdatedAt(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: itemfield.FieldUpdatedAt,
|
||||
})
|
||||
_spec.SetField(itemfield.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := ifuo.mutation.Name(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: itemfield.FieldName,
|
||||
})
|
||||
_spec.SetField(itemfield.FieldName, field.TypeString, value)
|
||||
}
|
||||
if value, ok := ifuo.mutation.Description(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: itemfield.FieldDescription,
|
||||
})
|
||||
_spec.SetField(itemfield.FieldDescription, field.TypeString, value)
|
||||
}
|
||||
if ifuo.mutation.DescriptionCleared() {
|
||||
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Column: itemfield.FieldDescription,
|
||||
})
|
||||
_spec.ClearField(itemfield.FieldDescription, field.TypeString)
|
||||
}
|
||||
if value, ok := ifuo.mutation.GetType(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeEnum,
|
||||
Value: value,
|
||||
Column: itemfield.FieldType,
|
||||
})
|
||||
_spec.SetField(itemfield.FieldType, field.TypeEnum, value)
|
||||
}
|
||||
if value, ok := ifuo.mutation.TextValue(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: itemfield.FieldTextValue,
|
||||
})
|
||||
_spec.SetField(itemfield.FieldTextValue, field.TypeString, value)
|
||||
}
|
||||
if ifuo.mutation.TextValueCleared() {
|
||||
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Column: itemfield.FieldTextValue,
|
||||
})
|
||||
_spec.ClearField(itemfield.FieldTextValue, field.TypeString)
|
||||
}
|
||||
if value, ok := ifuo.mutation.NumberValue(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: value,
|
||||
Column: itemfield.FieldNumberValue,
|
||||
})
|
||||
_spec.SetField(itemfield.FieldNumberValue, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := ifuo.mutation.AddedNumberValue(); ok {
|
||||
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: value,
|
||||
Column: itemfield.FieldNumberValue,
|
||||
})
|
||||
_spec.AddField(itemfield.FieldNumberValue, field.TypeInt, value)
|
||||
}
|
||||
if ifuo.mutation.NumberValueCleared() {
|
||||
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Column: itemfield.FieldNumberValue,
|
||||
})
|
||||
_spec.ClearField(itemfield.FieldNumberValue, field.TypeInt)
|
||||
}
|
||||
if value, ok := ifuo.mutation.BooleanValue(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeBool,
|
||||
Value: value,
|
||||
Column: itemfield.FieldBooleanValue,
|
||||
})
|
||||
_spec.SetField(itemfield.FieldBooleanValue, field.TypeBool, value)
|
||||
}
|
||||
if value, ok := ifuo.mutation.TimeValue(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: itemfield.FieldTimeValue,
|
||||
})
|
||||
_spec.SetField(itemfield.FieldTimeValue, field.TypeTime, value)
|
||||
}
|
||||
if ifuo.mutation.ItemCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
|
||||
@@ -282,43 +282,23 @@ func (lc *LabelCreate) createSpec() (*Label, *sqlgraph.CreateSpec) {
|
||||
_spec.ID.Value = &id
|
||||
}
|
||||
if value, ok := lc.mutation.CreatedAt(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: label.FieldCreatedAt,
|
||||
})
|
||||
_spec.SetField(label.FieldCreatedAt, field.TypeTime, value)
|
||||
_node.CreatedAt = value
|
||||
}
|
||||
if value, ok := lc.mutation.UpdatedAt(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: label.FieldUpdatedAt,
|
||||
})
|
||||
_spec.SetField(label.FieldUpdatedAt, field.TypeTime, value)
|
||||
_node.UpdatedAt = value
|
||||
}
|
||||
if value, ok := lc.mutation.Name(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: label.FieldName,
|
||||
})
|
||||
_spec.SetField(label.FieldName, field.TypeString, value)
|
||||
_node.Name = value
|
||||
}
|
||||
if value, ok := lc.mutation.Description(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: label.FieldDescription,
|
||||
})
|
||||
_spec.SetField(label.FieldDescription, field.TypeString, value)
|
||||
_node.Description = value
|
||||
}
|
||||
if value, ok := lc.mutation.Color(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: label.FieldColor,
|
||||
})
|
||||
_spec.SetField(label.FieldColor, field.TypeString, value)
|
||||
_node.Color = value
|
||||
}
|
||||
if nodes := lc.mutation.GroupIDs(); len(nodes) > 0 {
|
||||
|
||||
@@ -370,6 +370,11 @@ func (lq *LabelQuery) Select(fields ...string) *LabelSelect {
|
||||
return selbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a LabelSelect configured with the given aggregations.
|
||||
func (lq *LabelQuery) Aggregate(fns ...AggregateFunc) *LabelSelect {
|
||||
return lq.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (lq *LabelQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, f := range lq.fields {
|
||||
if !label.ValidColumn(f) {
|
||||
@@ -502,7 +507,7 @@ func (lq *LabelQuery) loadItems(ctx context.Context, query *ItemQuery, nodes []*
|
||||
outValue := *values[0].(*uuid.UUID)
|
||||
inValue := *values[1].(*uuid.UUID)
|
||||
if nids[inValue] == nil {
|
||||
nids[inValue] = map[*Label]struct{}{byID[outValue]: struct{}{}}
|
||||
nids[inValue] = map[*Label]struct{}{byID[outValue]: {}}
|
||||
return assign(columns[1:], values[1:])
|
||||
}
|
||||
nids[inValue][byID[outValue]] = struct{}{}
|
||||
@@ -676,8 +681,6 @@ func (lgb *LabelGroupBy) sqlQuery() *sql.Selector {
|
||||
for _, fn := range lgb.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
// If no columns were selected in a custom aggregation function, the default
|
||||
// selection is the fields used for "group-by", and the aggregation functions.
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(lgb.fields)+len(lgb.fns))
|
||||
for _, f := range lgb.fields {
|
||||
@@ -697,6 +700,12 @@ type LabelSelect struct {
|
||||
sql *sql.Selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (ls *LabelSelect) Aggregate(fns ...AggregateFunc) *LabelSelect {
|
||||
ls.fns = append(ls.fns, fns...)
|
||||
return ls
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (ls *LabelSelect) Scan(ctx context.Context, v any) error {
|
||||
if err := ls.prepareQuery(ctx); err != nil {
|
||||
@@ -707,6 +716,16 @@ func (ls *LabelSelect) Scan(ctx context.Context, v any) error {
|
||||
}
|
||||
|
||||
func (ls *LabelSelect) sqlScan(ctx context.Context, v any) error {
|
||||
aggregation := make([]string, 0, len(ls.fns))
|
||||
for _, fn := range ls.fns {
|
||||
aggregation = append(aggregation, fn(ls.sql))
|
||||
}
|
||||
switch n := len(*ls.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
ls.sql.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
ls.sql.AppendSelect(aggregation...)
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := ls.sql.Query()
|
||||
if err := ls.driver.Query(ctx, query, args, rows); err != nil {
|
||||
|
||||
@@ -252,44 +252,22 @@ func (lu *LabelUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
}
|
||||
}
|
||||
if value, ok := lu.mutation.UpdatedAt(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: label.FieldUpdatedAt,
|
||||
})
|
||||
_spec.SetField(label.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := lu.mutation.Name(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: label.FieldName,
|
||||
})
|
||||
_spec.SetField(label.FieldName, field.TypeString, value)
|
||||
}
|
||||
if value, ok := lu.mutation.Description(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: label.FieldDescription,
|
||||
})
|
||||
_spec.SetField(label.FieldDescription, field.TypeString, value)
|
||||
}
|
||||
if lu.mutation.DescriptionCleared() {
|
||||
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Column: label.FieldDescription,
|
||||
})
|
||||
_spec.ClearField(label.FieldDescription, field.TypeString)
|
||||
}
|
||||
if value, ok := lu.mutation.Color(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: label.FieldColor,
|
||||
})
|
||||
_spec.SetField(label.FieldColor, field.TypeString, value)
|
||||
}
|
||||
if lu.mutation.ColorCleared() {
|
||||
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Column: label.FieldColor,
|
||||
})
|
||||
_spec.ClearField(label.FieldColor, field.TypeString)
|
||||
}
|
||||
if lu.mutation.GroupCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
@@ -650,44 +628,22 @@ func (luo *LabelUpdateOne) sqlSave(ctx context.Context) (_node *Label, err error
|
||||
}
|
||||
}
|
||||
if value, ok := luo.mutation.UpdatedAt(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: label.FieldUpdatedAt,
|
||||
})
|
||||
_spec.SetField(label.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := luo.mutation.Name(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: label.FieldName,
|
||||
})
|
||||
_spec.SetField(label.FieldName, field.TypeString, value)
|
||||
}
|
||||
if value, ok := luo.mutation.Description(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: label.FieldDescription,
|
||||
})
|
||||
_spec.SetField(label.FieldDescription, field.TypeString, value)
|
||||
}
|
||||
if luo.mutation.DescriptionCleared() {
|
||||
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Column: label.FieldDescription,
|
||||
})
|
||||
_spec.ClearField(label.FieldDescription, field.TypeString)
|
||||
}
|
||||
if value, ok := luo.mutation.Color(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: label.FieldColor,
|
||||
})
|
||||
_spec.SetField(label.FieldColor, field.TypeString, value)
|
||||
}
|
||||
if luo.mutation.ColorCleared() {
|
||||
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Column: label.FieldColor,
|
||||
})
|
||||
_spec.ClearField(label.FieldColor, field.TypeString)
|
||||
}
|
||||
if luo.mutation.GroupCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
|
||||
@@ -297,35 +297,19 @@ func (lc *LocationCreate) createSpec() (*Location, *sqlgraph.CreateSpec) {
|
||||
_spec.ID.Value = &id
|
||||
}
|
||||
if value, ok := lc.mutation.CreatedAt(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: location.FieldCreatedAt,
|
||||
})
|
||||
_spec.SetField(location.FieldCreatedAt, field.TypeTime, value)
|
||||
_node.CreatedAt = value
|
||||
}
|
||||
if value, ok := lc.mutation.UpdatedAt(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: location.FieldUpdatedAt,
|
||||
})
|
||||
_spec.SetField(location.FieldUpdatedAt, field.TypeTime, value)
|
||||
_node.UpdatedAt = value
|
||||
}
|
||||
if value, ok := lc.mutation.Name(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: location.FieldName,
|
||||
})
|
||||
_spec.SetField(location.FieldName, field.TypeString, value)
|
||||
_node.Name = value
|
||||
}
|
||||
if value, ok := lc.mutation.Description(); ok {
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: location.FieldDescription,
|
||||
})
|
||||
_spec.SetField(location.FieldDescription, field.TypeString, value)
|
||||
_node.Description = value
|
||||
}
|
||||
if nodes := lc.mutation.ParentIDs(); len(nodes) > 0 {
|
||||
|
||||
@@ -440,6 +440,11 @@ func (lq *LocationQuery) Select(fields ...string) *LocationSelect {
|
||||
return selbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a LocationSelect configured with the given aggregations.
|
||||
func (lq *LocationQuery) Aggregate(fns ...AggregateFunc) *LocationSelect {
|
||||
return lq.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (lq *LocationQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, f := range lq.fields {
|
||||
if !location.ValidColumn(f) {
|
||||
@@ -794,8 +799,6 @@ func (lgb *LocationGroupBy) sqlQuery() *sql.Selector {
|
||||
for _, fn := range lgb.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
// If no columns were selected in a custom aggregation function, the default
|
||||
// selection is the fields used for "group-by", and the aggregation functions.
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(lgb.fields)+len(lgb.fns))
|
||||
for _, f := range lgb.fields {
|
||||
@@ -815,6 +818,12 @@ type LocationSelect struct {
|
||||
sql *sql.Selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (ls *LocationSelect) Aggregate(fns ...AggregateFunc) *LocationSelect {
|
||||
ls.fns = append(ls.fns, fns...)
|
||||
return ls
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (ls *LocationSelect) Scan(ctx context.Context, v any) error {
|
||||
if err := ls.prepareQuery(ctx); err != nil {
|
||||
@@ -825,6 +834,16 @@ func (ls *LocationSelect) Scan(ctx context.Context, v any) error {
|
||||
}
|
||||
|
||||
func (ls *LocationSelect) sqlScan(ctx context.Context, v any) error {
|
||||
aggregation := make([]string, 0, len(ls.fns))
|
||||
for _, fn := range ls.fns {
|
||||
aggregation = append(aggregation, fn(ls.sql))
|
||||
}
|
||||
switch n := len(*ls.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
ls.sql.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
ls.sql.AppendSelect(aggregation...)
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := ls.sql.Query()
|
||||
if err := ls.driver.Query(ctx, query, args, rows); err != nil {
|
||||
|
||||
@@ -288,31 +288,16 @@ func (lu *LocationUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
}
|
||||
}
|
||||
if value, ok := lu.mutation.UpdatedAt(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: location.FieldUpdatedAt,
|
||||
})
|
||||
_spec.SetField(location.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := lu.mutation.Name(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: location.FieldName,
|
||||
})
|
||||
_spec.SetField(location.FieldName, field.TypeString, value)
|
||||
}
|
||||
if value, ok := lu.mutation.Description(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: location.FieldDescription,
|
||||
})
|
||||
_spec.SetField(location.FieldDescription, field.TypeString, value)
|
||||
}
|
||||
if lu.mutation.DescriptionCleared() {
|
||||
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Column: location.FieldDescription,
|
||||
})
|
||||
_spec.ClearField(location.FieldDescription, field.TypeString)
|
||||
}
|
||||
if lu.mutation.ParentCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
@@ -798,31 +783,16 @@ func (luo *LocationUpdateOne) sqlSave(ctx context.Context) (_node *Location, err
|
||||
}
|
||||
}
|
||||
if value, ok := luo.mutation.UpdatedAt(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeTime,
|
||||
Value: value,
|
||||
Column: location.FieldUpdatedAt,
|
||||
})
|
||||
_spec.SetField(location.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := luo.mutation.Name(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: location.FieldName,
|
||||
})
|
||||
_spec.SetField(location.FieldName, field.TypeString, value)
|
||||
}
|
||||
if value, ok := luo.mutation.Description(); ok {
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: value,
|
||||
Column: location.FieldDescription,
|
||||
})
|
||||
_spec.SetField(location.FieldDescription, field.TypeString, value)
|
||||
}
|
||||
if luo.mutation.DescriptionCleared() {
|
||||
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Column: location.FieldDescription,
|
||||
})
|
||||
_spec.ClearField(location.FieldDescription, field.TypeString)
|
||||
}
|
||||
if luo.mutation.ParentCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
|
||||
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
|
||||
}
|
||||
@@ -37,6 +37,26 @@ var (
|
||||
},
|
||||
},
|
||||
}
|
||||
// AuthRolesColumns holds the columns for the "auth_roles" table.
|
||||
AuthRolesColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "role", Type: field.TypeEnum, Enums: []string{"admin", "user", "attachments"}, Default: "user"},
|
||||
{Name: "auth_tokens_roles", Type: field.TypeUUID, Unique: true, Nullable: true},
|
||||
}
|
||||
// AuthRolesTable holds the schema information for the "auth_roles" table.
|
||||
AuthRolesTable = &schema.Table{
|
||||
Name: "auth_roles",
|
||||
Columns: AuthRolesColumns,
|
||||
PrimaryKey: []*schema.Column{AuthRolesColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "auth_roles_auth_tokens_roles",
|
||||
Columns: []*schema.Column{AuthRolesColumns[2]},
|
||||
RefColumns: []*schema.Column{AuthTokensColumns[0]},
|
||||
OnDelete: schema.Cascade,
|
||||
},
|
||||
},
|
||||
}
|
||||
// AuthTokensColumns holds the columns for the "auth_tokens" table.
|
||||
AuthTokensColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeUUID},
|
||||
@@ -90,44 +110,13 @@ 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 = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeUUID},
|
||||
{Name: "created_at", Type: field.TypeTime},
|
||||
{Name: "updated_at", Type: field.TypeTime},
|
||||
{Name: "name", Type: field.TypeString, Size: 255},
|
||||
{Name: "currency", Type: field.TypeEnum, Enums: []string{"usd", "eur", "gbp", "jpy", "zar", "aud", "nok", "sek", "dkk"}, Default: "usd"},
|
||||
{Name: "currency", Type: field.TypeEnum, Enums: []string{"usd", "eur", "gbp", "jpy", "zar", "aud", "nok", "sek", "dkk", "inr", "rmb"}, Default: "usd"},
|
||||
}
|
||||
// GroupsTable holds the schema information for the "groups" table.
|
||||
GroupsTable = &schema.Table{
|
||||
@@ -171,6 +160,7 @@ var (
|
||||
{Name: "quantity", Type: field.TypeInt, Default: 1},
|
||||
{Name: "insured", Type: field.TypeBool, Default: false},
|
||||
{Name: "archived", Type: field.TypeBool, Default: false},
|
||||
{Name: "asset_id", Type: field.TypeInt, Default: 0},
|
||||
{Name: "serial_number", Type: field.TypeString, Nullable: true, Size: 255},
|
||||
{Name: "model_number", Type: field.TypeString, Nullable: true, Size: 255},
|
||||
{Name: "manufacturer", Type: field.TypeString, Nullable: true, Size: 255},
|
||||
@@ -196,19 +186,19 @@ var (
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "items_groups_items",
|
||||
Columns: []*schema.Column{ItemsColumns[23]},
|
||||
Columns: []*schema.Column{ItemsColumns[24]},
|
||||
RefColumns: []*schema.Column{GroupsColumns[0]},
|
||||
OnDelete: schema.Cascade,
|
||||
},
|
||||
{
|
||||
Symbol: "items_items_children",
|
||||
Columns: []*schema.Column{ItemsColumns[24]},
|
||||
Columns: []*schema.Column{ItemsColumns[25]},
|
||||
RefColumns: []*schema.Column{ItemsColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
{
|
||||
Symbol: "items_locations_items",
|
||||
Columns: []*schema.Column{ItemsColumns[25]},
|
||||
Columns: []*schema.Column{ItemsColumns[26]},
|
||||
RefColumns: []*schema.Column{LocationsColumns[0]},
|
||||
OnDelete: schema.Cascade,
|
||||
},
|
||||
@@ -222,23 +212,28 @@ var (
|
||||
{
|
||||
Name: "item_manufacturer",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{ItemsColumns[12]},
|
||||
Columns: []*schema.Column{ItemsColumns[13]},
|
||||
},
|
||||
{
|
||||
Name: "item_model_number",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{ItemsColumns[11]},
|
||||
Columns: []*schema.Column{ItemsColumns[12]},
|
||||
},
|
||||
{
|
||||
Name: "item_serial_number",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{ItemsColumns[10]},
|
||||
Columns: []*schema.Column{ItemsColumns[11]},
|
||||
},
|
||||
{
|
||||
Name: "item_archived",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{ItemsColumns[9]},
|
||||
},
|
||||
{
|
||||
Name: "item_asset_id",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{ItemsColumns[10]},
|
||||
},
|
||||
},
|
||||
}
|
||||
// ItemFieldsColumns holds the columns for the "item_fields" table.
|
||||
@@ -323,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 = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeUUID},
|
||||
@@ -379,15 +399,16 @@ var (
|
||||
// Tables holds all the tables in the schema.
|
||||
Tables = []*schema.Table{
|
||||
AttachmentsTable,
|
||||
AuthRolesTable,
|
||||
AuthTokensTable,
|
||||
DocumentsTable,
|
||||
DocumentTokensTable,
|
||||
GroupsTable,
|
||||
GroupInvitationTokensTable,
|
||||
ItemsTable,
|
||||
ItemFieldsTable,
|
||||
LabelsTable,
|
||||
LocationsTable,
|
||||
MaintenanceEntriesTable,
|
||||
UsersTable,
|
||||
LabelItemsTable,
|
||||
}
|
||||
@@ -396,9 +417,9 @@ var (
|
||||
func init() {
|
||||
AttachmentsTable.ForeignKeys[0].RefTable = DocumentsTable
|
||||
AttachmentsTable.ForeignKeys[1].RefTable = ItemsTable
|
||||
AuthRolesTable.ForeignKeys[0].RefTable = AuthTokensTable
|
||||
AuthTokensTable.ForeignKeys[0].RefTable = UsersTable
|
||||
DocumentsTable.ForeignKeys[0].RefTable = GroupsTable
|
||||
DocumentTokensTable.ForeignKeys[0].RefTable = DocumentsTable
|
||||
GroupInvitationTokensTable.ForeignKeys[0].RefTable = GroupsTable
|
||||
ItemsTable.ForeignKeys[0].RefTable = GroupsTable
|
||||
ItemsTable.ForeignKeys[1].RefTable = ItemsTable
|
||||
@@ -407,6 +428,7 @@ func init() {
|
||||
LabelsTable.ForeignKeys[0].RefTable = GroupsTable
|
||||
LocationsTable.ForeignKeys[0].RefTable = GroupsTable
|
||||
LocationsTable.ForeignKeys[1].RefTable = LocationsTable
|
||||
MaintenanceEntriesTable.ForeignKeys[0].RefTable = ItemsTable
|
||||
UsersTable.ForeignKeys[0].RefTable = GroupsTable
|
||||
LabelItemsTable.ForeignKeys[0].RefTable = LabelsTable
|
||||
LabelItemsTable.ForeignKeys[1].RefTable = ItemsTable
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -9,15 +9,15 @@ import (
|
||||
// Attachment is the predicate function for attachment builders.
|
||||
type Attachment func(*sql.Selector)
|
||||
|
||||
// AuthRoles is the predicate function for authroles builders.
|
||||
type AuthRoles func(*sql.Selector)
|
||||
|
||||
// AuthTokens is the predicate function for authtokens builders.
|
||||
type AuthTokens func(*sql.Selector)
|
||||
|
||||
// Document is the predicate function for document builders.
|
||||
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.
|
||||
type Group func(*sql.Selector)
|
||||
|
||||
@@ -36,5 +36,8 @@ type Label func(*sql.Selector)
|
||||
// Location is the predicate function for location builders.
|
||||
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.
|
||||
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/authtokens"
|
||||
"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/groupinvitationtoken"
|
||||
"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/label"
|
||||
"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/user"
|
||||
)
|
||||
@@ -43,6 +43,8 @@ func init() {
|
||||
attachmentDescID := attachmentMixinFields0[0].Descriptor()
|
||||
// attachment.DefaultID holds the default value on creation for the id field.
|
||||
attachment.DefaultID = attachmentDescID.Default.(func() uuid.UUID)
|
||||
authrolesFields := schema.AuthRoles{}.Fields()
|
||||
_ = authrolesFields
|
||||
authtokensMixin := schema.AuthTokens{}.Mixin()
|
||||
authtokensMixinFields0 := authtokensMixin[0].Fields()
|
||||
_ = authtokensMixinFields0
|
||||
@@ -121,37 +123,6 @@ func init() {
|
||||
documentDescID := documentMixinFields0[0].Descriptor()
|
||||
// document.DefaultID holds the default value on creation for the id field.
|
||||
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()
|
||||
groupMixinFields0 := groupMixin[0].Fields()
|
||||
_ = groupMixinFields0
|
||||
@@ -275,36 +246,40 @@ func init() {
|
||||
itemDescArchived := itemFields[4].Descriptor()
|
||||
// item.DefaultArchived holds the default value on creation for the archived field.
|
||||
item.DefaultArchived = itemDescArchived.Default.(bool)
|
||||
// itemDescAssetID is the schema descriptor for asset_id field.
|
||||
itemDescAssetID := itemFields[5].Descriptor()
|
||||
// item.DefaultAssetID holds the default value on creation for the asset_id field.
|
||||
item.DefaultAssetID = itemDescAssetID.Default.(int)
|
||||
// itemDescSerialNumber is the schema descriptor for serial_number field.
|
||||
itemDescSerialNumber := itemFields[5].Descriptor()
|
||||
itemDescSerialNumber := itemFields[6].Descriptor()
|
||||
// item.SerialNumberValidator is a validator for the "serial_number" field. It is called by the builders before save.
|
||||
item.SerialNumberValidator = itemDescSerialNumber.Validators[0].(func(string) error)
|
||||
// itemDescModelNumber is the schema descriptor for model_number field.
|
||||
itemDescModelNumber := itemFields[6].Descriptor()
|
||||
itemDescModelNumber := itemFields[7].Descriptor()
|
||||
// item.ModelNumberValidator is a validator for the "model_number" field. It is called by the builders before save.
|
||||
item.ModelNumberValidator = itemDescModelNumber.Validators[0].(func(string) error)
|
||||
// itemDescManufacturer is the schema descriptor for manufacturer field.
|
||||
itemDescManufacturer := itemFields[7].Descriptor()
|
||||
itemDescManufacturer := itemFields[8].Descriptor()
|
||||
// item.ManufacturerValidator is a validator for the "manufacturer" field. It is called by the builders before save.
|
||||
item.ManufacturerValidator = itemDescManufacturer.Validators[0].(func(string) error)
|
||||
// itemDescLifetimeWarranty is the schema descriptor for lifetime_warranty field.
|
||||
itemDescLifetimeWarranty := itemFields[8].Descriptor()
|
||||
itemDescLifetimeWarranty := itemFields[9].Descriptor()
|
||||
// item.DefaultLifetimeWarranty holds the default value on creation for the lifetime_warranty field.
|
||||
item.DefaultLifetimeWarranty = itemDescLifetimeWarranty.Default.(bool)
|
||||
// itemDescWarrantyDetails is the schema descriptor for warranty_details field.
|
||||
itemDescWarrantyDetails := itemFields[10].Descriptor()
|
||||
itemDescWarrantyDetails := itemFields[11].Descriptor()
|
||||
// item.WarrantyDetailsValidator is a validator for the "warranty_details" field. It is called by the builders before save.
|
||||
item.WarrantyDetailsValidator = itemDescWarrantyDetails.Validators[0].(func(string) error)
|
||||
// itemDescPurchasePrice is the schema descriptor for purchase_price field.
|
||||
itemDescPurchasePrice := itemFields[13].Descriptor()
|
||||
itemDescPurchasePrice := itemFields[14].Descriptor()
|
||||
// item.DefaultPurchasePrice holds the default value on creation for the purchase_price field.
|
||||
item.DefaultPurchasePrice = itemDescPurchasePrice.Default.(float64)
|
||||
// itemDescSoldPrice is the schema descriptor for sold_price field.
|
||||
itemDescSoldPrice := itemFields[16].Descriptor()
|
||||
itemDescSoldPrice := itemFields[17].Descriptor()
|
||||
// item.DefaultSoldPrice holds the default value on creation for the sold_price field.
|
||||
item.DefaultSoldPrice = itemDescSoldPrice.Default.(float64)
|
||||
// itemDescSoldNotes is the schema descriptor for sold_notes field.
|
||||
itemDescSoldNotes := itemFields[17].Descriptor()
|
||||
itemDescSoldNotes := itemFields[18].Descriptor()
|
||||
// item.SoldNotesValidator is a validator for the "sold_notes" field. It is called by the builders before save.
|
||||
item.SoldNotesValidator = itemDescSoldNotes.Validators[0].(func(string) error)
|
||||
// itemDescID is the schema descriptor for id field.
|
||||
@@ -456,6 +431,55 @@ func init() {
|
||||
locationDescID := locationMixinFields0[0].Descriptor()
|
||||
// location.DefaultID holds the default value on creation for the id field.
|
||||
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()
|
||||
userMixinFields0 := userMixin[0].Fields()
|
||||
_ = userMixinFields0
|
||||
|
||||
@@ -5,6 +5,6 @@ package runtime
|
||||
// The schema-stitching logic is generated in github.com/hay-kot/homebox/backend/internal/data/ent/runtime.go
|
||||
|
||||
const (
|
||||
Version = "v0.11.3" // Version of ent codegen.
|
||||
Sum = "h1:F5FBGAWiDCGder7YT+lqMnyzXl6d0xU3xMBM/SO3CMc=" // Sum of ent codegen.
|
||||
Version = "v0.11.4" // Version of ent codegen.
|
||||
Sum = "h1:grwVY0fp31BZ6oEo3YrXenAuv8VJmEw7F/Bi6WqeH3Q=" // Sum of ent codegen.
|
||||
)
|
||||
|
||||
34
backend/internal/data/ent/schema/auth_roles.go
Normal file
34
backend/internal/data/ent/schema/auth_roles.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// AuthRoles holds the schema definition for the AuthRoles entity.
|
||||
type AuthRoles struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the AuthRoles.
|
||||
func (AuthRoles) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Enum("role").
|
||||
Default("user").
|
||||
Values(
|
||||
"admin", // can do everything - currently unused
|
||||
"user", // default login role
|
||||
"attachments", // Read Attachments
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the AuthRoles.
|
||||
func (AuthRoles) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("token", AuthTokens.Type).
|
||||
Ref("roles").
|
||||
Unique(),
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/entsql"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/index"
|
||||
@@ -37,6 +38,11 @@ func (AuthTokens) Edges() []ent.Edge {
|
||||
edge.From("user", User.Type).
|
||||
Ref("auth_tokens").
|
||||
Unique(),
|
||||
edge.To("roles", AuthRoles.Type).
|
||||
Unique().
|
||||
Annotations(entsql.Annotation{
|
||||
OnDelete: entsql.Cascade,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,10 +38,6 @@ func (Document) Edges() []ent.Edge {
|
||||
Ref("documents").
|
||||
Required().
|
||||
Unique(),
|
||||
edge.To("document_tokens", DocumentToken.Type).
|
||||
Annotations(entsql.Annotation{
|
||||
OnDelete: entsql.Cascade,
|
||||
}),
|
||||
edge.To("attachments", Attachment.Type).
|
||||
Annotations(entsql.Annotation{
|
||||
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"),
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ func (Group) Fields() []ent.Field {
|
||||
NotEmpty(),
|
||||
field.Enum("currency").
|
||||
Default("usd").
|
||||
Values("usd", "eur", "gbp", "jpy", "zar", "aud", "nok", "sek", "dkk"),
|
||||
Values("usd", "eur", "gbp", "jpy", "zar", "aud", "nok", "sek", "dkk", "inr", "rmb"),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ func (Item) Indexes() []ent.Index {
|
||||
index.Fields("model_number"),
|
||||
index.Fields("serial_number"),
|
||||
index.Fields("archived"),
|
||||
index.Fields("asset_id"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +49,8 @@ func (Item) Fields() []ent.Field {
|
||||
Default(false),
|
||||
field.Bool("archived").
|
||||
Default(false),
|
||||
field.Int("asset_id").
|
||||
Default(0),
|
||||
|
||||
// ------------------------------------
|
||||
// item identification
|
||||
@@ -113,6 +116,10 @@ func (Item) Edges() []ent.Edge {
|
||||
Annotations(entsql.Annotation{
|
||||
OnDelete: entsql.Cascade,
|
||||
}),
|
||||
edge.To("maintenance_entries", MaintenanceEntry.Type).
|
||||
Annotations(entsql.Annotation{
|
||||
OnDelete: entsql.Cascade,
|
||||
}),
|
||||
edge.To("attachments", Attachment.Type).
|
||||
Annotations(entsql.Annotation{
|
||||
OnDelete: entsql.Cascade,
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user