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
1 change: 1 addition & 0 deletions Gebru-labenu-system4
Submodule Gebru-labenu-system4 added at 1d031b
5 changes: 5 additions & 0 deletions modulo6/arquitetura-de-software-1/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
package-lock.json
build
.env

29 changes: 29 additions & 0 deletions modulo6/arquitetura-de-software-1/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "arquitetura-de-software-1",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"@types/cors": "^2.8.12",
"@types/express": "^4.17.13",
"@types/knex": "^0.16.1",
"@types/mysql": "^2.15.21",
"@types/node": "^18.6.1",
"cors": "^2.8.5",
"express": "^4.18.1",
"knex": "^2.2.0",
"mysql": "^2.18.1",
"ts-node-dev": "^2.0.0",
"typescript": "^4.7.4"
},
"scripts": {
"dev": " ts-node-dev ./src/index.ts",
"start": "tsc && node ./build/index.js",
"test": "echo \"Error: no test specified\" && exit 1",
"build": "tsc"

},
"keywords": [],
"author": "",
"license": "ISC"
}
8 changes: 8 additions & 0 deletions modulo6/arquitetura-de-software-1/queries.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CREATE TABLE User_Arq(
id VARCHAR(255) PRIMARY KEY,
name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL
);


18 changes: 18 additions & 0 deletions modulo6/arquitetura-de-software-1/request.rest
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// padrão
GET http://localhost:3003/all
###


###
POST http://localhost:3003/user
Content-Type: application/json

{
"name": "Michele Scott",
"email": "michele@dundermifflin.com",
"password": "1theboss"
}

###
DELETE http://localhost:3003/:id

Binary file not shown.
19 changes: 19 additions & 0 deletions modulo6/arquitetura-de-software-1/src/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import express from "express"
import cors from "cors"
import { AddressInfo } from "net"

export const app = express()

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

const server = app.listen(process.env.PORT || 3003, () => {
if (server) {
const address = server.address() as AddressInfo;
console.log(`Server is running in http://localhost:${address.port}`);
//console.log(`Server is running in ${address.address}:${address.port}`);

} else {
console.error(`Failure upon starting server.`);
}
})
27 changes: 27 additions & 0 deletions modulo6/arquitetura-de-software-1/src/business/UserBusiness.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { UserDatabase } from "../data/UserDataBase"

export class UserBusiness {
createUser = async ( input:any ):Promise<void> => {
try {
const {name, email, password} = input
if (!name || !email || !password) {
throw new Error('Preencha os campos "name", "email" e "password"')
}

const id: string = Date.now().toString()

const useDatabase = new UserDatabase()
await useDatabase.createUser({
id,
name,
email ,
password
})

} catch (error:any) {
throw new Error( error.message || "Error creating user. Please check your system administrator.");
}



}}
24 changes: 24 additions & 0 deletions modulo6/arquitetura-de-software-1/src/controller/UserController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Request, Response } from "express"
import { UserBusiness } from "../business/UserBusiness"

export class UserController {
createUser = async (req: Request,res: Response) => {
try {
const input:any = {
email: req.body.email,
name: req.body.name,
password: req.body.password
}

const userBusiness = new UserBusiness()
await userBusiness.createUser(input)

res.status(201).send({ message: "Usuário criado!" })
} catch (error:any) {
res.status(400).send(error.message)
}
}


}

18 changes: 18 additions & 0 deletions modulo6/arquitetura-de-software-1/src/data/BaseDatabase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import knex from 'knex'
import dotenv from 'dotenv'

dotenv.config()

export class BaseDatabase {
protected static connection = knex({
client: 'mysql',
connection: {
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_SCHEMA,
port: 3306,
multipleStatements: true
}
})
}
25 changes: 25 additions & 0 deletions modulo6/arquitetura-de-software-1/src/data/UserDataBase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { BaseDatabase } from "./BaseDatabase";
import { user } from "../types/user";

export class UserDatabase extends BaseDatabase{

createUser = async (user: user):Promise<void> => {

try {
await UserDatabase.connection
.insert({
id: user.id,
name: user.name,
email: user.email,
password: user.password
})

.into('User_Arq');//nome da tabela

} catch (error:any) {
throw new Error(error.sqlMessage || error.message);
}

}
}

11 changes: 11 additions & 0 deletions modulo6/arquitetura-de-software-1/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { app } from "./app"
import { UserController } from "./controller/UserController"
//import { createTask } from './endpoints/createTask'

const userController = new UserController()

app.post('/user', userController.createUser )

//app.get('/all', createAll)


7 changes: 7 additions & 0 deletions modulo6/arquitetura-de-software-1/src/types/user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export type user = {
id: string,
name: string,
email: string,
password: string,

}
12 changes: 12 additions & 0 deletions modulo6/arquitetura-de-software-1/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
"outDir": "./build" /* Redirect output structure to the directory. */,
"rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
"strict": true /* Enable all strict type-checking options. */,
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */,
"resolveJsonModule": true
}
}
Loading