Skip to content

Commit

Permalink
Completes Initial DB Layer (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
gbdubs authored Sep 11, 2023
1 parent a1a6abe commit 7e9e07a
Show file tree
Hide file tree
Showing 42 changed files with 3,076 additions and 145 deletions.
1 change: 1 addition & 0 deletions cmd/server/pactasrv/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ go_library(
"//db",
"//openapi:pacta_generated",
"//pacta",
"@org_uber_go_zap//:zap",
],
)
3 changes: 1 addition & 2 deletions cmd/server/pactasrv/pacta_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

api "github.com/RMI/pacta/openapi/pacta"
"github.com/RMI/pacta/pacta"
"go.uber.org/zap"
)

// Returns a version of the PACTA model by ID
Expand All @@ -31,7 +30,7 @@ func (s *Server) CreatePactaVersion(ctx context.Context, request api.CreatePacta
Digest: request.Body.Digest,
})
if err != nil {
return nil, zap.Error(ctx, "failed to create PACTA version", zap.Error(err))
return nil, fmt.Errorf("failed to create PACTA version: %w", err)
}
return nil, nil
}
Expand Down
199 changes: 199 additions & 0 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,202 @@ func SetBlobFileName(v string) UpdateBlobFn {
return nil
}
}

type UpdatePortfolioFn func(*pacta.Portfolio) error

func SetPortfolioName(value string) UpdatePortfolioFn {
return func(v *pacta.Portfolio) error {
v.Name = value
return nil
}
}

func SetPortfolioDescription(value string) UpdatePortfolioFn {
return func(v *pacta.Portfolio) error {
v.Description = value
return nil
}
}

func SetPortfolioHoldingsDate(value *pacta.HoldingsDate) UpdatePortfolioFn {
return func(v *pacta.Portfolio) error {
v.HoldingsDate = value
return nil
}
}

func SetPortfolioOwner(value pacta.OwnerID) UpdatePortfolioFn {
return func(v *pacta.Portfolio) error {
v.Owner = &pacta.Owner{ID: value}
return nil
}
}

func SetPortfolioAdminDebugEnabled(value bool) UpdatePortfolioFn {
return func(v *pacta.Portfolio) error {
v.AdminDebugEnabled = value
return nil
}
}

func SetPortfolioNumberOfRows(value int) UpdatePortfolioFn {
return func(v *pacta.Portfolio) error {
v.NumberOfRows = value
return nil
}
}

type UpdatePortfolioGroupFn func(*pacta.PortfolioGroup) error

func SetPortfolioGroupName(value string) UpdatePortfolioGroupFn {
return func(v *pacta.PortfolioGroup) error {
v.Name = value
return nil
}
}

func SetPortfolioGroupDescription(value string) UpdatePortfolioGroupFn {
return func(v *pacta.PortfolioGroup) error {
v.Description = value
return nil
}
}

func SetPortfolioGroupOwner(value pacta.OwnerID) UpdatePortfolioGroupFn {
return func(v *pacta.PortfolioGroup) error {
v.Owner = &pacta.Owner{ID: value}
return nil
}
}

type UpdateAnalysisFn func(*pacta.Analysis) error

func SetAnalysisOwner(value pacta.OwnerID) UpdateAnalysisFn {
return func(v *pacta.Analysis) error {
v.Owner = &pacta.Owner{ID: value}
return nil
}
}

func SetAnalysisName(value string) UpdateAnalysisFn {
return func(v *pacta.Analysis) error {
v.Name = value
return nil
}
}

func SetAnalysisDescription(value string) UpdateAnalysisFn {
return func(v *pacta.Analysis) error {
v.Description = value
return nil
}
}

func SetAnalysisRanAt(value time.Time) UpdateAnalysisFn {
return func(v *pacta.Analysis) error {
v.RanAt = value
return nil
}
}

func SetAnalysisCompletedAt(value time.Time) UpdateAnalysisFn {
return func(v *pacta.Analysis) error {
v.CompletedAt = value
return nil
}
}

func SetAnalysisFailureCode(value pacta.FailureCode) UpdateAnalysisFn {
return func(v *pacta.Analysis) error {
v.FailureCode = value
return nil
}
}

func SetAnalysisFailureMessage(value string) UpdateAnalysisFn {
return func(v *pacta.Analysis) error {
v.FailureMessage = value
return nil
}
}

type UpdateAnalysisArtifactFn func(*pacta.AnalysisArtifact) error

func SetAnalysisArtifactAdminDebugEnabled(value bool) UpdateAnalysisArtifactFn {
return func(v *pacta.AnalysisArtifact) error {
v.AdminDebugEnabled = value
return nil
}
}

func SetAnalysisArtifactSharedToPublic(value bool) UpdateAnalysisArtifactFn {
return func(v *pacta.AnalysisArtifact) error {
v.SharedToPublic = value
return nil
}
}

type UpdateIncompleteUploadFn func(*pacta.IncompleteUpload) error

func SetIncompleteUploadOwner(value pacta.OwnerID) UpdateIncompleteUploadFn {
return func(v *pacta.IncompleteUpload) error {
v.Owner = &pacta.Owner{ID: value}
return nil
}
}

func SetIncompleteUploadAdminDebugEnabled(value bool) UpdateIncompleteUploadFn {
return func(v *pacta.IncompleteUpload) error {
v.AdminDebugEnabled = value
return nil
}
}

func SetIncompleteUploadName(value string) UpdateIncompleteUploadFn {
return func(v *pacta.IncompleteUpload) error {
v.Name = value
return nil
}
}

func SetIncompleteUploadDescription(value string) UpdateIncompleteUploadFn {
return func(v *pacta.IncompleteUpload) error {
v.Description = value
return nil
}
}

func SetIncompleteUploadRanAt(value time.Time) UpdateIncompleteUploadFn {
return func(v *pacta.IncompleteUpload) error {
v.RanAt = value
return nil
}
}

func SetIncompleteUploadCompletedAt(value time.Time) UpdateIncompleteUploadFn {
return func(v *pacta.IncompleteUpload) error {
v.CompletedAt = value
return nil
}
}

func SetIncompleteUploadFailureCode(value pacta.FailureCode) UpdateIncompleteUploadFn {
return func(v *pacta.IncompleteUpload) error {
v.FailureCode = value
return nil
}
}

func SetIncompleteUploadFailureMessage(value string) UpdateIncompleteUploadFn {
return func(v *pacta.IncompleteUpload) error {
v.FailureMessage = value
return nil
}
}

func SetIncompleteUploadHoldingsDate(value *pacta.HoldingsDate) UpdateIncompleteUploadFn {
return func(v *pacta.IncompleteUpload) error {
v.HoldingsDate = value
return nil
}
}
16 changes: 16 additions & 0 deletions db/sqldb/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
go_library(
name = "sqldb",
srcs = [
"analysis.go",
"analysis_artifact.go",
"audit_log.go",
"blob.go",
"cursor.go",
"incomplete_upload.go",
"initiative.go",
"initiative_invitation.go",
"initiative_user.go",
"owner.go",
"pacta_version.go",
"portfolio.go",
"portfolio_group.go",
"portfolio_initiative.go",
"snapshot.go",
"sqldb.go",
"user.go",
],
Expand All @@ -32,12 +39,21 @@ go_test(
name = "sqldb_test",
size = "large",
srcs = [
"analysis_artifact_test.go",
"analysis_test.go",
"audit_log_test.go",
"blob_test.go",
"cursor_test.go",
"incomplete_upload_test.go",
"initiative_invitation_test.go",
"initiative_test.go",
"initiative_user_test.go",
"owner_test.go",
"pacta_version_test.go",
"portfolio_group_test.go",
"portfolio_initiative_test.go",
"portfolio_test.go",
"snapshot_test.go",
"sqldb_test.go",
"user_test.go",
],
Expand Down
Loading

0 comments on commit 7e9e07a

Please sign in to comment.