// // GET /library/episode/:id // func getEpisode(c *echo.Context) error { id, err := strconv.ParseUint(c.Param("id"), 10, 64) if err != nil { return c.NoContent(400) } return c.JSON(200, store.GetEpisode(id)) }
func updateUser(c *echo.Context) error { u := new(user) if err := c.Bind(u); err != nil { return err } id, _ := strconv.Atoi(c.Param("id")) users[id].Name = u.Name return c.JSON(http.StatusOK, users[id]) }
// // DELETE /library/labels/:id // func removeLabel(c *echo.Context) error { id, err := strconv.ParseUint(c.Param("id"), 10, 64) if err != nil { return c.NoContent(400) } user := c.Get("user").(*User) return store.RemoveLabel(id, user.ID) }
// // DELETE /library/casts/:id // func removeCast(c *echo.Context) error { id, err := strconv.ParseUint(c.Param("id"), 10, 64) if err != nil { return c.NoContent(400) } user := c.Get("user").(*User) user, err = store.RemoveSubscription(user.ID, id) authCache.set(c.Get("token").(string), user) return err }
// // DELETE /account/settings/:id // func removeSetting(c *echo.Context) error { id, err := strconv.ParseUint(c.Param("id"), 10, 64) if err != nil { return c.NoContent(400) } user := c.Get("user").(*User) err = store.RemoveSetting(id, user.ID) if err == ErrSettingNotFound { return c.String(404, "Setting not found") } return err }
// // PUT /library/casts/:id // func renameCast(c *echo.Context) error { id, err := strconv.ParseUint(c.Param("id"), 10, 64) if err != nil { return c.NoContent(400) } cast := store.GetCast(id) if cast == nil { return c.String(404, "Cast not found") } prev := cast.Name cast.Name = form(c, "name") if cast.Name != prev { return store.SaveCast(cast) } return nil }
// // PUT /library/labels/:id // func updateLabel(c *echo.Context) error { id, err := strconv.ParseUint(c.Param("id"), 10, 64) if err != nil { return c.NoContent(400) } label := store.GetLabel(id) if label == nil { return c.String(404, "Label not found") } if name := form(c, "name"); name != "" { label.Name = name } if content := form(c, "content"); content != "" { label.Content = content } if expanded := form(c, "expanded"); expanded != "" { label.Expanded = expanded == "true" } user := c.Get("user").(*User) return store.SaveLabel(label, user.ID) }
func deleteUser(c *echo.Context) error { id, _ := strconv.Atoi(c.Param("id")) delete(users, id) return c.NoContent(http.StatusNoContent) }
func getUser(c *echo.Context) error { id, _ := strconv.Atoi(c.Param("id")) return c.JSON(http.StatusOK, users[id]) }