-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
604 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.