Skip to content

Commit

Permalink
refactor: fixing some code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ipdmartins committed Sep 6, 2020
1 parent 8f80ce4 commit 03a2129
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 109 deletions.
11 changes: 11 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
PORT=
HOST=
NODE_ENV=
APP_KEY=
SESSION_DRIVER=
DB_CONNECTION=
DB_HOST=
DB_USER=
DB_PASSWORD=
DB_NAME=
DB_PORT=
104 changes: 52 additions & 52 deletions app/Controllers/Http/CostumersController.ts
Original file line number Diff line number Diff line change
@@ -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(),
Expand All @@ -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,
Expand All @@ -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");
}
}
58 changes: 29 additions & 29 deletions resources/views/costumer/create.edge
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

@section('main')
<div class="flex justify-sb mb-3">
<h2 class="subtitle">New product</h2>
<h2 class="subtitle">New Costumer</h2>
<a href="/costumers" class="button info">Back</a>
</div>

Expand Down Expand Up @@ -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')
})

<button type="submit" class="button success mt-2">Save</button>
</form>
Expand Down
56 changes: 28 additions & 28 deletions resources/views/costumer/edit.edge
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})

<button type="submit" class="button success">Save</button>
</form>
Expand Down

0 comments on commit 03a2129

Please sign in to comment.