mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
fix: add missing non-zero field checks (fix #259)
This commit is contained in:
parent
8d073aaef2
commit
cc11226eab
@ -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,
|
||||
|
@ -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 {
|
||||
|
@ -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}).
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user