-
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.
- Loading branch information
Showing
7 changed files
with
79 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import 'package:intl/intl.dart'; | ||
|
||
final class DateFormatter { | ||
const DateFormatter._(); | ||
|
||
static final _yyyyMMddFormat = DateFormat('yyyy-MM-dd'); | ||
|
||
static String yyyyMMdd(DateTime date) => _yyyyMMddFormat.format(date); | ||
} |
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
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
44 changes: 44 additions & 0 deletions
44
lib/features/picture_of_the_day/data/models/local_picture_model.dart
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,44 @@ | ||
import 'package:nasa_potday/core/date_formatters/date_formatter.dart'; | ||
import 'package:nasa_potday/features/picture_of_the_day/domain/entities/picture_entity.dart'; | ||
|
||
class LocalPictureModel extends PictureEntity { | ||
const LocalPictureModel({ | ||
required super.url, | ||
required super.title, | ||
required super.explanation, | ||
required super.date, | ||
required super.isVideo, | ||
}); | ||
|
||
factory LocalPictureModel.fromEntity(PictureEntity entity) { | ||
return LocalPictureModel( | ||
url: entity.url, | ||
title: entity.title, | ||
explanation: entity.explanation, | ||
date: entity.date, | ||
isVideo: entity.isVideo, | ||
); | ||
} | ||
|
||
Map<String, dynamic> toJson() { | ||
return { | ||
'date': DateFormatter.yyyyMMdd(date), | ||
'url': url.toString(), | ||
'title': title, | ||
'explanation': explanation, | ||
'is_video': isVideo ? 1 : 0, | ||
}; | ||
} | ||
|
||
factory LocalPictureModel.fromJson(Map<String, dynamic> json) { | ||
final isVideo = json['media_type'] == 'video'; | ||
|
||
return LocalPictureModel( | ||
url: Uri.parse(isVideo ? json['thumbnail_url'] : json['url']), | ||
title: json['title'], | ||
explanation: json['explanation'], | ||
date: DateTime.parse(json['date']), | ||
isVideo: json['is_video'] == 1, | ||
); | ||
} | ||
} |
14 changes: 7 additions & 7 deletions
14
...of_the_day/data/models/picture_model.dart → ...day/data/models/remote_picture_model.dart
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,23 +1,23 @@ | ||
import 'package:nasa_potday/features/picture_of_the_day/domain/entities/picture_entity.dart'; | ||
|
||
class PictureModel extends PictureEntity { | ||
const PictureModel({ | ||
class RemotePictureModel extends PictureEntity { | ||
const RemotePictureModel({ | ||
required super.url, | ||
required super.title, | ||
required super.explanation, | ||
required super.date, | ||
required super.isVideo, | ||
}); | ||
|
||
factory PictureModel.fromJson(Map<String, dynamic> json) { | ||
final url = Uri.parse(json['url']); | ||
factory RemotePictureModel.fromJson(Map<String, dynamic> json) { | ||
final isVideo = json['media_type'] == 'video'; | ||
|
||
return PictureModel( | ||
url: url, | ||
return RemotePictureModel( | ||
url: Uri.parse(isVideo ? json['thumbnail_url'] : json['url']), | ||
title: json['title'], | ||
explanation: json['explanation'], | ||
date: DateTime.parse(json['date']), | ||
isVideo: json['media_type'] == 'video', | ||
isVideo: isVideo, | ||
); | ||
} | ||
} |
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