Skip to content

Commit

Permalink
enhance: adding branch to Schedule data type
Browse files Browse the repository at this point in the history
  • Loading branch information
Claire.Nicholas authored and Claire.Nicholas committed Aug 21, 2023
1 parent 6b577f3 commit 2606daf
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions database/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Schedule struct {
UpdatedAt sql.NullInt64 `sql:"updated_at"`
UpdatedBy sql.NullString `sql:"updated_by"`
ScheduledAt sql.NullInt64 `sql:"scheduled_at"`
Branch sql.NullString `sql:"branch"`
}

// ScheduleFromLibrary converts the library.Schedule type to a database Schedule type.
Expand All @@ -53,6 +54,7 @@ func ScheduleFromLibrary(s *library.Schedule) *Schedule {
UpdatedAt: sql.NullInt64{Int64: s.GetUpdatedAt(), Valid: true},
UpdatedBy: sql.NullString{String: s.GetUpdatedBy(), Valid: true},
ScheduledAt: sql.NullInt64{Int64: s.GetScheduledAt(), Valid: true},
Branch: sql.NullString{String: s.GetBranch(), Valid: true},
}

return schedule.Nullify()
Expand Down Expand Up @@ -87,6 +89,8 @@ func (s *Schedule) Nullify() *Schedule {
s.UpdatedBy.Valid = len(s.UpdatedBy.String) != 0
// check if the ScheduledAt field should be valid
s.ScheduledAt.Valid = s.ScheduledAt.Int64 != 0
// check if the Branch field should be valid
s.Branch.Valid = len(s.Branch.String) != 0

return s
}
Expand All @@ -104,6 +108,7 @@ func (s *Schedule) ToLibrary() *library.Schedule {
UpdatedAt: &s.UpdatedAt.Int64,
UpdatedBy: &s.UpdatedBy.String,
ScheduledAt: &s.ScheduledAt.Int64,
Branch: &s.Branch.String,
}
}

Expand Down
25 changes: 25 additions & 0 deletions library/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Schedule struct {
UpdatedAt *int64 `json:"updated_at,omitempty"`
UpdatedBy *string `json:"updated_by,omitempty"`
ScheduledAt *int64 `json:"scheduled_at,omitempty"`
Branch *string `json:"branch,omitempty"`
}

// GetID returns the ID field from the provided Schedule. If the object is nil,
Expand Down Expand Up @@ -134,6 +135,17 @@ func (s *Schedule) GetScheduledAt() int64 {
return *s.ScheduledAt
}

// GetBranch returns the Branch field from the provided Schedule. If the object is nil,
// or the field within the object is nil, it returns the zero value instead.
func (s *Schedule) GetBranch() string {
// return zero value if Schedule type or ScheduledAt field is nil
if s == nil || s.Branch == nil {
return ""
}

return *s.Branch
}

// SetID sets the ID field in the provided Schedule. If the object is nil,
// it will set nothing and immediately return making this a no-op.
func (s *Schedule) SetID(id int64) {
Expand Down Expand Up @@ -244,6 +256,17 @@ func (s *Schedule) SetScheduledAt(scheduledAt int64) {
s.ScheduledAt = &scheduledAt
}

// SetBranch sets the Branch field in the provided Schedule. If the object is nil,
// it will set nothing and immediately return making this a no-op.
func (s *Schedule) SetBranch(branch string) {
// return if Schedule type is nil
if s == nil {
return
}

s.Branch = &branch
}

// String implements the Stringer interface for the Schedule type.
func (s *Schedule) String() string {
return fmt.Sprintf(`{
Expand All @@ -257,6 +280,7 @@ func (s *Schedule) String() string {
ScheduledAt: %d,
UpdatedAt: %d,
UpdatedBy: %s,
Branch: %s,
}`,
s.GetActive(),
s.GetCreatedAt(),
Expand All @@ -268,5 +292,6 @@ func (s *Schedule) String() string {
s.GetScheduledAt(),
s.GetUpdatedAt(),
s.GetUpdatedBy(),
s.GetBranch(),
)
}

0 comments on commit 2606daf

Please sign in to comment.