Albirew/nyaa-pantsu
Albirew
/
nyaa-pantsu
Archivé
1
0
Bifurcation 0

unborked report list

Cette révision appartient à :
ayame-git 2017-05-10 22:09:37 +03:00
Parent 4ada27a3cc
révision 8373bce02f
5 fichiers modifiés avec 43 ajouts et 23 suppressions

Voir le fichier

@ -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
}

Voir le fichier

@ -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
}

Voir le fichier

@ -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)
}

Voir le fichier

@ -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
}
/*

Voir le fichier

@ -1,8 +1,8 @@
{{define "title"}}Torrents Report{{end}}
{{define "content"}}
<table class="table">
{{ range .Torrents}}
<tr><td><a href="{{ genRoute "mod_tedit" }}?id={{.Torrent.ID}}">{{ .Torrent.Name }}</a></td><td>{{.User.Username}}</td><td>{{.Description}}</td><td><a href="{{ genRoute "mod_tdelete" }}?id={{ .Torrent.ID }}">Delete</a></td></tr>
{{ range .TorrentReports}}
<tr><td><a href="{{ genRoute "mod_tedit"}}?id={{.Torrent.ID}}">{{.Torrent.Name}}</a></td><td>{{.User.Username}}</td><td>{{.Description}}</td><td><a href="{{ genRoute "mod_tdelete" }}?id={{ .Torrent.ID }}">Delete</a></td></tr>
{{end}}
</table>
{{end}}