Skip to content

Commit

Permalink
feat(front): uniform prices & filters
Browse files Browse the repository at this point in the history
  • Loading branch information
yyewolf committed Aug 23, 2023
1 parent 800e8c5 commit 9f14652
Show file tree
Hide file tree
Showing 5 changed files with 648 additions and 405 deletions.
4 changes: 2 additions & 2 deletions backend/api/items.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,12 +384,12 @@ func (s *Server) GetAllItems(c echo.Context, params autogen.GetAllItemsParams) e

page += 1
maxPage += 1
autogen.GetCategoryItems200JSONResponse{
autogen.GetAllItems200JSONResponse{
Items: &items,
Page: &page,
Limit: &size,
MaxPage: &maxPage,
}.VisitGetCategoryItemsResponse(c.Response())
}.VisitGetAllItemsResponse(c.Response())

return nil
}
114 changes: 106 additions & 8 deletions frontend/src/lib/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,31 +455,31 @@ export interface GetAccounts200Response {
/**
*
* @export
* @interface GetCategoryItems200Response
* @interface GetAllItems200Response
*/
export interface GetCategoryItems200Response {
export interface GetAllItems200Response {
/**
*
* @type {Array<Item>}
* @memberof GetCategoryItems200Response
* @memberof GetAllItems200Response
*/
'items'?: Array<Item>;
/**
*
* @type {number}
* @memberof GetCategoryItems200Response
* @memberof GetAllItems200Response
*/
'page'?: number;
/**
*
* @type {number}
* @memberof GetCategoryItems200Response
* @memberof GetAllItems200Response
*/
'limit'?: number;
/**
*
* @type {number}
* @memberof GetCategoryItems200Response
* @memberof GetAllItems200Response
*/
'max_page'?: number;
}
Expand Down Expand Up @@ -5206,6 +5206,62 @@ export class DeletedApi extends BaseAPI {
*/
export const ItemsApiAxiosParamCreator = function (configuration?: Configuration) {
return {
/**
* (admin) Get all items with filters and pagination
* @param {number} [page] Page number
* @param {number} [limit] Number of items per page
* @param {ItemState} [state] Filter by state
* @param {string} [categoryId] Filter by category
* @param {string} [name] Filter by name
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
getAllItems: async (page?: number, limit?: number, state?: ItemState, categoryId?: string, name?: string, 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);
let baseOptions;
if (configuration) {
baseOptions = configuration.baseOptions;
}

const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;

// authentication admin_auth required

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

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

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

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

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



setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};

return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions,
};
},
/**
* Get all items of a category
* @param {string} categoryId ID of the category
Expand Down Expand Up @@ -5430,6 +5486,20 @@ export const ItemsApiAxiosParamCreator = function (configuration?: Configuration
export const ItemsApiFp = function(configuration?: Configuration) {
const localVarAxiosParamCreator = ItemsApiAxiosParamCreator(configuration)
return {
/**
* (admin) Get all items with filters and pagination
* @param {number} [page] Page number
* @param {number} [limit] Number of items per page
* @param {ItemState} [state] Filter by state
* @param {string} [categoryId] Filter by category
* @param {string} [name] Filter by name
* @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);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
/**
* Get all items of a category
* @param {string} categoryId ID of the category
Expand All @@ -5439,7 +5509,7 @@ export const ItemsApiFp = function(configuration?: Configuration) {
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async getCategoryItems(categoryId: string, page?: number, limit?: number, state?: ItemState, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<GetCategoryItems200Response>> {
async getCategoryItems(categoryId: string, page?: number, limit?: number, state?: ItemState, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<GetAllItems200Response>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.getCategoryItems(categoryId, page, limit, state, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
Expand Down Expand Up @@ -5498,6 +5568,19 @@ export const ItemsApiFp = function(configuration?: Configuration) {
export const ItemsApiFactory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) {
const localVarFp = ItemsApiFp(configuration)
return {
/**
* (admin) Get all items with filters and pagination
* @param {number} [page] Page number
* @param {number} [limit] Number of items per page
* @param {ItemState} [state] Filter by state
* @param {string} [categoryId] Filter by category
* @param {string} [name] Filter by name
* @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));
},
/**
* Get all items of a category
* @param {string} categoryId ID of the category
Expand All @@ -5507,7 +5590,7 @@ export const ItemsApiFactory = function (configuration?: Configuration, basePath
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
getCategoryItems(categoryId: string, page?: number, limit?: number, state?: ItemState, options?: any): AxiosPromise<GetCategoryItems200Response> {
getCategoryItems(categoryId: string, page?: number, limit?: number, state?: ItemState, options?: any): AxiosPromise<GetAllItems200Response> {
return localVarFp.getCategoryItems(categoryId, page, limit, state, options).then((request) => request(axios, basePath));
},
/**
Expand Down Expand Up @@ -5561,6 +5644,21 @@ export const ItemsApiFactory = function (configuration?: Configuration, basePath
* @extends {BaseAPI}
*/
export class ItemsApi extends BaseAPI {
/**
* (admin) Get all items with filters and pagination
* @param {number} [page] Page number
* @param {number} [limit] Number of items per page
* @param {ItemState} [state] Filter by state
* @param {string} [categoryId] Filter by category
* @param {string} [name] Filter by name
* @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));
}

/**
* Get all items of a category
* @param {string} categoryId ID of the category
Expand Down
14 changes: 14 additions & 0 deletions frontend/src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
export const parsePrice = (price: string) => {
let splt: Array<string> = [price];
if (price.includes(',')) {
splt = price.split(',');
} else if (price.includes('.')) {
splt = price.split('.');
}

let res = 0;
if (price.length > 1) res = parseInt(price[0]) * 100 + parseInt(price[1]);
else res = parseInt(price[0]) * 100;
return res;
}

export const formatPrice = (price: number) => {
// Price is in cents, so we divide by 100 to get dollars
return `${(price / 100).toFixed(2)} €`;
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/routes/admin/accounts/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@
class="py-2 px-3 inline-flex justify-center items-center gap-2 rounded-md border font-medium bg-white text-gray-700 shadow-sm align-middle hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-white focus:ring-blue-600 transition-all text-sm dark:bg-slate-900 dark:hover:bg-slate-800 dark:border-gray-700 dark:text-gray-400 dark:hover:text-white dark:focus:ring-offset-gray-800"
on:click={() => {
if (page > 1) page--;
reloadAccounts();
}}
>
<svg
Expand Down Expand Up @@ -572,6 +573,7 @@
class="py-2 px-3 inline-flex justify-center items-center gap-2 rounded-md border font-medium bg-white text-gray-700 shadow-sm align-middle hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-white focus:ring-blue-600 transition-all text-sm dark:bg-slate-900 dark:hover:bg-slate-800 dark:border-gray-700 dark:text-gray-400 dark:hover:text-white dark:focus:ring-offset-gray-800"
on:click={() => {
if (page < max_page) page++;
reloadAccounts();
}}
>
Suivant
Expand Down
Loading

0 comments on commit 9f14652

Please sign in to comment.