Commit Graph

42 Commits

Author SHA1 Message Date
Dylan Knutson
c53dccbea2 error handler wrapper helper 2025-09-02 19:55:15 +00:00
Dylan Knutson
8610b4cc52 handler wrapper for catching error 2025-09-02 19:11:57 +00:00
Dylan Knutson
f74c3502d6 basic listing stuff 2025-09-02 01:47:45 +00:00
Dylan Knutson
da1fd1027f more handler refactoring 2025-08-31 00:04:18 +00:00
Dylan Knutson
461ce3aba4 Update new_listing and my_listings functionality 2025-08-30 18:41:42 +00:00
Dylan Knutson
a39dd01452 Refactor bot commands and database models
- Update my_listings command structure and keyboard handling
- Enhance new_listing workflow with improved callbacks and handlers
- Refactor database user model and keyboard utilities
- Add new handler utilities module
- Update main bot configuration and start command
2025-08-30 11:04:40 -07:00
Dylan Knutson
65a50b05e2 feat: Add inline keyboard support to auction listing inline queries
- Add interactive inline keyboard with bid, watch, and share buttons
- Implement separate inline query handler before dialogue system
- Fix dispatcher structure to handle both inline queries and regular messages
- Add dynamic bot username fetching for deep links
- Support rich formatted auction listing messages with pricing info
- Handle forward_listing:ID pattern for sharing specific auctions

Resolves inline query handling and adds interactive auction sharing
2025-08-30 15:37:02 +00:00
Dylan Knutson
c9a824dd88 cargo clippy 2025-08-30 05:50:44 +00:00
Dylan Knutson
5d7a5b26c1 feat: enhance UX with listing type selection and main menu improvements
- Add listing type selection to new listing wizard
  - Create SelectingListingType state for choosing between 4 listing types
  - Add ListingTypeKeyboardButtons with clear descriptions
  - Support BasicAuction, MultiSlotAuction, FixedPriceListing, BlindAuction
  - Update handlers to start with type selection before title input

- Improve main menu navigation
  - Add main menu with action buttons for /start command
  - Create MainMenuButtons with New Listing, My Listings, My Bids, Settings, Help
  - Add back button to My Listings screen for better navigation
  - Implement proper dialogue state management between screens

- Refactor callback handling for type safety
  - Convert string literal matching to enum-based callback handling
  - Use try_from() pattern for all keyboard button callbacks
  - Ensure compile-time safety and exhaustive matching
  - Apply pattern to listing type, slots, duration, and start time callbacks

- Eliminate code duplication
  - Extract reusable main menu functions (enter_main_menu, get_main_menu_message)
  - Centralize main menu logic and message content
  - Update all main menu transitions to use shared functions

- Technical improvements
  - Add proper error handling for invalid callback data
  - Maintain backward compatibility with existing flows
  - Follow established patterns for keyboard button definitions
  - Ensure all changes compile without errors
2025-08-30 05:45:49 +00:00
Dylan Knutson
9ef36b760e feat: Add high-level integration testing framework
- Created trait abstractions for dependency injection with mockall support
- Added comprehensive integration tests focusing on:
  * Database operations and persistence
  * Complete user workflow scenarios
  * Dialogue state transitions and validation
  * Multi-user scenarios and data integrity
- Removed trivial unit tests, kept only meaningful business logic tests
- Added UserRepository, ListingRepository, and BotMessenger traits
- Integration tests verify end-to-end workflows with real database
- Total: 30 focused tests (4 unit + 8 integration + 18 validation tests)

Key integration test scenarios:
- Complete listing creation workflow with database persistence
- Listing update workflows with state validation
- Multi-user independent operations
- Error handling that preserves data integrity
- Business rule enforcement (e.g., no timing changes on live listings)

Framework ready for advanced mock-based testing when needed.
2025-08-30 04:41:07 +00:00
Dylan Knutson
5fe4a52c2b refactor: Split new_listing module into logical submodules
- Organized 810-line monolithic file into 10 focused modules
- Main mod.rs reduced from 810 to 27 lines (96.7% reduction)
- Clear separation of concerns with logical hierarchy:

Module Structure:
├── mod.rs (27 lines) - Module coordinator and exports
├── handlers.rs (362 lines) - Main teloxide handler functions
├── callbacks.rs (205 lines) - Callback query processing
├── validations.rs (145 lines) - Input validation logic
├── ui.rs (102 lines) - Display and summary functions
├── types.rs (82 lines) - Data structures and states
├── field_processing.rs (76 lines) - Core field update logic
├── messages.rs (73 lines) - Centralized message constants
├── handler_factory.rs (60 lines) - Teloxide handler tree
└── keyboard.rs (55 lines) - Button and keyboard definitions

Benefits:
- Single responsibility principle enforced
- Easy navigation and maintenance
- Reduced coupling between components
- Enhanced testability
- All 112 tests still passing
2025-08-30 04:15:27 +00:00
Dylan Knutson
24819633f5 refactor: Aggressive refactoring of new_listing module
- Reduced code size by 26.7% (1083→810 lines)
- Eliminated ALL duplication patterns:
  * Consolidated 12 individual handlers into 2 unified handlers
  * Centralized all step messages and success messages into constants
  * Removed repetitive pattern matching and state transitions
- Major architectural improvements:
  * Refactored ListingFields enum to use struct-based variants
  * Enhanced type safety with dedicated field structs
  * Simplified field access patterns throughout codebase
- Updated database layer for new enum structure
- Maintained full teloxide compatibility and functionality
- All 112 tests still passing
2025-08-30 03:07:31 +00:00
Dylan Knutson
143bf3ce41 refactor: Update listing confirmation flow and summary display
- Consolidate Create and Save button handling in confirmation flow
- Add unsaved changes indicator to listing summary
- Improve edit flow by using enter_edit_listing_draft function
- Update confirmation button logic and user feedback messages
- Clean up dialogue state management in confirmation handlers
2025-08-30 01:29:29 +00:00
Dylan Knutson
8fb51d12a7 feat: Add natural language duration parsing to validate_duration
- Support parsing strings like '1 hour', '7 days' in addition to plain numbers
- Maintain backwards compatibility with numeric input (e.g., '24')
- Support units: hour(s), hr(s), day(s)
- Add comprehensive test suite using rstest
- Enforce 1-720 hour limit (1 hour to 30 days)
- Provide clear error messages for invalid input
2025-08-30 00:17:24 +00:00
Dylan Knutson
374abf8c42 major db refactors 2025-08-29 23:25:12 +00:00
Dylan Knutson
c9acdc9fff delta diff tool 2025-08-29 17:34:56 +00:00
Dylan Knutson
83cdbb770d devcontainer w/ sqlite3 2025-08-29 10:21:39 -07:00
Dylan Knutson
d8e6c4ef3e cargo clippy 2025-08-29 10:21:39 -07:00
Dylan Knutson
34de9b6d59 Major refactor: restructure new listing command and update data models
- Refactor new_listing from single file to modular structure
- Add handler factory pattern for state management
- Improve keyboard utilities and validations
- Update database models for bid, listing, and user systems
- Add new types: listing_duration, user_row_id
- Remove deprecated user_id type
- Update Docker configuration
- Enhance test utilities and message handling
2025-08-29 10:21:39 -07:00
Dylan Knutson
a81308d577 refactor: improve case! macro tests with rstest parametrization
- Fix failing tests by correcting test expectations for parameter extraction
- Add comprehensive coverage including InnerWithMultiStruct variant
- Reduce test duplication using rstest parametrization
- Create assert_handler_result helper function to eliminate repetitive code
- Consolidate similar test patterns into unified test functions
- Ensure all macro functionality is properly tested with clear test case names

All 20 parameterized test cases now pass, covering:
- Simple variant filtering
- Single/multiple parameter extraction from enums
- Nested enum parameter extraction
- Struct field extraction (single and multiple fields)
- Proper negative test cases for non-matching variants
2025-08-28 22:02:52 +00:00
Dylan Knutson
d4ccbb884c Refactor keyboard utilities and improve user interface
- Extract keyboard utility functions to new keyboard_utils.rs module
- Update new listing command with improved keyboard handling
- Enhance message utilities with better user interaction
- Refactor user ID type handling
- Remove development database file
- Update main.rs with improved structure
2025-08-28 20:01:15 +00:00
Dylan Knutson
1d4d5c05ed Complete message utility adoption - fix all remaining send_html_message usage
- Created edit_html_message utility for consistent message editing
- Converted all bot.edit_message_text() calls to use edit_html_message
- Fixed markdown to HTML conversion (**Error:** → <b>Error:</b>, *text* → <i>text</i>)
- Added MessageId import to fix compilation errors
- 100% message utility adoption achieved - all direct bot message calls eliminated
2025-08-28 14:16:42 +00:00
Dylan Knutson
869526005f Complete validation function usage - fix unused validation functions
🔧 Fixed unused validation functions:
- Updated validate_duration() to handle hours (1-720) instead of days to match handler expectations
- Refactored handle_duration_input() to use validate_duration() utility
- Refactored handle_start_time_input() to use validate_start_time() utility

 All validation functions now utilized:
- validate_title() ✓ (used in handle_title_input)
- validate_price() ✓ (used in handle_price_input)
- validate_slots() ✓ (used in handle_slots_input)
- validate_duration() ✓ (used in handle_duration_input) - NOW USED
- validate_start_time() ✓ (used in handle_start_time_input) - NOW USED

🎯 Benefits:
- Eliminated all unused validation function warnings
- Consistent validation patterns across ALL input handlers
- Centralized error messages for easier maintenance
- Improved code consistency and maintainability

📊 Final refactoring status: 100% complete
- All input handlers now use validation utilities
- All validation functions are properly utilized
- No more code duplication in validation logic
2025-08-28 07:38:52 +00:00
Dylan Knutson
79ed3a7e4c Complete keyboard creation pattern refactoring
🎯 Added comprehensive keyboard creation utilities:
- create_single_button_keyboard(): For simple one-button keyboards
- create_single_row_keyboard(): For multiple buttons in one row
- create_multi_row_keyboard(): For complex multi-row layouts
- create_numeric_options_keyboard(): For numeric option patterns

🔧 Specialized keyboard functions:
- create_duration_keyboard(): Duration selection with proper callback format
- create_slots_keyboard(): Slot selection using numeric pattern
- create_confirmation_keyboard(): Create/Discard/Edit actions
- create_field_selection_keyboard(): Field editing menu
- create_start_time_keyboard(): Start time selection
- create_back_button_keyboard(): Navigation back button
- create_back_button_keyboard_with_clear(): Back + clear options
- create_skip_keyboard(): Skip action button

♻️ Refactored existing code:
- Replaced inline keyboard creation with utility function calls
- Removed duplicate keyboard creation functions
- Standardized keyboard patterns across all handlers
- Maintained backward compatibility with existing callback data formats

📊 Benefits:
- Consistent keyboard styling and behavior
- Easy to modify keyboard layouts in one place
- Reduced code duplication by ~50 lines
- Better maintainability for UI changes
- Foundation for future keyboard enhancements

 All refactoring tasks completed:
- Input handler patterns ✓
- Callback query handling ✓
- Message sending utilities ✓
- Validation logic ✓
- State transitions ✓
- Keyboard creation patterns ✓
- Logging utilities ✓
2025-08-28 07:35:14 +00:00
Dylan Knutson
0eef18ea06 Major refactoring: Deduplicate and improve new_listing.rs maintainability
 Added utility functions for code deduplication:
- send_html_message(): Unified HTML message sending with optional keyboards
- extract_callback_data(): Standardized callback query handling with error management
- validate_*(): Centralized validation functions for title, price, slots, duration, start_time
- log_user_action() & log_user_callback_action(): Consistent logging patterns
- transition_to_state(): Simplified state transitions
- handle_callback_error(): Unified error handling for callbacks

🔧 Refactored input handlers:
- handle_title_input(): Now uses validation utilities and cleaner error handling
- handle_description_input(): Simplified with utility functions
- handle_price_input(): Uses validate_price() and improved structure
- handle_slots_input(): Streamlined with validate_slots()

🔧 Refactored callback handlers:
- handle_description_callback(): Uses extract_callback_data() utility
- handle_slots_callback(): Improved structure and error handling

📊 Impact:
- Significantly improved code maintainability and consistency
- Reduced duplication across input and callback handlers
- Centralized validation logic for easier maintenance
- Better error handling and logging throughout
- Foundation for further refactoring of remaining handlers

🏗️ Code structure:
- Added comprehensive utility section at top of file
- Maintained backward compatibility
- All existing functionality preserved
2025-08-28 07:30:59 +00:00
Dylan Knutson
764c17af05 Fix dialogue handler structure and enhance duration input
- Fix handler type mismatch error by properly ordering dialogue entry
- Move .enter_dialogue() before handlers that need dialogue context
- Remove duplicate command handler branches
- Add duration callback handler for inline keyboard buttons
- Add duration keyboard with 1, 3, 7, and 14 day options
- Refactor duration processing into shared function
- Simplify slots keyboard layout to single row
- Improve code organization and error handling
2025-08-28 07:23:40 +00:00
Dylan Knutson
71fe1e60c0 feat: Add comprehensive edit screen to new listing wizard
- Replace individual state structs with unified ListingDraft struct
- Add EditingListing state with field selection interface
- Implement individual field editing states (Title, Description, Price, Slots, StartTime, Duration)
- Add field-specific keyboards with Back buttons and Clear functionality for description
- Update all handlers to use ListingDraft instead of separate state structs
- Rename Confirming to ViewingDraft for clarity
- Add proper validation and error handling for all field edits
- Enable seamless navigation between edit screen and confirmation
- Maintain all existing functionality while adding edit capabilities
2025-08-28 06:58:55 +00:00
Dylan Knutson
4e5283b530 rename commands 2025-08-28 01:30:30 +00:00
Dylan Knutson
8745583990 Add configuration and database setup
- Updated Cargo.toml with necessary dependencies
- Enhanced config.rs with database and application configuration
- Updated main.rs with improved bot initialization
- Added development database file
2025-08-28 01:28:31 +00:00
Dylan Knutson
af1f3271a3 chore: update rstest dependency from 0.21 to 0.26.1
- Update rstest version for better test parametrization support
- Update corresponding Cargo.lock
2025-08-28 01:19:41 +00:00
Dylan Knutson
5212175df5 refactor: organize type definitions into dedicated db/types/ directory
- Move type files to src/db/types/: currency_type, listing_id, user_id, money_amount, telegram_user_id
- Create types/mod.rs with proper re-exports for all type modules
- Update db/mod.rs to import from new types module instead of individual files
- All tests pass - no functionality changes
- Improves code organization by clearly separating types, DAOs, and models
2025-08-28 01:17:45 +00:00
Dylan Knutson
3a7d0a6905 refactor: organize DAOs into dedicated db/dao/ directory
- Move listing_dao.rs and user_dao.rs to src/db/dao/
- Create dao/mod.rs with proper re-exports for ListingDAO and UserDAO
- Update import paths in DAO files to work from new location
- Update db/mod.rs to import from new dao module
- All tests still pass - no functionality changes
2025-08-28 01:15:40 +00:00
Dylan Knutson
7a16c5859b feat: add epsilon-based timestamp comparison macros for tests 2025-08-28 01:05:16 +00:00
Dylan Knutson
fc1a61ff32 feat: implement type-safe ID system and enum-based listing architecture
- Add UserId and ListingId newtype wrappers with SQLx integration
  - Prevents mixing up different ID types at compile time
  - Custom Encode/Decode traits for seamless database operations
  - Zero-cost abstractions with full type safety

- Refactor Listing to enum-based architecture
  - BasicAuction: Traditional time-based auction with bidding
  - MultiSlotAuction: Auction with multiple winners/slots
  - FixedPriceListing: Fixed price sale with no bidding
  - BlindAuction: Blind auction where seller chooses winner
  - ListingBase: Common fields shared by all listing types
  - ListingRow: Flat database row structure for SQLx compatibility

- Update ListingType enum variants
  - Standard -> BasicAuction
  - MultiSlot -> MultiSlotAuction
  - FixedPrice -> FixedPriceListing
  - Blind -> BlindAuction

- Add comprehensive conversion traits and helper methods
- Maintain full database compatibility with existing schema
- Remove unused helper methods and make base() private for cleaner API
2025-08-27 23:38:10 +00:00
Dylan Knutson
eca570c887 chore: Remove dead code - delete obsolete money.rs file
- Remove src/db/money.rs which contained the old Decimal-based MoneyAmount implementation
- This file was leftover from the INTEGER cents refactoring and was not referenced in mod.rs
- Only money_amount.rs with INTEGER storage is now active
- Compilation confirmed successful after removal
2025-08-27 23:24:44 +00:00
Dylan Knutson
0eaab7c743 refactor: Modularize database models into separate files
- Break down monolithic src/db/models.rs into focused model files
- Create src/db/models/ directory with individual files:
  - listing_type.rs - ListingType enum and variants
  - user.rs - User struct and NewUser helper
  - listing.rs - Listing struct and NewListing helper
  - bid.rs - Bid struct and NewBid helper
  - proxy_bid.rs - ProxyBid struct and NewProxyBid helper
  - listing_media.rs - ListingMedia for file attachments
  - user_settings.rs - UserSettings for user preferences
  - mod.rs - Re-exports all models for seamless access
- Remove old monolithic models.rs file
- Maintain backward compatibility through re-exports

Benefits:
- Improved code organization and maintainability
- Better separation of concerns for each model
- Easier navigation and IDE support
- Reduced merge conflicts in team development
- Scalable foundation for adding new models
2025-08-27 23:23:16 +00:00
Dylan Knutson
32dca5f4de refactor: Convert MoneyAmount to INTEGER cents storage and modularize currency types
- Refactor MoneyAmount to store as INTEGER cents instead of TEXT decimals
- Move CurrencyType to separate currency_type.rs module
- Rename money.rs to money_amount.rs for clarity
- Update database schema to use INTEGER for all monetary columns
- Remove complex CAST AS REAL workarounds from database queries
- Add comprehensive test coverage for cent-based arithmetic and storage
- Enable STRICT mode and foreign key constraints in SQLite
- Add rstest dependency for parameterized testing

Benefits:
- Faster INTEGER-based comparisons vs TEXT casting
- Exact financial precision without floating-point errors
- Simpler, cleaner SQL queries
- Better performance for auction bid operations
2025-08-27 23:19:13 +00:00
Dylan Knutson
348fa416e8 feat: implement database layer and rename auction -> listing
Major Changes:
- Set up SQLx database connection and migration system
- Create complete initial database schema with all tables
- Rename 'auction' to 'listing' throughout codebase for better terminology
- Update bot commands: /newauction -> /newlisting, /myauctions -> /mylistings
- Update all database tables: auctions -> listings, auction_medias -> listing_medias
- Update foreign key relationships and indexes
- Add automatic database migration on startup
- Update documentation and README
- Complete backlog tasks: task-001, task-002, task-010

The bot now has a solid database foundation ready for implementing core business logic.
All tests pass and code compiles successfully.
2025-08-27 19:24:15 +00:00
Dylan Knutson
30751181e4 add .env.example, user-stories.md 2025-08-27 19:12:40 +00:00
Dylan Knutson
947092ce54 add README.md 2025-08-27 02:57:14 +00:00
Dylan Knutson
b5f15f9d3e add .cursorrules with backlog.md description 2025-08-27 02:42:23 +00:00
Dylan Knutson
caebe567df initial commit 2025-08-26 22:39:40 -04:00