Skip to content

Commit dcbab6a

Browse files
refactored context as a parameter (#356)
1 parent 9050f8a commit dcbab6a

File tree

5 files changed

+15
-12
lines changed

5 files changed

+15
-12
lines changed

backend/database/repositories/main.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,23 @@ var context contexts.DatabaseContext = nil
1515
// Open constructors available for everyone
1616

1717
// NewFilesystemRepo instantiates a new file system repository with the current embedded context
18-
func NewFilesystemRepo() FilesystemRepository {
18+
func NewFilesystemRepo(context contexts.DatabaseContext) FilesystemRepository {
1919
return filesystemRepository{
20-
embeddedContext{getContext()},
20+
embeddedContext{context},
2121
}
2222
}
2323

2424
// NewGroupsRepo instantiates a new groups repository
25-
func NewGroupsRepo() GroupsRepository {
25+
func NewGroupsRepo(context contexts.DatabaseContext) GroupsRepository {
2626
return groupsRepository{
27-
embeddedContext{getContext()},
27+
embeddedContext{context},
2828
}
2929
}
3030

3131
// NewFrontendsRepo instantiates a new frontends repository
32-
func NewFrontendsRepo() FrontendsRepository {
32+
func NewFrontendsRepo(context contexts.DatabaseContext) FrontendsRepository {
3333
return frontendsRepository{
34-
embeddedContext{getContext()},
34+
embeddedContext{context},
3535
}
3636
}
3737

backend/database/repositories/tests/filesystem_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
)
1616

1717
var (
18-
repo = repositories.NewFilesystemRepo()
18+
repo = repositories.NewFilesystemRepo(contexts.GetDatabaseContext())
1919
testContext = repo.GetContext().(*contexts.TestingContext)
2020
)
2121

backend/editor/diffSync/document/manager.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"sync"
66

7+
"cms.csesoc.unsw.edu.au/database/contexts"
78
"cms.csesoc.unsw.edu.au/database/repositories"
89
"cms.csesoc.unsw.edu.au/internal/storage"
910
"github.com/google/uuid"
@@ -21,7 +22,7 @@ type Manager struct {
2122
var (
2223
managerInstance *Manager
2324
lock = &sync.Mutex{}
24-
repo = repositories.NewFilesystemRepo()
25+
repo = repositories.NewFilesystemRepo(contexts.GetDatabaseContext())
2526
)
2627

2728
// implementation of the singleton pattern :)

backend/endpoints/dependency_factory.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package endpoints
33
//go:generate mockgen -source=dependency_factory.go -destination=mocks/dependency_factory_mock.go -package=mocks
44

55
import (
6+
"cms.csesoc.unsw.edu.au/database/contexts"
67
repos "cms.csesoc.unsw.edu.au/database/repositories"
78
"cms.csesoc.unsw.edu.au/internal/logger"
89
)
@@ -31,17 +32,17 @@ type (
3132

3233
// GetFilesystemRepo is the constructor for FS repos
3334
func (dp DependencyProvider) GetFilesystemRepo() repos.FilesystemRepository {
34-
return repos.NewFilesystemRepo()
35+
return repos.NewFilesystemRepo(contexts.GetDatabaseContext())
3536
}
3637

3738
// GetGroupsRepo instantiates a new groups repository
3839
func (dp DependencyProvider) GetGroupsRepo() repos.GroupsRepository {
39-
return repos.NewGroupsRepo()
40+
return repos.NewGroupsRepo(contexts.GetDatabaseContext())
4041
}
4142

4243
// GetFrontendsRepo instantiates a new frontend repository
4344
func (dp DependencyProvider) GetFrontendsRepo() repos.FrontendsRepository {
44-
return repos.NewFrontendsRepo()
45+
return repos.NewFrontendsRepo(contexts.GetDatabaseContext())
4546
}
4647

4748
// GetPersonsRepo instantiates a new person repository

backend/endpoints/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"net/http"
77

8+
"cms.csesoc.unsw.edu.au/database/contexts"
89
"cms.csesoc.unsw.edu.au/database/repositories"
910
"cms.csesoc.unsw.edu.au/internal/logger"
1011
"cms.csesoc.unsw.edu.au/internal/session"
@@ -123,7 +124,7 @@ func (fn rawHandler[T, V]) ServeHTTP(w http.ResponseWriter, r *http.Request) {
123124

124125
// getFrontendID gets the frontend id for an incoming http request
125126
func getFrontendId(r *http.Request) int {
126-
frontendRepo := repositories.NewFrontendsRepo()
127+
frontendRepo := repositories.NewFrontendsRepo(contexts.GetDatabaseContext())
127128
return frontendRepo.GetFrontendFromURL(r.URL.Host)
128129
}
129130

0 commit comments

Comments
 (0)