implement item dtos
All checks were successful
Build and Deploy Frontend / build-and-deploy (push) Successful in 8s
Build and Deploy API / build-and-deploy (push) Successful in 10s

This commit is contained in:
2026-03-22 00:56:24 -05:00
parent 3d219b8cf7
commit 67baddf9d0
5 changed files with 35 additions and 23 deletions

View File

@@ -3,7 +3,7 @@
// this item service will handle all to <-> from the server when handling item objects
import api from "./axios.ts"
import type { Item } from "../models/Item.ts";
import type { Item, ItemDto } from "../models/Item.ts";
const API_URL: string = "/items";
@@ -11,8 +11,8 @@ export const getItems = () => api.get<Item[]>(`${API_URL}`);
export const getItem = (id: number) => api.get<Item>(`${API_URL}/${id}`);
export const createItem = (data: Item) => api.post<Item>(`${API_URL}`, data);
export const createItem = (data: ItemDto) => api.post<Item>(`${API_URL}`, data);
export const updateItem = (id: number, data: Item) => api.put<Item>(`${API_URL}/${id}`, data);
export const updateItem = (id: number, data: ItemDto) => api.put<Item>(`${API_URL}/${id}`, data);
export const deleteItem = (id: number) => api.delete<Item>(`${API_URL}/${id}`);

View File

@@ -7,13 +7,7 @@ export interface Item {
lastEditedAt: string;
}
export interface RegisterDto {
username: string;
email: string;
password: string;
}
export interface LoginDto {
username: string;
password: string;
export interface ItemDto {
name: string;
description: string;
}

View File

@@ -48,7 +48,7 @@ async function save(): Promise<void> {
<form @submit.prevent="save">
<input v-model="item.name" placeholder="Name" />
<input v-model="item.description" placeholder="Name" />
<button type="submit">Save</button>
</form>
</div>

View File

@@ -5,7 +5,7 @@
// sighh
import { defineStore } from "pinia";
import type { Item } from "../models/Item.ts";
import type { Item, ItemDto } from "../models/Item.ts";
import * as itemsApi from "../api/ItemsApi";
interface ItemState {
@@ -28,15 +28,15 @@ export const useItemsStore = defineStore("items", {
this.loading = false;
},
async addItem(item: Item) {
async addItem(item: ItemDto) {
const response = await itemsApi.createItem(item);
this.items.push(response.data);
},
async updateItem(id: number, item: Item) {
await itemsApi.updateItem(id, item);
async updateItem(id: number, item: ItemDto) {
const response = await itemsApi.updateItem(id, item);
const index = this.items.findIndex(i => i.id === id);
this.items[index] = item;
this.items[index] = response.data;
},
async removeItem(id: number) {