Skip to content

Commit

Permalink
projetos
Browse files Browse the repository at this point in the history
  • Loading branch information
wjrcode committed Oct 16, 2022
1 parent 311c6ad commit db99c42
Show file tree
Hide file tree
Showing 14 changed files with 604 additions and 41 deletions.
191 changes: 191 additions & 0 deletions lib/Controller/ProjetoController.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
import 'dart:ffi';

import 'package:flutter/material.dart';
import 'package:http/http.dart';
import 'package:organizei/Model/Projeto/ProjetoModel.dart';
import 'package:organizei/Controller/Base/Base.dart';
import 'package:organizei/Repository/ProjetoRepository.dart';
import 'package:organizei/services/persistencia/login.configuracoes.dart';

class ProjetoController extends Base {
ProjetoController(this.repository, this.context);

final BuildContext context;
final ProjetoRepository repository;
final formKey = GlobalKey<FormState>();
var model = ProjetoModel();
//var loginConfiguracoes = LoginConfiguracoes();

projetoId(int? value) => model.id = value;
projetoNome(String? value) => model.nome = value.toString();
projetoDataInical(String? value) => model.dataInicial = value.toString();
projetoObservacao(String? value) => model.observacao = value.toString();
projetoDataFinal(String? value) => model.dataFinal = value.toString();
projetoCor(String? value) => model.cor = value.toString();

var controllerNome = TextEditingController();
var controllerObservacao = TextEditingController();
var controllerPrioridade = TextEditingController();
var controllerCor = TextEditingController();
var controllerDataIncial = TextEditingController();
var controllerDataFinal = TextEditingController();

Future<bool> saveProjeto() async {
if (!formKey.currentState!.validate()) {
return false;
}

formKey.currentState!.save();

try {
if (model.id == null) {
return await repository.addProjeto(model).then((value) async {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
elevation: 6.0,
behavior: SnackBarBehavior.floating,
shape: RoundedRectangleBorder(
side: const BorderSide(color: Colors.black, width: 3),
borderRadius: BorderRadius.circular(16),
),
content: Text(
value.msg!,
style: const TextStyle(
color: Colors.black,
fontWeight: FontWeight.w500,
),
),
backgroundColor: value.valido!
? const Color(0xFF74C198)
: const Color(0xFFEF7E69),
),
);

await Future.delayed(const Duration(milliseconds: 500));

if (value.valido!) {
return value.valido!;
} else {
return false;
}
});
} else {
return await repository.updateProjeto(model).then((value) async {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
elevation: 6.0,
behavior: SnackBarBehavior.floating,
shape: RoundedRectangleBorder(
side: const BorderSide(color: Colors.black, width: 3),
borderRadius: BorderRadius.circular(16),
),
content: Text(
value.msg!,
style: const TextStyle(
color: Colors.black,
fontWeight: FontWeight.w500,
),
),
backgroundColor: value.valido!
? const Color(0xFF74C198)
: const Color(0xFFEF7E69),
),
);

await Future.delayed(const Duration(milliseconds: 500));

if (value.valido!) {
return value.valido!;
} else {
return false;
}
});
}
} catch (e) {
print(e);
return false;
}
}

Future<Map<String, dynamic>> getProjetos() async {
return await repository.getProjetos();
}

Future<bool> concluirProjeto(bool concluido) async {
try {
return await repository
.concluirProjeto(model, concluido)
.then((value) async {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
elevation: 6.0,
behavior: SnackBarBehavior.floating,
shape: RoundedRectangleBorder(
side: const BorderSide(color: Colors.black, width: 3),
borderRadius: BorderRadius.circular(16),
),
content: Text(
value.msg!,
style: const TextStyle(
color: Colors.black,
fontWeight: FontWeight.w500,
),
),
backgroundColor: value.valido!
? const Color(0xFF74C198)
: const Color(0xFFEF7E69),
),
);

await Future.delayed(const Duration(milliseconds: 500));

if (value.valido!) {
return value.valido!;
} else {
return false;
}
});
} catch (e) {
print(e);
return false;
}
}

Future<bool> excluirProjeto() async {
try {
return await repository.excluirProjeto(model).then((value) async {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
elevation: 6.0,
behavior: SnackBarBehavior.floating,
shape: RoundedRectangleBorder(
side: const BorderSide(color: Colors.black, width: 3),
borderRadius: BorderRadius.circular(16),
),
content: Text(
value.msg!,
style: const TextStyle(
color: Colors.black,
fontWeight: FontWeight.w500,
),
),
backgroundColor: value.valido!
? const Color(0xFF74C198)
: const Color(0xFFEF7E69),
),
);

await Future.delayed(const Duration(milliseconds: 500));

if (value.valido!) {
return value.valido!;
} else {
return false;
}
});
} catch (e) {
print(e);
return false;
}
}
}
4 changes: 2 additions & 2 deletions lib/Model/Login/LoginModel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class LoginModel {

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['usuario'] = this.usuario;
data['senha'] = this.senha;
data['usuario'] = usuario;
data['senha'] = senha;

return data;
}
Expand Down
40 changes: 40 additions & 0 deletions lib/Model/Projeto/ProjetoModel.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import 'package:organizei/Model/API/ResponseAPIModel.dart';

class ProjetoModel {
int? id;
String? nome;
String? dataInicial;
String? observacao;
String? dataFinal;
String? cor;
ResponseAPIModel? responseAPIModel;

ProjetoModel(
{this.id,
this.nome,
this.dataInicial,
this.observacao,
this.dataFinal,
this.cor});

ProjetoModel.fromJson(Map<String, dynamic> json) {
id = int.parse(json['id']);
nome = json['nome'];
dataInicial = json['dataInicial'];
observacao = json['observacao'];
dataFinal = json['dataFinal'];
cor = json['cor'];
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = id;
data['nome'] = nome;
data['dataInicial'] = dataInicial;
data['observacao'] = observacao;
data['dataFinal'] = dataFinal;
data['cor'] = cor;

return data;
}
}
12 changes: 6 additions & 6 deletions lib/Model/Tarefa/TarefaModel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ class TarefaModel {

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = this.id;
data['nome'] = this.nome;
data['data'] = this.data;
data['observacao'] = this.observacao;
data['prioridade'] = this.prioridade;
data['cor'] = this.cor;
data['id'] = id;
data['nome'] = nome;
data['data'] = data;
data['observacao'] = observacao;
data['prioridade'] = prioridade;
data['cor'] = cor;

return data;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Repository/HabitoRepository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ class HabitoRepository {
}

Future<List<HabitoModel>> getHabitos() async {
Uri _uriSearchProduto = Uri.parse(ApiModel.ApiUrl + '/habitos');
Uri url = Uri.parse(ApiModel.ApiUrl + '/habitos');

var _url = Uri.parse(_uriSearchProduto.toString());
var _url = Uri.parse(url.toString());
final response = await http.get(_url, headers: ApiModel.headers);

Map<String, dynamic> jsonMap = jsonDecode(response.body);
Expand Down
8 changes: 4 additions & 4 deletions lib/Repository/LembreteRepository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ class LembreteRepository {
}

Future<List<LembreteModel>> getLembretes() async {
Uri _uriSearchProduto = Uri.parse(ApiModel.ApiUrl + '/lembretes');
Uri url = Uri.parse(ApiModel.ApiUrl + '/lembretes');

var _url = Uri.parse(_uriSearchProduto.toString());
var _url = Uri.parse(url.toString());
final response = await http.get(_url, headers: ApiModel.headers);

Map<String, dynamic> jsonMap = jsonDecode(response.body);
Expand Down Expand Up @@ -77,9 +77,9 @@ class LembreteRepository {
}

Future<Map<String, dynamic>> get() async {
Uri _uriSearchProduto = Uri.parse(ApiModel.ApiUrl + '/lembretes');
Uri url = Uri.parse(ApiModel.ApiUrl + '/lembretes');

var _url = Uri.parse(_uriSearchProduto.toString());
var _url = Uri.parse(url.toString());
final response = await http.get(_url, headers: ApiModel.headers);

Map<String, dynamic> jsonMap = jsonDecode(response.body);
Expand Down
4 changes: 2 additions & 2 deletions lib/Repository/ListaRepository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ class ListaRepository {
}

Future<Map<String, dynamic>> getListas() async {
Uri _uriSearchProduto = Uri.parse(ApiModel.ApiUrl + '/listas');
Uri url = Uri.parse(ApiModel.ApiUrl + '/listas');

var _url = Uri.parse(_uriSearchProduto.toString());
var _url = Uri.parse(url.toString());
final response = await http.get(_url, headers: ApiModel.headers);

Map<String, dynamic> jsonMap = jsonDecode(response.body);
Expand Down
88 changes: 88 additions & 0 deletions lib/Repository/ProjetoRepository.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import 'dart:convert';

import 'package:organizei/Model/API/APIModel.dart';

import 'package:http/http.dart' as http;
import 'package:organizei/Model/API/ResponseAPIModel.dart';
import 'package:organizei/Model/Projeto/ProjetoModel.dart';

class ProjetoRepository {
Future<ResponseAPIModel> addProjeto(ProjetoModel model) async {
var json = {
"nome": model.nome,
"dataInicial": model.dataInicial,
"observacao": model.observacao,
"dataFinal": model.dataFinal,
"cor": model.cor,
};

print('olha to here');

final response = await http.post(Uri.parse(ApiModel.ApiUrl + '/projetos'),
headers: ApiModel.headers, body: jsonEncode(json));

return ResponseAPIModel.fromJson(jsonDecode(response.body));
}

Future<ResponseAPIModel> updateProjeto(ProjetoModel model) async {
var json = {
"nome": model.nome,
"dataInicial": model.dataInicial,
"observacao": model.observacao,
"dataFinal": model.dataFinal,
"cor": model.cor,
};

final response = await http.put(
Uri.parse(ApiModel.ApiUrl + '/projetos/' + model.id.toString()),
headers: ApiModel.headers,
body: jsonEncode(json));

return ResponseAPIModel.fromJson(jsonDecode(response.body));
}

Future<ResponseAPIModel> concluirProjeto(
ProjetoModel model, bool concluido) async {
var json = {
"concluido": concluido,
};

final response = await http.put(
Uri.parse(
ApiModel.ApiUrl + '/projetos/' + model.id.toString() + '/concluir'),
headers: ApiModel.headers,
body: jsonEncode(json));

return ResponseAPIModel.fromJson(jsonDecode(response.body));
}

Future<ResponseAPIModel> excluirProjeto(ProjetoModel model) async {
final response = await http.delete(
Uri.parse(ApiModel.ApiUrl + '/projetos/' + model.id.toString()),
headers: ApiModel.headers);

return ResponseAPIModel.fromJson(jsonDecode(response.body));
}

Future<Map<String, dynamic>> getProjetos() async {
Uri url = Uri.parse(ApiModel.ApiUrl + '/projetos');

var _url = Uri.parse(url.toString());
final response = await http.get(_url, headers: ApiModel.headers);

Map<String, dynamic> jsonMap = jsonDecode(response.body);

return jsonMap;
}

Future<Map<String, dynamic>> get() async {
Uri url = Uri.parse(ApiModel.ApiUrl + '/projetos');

var _url = Uri.parse(url.toString());
final response = await http.get(_url, headers: ApiModel.headers);

Map<String, dynamic> jsonMap = jsonDecode(response.body);

return jsonMap;
}
}
Loading

0 comments on commit db99c42

Please sign in to comment.