Сгенерировал мапперы DTO

This commit is contained in:
Никита Потапов 2024-12-13 01:01:50 +04:00
parent 5a97a3bb7f
commit 12cf583b35
5 changed files with 57 additions and 11 deletions

View File

@ -1,16 +1,19 @@
import 'package:json_annotation/json_annotation.dart';
import 'package:pmu/data/dto/user_dto.dart';
part 'page_dto.g.dart';
@JsonSerializable(createToJson: false)
class PageDto {
final List<UserDto> items;
final int itemsCount;
final int totalItemsCount;
final int pageNumber;
final int itemsByPage;
final List<UserDto>? items;
final int? itemsCount;
final int? totalItemsCount;
final int? pageNumber;
final int? itemsByPage;
final int? prevPageNumber;
final int? nextPageNumber;
final int firstPageNumber;
final int lastPageNumber;
final int? firstPageNumber;
final int? lastPageNumber;
const PageDto(
{this.items,

View File

@ -0,0 +1,21 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'page_dto.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
PageDto _$PageDtoFromJson(Map<String, dynamic> json) => PageDto(
items: (json['items'] as List<dynamic>?)
?.map((e) => UserDto.fromJson(e as Map<String, dynamic>))
.toList(),
itemsCount: (json['itemsCount'] as num?)?.toInt(),
totalItemsCount: (json['totalItemsCount'] as num?)?.toInt(),
pageNumber: (json['pageNumber'] as num?)?.toInt(),
itemsByPage: (json['itemsByPage'] as num?)?.toInt(),
prevPageNumber: (json['prevPageNumber'] as num?)?.toInt(),
nextPageNumber: (json['nextPageNumber'] as num?)?.toInt(),
firstPageNumber: (json['firstPageNumber'] as num?)?.toInt(),
lastPageNumber: (json['lastPageNumber'] as num?)?.toInt(),
);

View File

@ -1,5 +1,7 @@
import 'package:json_annotation/json_annotation.dart';
part 'user_dto.g.dart';
@JsonSerializable(createToJson: false)
class UserDto {
final int? id;

View File

@ -0,0 +1,21 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'user_dto.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
UserDto _$UserDtoFromJson(Map<String, dynamic> json) => UserDto(
id: (json['id'] as num?)?.toInt(),
name: json['name'] as String?,
surname: json['surname'] as String?,
description: json['description'] as String?,
image: json['image'] as String?,
gender: json['gender'] as String?,
dateOfBirth: json['dateOfBirth'] as String?,
lat: (json['lat'] as num?)?.toDouble(),
lon: (json['lon'] as num?)?.toDouble(),
age: (json['age'] as num?)?.toInt(),
distance: (json['distance'] as num?)?.toDouble(),
);

View File

@ -1,8 +1,7 @@
import 'package:pmu/data/dtos/user_dto.dart';
import 'package:pmu/data/dto/user_dto.dart';
import 'package:pmu/domain/card.dart';
import '../../domain/card.dart';
extension UserDataDtoToModel on UserDataDto {
extension UserDtoToModel on UserDto {
CardPostData toDomain() {
const allowedExtensions = ['jpg', 'jpeg', 'gif'];