mirror of
https://github.com/hay-kot/homebox.git
synced 2024-12-21 22:36:31 +00:00
location API
This commit is contained in:
parent
c7cfb4335b
commit
ec170f9b93
4 changed files with 43 additions and 4 deletions
3
frontend/src/api/base/base-types.ts
Normal file
3
frontend/src/api/base/base-types.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
export type Results<T> = {
|
||||
items: T[];
|
||||
};
|
24
frontend/src/api/classes/locations.ts
Normal file
24
frontend/src/api/classes/locations.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
import { BaseAPI, UrlBuilder } from '../base';
|
||||
import { type Results } from '../base/base-types';
|
||||
|
||||
export type LocationCreate = {
|
||||
name: string;
|
||||
description: string;
|
||||
};
|
||||
|
||||
export type Location = LocationCreate & {
|
||||
id: string;
|
||||
groupId: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
};
|
||||
|
||||
export class LocationsApi extends BaseAPI {
|
||||
async getAll() {
|
||||
return this.http.get<Results<Location>>(UrlBuilder('/locations'));
|
||||
}
|
||||
|
||||
async create(location: LocationCreate) {
|
||||
return this.http.post<LocationCreate, Location>(UrlBuilder('/locations'), location);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,6 @@
|
|||
import { Requests } from '@/lib/requests';
|
||||
import { BaseAPI, UrlBuilder } from './base';
|
||||
import { LocationsApi } from './classes/locations';
|
||||
|
||||
export type Result<T> = {
|
||||
item: T;
|
||||
|
@ -12,6 +14,16 @@ export type User = {
|
|||
};
|
||||
|
||||
export class UserApi extends BaseAPI {
|
||||
locations: LocationsApi;
|
||||
|
||||
constructor(requests: Requests) {
|
||||
super(requests);
|
||||
|
||||
this.locations = new LocationsApi(requests);
|
||||
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
||||
public self() {
|
||||
return this.http.get<Result<User>>(UrlBuilder('/users/self'));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue