From 03a2129799f31ec963df2e023531dc9dda55bb58 Mon Sep 17 00:00:00 2001 From: ipdmartins Date: Sun, 6 Sep 2020 11:52:35 -0300 Subject: [PATCH] refactor: fixing some code formatting --- .env.example | 11 +++ app/Controllers/Http/CostumersController.ts | 104 ++++++++++---------- resources/views/costumer/create.edge | 58 +++++------ resources/views/costumer/edit.edge | 56 +++++------ 4 files changed, 120 insertions(+), 109 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..9b8c63f --- /dev/null +++ b/.env.example @@ -0,0 +1,11 @@ +PORT= +HOST= +NODE_ENV= +APP_KEY= +SESSION_DRIVER= +DB_CONNECTION= +DB_HOST= +DB_USER= +DB_PASSWORD= +DB_NAME= +DB_PORT= \ No newline at end of file diff --git a/app/Controllers/Http/CostumersController.ts b/app/Controllers/Http/CostumersController.ts index 28a1a91..0d2f0a9 100644 --- a/app/Controllers/Http/CostumersController.ts +++ b/app/Controllers/Http/CostumersController.ts @@ -1,21 +1,21 @@ -import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext' -import { schema } from '@ioc:Adonis/Core/Validator' -import Costumer from 'App/Models/Costumer' +import { HttpContextContract } from "@ioc:Adonis/Core/HttpContext"; +import { schema } from "@ioc:Adonis/Core/Validator"; +import Costumer from "App/Models/Costumer"; export default class CostumersController { - public async index ({ view }: HttpContextContract) { - const costumers = await Costumer.all() + public async index({ view }: HttpContextContract) { + const costumers = await Costumer.all(); - return view.render('costumer/index', { + return view.render("costumer/index", { costumers, - }) + }); } - public async create ({ view }: HttpContextContract) { - return view.render('costumer/create') + public async create({ view }: HttpContextContract) { + return view.render("costumer/create"); } - public async store ({ request, session, response }: HttpContextContract) { + public async store({ request, session, response }: HttpContextContract) { const costumerSchema = schema.create({ name: schema.string(), cpf: schema.string(), @@ -25,46 +25,46 @@ export default class CostumersController { city: schema.string(), zip: schema.string(), state: schema.string(), - }) + }); const data = await request.validate({ schema: costumerSchema, messages: { - 'name.required': 'Please enter the costumer name', - 'CPF.required': 'Please enter the costumer CPF', - 'street.required': 'Please enter the costumer street', - 'number.required': 'Please enter the costumer number', - 'district.required': 'Please enter the costumer district', - 'city.required': 'Please enter the costumer city', - 'zip.required': 'Please enter the costumer zip', - 'state.required': 'Please enter the costumer state', + "name.required": "Please enter the costumer name", + "cpf.required": "Please enter the costumer CPF", + "street.required": "Please enter the costumer street", + "number.required": "Please enter the costumer number", + "district.required": "Please enter the costumer district", + "city.required": "Please enter the costumer city", + "zip.required": "Please enter the costumer zip", + "state.required": "Please enter the costumer state", }, cacheKey: request.url(), - }) + }); - await Costumer.create(data) + await Costumer.create(data); - session.flash('success', 'Costumer created successfully') - response.redirect('back') + session.flash("success", "Costumer created successfully"); + response.redirect("back"); } - public async show ({ params: { id }, view }: HttpContextContract) { - const costumer = await Costumer.findOrFail(id) + public async show({ params: { id }, view }: HttpContextContract) { + const costumer = await Costumer.findOrFail(id); - return view.render('costumer/show', { + return view.render("costumer/show", { costumer, - }) + }); } - public async edit ({ params: { id }, view }: HttpContextContract) { - const costumer = await Costumer.findOrFail(id) + public async edit({ params: { id }, view }: HttpContextContract) { + const costumer = await Costumer.findOrFail(id); - return view.render('costumer/edit', { + return view.render("costumer/edit", { costumer, - }) + }); } - public async update ({ + public async update({ request, session, response, @@ -79,43 +79,43 @@ export default class CostumersController { city: schema.string(), zip: schema.string(), state: schema.string(), - }) + }); const data = await request.validate({ schema: costumerSchema, messages: { - 'name.required': 'Please enter the costumer name', - 'CPF.required': 'Please enter the costumer CPF', - 'street.required': 'Please enter the costumer street', - 'number.required': 'Please enter the costumer number', - 'district.required': 'Please enter the costumer district', - 'city.required': 'Please enter the costumer city', - 'zip.required': 'Please enter the costumer zip', - 'state.required': 'Please enter the costumer state', + "name.required": "Please enter the costumer name", + "cpf.required": "Please enter the costumer CPF", + "street.required": "Please enter the costumer street", + "number.required": "Please enter the costumer number", + "district.required": "Please enter the costumer district", + "city.required": "Please enter the costumer city", + "zip.required": "Please enter the costumer zip", + "state.required": "Please enter the costumer state", }, cacheKey: request.url(), - }) + }); - const costumer = await Costumer.findOrFail(id) + const costumer = await Costumer.findOrFail(id); - costumer.merge(data) + costumer.merge(data); - await costumer.save() + await costumer.save(); - await session.flash('success', 'Costumer updated successfully') - response.redirect('back') + await session.flash("success", "Costumer updated successfully"); + response.redirect("back"); } - public async destroy ({ + public async destroy({ params: { id }, session, response, }: HttpContextContract) { - const costumer = await Costumer.findOrFail(id) + const costumer = await Costumer.findOrFail(id); - await costumer.delete() + await costumer.delete(); - await session.flash('success', 'Costumer deleted successfully') - response.redirect('back') + await session.flash("success", "Costumer deleted successfully"); + response.redirect("back"); } } diff --git a/resources/views/costumer/create.edge b/resources/views/costumer/create.edge index b74a290..9d02ee3 100644 --- a/resources/views/costumer/create.edge +++ b/resources/views/costumer/create.edge @@ -2,7 +2,7 @@ @section('main')
-

New product

+

New Costumer

Back
@@ -45,37 +45,37 @@ error: flashMessages.has('errors.number') && flashMessages.get('errors.number') }) -@!component('components/input', { - name: 'district', - text: 'District', - type: 'text', - value: flashMessages.get('district') || '', - error: flashMessages.has('errors.district') && flashMessages.get('errors.district') -}) + @!component('components/input', { + name: 'district', + text: 'District', + type: 'text', + value: flashMessages.get('district') || '', + error: flashMessages.has('errors.district') && flashMessages.get('errors.district') + }) -@!component('components/input', { - name: 'city', - text: 'City', - type: 'text', - value: flashMessages.get('city') || '', - error: flashMessages.has('errors.city') && flashMessages.get('errors.city') -}) + @!component('components/input', { + name: 'city', + text: 'City', + type: 'text', + value: flashMessages.get('city') || '', + error: flashMessages.has('errors.city') && flashMessages.get('errors.city') + }) -@!component('components/input', { - name: 'zip', - text: 'ZIP', - type: 'text', - value: flashMessages.get('zip') || '', - error: flashMessages.has('errors.zip') && flashMessages.get('errors.zip') -}) + @!component('components/input', { + name: 'zip', + text: 'ZIP', + type: 'text', + value: flashMessages.get('zip') || '', + error: flashMessages.has('errors.zip') && flashMessages.get('errors.zip') + }) -@!component('components/input', { - name: 'state', - text: 'State', - type: 'text', - value: flashMessages.get('state') || '', - error: flashMessages.has('errors.state') && flashMessages.get('errors.state') -}) + @!component('components/input', { + name: 'state', + text: 'State', + type: 'text', + value: flashMessages.get('state') || '', + error: flashMessages.has('errors.state') && flashMessages.get('errors.state') + }) diff --git a/resources/views/costumer/edit.edge b/resources/views/costumer/edit.edge index c64d5af..bbe03ed 100644 --- a/resources/views/costumer/edit.edge +++ b/resources/views/costumer/edit.edge @@ -45,37 +45,37 @@ error: flashMessages.has('errors.number') && flashMessages.get('errors.number') }) -@!component('components/input', { - name: 'district', - text: 'District', - type: 'text', - value: costumer.district || '', - error: flashMessages.has('errors.district') && flashMessages.get('errors.district') -}) + @!component('components/input', { + name: 'district', + text: 'District', + type: 'text', + value: costumer.district || '', + error: flashMessages.has('errors.district') && flashMessages.get('errors.district') + }) -@!component('components/input', { - name: 'city', - text: 'City', - type: 'text', - value: costumer.city || '', - error: flashMessages.has('errors.city') && flashMessages.get('errors.city') -}) + @!component('components/input', { + name: 'city', + text: 'City', + type: 'text', + value: costumer.city || '', + error: flashMessages.has('errors.city') && flashMessages.get('errors.city') + }) -@!component('components/input', { - name: 'zip', - text: 'ZIP', - type: 'text', - value: costumer.zip || '', - error: flashMessages.has('errors.zip') && flashMessages.get('errors.zip') -}) + @!component('components/input', { + name: 'zip', + text: 'ZIP', + type: 'text', + value: costumer.zip || '', + error: flashMessages.has('errors.zip') && flashMessages.get('errors.zip') + }) -@!component('components/input', { - name: 'state', - text: 'State', - type: 'text', - value: costumer.state || '', - error: flashMessages.has('errors.state') && flashMessages.get('errors.state') -}) + @!component('components/input', { + name: 'state', + text: 'State', + type: 'text', + value: costumer.state || '', + error: flashMessages.has('errors.state') && flashMessages.get('errors.state') + })