forked from luiscib3r/todo
-
Notifications
You must be signed in to change notification settings - Fork 5
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
Luis Ciber
committed
Sep 28, 2021
1 parent
8446be1
commit 27ed6ff
Showing
28 changed files
with
325 additions
and
46 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
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export 'nauta/nauta_account_datasource.dart'; | ||
export 'ussd/ussd.dart'; |
85 changes: 85 additions & 0 deletions
85
lib/app/data/datasources/nauta/nauta_account_datasource.dart
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,85 @@ | ||
import 'package:injectable/injectable.dart'; | ||
import 'package:sqflite/sqflite.dart'; | ||
import 'package:todo/app/app.dart'; | ||
|
||
abstract class NautaAccountDatasource { | ||
Future<int> save(NautaAccount account); | ||
Future<List<NautaAccount>> findAll(); | ||
Future<NautaAccount?> findById(int id); | ||
Future<NautaAccount?> findByUsername(String username); | ||
Future<int> update(int id, NautaAccount account); | ||
Future<int> delete(int id); | ||
} | ||
|
||
@Injectable(as: NautaAccountDatasource) | ||
class NautaAccountSqliteDatasource extends NautaAccountDatasource { | ||
NautaAccountSqliteDatasource(this._db); | ||
|
||
final Database _db; | ||
|
||
static const table = 'users'; | ||
|
||
@override | ||
Future<int> delete(int id) => _db.delete( | ||
table, | ||
where: 'id = ?', | ||
whereArgs: [id], | ||
); | ||
|
||
@override | ||
Future<List<NautaAccount>> findAll() async { | ||
final map = await _db.query(table); | ||
|
||
return List.generate( | ||
map.length, | ||
(index) => NautaAccount.fromJson(map[index]), | ||
); | ||
} | ||
|
||
@override | ||
Future<NautaAccount?> findById(int id) async { | ||
final map = await _db.query( | ||
table, | ||
where: 'id = ?', | ||
whereArgs: [id], | ||
); | ||
|
||
final result = List.generate( | ||
map.length, | ||
(index) => NautaAccount.fromJson(map[index]), | ||
); | ||
|
||
return result.isNotEmpty ? result.first : null; | ||
} | ||
|
||
@override | ||
Future<NautaAccount?> findByUsername(String username) async { | ||
final map = await _db.query( | ||
table, | ||
where: 'username = ?', | ||
whereArgs: [username], | ||
); | ||
|
||
final result = List.generate( | ||
map.length, | ||
(index) => NautaAccount.fromJson(map[index]), | ||
); | ||
|
||
return result.isNotEmpty ? result.first : null; | ||
} | ||
|
||
@override | ||
Future<int> save(NautaAccount account) => _db.insert( | ||
table, | ||
account.toJson(), | ||
conflictAlgorithm: ConflictAlgorithm.replace, | ||
); | ||
|
||
@override | ||
Future<int> update(int id, NautaAccount account) => _db.update( | ||
table, | ||
account.toJson(), | ||
where: 'id = ?', | ||
whereArgs: [id], | ||
); | ||
} |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export 'nauta/nauta_account.dart'; | ||
export 'ussd/ussd.dart'; |
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,29 @@ | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
part 'nauta_account.g.dart'; | ||
|
||
@JsonSerializable() | ||
class NautaAccount extends Equatable { | ||
const NautaAccount({ | ||
this.id = 0, | ||
required this.username, | ||
required this.password, | ||
}); | ||
|
||
factory NautaAccount.fromJson(Map<String, dynamic> json) => | ||
_$NautaAccountFromJson(json); | ||
|
||
Map<String, dynamic> toJson() => _$NautaAccountToJson(this); | ||
|
||
final int id; | ||
final String username; | ||
final String password; | ||
|
||
@override | ||
List<Object?> get props => [ | ||
id, | ||
username, | ||
password, | ||
]; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,25 @@ | ||
import 'package:injectable/injectable.dart'; | ||
import 'package:todo/app/app.dart'; | ||
|
||
@injectable | ||
class NautaRepository { | ||
NautaRepository(this._accountDatasource); | ||
|
||
final NautaAccountDatasource _accountDatasource; | ||
|
||
Future<int> saveAccount(NautaAccount account) => | ||
_accountDatasource.save(account); | ||
|
||
Future<List<NautaAccount>> findAllAccounts() => _accountDatasource.findAll(); | ||
|
||
Future<NautaAccount?> findByIdAccount(int id) => | ||
_accountDatasource.findById(id); | ||
|
||
Future<NautaAccount?> findByUsernameAccount(String username) => | ||
_accountDatasource.findByUsername(username); | ||
|
||
Future<int> updateAccount(int id, NautaAccount account) => | ||
_accountDatasource.update(id, account); | ||
|
||
Future<int> deleteAccount(int id) => _accountDatasource.delete(id); | ||
} |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export 'nauta_repository.dart'; | ||
export 'ussd_repository.dart'; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Empty file.
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,4 @@ | ||
export 'bloc/bloc.dart'; | ||
export 'router/router.dart'; | ||
export 'view/view.dart'; | ||
export 'widgets/widgets.dart'; |
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,21 @@ | ||
import 'package:beamer/beamer.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:todo/nauta/nauta.dart'; | ||
|
||
class AccountsPage extends BeamPage { | ||
AccountsPage() | ||
: super( | ||
title: 'Cuentas', | ||
type: BeamPageType.cupertino, | ||
child: const AccountsView(), | ||
); | ||
|
||
static String get pathBlueprint => '/nauta/accounts'; | ||
|
||
static String route() => '/nauta/accounts'; | ||
|
||
static void open(BuildContext context) => context.beamToNamed(route()); | ||
|
||
static bool checkBeamState(BeamState state) => | ||
state.pathBlueprintSegments.contains('accounts'); | ||
} |
Oops, something went wrong.