Add enums for ReviewStatus, TrackMaterial, LaunchType, RideCategory, and RollerCoasterType; implement Designer and RideModel models; create migrations for ride_models and helpful_votes tables; enhance RideGalleryComponent documentation

This commit is contained in:
pacnpal
2025-02-25 20:37:19 -05:00
parent 8951e59f49
commit 64b0e90a27
35 changed files with 3157 additions and 1 deletions

View File

@@ -0,0 +1,101 @@
# Review System Models
## Review Model
Represents user reviews for rides in the system.
### Properties
- `id` (int) - Primary key
- `ride_id` (int) - Foreign key to rides table
- `user_id` (int) - Foreign key to users table
- `rating` (int) - Rating from 1 to 5
- `title` (string, nullable) - Optional review title
- `content` (text) - Review content
- `status` (enum) - ReviewStatus enum value
- `moderated_at` (timestamp) - When review was moderated
- `moderated_by` (int) - Foreign key to users table (moderator)
- `helpful_votes_count` (int) - Counter cache for helpful votes
### Relationships
- `ride` - BelongsTo relationship to Ride model
- `user` - BelongsTo relationship to User model
- `moderator` - BelongsTo relationship to User model
- `helpfulVotes` - HasMany relationship to HelpfulVote model
### Scopes
- `pending()` - Reviews awaiting moderation
- `approved()` - Approved reviews
- `rejected()` - Rejected reviews
- `byRide()` - Filter by ride
- `byUser()` - Filter by user
### Methods
- `approve()` - Approve the review
- `reject()` - Reject the review
- `moderate()` - General moderation method
- `toggleHelpfulVote()` - Toggle helpful vote from a user
## HelpfulVote Model
Represents users marking reviews as helpful.
### Properties
- `id` (int) - Primary key
- `review_id` (int) - Foreign key to reviews table
- `user_id` (int) - Foreign key to users table
- `created_at` (timestamp) - When vote was cast
### Relationships
- `review` - BelongsTo relationship to Review model
- `user` - BelongsTo relationship to User model
### Methods
- `toggle()` - Toggle vote status
## Database Considerations
### Indexes
1. Reviews Table:
- Primary Key: id
- Foreign Keys: ride_id, user_id, moderated_by
- Composite: [ride_id, user_id] (unique)
- Indexes: [ride_id, status], [user_id, created_at], status
2. Helpful Votes Table:
- Primary Key: id
- Foreign Keys: review_id, user_id
- Composite: [review_id, user_id] (unique)
- Indexes: [user_id, created_at]
### Constraints
1. Reviews:
- One review per ride per user
- Rating must be between 1 and 5
- Status must be valid enum value
- Content is required
2. Helpful Votes:
- One vote per review per user
- Cascading deletes with review
## Usage Examples
```php
// Create a review
$review = Review::create([
'ride_id' => $ride->id,
'user_id' => Auth::id(),
'rating' => 5,
'title' => 'Great ride!',
'content' => 'This was amazing...',
]);
// Toggle helpful vote
$review->toggleHelpfulVote(Auth::id());
// Moderate a review
$review->moderate(ReviewStatus::APPROVED, Auth::id());
// Get ride's approved reviews
$reviews = $ride->reviews()->approved()->latest()->get();
// Get user's helpful votes
$votes = $user->helpfulVotes()->with('review')->get();