You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
3.0 KiB

package models
4 years ago
import (
"time"
"github.com/imdotdev/im.dev/server/pkg/db"
)
4 years ago
const (
StatusDraft = 1
StatusPublished = 2
StatusHidden = 3
StatusForbidden = 4
4 years ago
)
4 years ago
type Story struct {
4 years ago
ID string `json:"id"`
4 years ago
Type string `json:"type"`
4 years ago
Creator *UserSimple `json:"creator"`
4 years ago
CreatorID string `json:"creatorId"`
4 years ago
Owner *UserSimple `json:"owner"`
OwnerID string `json:"ownerId"`
4 years ago
Title string `json:"title"`
Slug string `json:"slug"`
Md string `json:"md"`
URL string `json:"url"`
Cover string `json:"cover"`
Brief string `json:"brief"`
4 years ago
Tags []string `json:"tags"`
4 years ago
RawTags []*Tag `json:"rawTags"`
Likes int `json:"likes"`
Liked bool `json:"liked"`
Pinned bool `json:"pinned,omitempty"`
4 years ago
Comments int `json:"comments"`
Views int `json:"views"`
Bookmarked bool `json:"bookmarked"`
Status int `json:"status"`
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
4 years ago
Priority int `json:"-"`
}
4 years ago
type Stories []*Story
4 years ago
func (s Stories) Len() int { return len(s) }
func (s Stories) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s Stories) Less(i, j int) bool {
return s[i].Created.Unix() > s[j].Created.Unix()
}
4 years ago
4 years ago
type FavorStories []*Story
4 years ago
4 years ago
func (s FavorStories) Len() int { return len(s) }
func (s FavorStories) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s FavorStories) Less(i, j int) bool {
return s[i].Likes > s[j].Likes
4 years ago
}
4 years ago
4 years ago
type PriorityStories []*Story
func (s PriorityStories) Len() int { return len(s) }
func (s PriorityStories) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s PriorityStories) Less(i, j int) bool {
return s[i].Priority < s[j].Priority
}
4 years ago
type SeriesPost struct {
PostID string `json:"id"`
Priority int `json:"priority"`
}
4 years ago
type SeriesPosts []*SeriesPost
func (s SeriesPosts) Len() int { return len(s) }
func (s SeriesPosts) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s SeriesPosts) Less(i, j int) bool {
return s[i].Priority < s[j].Priority
}
4 years ago
func IsStoryCreator(userID string, storyID string) bool {
var nid string
err := db.Conn.QueryRow("SELECT creator FROM story WHERE id=?", storyID).Scan(&nid)
if err != nil {
return false
}
if nid == userID {
return true
}
return false
}
4 years ago
func GetStoryCreated(storyID string) time.Time {
var t time.Time
db.Conn.QueryRow("SELECT created FROM story WHERE id=?", storyID).Scan(&t)
return t
}
4 years ago
func GetStoryCreatorAndOrg(storyID string) (string, string) {
var creator, owner string
if GetIDType(storyID) == IDTypeComment {
db.Conn.QueryRow("SELECT creator FROM comments WHERE id=?", storyID).Scan(&creator)
} else {
db.Conn.QueryRow("SELECT creator,owner FROM story WHERE id=?", storyID).Scan(&creator, &owner)
}
return creator, owner
}
4 years ago
func GetStoryTitle(storyID string) string {
var t string
db.Conn.QueryRow("SELECT title FROM story WHERE id=?", storyID).Scan(&t)
return t
}