Mod Page (WIP)
Cette révision appartient à :
Parent
8f8fce89fc
révision
d4c7138081
4 fichiers modifiés avec 96 ajouts et 0 suppressions
57
router/modpanel.go
Fichier normal
57
router/modpanel.go
Fichier normal
|
@ -0,0 +1,57 @@
|
|||
// hurry mod panel to get it faaaaaaaaaaaast
|
||||
|
||||
package router
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"html/template"
|
||||
|
||||
"github.com/ewhal/nyaa/model"
|
||||
"github.com/ewhal/nyaa/service/user"
|
||||
"github.com/ewhal/nyaa/service/user/permission"
|
||||
// "github.com/ewhal/nyaa/util/languages"
|
||||
// "github.com/ewhal/nyaa/util/modelHelper"
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
var panelCommentList *template.Template
|
||||
func init() {
|
||||
panelCommentList = template.Must(template.New("commentlist").Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "admin_index.html"), filepath.Join(TemplateDir, "admin/commentlist.html")))
|
||||
}
|
||||
|
||||
func IndexModPanel(w http.ResponseWriter, r *http.Request) {}
|
||||
func TorrentsListPanel(w http.ResponseWriter, r *http.Request) {}
|
||||
func UsersListPanel(w http.ResponseWriter, r *http.Request) {}
|
||||
func CommentsListPanel(w http.ResponseWriter, r *http.Request) {
|
||||
page,_ := strconv.Atoi(r.URL.Query().Get("p"))
|
||||
offset := 100
|
||||
|
||||
comments := commentService.GetAllTorrents(page*offset, offset)
|
||||
languages.SetTranslationFromRequest(panelCommentList, r, "en-us")
|
||||
htv := PanelCommentListVbs{comments}
|
||||
err := panelCommentList.ExecuteTemplate(w, "index.html", htv)
|
||||
|
||||
}
|
||||
func TorrentEditModPanel(w http.ResponseWriter, r *http.Request) {
|
||||
// Todo
|
||||
}
|
||||
func CommentDeleteModPanel(w http.ResponseWriter, r *http.Request) {
|
||||
currentUser := GetUser(r)
|
||||
if (HasAdmin(currentUser)) {
|
||||
err := form.NewErrors()
|
||||
_, _ := userService.DeleteComment(id)
|
||||
url, _ := Router.Get("mod_comment_list")
|
||||
http.Redirect(w, r, url.String()+"?deleted", http.StatusSeeOther)
|
||||
}
|
||||
}
|
||||
func TorrentDeleteModPanel(w http.ResponseWriter, r *http.Request) {
|
||||
currentUser := GetUser(r)
|
||||
if (HasAdmin(currentUser)) {
|
||||
err := form.NewErrors()
|
||||
_, _ := torrentService.DeleteTorrent(id)
|
||||
url, _ := Router.Get("mod_torrent_list")
|
||||
http.Redirect(w, r, url.String()+"?deleted", http.StatusSeeOther)
|
||||
}
|
||||
}
|
17
service/comment/comment.go
Fichier normal
17
service/comment/comment.go
Fichier normal
|
@ -0,0 +1,17 @@
|
|||
package commentService
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/ewhal/nyaa/db"
|
||||
"github.com/ewhal/nyaa/model"
|
||||
"github.com/ewhal/nyaa/service/user/permission"
|
||||
"github.com/ewhal/nyaa/util/modelHelper"
|
||||
|
||||
)
|
||||
|
||||
func GetAllComments(limit int, offset int) {
|
||||
var comments []model.Comment
|
||||
db.ORM.Limit(limit).Offset(offset).Preload("Uploader").Find(&comments)
|
||||
return comments
|
||||
}
|
|
@ -176,3 +176,14 @@ func CreateWhereParams(conditions string, params ...string) WhereParams {
|
|||
}
|
||||
return whereParams
|
||||
}
|
||||
|
||||
func DeleteTorrent(id string) {
|
||||
var torrent model.Torrents
|
||||
if db.ORM.First(&torrent, id).RecordNotFound() {
|
||||
return http.StatusNotFound, errors.New("Torrent is not found.")
|
||||
}
|
||||
if db.ORM.Delete(&torrent).Error != nil {
|
||||
return http.StatusInternalServerError, errors.New("Torrent is not deleted.")
|
||||
}
|
||||
return http.StatusOK, nil
|
||||
}
|
|
@ -305,4 +305,15 @@ func RemoveFollow(user *model.User, follower *model.User) {
|
|||
var userFollows = model.UserFollows{UserID: user.Id, FollowerID: follower.Id}
|
||||
db.ORM.Delete(&userFollows)
|
||||
}
|
||||
}
|
||||
|
||||
func DeleteComment(id string) {
|
||||
var comment model.Comment
|
||||
if db.ORM.First(&comment, id).RecordNotFound() {
|
||||
return http.StatusNotFound, errors.New("Comment is not found.")
|
||||
}
|
||||
if db.ORM.Delete(&comment).Error != nil {
|
||||
return http.StatusInternalServerError, errors.New("Comment is not deleted.")
|
||||
}
|
||||
return http.StatusOK, nil
|
||||
}
|
Référencer dans un nouveau ticket