More redux work. User creation/retrieve
This commit is contained in:
parent
2c67b68512
commit
2dfa745c6a
16 changed files with 212 additions and 110 deletions
|
|
@ -1,9 +1,9 @@
|
|||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
import 'package:comunes_flutter/comunes_flutter.dart';
|
||||
import 'fireMapState.dart';
|
||||
import 'yourLocation.dart';
|
||||
|
||||
import 'user.dart';
|
||||
part 'appState.g.dart';
|
||||
|
||||
@immutable
|
||||
|
|
@ -15,8 +15,14 @@ class AppState extends Object with _$AppStateSerializerMixin {
|
|||
final bool isLoaded;
|
||||
@JsonKey(ignore: true)
|
||||
final String error;
|
||||
final String userId;
|
||||
final String token;
|
||||
@JsonKey(ignore: true)
|
||||
final User user;
|
||||
@JsonKey(ignore: true)
|
||||
final String gmapKey;
|
||||
@JsonKey(ignore: true)
|
||||
final String firesApiKey;
|
||||
@JsonKey(ignore: true)
|
||||
final String firesApiUrl;
|
||||
final List<YourLocation> yourLocations;
|
||||
@JsonKey(ignore: true)
|
||||
final FireMapState fireMapState;
|
||||
|
|
@ -26,34 +32,40 @@ class AppState extends Object with _$AppStateSerializerMixin {
|
|||
_$AppStateFromJson(json);
|
||||
|
||||
AppState(
|
||||
{this.yourLocations = const [],
|
||||
this.userId,
|
||||
this.token,
|
||||
{this.yourLocations : const <YourLocation>[],
|
||||
this.user: const User.initial(),
|
||||
this.isLoading: false,
|
||||
this.isLoaded: false,
|
||||
this.error: null,
|
||||
this.gmapKey,
|
||||
this.firesApiKey,
|
||||
this.firesApiUrl,
|
||||
this.fireMapState: const FireMapState.initial()});
|
||||
|
||||
AppState copyWith(
|
||||
{bool isLoading,
|
||||
bool isLoaded,
|
||||
String userId,
|
||||
String token,
|
||||
String user,
|
||||
String error,
|
||||
String gmapKey,
|
||||
String firesApiKey,
|
||||
String firesApiUrl,
|
||||
List<YourLocation> yourLocations,
|
||||
FireMapState fireMapState}) {
|
||||
return new AppState(
|
||||
isLoading: isLoading ?? this.isLoading,
|
||||
isLoaded: isLoaded ?? this.isLoaded,
|
||||
userId: userId ?? this.userId,
|
||||
token: token ?? this.token,
|
||||
user: user ?? this.user,
|
||||
error: error ?? this.error,
|
||||
gmapKey: gmapKey ?? this.gmapKey,
|
||||
firesApiKey: firesApiKey ?? this.firesApiKey,
|
||||
firesApiUrl: firesApiUrl ?? this.firesApiUrl,
|
||||
yourLocations: yourLocations ?? this.yourLocations,
|
||||
fireMapState: fireMapState ?? this.fireMapState);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'AppState{\nuserId: $userId\ntoken: $token\nisLoading: $isLoading\nisLoaded: $isLoaded\nYourLocations: $yourLocations}';
|
||||
return 'AppState{\nuser: ${user}\nisLoading: $isLoading\nisLoaded: $isLoaded\napiKey: ${ellipse(firesApiKey, 8)}\napiUrl: ${ellipse(firesApiUrl, 8)}';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,13 +11,9 @@ part of 'appState.dart';
|
|||
AppState _$AppStateFromJson(Map<String, dynamic> json) => new AppState(
|
||||
yourLocations: (json['yourLocations'] as List)
|
||||
.map((e) => new YourLocation.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
userId: json['userId'] as String,
|
||||
token: json['token'] as String);
|
||||
.toList());
|
||||
|
||||
abstract class _$AppStateSerializerMixin {
|
||||
String get userId;
|
||||
String get token;
|
||||
List<YourLocation> get yourLocations;
|
||||
Map<String, dynamic> toJson() => new _$AppStateJsonMapWrapper(this);
|
||||
}
|
||||
|
|
@ -27,16 +23,12 @@ class _$AppStateJsonMapWrapper extends $JsonMapWrapper {
|
|||
_$AppStateJsonMapWrapper(this._v);
|
||||
|
||||
@override
|
||||
Iterable<String> get keys => const ['userId', 'token', 'yourLocations'];
|
||||
Iterable<String> get keys => const ['yourLocations'];
|
||||
|
||||
@override
|
||||
dynamic operator [](Object key) {
|
||||
if (key is String) {
|
||||
switch (key) {
|
||||
case 'userId':
|
||||
return _v.userId;
|
||||
case 'token':
|
||||
return _v.token;
|
||||
case 'yourLocations':
|
||||
return _v.yourLocations;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,39 @@
|
|||
import 'yourLocation.dart';
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:http/http.dart' as ht;
|
||||
import 'package:jaguar_resty/jaguar_resty.dart' as resty;
|
||||
|
||||
import 'appState.dart';
|
||||
import 'yourLocation.dart';
|
||||
|
||||
class FiresApi {
|
||||
|
||||
Future<String> createUser(String token) async {
|
||||
|
||||
FiresApi() {
|
||||
resty.globalClient = new ht.IOClient();
|
||||
}
|
||||
|
||||
Future<List<YourLocation>> fetchYourLocations() async {
|
||||
Future<String> createUser(AppState state, String token, String lang) async {
|
||||
assert(state.firesApiUrl != null);
|
||||
assert(state.firesApiKey != null);
|
||||
assert(token != null);
|
||||
assert(lang != null);
|
||||
|
||||
final params = {
|
||||
"token": state.firesApiKey,
|
||||
"mobileToken": token,
|
||||
"lang": lang
|
||||
};
|
||||
final url = '${state.firesApiUrl}mobile/users';
|
||||
/* print(url);
|
||||
print(params); */
|
||||
String resp = await resty.post(url).json(params).go().then((response) {
|
||||
if (response.statusCode == 200) {
|
||||
// print(response.body);
|
||||
return json.decode(response.body)['data']['userId'];
|
||||
}
|
||||
});
|
||||
return resp;
|
||||
}
|
||||
|
||||
Future<List<YourLocation>> fetchYourLocations() async {}
|
||||
}
|
||||
|
|
|
|||
29
lib/models/user.dart
Normal file
29
lib/models/user.dart
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import 'package:meta/meta.dart';
|
||||
import 'package:comunes_flutter/comunes_flutter.dart';
|
||||
|
||||
@immutable
|
||||
class User {
|
||||
final String userId;
|
||||
final String lang;
|
||||
final String token;
|
||||
|
||||
const User.initial()
|
||||
: this.userId = null,
|
||||
lang = null,
|
||||
token = null;
|
||||
|
||||
User({this.userId, this.lang, this.token});
|
||||
|
||||
User copyWith({String userId, String lang, String token}) {
|
||||
return new User(
|
||||
userId: userId ?? this.userId,
|
||||
token: token ?? this.token,
|
||||
lang: lang ?? this.lang);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'User {userId: $userId, lang: $lang, token: ${ellipse(token)}';
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue