mirror of
https://github.com/Floriansylvain/CineAllo.git
synced 2026-08-19 11:43:24 +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 express from 'express'
|
||||||
import logger from 'morgan'
|
import logger from 'morgan'
|
||||||
import * as dotenv from 'dotenv'
|
import * as dotenv from 'dotenv'
|
||||||
import { indexRouter } from './routes/index.js'
|
import { showsRouter } from './routes/shows.js'
|
||||||
import { usersRouter } from './routes/users.js'
|
|
||||||
|
|
||||||
dotenv.config()
|
dotenv.config()
|
||||||
const app = express()
|
const app = express()
|
||||||
const port = process.env.CINEALLO_PORT
|
const port = 3000
|
||||||
|
|
||||||
app.use(logger('dev'))
|
app.use(logger('dev'))
|
||||||
app.use(express.json())
|
app.use(express.json())
|
||||||
app.use(express.urlencoded({ extended: false }))
|
app.use(express.urlencoded({ extended: false }))
|
||||||
|
|
||||||
app.use('/', indexRouter)
|
app.get('/', async (req, res, next) => {
|
||||||
app.use('/users', usersRouter)
|
res.send({message:"voila ton index"})
|
||||||
|
})
|
||||||
|
app.use('/shows', showsRouter)
|
||||||
|
|
||||||
app.listen(port, () => console.log(`Listening on port ${port}`))
|
app.listen(port, () => console.log(`Listening on port ${port}`))
|
||||||
+19
-11
@@ -1,13 +1,4 @@
|
|||||||
services:
|
services:
|
||||||
backend:
|
|
||||||
build: .
|
|
||||||
image: cineallo-backend
|
|
||||||
env_file:
|
|
||||||
- .env
|
|
||||||
networks:
|
|
||||||
- back-net
|
|
||||||
ports:
|
|
||||||
- 3000:3000
|
|
||||||
db:
|
db:
|
||||||
image: mysql:8.0.31
|
image: mysql:8.0.31
|
||||||
env_file:
|
env_file:
|
||||||
@@ -16,9 +7,26 @@ services:
|
|||||||
- back-net
|
- back-net
|
||||||
environment:
|
environment:
|
||||||
- "MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}"
|
- "MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}"
|
||||||
- "MYSQL_DATABASE=cineallo"
|
- "MYSQL_DATABASE=${MYSQL_DATABASE}"
|
||||||
volumes:
|
volumes:
|
||||||
- ./mysql-data:/var/lib/mysql
|
- ./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:
|
networks:
|
||||||
back-net:
|
back-net:
|
||||||
|
|||||||
+2
-1
@@ -4,7 +4,8 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node app.js"
|
"start": "npx prisma migrate deploy && node app.js",
|
||||||
|
"dev": "node app.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@prisma/client": "^4.6.0",
|
"@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;
|
||||||
@@ -2,15 +2,18 @@
|
|||||||
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
||||||
|
|
||||||
generator client {
|
generator client {
|
||||||
provider = "prisma-client-js"
|
provider = "prisma-client-js"
|
||||||
}
|
}
|
||||||
|
|
||||||
datasource db {
|
datasource db {
|
||||||
provider = "mysql"
|
provider = "mysql"
|
||||||
url = env("DATABASE_URL")
|
url = env("DATABASE_URL")
|
||||||
}
|
}
|
||||||
|
|
||||||
model Article {
|
model Serie {
|
||||||
id Int @id @default(autoincrement())
|
title String @id
|
||||||
title String
|
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