mirror of
https://github.com/hay-kot/homebox.git
synced 2025-08-04 00:30:27 +00:00
generate API types
This commit is contained in:
parent
7b25878c89
commit
8a4207a5be
6 changed files with 67 additions and 12 deletions
|
@ -47,6 +47,14 @@ func (ctrl *V1Controller) HandleItemsGetAll() server.HandlerFunc {
|
|||
return i
|
||||
}
|
||||
|
||||
getBool := func(s string) bool {
|
||||
b, err := strconv.ParseBool(s)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
extractQuery := func(r *http.Request) repo.ItemQuery {
|
||||
params := r.URL.Query()
|
||||
|
||||
|
@ -56,6 +64,7 @@ func (ctrl *V1Controller) HandleItemsGetAll() server.HandlerFunc {
|
|||
Search: params.Get("q"),
|
||||
LocationIDs: uuidList(params, "locations"),
|
||||
LabelIDs: uuidList(params, "labels"),
|
||||
IncludeArchived: getBool(params.Get("includeArchived")),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1274,6 +1274,9 @@ const docTemplate = `{
|
|||
"repo.ItemOut": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"archived": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"attachments": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
|
@ -1383,6 +1386,9 @@ const docTemplate = `{
|
|||
"repo.ItemSummary": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"archived": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"createdAt": {
|
||||
"type": "string"
|
||||
},
|
||||
|
@ -1421,6 +1427,9 @@ const docTemplate = `{
|
|||
"repo.ItemUpdate": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"archived": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"description": {
|
||||
"type": "string"
|
||||
},
|
||||
|
|
|
@ -1266,6 +1266,9 @@
|
|||
"repo.ItemOut": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"archived": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"attachments": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
|
@ -1375,6 +1378,9 @@
|
|||
"repo.ItemSummary": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"archived": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"createdAt": {
|
||||
"type": "string"
|
||||
},
|
||||
|
@ -1413,6 +1419,9 @@
|
|||
"repo.ItemUpdate": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"archived": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"description": {
|
||||
"type": "string"
|
||||
},
|
||||
|
|
|
@ -85,6 +85,8 @@ definitions:
|
|||
type: object
|
||||
repo.ItemOut:
|
||||
properties:
|
||||
archived:
|
||||
type: boolean
|
||||
attachments:
|
||||
items:
|
||||
$ref: '#/definitions/repo.ItemAttachment'
|
||||
|
@ -161,6 +163,8 @@ definitions:
|
|||
type: object
|
||||
repo.ItemSummary:
|
||||
properties:
|
||||
archived:
|
||||
type: boolean
|
||||
createdAt:
|
||||
type: string
|
||||
description:
|
||||
|
@ -187,6 +191,8 @@ definitions:
|
|||
type: object
|
||||
repo.ItemUpdate:
|
||||
properties:
|
||||
archived:
|
||||
type: boolean
|
||||
description:
|
||||
type: string
|
||||
fields:
|
||||
|
|
|
@ -26,6 +26,7 @@ type (
|
|||
LocationIDs []uuid.UUID `json:"locationIds"`
|
||||
LabelIDs []uuid.UUID `json:"labelIds"`
|
||||
SortBy string `json:"sortBy"`
|
||||
IncludeArchived bool `json:"includeArchived"`
|
||||
}
|
||||
|
||||
ItemField struct {
|
||||
|
@ -55,6 +56,7 @@ type (
|
|||
Description string `json:"description"`
|
||||
Quantity int `json:"quantity"`
|
||||
Insured bool `json:"insured"`
|
||||
Archived bool `json:"archived"`
|
||||
|
||||
// Edges
|
||||
LocationID uuid.UUID `json:"locationId"`
|
||||
|
@ -93,6 +95,7 @@ type (
|
|||
Description string `json:"description"`
|
||||
Quantity int `json:"quantity"`
|
||||
Insured bool `json:"insured"`
|
||||
Archived bool `json:"archived"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
|
||||
|
@ -157,6 +160,7 @@ func mapItemSummary(item *ent.Item) ItemSummary {
|
|||
Quantity: item.Quantity,
|
||||
CreatedAt: item.CreatedAt,
|
||||
UpdatedAt: item.UpdatedAt,
|
||||
Archived: item.Archived,
|
||||
|
||||
// Edges
|
||||
Location: location,
|
||||
|
@ -276,7 +280,21 @@ func (e *ItemsRepository) GetOneByGroup(ctx context.Context, gid, id uuid.UUID)
|
|||
|
||||
// QueryByGroup returns a list of items that belong to a specific group based on the provided query.
|
||||
func (e *ItemsRepository) QueryByGroup(ctx context.Context, gid uuid.UUID, q ItemQuery) (PaginationResult[ItemSummary], error) {
|
||||
qb := e.db.Item.Query().Where(item.HasGroupWith(group.ID(gid)))
|
||||
qb := e.db.Item.Query().Where(
|
||||
item.HasGroupWith(group.ID(gid)),
|
||||
)
|
||||
|
||||
if q.IncludeArchived {
|
||||
println("include archived")
|
||||
qb = qb.Where(
|
||||
item.Or(
|
||||
item.Archived(true),
|
||||
item.Archived(false),
|
||||
),
|
||||
)
|
||||
} else {
|
||||
qb = qb.Where(item.Archived(false))
|
||||
}
|
||||
|
||||
if len(q.LabelIDs) > 0 {
|
||||
labels := make([]predicate.Item, 0, len(q.LabelIDs))
|
||||
|
@ -384,6 +402,7 @@ func (e *ItemsRepository) UpdateByGroup(ctx context.Context, gid uuid.UUID, data
|
|||
SetSerialNumber(data.SerialNumber).
|
||||
SetModelNumber(data.ModelNumber).
|
||||
SetManufacturer(data.Manufacturer).
|
||||
SetArchived(data.Archived).
|
||||
SetPurchaseTime(data.PurchaseTime).
|
||||
SetPurchaseFrom(data.PurchaseFrom).
|
||||
SetPurchasePrice(data.PurchasePrice).
|
||||
|
|
|
@ -63,6 +63,7 @@ export interface ItemField {
|
|||
}
|
||||
|
||||
export interface ItemOut {
|
||||
archived: boolean;
|
||||
attachments: ItemAttachment[];
|
||||
children: ItemSummary[];
|
||||
createdAt: Date;
|
||||
|
@ -107,6 +108,7 @@ export interface ItemOut {
|
|||
}
|
||||
|
||||
export interface ItemSummary {
|
||||
archived: boolean;
|
||||
createdAt: Date;
|
||||
description: string;
|
||||
id: string;
|
||||
|
@ -121,6 +123,7 @@ export interface ItemSummary {
|
|||
}
|
||||
|
||||
export interface ItemUpdate {
|
||||
archived: boolean;
|
||||
description: string;
|
||||
fields: ItemField[];
|
||||
id: string;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue