Skip to content

Commit

Permalink
Removed name field from FDC (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
maneesht authored Dec 12, 2024
1 parent 4a9d883 commit bd35f61
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 30 deletions.
3 changes: 1 addition & 2 deletions data_connect/dataconnect/connector/mutations.gql
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
mutation UpsertUser($username: String!, $name: String!) @auth(level: USER) {
mutation UpsertUser($username: String!) @auth(level: USER) {
user_upsert(
data: {
id_expr: "auth.uid"
username: $username
name: $name
}
)
}
Expand Down
1 change: 0 additions & 1 deletion data_connect/dataconnect/connector/queries.gql
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ query GetCurrentUser @auth(level: USER) {
user(key: { id_expr: "auth.uid" }) {
id
username
name
reviews: reviews_on_user {
id
rating
Expand Down
1 change: 0 additions & 1 deletion data_connect/dataconnect/schema/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ type User
@table {
id: String! @col(name: "user_auth")
username: String! @col(name: "username", dataType: "varchar(50)")
name: String!
# The following are generated from the @ref in the Review table
# reviews_on_user
# movies_via_Review
Expand Down
2 changes: 1 addition & 1 deletion data_connect/lib/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class _LoginState extends State<Login> {
await MoviesConnector.instance.getCurrentUser().execute();
if (isLoggedIn.data.user == null) {
await MoviesConnector.instance
.upsertUser(username: _username.text, name: _username.text)
.upsertUser(username: _username.text)
.execute();
}
if (mounted) {
Expand Down
6 changes: 0 additions & 6 deletions data_connect/lib/movies_connector/get_current_user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,13 @@ class GetCurrentUserUser {

String username;

String name;

List<GetCurrentUserUserReviews> reviews;

List<GetCurrentUserUserFavoriteMovies> favoriteMovies;

GetCurrentUserUser.fromJson(dynamic json)
: id = nativeFromJson<String>(json['id']),
username = nativeFromJson<String>(json['username']),
name = nativeFromJson<String>(json['name']),
reviews = (json['reviews'] as List<dynamic>)
.map((e) => GetCurrentUserUserReviews.fromJson(e))
.toList(),
Expand All @@ -48,8 +45,6 @@ class GetCurrentUserUser {

json['username'] = nativeToJson<String>(username);

json['name'] = nativeToJson<String>(name);

json['reviews'] = reviews.map((e) => e.toJson()).toList();

json['favoriteMovies'] = favoriteMovies.map((e) => e.toJson()).toList();
Expand All @@ -60,7 +55,6 @@ class GetCurrentUserUser {
GetCurrentUserUser({
required this.id,
required this.username,
required this.name,
required this.reviews,
required this.favoriteMovies,
});
Expand Down
2 changes: 0 additions & 2 deletions data_connect/lib/movies_connector/movies.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,10 @@ String enumSerializer(Enum e) {
class MoviesConnector {
UpsertUserVariablesBuilder upsertUser({
required String username,
required String name,
}) {
return UpsertUserVariablesBuilder(
dataConnect,
username: username,
name: name,
);
}

Expand Down
11 changes: 1 addition & 10 deletions data_connect/lib/movies_connector/upsert_user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ part of movies_connector;

class UpsertUserVariablesBuilder {
String username;
String name;

FirebaseDataConnect _dataConnect;

UpsertUserVariablesBuilder(
this._dataConnect, {
required String this.username,
required String this.name,
});
Deserializer<UpsertUserData> dataDeserializer =
(dynamic json) => UpsertUserData.fromJson(jsonDecode(json));
Expand All @@ -22,7 +20,6 @@ class UpsertUserVariablesBuilder {
MutationRef<UpsertUserData, UpsertUserVariables> ref() {
UpsertUserVariables vars = UpsertUserVariables(
username: username,
name: name,
);

return _dataConnect.mutation(
Expand Down Expand Up @@ -71,26 +68,20 @@ class UpsertUserData {
class UpsertUserVariables {
String username;

String name;

@Deprecated(
'fromJson is deprecated for Variable classes as they are no longer required for deserialization.')
UpsertUserVariables.fromJson(Map<String, dynamic> json)
: username = nativeFromJson<String>(json['username']),
name = nativeFromJson<String>(json['name']) {}
: username = nativeFromJson<String>(json['username']) {}

Map<String, dynamic> toJson() {
Map<String, dynamic> json = {};

json['username'] = nativeToJson<String>(username);

json['name'] = nativeToJson<String>(name);

return json;
}

UpsertUserVariables({
required this.username,
required this.name,
});
}
9 changes: 5 additions & 4 deletions data_connect/lib/profile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@ class Profile extends StatelessWidget {
stream: MovieState.subscribeToCurrentUser(),
builder: (context, snapshot) {
final res = snapshot.data;
if (res == null) {
if (res == null || res.data.user == null) {
return const Center(
child: CircularProgressIndicator(),
);
}
final displayName = res.data.user!.name;
final displayName =
FirebaseAuth.instance.currentUser?.displayName ?? '';
final favoriteMovies =
res.data.user!.favoriteMovies.map((e) => e.movie).toList();
final reviews = res.data.user!.reviews;
final reviews = res.data.user == null ? [] : res.data.user!.reviews;
return RefreshIndicator(
child: SingleChildScrollView(
physics: const AlwaysScrollableScrollPhysics(),
Expand All @@ -40,7 +41,7 @@ class Profile extends StatelessWidget {
children: [
Column(
children: [
Text('Welcome back $displayName !'),
Text('Welcome back $displayName!'),
TextButton(
onPressed: () async {
FirebaseAuth.instance.signOut();
Expand Down
7 changes: 4 additions & 3 deletions data_connect/lib/sign_up.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:dataconnect/movie_state.dart';
import 'package:dataconnect/movies_connector/movies.dart';
import 'package:dataconnect/widgets/auth_dialog.dart';
import 'package:firebase_auth/firebase_auth.dart';
Expand All @@ -23,9 +24,9 @@ class _SignUpState extends State<SignUp> {
try {
await FirebaseAuth.instance.createUserWithEmailAndPassword(
email: _username, password: _password);
await MoviesConnector.instance
.upsertUser(username: _username, name: _name)
.execute();
await FirebaseAuth.instance.currentUser!.updateDisplayName(_name);
await MoviesConnector.instance.upsertUser(username: _username).execute();
MovieState.triggerUpdateFavorite();
if (mounted) {
context.go('/home');
}
Expand Down

0 comments on commit bd35f61

Please sign in to comment.