Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build API handler should have no dependencies on gorm #291

Open
pwaller opened this issue Oct 17, 2018 · 0 comments
Open

Build API handler should have no dependencies on gorm #291

pwaller opened this issue Oct 17, 2018 · 0 comments

Comments

@pwaller
Copy link
Contributor

pwaller commented Oct 17, 2018

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

  1. a thing which figures out the BuildID for the request, and
  2. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant