127 lines
3.0 KiB
Go
Raw Normal View History

package search
import (
2017-11-11 15:16:25 +00:00
"strings"
"github.com/animenotifier/notify.moe/utils"
"github.com/aerogo/aero"
"github.com/animenotifier/arn/search"
2017-06-20 20:54:45 +00:00
"github.com/animenotifier/notify.moe/components"
)
2018-03-17 21:09:17 +00:00
const (
maxUsers = 25
maxAnime = 25
maxPosts = 2
maxThreads = 2
maxSoundTracks = 3
2018-11-12 07:52:07 +00:00
maxAMVs = 3
2018-03-17 21:09:17 +00:00
maxCharacters = 22
maxCompanies = 3
)
2017-06-20 20:54:45 +00:00
2017-06-16 23:25:02 +00:00
// Get search page.
func Get(ctx *aero.Context) string {
2017-11-11 15:16:25 +00:00
term := ctx.Get("term")
term = strings.TrimPrefix(term, "/")
user := utils.GetUser(ctx)
2017-06-20 20:54:45 +00:00
2018-11-12 07:52:07 +00:00
users, animes, posts, threads, tracks, characters, amvs, companies := search.All(
2018-03-17 21:09:17 +00:00
term,
maxUsers,
maxAnime,
maxPosts,
maxThreads,
maxSoundTracks,
maxCharacters,
2018-11-12 07:52:07 +00:00
maxAMVs,
2018-03-17 21:09:17 +00:00
maxCompanies,
)
2018-11-12 07:52:07 +00:00
return ctx.HTML(components.SearchResults(term, users, animes, posts, threads, tracks, characters, amvs, companies, nil, user))
}
2018-03-17 19:41:18 +00:00
// GetEmptySearch renders the search page with no contents.
func GetEmptySearch(ctx *aero.Context) string {
2018-11-12 07:52:07 +00:00
return ctx.HTML(components.SearchResults("", nil, nil, nil, nil, nil, nil, nil, nil, nil, utils.GetUser(ctx)))
2018-03-17 19:41:18 +00:00
}
// Anime search.
func Anime(ctx *aero.Context) string {
term := ctx.Get("term")
term = strings.TrimPrefix(term, "/")
2018-04-23 08:30:25 +00:00
user := utils.GetUser(ctx)
2018-03-17 19:41:18 +00:00
animes := search.Anime(term, maxAnime)
2018-04-23 08:30:25 +00:00
return ctx.HTML(components.AnimeSearchResults(animes, user))
2018-03-17 19:41:18 +00:00
}
// Characters search.
func Characters(ctx *aero.Context) string {
term := ctx.Get("term")
term = strings.TrimPrefix(term, "/")
user := utils.GetUser(ctx)
2018-03-17 19:41:18 +00:00
characters := search.Characters(term, maxCharacters)
return ctx.HTML(components.CharacterSearchResults(characters, user))
2018-03-17 19:41:18 +00:00
}
2018-12-06 04:27:01 +00:00
// Posts search.
func Posts(ctx *aero.Context) string {
2018-03-17 19:41:18 +00:00
term := ctx.Get("term")
term = strings.TrimPrefix(term, "/")
2018-10-28 23:12:34 +00:00
user := utils.GetUser(ctx)
2018-12-06 04:27:01 +00:00
posts := search.Posts(term, maxPosts)
2018-03-17 19:41:18 +00:00
2018-12-06 04:27:01 +00:00
return ctx.HTML(components.PostsSearchResults(posts, user))
}
2018-03-17 19:41:18 +00:00
2018-12-06 04:27:01 +00:00
// Threads search.
func Threads(ctx *aero.Context) string {
term := ctx.Get("term")
term = strings.TrimPrefix(term, "/")
user := utils.GetUser(ctx)
threads := search.Threads(term, maxThreads)
2018-03-17 19:41:18 +00:00
2018-12-06 04:27:01 +00:00
return ctx.HTML(components.ThreadsSearchResults(threads, user))
2018-03-17 19:41:18 +00:00
}
// SoundTracks search.
func SoundTracks(ctx *aero.Context) string {
term := ctx.Get("term")
term = strings.TrimPrefix(term, "/")
2018-10-29 02:30:23 +00:00
user := utils.GetUser(ctx)
2018-03-17 19:41:18 +00:00
tracks := search.SoundTracks(term, maxSoundTracks)
2018-10-29 02:30:23 +00:00
return ctx.HTML(components.SoundTrackSearchResults(tracks, user))
2018-03-17 19:41:18 +00:00
}
2018-11-12 07:52:07 +00:00
// AMVs search.
func AMVs(ctx *aero.Context) string {
term := ctx.Get("term")
term = strings.TrimPrefix(term, "/")
user := utils.GetUser(ctx)
amvs := search.AMVs(term, maxAMVs)
return ctx.HTML(components.AMVSearchResults(amvs, user))
}
2018-03-17 19:41:18 +00:00
// Users search.
func Users(ctx *aero.Context) string {
term := ctx.Get("term")
term = strings.TrimPrefix(term, "/")
users := search.Users(term, maxUsers)
2018-03-17 19:41:18 +00:00
return ctx.HTML(components.UserSearchResults(users))
}
2018-03-17 21:09:17 +00:00
// Companies search.
func Companies(ctx *aero.Context) string {
term := ctx.Get("term")
term = strings.TrimPrefix(term, "/")
companies := search.Companies(term, maxCompanies)
2018-03-17 21:09:17 +00:00
return ctx.HTML(components.CompanySearchResults(companies))
}