Skip to content

Build API handler should have no dependencies on gorm #291

Description

@pwaller

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions