diff --git a/repositories/alias.go b/repositories/alias.go index 676d0df..7c1f05a 100644 --- a/repositories/alias.go +++ b/repositories/alias.go @@ -24,6 +24,9 @@ func (r *AliasRepository) GetAll() ([]*models.Alias, error) { func (r *AliasRepository) GetByUser(userId string) ([]*models.Alias, error) { var aliases []*models.Alias + if userId == "" { + return aliases, nil + } if err := r.db. Where(&models.Alias{UserID: userId}). Find(&aliases).Error; err != nil { @@ -34,6 +37,9 @@ func (r *AliasRepository) GetByUser(userId string) ([]*models.Alias, error) { func (r *AliasRepository) GetByUserAndKey(userId, key string) ([]*models.Alias, error) { var aliases []*models.Alias + if userId == "" { + return aliases, nil + } if err := r.db. Where(&models.Alias{ UserID: userId, @@ -47,6 +53,9 @@ func (r *AliasRepository) GetByUserAndKey(userId, key string) ([]*models.Alias, func (r *AliasRepository) GetByUserAndKeyAndType(userId, key string, summaryType uint8) ([]*models.Alias, error) { var aliases []*models.Alias + if userId == "" { + return aliases, nil + } if err := r.db. Where(&models.Alias{ UserID: userId, @@ -61,6 +70,9 @@ func (r *AliasRepository) GetByUserAndKeyAndType(userId, key string, summaryType func (r *AliasRepository) GetByUserAndTypeAndValue(userId string, summaryType uint8, value string) (*models.Alias, error) { alias := &models.Alias{} + if userId == "" { + return nil, errors.New("invalid input") + } if err := r.db. Where(&models.Alias{ UserID: userId, diff --git a/repositories/language_mapping.go b/repositories/language_mapping.go index 1d0c029..f6fcf14 100644 --- a/repositories/language_mapping.go +++ b/repositories/language_mapping.go @@ -34,6 +34,9 @@ func (r *LanguageMappingRepository) GetById(id uint) (*models.LanguageMapping, e func (r *LanguageMappingRepository) GetByUser(userId string) ([]*models.LanguageMapping, error) { var mappings []*models.LanguageMapping + if userId == "" { + return mappings, nil + } if err := r.db. Where(&models.LanguageMapping{UserID: userId}). Find(&mappings).Error; err != nil { diff --git a/repositories/project_label.go b/repositories/project_label.go index 7c87ef0..05320b3 100644 --- a/repositories/project_label.go +++ b/repositories/project_label.go @@ -33,6 +33,9 @@ func (r *ProjectLabelRepository) GetById(id uint) (*models.ProjectLabel, error) } func (r *ProjectLabelRepository) GetByUser(userId string) ([]*models.ProjectLabel, error) { + if userId == "" { + return []*models.ProjectLabel{}, nil + } var labels []*models.ProjectLabel if err := r.db. Where(&models.ProjectLabel{UserID: userId}). diff --git a/repositories/user.go b/repositories/user.go index 69e4e29..abc833c 100644 --- a/repositories/user.go +++ b/repositories/user.go @@ -35,6 +35,9 @@ func (r *UserRepository) GetByIds(userIds []string) ([]*models.User, error) { } func (r *UserRepository) GetByApiKey(key string) (*models.User, error) { + if key == "" { + return nil, errors.New("invalid input") + } u := &models.User{} if err := r.db.Where(&models.User{ApiKey: key}).First(u).Error; err != nil { return u, err