Create 创建项目
(w http.ResponseWriter, r *http.Request)
| 218 | |
| 219 | // Create 创建项目 |
| 220 | func (h *ProjectHandler) Create(w http.ResponseWriter, r *http.Request) { |
| 221 | if r.Method != http.MethodPost { |
| 222 | http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) |
| 223 | return |
| 224 | } |
| 225 | var req struct { |
| 226 | Name string `json:"name"` |
| 227 | } |
| 228 | if err := json.NewDecoder(r.Body).Decode(&req); err != nil || req.Name == "" { |
| 229 | writeJSON(w, http.StatusBadRequest, map[string]string{"error": "name is required"}) |
| 230 | return |
| 231 | } |
| 232 | p, err := h.store.Create(req.Name) |
| 233 | if err != nil { |
| 234 | writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()}) |
| 235 | return |
| 236 | } |
| 237 | writeJSON(w, http.StatusOK, p) |
| 238 | } |
| 239 | |
| 240 | // Get 获取项目详情 |
| 241 | func (h *ProjectHandler) Get(w http.ResponseWriter, r *http.Request) { |