Skip to content

Commit

Permalink
Merge pull request #106 from jefersonralmeida/development
Browse files Browse the repository at this point in the history
Versão 1.1
  • Loading branch information
jefersonralmeida authored Apr 25, 2020
2 parents 0a50f61 + eb37917 commit d820583
Show file tree
Hide file tree
Showing 19 changed files with 604 additions and 318 deletions.
8 changes: 5 additions & 3 deletions api/app/Http/Requests/CreateDemandRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ public function authorize()
public function rules()
{
return [
'title' => 'required',
'text' => 'required',
'quantity' => 'filled|int|min:0'
'title' => 'required|string',
'text' => 'required|string',
'contact_info' => 'filled|string',
'quantity' => 'filled|int|min:0',
'unit' => 'filled|string'
];
}
}
1 change: 1 addition & 0 deletions api/app/Http/Requests/CreateEntityRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ function ($attribute, $value, $fail) {
'name' => 'required|string|min:4',
'legal_name' => 'required|string|min:4',
'description' => 'required|string|min:10',
'contact_info' => 'filled|string',
'street_address' => 'required|string:10',
'district_id' => 'required|int|exists:districts,id',
];
Expand Down
2 changes: 2 additions & 0 deletions api/app/Http/Requests/UpdateDemandRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ public function rules()
return [
'title' => 'filled',
'text' => 'filled',
'contact_info' => 'filled|string',
'quantity' => 'filled|int|min:0',
'unit' => 'filled|string',
];
}
}
3 changes: 1 addition & 2 deletions api/app/Http/Requests/UpdateEntityRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public function filters()
return [
'name' => 'uppercase',
'legal_name' => 'uppercase',
'city' => 'uppercase',
'state' => 'uppercase',
];
}

Expand All @@ -44,6 +42,7 @@ public function rules()
'name' => 'filled|string|min:4',
'legal_name' => 'filled|string|min:4',
'description' => 'filled|string|min:10',
'contact_info' => 'filled|string',
'street_address' => 'filled|string:10',
'district_id' => 'filled|int|exists:districts,id'
];
Expand Down
2 changes: 1 addition & 1 deletion api/app/Models/Demand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Demand extends Model

use Searchable;

protected $fillable = ['title', 'text', 'quantity', 'entity_id'];
protected $fillable = ['title', 'text', 'contact_info', 'quantity', 'entity_id', 'unit'];
protected $hidden = ['entity_id'];

public function toSearchableArray()
Expand Down
10 changes: 8 additions & 2 deletions api/app/Models/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@ class Entity extends Model
'name',
'legal_name',
'description',
'contact_info',
'street_address',
'district_id',
'entity_type_id',
'entity_type_document',
];

protected $hidden = ['district_id', 'district'];
protected $hidden = ['district'];

protected $appends = ['entity_type', 'entity_type_document_label', 'city'];
protected $appends = ['entity_type', 'entity_type_document_label', 'city', 'state_id'];

public function getEntityTypeAttribute()
{
Expand All @@ -51,6 +52,11 @@ public function getCityAttribute()
return "{$this->district->name} - {$this->district->uf}";
}

public function getStateIdAttribute()
{
return $this->district->state->id;
}

/**
* Users NxM relationship
* @return BelongsToMany
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddContactInfoColumnToEntitiesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('entities', function (Blueprint $table) {
$table->string('contact_info')->nullable()->after('description');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('entities', function (Blueprint $table) {
//
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddContactInfoAndUnitColumnsToDemandsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('demands', function (Blueprint $table) {
$table->string('contact_info')->nullable()->after('text');
$table->string('unit')->nullable()->after('quantity');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('demands', function (Blueprint $table) {
//
});
}
}
4 changes: 3 additions & 1 deletion api/routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
Route::get('states', 'StatesController@index');
Route::get('states/{state}/search-districts', 'StatesController@searchDistricts');

// route to get entities details
Route::get('entities/{entity}', 'EntitiesController@info');

Route::middleware('auth:api')->group(function() {

// auth routes
Expand All @@ -31,7 +34,6 @@
Route::get('entities/{entity}/demands', 'EntitiesController@indexDemands');
Route::post('entities/{entity}/new-demand', 'EntitiesController@createDemand')->middleware('can:createDemand,entity');
Route::post('entities', 'EntitiesController@create');
Route::get('entities/{entity}', 'EntitiesController@info');
Route::put('entities/{entity}', 'EntitiesController@update')->middleware('can:update,entity');
Route::post('entities/{entity}/invite/{invitee}', 'EntitiesController@invite')->middleware('can:invite,entity');
Route::post('entities/{entity}/leave', 'EntitiesController@leave')->middleware('can:leave,entity');
Expand Down
67 changes: 23 additions & 44 deletions spa/src/components/forms/Outros.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</div>
<div class="form-group">
<v-text-field
ref="address"
ref="street_address"
v-model="entity.street_address"
:counter="300"
:rules="[rules.required, (value) => rules.min(value, 15), (value) => rules.max(value, 300)]"
Expand All @@ -59,23 +59,18 @@
></v-select>
</div>
<div class="form-group col-md-10 col-sm-9 col-12">
<v-autocomplete
ref="city"
v-model="entity.city"
:disabled="entity.state == ''"
:items="cities"
item-text="name"
label="Cidade"
autocomplete="null"
placeholder="Digite o nome da cidade para buscar"
:search-input.sync="search"
outlined
:no-data-text="noDataText"
hide-selected
return-object
></v-autocomplete>
<DistrictSelector :stateId="entity.state" :disabled="entity.state == null" :rules="[rules.required]" :onChangeCB="onCityChange"/>
</div>
</div>
<div class="form-group">
<v-text-field
ref="contact_info"
v-model="entity.contact_info"
label="Contato"
placeholder="Ex: tel: (00) 0000-0000, email: [email protected]"
outlined
></v-text-field>
</div>
<div class="form-group">
<v-textarea
ref="description"
Expand All @@ -99,6 +94,7 @@
<script>
import api from "../../api";
import rules from "../../util/rules";
import DistrictSelector from "../widgets/DistrictSelector";
export default {
props: {
Expand All @@ -113,8 +109,8 @@ export default {
default: () => {}
},
loading: {
type: Boolean,
default: false
type: Boolean,
default: false
}
},
data() {
Expand All @@ -126,14 +122,11 @@ export default {
description: "",
street_address: "",
city: "",
state: ""
contact_info: "",
state: 0
},
statesFetched: false,
states: [],
cities: [],
search: null,
debounce: null,
noDataText: "Continue digitando para encontrar uma cidade."
};
},
computed: {
Expand All @@ -143,6 +136,7 @@ export default {
entity_type_id: 0,
cnpj: entity.cnpj,
name: entity.name,
contact_info: entity.contact_info,
legal_name: entity.legal_name,
description: entity.description,
street_address: entity.street_address,
Expand All @@ -169,38 +163,23 @@ export default {
this.statesFetched = true;
});
},
fetchCities(stateId, query) {
return api.getDistricts(stateId, query);
},
handleSubmit() {
if (!this.isValidForm()) return;
this.onSubmit(this.entityPayload);
},
isValidForm() {
return this.$refs.form.validate();
}
},
watch: {
search(query) {
if (query === null) return;
if (query.length < 3) {
this.noDataText = "Continue digitando para encontrar uma cidade.";
return;
}
clearTimeout(this.debounce);
let that = this;
this.debounce = setTimeout(function() {
that.fetchCities(that.entity.state, query).then(res => {
that.cities = res.data;
that.noDataText =
"Nenhuma cidade encontrada. Verifique a busca ou seja mais específico";
});
}, 300);
},
onCityChange(city){
this.entity.city = city;
}
},
created() {
this.fetchStates();
},
components: {
DistrictSelector
}
};
</script>
Expand Down
Loading

0 comments on commit d820583

Please sign in to comment.