-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(auction): implement get all ongoing auctions flow (view/vm/service)
- Loading branch information
WarriorsSami
committed
Mar 22, 2024
1 parent
fc7746b
commit 04e2023
Showing
23 changed files
with
1,242 additions
and
131 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,18 @@ | ||
class Auction { | ||
late String id; | ||
late double startingPrice; | ||
late DateTime endDate; | ||
late String itemId; | ||
import 'package:freezed_annotation/freezed_annotation.dart'; | ||
import 'package:rainbowbid_frontend/models/core/timestamp_converter.dart'; | ||
|
||
Auction({ | ||
required this.id, | ||
required this.startingPrice, | ||
required this.endDate, | ||
required this.itemId, | ||
}); | ||
part 'auction.freezed.dart'; | ||
part 'auction.g.dart'; | ||
|
||
Map<String, dynamic> toJson() { | ||
return { | ||
'id': id, | ||
'starting_price': startingPrice, | ||
'end_date': endDate.toIso8601String(), | ||
'item_id': itemId, | ||
}; | ||
} | ||
@freezed | ||
class Auction with _$Auction { | ||
factory Auction({ | ||
required String id, | ||
@JsonKey(name: 'starting_price') required double startingPrice, | ||
@JsonKey(name: 'end_date') @TimestampConverter() required DateTime endDate, | ||
@JsonKey(name: 'item_id') required String itemId, | ||
}) = _Auction; | ||
|
||
factory Auction.fromJson(Map<String, dynamic> json) { | ||
return Auction( | ||
id: json['id'], | ||
startingPrice: double.parse(json['starting_price']), | ||
endDate: DateTime.fromMillisecondsSinceEpoch( | ||
json['end_date'] * 1000, | ||
isUtc: true, | ||
), | ||
itemId: json['item_id'], | ||
); | ||
} | ||
factory Auction.fromJson(Map<String, dynamic> json) => | ||
_$AuctionFromJson(json); | ||
} |
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,227 @@ | ||
// 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, unnecessary_question_mark | ||
|
||
part of 'auction.dart'; | ||
|
||
// ************************************************************************** | ||
// FreezedGenerator | ||
// ************************************************************************** | ||
|
||
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#adding-getters-and-methods-to-our-models'); | ||
|
||
Auction _$AuctionFromJson(Map<String, dynamic> json) { | ||
return _Auction.fromJson(json); | ||
} | ||
|
||
/// @nodoc | ||
mixin _$Auction { | ||
String get id => throw _privateConstructorUsedError; | ||
@JsonKey(name: 'starting_price') | ||
double get startingPrice => throw _privateConstructorUsedError; | ||
@JsonKey(name: 'end_date') | ||
@TimestampConverter() | ||
DateTime get endDate => throw _privateConstructorUsedError; | ||
@JsonKey(name: 'item_id') | ||
String get itemId => throw _privateConstructorUsedError; | ||
|
||
Map<String, dynamic> toJson() => throw _privateConstructorUsedError; | ||
@JsonKey(ignore: true) | ||
$AuctionCopyWith<Auction> get copyWith => throw _privateConstructorUsedError; | ||
} | ||
|
||
/// @nodoc | ||
abstract class $AuctionCopyWith<$Res> { | ||
factory $AuctionCopyWith(Auction value, $Res Function(Auction) then) = | ||
_$AuctionCopyWithImpl<$Res, Auction>; | ||
@useResult | ||
$Res call( | ||
{String id, | ||
@JsonKey(name: 'starting_price') double startingPrice, | ||
@JsonKey(name: 'end_date') @TimestampConverter() DateTime endDate, | ||
@JsonKey(name: 'item_id') String itemId}); | ||
} | ||
|
||
/// @nodoc | ||
class _$AuctionCopyWithImpl<$Res, $Val extends Auction> | ||
implements $AuctionCopyWith<$Res> { | ||
_$AuctionCopyWithImpl(this._value, this._then); | ||
|
||
// ignore: unused_field | ||
final $Val _value; | ||
// ignore: unused_field | ||
final $Res Function($Val) _then; | ||
|
||
@pragma('vm:prefer-inline') | ||
@override | ||
$Res call({ | ||
Object? id = null, | ||
Object? startingPrice = null, | ||
Object? endDate = null, | ||
Object? itemId = null, | ||
}) { | ||
return _then(_value.copyWith( | ||
id: null == id | ||
? _value.id | ||
: id // ignore: cast_nullable_to_non_nullable | ||
as String, | ||
startingPrice: null == startingPrice | ||
? _value.startingPrice | ||
: startingPrice // ignore: cast_nullable_to_non_nullable | ||
as double, | ||
endDate: null == endDate | ||
? _value.endDate | ||
: endDate // ignore: cast_nullable_to_non_nullable | ||
as DateTime, | ||
itemId: null == itemId | ||
? _value.itemId | ||
: itemId // ignore: cast_nullable_to_non_nullable | ||
as String, | ||
) as $Val); | ||
} | ||
} | ||
|
||
/// @nodoc | ||
abstract class _$$AuctionImplCopyWith<$Res> implements $AuctionCopyWith<$Res> { | ||
factory _$$AuctionImplCopyWith( | ||
_$AuctionImpl value, $Res Function(_$AuctionImpl) then) = | ||
__$$AuctionImplCopyWithImpl<$Res>; | ||
@override | ||
@useResult | ||
$Res call( | ||
{String id, | ||
@JsonKey(name: 'starting_price') double startingPrice, | ||
@JsonKey(name: 'end_date') @TimestampConverter() DateTime endDate, | ||
@JsonKey(name: 'item_id') String itemId}); | ||
} | ||
|
||
/// @nodoc | ||
class __$$AuctionImplCopyWithImpl<$Res> | ||
extends _$AuctionCopyWithImpl<$Res, _$AuctionImpl> | ||
implements _$$AuctionImplCopyWith<$Res> { | ||
__$$AuctionImplCopyWithImpl( | ||
_$AuctionImpl _value, $Res Function(_$AuctionImpl) _then) | ||
: super(_value, _then); | ||
|
||
@pragma('vm:prefer-inline') | ||
@override | ||
$Res call({ | ||
Object? id = null, | ||
Object? startingPrice = null, | ||
Object? endDate = null, | ||
Object? itemId = null, | ||
}) { | ||
return _then(_$AuctionImpl( | ||
id: null == id | ||
? _value.id | ||
: id // ignore: cast_nullable_to_non_nullable | ||
as String, | ||
startingPrice: null == startingPrice | ||
? _value.startingPrice | ||
: startingPrice // ignore: cast_nullable_to_non_nullable | ||
as double, | ||
endDate: null == endDate | ||
? _value.endDate | ||
: endDate // ignore: cast_nullable_to_non_nullable | ||
as DateTime, | ||
itemId: null == itemId | ||
? _value.itemId | ||
: itemId // ignore: cast_nullable_to_non_nullable | ||
as String, | ||
)); | ||
} | ||
} | ||
|
||
/// @nodoc | ||
@JsonSerializable() | ||
class _$AuctionImpl implements _Auction { | ||
_$AuctionImpl( | ||
{required this.id, | ||
@JsonKey(name: 'starting_price') required this.startingPrice, | ||
@JsonKey(name: 'end_date') @TimestampConverter() required this.endDate, | ||
@JsonKey(name: 'item_id') required this.itemId}); | ||
|
||
factory _$AuctionImpl.fromJson(Map<String, dynamic> json) => | ||
_$$AuctionImplFromJson(json); | ||
|
||
@override | ||
final String id; | ||
@override | ||
@JsonKey(name: 'starting_price') | ||
final double startingPrice; | ||
@override | ||
@JsonKey(name: 'end_date') | ||
@TimestampConverter() | ||
final DateTime endDate; | ||
@override | ||
@JsonKey(name: 'item_id') | ||
final String itemId; | ||
|
||
@override | ||
String toString() { | ||
return 'Auction(id: $id, startingPrice: $startingPrice, endDate: $endDate, itemId: $itemId)'; | ||
} | ||
|
||
@override | ||
bool operator ==(Object other) { | ||
return identical(this, other) || | ||
(other.runtimeType == runtimeType && | ||
other is _$AuctionImpl && | ||
(identical(other.id, id) || other.id == id) && | ||
(identical(other.startingPrice, startingPrice) || | ||
other.startingPrice == startingPrice) && | ||
(identical(other.endDate, endDate) || other.endDate == endDate) && | ||
(identical(other.itemId, itemId) || other.itemId == itemId)); | ||
} | ||
|
||
@JsonKey(ignore: true) | ||
@override | ||
int get hashCode => | ||
Object.hash(runtimeType, id, startingPrice, endDate, itemId); | ||
|
||
@JsonKey(ignore: true) | ||
@override | ||
@pragma('vm:prefer-inline') | ||
_$$AuctionImplCopyWith<_$AuctionImpl> get copyWith => | ||
__$$AuctionImplCopyWithImpl<_$AuctionImpl>(this, _$identity); | ||
|
||
@override | ||
Map<String, dynamic> toJson() { | ||
return _$$AuctionImplToJson( | ||
this, | ||
); | ||
} | ||
} | ||
|
||
abstract class _Auction implements Auction { | ||
factory _Auction( | ||
{required final String id, | ||
@JsonKey(name: 'starting_price') required final double startingPrice, | ||
@JsonKey(name: 'end_date') | ||
@TimestampConverter() | ||
required final DateTime endDate, | ||
@JsonKey(name: 'item_id') required final String itemId}) = _$AuctionImpl; | ||
|
||
factory _Auction.fromJson(Map<String, dynamic> json) = _$AuctionImpl.fromJson; | ||
|
||
@override | ||
String get id; | ||
@override | ||
@JsonKey(name: 'starting_price') | ||
double get startingPrice; | ||
@override | ||
@JsonKey(name: 'end_date') | ||
@TimestampConverter() | ||
DateTime get endDate; | ||
@override | ||
@JsonKey(name: 'item_id') | ||
String get itemId; | ||
@override | ||
@JsonKey(ignore: true) | ||
_$$AuctionImplCopyWith<_$AuctionImpl> get copyWith => | ||
throw _privateConstructorUsedError; | ||
} |
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,16 @@ | ||
import 'package:json_annotation/json_annotation.dart'; | ||
import 'package:rainbowbid_frontend/models/items/item.dart'; | ||
|
||
class CategoryConverter implements JsonConverter<Category, String> { | ||
const CategoryConverter(); | ||
|
||
@override | ||
Category fromJson(String json) { | ||
return Category.fromValue(json); | ||
} | ||
|
||
@override | ||
String toJson(Category object) { | ||
return object.value; | ||
} | ||
} |
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,15 @@ | ||
import 'package:freezed_annotation/freezed_annotation.dart'; | ||
|
||
class TimestampConverter implements JsonConverter<DateTime, int> { | ||
const TimestampConverter(); | ||
|
||
@override | ||
DateTime fromJson(int json) { | ||
return DateTime.fromMillisecondsSinceEpoch(json * 1000, isUtc: true); | ||
} | ||
|
||
@override | ||
int toJson(DateTime object) { | ||
return object.millisecondsSinceEpoch; | ||
} | ||
} |
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,23 @@ | ||
import 'package:freezed_annotation/freezed_annotation.dart'; | ||
import 'package:rainbowbid_frontend/models/core/category_converter.dart'; | ||
import 'package:rainbowbid_frontend/models/items/item.dart'; | ||
|
||
part 'auction_with_item_dto.freezed.dart'; | ||
part 'auction_with_item_dto.g.dart'; | ||
|
||
@freezed | ||
class AuctionWithItemDto with _$AuctionWithItemDto { | ||
const factory AuctionWithItemDto({ | ||
required String id, | ||
@JsonKey(name: 'starting_price') required double startingPrice, | ||
@JsonKey(name: 'end_date') required DateTime endDate, | ||
@JsonKey(name: 'item_id') required String itemId, | ||
required String brief, | ||
required String description, | ||
@CategoryConverter() required Category category, | ||
@JsonKey(name: 'user_id') required String userId, | ||
}) = _AuctionWithItemDto; | ||
|
||
factory AuctionWithItemDto.fromJson(Map<String, dynamic> json) => | ||
_$AuctionWithItemDtoFromJson(json); | ||
} |
Oops, something went wrong.