-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
56 lines (39 loc) · 1.28 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import fastify from 'fastify';
import {DatabasePostgres} from './db-postgres.mjs'
const server = fastify()
const database = new DatabasePostgres()
server.post('/videos', async (request, reply) => {
const {title, description, duration} = request.body
await database.create ({
title,
description,
duration,
})
return reply.status(201).send()
})
server.get('/videos', async (request) => {
const search = request.query.search
const videos = await database.list(search)
//return videos
})
server.get('/', async (request) => {
return 'renato ';
})
server.put('/videos/:id' , async (request, reply) => {
const videoId = request.params.id
const { title, description, duration} = request.body
database.update( videoId, {
title,
description,
duration,
})
return reply.status(204).send()
} )
server.delete('/videos/:id', async (request, reply) => {
const videoId = request.params.id
await database.deleteById(videoId)
return reply.status(204).send()
})
server.listen({
port: 3333,
})