Added characters and relations editing

This commit is contained in:
2018-03-09 15:09:27 +01:00
parent cb9e277718
commit e0dc3f2f93
3 changed files with 69 additions and 22 deletions

View File

@ -5,17 +5,18 @@ import (
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/utils"
"github.com/animenotifier/notify.moe/utils/editform"
)
// Get anime edit page.
func Get(ctx *aero.Context) string {
// Main anime edit page.
func Main(ctx *aero.Context) string {
id := ctx.Get("id")
user := utils.GetUser(ctx)
if user == nil || (user.Role != "editor" && user.Role != "admin") {
return ctx.Error(http.StatusBadRequest, "Not logged in or not auhorized to edit this anime", nil)
return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit this anime", nil)
}
anime, err := arn.GetAnime(id)
@ -24,5 +25,53 @@ func Get(ctx *aero.Context) string {
return ctx.Error(http.StatusNotFound, "Anime not found", err)
}
return ctx.HTML(editform.Render(anime, "Edit anime", user))
return ctx.HTML(components.EditAnimeTabs(anime) + editform.Render(anime, "Edit anime", user))
}
// Characters anime characters edit page.
func Characters(ctx *aero.Context) string {
id := ctx.Get("id")
user := utils.GetUser(ctx)
if user == nil || (user.Role != "editor" && user.Role != "admin") {
return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit", nil)
}
anime, err := arn.GetAnime(id)
if err != nil {
return ctx.Error(http.StatusNotFound, "Anime not found", err)
}
animeCharacters, err := arn.GetAnimeCharacters(id)
if err != nil {
return ctx.Error(http.StatusNotFound, "Anime characters not found", err)
}
return ctx.HTML(components.EditAnimeTabs(anime) + editform.Render(animeCharacters, "Edit anime characters", user))
}
// Relations anime relations edit page.
func Relations(ctx *aero.Context) string {
id := ctx.Get("id")
user := utils.GetUser(ctx)
if user == nil || (user.Role != "editor" && user.Role != "admin") {
return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit", nil)
}
anime, err := arn.GetAnime(id)
if err != nil {
return ctx.Error(http.StatusNotFound, "Anime not found", err)
}
animeRelations, err := arn.GetAnimeRelations(id)
if err != nil {
return ctx.Error(http.StatusNotFound, "Anime relations not found", err)
}
return ctx.HTML(components.EditAnimeTabs(anime) + editform.Render(animeRelations, "Edit anime relations", user))
}