diff --git a/model/report.go b/model/report.go index 3ada3d45..ae158448 100644 --- a/model/report.go +++ b/model/report.go @@ -5,25 +5,26 @@ package model // INFO User can be null (anonymous reports) // FIXME can't preload field Torrents for model.TorrentReport type TorrentReport struct { - ID uint `gorm:"column:torrent_report_id;primary_key"` - Description string `gorm:"column:type"` - TorrentID uint `gorm:"column:torrent_id"` - UserID uint `gorm:"column:user_id"` - Torrent Torrent `gorm:"AssociationForeignKey:TorrentID;ForeignKey:torrent_id"` - User User `gorm:"AssociationForeignKey:UserID;ForeignKey:ID"` + ID uint `gorm:"column:torrent_report_id;primary_key"` + Description string `gorm:"column:type"` + TorrentID uint `gorm:"column:torrent_id"` + UserID uint `gorm:"column:user_id"` + + Torrent Torrent `gorm:"AssociationForeignKey:TorrentID;ForeignKey:torrent_id"` + User User `gorm:"AssociationForeignKey:UserID;ForeignKey:ID"` } type TorrentReportJson struct { ID uint `json:"id"` Description string `json:"description"` Torrent TorrentJSON `json:"torrent"` - User string + User UserJSON `json:"user"` } /* Model Conversion to Json */ func (report *TorrentReport) ToJson() TorrentReportJson { - json := TorrentReportJson{report.ID, report.Description, report.Torrent.ToJSON(), report.User.Username} + json := TorrentReportJson{report.ID, report.Description, report.Torrent.ToJSON(), report.User.ToJSON()} return json } diff --git a/model/user.go b/model/user.go index 9e5ef066..1e1e3ca7 100644 --- a/model/user.go +++ b/model/user.go @@ -26,6 +26,15 @@ type User struct { Torrents []Torrent `gorm:"ForeignKey:UploaderID"` } +type UserJSON struct { + ID uint `json:"user_id"` + Username string `json:"username"` + Status int `json:"status"` + CreatedAt string `json:"created_at"` + LikingCount int `json:"liking_count"` + LikedCount int `json:"liked_count"` +} + // Returns the total size of memory recursively allocated for this struct func (u User) Size() (s int) { s += 4 + // ints @@ -60,3 +69,15 @@ func (c UserUploadsOld) TableName() string { // TODO: rename this in db return "user_uploads_old" } + +func (u *User) ToJSON() UserJSON { + json := UserJSON{ + ID: u.ID, + Username: u.Username, + Status: u.Status, + CreatedAt: u.CreatedAt.Format(time.RFC3339), + LikingCount: u.LikingCount, + LikedCount: u.LikedCount, + } + return json +} diff --git a/router/modpanel.go b/router/modpanel.go index 01102e5d..d48c5b5c 100644 --- a/router/modpanel.go +++ b/router/modpanel.go @@ -3,7 +3,6 @@ package router import ( - "fmt" "html" "html/template" "net/http" @@ -52,7 +51,6 @@ func IndexModPanel(w http.ResponseWriter, r *http.Request) { comments, _ := commentService.GetAllComments(offset, 0, "", "") torrentReports, _, _ := reportService.GetAllTorrentReports(offset, 0) - fmt.Println(torrentReports) languages.SetTranslationFromRequest(panelIndex, r, "en-us") htv := PanelIndexVbs{torrents, torrentReports, users, comments, NewSearchForm(), currentUser, r.URL} _ = panelIndex.ExecuteTemplate(w, "admin_index.html", htv) @@ -88,7 +86,7 @@ func TorrentsListPanel(w http.ResponseWriter, r *http.Request) { languages.SetTranslationFromRequest(panelTorrentList, r, "en-us") htv := PanelTorrentListVbs{torrents, searchForm, Navigation{int(searchParam.Max), offset, pagenum, "mod_tlist_page"}, currentUser, r.URL} err = panelTorrentList.ExecuteTemplate(w, "admin_index.html", htv) - fmt.Println(err) + log.CheckError(err) } else { http.Error(w, "admins only", http.StatusForbidden) @@ -115,10 +113,10 @@ func TorrentReportListPanel(w http.ResponseWriter, r *http.Request) { torrentReports, nbReports, _ := reportService.GetAllTorrentReports(offset, (pagenum-1)*offset) reportJSON := model.TorrentReportsToJSON(torrentReports) - languages.SetTranslationFromRequest(panelUserList, r, "en-us") + languages.SetTranslationFromRequest(panelTorrentReportList, r, "en-us") htv := PanelTorrentReportListVbs{reportJSON, NewSearchForm(), Navigation{nbReports, offset, pagenum, "mod_trlist_page"}, currentUser, r.URL} err = panelTorrentReportList.ExecuteTemplate(w, "admin_index.html", htv) - fmt.Println(err) + log.CheckError(err) } else { http.Error(w, "admins only", http.StatusForbidden) } @@ -145,7 +143,7 @@ func UsersListPanel(w http.ResponseWriter, r *http.Request) { languages.SetTranslationFromRequest(panelUserList, r, "en-us") htv := PanelUserListVbs{users, NewSearchForm(), Navigation{nbUsers, offset, pagenum, "mod_ulist_page"}, currentUser, r.URL} err = panelUserList.ExecuteTemplate(w, "admin_index.html", htv) - fmt.Println(err) + log.CheckError(err) } else { http.Error(w, "admins only", http.StatusForbidden) } @@ -179,7 +177,7 @@ func CommentsListPanel(w http.ResponseWriter, r *http.Request) { languages.SetTranslationFromRequest(panelCommentList, r, "en-us") htv := PanelCommentListVbs{comments, NewSearchForm(), Navigation{nbComments, offset, pagenum, "mod_clist_page"}, currentUser, r.URL} err = panelCommentList.ExecuteTemplate(w, "admin_index.html", htv) - fmt.Println(err) + log.CheckError(err) } else { http.Error(w, "admins only", http.StatusForbidden) } @@ -193,7 +191,7 @@ func TorrentEditModPanel(w http.ResponseWriter, r *http.Request) { languages.SetTranslationFromRequest(panelTorrentEd, r, "en-us") htv := PanelTorrentEdVbs{torrent, NewSearchForm(), currentUser} err := panelTorrentEd.ExecuteTemplate(w, "admin_index.html", htv) - fmt.Println(err) + log.CheckError(err) } else { http.Error(w, "admins only", http.StatusForbidden) } diff --git a/router/templateVariables.go b/router/templateVariables.go index 1cf201e7..c1907ca6 100644 --- a/router/templateVariables.go +++ b/router/templateVariables.go @@ -153,11 +153,11 @@ type PanelTorrentEdVbs struct { } type PanelTorrentReportListVbs struct { - Torrents []model.TorrentReportJson - Search SearchForm - Navigation Navigation - User *model.User - URL *url.URL // For parsing Url in templates + TorrentReports []model.TorrentReportJson + Search SearchForm + Navigation Navigation + User *model.User + URL *url.URL // For parsing Url in templates } /* diff --git a/templates/admin/torrent_report.html b/templates/admin/torrent_report.html index aa1e7f9e..2ff7c881 100644 --- a/templates/admin/torrent_report.html +++ b/templates/admin/torrent_report.html @@ -1,8 +1,8 @@ {{define "title"}}Torrents Report{{end}} {{define "content"}} - {{ range .Torrents}} - + {{ range .TorrentReports}} + {{end}}
{{ .Torrent.Name }}{{.User.Username}}{{.Description}}Delete
{{.Torrent.Name}}{{.User.Username}}{{.Description}}Delete
{{end}}