(r *http.Request)
| 63 | } |
| 64 | |
| 65 | func (m *FishingModule) apiUpdateCatchable(r *http.Request) (int, bool, any) { |
| 66 | idStr := r.PathValue("id") |
| 67 | if idStr == "" { |
| 68 | idStr = r.URL.Query().Get("id") |
| 69 | } |
| 70 | |
| 71 | id, err := strconv.Atoi(idStr) |
| 72 | if err != nil || id < 1 { |
| 73 | return http.StatusBadRequest, false, map[string]string{"error": "valid id is required"} |
| 74 | } |
| 75 | |
| 76 | var body CatchableItem |
| 77 | if err := json.NewDecoder(r.Body).Decode(&body); err != nil { |
| 78 | return http.StatusBadRequest, false, map[string]string{"error": "malformed request body: " + err.Error()} |
| 79 | } |
| 80 | |
| 81 | if body.ChanceToCatch < 1 || body.ChanceToCatch > 100 { |
| 82 | return http.StatusBadRequest, false, map[string]string{"error": "chancetocatch must be between 1 and 100"} |
| 83 | } |
| 84 | |
| 85 | for i, c := range m.cfg.Catchables { |
| 86 | if c.ID == id { |
| 87 | body.ID = id |
| 88 | m.cfg.Catchables[i] = body |
| 89 | if err := m.plug.WriteStruct(configKey, m.cfg); err != nil { |
| 90 | return http.StatusInternalServerError, false, map[string]string{"error": "failed to save: " + err.Error()} |
| 91 | } |
| 92 | return http.StatusOK, true, body |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | return http.StatusNotFound, false, map[string]string{"error": "catchable not found"} |
| 97 | } |
| 98 | |
| 99 | func (m *FishingModule) apiDeleteCatchable(r *http.Request) (int, bool, any) { |
| 100 | idStr := r.PathValue("id") |
nothing calls this directly
no test coverage detected