package com.bomaos.designer.controller;

import com.bomaos.designer.model.DesignerWork;
import com.bomaos.designer.service.DesignerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; // ✅ 正确导入
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/designer")
public class DesignerController {

    @Autowired
    private DesignerService designerService;

    @GetMapping("/upload")
    public String uploadPage() {
        return "designer/upload";
    }

    @PostMapping("/upload")
    public String handleUpload(@ModelAttribute DesignerWork work) {
        designerService.uploadDesign(work);
        return "redirect:/designer/list?id=" + work.getDesignerId(); // 可跳转回对应设计师的页面
    }

    @GetMapping("/list")
    public String listPage(Model model, @RequestParam("id") Integer designerId) {
        List<DesignerWork> works = designerService.getDesignsByDesigner(designerId);
        model.addAttribute("works", works);
        return "designer/index";
    }

    @GetMapping("/chart")
    public String chartPage() {
        return "designer/chart";
    }
}
