2017-11-18 10:28:53 +00:00
|
|
|
package company
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2018-04-08 07:31:31 +00:00
|
|
|
"sort"
|
2017-11-18 10:28:53 +00:00
|
|
|
|
|
|
|
"github.com/aerogo/aero"
|
2019-06-03 09:32:43 +00:00
|
|
|
"github.com/animenotifier/notify.moe/arn"
|
2019-06-01 04:55:49 +00:00
|
|
|
"github.com/animenotifier/notify.moe/assets"
|
2017-11-18 10:28:53 +00:00
|
|
|
"github.com/animenotifier/notify.moe/components"
|
2019-06-01 04:55:49 +00:00
|
|
|
"github.com/animenotifier/notify.moe/middleware"
|
2017-11-18 10:46:17 +00:00
|
|
|
"github.com/animenotifier/notify.moe/utils"
|
2017-11-18 10:28:53 +00:00
|
|
|
)
|
|
|
|
|
2018-03-13 22:06:16 +00:00
|
|
|
// Get renders a company page.
|
2019-06-01 04:55:49 +00:00
|
|
|
func Get(ctx aero.Context) error {
|
2017-11-18 10:46:17 +00:00
|
|
|
user := utils.GetUser(ctx)
|
2017-11-18 10:28:53 +00:00
|
|
|
id := ctx.Get("id")
|
|
|
|
company, err := arn.GetCompany(id)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return ctx.Error(http.StatusNotFound, "Company not found", err)
|
|
|
|
}
|
|
|
|
|
2018-04-13 10:20:13 +00:00
|
|
|
description := utils.CutLongDescription(company.Description)
|
2018-03-01 23:48:44 +00:00
|
|
|
|
2017-11-29 13:40:37 +00:00
|
|
|
openGraph := &arn.OpenGraph{
|
2017-11-18 23:34:03 +00:00
|
|
|
Tags: map[string]string{
|
2018-03-01 23:48:44 +00:00
|
|
|
"og:title": company.Name.English,
|
2019-06-01 04:55:49 +00:00
|
|
|
"og:url": "https://" + assets.Domain + company.Link(),
|
2018-03-01 23:48:44 +00:00
|
|
|
"og:site_name": "notify.moe",
|
|
|
|
"og:type": "article",
|
2017-11-18 23:34:03 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-04-08 15:30:32 +00:00
|
|
|
// if company.Image != "" {
|
|
|
|
// openGraph.Tags["og:image"] = company.Image
|
|
|
|
// }
|
2017-11-29 13:40:37 +00:00
|
|
|
|
2018-03-01 23:48:44 +00:00
|
|
|
if description != "" {
|
|
|
|
openGraph.Tags["og:description"] = description
|
2017-11-29 13:44:02 +00:00
|
|
|
} else {
|
|
|
|
openGraph.Tags["og:description"] = company.Name.English + " company information."
|
|
|
|
}
|
|
|
|
|
2019-06-01 04:55:49 +00:00
|
|
|
customCtx := ctx.(*middleware.OpenGraphContext)
|
|
|
|
customCtx.OpenGraph = openGraph
|
2018-03-01 23:17:27 +00:00
|
|
|
|
|
|
|
studioAnime, producedAnime, licensedAnime := company.Anime()
|
|
|
|
|
2018-04-08 07:31:31 +00:00
|
|
|
// Find close companies
|
|
|
|
var closeCompanies []*arn.Company
|
|
|
|
distances := map[string]float64{}
|
|
|
|
|
|
|
|
if company.Location.IsValid() {
|
|
|
|
closeCompanies = arn.FilterCompanies(func(closeCompany *arn.Company) bool {
|
|
|
|
if closeCompany.ID == company.ID {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if !closeCompany.Location.IsValid() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
distance := company.Location.Distance(closeCompany.Location)
|
|
|
|
distances[closeCompany.ID] = distance
|
|
|
|
|
|
|
|
return distance <= 1.0
|
|
|
|
})
|
|
|
|
|
|
|
|
sort.Slice(closeCompanies, func(i, j int) bool {
|
|
|
|
return distances[closeCompanies[i].ID] < distances[closeCompanies[j].ID]
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return ctx.HTML(components.CompanyPage(company, studioAnime, producedAnime, licensedAnime, closeCompanies, distances, user))
|
2017-11-18 10:28:53 +00:00
|
|
|
}
|