carga inicial
This commit is contained in:
@@ -0,0 +1,159 @@
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import '../../default_response_api.dart';
|
||||
import '../../funcoes_gerais.dart';
|
||||
import 'notificacoes_classes.dart';
|
||||
|
||||
class NotificacoesApi{
|
||||
|
||||
Future<NotificacoesResponse> getNotificacoes(int pagina,{String lidas = 'T',String curtidas = 'T'}) async{
|
||||
var retorno = new NotificacoesResponse(
|
||||
errorCode: 0,
|
||||
errorMessage: "",
|
||||
loadMore: false,
|
||||
results: []
|
||||
);
|
||||
if(await FuncoesGerais.checkInternetConnection() == false){
|
||||
retorno.errorCode = 1;
|
||||
retorno.errorMessage = "Sem conexão com a Internet";
|
||||
}
|
||||
else{
|
||||
var token = await FuncoesGerais.getUsuToken();
|
||||
String url = FuncoesGerais.urlBaseNewCore+'api/v1/user/notificacoes/$token/$pagina/10/$lidas/$curtidas';
|
||||
Map<String, String> heads = Map();
|
||||
heads["Content-type"] = "application/json; charset=utf-8";
|
||||
|
||||
var response = await http.get(url, headers: heads);
|
||||
|
||||
if (response != null) {
|
||||
if (response.statusCode == 200) {
|
||||
var data = jsonDecode(response.body);
|
||||
retorno = NotificacoesResponse.fromJson(data);
|
||||
}
|
||||
else{
|
||||
retorno.errorCode = response.statusCode;
|
||||
retorno.errorMessage = "Falha: ${response.statusCode}";
|
||||
}
|
||||
}
|
||||
else{
|
||||
retorno.errorCode = 2;
|
||||
retorno.errorMessage = "Falha na comunicação com o server. Tente novamente";
|
||||
}
|
||||
}
|
||||
|
||||
return retorno;
|
||||
}
|
||||
|
||||
Future<NotificacaoResponse> getNotificacao(int id) async{
|
||||
var retorno = new NotificacaoResponse(
|
||||
errorCode: 0,
|
||||
errorMessage: ""
|
||||
);
|
||||
|
||||
if(await FuncoesGerais.checkInternetConnection() == false){
|
||||
retorno.errorCode = 1;
|
||||
retorno.errorMessage = "Sem conexão com a Internet";
|
||||
}
|
||||
else{
|
||||
var token = await FuncoesGerais.getUsuToken();
|
||||
String url = FuncoesGerais.urlBaseNewCore+'api/v1/user/notificacao/$token/$id';
|
||||
Map<String, String> heads = Map();
|
||||
heads["Content-type"] = "application/json; charset=utf-8";
|
||||
|
||||
var response = await http.get(url, headers: heads);
|
||||
|
||||
if (response != null) {
|
||||
if (response.statusCode == 200) {
|
||||
var data = jsonDecode(response.body);
|
||||
retorno = NotificacaoResponse.fromJson(data);
|
||||
}
|
||||
else{
|
||||
retorno.errorCode = response.statusCode;
|
||||
retorno.errorMessage = "Falha: ${response.statusCode}";
|
||||
}
|
||||
}
|
||||
else{
|
||||
retorno.errorCode = 2;
|
||||
retorno.errorMessage = "Falha na comunicação com o server. Tente novamente";
|
||||
}
|
||||
}
|
||||
|
||||
return retorno;
|
||||
}
|
||||
|
||||
Future<DefaultResponseApi> notificacaoLike(NotificacaoLikeRequest post) async{
|
||||
DefaultResponseApi objRetorno = new DefaultResponseApi();
|
||||
|
||||
if(await FuncoesGerais.checkInternetConnection() == false){
|
||||
objRetorno.errorCode = 1;
|
||||
objRetorno.errorMessage = "Sem Conexão com a Internet.";
|
||||
return objRetorno;
|
||||
}
|
||||
|
||||
var token = await FuncoesGerais.getUsuToken();
|
||||
String url = FuncoesGerais.urlBaseNewCore+'api/v1/user/notificacaolike/$token';
|
||||
Map<String, String> heads = Map();
|
||||
heads["Content-type"] = "application/json; charset=utf-8";
|
||||
|
||||
var body = json.encode(post);
|
||||
|
||||
var response = await http.post(url, headers: heads, body: body);
|
||||
|
||||
if (response != null) {
|
||||
if (response.statusCode == 200) {
|
||||
var data = jsonDecode(response.body);
|
||||
objRetorno = DefaultResponseApi.fromJson(data);
|
||||
}
|
||||
else{
|
||||
objRetorno.errorCode = response.statusCode;
|
||||
objRetorno.errorMessage = "Falha: ${response.statusCode}";
|
||||
}
|
||||
}
|
||||
else{
|
||||
objRetorno.errorCode = 2;
|
||||
objRetorno.errorMessage = "Falha na comunicação com o server. Tente novamente";
|
||||
}
|
||||
|
||||
return objRetorno;
|
||||
}
|
||||
|
||||
Future<DefaultResponseApi> notificacaoLida(NotificacaoLidaRequest post, int notificacaoId) async{
|
||||
DefaultResponseApi objRetorno = new DefaultResponseApi();
|
||||
if(await FuncoesGerais.checkInternetConnection() == false){
|
||||
objRetorno.errorCode = 1;
|
||||
objRetorno.errorMessage = "Sem Conexão com a Internet.";
|
||||
return objRetorno;
|
||||
}
|
||||
|
||||
var token = await FuncoesGerais.getUsuToken();
|
||||
String url = FuncoesGerais.urlBaseNewCore+'api/v1/user/notificacaolida/$token/$notificacaoId';
|
||||
Map<String, String> heads = Map();
|
||||
heads["Content-type"] = "application/json; charset=utf-8";
|
||||
|
||||
var body = json.encode(post);
|
||||
|
||||
var response = await http.post(url, headers: heads, body: body);
|
||||
|
||||
|
||||
if (response != null) {
|
||||
if (response.statusCode == 200) {
|
||||
var data = jsonDecode(response.body);
|
||||
objRetorno = DefaultResponseApi.fromJson(data);
|
||||
}
|
||||
else{
|
||||
objRetorno.errorCode = response.statusCode;
|
||||
objRetorno.errorMessage = "Falha: ${response.statusCode}";
|
||||
}
|
||||
}
|
||||
else{
|
||||
objRetorno.errorCode = 2;
|
||||
objRetorno.errorMessage = "Falha na comunicação com o server. Tente novamente";
|
||||
}
|
||||
|
||||
return objRetorno;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
class NotificacaoLikeRequest {
|
||||
int iD;
|
||||
String like;
|
||||
|
||||
NotificacaoLikeRequest({this.iD, this.like});
|
||||
|
||||
NotificacaoLikeRequest.fromJson(Map<String, dynamic> json) {
|
||||
iD = json['ID'];
|
||||
like = json['Like'];
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||
data['ID'] = this.iD;
|
||||
data['Like'] = this.like;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
class NotificacaoLidaRequest {
|
||||
String latitude;
|
||||
String longitude;
|
||||
|
||||
NotificacaoLidaRequest({this.latitude, this.longitude});
|
||||
|
||||
NotificacaoLidaRequest.fromJson(Map<String, dynamic> json) {
|
||||
latitude = json['Latitude'];
|
||||
longitude = json['Longitude'];
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||
data['Latitude'] = this.latitude;
|
||||
data['Longitude'] = this.longitude;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class NotificacaoResponse {
|
||||
NotificacaoResults result;
|
||||
int errorCode;
|
||||
String errorMessage;
|
||||
|
||||
NotificacaoResponse({this.result, this.errorCode, this.errorMessage});
|
||||
|
||||
NotificacaoResponse.fromJson(Map<String, dynamic> json) {
|
||||
result =
|
||||
json['Result'] != null ? new NotificacaoResults.fromJson(json['Result']) : null;
|
||||
errorCode = json['ErrorCode'];
|
||||
errorMessage = json['ErrorMessage'];
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||
if (this.result != null) {
|
||||
data['Result'] = this.result.toJson();
|
||||
}
|
||||
data['ErrorCode'] = this.errorCode;
|
||||
data['ErrorMessage'] = this.errorMessage;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
class NotificacoesResponse {
|
||||
List<NotificacaoResults> results;
|
||||
int errorCode;
|
||||
String errorMessage;
|
||||
bool loadMore;
|
||||
|
||||
NotificacoesResponse({this.results, this.errorCode, this.errorMessage,this.loadMore});
|
||||
|
||||
NotificacoesResponse.fromJson(Map<String, dynamic> json) {
|
||||
if (json['Results'] != null) {
|
||||
results = new List<NotificacaoResults>();
|
||||
json['Results'].forEach((v) {
|
||||
results.add(new NotificacaoResults.fromJson(v));
|
||||
});
|
||||
}
|
||||
errorCode = json['ErrorCode'];
|
||||
errorMessage = json['ErrorMessage'];
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||
if (this.results != null) {
|
||||
data['Results'] = this.results.map((v) => v.toJson()).toList();
|
||||
}
|
||||
data['ErrorCode'] = this.errorCode;
|
||||
data['ErrorMessage'] = this.errorMessage;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
class NotificacaoResults {
|
||||
int iD;
|
||||
String titulo;
|
||||
String texto;
|
||||
String conteudo;
|
||||
String dataNotificacao;
|
||||
String tipoConteudo;
|
||||
bool visualizado;
|
||||
String imageUrl;
|
||||
String like;
|
||||
|
||||
NotificacaoResults(
|
||||
{this.iD,
|
||||
this.titulo,
|
||||
this.texto,
|
||||
this.conteudo,
|
||||
this.dataNotificacao,
|
||||
this.tipoConteudo,
|
||||
this.visualizado,
|
||||
this.imageUrl,
|
||||
this.like = ''});
|
||||
|
||||
NotificacaoResults.fromJson(Map<String, dynamic> json) {
|
||||
iD = json['ID'];
|
||||
titulo = json['Titulo'] ?? '';
|
||||
texto = json['Texto'];
|
||||
conteudo = json['Conteudo'];
|
||||
dataNotificacao = json['DataNotificacao'];
|
||||
tipoConteudo = json['TipoConteudo'];
|
||||
visualizado = json['Visualizado'];
|
||||
imageUrl = json['ImageUrl'];
|
||||
like = json['Like'] ?? '';
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||
data['ID'] = this.iD;
|
||||
data['Titulo'] = this.titulo;
|
||||
data['Texto'] = this.texto;
|
||||
data['Conteudo'] = this.conteudo;
|
||||
data['DataNotificacao'] = this.dataNotificacao;
|
||||
data['TipoConteudo'] = this.tipoConteudo;
|
||||
data['Visualizado'] = this.visualizado;
|
||||
data['ImageUrl'] = this.imageUrl;
|
||||
data['Like'] = this.like;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user