# Sky Art Shop - Admin CMS Integration Guide ## ✅ What's Been Set Up Your Admin backend (ASP.NET Core + MongoDB) now exposes public read-only APIs for your static website: - **Backend URL**: (or ) - **CORS Enabled**: Static files can call the API from `file://` URLs - **Image Serving**: `/uploads/products/`, `/uploads/projects/`, `/uploads/blog/` ### Available API Endpoints | Endpoint | Description | Example | |----------|-------------|---------| | `GET /api/products` | All products | Returns array of products with images, prices, descriptions | | `GET /api/products/{id}` | Single product | Get one product by ID | | `GET /api/projects` | Portfolio projects | Returns array of projects with images | | `GET /api/projects/{id}` | Single project | Get one project by ID | | `GET /api/blog` | Blog posts | Returns array of posts with featured images | | `GET /api/blog/{id}` | Single post | Get one post by ID | | `GET /api/pages/{slug}` | Page by slug | Get page content (e.g., "about", "contact") | | `GET /api/categories` | Categories | All portfolio categories | | `GET /api/settings` | Site settings | Global site configuration | --- ## 📦 Integration Files Created All integration code has been created in your `Sky_Art_Shop` folder: ``` Sky_Art_Shop/ ├── js/ │ ├── api-integration.js # Core API functions (load this first!) │ ├── shop-page.js # For shop.html │ ├── portfolio-page.js # For portfolio.html │ ├── blog-page.js # For blog.html │ ├── index-page.js # For index.html │ └── about-page.js # For about.html └── css/ └── api-styles.css # Styling for product/project/blog cards ``` --- ## 🔧 How to Integrate Each Page ### 1. **shop.html** (Products Page) Add these lines **before the closing `` tag**: ```html ``` **In your HTML body**, add a container where products will render: ```html

Our Products

Loading products

``` --- ### 2. **portfolio.html** (Projects Page) Add before ``: ```html ``` Add container: ```html

Our Portfolio

Loading projects

``` --- ### 3. **blog.html** (Blog Page) Add before ``: ```html ``` Add container: ```html

Latest Blog Posts

Loading posts

``` --- ### 4. **index.html** (Home Page) Add before ``: ```html ``` Add containers for featured content (optional): ```html

Recent Projects

Latest Posts

``` --- ### 5. **about.html** (About Page) Add before ``: ```html ``` **Option A**: Load dynamic CMS content (if you create an "about" page in admin): ```html

Loading content

``` **Option B**: Keep your static content and just load settings for site name, etc. --- ### 6. **contact.html** (Contact Page) For contact forms, you typically keep static content. Optionally load settings: ```html ``` --- ## 🎨 Customizing the Look The `css/api-styles.css` file contains complete styling for: - Product cards (`.product-card`) - Project cards (`.project-card`) - Blog cards (`.blog-card`) - Grids (`.products-grid`, `.projects-grid`, `.blog-grid`) **To match your existing design:** 1. Open `css/api-styles.css` 2. Adjust colors, fonts, spacing to match your site 3. Or copy the card styles into your existing stylesheet --- ## 🚀 Testing 1. **Start the backend** (if not already running): ```powershell cd "e:\Documents\Website Projects\Sky_Art_Shop\Admin" dotnet run --launch-profile https ``` 2. **Open your static site**: - `file:///E:/Documents/Website%20Projects/Sky_Art_Shop/index.html` - `file:///E:/Documents/Website%20Projects/Sky_Art_Shop/shop.html` - etc. 3. **Check browser console** (F12): - Should see: `"Loaded products: X"`, `"Loaded projects: Y"`, etc. - If you see CORS errors, they should resolve automatically (CORS is enabled) - If API fails, make sure backend is running on 4. **Verify images appear**: - Images should load from `https://localhost:5001/uploads/products/` - Check Network tab to see image requests --- ## 🔄 How It Works When a user visits your static site: 1. Browser loads the HTML page 2. JavaScript calls the Admin backend API (e.g., `/api/products`) 3. API queries MongoDB and returns JSON data 4. JavaScript renders the data into HTML cards with images 5. Images are served from `wwwroot/uploads/` via the backend **When you edit content in Admin:** - Add/edit/delete products, projects, or blog posts - Upload images - Changes appear immediately when users refresh the static pages --- ## 📝 Advanced: Custom Rendering If you want custom HTML for products, edit `js/api-integration.js`: ```javascript // In loadProducts() function, customize the template string: return `
${product.title}

${product.title}

${product.description}

${price}

`; ``` --- ## 🐛 Troubleshooting | Issue | Solution | |-------|----------| | **Images not showing** | 1. Check backend is running
2. Verify files in `Admin/wwwroot/uploads/products/`
3. Open DevTools Network tab, check image URLs
4. Confirm product has `mainImageUrl` in database | | **"Unable to load products"** | 1. Backend not running (start with `dotnet run --launch-profile https`)
2. CORS issue (already fixed)
3. Check console for specific error | | **Products show but no images** | Products in database missing `mainImageUrl`. Edit product in admin and upload image. | | **Blank page** | Check console (F12) for JavaScript errors. Ensure `api-integration.js` loads first. | | **Mixed content warning** | If static site is on `https://` but API is `http://`, change `API_BASE` in `api-integration.js` to `https://localhost:5001` | --- ## 📧 API Response Examples ### Product Response ```json { "id": "123abc", "title": "Sky Painting", "description": "Beautiful artwork...", "price": 299.99, "mainImageUrl": "/uploads/products/abc123.jpg", "images": ["/uploads/products/abc123.jpg", "/uploads/products/xyz456.jpg"], "category": "Paintings" } ``` ### Project Response ```json { "id": "456def", "title": "Mural Project", "shortDescription": "City mural...", "coverImageUrl": "/uploads/projects/mural.jpg", "images": ["/uploads/projects/mural.jpg"], "category": "Murals" } ``` --- ## ✅ Next Steps 1. **Add script tags** to each HTML page as shown above 2. **Add container divs** with the correct IDs 3. **Refresh pages** and check console for "Loaded X items" 4. **Customize styles** in `api-styles.css` to match your design 5. **Test editing** content in Admin and seeing changes on static site **Questions or issues?** Check the console first, then refer to the Troubleshooting section above. --- **That's it!** Your static site is now powered by the Admin CMS. Any content changes you make in the admin will instantly reflect on the static pages when users refresh. 🎉