2024-12-13 01:01:50 +04:00
|
|
|
import 'package:pmu/data/dto/user_dto.dart';
|
2024-12-19 13:20:27 +04:00
|
|
|
import 'package:pmu/domain/models/card.dart';
|
2024-12-11 04:57:28 +04:00
|
|
|
|
2024-12-13 01:01:50 +04:00
|
|
|
extension UserDtoToModel on UserDto {
|
2024-12-19 13:20:27 +04:00
|
|
|
CardData toDomain() {
|
2024-12-13 03:19:59 +04:00
|
|
|
const allowedExtensions = ['jpg', 'jpeg', 'gif', 'png'];
|
2024-12-11 04:57:28 +04:00
|
|
|
|
|
|
|
bool isValidImageUrl(String? url) {
|
|
|
|
if (url == null) return false;
|
|
|
|
final extension = url.split('.').last.toLowerCase();
|
|
|
|
return allowedExtensions.contains(extension);
|
|
|
|
}
|
|
|
|
|
2024-12-19 13:20:27 +04:00
|
|
|
return CardData(
|
2024-12-13 03:03:08 +04:00
|
|
|
name: name ?? "",
|
|
|
|
surname: surname ?? "",
|
|
|
|
description: description ?? "",
|
|
|
|
imageUrl: isValidImageUrl(image)
|
|
|
|
? image
|
|
|
|
: (gender! == "male"
|
|
|
|
? "https://avatar.iran.liara.run/public/boy"
|
|
|
|
: "https://avatar.iran.liara.run/public/girl")
|
|
|
|
.toString(),
|
|
|
|
age: age,
|
2024-12-19 18:59:49 +04:00
|
|
|
distance: distance,
|
|
|
|
id: id?.toString());
|
2024-12-11 04:57:28 +04:00
|
|
|
}
|
|
|
|
}
|