Skip to content

A continuation of HomeBox the inventory and organization system built for the Home User

location API

Haydenec170f9b9383
diff --git a/frontend/src/api/base/base-api.ts b/frontend/src/api/base/base-api.ts
index 785cb821..e05a94d5 100644
--- a/frontend/src/api/base/base-api.ts
+++ b/frontend/src/api/base/base-api.ts
@@ -9,9 +9,9 @@ import { Requests } from '../../lib/requests';
// >
export class BaseAPI {
- http: Requests;
+ http: Requests;
- constructor(requests: Requests) {
- this.http = requests;
- }
+ constructor(requests: Requests) {
+ this.http = requests;
+ }
}
diff --git a/frontend/src/api/base/base-types.ts b/frontend/src/api/base/base-types.ts
new file mode 100644
index 00000000..95a3b655
--- /dev/null
+++ b/frontend/src/api/base/base-types.ts
@@ -0,0 +1,3 @@
+export type Results<T> = {
+ items: T[];
+};
diff --git a/frontend/src/api/classes/locations.ts b/frontend/src/api/classes/locations.ts
new file mode 100644
index 00000000..17ad9de1
--- /dev/null
+++ b/frontend/src/api/classes/locations.ts
@@ -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);
+ }
+}
diff --git a/frontend/src/api/user.ts b/frontend/src/api/user.ts
index fb93a078..1bd0f2a9 100644
--- a/frontend/src/api/user.ts
+++ b/frontend/src/api/user.ts
@@ -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'));
}