Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions modulo5/arquitetura-de-software-3/labeflix/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.env
build
node_modules
2,324 changes: 2,324 additions & 0 deletions modulo5/arquitetura-de-software-3/labeflix/package-lock.json

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions modulo5/arquitetura-de-software-3/labeflix/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "labeflix",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "ts-node-dev src/index.ts"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@types/cors": "^2.8.12",
"@types/express": "^4.17.13",
"@types/uuid": "^8.3.1",
"ts-node-dev": "^2.0.0",
"typescript": "^4.7.4"
},
"dependencies": {
"cors": "^2.8.5",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"knex": "^0.21.21",
"mysql": "^2.18.1",
"ts-node": "^10.9.1",
"uuid": "^8.3.2"
}
}
15 changes: 15 additions & 0 deletions modulo5/arquitetura-de-software-3/labeflix/queries.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- Active: 1658925567615@@35.226.146.116@3306@guimaraes-4211155-caio-ramos
CREATE TABLE LABEFLIX_USER (
id VARCHAR(255) PRIMARY KEY,
name VARCHAR(255) NULL,
email VARCHAR(255) UNIQUE NOT NULL,
password VARCHAR(255) NOT NULL
);

CREATE TABLE LABEFLIX_MOVIE (
id VARCHAR(255) PRIMARY KEY,
title VARCHAR(255) NOT NULL,
description TEXT NOT NULL,
duration_in_minutes INT NOT NULL,
year_of_release INT NOT NULL
);
29 changes: 29 additions & 0 deletions modulo5/arquitetura-de-software-3/labeflix/request.rest
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
POST http://localhost:3003/user/create
Content-Type: application/json

{
"name": "Laine",
"email": "lala@email.com",
"password": "96741832"
}

###

GET http://localhost:3003/user/getall


###


POST http://localhost:3003/movie/create
Content-Type: application/json

{"title":"Arremessando Alto",
"description":"Um caçador de talentos do basquete descobre um fenomenal jogador de rua enquanto está na Espanha e vê essa perspectiva como sua chance de voltar à NBA.",
"duration_in_minutes":117,
"year_of_release":2022
}

###
GET http://localhost:3003/movie/getall
###
48 changes: 48 additions & 0 deletions modulo5/arquitetura-de-software-3/labeflix/src/Classes/Movie.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
export class Movie {
constructor(
private id: string,
private title: string,
private description: string,
private duration_in_minutes: number,
private year_of_release: number
) {}

getId() {
return this.id;
}

getTitle() {
return this.title;
}

getDescription() {
return this.description;
}

getDIM() {
return this.duration_in_minutes;
}

getYoR() {
return this.year_of_release;
}

setId(newId: string) {
this.id = newId;
}

setTitle(newTitle: string) {
this.title = newTitle;
}

setDescription(newDescription: string) {
this.description = newDescription;
}

setDIM(newDIM: number) {
this.duration_in_minutes = newDIM;
}
setYoR(newYoR: number) {
this.year_of_release = newYoR;
}
}
40 changes: 40 additions & 0 deletions modulo5/arquitetura-de-software-3/labeflix/src/Classes/User.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
export class User {
constructor(
private id: string,
private name: string,
private email: string,
private password: string
) { }

getId() {
return this.id
}

getName() {
return this.name
}

getEmail() {
return this.email
}

getPassword() {
return this.password
}

setId(newId: string) {
this.id = newId
}

setName(newName: string) {
this.name = newName
}

setEmail(newEmail: string) {
this.email = newEmail
}

setPassword(newPassword: string) {
this.password = newPassword
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export class CustomError extends Error {
constructor(public message: string, public statusCode: number) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { CustomError } from "./CustomError";

export class InvalidDIM extends CustomError {
constructor() {
super("Duração em minutos inválida. Tente utilizar um número.", 406);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { CustomError } from "./CustomError";

export class InvalidDescription extends CustomError {
constructor() {
super("Descrição inválida. Tente novamente.", 406);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { CustomError } from "./CustomError";

export class InvalidEmail extends CustomError {
constructor() {
super("Email inválido. Tente novamente.", 406);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { CustomError } from "./CustomError";

export class InvalidName extends CustomError {
constructor() {
super("Nome inválido. Tente novamente.", 406);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { CustomError } from "./CustomError";

export class InvalidPassword extends CustomError {
constructor() {
super("Senha não atende aos requisitos mínimos. Tente novamente.", 406);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { CustomError } from "./CustomError";

export class InvalidTitle extends CustomError {
constructor() {
super("Título inválido. Tente novamente.", 406);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { CustomError } from "./CustomError";

export class InvalidYoR extends CustomError {
constructor() {
super("Ano de lançamento inválida. Tente utilizar um número.", 406);
}
}
11 changes: 11 additions & 0 deletions modulo5/arquitetura-de-software-3/labeflix/src/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import express from 'express'
import cors from 'cors'

export const app = express()

app.use(express.json())
app.use(cors())

app.listen(3003, () => {
console.log("Servidor rodando na 3003")
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { MovieDatabase } from "../data/MovieDatabase";
import { generateId } from '../services/generateId';
import { Movie } from '../Classes/Movie';
import { createMovieDTO } from '../model/createMovieDTO';
export class MovieBusiness {
async create({
title,
description,
duration_in_minutes,
year_of_release,
}: createMovieDTO): Promise<void> {
if (!title || !description || !duration_in_minutes || !year_of_release) {
throw new Error(
"Dados inválidos (title, description, duration_in_minutes, year_of_release)"
);
}

const id = generateId();

const movieDatabase = new MovieDatabase();
await movieDatabase.create({
id,
title,
description,
duration_in_minutes,
year_of_release,
});
}
getAll = async (): Promise<Movie[]> => {
const movieDB = new MovieDatabase();
return await movieDB.getAll();
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { UserDatabase } from "../data/UserDatabase";
import { generateId } from '../services/generateId';
import { User } from "../Classes/User";
import { createUserDTO } from '../model/createUserDTO';

export class UserBusiness {
async create({ email, name, password }: createUserDTO): Promise<void> {
if (!email || !name || !password) {
throw new Error("Dados inválidos (email, name, password)");
}

const id = generateId();

const userDatabase = new UserDatabase();
await userDatabase.create({
id,
name,
email,
password,
});
}
getAll = async (): Promise<User[]> => {
const userDB = new UserDatabase();
return await userDB.getAll();
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Request, Response } from "express";
import { MovieBusiness } from "../business/MovieBusiness";
import { InvalidDescription } from "../Error/InvalidDescription";
import { InvalidDIM } from "../Error/InvalidDIM";
import { InvalidTitle } from "../Error/InvalidTitle";
import { InvalidYoR } from "../Error/InvalidYoR";

export class MovieController {
async create(req: Request, res: Response): Promise<void> {
try {
const { title, description, duration_in_minutes, year_of_release } =
req.body;
if (!title) {
throw new InvalidTitle();
}
if (!description) {
throw new InvalidDescription();
}
if (!duration_in_minutes) {
throw new InvalidDIM();
}
if (!year_of_release) {
throw new InvalidYoR();
}
const movieBusiness = new MovieBusiness();
await movieBusiness.create({
title,
description,
duration_in_minutes,
year_of_release,
});

res.status(201).send({ message: "Filme cadastrado com sucesso" });
} catch (error: any) {
res.status(400).send(error.message);
}
}

getAll = async (req: Request, res: Response): Promise<void> => {
try {
const movies = await new MovieBusiness().getAll();

res.status(200).send(movies);
} catch (error: any) {
res.status(400).send(error.message);
}
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Request, Response } from "express";
import { UserBusiness } from "../business/UserBusiness";
import { InvalidEmail } from "../Error/InvalidEmail";
import { InvalidName } from "../Error/InvalidName";
import { InvalidPassword } from "../Error/InvalidPassword";

export class UserController {
async create(req: Request, res: Response): Promise<void> {
try {
const { email, name, password } = req.body;
if (!email) {
throw new InvalidEmail();
}
if (!name) {
throw new InvalidName();
}
if (!password) {
throw new InvalidPassword();
}
const userBusiness = new UserBusiness();
await userBusiness.create({ email, name, password });

res.status(201).send({ message: "Usuário cadastrado com sucesso" });
} catch (error: any) {
res.status(400).send(error.message);
}
}

getAll = async (req: Request, res: Response): Promise<void> => {
try {
const users = await new UserBusiness().getAll();

res.status(200).send(users);
} catch (error: any) {
res
.status(error.statusCode || 400)
.send(error.message || error.sqlMessage);
}
};
}
Loading