mirror of
https://github.com/Floriansylvain/CineAllo.git
synced 2026-08-19 19:53:16 +02:00
Merge pull request #1 from Floriansylvain/develop
Full featured CineAllo
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
# CineAllo
|
||||
## Setup
|
||||
### Env file
|
||||
- DATABASE_URL
|
||||
- MYSQL_DATABASE
|
||||
- MYSQL_ROOT_PASSWORD
|
||||
- CINEALLO_PORT
|
||||
|
||||
``DATABASE_URL`` shoud look like this:
|
||||
```html
|
||||
mysql://root:<MYSQL_ROOT_PASSWORD>@db:3306/<MYSQL_DATABASE>
|
||||
```
|
||||
## Usage
|
||||
### Docker
|
||||
```bash
|
||||
docker-compose up --build
|
||||
```
|
||||
### From scratch
|
||||
You'll need your own MySql DB running.
|
||||
```bash
|
||||
npm ci
|
||||
```
|
||||
```bash
|
||||
npm run start
|
||||
```
|
||||
@@ -1,18 +1,19 @@
|
||||
import express from 'express'
|
||||
import logger from 'morgan'
|
||||
import * as dotenv from 'dotenv'
|
||||
import { indexRouter } from './routes/index.js'
|
||||
import { usersRouter } from './routes/users.js'
|
||||
import { showsRouter } from './routes/shows.js'
|
||||
|
||||
dotenv.config()
|
||||
const app = express()
|
||||
const port = process.env.CINEALLO_PORT
|
||||
const port = 3000
|
||||
|
||||
app.use(logger('dev'))
|
||||
app.use(express.json())
|
||||
app.use(express.urlencoded({ extended: false }))
|
||||
|
||||
app.use('/', indexRouter)
|
||||
app.use('/users', usersRouter)
|
||||
app.get('/', async (req, res, next) => {
|
||||
res.send({message:"voila ton index"})
|
||||
})
|
||||
app.use('/shows', showsRouter)
|
||||
|
||||
app.listen(port, () => console.log(`Listening on port ${port}`))
|
||||
+18
-10
@@ -1,13 +1,4 @@
|
||||
services:
|
||||
backend:
|
||||
build: .
|
||||
image: cineallo-backend
|
||||
env_file:
|
||||
- .env
|
||||
networks:
|
||||
- back-net
|
||||
ports:
|
||||
- 3000:3000
|
||||
db:
|
||||
image: mysql:8.0.31
|
||||
env_file:
|
||||
@@ -16,9 +7,26 @@ services:
|
||||
- back-net
|
||||
environment:
|
||||
- "MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}"
|
||||
- "MYSQL_DATABASE=cineallo"
|
||||
- "MYSQL_DATABASE=${MYSQL_DATABASE}"
|
||||
volumes:
|
||||
- ./mysql-data:/var/lib/mysql
|
||||
healthcheck:
|
||||
test: [ "CMD", "curl", "-f", "http://localhost:3306" ]
|
||||
interval: 3s
|
||||
timeout: 30s
|
||||
retries: 10
|
||||
backend:
|
||||
build: .
|
||||
image: cineallo-backend
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
env_file:
|
||||
- .env
|
||||
networks:
|
||||
- back-net
|
||||
ports:
|
||||
- "${CINEALLO_PORT}:3000"
|
||||
|
||||
networks:
|
||||
back-net:
|
||||
+2
-1
@@ -4,7 +4,8 @@
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"start": "node app.js"
|
||||
"start": "npx prisma migrate deploy && node app.js",
|
||||
"dev": "node app.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@prisma/client": "^4.6.0",
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the `Article` table. If the table is not empty, all the data it contains will be lost.
|
||||
|
||||
*/
|
||||
-- DropTable
|
||||
DROP TABLE `Article`;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `Serie` (
|
||||
`title` VARCHAR(191) NOT NULL,
|
||||
`date` INTEGER NOT NULL,
|
||||
`description` VARCHAR(2000) NOT NULL,
|
||||
`thumbmailURL` VARCHAR(2048) NOT NULL,
|
||||
|
||||
PRIMARY KEY (`title`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE `Serie` ADD COLUMN `likes` INTEGER NOT NULL DEFAULT 0;
|
||||
@@ -10,7 +10,10 @@ datasource db {
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
model Article {
|
||||
id Int @id @default(autoincrement())
|
||||
title String
|
||||
model Serie {
|
||||
title String @id
|
||||
date Int
|
||||
description String @db.VarChar(2000)
|
||||
thumbmailURL String @db.VarChar(2048)
|
||||
likes Int @default(0)
|
||||
}
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
import express from 'express'
|
||||
import { PrismaClient } from '@prisma/client'
|
||||
|
||||
const prisma = new PrismaClient()
|
||||
export const indexRouter = express.Router()
|
||||
|
||||
indexRouter.get('/', async (req, res, next) => {
|
||||
res.send({message:"voila ton index"})
|
||||
})
|
||||
|
||||
indexRouter.get('/articles', async (req, res, next) => {
|
||||
const articles = await prisma.article.findMany({})
|
||||
res.send({
|
||||
message:"voila tes articles",
|
||||
articles
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,61 @@
|
||||
import express from 'express'
|
||||
import { Prisma, PrismaClient } from '@prisma/client'
|
||||
import createHttpError from 'http-errors'
|
||||
|
||||
const prisma = new PrismaClient()
|
||||
export const showsRouter = express.Router()
|
||||
|
||||
showsRouter.get('/', function (req, res, next) {
|
||||
prisma.serie.findMany({
|
||||
orderBy: {
|
||||
likes: 'desc'
|
||||
}
|
||||
})
|
||||
.then(shows => res.send({ shows }))
|
||||
})
|
||||
|
||||
showsRouter.get('/:id', function (req, res, next) {
|
||||
prisma.serie.findUniqueOrThrow({
|
||||
where: {
|
||||
title: req.params.id
|
||||
}
|
||||
})
|
||||
.then(show => res.send({ show }))
|
||||
.catch(error => {
|
||||
if (error instanceof Prisma.NotFoundError) {
|
||||
next(createHttpError(404, 'Show not found.'))
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
showsRouter.post('/', function (req, res, next) {
|
||||
prisma.serie.create({
|
||||
data: {
|
||||
title: req.body.title,
|
||||
date: req.body.date,
|
||||
description: req.body.description,
|
||||
thumbmailURL: req.body.thumbmailURL
|
||||
}
|
||||
})
|
||||
.then(() => res.send({ message: 'Show posted!' }))
|
||||
.catch(() => {
|
||||
next(createHttpError(400, 'Check your show model/content.'))
|
||||
})
|
||||
})
|
||||
|
||||
showsRouter.patch('/like/:id', function (req, res, next) {
|
||||
prisma.serie.update({
|
||||
where: {
|
||||
title: req.params.id
|
||||
},
|
||||
data: {
|
||||
likes: {
|
||||
increment: 1
|
||||
}
|
||||
}
|
||||
})
|
||||
.then(() => res.send({ message: 'Show liked!' }))
|
||||
.catch(() => {
|
||||
next(createHttpError(400, 'Show not found.'))
|
||||
})
|
||||
})
|
||||
@@ -1,7 +0,0 @@
|
||||
import express from 'express'
|
||||
|
||||
export const usersRouter = express.Router()
|
||||
|
||||
usersRouter.get('/', function(req, res, next) {
|
||||
res.send({message:"voila tes users"})
|
||||
})
|
||||
Reference in New Issue
Block a user