Design a likes table: CREATE TABLE likes (
like_id SERIAL PRIMARY KEY,
user_id INT REFERENCES users(user_id),
brand_id INT REFERENCES brands(brand_id),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
UNIQUE (user_id, brand_id) -- Ensures a user can only like a brand once
);
API ENDPOINTS:
Like a brand
Unlike a brand
Get the count of likes for a brand
Get the brands liked by a user
Frontend Implementation:
Like Button: A button or icon on the brand page to like/unlike the brand.
Display Like Count: Show the number of likes a brand has received.
User's Liked Brands: A section in the user's profile to display the brands they have liked.
Design a likes table: CREATE TABLE likes ( like_id SERIAL PRIMARY KEY, user_id INT REFERENCES users(user_id), brand_id INT REFERENCES brands(brand_id), created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, UNIQUE (user_id, brand_id) -- Ensures a user can only like a brand once );
API ENDPOINTS: Like a brand Unlike a brand Get the count of likes for a brand Get the brands liked by a user
Frontend Implementation: Like Button: A button or icon on the brand page to like/unlike the brand. Display Like Count: Show the number of likes a brand has received. User's Liked Brands: A section in the user's profile to display the brands they have liked.