Skip to content

Commit

Permalink
Merge branch 'main' into chore/flutter-3.3-update
Browse files Browse the repository at this point in the history
  • Loading branch information
anmolvermamm authored Sep 6, 2022
2 parents c4bc818 + 4e43a49 commit a3d458c
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 45 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build_firebase_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
with:
name: release-ios
- name: Upload IPA
uses: wzieba/[email protected].2
uses: wzieba/[email protected].4
with:
appId: ${{secrets.FIREBASE_IOS_APPID}}
token: ${{secrets.FIREBASE_TOKEN}}
Expand Down Expand Up @@ -147,7 +147,7 @@ jobs:
with:
name: android-build
- name: Upload APK
uses: wzieba/[email protected].2
uses: wzieba/[email protected].4
with:
appId: ${{secrets.FIREBASE_APP_ID}}
token: ${{secrets.FIREBASE_TOKEN}}
Expand Down
2 changes: 1 addition & 1 deletion lib/features/joke_list/joke_list_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class JokeListPage extends StatelessWidget {
return ListView.builder(
itemCount: state.data.jokes.length,
itemBuilder: (context, index) {
return Text(state.data.jokes[index].joke).paddingAll(8);
return Text(state.data.jokes[index].value).paddingAll(8);
});
}

Expand Down
9 changes: 4 additions & 5 deletions lib/ui/model/jokes/ui_joke.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ import 'package:praxis_flutter/ui/model/ui_model.dart';


class UiJoke extends UIModel {
String joke;
int id;
String value;
String id;

UiJoke(this.id, this.joke);
UiJoke(this.id, this.value);
}

class UIJokeList extends UIModel {
List<UiJoke> jokes;
String type;

UIJokeList(this.type, this.jokes);
UIJokeList(this.jokes);
}
7 changes: 3 additions & 4 deletions lib/ui/model/jokes/ui_jokes_mapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import 'package:praxis_flutter_domain/entities/jokes/dm_joke.dart';
class UIJokeMapper extends UiModelMapper<JokesListWithType, UIJokeList> {
@override
JokesListWithType mapToDomain(UIJokeList modelItem) {
return JokesListWithType(modelItem.type,
modelItem.jokes.map((e) => Joke(e.id, e.joke)).toList());
return JokesListWithType(
modelItem.jokes.map((e) => Joke(e.id, e.value)).toList());
}

@override
UIJokeList mapToPresentation(JokesListWithType model) {
return UIJokeList(
model.type, model.jokeList.map((e) => UiJoke(e.id, e.joke)).toList());
return UIJokeList(model.jokeList.map((e) => UiJoke(e.id, e.value)).toList());
}
}
8 changes: 4 additions & 4 deletions praxis_data/lib/mapper/jokes/jokes_mappers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ class JokesListMapper extends EntityMapper<JokesListWithType, DTJokeList> {

@override
DTJokeList mapToData(JokesListWithType model) {
return DTJokeList(model.type,
return DTJokeList(
model.jokeList.map((e) => jokeMapper.mapToData(e)).toList());
}

@override
JokesListWithType mapToDomain(DTJokeList entity) {
return JokesListWithType(entity.type,
return JokesListWithType(
entity.jokeList.map((e) => jokeMapper.mapToDomain(e)).toList());
}
}
Expand All @@ -29,11 +29,11 @@ class JokeMapper extends EntityMapper<Joke, DTJoke> {

@override
DTJoke mapToData(Joke model) {
return DTJoke(model.id, model.joke);
return DTJoke(model.id, model.value);
}

@override
Joke mapToDomain(DTJoke entity) {
return Joke(entity.id, entity.joke);
return Joke(entity.id, entity.value);
}
}
18 changes: 9 additions & 9 deletions praxis_data/lib/models/jokes/dt_joke.dart
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
const String jokesTable = "jokesTable";

class JokeFields {
static const String id = "_id";
static const String joke = "joke";
static const String id = "id";
static const String value = "value";
}

class DTJoke {
final int id;
final String joke;
final String id;
final String value;

DTJoke(this.id, this.joke);
DTJoke(this.id, this.value);

DTJoke.fromJson(Map<String, dynamic> map)
: id = map['id'],
joke = map['joke'];
value = map['value'];

Map<String, Object?> toJson() => {JokeFields.id: id, JokeFields.joke: joke};
Map<String, Object?> toJson() => {JokeFields.id: id, JokeFields.value: value};

static DTJoke dtJokeFromJson(Map<String, Object?> json) =>
DTJoke(json[JokeFields.id] as int? ?? 0, json[JokeFields.joke] as String);
DTJoke(json[JokeFields.id] as String, json[JokeFields.value] as String);

@override
String toString() {
return '$id, $joke';
return '$id, $value';
}
}
9 changes: 4 additions & 5 deletions praxis_data/lib/models/jokes/dt_joke_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@ import 'package:praxis_data/mapper/entity_mapper.dart';
import 'package:praxis_data/models/jokes/dt_joke.dart';

class DTJokeList {
final String type;
final List<DTJoke> jokeList;

DTJokeList(this.type, this.jokeList);
DTJokeList(this.jokeList);

DTJokeList.fromJson(Map<String, dynamic> map)
: type = map['type'],
jokeList = List<DTJoke>.from((map['value'].cast<Map<String, dynamic>>())
:
jokeList = List<DTJoke>.from((map['result'].cast<Map<String, dynamic>>())
.toList()
.map((map) => DTJoke.fromJson(map)));

@override
String toString() {
return '$type, $jokeList';
return '$jokeList';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class DataJokesRepository implements JokesRepository {

@override
Future<ApiResponse<JokesListWithType>> getFiveRandomJokes() async {
String? type;
// Checking platform since sqflite doesn't support WEB
if (isMobile()) {
try {
Expand All @@ -32,7 +31,6 @@ class DataJokesRepository implements JokesRepository {
await _praxisDatabase.deleteAllJokes();
final networkJokes = (networkResponse as Success).data as JokesListWithType;
final jokes = mapper.mapToData(networkJokes);
type = jokes.type;
jokes.jokeList.forEach((joke) {
_praxisDatabase.insertJoke(joke);
});
Expand All @@ -43,7 +41,7 @@ class DataJokesRepository implements JokesRepository {
final dbJokes = await _praxisDatabase.getAllJokes();
final domainJokes =
dbJokes.map((dbJoke) => _jokeMapper.mapToDomain(dbJoke)).toList();
return Success(data: JokesListWithType(type ?? "", domainJokes));
return Success(data: JokesListWithType( domainJokes));
} else {
return _jokesApi.getFiveRandomJokes();
}
Expand Down
2 changes: 1 addition & 1 deletion praxis_data/lib/sources/local/praxis_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class PraxisDatabase {
await db.execute("""
CREATE TABLE $jokesTable (
${JokeFields.id} $idType,
${JokeFields.joke} $jokeType
${JokeFields.value} $jokeType
)
""");
}
Expand Down
3 changes: 1 addition & 2 deletions praxis_data/lib/sources/network/jokes_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ class JokesApi {

Future<ApiResponse<JokesListWithType>> getFiveRandomJokes() async {
try {
final networkResponse = await dio
.get(Uri.https(URL.baseUrl, URL.fiveRandomJokesPath).toString());
final networkResponse = await dio.get(URL.fiveRandomJokesUrl);
if (networkResponse.data != null) {
final parsedDataResponse = DTJokeList.fromJson(networkResponse.data);
final parsedDomainResponse = _mapper.mapToDomain(parsedDataResponse);
Expand Down
5 changes: 2 additions & 3 deletions praxis_data/lib/sources/network/url.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class URL {
static const String baseUrl = 'api.icndb.com';
static const String fiveRandomJokesUrl = '$baseUrl/jokes/random/5';
static const String fiveRandomJokesPath = '/jokes/random/5';
static const String baseUrl = 'https://api.chucknorris.io';
static const String fiveRandomJokesUrl = '$baseUrl/jokes/search?query=animal';
}
6 changes: 3 additions & 3 deletions praxis_flutter_domain/lib/entities/jokes/dm_joke.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Joke{
final int id;
final String joke;
final String id;
final String value;

Joke(this.id, this.joke);
Joke(this.id, this.value);
}
3 changes: 1 addition & 2 deletions praxis_flutter_domain/lib/entities/jokes/dm_joke_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import 'package:praxis_flutter_domain/entities/jokes/dm_joke.dart';
import 'package:praxis_flutter_domain/mapper/ui_model_mapper.dart';

class JokesListWithType {
final String type;
final List<Joke> jokeList;

JokesListWithType(this.type, this.jokeList);
JokesListWithType(this.jokeList);
}
2 changes: 1 addition & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1331,4 +1331,4 @@ packages:
version: "3.1.0"
sdks:
dart: ">=2.18.0 <3.0.0"
flutter: ">=3.3.0"
flutter: ">=3.3.0"

0 comments on commit a3d458c

Please sign in to comment.