Task #36
openFavorites & View
0%
Description
*Favorite / Unfavorite Ads
Allow users to save ads as favorites for quick access later and remove them when no longer needed.
*Track Ad Views
Record each time an ad is viewed to measure popularity and user engagement.
***Table: favorites
*id-INT (PK)-Unique favorite record ID
*user_id-INT (FK)-User who favorited the ad
*ad_id-INT (FK)-Favorited ad
*created_at-DATETIME-Time when ad was favorited
*Each record represents one user favoriting one ad.
*A unique constraint can be applied on (user_id, ad_id) to avoid duplicates.
*Used to display “My Favorites” section for users.
***Table: ad_views
*id-INT (PK)-Unique view ID
*ad_id-INT (FK)-Ad that was viewed
*viewer_user_id-INT-Viewing user (nullable)
*viewed_at-DATETIME-Time of view
*Each row represents one view of an ad.
*viewer_user_id is NULL for guest users.
*Helps calculate total views, popularity, and trending ads.
***Validations
*A user cannot favorite the same ad more than once.
*Only logged-in users can add or remove favorites.
*Favorite entries should be deleted when an ad is removed.
*Ad views should be counted every time the ad details page is opened.
*Duplicate views from the same user in a short time can be optionally filtered.
*Guest users may be tracked using IP address or session ID (optional).