-
Notifications
You must be signed in to change notification settings - Fork 3
Base arch structure #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5a37c04
Add base Flutter dependencies
abelfodil 65cf38d
Bump minimal android sdk version
abelfodil 0c53add
Increment and decrement with counter cubit & create main/app/locator …
8697b35
create and implement domain layer
15e4ab8
Create Flutter code structure example based on this [arch](https://gi…
ff2854f
Merge branch 'master' of https://github.com/PolyCortex/polydodo into …
428d554
Remove widget test specific to counter app
118ed85
Create an empty test for pipeline to perform build
baebeab
Create an empty test in order for build pipeline to pass
0c23975
fix mistake: move test/ under mobile/
0e6d790
Merge branch 'master' of https://github.com/PolyCortex/polydodo into …
9bbde0a
add venv to gitignoe && remove useless print in wallets_route
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
| .venv/ |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
| .buildlog/ | ||
| .history | ||
| .svn/ | ||
| .vscode/ | ||
|
|
||
| # IntelliJ related | ||
| *.iml | ||
|
|
||
This file contains hidden or 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,117 +1,7 @@ | ||
| import 'package:flutter/material.dart'; | ||
|
|
||
| void main() { | ||
| runApp(MyApp()); | ||
| } | ||
|
|
||
| class MyApp extends StatelessWidget { | ||
| // This widget is the root of your application. | ||
| @override | ||
| Widget build(BuildContext context) { | ||
| return MaterialApp( | ||
| title: 'Flutter Demo', | ||
| theme: ThemeData( | ||
| // This is the theme of your application. | ||
| // | ||
| // Try running your application with "flutter run". You'll see the | ||
| // application has a blue toolbar. Then, without quitting the app, try | ||
| // changing the primarySwatch below to Colors.green and then invoke | ||
| // "hot reload" (press "r" in the console where you ran "flutter run", | ||
| // or simply save your changes to "hot reload" in a Flutter IDE). | ||
| // Notice that the counter didn't reset back to zero; the application | ||
| // is not restarted. | ||
| primarySwatch: Colors.blue, | ||
| // This makes the visual density adapt to the platform that you run | ||
| // the app on. For desktop platforms, the controls will be smaller and | ||
| // closer together (more dense) than on mobile platforms. | ||
| visualDensity: VisualDensity.adaptivePlatformDensity, | ||
| ), | ||
| home: MyHomePage(title: 'Flutter Demo Home Page'), | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| class MyHomePage extends StatefulWidget { | ||
| MyHomePage({Key key, this.title}) : super(key: key); | ||
|
|
||
| // This widget is the home page of your application. It is stateful, meaning | ||
| // that it has a State object (defined below) that contains fields that affect | ||
| // how it looks. | ||
|
|
||
| // This class is the configuration for the state. It holds the values (in this | ||
| // case the title) provided by the parent (in this case the App widget) and | ||
| // used by the build method of the State. Fields in a Widget subclass are | ||
| // always marked "final". | ||
| import 'src/app.dart'; | ||
|
|
||
| final String title; | ||
|
|
||
| @override | ||
| _MyHomePageState createState() => _MyHomePageState(); | ||
| } | ||
|
|
||
| class _MyHomePageState extends State<MyHomePage> { | ||
| int _counter = 0; | ||
|
|
||
| void _incrementCounter() { | ||
| setState(() { | ||
| // This call to setState tells the Flutter framework that something has | ||
| // changed in this State, which causes it to rerun the build method below | ||
| // so that the display can reflect the updated values. If we changed | ||
| // _counter without calling setState(), then the build method would not be | ||
| // called again, and so nothing would appear to happen. | ||
| _counter++; | ||
| }); | ||
| } | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| // This method is rerun every time setState is called, for instance as done | ||
| // by the _incrementCounter method above. | ||
| // | ||
| // The Flutter framework has been optimized to make rerunning build methods | ||
| // fast, so that you can just rebuild anything that needs updating rather | ||
| // than having to individually change instances of widgets. | ||
| return Scaffold( | ||
| appBar: AppBar( | ||
| // Here we take the value from the MyHomePage object that was created by | ||
| // the App.build method, and use it to set our appbar title. | ||
| title: Text(widget.title), | ||
| ), | ||
| body: Center( | ||
| // Center is a layout widget. It takes a single child and positions it | ||
| // in the middle of the parent. | ||
| child: Column( | ||
| // Column is also a layout widget. It takes a list of children and | ||
| // arranges them vertically. By default, it sizes itself to fit its | ||
| // children horizontally, and tries to be as tall as its parent. | ||
| // | ||
| // Invoke "debug painting" (press "p" in the console, choose the | ||
| // "Toggle Debug Paint" action from the Flutter Inspector in Android | ||
| // Studio, or the "Toggle Debug Paint" command in Visual Studio Code) | ||
| // to see the wireframe for each widget. | ||
| // | ||
| // Column has various properties to control how it sizes itself and | ||
| // how it positions its children. Here we use mainAxisAlignment to | ||
| // center the children vertically; the main axis here is the vertical | ||
| // axis because Columns are vertical (the cross axis would be | ||
| // horizontal). | ||
| mainAxisAlignment: MainAxisAlignment.center, | ||
| children: <Widget>[ | ||
| Text( | ||
| 'You have pushed the button this many times:', | ||
| ), | ||
| Text( | ||
| '$_counter', | ||
| style: Theme.of(context).textTheme.headline4, | ||
| ), | ||
| ], | ||
| ), | ||
| ), | ||
| floatingActionButton: FloatingActionButton( | ||
| onPressed: _incrementCounter, | ||
| tooltip: 'Increment', | ||
| child: Icon(Icons.add), | ||
| ), // This trailing comma makes auto-formatting nicer for build methods. | ||
| ); | ||
| } | ||
| void main() { | ||
| runApp(App()); | ||
| } |
This file contains hidden or 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:flutter/material.dart'; | ||
| import 'package:flutter_bloc/flutter_bloc.dart'; | ||
|
|
||
| import 'presentation/wallets/wallets_route.dart'; | ||
| import 'locator.dart'; | ||
| import 'theme.dart'; | ||
|
|
||
| class App extends StatelessWidget { | ||
| App() { | ||
| registerServices(); | ||
| } | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| /// Cubits are provided globally down all of the context tree | ||
| return MultiBlocProvider( | ||
| providers: createBlocProviders(), | ||
| child: MaterialApp( | ||
| title: 'PolyDodo', | ||
| theme: theme, | ||
| home: WalletsRoute(), | ||
| initialRoute: WalletsRoute.name, | ||
| routes: { | ||
| WalletsRoute.name: (context) => WalletsRoute(), | ||
| }, | ||
| ), | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or 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,63 @@ | ||
| import 'dart:math'; | ||
|
|
||
| import 'package:bloc/bloc.dart'; | ||
|
|
||
| import 'package:polydodo/src/application/wallets/wallets_state.dart'; | ||
| import 'package:polydodo/src/domain/unique_id.dart'; | ||
| import 'package:polydodo/src/domain/wallet/i_wallet_repository.dart'; | ||
| import 'package:polydodo/src/domain/wallet/money.dart'; | ||
| import 'package:polydodo/src/domain/wallet/owner.dart'; | ||
| import 'package:polydodo/src/domain/wallet/wallet.dart'; | ||
|
|
||
| class WalletsCubit extends Cubit<WalletsState> { | ||
| final IWalletRepository _walletRepository; | ||
|
|
||
| WalletsCubit(this._walletRepository) : super(WalletsInitial()) { | ||
| createNewWallets(); | ||
| emit(WalletsLoadInProgress()); | ||
| _walletRepository | ||
| .watch() | ||
| .listen((wallets) => emit(WalletsLoadSuccess(wallets))) | ||
| .onError((e) => emit(WalletsLoadFailure(e))); | ||
| } | ||
|
|
||
| // Does not yield another state | ||
| void transfer(Wallet sender, Wallet receiver, Money amount) async { | ||
| try { | ||
| sender.transfer(amount, receiver); | ||
| } catch (e) { | ||
| emit(WalletsTransferFailure(e)); | ||
| } | ||
| await Future.wait([ | ||
| _walletRepository.store(sender), | ||
| _walletRepository.store(receiver), | ||
| ]).catchError((e) => emit(WalletsTransferFailure(e))); | ||
| } | ||
|
|
||
| Future<List<void>> createNewWallets() => Future.wait([ | ||
| _walletRepository.store( | ||
| Wallet( | ||
| UniqueId(), | ||
| Owner( | ||
| id: UniqueId.from('1'), | ||
| firstName: 'Bob', | ||
| lastName: 'Skiridovsky', | ||
| age: 25, | ||
| ), | ||
| Money(Random().nextDouble() * 10, Currency.cad), | ||
| ), | ||
| ), | ||
| _walletRepository.store( | ||
| Wallet( | ||
| UniqueId(), | ||
| Owner( | ||
| id: UniqueId.from('2'), | ||
| firstName: 'Alice', | ||
| lastName: 'Pogo', | ||
| age: 35, | ||
| ), | ||
| Money(Random().nextDouble() * 1000, Currency.cad), | ||
| ), | ||
| ) | ||
| ]); | ||
| } |
This file contains hidden or 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:polydodo/src/domain/wallet/wallet.dart'; | ||
|
|
||
| abstract class WalletsState {} | ||
|
|
||
| class WalletsInitial extends WalletsState {} | ||
|
|
||
| class WalletsLoadInProgress extends WalletsState {} | ||
|
|
||
| class WalletsLoadSuccess extends WalletsState { | ||
| final List<Wallet> wallets; | ||
|
|
||
| WalletsLoadSuccess(this.wallets); | ||
| } | ||
|
|
||
| class WalletsLoadFailure extends WalletsState { | ||
| final Exception cause; | ||
|
|
||
| WalletsLoadFailure(this.cause); | ||
| } | ||
|
|
||
| class WalletsTransferFailure extends WalletsState { | ||
| final Exception cause; | ||
|
|
||
| WalletsTransferFailure(this.cause); | ||
| } |
This file contains hidden or 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,20 @@ | ||
| import 'package:equatable/equatable.dart'; | ||
| import 'package:uuid/uuid.dart'; | ||
|
|
||
| class UniqueId extends Equatable { | ||
| final String _id; | ||
|
|
||
| UniqueId() : _id = Uuid().v4(); | ||
|
|
||
| UniqueId.from(String unique) | ||
| : assert(unique != null), | ||
| _id = unique; | ||
|
|
||
| String get() => _id; | ||
|
|
||
| @override | ||
| List<Object> get props => [_id]; | ||
|
|
||
| @override | ||
| bool get stringify => true; | ||
| } |
This file contains hidden or 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 @@ | ||
| const cadToUsdRate = 1.32; |
This file contains hidden or 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,6 @@ | ||
| import 'wallet.dart'; | ||
|
|
||
| abstract class IWalletRepository { | ||
| Future<void> store(Wallet wallet); | ||
| Stream<List<Wallet>> watch(); | ||
| } |
This file contains hidden or 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,57 @@ | ||
| import 'package:equatable/equatable.dart'; | ||
|
|
||
| import 'constants.dart'; | ||
|
|
||
| enum Currency { usd, cad } | ||
|
|
||
| Map<Currency, String> currencyToString = { | ||
| Currency.usd: 'USD', | ||
| Currency.cad: 'CAD', | ||
| }; | ||
|
|
||
| // Value object usually extends equatable | ||
| class Money extends Equatable { | ||
| static const _min = 0; | ||
|
|
||
| final double value; | ||
| final Currency currency; | ||
|
|
||
| Money(this.value, this.currency) | ||
| : assert(value != null), | ||
| assert(currency != null) { | ||
| // Validation that money cannot be in an impossible state | ||
| if (value <= _min) { | ||
| Exception('Money amount cannot be inferior to $_min'); | ||
| } | ||
| } | ||
|
|
||
| double get usd { | ||
| if (currency == Currency.cad) { | ||
| return value / cadToUsdRate; | ||
| } | ||
| return value; | ||
| } | ||
|
|
||
| double get cad { | ||
| if (currency == Currency.usd) { | ||
| return value * cadToUsdRate; | ||
| } | ||
| return value; | ||
| } | ||
|
|
||
| Money convertTo(Currency currency) { | ||
| if (currency == Currency.usd) { | ||
| return Money(usd, currency); | ||
| } | ||
| return Money(cad, currency); | ||
| } | ||
|
|
||
| /// Gives back result into left operand's currency | ||
| Money operator +(Money other) => | ||
| Money(this.usd + other.usd, Currency.usd).convertTo(this.currency); | ||
| Money operator -(Money other) => | ||
| Money(this.usd - other.usd, Currency.usd).convertTo(this.currency); | ||
|
|
||
| @override | ||
| List<Object> get props => [usd]; | ||
| } |
This file contains hidden or 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,32 @@ | ||
| import 'package:meta/meta.dart'; | ||
|
|
||
| import 'package:polydodo/src/domain/unique_id.dart'; | ||
|
|
||
| class Owner { | ||
| static const _legalAge = 16; | ||
|
|
||
| final UniqueId id; | ||
| final String firstName; | ||
| final String lastName; | ||
| final int age; | ||
|
|
||
| Owner({ | ||
| @required this.id, | ||
| @required this.firstName, | ||
| @required this.lastName, | ||
| @required this.age, | ||
| }) : assert(id != null), | ||
| assert(firstName != null), | ||
| assert(lastName != null) { | ||
| if (firstName.length <= 0 || lastName.length <= 0) { | ||
| throw Exception('First and last name cannot be empty'); | ||
| } | ||
| if (!_hasLegalAge()) { | ||
| throw Exception('This owner does not have the legal age'); | ||
| } | ||
| } | ||
|
|
||
| bool _hasLegalAge() => age >= _legalAge; | ||
|
|
||
| // In a good model entity, we should have behavorial method... | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.