mirror of
https://github.com/hay-kot/homebox.git
synced 2025-05-28 08:02:31 +00:00
labels create and get
This commit is contained in:
parent
f956ec8eb2
commit
8ece3bd7bf
24 changed files with 850 additions and 132 deletions
|
@ -1,3 +0,0 @@
|
|||
export type Results<T> = {
|
||||
items: T[];
|
||||
};
|
32
frontend/lib/api/classes/labels.ts
Normal file
32
frontend/lib/api/classes/labels.ts
Normal file
|
@ -0,0 +1,32 @@
|
|||
import { BaseAPI, UrlBuilder } from '../base';
|
||||
import { Details, OutType, Results } from './types';
|
||||
|
||||
export type LabelCreate = Details & {
|
||||
color: string;
|
||||
};
|
||||
|
||||
export type LabelUpdate = LabelCreate;
|
||||
|
||||
export type Label = LabelCreate & OutType;
|
||||
|
||||
export class LabelsApi extends BaseAPI {
|
||||
async getAll() {
|
||||
return this.http.get<Results<Label>>(UrlBuilder('/labels'));
|
||||
}
|
||||
|
||||
async create(label: LabelCreate) {
|
||||
return this.http.post<LabelCreate, Label>(UrlBuilder('/labels'), label);
|
||||
}
|
||||
|
||||
async get(id: string) {
|
||||
return this.http.get<Label>(UrlBuilder(`/labels/${id}`));
|
||||
}
|
||||
|
||||
async delete(id: string) {
|
||||
return this.http.delete<void>(UrlBuilder(`/labels/${id}`));
|
||||
}
|
||||
|
||||
async update(id: string, label: LabelUpdate) {
|
||||
return this.http.put<LabelUpdate, Label>(UrlBuilder(`/labels/${id}`), label);
|
||||
}
|
||||
}
|
|
@ -1,17 +1,12 @@
|
|||
import { BaseAPI, UrlBuilder } from '../base';
|
||||
import { type Results } from '../base/base-types';
|
||||
import { Details, OutType, Results } from './types';
|
||||
|
||||
export type LocationCreate = {
|
||||
name: string;
|
||||
description: string;
|
||||
};
|
||||
export type LocationCreate = Details;
|
||||
|
||||
export type Location = LocationCreate & {
|
||||
id: string;
|
||||
groupId: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
};
|
||||
export type Location = LocationCreate &
|
||||
OutType & {
|
||||
groupId: string;
|
||||
};
|
||||
|
||||
export type LocationUpdate = LocationCreate;
|
||||
|
||||
|
|
19
frontend/lib/api/classes/types/index.ts
Normal file
19
frontend/lib/api/classes/types/index.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
/**
|
||||
* OutType is the base type that is returned from the API.
|
||||
* In contains the common fields that are included with every
|
||||
* API response that isn't a bulk result
|
||||
*/
|
||||
export type OutType = {
|
||||
id: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
};
|
||||
|
||||
export type Details = {
|
||||
name: string;
|
||||
description: string;
|
||||
};
|
||||
|
||||
export type Results<T> = {
|
||||
items: T[];
|
||||
};
|
|
@ -1,4 +1,4 @@
|
|||
import { BaseAPI, UrlBuilder } from "./base";
|
||||
import { BaseAPI, UrlBuilder } from './base';
|
||||
|
||||
export type LoginResult = {
|
||||
token: string;
|
||||
|
@ -21,19 +21,13 @@ export type RegisterPayload = {
|
|||
|
||||
export class PublicApi extends BaseAPI {
|
||||
public login(username: string, password: string) {
|
||||
return this.http.post<LoginPayload, LoginResult>(
|
||||
UrlBuilder("/users/login"),
|
||||
{
|
||||
username,
|
||||
password,
|
||||
}
|
||||
);
|
||||
return this.http.post<LoginPayload, LoginResult>(UrlBuilder('/users/login'), {
|
||||
username,
|
||||
password,
|
||||
});
|
||||
}
|
||||
|
||||
public register(payload: RegisterPayload) {
|
||||
return this.http.post<RegisterPayload, LoginResult>(
|
||||
UrlBuilder("/users/register"),
|
||||
payload
|
||||
);
|
||||
return this.http.post<RegisterPayload, LoginResult>(UrlBuilder('/users/register'), payload);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { Requests } from "~~/lib/requests";
|
||||
import { BaseAPI, UrlBuilder } from "./base";
|
||||
import { LocationsApi } from "./classes/locations";
|
||||
import { Requests } from '~~/lib/requests';
|
||||
import { BaseAPI, UrlBuilder } from './base';
|
||||
import { LabelsApi } from './classes/labels';
|
||||
import { LocationsApi } from './classes/locations';
|
||||
|
||||
export type Result<T> = {
|
||||
item: T;
|
||||
|
@ -15,20 +16,21 @@ export type User = {
|
|||
|
||||
export class UserApi extends BaseAPI {
|
||||
locations: LocationsApi;
|
||||
|
||||
labels: LabelsApi;
|
||||
constructor(requests: Requests) {
|
||||
super(requests);
|
||||
|
||||
this.locations = new LocationsApi(requests);
|
||||
this.labels = new LabelsApi(requests);
|
||||
|
||||
Object.freeze(this);
|
||||
}
|
||||
|
||||
public self() {
|
||||
return this.http.get<Result<User>>(UrlBuilder("/users/self"));
|
||||
return this.http.get<Result<User>>(UrlBuilder('/users/self'));
|
||||
}
|
||||
|
||||
public logout() {
|
||||
return this.http.post<object, void>(UrlBuilder("/users/logout"), {});
|
||||
return this.http.post<object, void>(UrlBuilder('/users/logout'), {});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue