Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ecrupper committed Feb 27, 2024
1 parent bab8877 commit 34721c7
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 8 deletions.
32 changes: 26 additions & 6 deletions database/build_executable.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ var (
// ErrEmptyBuildExecutableBuildID defines the error type when a
// BuildExecutable type has an empty BuildID field provided.
ErrEmptyBuildExecutableBuildID = errors.New("empty build_executable build_id provided")

// ErrEmptyBuildExecutableRepoID defines the error type when a
// BuildExecutable type has an empty RepoID field provided.
ErrEmptyBuildExecutableRepoID = errors.New("empty build_executable repo_id provided")
)

// BuildExecutable is the database representation of a BuildExecutable.
type BuildExecutable struct {
ID sql.NullInt64 `sql:"id"`
BuildID sql.NullInt64 `sql:"build_id"`
Data []byte `sql:"data"`
ID sql.NullInt64 `sql:"id"`
BuildID sql.NullInt64 `sql:"build_id"`
RepoID sql.NullInt64 `sql:"repo_id"`
CreatedAt sql.NullInt64 `sql:"created_at"`
Data []byte `sql:"data"`
}

// Compress will manipulate the existing data for the
Expand Down Expand Up @@ -126,6 +132,11 @@ func (b *BuildExecutable) Nullify() *BuildExecutable {
b.BuildID.Valid = false
}

// check if the RepoID field should be false
if b.RepoID.Int64 == 0 {
b.RepoID.Valid = false
}

return b
}

Expand All @@ -136,6 +147,8 @@ func (b *BuildExecutable) ToLibrary() *library.BuildExecutable {

buildExecutable.SetID(b.ID.Int64)
buildExecutable.SetBuildID(b.BuildID.Int64)
buildExecutable.SetRepoID(b.RepoID.Int64)
buildExecutable.SetCreatedAt(b.CreatedAt.Int64)
buildExecutable.SetData(b.Data)

return buildExecutable
Expand All @@ -149,16 +162,23 @@ func (b *BuildExecutable) Validate() error {
return ErrEmptyBuildExecutableBuildID
}

// verify the RepoID field is populated
if b.RepoID.Int64 <= 0 {
return ErrEmptyBuildExecutableRepoID
}

return nil
}

// BuildExecutableFromLibrary converts the library BuildExecutable type
// to a database BuildExecutable type.
func BuildExecutableFromLibrary(c *library.BuildExecutable) *BuildExecutable {
buildExecutable := &BuildExecutable{
ID: sql.NullInt64{Int64: c.GetID(), Valid: true},
BuildID: sql.NullInt64{Int64: c.GetBuildID(), Valid: true},
Data: c.GetData(),
ID: sql.NullInt64{Int64: c.GetID(), Valid: true},
BuildID: sql.NullInt64{Int64: c.GetBuildID(), Valid: true},
RepoID: sql.NullInt64{Int64: c.GetRepoID(), Valid: true},
CreatedAt: sql.NullInt64{Int64: c.GetCreatedAt(), Valid: true},
Data: c.GetData(),
}

return buildExecutable.Nullify()
Expand Down
58 changes: 56 additions & 2 deletions library/build_executable.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import (
//
// swagger:model BuildExecutable
type BuildExecutable struct {
ID *int64 `json:"id,omitempty"`
BuildID *int64 `json:"build_id,omitempty"`
ID *int64 `json:"id,omitempty"`
BuildID *int64 `json:"build_id,omitempty"`
RepoID *int64 `json:"repo_id,omitempty"`
CreatedAt *int64 `json:"created_at,omitempty"`
// swagger:strfmt base64
Data *[]byte `json:"data,omitempty"`
}
Expand Down Expand Up @@ -42,6 +44,32 @@ func (b *BuildExecutable) GetBuildID() int64 {
return *b.BuildID
}

// GetRepoID returns the RepoID field.
//
// When the provided BuildExecutable type is nil, or the field within
// the type is nil, it returns the zero value for the field.
func (b *BuildExecutable) GetRepoID() int64 {
// return zero value if BuildExecutable type or RepoID field is nil
if b == nil || b.RepoID == nil {
return 0
}

return *b.RepoID
}

// GetCreatedAt returns the CreatedAt field.
//
// When the provided BuildExecutable type is nil, or the field within
// the type is nil, it returns the zero value for the field.
func (b *BuildExecutable) GetCreatedAt() int64 {
// return zero value if BuildExecutable type or CreatedAt field is nil
if b == nil || b.CreatedAt == nil {
return 0
}

return *b.CreatedAt
}

// GetData returns the Data field.
//
// When the provided BuildExecutable type is nil, or the field within
Expand Down Expand Up @@ -81,6 +109,32 @@ func (b *BuildExecutable) SetBuildID(v int64) {
b.BuildID = &v
}

// SetRepoID sets the RepoID field.
//
// When the provided BuildExecutable type is nil, it
// will set nothing and immediately return.
func (b *BuildExecutable) SetRepoID(v int64) {
// return if BuildExecutable type is nil
if b == nil {
return
}

b.RepoID = &v
}

// SetCreatedAt sets the CreatedAt field.
//
// When the provided BuildExecutable type is nil, it
// will set nothing and immediately return.
func (b *BuildExecutable) SetCreatedAt(v int64) {
// return if BuildExecutable type is nil
if b == nil {
return
}

b.CreatedAt = &v
}

// SetData sets the Data field.
//
// When the provided BuildExecutable type is nil, it
Expand Down

0 comments on commit 34721c7

Please sign in to comment.