Skip to content

Commit

Permalink
Implement Brand model and CRUD operations for models with Express
Browse files Browse the repository at this point in the history
  • Loading branch information
666sylar committed Dec 21, 2024
1 parent 1fb1f66 commit 2f6bb3a
Show file tree
Hide file tree
Showing 31 changed files with 4,198 additions and 0 deletions.
8 changes: 8 additions & 0 deletions 36_EXPRESS_SEQUILEZE/.env-template
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
PORT=
HOST=
NODE_ENV=
DB_USER=
DB_PASSWORD=
DB_NAME=
DB_HOST=
STATIC_FOLDER=
4 changes: 4 additions & 0 deletions 36_EXPRESS_SEQUILEZE/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
!.sequelizerc
!.env-template
public/images/*
5 changes: 5 additions & 0 deletions 36_EXPRESS_SEQUILEZE/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"semi": true,
"trailingComma": "es5",
"singleQuote": true
}
9 changes: 9 additions & 0 deletions 36_EXPRESS_SEQUILEZE/.sequelizerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const path = require('path');
require('dotenv').config();

module.exports = {
config: path.resolve('config', 'config.js'),
'models-path': path.resolve('db', 'models'),
'seeders-path': path.resolve('db', 'seeders'),
'migrations-path': path.resolve('db', 'migrations'),
};
251 changes: 251 additions & 0 deletions 36_EXPRESS_SEQUILEZE/Phones.postman_collection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
{
"info": {
"_postman_id": "eb990b76-e90c-45d0-adac-896700846c2c",
"name": "Phones",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "37224117"
},
"item": [
{
"name": "Brand",
"item": [
{
"name": "brands",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "{{url}}/brands",
"host": [
"{{url}}"
],
"path": [
"brands"
]
}
},
"response": []
},
{
"name": "brands/id/phones",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "{{url}}/brands/{{id}}/phones",
"host": [
"{{url}}"
],
"path": [
"brands",
"{{id}}",
"phones"
]
}
},
"response": []
},
{
"name": "brands/id/phones",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"model\": \"iPhone 14\",\r\n \"year\": 2023,\r\n \"ram\": 6,\r\n \"processor\": \"A16 Bionic\",\r\n \"screenSize\": 6.1,\r\n \"hasNFC\": true,\r\n \"image\": \"\"\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{url}}/brands/{{id}}/phones",
"host": [
"{{url}}"
],
"path": [
"brands",
"{{id}}",
"phones"
]
}
},
"response": []
}
]
},
{
"name": "phone",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"model\": \"iPhone 14\",\r\n \"year\": 2023,\r\n \"ram\": 6,\r\n \"processor\": \"A16 Bionic\",\r\n \"screenSize\": 6.1,\r\n \"hasNFC\": true,\r\n \"image\": \"\",\r\n \"brandId\": 1\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{url}}/phones",
"host": [
"{{url}}"
],
"path": [
"phones"
]
}
},
"response": []
},
{
"name": "phones",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "{{url}}/phones?page=1&results=5",
"host": [
"{{url}}"
],
"path": [
"phones"
],
"query": [
{
"key": "page",
"value": "1"
},
{
"key": "results",
"value": "5"
}
]
}
},
"response": []
},
{
"name": "phones/id",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "{{url}}/phones/{{id}}",
"host": [
"{{url}}"
],
"path": [
"phones",
"{{id}}"
]
}
},
"response": []
},
{
"name": "phones/id",
"request": {
"method": "PATCH",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"model\": \"iPhone 14\",\n \"year\": 2023,\n \"ram\": 6,\n \"processor\": \"A16 Bionic\",\n \"screenSize\": 6.1,\n \"hasNFC\": true,\n \"image\": \"123\",\n \"brandId\": 1\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{url}}/phones/{{id}}",
"host": [
"{{url}}"
],
"path": [
"phones",
"{{id}}"
]
}
},
"response": []
},
{
"name": "phones/id/image",
"request": {
"method": "PATCH",
"header": [],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "phoneImage",
"type": "file",
"src": []
}
]
},
"url": {
"raw": "{{url}}/phones/{{id}}/image",
"host": [
"{{url}}"
],
"path": [
"phones",
"{{id}}",
"image"
]
}
},
"response": []
},
{
"name": "phones/id",
"request": {
"method": "PUT",
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"model\": \"iPhone 14\",\r\n \"year\": 2023,\r\n \"ram\": 6,\r\n \"processor\": \"A16 Bionic\",\r\n \"screenSize\": 6.1,\r\n \"hasNFC\": true,\r\n \"image\": \"\",\r\n \"brandId\": 1\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{url}}/phones/{{id}}",
"host": [
"{{url}}"
],
"path": [
"phones",
"{{id}}"
]
}
},
"response": []
},
{
"name": "phones/id",
"request": {
"method": "DELETE",
"header": [],
"url": {
"raw": "{{url}}/phones/{{id}}",
"host": [
"{{url}}"
],
"path": [
"phones",
"{{id}}"
]
}
},
"response": []
}
]
}
21 changes: 21 additions & 0 deletions 36_EXPRESS_SEQUILEZE/Phones.postman_environment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"id": "3baf009c-9094-4733-b034-01806cdedcb0",
"name": "Phones",
"values": [
{
"key": "url",
"value": "http://localhost:5555/api",
"type": "default",
"enabled": true
},
{
"key": "id",
"value": "1",
"type": "default",
"enabled": true
}
],
"_postman_variable_scope": "environment",
"_postman_exported_at": "2024-12-21T21:51:20.039Z",
"_postman_exported_using": "Postman/11.23.3"
}
16 changes: 16 additions & 0 deletions 36_EXPRESS_SEQUILEZE/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const express = require('express');
const { STATIC_PATH } = require('./constants');
const router = require('./routes');
const { errorHandlers } = require('./middleware');

const app = express();

app.use(express.static(STATIC_PATH));

app.use(express.json());

app.use('/api', router);

app.use(errorHandlers.dbErrorHandler, errorHandlers.errorHandler);

module.exports = app;
24 changes: 24 additions & 0 deletions 36_EXPRESS_SEQUILEZE/config/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
development: {
username: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
host: process.env.DB_HOST,
dialect: 'postgres',
seederStorage: 'sequelize',
},
test: {
username: 'root',
password: null,
database: 'database_test',
host: '127.0.0.1',
dialect: 'mysql',
},
production: {
username: 'root',
password: null,
database: 'database_production',
host: '127.0.0.1',
dialect: 'mysql',
},
};
7 changes: 7 additions & 0 deletions 36_EXPRESS_SEQUILEZE/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const path = require('path');

const CONSTANTS = {
STATIC_PATH: path.join(__dirname, process.env.STATIC_FOLDER),
};

module.exports = CONSTANTS;
Loading

0 comments on commit 2f6bb3a

Please sign in to comment.