Skip to content

Commit

Permalink
Merge pull request #6 from joaopegoraro/release/v1.0.2
Browse files Browse the repository at this point in the history
Release/v1.0.2
  • Loading branch information
joaopegoraro authored Sep 5, 2023
2 parents b6bd698 + 8a1d876 commit c3ec8fb
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 204 deletions.
18 changes: 7 additions & 11 deletions lib/data/api/api_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'package:meu_mengao/data/models/campeonato.dart';
import 'package:meu_mengao/data/models/noticia.dart';
import 'package:meu_mengao/data/models/partida.dart';
import 'package:meu_mengao/data/models/posicao.dart';
import 'package:meu_mengao/data/repositories/auth_repository.dart';

abstract class ApiService {
Future<List<Noticia>?> getNoticias();
Expand All @@ -28,10 +27,6 @@ abstract class ApiService {
}

class ApiServiceImpl extends ApiService {
ApiServiceImpl(this._authRepository);

final AuthRepository _authRepository;

@override
Future<List<Noticia>?> getNoticias() async {
return _getData("noticias", (response) {
Expand Down Expand Up @@ -94,17 +89,18 @@ class ApiServiceImpl extends ApiService {
try {
final baseUrl = dotenv.env['BASE_URL'];
final url = Uri.parse("$baseUrl$endpoint");
final token = await _authRepository.getToken();
final response = await http.get(url, headers: {'Authorization': 'Bearer $token'});
final response = await http.get(url);
return response.statusCode == 200 ? parseResponse(response) : null;
} catch (e) {
if (kDebugMode) print(e);
} catch (e, stackTrace) {
if (kDebugMode) {
print(e);
print(stackTrace);
}
return null;
}
}
}

final apiServiceProvider = Provider<ApiService>((ref) {
final authRepository = ref.watch(authRepositoryProvider);
return ApiServiceImpl(authRepository);
return ApiServiceImpl();
});
6 changes: 0 additions & 6 deletions lib/data/database/entities/campeonato_entity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ class CampeonatoEntity {
required this.id,
required this.nome,
required this.ano,
required this.logo,
required this.rodadaAtual,
required this.possuiClassificacao,
});

final String? id;
final String? nome;
final String? ano;
final String? logo;
final int? rodadaAtual;
final bool? possuiClassificacao;

Expand All @@ -23,7 +21,6 @@ class CampeonatoEntity {
id: id ?? "",
nome: nome ?? "",
ano: ano ?? "",
logo: logo ?? "",
rodadaAtual: rodadaAtual ?? 0,
possuiClassificacao: possuiClassificacao ?? false,
);
Expand All @@ -34,7 +31,6 @@ class CampeonatoEntity {
id: campeonato.id,
nome: campeonato.nome,
ano: campeonato.ano,
logo: campeonato.logo,
rodadaAtual: campeonato.rodadaAtual,
possuiClassificacao: campeonato.possuiClassificacao,
);
Expand All @@ -45,7 +41,6 @@ class CampeonatoEntity {
idColumn: id,
nomeColumn: nome,
anoColumn: ano,
logoColumn: logo,
rodadaAtualColumn: rodadaAtual,
possuiClassificacaoColumn: possuiClassificacao == true ? 1 : 0,
};
Expand All @@ -56,7 +51,6 @@ class CampeonatoEntity {
id: map[idColumn] as String?,
nome: map[nomeColumn] as String?,
ano: map[anoColumn] as String?,
logo: map[logoColumn] as String?,
rodadaAtual: map[rodadaAtualColumn] as int?,
possuiClassificacao: (map[possuiClassificacaoColumn] as int?) != 0,
);
Expand Down
21 changes: 7 additions & 14 deletions lib/data/models/campeonato.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ class Campeonato {
required this.id,
required this.nome,
required this.ano,
required this.logo,
required this.rodadaAtual,
required this.possuiClassificacao,
});

final String id;
final String nome;
final String ano;
final String logo;
final int rodadaAtual;
final bool possuiClassificacao;

Expand All @@ -24,15 +22,13 @@ class Campeonato {
String? id,
String? nome,
String? ano,
String? logo,
int? rodadaAtual,
bool? possuiClassificacao,
}) {
return Campeonato(
id: id ?? this.id,
nome: nome ?? this.nome,
ano: ano ?? this.ano,
logo: logo ?? this.logo,
rodadaAtual: rodadaAtual ?? this.rodadaAtual,
possuiClassificacao: possuiClassificacao ?? this.possuiClassificacao,
);
Expand All @@ -43,9 +39,8 @@ class Campeonato {
'id': id,
'nome': nome,
'ano': ano,
'logo': logo,
'rodadaAtual': rodadaAtual,
'possuiClassificacao': possuiClassificacao,
'rodada_atual': rodadaAtual,
'possui_classificacao': possuiClassificacao,
};
}

Expand All @@ -54,15 +49,14 @@ class Campeonato {
id: map['id'] as String,
nome: map['nome'] as String,
ano: map['ano'] as String,
logo: map['logo'] as String,
rodadaAtual: map['rodadaAtual'] as int,
possuiClassificacao: map['possuiClassificacao'] as bool,
rodadaAtual: map['rodada_atual'] as int,
possuiClassificacao: map['possui_classificacao'] as bool,
);
}

@override
String toString() {
return 'Campeonato(id: $id, nome: $nome, ano: $ano, logo: $logo, rodadaAtual: $rodadaAtual, possuiClassificacao: $possuiClassificacao)';
return 'Campeonato(id: $id, nome: $nome, ano: $ano, rodadaAtual: $rodadaAtual, possuiClassificacao: $possuiClassificacao)';
}

@override
Expand All @@ -72,7 +66,6 @@ class Campeonato {
return other.id == id &&
other.nome == nome &&
other.ano == ano &&
other.logo == logo &&
other.rodadaAtual == rodadaAtual &&
other.possuiClassificacao == possuiClassificacao;
}
Expand All @@ -82,12 +75,12 @@ class Campeonato {
return id.hashCode ^
nome.hashCode ^
ano.hashCode ^
logo.hashCode ^
rodadaAtual.hashCode ^
possuiClassificacao.hashCode;
}

String toJson() => json.encode(toMap());

factory Campeonato.fromJson(String source) => Campeonato.fromMap(json.decode(source) as Map<String, dynamic>);
factory Campeonato.fromJson(String source) =>
Campeonato.fromMap(json.decode(source) as Map<String, dynamic>);
}
22 changes: 15 additions & 7 deletions lib/data/models/noticia.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,21 @@ class Noticia {
'link': link,
'data': data?.millisecondsSinceEpoch,
'titulo': titulo,
'logoSite': logoSite,
'foto': foto,
'logo_site': logoSite,
'foto_base_64': foto,
};
}

factory Noticia.fromMap(Map<String, dynamic> map) {
return Noticia(
id: map['id'] as int,
link: map['link'] as String,
data: map['data'] != null ? DateTime.fromMillisecondsSinceEpoch(int.tryParse(map['data']) ?? 0) : null,
data: map['data'] != null
? DateTime.fromMillisecondsSinceEpoch(int.tryParse(map['data']) ?? 0)
: null,
titulo: map['titulo'] as String,
logoSite: map['logoSite'] as String,
foto: map['foto'] != null ? map['foto'] as String : null,
logoSite: map['logo_site'] as String,
foto: map['foto_base_64'] != null ? map['foto_base_64'] as String : null,
);
}

Expand All @@ -79,10 +81,16 @@ class Noticia {

@override
int get hashCode {
return id.hashCode ^ link.hashCode ^ data.hashCode ^ titulo.hashCode ^ logoSite.hashCode ^ foto.hashCode;
return id.hashCode ^
link.hashCode ^
data.hashCode ^
titulo.hashCode ^
logoSite.hashCode ^
foto.hashCode;
}

String toJson() => json.encode(toMap());

factory Noticia.fromJson(String source) => Noticia.fromMap(json.decode(source) as Map<String, dynamic>);
factory Noticia.fromJson(String source) =>
Noticia.fromMap(json.decode(source) as Map<String, dynamic>);
}
43 changes: 23 additions & 20 deletions lib/data/models/partida.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,33 +96,35 @@ class Partida {
return <String, dynamic>{
'id': id,
'campeonato': campeonato,
'campeonatoId': campeonatoId,
'campeonato_id': campeonatoId,
'data': data?.millisecondsSinceEpoch.toString(),
'rodadaName': rodadaName,
'rodadaIndex': rodadaIndex,
'timeCasa': timeCasa,
'golsCasa': golsCasa,
'timeFora': timeFora,
'golsFora': golsFora,
'escudoCasa': escudoCasa,
'escudoFora': escudoFora,
'rodada_name': rodadaName,
'rodada_index': rodadaIndex,
'time_casa': timeCasa,
'gols_casa': golsCasa,
'time_fora': timeFora,
'gols_fora': golsFora,
'escudo_casa': escudoCasa,
'escudo_fora': escudoFora,
};
}

factory Partida.fromMap(Map<String, dynamic> map) {
return Partida(
id: map['id'] as String,
campeonato: map['campeonato'] as String,
campeonatoId: map['campeonatoId'] as String,
data: map['data'] != null ? DateTime.fromMillisecondsSinceEpoch(int.tryParse(map['data']) ?? 0) : null,
rodadaName: map['rodadaName'] != null ? map['rodadaName'] as String : null,
rodadaIndex: map['rodadaIndex'] as int?,
timeCasa: map['timeCasa'] as String,
golsCasa: int.tryParse(map['golsCasa']),
timeFora: map['timeFora'] as String,
golsFora: int.tryParse(map['golsFora']),
escudoCasa: map['escudoCasa'] as String,
escudoFora: map['escudoFora'] as String,
campeonatoId: map['campeonato_id'] as String,
data: map['data'] != null
? DateTime.fromMillisecondsSinceEpoch(int.tryParse(map['data']) ?? 0)
: null,
rodadaName: map['rodada_name'] != null ? map['rodada_name'] as String : null,
rodadaIndex: map['rodada_index'] as int?,
timeCasa: map['time_casa'] as String,
golsCasa: int.tryParse(map['gols_casa']),
timeFora: map['time_fora'] as String,
golsFora: int.tryParse(map['gols_fora']),
escudoCasa: map['escudo_casa'] as String,
escudoFora: map['escudo_fora'] as String,
);
}

Expand Down Expand Up @@ -167,5 +169,6 @@ class Partida {

String toJson() => json.encode(toMap());

factory Partida.fromJson(String source) => Partida.fromMap(json.decode(source) as Map<String, dynamic>);
factory Partida.fromJson(String source) =>
Partida.fromMap(json.decode(source) as Map<String, dynamic>);
}
35 changes: 18 additions & 17 deletions lib/data/models/posicao.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,39 +78,39 @@ class Posicao {
return <String, dynamic>{
'id': id,
'posicao': posicao,
'nomeTime': nomeTime,
'escudoTime': escudoTime,
'nome_time': nomeTime,
'escudo_time': escudoTime,
'pontos': pontos,
'jogos': jogos,
'vitorias': vitorias,
'empates': empates,
'derrotas': derrotas,
'golsFeitos': golsFeitos,
'golsSofridos': golsSofridos,
'saldoGols': saldoGols,
'campeonatoId': campeonatoId,
'classificacaoName': classificacaoName,
'classificacaoIndex': classificacaoIndex,
'gols_feitos': golsFeitos,
'gols_sofridos': golsSofridos,
'saldo_gols': saldoGols,
'campeonato_id': campeonatoId,
'classificacao_name': classificacaoName,
'classificacao_index': classificacaoIndex,
};
}

factory Posicao.fromMap(Map<String, dynamic> map) {
return Posicao(
id: map['id'] as String,
posicao: int.tryParse(map['posicao']) ?? 0,
nomeTime: map['nomeTime'] as String,
escudoTime: map['escudoTime'] != null ? map['escudoTime'] as String : null,
nomeTime: map['nome_time'] as String,
escudoTime: map['escudo_time'] != null ? map['escudo_time'] as String : null,
pontos: map['pontos'] as String,
jogos: map['jogos'] as String,
vitorias: map['vitorias'] as String,
empates: map['empates'] as String,
derrotas: map['derrotas'] as String,
golsFeitos: map['golsFeitos'] as String,
golsSofridos: map['golsSofridos'] as String,
saldoGols: map['saldoGols'] as String,
campeonatoId: map['campeonatoId'] as String,
classificacaoName: map['classificacaoName'] as String,
classificacaoIndex: map['classificacaoIndex'] as int,
golsFeitos: map['gols_feitos'] as String,
golsSofridos: map['gols_sofridos'] as String,
saldoGols: map['saldo_gols'] as String,
campeonatoId: map['campeonato_id'] as String,
classificacaoName: map['classificacao_name'] as String,
classificacaoIndex: map['classificacao_index'] as int,
);
}

Expand Down Expand Up @@ -161,5 +161,6 @@ class Posicao {

String toJson() => json.encode(toMap());

factory Posicao.fromJson(String source) => Posicao.fromMap(json.decode(source) as Map<String, dynamic>);
factory Posicao.fromJson(String source) =>
Posicao.fromMap(json.decode(source) as Map<String, dynamic>);
}
44 changes: 0 additions & 44 deletions lib/data/repositories/auth_repository.dart

This file was deleted.

Loading

0 comments on commit c3ec8fb

Please sign in to comment.