Skip to content

Commit 851fd08

Browse files
author
user
committed
Code review change implemented: The Organization object could be the first parameter of the function.
1 parent 108705c commit 851fd08

File tree

3 files changed

+11
-26
lines changed

3 files changed

+11
-26
lines changed

models/organization/org_times.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type ResultTimesByMembers struct {
3333
}
3434

3535
// GetTimesByRepos fetches data from DB to serve TimesByRepos.
36-
func (org *Organization) GetTimesByRepos(unixfrom, unixto int64) (results []ResultTimesByRepos, err error) {
36+
func GetTimesByRepos(org *Organization, unixfrom, unixto int64) (results []ResultTimesByRepos, err error) {
3737
// Get the data from the DB
3838
err = db.GetEngine(db.DefaultContext).
3939
Select("repository.name, SUM(tracked_time.time) AS sum_time").
@@ -51,7 +51,7 @@ func (org *Organization) GetTimesByRepos(unixfrom, unixto int64) (results []Resu
5151
}
5252

5353
// GetTimesByMilestones gets the actual data from the DB to serve TimesByMilestones.
54-
func (org *Organization) GetTimesByMilestones(unixfrom, unixto int64) (results []ResultTimesByMilestones, err error) {
54+
func GetTimesByMilestones(org *Organization, unixfrom, unixto int64) (results []ResultTimesByMilestones, err error) {
5555
err = db.GetEngine(db.DefaultContext).
5656
Select("repository.name AS repo_name, milestone.name, milestone.id, SUM(tracked_time.time) AS sum_time").
5757
Table("tracked_time").
@@ -70,7 +70,7 @@ func (org *Organization) GetTimesByMilestones(unixfrom, unixto int64) (results [
7070
}
7171

7272
// getTimesByMembers gets the actual data from the DB to serve TimesByMembers.
73-
func (org *Organization) GetTimesByMembers(unixfrom, unixto int64) (results []ResultTimesByMembers, err error) {
73+
func GetTimesByMembers(org *Organization, unixfrom, unixto int64) (results []ResultTimesByMembers, err error) {
7474
err = db.GetEngine(db.DefaultContext).
7575
Select("user.name, SUM(tracked_time.time) AS sum_time").
7676
Table("tracked_time").

models/organization/org_time/org_times_test.go renamed to models/organization/org_times_test.go

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
// license that can be found in the LICENSE file.
44
// SPDX-License-Identifier: MIT
55

6-
package orgtime_test
6+
package organization_test
77

88
import (
9-
"path/filepath"
109
"testing"
1110

1211
"code.gitea.io/gitea/models/db"
@@ -18,21 +17,6 @@ import (
1817
"github.com/stretchr/testify/assert"
1918
)
2019

21-
// TestMain sets up the testing environment specifically for testing org times.
22-
func TestMain(m *testing.M) {
23-
unittest.MainTest(m, &unittest.TestOptions{
24-
GiteaRootPath: filepath.Join("..", "..", ".."),
25-
FixtureFiles: []string{
26-
"user.yml",
27-
"org_user.yml",
28-
"repository.yml",
29-
"issue.yml",
30-
"milestone.yml",
31-
"tracked_time.yml",
32-
},
33-
})
34-
}
35-
3620
// TestTimesPrepareDB prepares the database for the following tests.
3721
func TestTimesPrepareDB(t *testing.T) {
3822
assert.NoError(t, unittest.PrepareTestDatabase())
@@ -113,7 +97,7 @@ func TestTimesByRepos(t *testing.T) {
11397
t.Run(kase.name, func(t *testing.T) {
11498
org, err := organization.GetOrgByID(db.DefaultContext, kase.orgname)
11599
assert.NoError(t, err)
116-
results, err := org.GetTimesByRepos(kase.unixfrom, kase.unixto)
100+
results, err := organization.GetTimesByRepos(org, kase.unixfrom, kase.unixto)
117101
assert.NoError(t, err)
118102
assert.Equal(t, kase.expected, results)
119103
})
@@ -217,7 +201,7 @@ func TestTimesByMilestones(t *testing.T) {
217201
t.Run(kase.name, func(t *testing.T) {
218202
org, err := organization.GetOrgByID(db.DefaultContext, kase.orgname)
219203
assert.NoError(t, err)
220-
results, err := org.GetTimesByMilestones(kase.unixfrom, kase.unixto)
204+
results, err := organization.GetTimesByMilestones(org, kase.unixfrom, kase.unixto)
221205
assert.NoError(t, err)
222206
assert.Equal(t, kase.expected, results)
223207
})
@@ -300,7 +284,7 @@ func TestTimesByMembers(t *testing.T) {
300284
t.Run(kase.name, func(t *testing.T) {
301285
org, err := organization.GetOrgByID(db.DefaultContext, kase.orgname)
302286
assert.NoError(t, err)
303-
results, err := org.GetTimesByMembers(kase.unixfrom, kase.unixto)
287+
results, err := organization.GetTimesByMembers(org, kase.unixfrom, kase.unixto)
304288
assert.NoError(t, err)
305289
assert.Equal(t, kase.expected, results)
306290
})

routers/web/org/times.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"net/http"
1010
"time"
1111

12+
"code.gitea.io/gitea/models/organization"
1213
"code.gitea.io/gitea/modules/base"
1314
"code.gitea.io/gitea/modules/context"
1415
"code.gitea.io/gitea/modules/setting"
@@ -70,7 +71,7 @@ func TimesByRepos(ctx *context.Context) {
7071
// Set submenu tab
7172
ctx.Data["TabIsByRepos"] = true
7273

73-
results, err := ctx.Org.Organization.GetTimesByRepos(unixfrom, unixto)
74+
results, err := organization.GetTimesByRepos(ctx.Org.Organization, unixfrom, unixto)
7475
if err != nil {
7576
ctx.ServerError("getTimesByRepos", err)
7677
return
@@ -97,7 +98,7 @@ func TimesByMilestones(ctx *context.Context) {
9798
ctx.Data["TabIsByMilestones"] = true
9899

99100
// Get the data from the DB
100-
results, err := ctx.Org.Organization.GetTimesByMilestones(unixfrom, unixto)
101+
results, err := organization.GetTimesByMilestones(ctx.Org.Organization, unixfrom, unixto)
101102
if err != nil {
102103
ctx.ServerError("getTimesByMilestones", err)
103104
return
@@ -136,7 +137,7 @@ func TimesByMembers(ctx *context.Context) {
136137
ctx.Data["TabIsByMembers"] = true
137138

138139
// Get the data from the DB
139-
results, err := ctx.Org.Organization.GetTimesByMembers(unixfrom, unixto)
140+
results, err := organization.GetTimesByMembers(ctx.Org.Organization, unixfrom, unixto)
140141
if err != nil {
141142
ctx.ServerError("getTimesByMembers", err)
142143
return

0 commit comments

Comments
 (0)