Skip to content

Commit

Permalink
Improve api json validation with patterns and add piston model
Browse files Browse the repository at this point in the history
  • Loading branch information
dhzdhd committed Nov 12, 2023
1 parent 30ecb8e commit dbe422f
Show file tree
Hide file tree
Showing 20 changed files with 494 additions and 243 deletions.
6 changes: 3 additions & 3 deletions lib/src/cloud/models/auth_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:supabase_flutter/supabase_flutter.dart';

part 'auth_model.freezed.dart';
part 'auth_model.g.dart';
// part 'auth_model.g.dart';

@freezed
class AuthModel with _$AuthModel {
const factory AuthModel({
required User? user,
}) = _AuthModel;

factory AuthModel.fromJson(Map<String, dynamic> json) =>
_$AuthModelFromJson(json);
// factory AuthModel.fromJson(Map<String, dynamic> json) =>
// _$AuthModelFromJson(json);
}
56 changes: 19 additions & 37 deletions lib/src/cloud/models/auth_model.freezed.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark

part of 'auth_model.dart';

Expand All @@ -14,15 +14,10 @@ T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods');

AuthModel _$AuthModelFromJson(Map<String, dynamic> json) {
return _AuthModel.fromJson(json);
}

/// @nodoc
mixin _$AuthModel {
User? get user => throw _privateConstructorUsedError;

Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$AuthModelCopyWith<AuthModel> get copyWith =>
throw _privateConstructorUsedError;
Expand Down Expand Up @@ -61,29 +56,30 @@ class _$AuthModelCopyWithImpl<$Res, $Val extends AuthModel>
}

/// @nodoc
abstract class _$$_AuthModelCopyWith<$Res> implements $AuthModelCopyWith<$Res> {
factory _$$_AuthModelCopyWith(
_$_AuthModel value, $Res Function(_$_AuthModel) then) =
__$$_AuthModelCopyWithImpl<$Res>;
abstract class _$$AuthModelImplCopyWith<$Res>
implements $AuthModelCopyWith<$Res> {
factory _$$AuthModelImplCopyWith(
_$AuthModelImpl value, $Res Function(_$AuthModelImpl) then) =
__$$AuthModelImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({User? user});
}

/// @nodoc
class __$$_AuthModelCopyWithImpl<$Res>
extends _$AuthModelCopyWithImpl<$Res, _$_AuthModel>
implements _$$_AuthModelCopyWith<$Res> {
__$$_AuthModelCopyWithImpl(
_$_AuthModel _value, $Res Function(_$_AuthModel) _then)
class __$$AuthModelImplCopyWithImpl<$Res>
extends _$AuthModelCopyWithImpl<$Res, _$AuthModelImpl>
implements _$$AuthModelImplCopyWith<$Res> {
__$$AuthModelImplCopyWithImpl(
_$AuthModelImpl _value, $Res Function(_$AuthModelImpl) _then)
: super(_value, _then);

@pragma('vm:prefer-inline')
@override
$Res call({
Object? user = freezed,
}) {
return _then(_$_AuthModel(
return _then(_$AuthModelImpl(
user: freezed == user
? _value.user
: user // ignore: cast_nullable_to_non_nullable
Expand All @@ -93,12 +89,9 @@ class __$$_AuthModelCopyWithImpl<$Res>
}

/// @nodoc
@JsonSerializable()
class _$_AuthModel implements _AuthModel {
const _$_AuthModel({required this.user});
factory _$_AuthModel.fromJson(Map<String, dynamic> json) =>
_$$_AuthModelFromJson(json);
class _$AuthModelImpl implements _AuthModel {
const _$AuthModelImpl({required this.user});

@override
final User? user;
Expand All @@ -112,38 +105,27 @@ class _$_AuthModel implements _AuthModel {
bool operator ==(dynamic other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$_AuthModel &&
other is _$AuthModelImpl &&
(identical(other.user, user) || other.user == user));
}

@JsonKey(ignore: true)
@override
int get hashCode => Object.hash(runtimeType, user);

@JsonKey(ignore: true)
@override
@pragma('vm:prefer-inline')
_$$_AuthModelCopyWith<_$_AuthModel> get copyWith =>
__$$_AuthModelCopyWithImpl<_$_AuthModel>(this, _$identity);

@override
Map<String, dynamic> toJson() {
return _$$_AuthModelToJson(
this,
);
}
_$$AuthModelImplCopyWith<_$AuthModelImpl> get copyWith =>
__$$AuthModelImplCopyWithImpl<_$AuthModelImpl>(this, _$identity);
}

abstract class _AuthModel implements AuthModel {
const factory _AuthModel({required final User? user}) = _$_AuthModel;

factory _AuthModel.fromJson(Map<String, dynamic> json) =
_$_AuthModel.fromJson;
const factory _AuthModel({required final User? user}) = _$AuthModelImpl;

@override
User? get user;
@override
@JsonKey(ignore: true)
_$$_AuthModelCopyWith<_$_AuthModel> get copyWith =>
_$$AuthModelImplCopyWith<_$AuthModelImpl> get copyWith =>
throw _privateConstructorUsedError;
}
18 changes: 0 additions & 18 deletions lib/src/cloud/models/auth_model.g.dart

This file was deleted.

42 changes: 21 additions & 21 deletions lib/src/cloud/models/cloud_model.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ class _$CloudModelCopyWithImpl<$Res, $Val extends CloudModel>
}

/// @nodoc
abstract class _$$_CloudModelCopyWith<$Res>
abstract class _$$CloudModelImplCopyWith<$Res>
implements $CloudModelCopyWith<$Res> {
factory _$$_CloudModelCopyWith(
_$_CloudModel value, $Res Function(_$_CloudModel) then) =
__$$_CloudModelCopyWithImpl<$Res>;
factory _$$CloudModelImplCopyWith(
_$CloudModelImpl value, $Res Function(_$CloudModelImpl) then) =
__$$CloudModelImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({SettingsModel settings, List<SnippetModel> snippets});
Expand All @@ -92,11 +92,11 @@ abstract class _$$_CloudModelCopyWith<$Res>
}

/// @nodoc
class __$$_CloudModelCopyWithImpl<$Res>
extends _$CloudModelCopyWithImpl<$Res, _$_CloudModel>
implements _$$_CloudModelCopyWith<$Res> {
__$$_CloudModelCopyWithImpl(
_$_CloudModel _value, $Res Function(_$_CloudModel) _then)
class __$$CloudModelImplCopyWithImpl<$Res>
extends _$CloudModelCopyWithImpl<$Res, _$CloudModelImpl>
implements _$$CloudModelImplCopyWith<$Res> {
__$$CloudModelImplCopyWithImpl(
_$CloudModelImpl _value, $Res Function(_$CloudModelImpl) _then)
: super(_value, _then);

@pragma('vm:prefer-inline')
Expand All @@ -105,7 +105,7 @@ class __$$_CloudModelCopyWithImpl<$Res>
Object? settings = null,
Object? snippets = null,
}) {
return _then(_$_CloudModel(
return _then(_$CloudModelImpl(
settings: null == settings
? _value.settings
: settings // ignore: cast_nullable_to_non_nullable
Expand All @@ -120,13 +120,13 @@ class __$$_CloudModelCopyWithImpl<$Res>

/// @nodoc
@JsonSerializable()
class _$_CloudModel implements _CloudModel {
const _$_CloudModel(
class _$CloudModelImpl implements _CloudModel {
const _$CloudModelImpl(
{required this.settings, required final List<SnippetModel> snippets})
: _snippets = snippets;

factory _$_CloudModel.fromJson(Map<String, dynamic> json) =>
_$$_CloudModelFromJson(json);
factory _$CloudModelImpl.fromJson(Map<String, dynamic> json) =>
_$$CloudModelImplFromJson(json);

@override
final SettingsModel settings;
Expand All @@ -147,7 +147,7 @@ class _$_CloudModel implements _CloudModel {
bool operator ==(dynamic other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$_CloudModel &&
other is _$CloudModelImpl &&
(identical(other.settings, settings) ||
other.settings == settings) &&
const DeepCollectionEquality().equals(other._snippets, _snippets));
Expand All @@ -161,12 +161,12 @@ class _$_CloudModel implements _CloudModel {
@JsonKey(ignore: true)
@override
@pragma('vm:prefer-inline')
_$$_CloudModelCopyWith<_$_CloudModel> get copyWith =>
__$$_CloudModelCopyWithImpl<_$_CloudModel>(this, _$identity);
_$$CloudModelImplCopyWith<_$CloudModelImpl> get copyWith =>
__$$CloudModelImplCopyWithImpl<_$CloudModelImpl>(this, _$identity);

@override
Map<String, dynamic> toJson() {
return _$$_CloudModelToJson(
return _$$CloudModelImplToJson(
this,
);
}
Expand All @@ -175,17 +175,17 @@ class _$_CloudModel implements _CloudModel {
abstract class _CloudModel implements CloudModel {
const factory _CloudModel(
{required final SettingsModel settings,
required final List<SnippetModel> snippets}) = _$_CloudModel;
required final List<SnippetModel> snippets}) = _$CloudModelImpl;

factory _CloudModel.fromJson(Map<String, dynamic> json) =
_$_CloudModel.fromJson;
_$CloudModelImpl.fromJson;

@override
SettingsModel get settings;
@override
List<SnippetModel> get snippets;
@override
@JsonKey(ignore: true)
_$$_CloudModelCopyWith<_$_CloudModel> get copyWith =>
_$$CloudModelImplCopyWith<_$CloudModelImpl> get copyWith =>
throw _privateConstructorUsedError;
}
6 changes: 3 additions & 3 deletions lib/src/cloud/models/cloud_model.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions lib/src/cloud/views/auth_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ class _AuthViewState extends ConsumerState<AuthView> {
response.match(
(l) => context.showErrorSnackBar(l),
(r) {
ref.read(authStateProvider.notifier).setUser(r);
// TODO: Fix auth model
// ref.read(authStateProvider.notifier).setUser(r);
Navigator.pop(context);
context.showSuccessSnackBar(
content:
Expand All @@ -179,7 +180,7 @@ class _AuthViewState extends ConsumerState<AuthView> {
response.match(
(l) => context.showErrorSnackBar(l),
(r) {
ref.read(authStateProvider.notifier).setUser(r);
// ref.read(authStateProvider.notifier).setUser(r);
Navigator.pop(context);
context.showSuccessSnackBar(
content: 'Successfully logged in!',
Expand Down
Loading

0 comments on commit dbe422f

Please sign in to comment.