Skip to content

Commit

Permalink
add amount_per_bundle ref_bundle fournisseur in item and create a pag…
Browse files Browse the repository at this point in the history
…e to modify it
  • Loading branch information
BaptTF committed Apr 26, 2024
1 parent e484308 commit 8dbec9f
Show file tree
Hide file tree
Showing 12 changed files with 1,219 additions and 171 deletions.
21 changes: 17 additions & 4 deletions backend/api/items.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ func (s *Server) GetCategoryItems(c echo.Context, categoryId autogen.UUID, param
return Error500(c)
}

count, err := s.DBackend.CountItems(c.Request().Context(), categoryId.String(), state, "")
count, err := s.DBackend.CountItems(c.Request().Context(), categoryId.String(), state, "", "")
if err != nil {
return Error500(c)
}

// Make sure the last page is not empty
dbpage, page, limit, maxPage := autogen.Pager(params.Page, params.Limit, &count)

data, err := s.DBackend.GetItems(c.Request().Context(), categoryId.String(), dbpage, limit, state, "")
data, err := s.DBackend.GetItems(c.Request().Context(), categoryId.String(), dbpage, limit, state, "", "")
if err != nil {
return Error500(c)
}
Expand Down Expand Up @@ -174,6 +174,15 @@ func (s *Server) PatchItem(c echo.Context, categoryId autogen.UUID, itemId autog
item.BuyLimit = &buyLimit
}
}
if p.AmountPerBundle != nil {
item.AmountPerBundle = p.AmountPerBundle
}
if p.RefBundle != nil {
item.RefBundle = p.RefBundle
}
if p.Fournisseur != nil {
item.Fournisseur = p.Fournisseur
}

rp := item.RealPrices()
item.DisplayPrices = &rp
Expand Down Expand Up @@ -238,6 +247,7 @@ func (s *Server) GetAllItems(c echo.Context, params autogen.GetAllItemsParams) e
state := ""
categoryId := ""
name := ""
fournisseur := ""
if params.State != nil {
state = string(*params.State)
}
Expand All @@ -247,8 +257,11 @@ func (s *Server) GetAllItems(c echo.Context, params autogen.GetAllItemsParams) e
if params.Name != nil {
name = string(*params.Name)
}
if params.Fournisseur != nil {
fournisseur = string(*params.Fournisseur)
}

count, err := s.DBackend.CountItems(c.Request().Context(), categoryId, state, name)
count, err := s.DBackend.CountItems(c.Request().Context(), categoryId, state, name, fournisseur)
if err != nil {
logrus.Error(err)
return Error500(c)
Expand All @@ -257,7 +270,7 @@ func (s *Server) GetAllItems(c echo.Context, params autogen.GetAllItemsParams) e
// Make sure the last page is not empty
dbpage, page, limit, maxPage := autogen.Pager(params.Page, params.Limit, &count)

data, err := s.DBackend.GetItems(c.Request().Context(), categoryId, dbpage, limit, state, name)
data, err := s.DBackend.GetItems(c.Request().Context(), categoryId, dbpage, limit, state, name, fournisseur)
if err != nil {
logrus.Error(err)
return Error500(c)
Expand Down
313 changes: 166 additions & 147 deletions backend/autogen/bar.gen.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions backend/internal/db/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ type DBackend interface {
CountAccounts(ctx context.Context, query string) (uint64, error)
GetRefills(ctx context.Context, account string, page uint64, size uint64, startAt, endAt uint64) ([]*models.Refill, error)
CountRefills(ctx context.Context, account string, startAt, endAt uint64) (uint64, error)
GetItems(ctx context.Context, categoryID string, page, size uint64, state string, name string) ([]*models.Item, error)
CountItems(ctx context.Context, categoryID string, state string, name string) (uint64, error)
GetItems(ctx context.Context, categoryID string, page, size uint64, state string, name string, fournisseur string) ([]*models.Item, error)
CountItems(ctx context.Context, categoryID string, state string, name string, fournisseur string) (uint64, error)

GetAllRefills(ctx context.Context, page uint64, size uint64, startAt, endAt uint64) ([]*models.Refill, error)
CountAllRefills(ctx context.Context, startAt, endAt uint64) (uint64, error)
Expand Down
12 changes: 9 additions & 3 deletions backend/internal/db/mongo/item_misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"go.mongodb.org/mongo-driver/mongo/options"
)

func (b *Backend) GetItems(ctx context.Context, categoryID string, page, size uint64, state string, name string) ([]*models.Item, error) {
func (b *Backend) GetItems(ctx context.Context, categoryID string, page, size uint64, state string, name string, fournisseur string) ([]*models.Item, error) {
ctx, cancel := b.TimeoutContext(ctx)
defer cancel()

Expand Down Expand Up @@ -72,7 +72,10 @@ func (b *Backend) GetItems(ctx context.Context, categoryID string, page, size ui
"$options": "i",
}
}

if fournisseur != "" {
filter["fournisseur"] = fournisseur
}

cursor, err := b.db.Collection(ItemsCollection).Find(ctx, filter, options.Find().SetSkip(int64(page*size)).SetLimit(int64(size)))
if err != nil {
return nil, err
Expand All @@ -85,7 +88,7 @@ func (b *Backend) GetItems(ctx context.Context, categoryID string, page, size ui
return items, nil
}

func (b *Backend) CountItems(ctx context.Context, categoryID string, state string, name string) (uint64, error) {
func (b *Backend) CountItems(ctx context.Context, categoryID string, state string, name string, fournisseur string) (uint64, error) {
ctx, cancel := b.TimeoutContext(ctx)
defer cancel()

Expand Down Expand Up @@ -142,6 +145,9 @@ func (b *Backend) CountItems(ctx context.Context, categoryID string, state strin
"$options": "i",
}
}
if fournisseur != "" {
filter["fournisseur"] = fournisseur
}

count, err := b.db.Collection(ItemsCollection).CountDocuments(ctx, filter)
if err != nil {
Expand Down
21 changes: 21 additions & 0 deletions bar.openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2394,6 +2394,12 @@ paths:
required: false
schema:
type: string
- name: fournisseur
in: query
description: Filter by fournisseur
required: false
schema:
$ref: "#/components/schemas/RestockType"
responses:
"200":
description: ""
Expand Down Expand Up @@ -4804,6 +4810,13 @@ components:
type: array
items:
$ref: "#/components/schemas/MenuCategory"
amount_per_bundle:
type: integer
format: uint64
ref_bundle:
type: string
fournisseur:
$ref: "#/components/schemas/RestockType"
ItemPrices:
type: object
properties:
Expand Down Expand Up @@ -4960,6 +4973,14 @@ components:
format: uint64
deleted_by:
$ref: "#/components/schemas/UUID"
amount_per_bundle:
type: integer
format: uint64
ref_bundle:
type: string
description: Referal code of the product in the Drive
fournisseur:
$ref: "#/components/schemas/RestockType"
required:
- id
- prices
Expand Down
58 changes: 51 additions & 7 deletions frontend/src/lib/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,24 @@ export interface Item {
* @memberof Item
*/
'deleted_by'?: string;
/**
*
* @type {number}
* @memberof Item
*/
'amount_per_bundle'?: number;
/**
* Referal code of the product in the Drive
* @type {string}
* @memberof Item
*/
'ref_bundle'?: string;
/**
*
* @type {RestockType}
* @memberof Item
*/
'fournisseur'?: RestockType;
}


Expand Down Expand Up @@ -2224,6 +2242,24 @@ export interface UpdateItem {
* @memberof UpdateItem
*/
'menu_categories'?: Array<MenuCategory>;
/**
*
* @type {number}
* @memberof UpdateItem
*/
'amount_per_bundle'?: number;
/**
*
* @type {string}
* @memberof UpdateItem
*/
'ref_bundle'?: string;
/**
*
* @type {RestockType}
* @memberof UpdateItem
*/
'fournisseur'?: RestockType;
}


Expand Down Expand Up @@ -6644,10 +6680,11 @@ export const ItemsApiAxiosParamCreator = function (configuration?: Configuration
* @param {ItemState} [state] Filter by state
* @param {string} [categoryId] Filter by category
* @param {string} [name] Filter by name
* @param {RestockType} [fournisseur] Filter by fournisseur
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
getAllItems: async (page?: number, limit?: number, state?: ItemState, categoryId?: string, name?: string, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
getAllItems: async (page?: number, limit?: number, state?: ItemState, categoryId?: string, name?: string, fournisseur?: RestockType, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
const localVarPath = `/items`;
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
Expand Down Expand Up @@ -6682,6 +6719,10 @@ export const ItemsApiAxiosParamCreator = function (configuration?: Configuration
localVarQueryParameter['name'] = name;
}

if (fournisseur !== undefined) {
localVarQueryParameter['fournisseur'] = fournisseur;
}



setSearchParams(localVarUrlObj, localVarQueryParameter);
Expand Down Expand Up @@ -6924,11 +6965,12 @@ export const ItemsApiFp = function(configuration?: Configuration) {
* @param {ItemState} [state] Filter by state
* @param {string} [categoryId] Filter by category
* @param {string} [name] Filter by name
* @param {RestockType} [fournisseur] Filter by fournisseur
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async getAllItems(page?: number, limit?: number, state?: ItemState, categoryId?: string, name?: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<GetAllItems200Response>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.getAllItems(page, limit, state, categoryId, name, options);
async getAllItems(page?: number, limit?: number, state?: ItemState, categoryId?: string, name?: string, fournisseur?: RestockType, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<GetAllItems200Response>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.getAllItems(page, limit, state, categoryId, name, fournisseur, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
/**
Expand Down Expand Up @@ -7006,11 +7048,12 @@ export const ItemsApiFactory = function (configuration?: Configuration, basePath
* @param {ItemState} [state] Filter by state
* @param {string} [categoryId] Filter by category
* @param {string} [name] Filter by name
* @param {RestockType} [fournisseur] Filter by fournisseur
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
getAllItems(page?: number, limit?: number, state?: ItemState, categoryId?: string, name?: string, options?: any): AxiosPromise<GetAllItems200Response> {
return localVarFp.getAllItems(page, limit, state, categoryId, name, options).then((request) => request(axios, basePath));
getAllItems(page?: number, limit?: number, state?: ItemState, categoryId?: string, name?: string, fournisseur?: RestockType, options?: any): AxiosPromise<GetAllItems200Response> {
return localVarFp.getAllItems(page, limit, state, categoryId, name, fournisseur, options).then((request) => request(axios, basePath));
},
/**
* Get all items of a category
Expand Down Expand Up @@ -7082,12 +7125,13 @@ export class ItemsApi extends BaseAPI {
* @param {ItemState} [state] Filter by state
* @param {string} [categoryId] Filter by category
* @param {string} [name] Filter by name
* @param {RestockType} [fournisseur] Filter by fournisseur
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof ItemsApi
*/
public getAllItems(page?: number, limit?: number, state?: ItemState, categoryId?: string, name?: string, options?: AxiosRequestConfig) {
return ItemsApiFp(this.configuration).getAllItems(page, limit, state, categoryId, name, options).then((request) => request(this.axios, this.basePath));
public getAllItems(page?: number, limit?: number, state?: ItemState, categoryId?: string, name?: string, fournisseur?: RestockType, options?: AxiosRequestConfig) {
return ItemsApiFp(this.configuration).getAllItems(page, limit, state, categoryId, name, fournisseur, options).then((request) => request(this.axios, this.basePath));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/routes/admin/produits/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
function reloadItems() {
itemsApi()
.getAllItems(page, itemsPerPage, searchState, searchCategory, searchName, {
.getAllItems(page, itemsPerPage, searchState, searchCategory, searchName, undefined, {
withCredentials: true
})
.then((res) => {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/routes/panel/products/create-menu/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
on:click={async () => {
steps.category = c;
currentStep = 2;
const res = await itemsApi().getAllItems(0, 16, undefined, undefined, '', {
const res = await itemsApi().getAllItems(0, 16, undefined, undefined, '', undefined, {
withCredentials: true
});
if (!Array.isArray(res.data.items)) {
Expand Down Expand Up @@ -182,7 +182,7 @@
on:keyup={async (e) => {
// @ts-ignore
let val = e.target?.value;
const res = await itemsApi().getAllItems(0, 16, undefined, undefined, val, {
const res = await itemsApi().getAllItems(0, 16, undefined, undefined, val, undefined, {
withCredentials: true
});
if (!Array.isArray(res.data.items)) {
Expand Down
Loading

0 comments on commit 8dbec9f

Please sign in to comment.