mirror of
https://github.com/ThisIsBenny/wishlist-app.git
synced 2025-06-07 05:57:41 +00:00
#1 delete endpoint added
This commit is contained in:
parent
14cded061f
commit
16df584334
5 changed files with 84 additions and 3 deletions
|
@ -55,3 +55,19 @@ Content-Type: application/json
|
|||
"imageSrc": "https://www.lego.com/cdn/cs/set/assets/blt1fc37afef51cfa9f/40442.jpg?fit=bounds&format=jpg&quality=80&width=1500&height=1500&dpr=1",
|
||||
"description": "Cute goldfish and fry, build-and-display BrickHeadz™ model"
|
||||
}
|
||||
|
||||
###
|
||||
# @name updateItemOnFirstWishlist
|
||||
PUT {{BASE_URL}}/wishlist/{{getWishlists.response.body.0.id}}/item/1
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"title": "Goldfish | BrickHeadz",
|
||||
"url": "https://www.lego.com/en-de/product/goldfish-40442",
|
||||
"imageSrc": "https://www.lego.com/cdn/cs/set/assets/blt1fc37afef51cfa9f/40442.jpg?fit=bounds&format=jpg&quality=80&width=1500&height=1500&dpr=1",
|
||||
"description": "Cute goldfish and fry, build-and-display BrickHeadz™ model"
|
||||
}
|
||||
|
||||
###
|
||||
# @name deleteItemToFirstWishlist
|
||||
DELETE {{BASE_URL}}/wishlist/{{getWishlists.response.body.0.id}}/item/2
|
||||
|
|
|
@ -30,6 +30,13 @@ export default {
|
|||
},
|
||||
})
|
||||
},
|
||||
delete: async (id: string) => {
|
||||
return await prisma.client.wishlist.delete({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
})
|
||||
},
|
||||
createItem: async (wishlistId: string, payload: WishlistItem) => {
|
||||
const wishlist = await prisma.client.wishlist.update({
|
||||
where: {
|
||||
|
@ -57,4 +64,11 @@ export default {
|
|||
},
|
||||
})
|
||||
},
|
||||
deleteItem: async (itemId: number) => {
|
||||
return await prisma.client.item.delete({
|
||||
where: {
|
||||
id: itemId,
|
||||
},
|
||||
})
|
||||
},
|
||||
}
|
||||
|
|
50
src/api/routes/wishlist/delete.ts
Normal file
50
src/api/routes/wishlist/delete.ts
Normal file
|
@ -0,0 +1,50 @@
|
|||
import { FastifyRequest, FastifyReply, RouteOptions } from 'fastify'
|
||||
import { wishlist } from '../../models'
|
||||
|
||||
interface deleteRequest extends FastifyRequest {
|
||||
params: {
|
||||
wishlistId: string
|
||||
}
|
||||
}
|
||||
|
||||
interface deleteItemRequest extends FastifyRequest {
|
||||
params: {
|
||||
wishlistId: string
|
||||
itemId: number
|
||||
}
|
||||
}
|
||||
|
||||
export const deleteList = <RouteOptions>{
|
||||
method: 'DELETE',
|
||||
url: '/:wishlistId',
|
||||
schema: {
|
||||
params: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
wishlistId: { type: 'string' },
|
||||
},
|
||||
},
|
||||
},
|
||||
handler: async (request: deleteRequest, reply: FastifyReply) => {
|
||||
await wishlist.delete(request.params.wishlistId)
|
||||
reply.code(204).send()
|
||||
},
|
||||
}
|
||||
|
||||
export const deleteItem = <RouteOptions>{
|
||||
method: 'DELETE',
|
||||
url: '/:wishlistId/item/:itemId',
|
||||
schema: {
|
||||
params: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
wishlistId: { type: 'string' },
|
||||
itemId: { type: 'number' },
|
||||
},
|
||||
},
|
||||
},
|
||||
handler: async (request: deleteItemRequest, reply: FastifyReply) => {
|
||||
await wishlist.deleteItem(request.params.itemId)
|
||||
reply.code(204).send()
|
||||
},
|
||||
}
|
|
@ -2,6 +2,7 @@ import { FastifyInstance } from 'fastify'
|
|||
import { getAll, getBySlugUrl } from './read'
|
||||
import { updateList, updateItem } from './update'
|
||||
import { createList, createItem } from './create'
|
||||
import { deleteList, deleteItem } from './delete'
|
||||
|
||||
export default async (app: FastifyInstance) => {
|
||||
await app.route(getAll)
|
||||
|
@ -10,4 +11,6 @@ export default async (app: FastifyInstance) => {
|
|||
await app.route(createItem)
|
||||
await app.route(updateList)
|
||||
await app.route(updateItem)
|
||||
await app.route(deleteList)
|
||||
await app.route(deleteItem)
|
||||
}
|
||||
|
|
|
@ -64,8 +64,6 @@ export const updateItem = <RouteOptions>{
|
|||
},
|
||||
handler: async (request: updateItemRequest, reply: FastifyReply) => {
|
||||
request.log.debug(request.body)
|
||||
reply.send(
|
||||
await wishlist.updateItem(Number(request.params.itemId), request.body)
|
||||
)
|
||||
reply.send(await wishlist.updateItem(request.params.itemId, request.body))
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue