@@ -10,15 +10,13 @@ import (
1010 "code.gitea.io/gitea/modules/timeutil"
1111)
1212
13- // StarList ...
1413type StarList struct {
1514 ID int64 `xorm:"pk autoincr"`
1615 UID int64 `xorm:"INDEX"`
1716 Name string
1817 Desc string
1918
20- StarIDs []int64 `xorm:"-"`
21- Repos []Repository `xorm:"-"`
19+ Repos []Repository `xorm:"-"`
2220
2321 CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
2422 UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
@@ -28,40 +26,33 @@ func init() {
2826 db .RegisterModel (new (StarList ))
2927}
3028
31- func (list * StarList ) GetCount () int64 {
32- var star Star
33- count , err := db .GetEngine (context .Background ()).Where ("star_list_id = ?" , list .ID ).Count (star )
34- if err != nil {
35- return 0
36- }
37- return count
29+ func InsertStarList (ctx context.Context , starList * StarList ) error {
30+ _ , err := db .GetEngine (ctx ).Insert (starList )
31+ return err
3832}
3933
40- func (list * StarList ) LoadStars () {
41- var star []Star
42- err := db .GetEngine (context .Background ()).Where ("star_list_id = ?" , list .ID ).Find (& star )
43- if err != nil {
44- return
45- }
46- for _ , star := range star {
47- list .StarIDs = append (list .StarIDs , star .ID )
48- }
34+ func UpdateStarList (ctx context.Context , starList * StarList ) error {
35+ _ , err := db .GetEngine (ctx ).Where ("id = ?" , starList .ID ).AllCols ().Update (starList )
36+ return err
4937}
5038
51- func GetStarListByUID (ctx context.Context , uid int64 ) ([]* StarList , error ) {
52- var list []* StarList
53- err := db .GetEngine (ctx ).Where ("uid = ?" , uid ).Find (& list )
54- if err != nil {
55- return nil , err
56- }
57- return list , nil
39+ func DeleteStarListByID (ctx context.Context , id int64 ) error {
40+ _ , err := db .GetEngine (ctx ).Delete (& StarList {ID : id })
41+ return err
5842}
5943
60- func GetReposByStarListID (ctx context.Context , starListID int64 ) ([]* Repository , error ) {
61- repos := make ([]* Repository , 0 , 100 )
62- err := db .GetEngine (ctx ).Where ("star_list_id = ?" , starListID ).Find (& repos )
63- if err != nil {
44+ func GetStarListByID (ctx context.Context , id int64 ) (* StarList , error ) {
45+ starList := new (StarList )
46+ if has , err := db .GetEngine (ctx ).Where ("id = ?" , id ).Get (starList ); err != nil {
6447 return nil , err
48+ } else if ! has {
49+ return nil , nil
6550 }
66- return repos , nil
51+ return starList , nil
52+ }
53+
54+ func GetStarListsForUser (ctx context.Context , id int64 ) ([]* StarList , error ) {
55+ starLists := make ([]* StarList , 0 , 10 )
56+ err := db .GetEngine (ctx ).Where ("uid = ?" , id ).Find (& starLists )
57+ return starLists , err
6758}
0 commit comments