Skip to content

Refactor favorite status to type-safe enum and fix DateTime comparison - #201

Merged
richardthe3rd merged 3 commits into
claude/implement-my-festival-3diaOfrom
copilot/sub-pr-200
Jan 2, 2026
Merged

Refactor favorite status to type-safe enum and fix DateTime comparison#201
richardthe3rd merged 3 commits into
claude/implement-my-festival-3diaOfrom
copilot/sub-pr-200

Conversation

Copilot AI commented Jan 2, 2026

Copy link
Copy Markdown
Contributor

Addresses PR review feedback on the My Festival feature by replacing string literals with type-safe enums and fixing timestamp comparison issues.

Type Safety

  • Introduced FavoriteStatus enum (wantToTry, tasted) with fromString() factory for JSON deserialization
  • Replaced all string literal status values throughout models, services, repositories, and tests
  • Updated getFavoriteStatus() to return .value from enum

DateTime Comparison Fix

  • Changed deleteTry to compare timestamps via millisecondsSinceEpoch instead of direct equality
  • Prevents false matches when DateTime objects are deserialized from JSON with potentially different microsecond precision

Test Coverage

  • Added test verifying deleteTry works correctly after JSON round-trip serialization
  • Added delays between rapid timestamp creation to ensure distinct millisecond values
  • Fixed test assertion type from Map<String, dynamic> to Map<String, FavoriteItem>

Documentation

  • Documented FavoriteItem equality operator's ID-only comparison rationale (enables use in Sets/Maps where uniqueness is by drink, not state)
  • Added comprehensive Optional<T> class documentation with usage examples for nullable copyWith parameters
// Before: error-prone string literals
status: 'want_to_try'

// After: type-safe enum
status: FavoriteStatus.wantToTry

// Before: fragile DateTime comparison
updatedTries = tries.where((t) => t != timestamp)

// After: reliable millisecond comparison  
updatedTries = tries.where((t) => t.millisecondsSinceEpoch != timestamp.millisecondsSinceEpoch)

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits January 2, 2026 19:41
- Added FavoriteStatus enum with wantToTry and tasted values
- Updated FavoriteItem model to use FavoriteStatus instead of string literals
- Fixed DateTime comparison in deleteTry to use millisecondsSinceEpoch
- Added comprehensive documentation for FavoriteItem equality operator
- Added detailed documentation for Optional class with usage examples
- Fixed test assertion type from Map<String, dynamic> to Map<String, FavoriteItem>
- Added test coverage for deleteTry after JSON serialization
- Updated all tests to use FavoriteStatus enum

Co-authored-by: richardthe3rd <573334+richardthe3rd@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement My Festival favourites feature Refactor favorite status to type-safe enum and fix DateTime comparison Jan 2, 2026
Copilot AI requested a review from richardthe3rd January 2, 2026 19:45
@richardthe3rd
richardthe3rd marked this pull request as ready for review January 2, 2026 19:45
@richardthe3rd
richardthe3rd merged commit db8a05b into claude/implement-my-festival-3diaO Jan 2, 2026
@richardthe3rd
richardthe3rd deleted the copilot/sub-pr-200 branch January 2, 2026 19:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants