Init project
This commit is contained in:
parent
050fdb4f64
commit
e5d6c890a8
46 changed files with 7856 additions and 0 deletions
12
cms/src/routes/api/users/+server.ts
Normal file
12
cms/src/routes/api/users/+server.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import type { RequestEvent, RequestHandler } from './$types'
|
||||
import {json} from '@sveltejs/kit'
|
||||
import { createUser, getUsers } from '$lib/data/users'
|
||||
|
||||
//api/users
|
||||
export const POST: RequestHandler = async ({ request }: RequestEvent) => {
|
||||
const data = await request.json()
|
||||
return json(await createUser( data))
|
||||
}
|
||||
export const GET: RequestHandler = async () => {
|
||||
return json(await getUsers())
|
||||
}
|
||||
19
cms/src/routes/api/users/[id]/+server.ts
Normal file
19
cms/src/routes/api/users/[id]/+server.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import type { RequestEvent, RequestHandler } from './$types'
|
||||
import {json} from '@sveltejs/kit'
|
||||
import { getUser, updateUser } from '$lib/data/users'
|
||||
|
||||
//api/users/1
|
||||
export const PUT: RequestHandler = async ({ request }: RequestEvent) => {
|
||||
const o = await request.json()
|
||||
if(!updateUser(o))
|
||||
return json({message:"call updateUser fail "},{status:400})
|
||||
return json({message:"Update Success"})
|
||||
}
|
||||
export const GET: RequestHandler = async ({params}: RequestEvent) => {
|
||||
const id = Number(params.id)
|
||||
const u = await getUser(id)
|
||||
if(!u)
|
||||
return json({message:`User ${id} not found`},{status:404})
|
||||
return json(u)
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue