refac: removed ugly multi-line method chaining
This commit is contained in:
1 parent
e8dff6bb5f
commit
ce9c876db6
6 files changed
+72
-67
No files matched your search
@@ -64,22 +64,24 @@ func (a *APIKeyRepository) list(query *gorm.DB) ([]domainAPIKey.APIKey, error) {
|
||||
}
|
||||
|
||||
func (a *APIKeyRepository) Revoke(id uint32, at time.Time) error {
|
||||
result := a.db.Model(&entity.APIKey{}).
|
||||
Where("id = ? AND revoked_at IS NULL", id).
|
||||
Update("revoked_at", at)
|
||||
query := a.db.Model(&entity.APIKey{})
|
||||
query = query.Where("id = ? AND revoked_at IS NULL", id)
|
||||
result := query.Update("revoked_at", at)
|
||||
return result.Error
|
||||
}
|
||||
|
||||
func (a *APIKeyRepository) RevokeAllByUser(userId uint32, at time.Time) error {
|
||||
return a.db.Model(&entity.APIKey{}).
|
||||
Where("user_id = ? AND revoked_at IS NULL", userId).
|
||||
Update("revoked_at", at).Error
|
||||
query := a.db.Model(&entity.APIKey{})
|
||||
query = query.Where("user_id = ? AND revoked_at IS NULL", userId)
|
||||
result := query.Update("revoked_at", at)
|
||||
return result.Error
|
||||
}
|
||||
|
||||
func (a *APIKeyRepository) TouchLastUsed(id uint32, at time.Time) error {
|
||||
return a.db.Model(&entity.APIKey{}).
|
||||
Where("id = ?", id).
|
||||
Update("last_used_at", at).Error
|
||||
query := a.db.Model(&entity.APIKey{})
|
||||
query = query.Where("id = ?", id)
|
||||
result := query.Update("last_used_at", at)
|
||||
return result.Error
|
||||
}
|
||||
|
||||
var _ domainAPIKey.Repository = &APIKeyRepository{}
|
||||
Reference in new issue
Block a user