120 lines
3.2 KiB
Go
Raw Normal View History

2017-06-28 15:55:08 +00:00
package editanime
import (
"net/http"
"github.com/aerogo/aero"
2019-06-03 09:32:43 +00:00
"github.com/animenotifier/notify.moe/arn"
2018-03-09 14:09:27 +00:00
"github.com/animenotifier/notify.moe/components"
2017-11-27 18:57:58 +00:00
"github.com/animenotifier/notify.moe/utils/editform"
2017-06-28 15:55:08 +00:00
)
2018-03-09 14:09:27 +00:00
// Main anime edit page.
2019-06-01 04:55:49 +00:00
func Main(ctx aero.Context) error {
2017-06-28 15:55:08 +00:00
id := ctx.Get("id")
2019-11-17 07:59:34 +00:00
user := arn.GetUserFromContext(ctx)
2017-06-28 15:55:08 +00:00
if user == nil || (user.Role != "editor" && user.Role != "admin") {
2018-07-07 03:42:00 +00:00
return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit this anime")
2017-06-28 15:55:08 +00:00
}
anime, err := arn.GetAnime(id)
if err != nil {
return ctx.Error(http.StatusNotFound, "Anime not found", err)
}
2018-03-09 14:09:27 +00:00
return ctx.HTML(components.EditAnimeTabs(anime) + editform.Render(anime, "Edit anime", user))
}
2018-03-16 21:40:38 +00:00
// Images anime images edit page.
2019-06-01 04:55:49 +00:00
func Images(ctx aero.Context) error {
2018-03-16 21:40:38 +00:00
id := ctx.Get("id")
2019-11-17 07:59:34 +00:00
user := arn.GetUserFromContext(ctx)
2018-03-16 21:40:38 +00:00
if user == nil || (user.Role != "editor" && user.Role != "admin") {
2018-07-07 03:42:00 +00:00
return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit this anime")
2018-03-16 21:40:38 +00:00
}
anime, err := arn.GetAnime(id)
if err != nil {
return ctx.Error(http.StatusNotFound, "Anime not found", err)
}
return ctx.HTML(components.EditAnimeImages(anime))
}
2018-03-09 14:09:27 +00:00
// Characters anime characters edit page.
2019-06-01 04:55:49 +00:00
func Characters(ctx aero.Context) error {
2018-03-09 14:09:27 +00:00
id := ctx.Get("id")
2019-11-17 07:59:34 +00:00
user := arn.GetUserFromContext(ctx)
2018-03-09 14:09:27 +00:00
if user == nil || (user.Role != "editor" && user.Role != "admin") {
2018-07-07 03:42:00 +00:00
return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit")
2018-03-09 14:09:27 +00:00
}
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.
2019-06-01 04:55:49 +00:00
func Relations(ctx aero.Context) error {
2018-03-09 14:09:27 +00:00
id := ctx.Get("id")
2019-11-17 07:59:34 +00:00
user := arn.GetUserFromContext(ctx)
2018-03-09 14:09:27 +00:00
if user == nil || (user.Role != "editor" && user.Role != "admin") {
2018-07-07 03:42:00 +00:00
return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit")
2018-03-09 14:09:27 +00:00
}
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))
2017-06-28 15:55:08 +00:00
}
2018-03-09 15:27:40 +00:00
// Episodes anime episodes edit page.
2019-06-01 04:55:49 +00:00
func Episodes(ctx aero.Context) error {
2018-03-09 15:27:40 +00:00
id := ctx.Get("id")
2019-11-17 07:59:34 +00:00
user := arn.GetUserFromContext(ctx)
2018-03-09 15:27:40 +00:00
if user == nil || (user.Role != "editor" && user.Role != "admin") {
2018-07-07 03:42:00 +00:00
return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit")
2018-03-09 15:27:40 +00:00
}
anime, err := arn.GetAnime(id)
if err != nil {
return ctx.Error(http.StatusNotFound, "Anime not found", err)
}
2019-08-28 08:06:42 +00:00
// episodes := anime.Episodes()
2018-03-09 15:27:40 +00:00
2019-08-28 08:06:42 +00:00
// if err != nil {
// return ctx.Error(http.StatusNotFound, "Anime episodes not found", err)
// }
2018-03-09 15:27:40 +00:00
2019-08-28 08:06:42 +00:00
// editform.Render(episodes, "Edit anime episodes", user)
return ctx.HTML(components.EditAnimeTabs(anime) + "<p class='no-data mountable'>Temporarily disabled.</p>")
2018-03-09 15:27:40 +00:00
}