Files
MyClub/DOCS/CLOTHING_SYSTEM_IMPLEMENTATION.md
T
Tomáš Dvořák 12cba639b9 upload
2025-10-16 13:32:05 +02:00

107 lines
3.5 KiB
Markdown

# Clothing System Implementation
## Summary
A comprehensive clothing/merchandise system has been implemented with the following features:
### Features
1. **Database & Backend**
- New `clothing` table with fields: title, description, price, currency, image_url, url, is_active, display_order
- Full CRUD API endpoints (public & admin)
- Soft delete support
2. **Admin Management** (`/admin/obleceni`)
- Create, update, delete clothing items
- Fields:
- **Title** (required)
- **Description** (optional)
- **Price** (optional, with currency field)
- **Image URL** (required)
- **Shop URL** (optional)
- **Display Order** (for sorting)
- **Active/Inactive** toggle
- Individual save buttons for each item
- Real-time validation
3. **Public Pages**
- **Homepage** (`/`): Shows 5 newest clothing items in the MerchSection
- **Clothing Page** (`/obleceni`): Shows all active items in a grid layout
- Displays price badges when available
- Links to e-shop URLs (external links)
- "View All" button on homepage to navigate to full clothing page
4. **Design**
- Responsive grid layout
- Price badges for items with pricing
- Image placeholders for missing images
- Hover effects and smooth transitions
- External link indicators
## Files Created
### Backend
- `database/migrations/20251012000001_create_clothing_table.up.sql`
- `database/migrations/20251012000001_create_clothing_table.down.sql`
- `internal/models/clothing.go`
- `internal/controllers/clothing_controller.go`
### Frontend
- `frontend/src/services/clothing.ts`
- `frontend/src/pages/ClothingPage.tsx`
### Modified Files
- `internal/routes/routes.go` - Added clothing routes
- `main.go` - Added Clothing model to AutoMigrate
- `frontend/src/App.tsx` - Added /obleceni route
- `frontend/src/pages/admin/AdminMerchPage.tsx` - Complete rewrite with price field and proper CRUD
- `frontend/src/components/home/MerchSection.tsx` - Updated to fetch from API and show 5 newest items
## API Endpoints
### Public
- `GET /api/v1/clothing` - Get all active clothing items
### Admin (requires authentication)
- `GET /api/v1/admin/clothing` - Get all clothing items (including inactive)
- `GET /api/v1/admin/clothing/:id` - Get single clothing item
- `POST /api/v1/admin/clothing` - Create new clothing item
- `PUT /api/v1/admin/clothing/:id` - Update clothing item
- `DELETE /api/v1/admin/clothing/:id` - Delete clothing item (soft delete)
- `POST /api/v1/admin/clothing/reorder` - Update display order
## Database Schema
```sql
CREATE TABLE clothing (
id SERIAL PRIMARY KEY,
title VARCHAR(255) NOT NULL,
description TEXT,
price DECIMAL(10, 2),
currency VARCHAR(10) DEFAULT '',
image_url VARCHAR(500),
url VARCHAR(500),
is_active BOOLEAN DEFAULT true,
display_order INT DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
deleted_at TIMESTAMP
);
```
## Usage
1. **Add Items**: Navigate to `/admin/obleceni` and click "Přidat položku"
2. **Fill Details**: Add title, image URL, price (optional), and shop link
3. **Save**: Click the "Uložit" button for each item
4. **View Public**: Items appear on homepage (5 newest) and `/obleceni` (all items)
## Next Steps (Optional Enhancements)
- Add image upload functionality instead of URL-only
- Add categories/tags for clothing items
- Add size/color variants
- Add stock tracking
- Add multi-image support for each item
- Add sorting options on public page (price, newest, etc.)