| | | 1 | | using Pomodoro.Web.Models; |
| | | 2 | | |
| | | 3 | | namespace Pomodoro.Web.Services.Formatters; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// Service for formatting ActivityItem component data. |
| | | 7 | | /// Extracts formatting logic from component to enable testable code with coverage tracking. |
| | | 8 | | /// </summary> |
| | | 9 | | public class ActivityItemFormatter |
| | | 10 | | { |
| | | 11 | | /// <summary> |
| | | 12 | | /// Checks if the activity is valid. |
| | | 13 | | /// </summary> |
| | | 14 | | /// <param name="activity">The activity to check</param> |
| | | 15 | | /// <returns>True if activity is not null and has a valid ID</returns> |
| | | 16 | | public bool IsValidActivity(ActivityRecord? activity) |
| | 6 | 17 | | { |
| | 6 | 18 | | return activity != null && activity.Id != Guid.Empty; |
| | 6 | 19 | | } |
| | | 20 | | |
| | | 21 | | /// <summary> |
| | | 22 | | /// Gets the formatted time for display. |
| | | 23 | | /// </summary> |
| | | 24 | | /// <param name="activity">The activity to format</param> |
| | | 25 | | /// <returns>Formatted time string (HH:mm) or "N/A" if null</returns> |
| | | 26 | | public string GetFormattedTime(ActivityRecord? activity) |
| | 5 | 27 | | { |
| | 6 | 28 | | if (activity == null) return "N/A"; |
| | 4 | 29 | | return activity.CompletedAt.ToString("HH:mm"); |
| | 5 | 30 | | } |
| | | 31 | | |
| | | 32 | | /// <summary> |
| | | 33 | | /// Gets the formatted duration for display. |
| | | 34 | | /// </summary> |
| | | 35 | | /// <param name="activity">The activity to format</param> |
| | | 36 | | /// <returns>Formatted duration string (e.g., "25m") or "0m" if null</returns> |
| | | 37 | | public string GetFormattedDuration(ActivityRecord? activity) |
| | 5 | 38 | | { |
| | 6 | 39 | | if (activity == null) return "0m"; |
| | 4 | 40 | | return $"{activity.DurationMinutes}m"; |
| | 5 | 41 | | } |
| | | 42 | | |
| | | 43 | | /// <summary> |
| | | 44 | | /// Gets the session type display name. |
| | | 45 | | /// </summary> |
| | | 46 | | /// <param name="activity">The activity to format</param> |
| | | 47 | | /// <returns>Session type name or "Unknown" if null</returns> |
| | | 48 | | public string GetSessionTypeDisplay(ActivityRecord? activity) |
| | 5 | 49 | | { |
| | 6 | 50 | | if (activity == null) return "Unknown"; |
| | 4 | 51 | | return activity.Type.ToString(); |
| | 5 | 52 | | } |
| | | 53 | | |
| | | 54 | | /// <summary> |
| | | 55 | | /// Checks if the activity has an associated task. |
| | | 56 | | /// </summary> |
| | | 57 | | /// <param name="activity">The activity to check</param> |
| | | 58 | | /// <returns>True if activity has a task name</returns> |
| | | 59 | | public bool HasTask(ActivityRecord? activity) |
| | 7 | 60 | | { |
| | 7 | 61 | | return activity != null && !string.IsNullOrWhiteSpace(activity.TaskName); |
| | 7 | 62 | | } |
| | | 63 | | |
| | | 64 | | /// <summary> |
| | | 65 | | /// Gets the task name for display. |
| | | 66 | | /// </summary> |
| | | 67 | | /// <param name="activity">The activity to format</param> |
| | | 68 | | /// <returns>Task name or "No task" if null or empty</returns> |
| | | 69 | | public string GetTaskName(ActivityRecord? activity) |
| | 7 | 70 | | { |
| | 8 | 71 | | if (activity == null) return "No task"; |
| | 6 | 72 | | return string.IsNullOrWhiteSpace(activity.TaskName) ? "No task" : activity.TaskName; |
| | 7 | 73 | | } |
| | | 74 | | } |