See "A motivating example" in issue #290.
It should be possible to make it so that none of the handlers in build.go reference a gorm DB directly, only through a buildRepo.
For example:
|
// Report fetches a build's report. |
|
func (b Build) Report(c *gin.Context) { |
|
buildRepo := models.BuildDataSource(db) |
|
build, err := b.ByID(c) |
|
if err != nil { |
|
return |
|
} |
|
|
|
report, err := buildRepo.GetBuildReport(build) |
|
|
|
if err != nil { |
|
sugar.NotFoundOrError(c, err) |
|
return |
|
} |
|
|
|
sugar.SuccessResponse(c, 200, report) |
|
} |
Line 130 should be moved out to the main entry point, and b.ByID(c) should be broken up into
- a thing which figures out the
BuildID for the request, and
- a
buildRepo.ByID(id) call which returns the build ID.
This issue is fixed when handlers/api/build.go no longer refers to the db global variable.
See "A motivating example" in issue #290.
It should be possible to make it so that none of the handlers in build.go reference a gorm DB directly, only through a
buildRepo.For example:
platform/handlers/api/build.go
Lines 128 to 144 in ffb20d4
Line 130 should be moved out to the main entry point, and
b.ByID(c)should be broken up intoBuildIDfor the request, andbuildRepo.ByID(id)call which returns the build ID.This issue is fixed when
handlers/api/build.gono longer refers to thedbglobal variable.