@@ -49,22 +49,67 @@ func init() {
49
49
db .RegisterModel (new (TeamUnit ))
50
50
}
51
51
52
- // SearchTeamOptions holds the search options
53
- type SearchTeamOptions struct {
52
+ // SearchOrgTeamOptions holds the search options
53
+ type SearchOrgTeamOptions struct {
54
54
db.ListOptions
55
- UserID int64
56
55
Keyword string
57
56
OrgID int64
58
57
IncludeDesc bool
59
58
}
60
59
60
+ // GetUserTeamOptions holds the search options.
61
+ type GetUserTeamOptions struct {
62
+ db.ListOptions
63
+ UserID int64
64
+ }
65
+
61
66
// SearchMembersOptions holds the search options
62
67
type SearchMembersOptions struct {
63
68
db.ListOptions
64
69
}
65
70
66
- // SearchTeam search for teams. Caller is responsible to check permissions.
67
- func SearchTeam (opts * SearchTeamOptions ) ([]* Team , int64 , error ) {
71
+ // GetUserTeams search for org teams. Caller is responsible to check permissions.
72
+ func GetUserTeams (opts * GetUserTeamOptions ) ([]* Team , int64 , error ) {
73
+ if opts .Page <= 0 {
74
+ opts .Page = 1
75
+ }
76
+ if opts .PageSize == 0 {
77
+ // Default limit
78
+ opts .PageSize = 10
79
+ }
80
+
81
+ sess := db .GetEngine (db .DefaultContext )
82
+
83
+ sess = sess .Join ("INNER" , "team_user" , "team_user.team_id = team.id" ).
84
+ And ("team_user.uid=?" , opts .UserID )
85
+
86
+ count , err := sess .
87
+ Count (new (Team ))
88
+ if err != nil {
89
+ return nil , 0 , err
90
+ }
91
+
92
+ if opts .PageSize == - 1 {
93
+ opts .PageSize = int (count )
94
+ } else {
95
+ sess = sess .Limit (opts .PageSize , (opts .Page - 1 )* opts .PageSize )
96
+ }
97
+
98
+ sess = sess .Join ("INNER" , "team_user" , "team_user.team_id = team.id" ).
99
+ And ("team_user.uid=?" , opts .UserID )
100
+
101
+ teams := make ([]* Team , 0 , opts .PageSize )
102
+ if err = sess .
103
+ OrderBy ("lower_name" ).
104
+ Find (& teams ); err != nil {
105
+ return nil , 0 , err
106
+ }
107
+
108
+ return teams , count , nil
109
+ }
110
+
111
+ // SearchOrgTeams search for org teams. Caller is responsible to check permissions.
112
+ func SearchOrgTeams (opts * SearchOrgTeamOptions ) ([]* Team , int64 , error ) {
68
113
if opts .Page <= 0 {
69
114
opts .Page = 1
70
115
}
@@ -196,7 +241,7 @@ func (t *Team) getRepositories(e db.Engine) error {
196
241
}
197
242
198
243
// GetRepositories returns paginated repositories in team of organization.
199
- func (t * Team ) GetRepositories (opts * SearchTeamOptions ) error {
244
+ func (t * Team ) GetRepositories (opts * SearchOrgTeamOptions ) error {
200
245
if opts .Page == 0 {
201
246
return t .getRepositories (db .GetEngine (db .DefaultContext ))
202
247
}
@@ -716,7 +761,7 @@ func UpdateTeam(t *Team, authChanged, includeAllChanged bool) (err error) {
716
761
// DeleteTeam deletes given team.
717
762
// It's caller's responsibility to assign organization ID.
718
763
func DeleteTeam (t * Team ) error {
719
- if err := t .GetRepositories (& SearchTeamOptions {}); err != nil {
764
+ if err := t .GetRepositories (& SearchOrgTeamOptions {}); err != nil {
720
765
return err
721
766
}
722
767
@@ -858,7 +903,7 @@ func AddTeamMember(team *Team, userID int64) error {
858
903
}
859
904
860
905
// Get team and its repositories.
861
- if err := team .GetRepositories (& SearchTeamOptions {}); err != nil {
906
+ if err := team .GetRepositories (& SearchOrgTeamOptions {}); err != nil {
862
907
return err
863
908
}
864
909
0 commit comments