Cleanup
Cette révision appartient à :
Parent
7cd7a625fc
révision
48eb6397e4
2 fichiers modifiés avec 10 ajouts et 8 suppressions
|
@ -4,7 +4,6 @@ import (
|
||||||
"github.com/ewhal/nyaa/config"
|
"github.com/ewhal/nyaa/config"
|
||||||
"github.com/ewhal/nyaa/util"
|
"github.com/ewhal/nyaa/util"
|
||||||
|
|
||||||
// "encoding/json"
|
|
||||||
"html"
|
"html"
|
||||||
"html/template"
|
"html/template"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -40,11 +39,7 @@ type Torrents struct {
|
||||||
Comments []Comment `gorm:"ForeignKey:torrent_id"`
|
Comments []Comment `gorm:"ForeignKey:torrent_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We need JSON Object instead because of Magnet URL that is not in the database but generated dynamically
|
/* We need JSON Object instead because of Magnet URL that is not in the database but generated dynamically */
|
||||||
--------------------------------------------------------------------------------------------------------------
|
|
||||||
JSON Models Oject
|
|
||||||
--------------------------------------------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
type ApiResultJson struct {
|
type ApiResultJson struct {
|
||||||
Torrents []TorrentsJson `json:"torrents"`
|
Torrents []TorrentsJson `json:"torrents"`
|
||||||
|
@ -81,7 +76,7 @@ func (t *Torrents) ToJson() TorrentsJson {
|
||||||
commentsJson = append(commentsJson, CommentsJson{Username: c.Username, Content: template.HTML(c.Content), Date: c.Date})
|
commentsJson = append(commentsJson, CommentsJson{Username: c.Username, Content: template.HTML(c.Content), Date: c.Date})
|
||||||
}
|
}
|
||||||
for _, c := range t.Comments {
|
for _, c := range t.Comments {
|
||||||
commentsJson = append(commentsJson, CommentsJson{Username: (*c.User).Username, Content: template.HTML(c.Content), Date: c.CreatedAt})
|
commentsJson = append(commentsJson, CommentsJson{Username: c.User.Username, Content: template.HTML(c.Content), Date: c.CreatedAt})
|
||||||
}
|
}
|
||||||
res := TorrentsJson{
|
res := TorrentsJson{
|
||||||
Id: strconv.FormatUint(uint64(t.Id), 10),
|
Id: strconv.FormatUint(uint64(t.Id), 10),
|
||||||
|
|
|
@ -45,9 +45,16 @@ func GetFeeds() []model.Feed {
|
||||||
func GetTorrentById(id string) (model.Torrents, error) {
|
func GetTorrentById(id string) (model.Torrents, error) {
|
||||||
var torrent model.Torrents
|
var torrent model.Torrents
|
||||||
|
|
||||||
if db.ORM.Where("torrent_id = ?", id).Preload("Comments").Preload("OldComments").Find(&torrent).RecordNotFound() {
|
if db.ORM.Where("torrent_id = ?", id).
|
||||||
|
Preload("Comments").Preload("OldComments").
|
||||||
|
Find(&torrent).RecordNotFound() {
|
||||||
return torrent, errors.New("Article is not found.")
|
return torrent, errors.New("Article is not found.")
|
||||||
}
|
}
|
||||||
|
// .Preload("Comments.User") doesn't work
|
||||||
|
for i := range torrent.Comments {
|
||||||
|
torrent.Comments[i].User = new(model.User)
|
||||||
|
db.ORM.Where("user_id = ?", torrent.Comments[i].UserId).Find(torrent.Comments[i].User)
|
||||||
|
}
|
||||||
|
|
||||||
return torrent, nil
|
return torrent, nil
|
||||||
}
|
}
|
||||||
|
|
Référencer dans un nouveau ticket