Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

display reports properly

Cette révision appartient à :
Your Name 2017-05-10 07:57:55 +00:00
Parent 07d488ed96
révision a8e3f705fb
6 fichiers modifiés avec 25 ajouts et 20 suppressions

Voir le fichier

@ -47,9 +47,11 @@ type Torrent struct {
// FIXME can't preload field Torrents for model.TorrentReport
type TorrentReport struct {
ID uint `gorm:"column:torrent_report_id;primary_key"`
Description string `gorm:"description"`
Torrent Torrent `gorm:"ForeignKey:Id"`
User User `gorm:"ForeignKey:Id"`
Description string `gorm:"column:type"`
TorrentID uint
UserID uint
Torrent Torrent `gorm:"ForeignKey:TorrentID;AssociationForeignKey:ID"`
User User `gorm:"ForeignKey:UserID;AssociationForeignKey:ID"`
}
/* We need a JSON object instead of a Gorm structure because magnet URLs are
@ -89,14 +91,14 @@ type TorrentJSON struct {
type TorrentReportJson struct {
ID uint `json:"id"`
Description string `json:"description"`
Torrent Torrent `json:"torrent"`
User User `json:"user"`
Torrent TorrentJSON `json:"torrent"`
User string
}
/* Model Conversion to Json */
func (report *TorrentReport) ToJson() TorrentReportJson {
json := TorrentReportJson{report.ID, report.Description, report.Torrent, report.User}
json := TorrentReportJson{report.ID, report.Description, report.Torrent.ToJSON(), report.User.Username}
return json
}

Voir le fichier

@ -49,9 +49,9 @@ func init() {
gzipTorrentDeleteModPanel := handlers.CompressHandler(http.HandlerFunc(TorrentDeleteModPanel))
gzipGetTorrentReportHandler := handlers.CompressHandler(http.HandlerFunc(GetTorrentReportHandler))
gzipTorrentReportCreateHandler := handlers.CompressHandler(http.HandlerFunc(CreateTorrentReportHandler))
gzipTorrentReportDeleteHandler := handlers.CompressHandler(http.HandlerFunc(DeleteTorrentReportHandler))
gzipTorrentDeleteHandler := handlers.CompressHandler(http.HandlerFunc(DeleteTorrentHandler))
//gzipTorrentReportCreateHandler := handlers.CompressHandler(http.HandlerFunc(CreateTorrentReportHandler))
//gzipTorrentReportDeleteHandler := handlers.CompressHandler(http.HandlerFunc(DeleteTorrentReportHandler))
//gzipTorrentDeleteHandler := handlers.CompressHandler(http.HandlerFunc(DeleteTorrentHandler))
Router = mux.NewRouter()
@ -96,10 +96,10 @@ func init() {
Router.PathPrefix("/captcha").Methods("GET").HandlerFunc(captcha.ServeFiles)
Router.Handle("/report/create", gzipTorrentReportCreateHandler).Name("torrent_report_create").Methods("POST")
//Router.Handle("/report/create", gzipTorrentReportCreateHandler).Name("torrent_report_create").Methods("POST")
// TODO Allow only moderators to access /moderation/*
Router.Handle("/moderation/report/delete", gzipTorrentReportDeleteHandler).Name("torrent_report_delete").Methods("POST")
Router.Handle("/moderation/torrent/delete", gzipTorrentDeleteHandler).Name("torrent_delete").Methods("POST")
//Router.Handle("/moderation/report/delete", gzipTorrentReportDeleteHandler).Name("torrent_report_delete").Methods("POST")
//Router.Handle("/moderation/torrent/delete", gzipTorrentDeleteHandler).Name("torrent_delete").Methods("POST")
Router.Handle("/moderation/report", gzipGetTorrentReportHandler ).Name("torrent_report").Methods("GET")
Router.NotFoundHandler = http.HandlerFunc(NotFoundHandler)

Voir le fichier

@ -132,6 +132,10 @@ type PanelTorrentEdVbs struct {
Torrent model.Torrent
}
type ViewTorrentReportsVariables struct {
Torrents []model.TorrentReportJson
}
/*
* Variables used by the upper ones
*/

Voir le fichier

@ -5,10 +5,8 @@ import (
"github.com/ewhal/nyaa/model"
"github.com/ewhal/nyaa/service/moderation"
"github.com/ewhal/nyaa/service/torrent"
"github.com/ewhal/nyaa/util/modelHelper"
)
/*
func SanitizeTorrentReport(torrentReport *model.TorrentReport) {
// TODO unescape html ?
return
@ -47,19 +45,20 @@ func DeleteTorrentReportHandler(w http.ResponseWriter, r *http.Request) {
return
}
}
*/
func GetTorrentReportHandler(w http.ResponseWriter, r *http.Request) {
torrentReports, err := moderationService.GetTorrentReports()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
err = torrentReportTemplate.ExecuteTemplate(w, "torrent_report.html", model.TorrentReportsToJSON(torrentReports))
err = torrentReportTemplate.ExecuteTemplate(w, "torrent_report.html", ViewTorrentReportsVariables{model.TorrentReportsToJSON(torrentReports)})
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
/*
func DeleteTorrentHandler(w http.ResponseWriter, r *http.Request) {
// TODO Figure out how to get torrent report id from form
@ -69,4 +68,4 @@ func DeleteTorrentHandler(w http.ResponseWriter, r *http.Request) {
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
}*/

Voir le fichier

@ -31,7 +31,7 @@ func DeleteTorrentReport(id int) (int, error) {
// TODO Use limit, offset
func GetTorrentReports() ([]model.TorrentReport, error) {
var torrentReports []model.TorrentReport
if db.ORM.Preload("User").Preload("Torrents").Find(&torrentReports).Error != nil {
if db.ORM.Preload("User").Preload("Torrent").Find(&torrentReports).Error != nil {
return nil, errors.New("Problem finding all torrent reports.")
}
return torrentReports, nil

Voir le fichier

@ -1,6 +1,6 @@
<!DOCTYPE html>
<html>
{{ range .TorrentReport }}
{{ range .Torrents}}
{{ .ID }} {{ .Description }} {{ .User }}
{{end}}
</html>