Skip to content

Commit

Permalink
Merge pull request #1 from williamtcastro/function_create-events
Browse files Browse the repository at this point in the history
Function create events
  • Loading branch information
williamtcastro authored Oct 6, 2019
2 parents bd667ea + f68c173 commit a102b7c
Show file tree
Hide file tree
Showing 28 changed files with 7,641 additions and 5,498 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
root = true

[*]
indent_size = 2
indent_size = 4
indent_style = space
end_of_line = lf
charset = utf-8
Expand Down
4 changes: 4 additions & 0 deletions .env.test → .env.testing
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
HOST=127.0.0.1
PORT=4000

NODE_ENV=testing
DB_CONNECTION=sqlite
DB_HOST=127.0.0.1
DB_PORT=3306
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ tmp

# Environment variables, never commit this file
.env
.env-test

# The development sqlite file
database/development.sqlite
Expand Down
19 changes: 19 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
language: node_js
node_js:
- 10.16.3
cache: npm

install:
- npm ci

sricpt:
- adonis test
- npm run build

deploy:
provider: pages
skip-clanup: true
github-token: $GITHUB_TOKEN
on:
branch: master

46 changes: 46 additions & 0 deletions app/Controllers/Http/EventController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/** @type {typeof import('@adonisjs/lucid/src/Lucid/Model')} */
const Event = use('App/Models/Event')

class EventController {
async index() {
const events = Event.query()
.with('user', builder => {
builder.select(['id', 'name'])
})
.fetch()
return events
}

async show({ params }) {
const event = await Event.find(params.id)
await event.load('user', builder => {
builder.select(['id', 'name'])
})
return event
}

async store({ request, response }) {
const data = request.only([
'title',
'description',
'location_addres',
'location_city_state',
'start_time',
'event_time',
'user_id',
'event_type',
'language',
'dificult_level',
'max_attendess',
'is_public',
'require_registration',
'website',
])

const event = await Event.create(data)

return response.status(201).json(event)
}
}

module.exports = EventController
5 changes: 3 additions & 2 deletions app/Controllers/Http/RegisterUserController.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
const User = use('App/Models/User')

class RegisterUserController {
async store({ request }) {
async store({ request, response }) {
const data = request.only(['email', 'username', 'name', 'password'])
await User.create(data)
const user = await User.create(data)
if (user) return response.status(201).json({ message: 'user created' })
}
}

Expand Down
2 changes: 2 additions & 0 deletions app/Controllers/Http/ResetPasswordController.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class ResetPasswordController {
const user = await userToken.user().fetch()
user.password = password
await user.save()

return response.status(201).json({ mensage: 'Password reset' })
}
}

Expand Down
10 changes: 10 additions & 0 deletions app/Models/Event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/** @type {typeof import('@adonisjs/lucid/src/Lucid/Model')} */
const Model = use('Model')

class Event extends Model {
user() {
return this.belongsTo('App/Models/User')
}
}

module.exports = Event
4 changes: 4 additions & 0 deletions app/Models/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ class User extends Model {
tokens() {
return this.hasMany('App/Models/Token')
}

events() {
return this.hasMany('App/Models/Event')
}
}

module.exports = User
25 changes: 25 additions & 0 deletions app/Validators/Event.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const Antl = use('Antl')

class Event {
get validateAll() {
return true
}

get rules() {
return {
title: 'required',
description: 'required',
location_addres: 'required',
location_city_state: 'required',
start_time: 'required',
event_time: 'required',
user_id: 'required|exists:users,id',
}
}

get messages() {
return Antl.list('validation')
}
}

module.exports = Event
10 changes: 10 additions & 0 deletions app/Validators/Forgot.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
const Antl = use('Antl')

class Forgot {
get validateAll() {
return true
}

get rules() {
return {
email: 'email|required',
}
}

get messages() {
return Antl.list('validation')
}
}

module.exports = Forgot
16 changes: 13 additions & 3 deletions app/Validators/RegisterUser.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
const Antl = use('Antl')

class RegisterUser {
get validateAll() {
return true
}

get rules() {
return {
username: 'required|unique:users',
username: 'required',
name: 'required',
email: 'email|required|unique:users',
password: 'required|confirmed',
email: 'email|required',
password: 'required',
}
}

get messages() {
return Antl.list('validation')
}
}

module.exports = RegisterUser
10 changes: 10 additions & 0 deletions app/Validators/Reset.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
const Antl = use('Antl')

class Reset {
get validateAll() {
return true
}

get rules() {
return {
token: 'required',
password: 'required|confirmed',
}
}

get messages() {
return Antl.list('validation')
}
}

module.exports = Reset
9 changes: 9 additions & 0 deletions app/Validators/Session.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
const Antl = use('Antl')
class Session {
get validateAll() {
return true
}

get rules() {
return {
email: 'email|required',
password: 'required',
}
}

get messages() {
return Antl.list('validation')
}
}

module.exports = Session
2 changes: 1 addition & 1 deletion config/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ module.exports = {
| based on HTTP headers/query string.
|
*/
locale: 'en',
locale: 'pt',
},

logger: {
Expand Down
Binary file modified database/adonis.sqlite
Binary file not shown.
12 changes: 12 additions & 0 deletions database/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,15 @@ Factory.blueprint('App/Models/Token', (faker, i, data = {}) => {
...data,
}
})

Factory.blueprint('App/Models/Event', (faker, i, data = {}) => {
return {
title: faker.sentence({ words: 5 }),
description: faker.paragraph(),
location_addres: faker.string({ lenght: 15 }),
location_city_state: faker.string({ lenght: 15 }),
start_time: faker.date({ string: true, american: false }),
event_time: faker.hour(),
...data,
}
})
4 changes: 4 additions & 0 deletions database/migrations/1503250034279_user.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class UserSchema extends Schema {
table.string('github')
table.string('email').notNullable()
table.string('password').notNullable()
table
.boolean('is_admin')
.defaultTo(false)
.notNullable()
table.timestamps()
})
}
Expand Down
37 changes: 37 additions & 0 deletions database/migrations/1570064702996_events_schema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/** @type {import('@adonisjs/lucid/src/Schema')} */
const Schema = use('Schema')

class EventsSchema extends Schema {
up() {
this.create('events', table => {
table.increments()
table
.integer('user_id')
.unsigned()
.references('id')
.inTable('users')
.onDelete('SET NULL')
.onUpdate('CASCADE')
table.string('title').notNullable()
table.text('description').notNullable()
table.string('location_addres').notNullable()
table.string('location_city_state').notNullable()
table.date('start_time').notNullable()
table.time('event_time', { precision: 4 }).notNullable()
table.string('event_type').notNullable()
table.string('language').notNullable()
table.integer('dificult_level').notNullable()
table.integer('max_attendess').notNullable()
table.boolean('is_public').notNullable()
table.boolean('require_registration').notNullable()
table.string('website')
table.timestamps()
})
}

down() {
this.drop('events')
}
}

module.exports = EventsSchema
Loading

0 comments on commit a102b7c

Please sign in to comment.