LCOV - code coverage report
Current view: top level - app\domain\entities\models\mdl_getlist_movies.dart - mdl_getlist_movies.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 22 22 100.0 %
Date: Wed Aug 6 23:43:55 2025 Functions: 0 0 -

          Line data    Source code
       1             : import 'dart:convert';
       2             : 
       3             : import 'mdl_the_movie.dart';
       4             : 
       5             : /// Represents a paginated list of movies fetched from the API.
       6             : ///
       7             : /// The [GetListMovies] class contains pagination information and a list of [TheMovie] objects.
       8             : /// It is used to handle the response from the API when fetching popular or searched movies.
       9             : ///
      10             : /// ### Properties
      11             : /// - [page]: The current page number.
      12             : /// - [results]: The list of movies ([TheMovie]) for the current page.
      13             : /// - [totalPages]: The total number of pages available.
      14             : /// - [totalResults]: The total number of results available.
      15             : ///
      16             : /// ### Methods
      17             : /// - [copyWith]: Returns a copy of the instance with modified values.
      18             : /// - [fromRaw]: Creates an instance from a raw JSON string.
      19             : /// - [fromMap]: Creates an instance from a JSON map.
      20             : /// - [empty]: Creates an empty instance.
      21             : /// - [toMap]: Converts the instance to a JSON map.
      22             : ///
      23             : /// ### Example
      24             : /// ```dart
      25             : /// final movies = GetListMovies.fromRaw(jsonString);
      26             : /// print(movies.results.length);
      27             : /// ```
      28             : class GetListMovies {
      29             :   /// Creates an instance of `GetListMovies`.
      30             :   ///
      31             :   /// **Parameters:**
      32             :   /// - `page` (int): The current page number.
      33             :   /// - `results` (List<TheMovie>): The list of movies.
      34             :   /// - `totalPages` (int): The total number of pages available.
      35             :   /// - `totalResults` (int): The total number of results available.
      36           2 :   GetListMovies({
      37             :     required this.page,
      38             :     required this.results,
      39             :     required this.totalPages,
      40             :     required this.totalResults,
      41             :   });
      42             : 
      43             :   int page;
      44             :   List<TheMovie> results;
      45             :   int totalPages;
      46             :   int totalResults;
      47             : 
      48             :   /// Creates a copy of the current `GetListMovies` instance with optional modifications.
      49             :   ///
      50             :   /// **Parameters:**
      51             :   /// - `page` (int?): The new page number.
      52             :   /// - `results` (List<TheMovie>?): The new list of movies.
      53             :   /// - `totalPages` (int?): The new total number of pages.
      54             :   /// - `totalResults` (int?): The new total number of results.
      55             :   ///
      56             :   /// **Returns:**
      57             :   /// - A new `GetListMovies` instance with the updated values.
      58           1 :   GetListMovies copyWith({
      59             :     int? page,
      60             :     List<TheMovie>? results,
      61             :     int? totalPages,
      62             :     int? totalResults,
      63           1 :   }) => GetListMovies(
      64           1 :     page: page ?? this.page,
      65           1 :     results: results ?? this.results,
      66           1 :     totalPages: totalPages ?? this.totalPages,
      67           1 :     totalResults: totalResults ?? this.totalResults,
      68             :   );
      69             : 
      70             :   /// Creates a `GetListMovies` instance from a raw JSON string.
      71             :   ///
      72             :   /// **Parameters:**
      73             :   /// - `str` (String): The raw JSON string.
      74             :   ///
      75             :   /// **Returns:**
      76             :   /// - A `GetListMovies` instance parsed from the JSON string.
      77           1 :   factory GetListMovies.fromRaw(String str) =>
      78           2 :       GetListMovies.fromMap(json.decode(str));
      79             : 
      80             :   /// Creates a `GetListMovies` instance from a JSON map.
      81             :   ///
      82             :   /// **Parameters:**
      83             :   /// - `json` (Map<String, dynamic>): The JSON map.
      84             :   ///
      85             :   /// **Returns:**
      86             :   /// - A `GetListMovies` instance parsed from the JSON map.
      87           2 :   factory GetListMovies.fromMap(Map<String, dynamic> json) => GetListMovies(
      88           1 :     page: json["page"] ?? 0,
      89           1 :     results: List<TheMovie>.from(
      90           4 :       (json["results"] ?? []).map((x) => TheMovie.fromMap(x)),
      91             :     ),
      92           1 :     totalPages: json["total_pages"] ?? 0,
      93           1 :     totalResults: json["total_results"] ?? 0,
      94             :   );
      95             : 
      96             :   /// Creates an empty `GetListMovies` instance.
      97             :   ///
      98             :   /// **Returns:**
      99             :   /// - A `GetListMovies` instance with default values.
     100           1 :   factory GetListMovies.empty() =>
     101           2 :       GetListMovies(page: 0, results: [], totalPages: 0, totalResults: 0);
     102             : 
     103             :   /// Converts the `GetListMovies` instance to a JSON map.
     104             :   ///
     105             :   /// **Returns:**
     106             :   /// - A `Map<String, dynamic>` representing the `GetListMovies` instance.
     107           2 :   Map<String, dynamic> toMap() => {
     108           1 :     "page": page,
     109           5 :     "results": results.map((x) => x.toMap()).toList(),
     110           1 :     "total_pages": totalPages,
     111           1 :     "total_results": totalResults,
     112             :   };
     113             : }

Generated by: LCOV version 1.15.alpha0w