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

refactor(db): constructor for row models #423

Open
1 task
MR2011 opened this issue Dec 12, 2024 · 0 comments
Open
1 task

refactor(db): constructor for row models #423

MR2011 opened this issue Dec 12, 2024 · 0 comments

Comments

@MR2011
Copy link
Collaborator

MR2011 commented Dec 12, 2024

Task Description
Currently we use From functions to convert an entity to a database row object. Instead, we should use a constructor, so that we don't have to create an instance before initializing it.

Example:

// Before

func (cr *ComponentRow) FromComponent(c *entity.Component) {
	cr.Id = sql.NullInt64{Int64: c.Id, Valid: true}
	cr.CCRN = sql.NullString{String: c.CCRN, Valid: true}
	cr.Type = sql.NullString{String: c.Type, Valid: true}
	cr.CreatedAt = sql.NullTime{Time: c.CreatedAt, Valid: true}
	cr.CreatedBy = sql.NullInt64{Int64: c.CreatedBy, Valid: true}
	cr.DeletedAt = sql.NullTime{Time: c.DeletedAt, Valid: true}
	cr.UpdatedAt = sql.NullTime{Time: c.UpdatedAt, Valid: true}
	cr.UpdatedBy = sql.NullInt64{Int64: c.UpdatedBy, Valid: true}
}

// After

func NewComponent(c *entity.Component) ComponentRow {
        return ComponentRow {
	   Id: sql.NullInt64{Int64: c.Id, Valid: true},
	   CCRN: sql.NullString{String: c.CCRN, Valid: true},
          ...
       }
}

Acceptance Criteria:

  • All existing tests pass
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