use make to initialize slices in the repositories
This commit is contained in:
parent
9fbaa7325d
commit
89ec5586f0
|
@ -62,7 +62,7 @@ func (repo *pgRepository) UpdateMany(ctx context.Context, f *models.ProfessionFi
|
|||
}
|
||||
|
||||
func (repo *pgRepository) Delete(ctx context.Context, f *models.ProfessionFilter) ([]*models.Profession, error) {
|
||||
var items []*models.Profession
|
||||
items := make([]*models.Profession, 0)
|
||||
if _, err := repo.
|
||||
Model(&items).
|
||||
Context(ctx).
|
||||
|
@ -76,7 +76,7 @@ func (repo *pgRepository) Delete(ctx context.Context, f *models.ProfessionFilter
|
|||
|
||||
func (repo *pgRepository) Fetch(ctx context.Context, cfg *profession.FetchConfig) ([]*models.Profession, int, error) {
|
||||
var err error
|
||||
var items []*models.Profession
|
||||
items := make([]*models.Profession, 0)
|
||||
total := 0
|
||||
query := repo.
|
||||
Model(&items).
|
||||
|
@ -105,7 +105,7 @@ func (repo *pgRepository) GetAssociatedQualifications(
|
|||
) (map[int][]*models.Qualification, error) {
|
||||
m := make(map[int][]*models.Qualification)
|
||||
for _, id := range ids {
|
||||
m[id] = []*models.Qualification{}
|
||||
m[id] = make([]*models.Qualification, 0)
|
||||
}
|
||||
var qualificationToProfession []*models.QualificationToProfession
|
||||
if err := repo.
|
||||
|
|
|
@ -57,7 +57,7 @@ func (repo *pgRepository) UpdateMany(
|
|||
f *models.QualificationFilter,
|
||||
input *models.QualificationInput,
|
||||
) ([]*models.Qualification, error) {
|
||||
var items []*models.Qualification
|
||||
items := make([]*models.Qualification, 0)
|
||||
err := repo.RunInTransaction(ctx, func(tx *pg.Tx) error {
|
||||
if input.HasBasicDataToUpdate() {
|
||||
if _, err := tx.
|
||||
|
@ -108,7 +108,7 @@ func (repo *pgRepository) UpdateMany(
|
|||
}
|
||||
|
||||
func (repo *pgRepository) Delete(ctx context.Context, f *models.QualificationFilter) ([]*models.Qualification, error) {
|
||||
var items []*models.Qualification
|
||||
items := make([]*models.Qualification, 0)
|
||||
if _, err := repo.
|
||||
Model(&items).
|
||||
Context(ctx).
|
||||
|
@ -122,7 +122,7 @@ func (repo *pgRepository) Delete(ctx context.Context, f *models.QualificationFil
|
|||
|
||||
func (repo *pgRepository) Fetch(ctx context.Context, cfg *qualification.FetchConfig) ([]*models.Qualification, int, error) {
|
||||
var err error
|
||||
var items []*models.Qualification
|
||||
items := make([]*models.Qualification, 0)
|
||||
total := 0
|
||||
query := repo.
|
||||
Model(&items).
|
||||
|
|
|
@ -98,7 +98,7 @@ func (repo *pgRepository) UpdateOneByID(ctx context.Context, id int, input *mode
|
|||
}
|
||||
|
||||
func (repo *pgRepository) Delete(ctx context.Context, f *models.QuestionFilter) ([]*models.Question, error) {
|
||||
var items []*models.Question
|
||||
items := make([]*models.Question, 0)
|
||||
if _, err := repo.
|
||||
Model(&items).
|
||||
Context(ctx).
|
||||
|
@ -115,7 +115,7 @@ func (repo *pgRepository) Delete(ctx context.Context, f *models.QuestionFilter)
|
|||
|
||||
func (repo *pgRepository) Fetch(ctx context.Context, cfg *question.FetchConfig) ([]*models.Question, int, error) {
|
||||
var err error
|
||||
var items []*models.Question
|
||||
items := make([]*models.Question, 0)
|
||||
total := 0
|
||||
query := repo.
|
||||
Model(&items).
|
||||
|
@ -145,7 +145,7 @@ func (repo *pgRepository) GenerateTest(ctx context.Context, cfg *question.Genera
|
|||
Where(gopgutil.BuildConditionArray("qualification_id"), pg.Array(cfg.Qualifications)).
|
||||
OrderExpr("random()").
|
||||
Limit(cfg.Limit)
|
||||
var items []*models.Question
|
||||
items := make([]*models.Question, 0)
|
||||
if err := repo.
|
||||
Model(&items).
|
||||
Context(ctx).
|
||||
|
|
|
@ -62,7 +62,7 @@ func (repo *pgRepository) UpdateMany(ctx context.Context, f *models.UserFilter,
|
|||
}
|
||||
|
||||
func (repo *pgRepository) Delete(ctx context.Context, f *models.UserFilter) ([]*models.User, error) {
|
||||
var items []*models.User
|
||||
items := make([]*models.User, 0)
|
||||
if _, err := repo.
|
||||
Model(&items).
|
||||
Context(ctx).
|
||||
|
@ -76,7 +76,7 @@ func (repo *pgRepository) Delete(ctx context.Context, f *models.UserFilter) ([]*
|
|||
|
||||
func (repo *pgRepository) Fetch(ctx context.Context, cfg *user.FetchConfig) ([]*models.User, int, error) {
|
||||
var err error
|
||||
var items []*models.User
|
||||
items := make([]*models.User, 0)
|
||||
total := 0
|
||||
query := repo.
|
||||
Model(&items).
|
||||
|
|
Reference in New Issue