set validate + order fields by name

This commit is contained in:
Hayden 2023-03-06 20:55:40 -09:00
parent 8c72d66d87
commit e71146df3d
No known key found for this signature in database
GPG key ID: 17CF79474E257545

View file

@ -37,13 +37,13 @@ type (
NotifierCreate struct { NotifierCreate struct {
Name string `json:"name" validate:"required,min=1,max=255"` Name string `json:"name" validate:"required,min=1,max=255"`
IsActive bool `json:"isActive"` IsActive bool `json:"isActive"`
URL string `json:"url" validate:"required"` URL string `json:"url" validate:"required,shoutrrr"`
} }
NotifierUpdate struct { NotifierUpdate struct {
Name string `json:"name" validate:"required,min=1,max=255"` Name string `json:"name" validate:"required,min=1,max=255"`
IsActive bool `json:"isActive"` IsActive bool `json:"isActive"`
URL *string `json:"url" extensions:"x-nullable"` URL *string `json:"url" extensions:"x-nullable" validate:"omitempty,shoutrrr"`
} }
NotifierOut struct { NotifierOut struct {
@ -60,12 +60,19 @@ type (
) )
func (r *NotifierRepository) GetByUser(ctx context.Context, userID uuid.UUID) ([]NotifierOut, error) { func (r *NotifierRepository) GetByUser(ctx context.Context, userID uuid.UUID) ([]NotifierOut, error) {
notifier, err := r.db.Notifier.Query().Where(notifier.UserID(userID)).All(ctx) notifier, err := r.db.Notifier.Query().
Where(notifier.UserID(userID)).
Order(ent.Asc(notifier.FieldName)).
All(ctx)
return r.mapper.MapEachErr(notifier, err) return r.mapper.MapEachErr(notifier, err)
} }
func (r *NotifierRepository) GetByGroup(ctx context.Context, groupID uuid.UUID) ([]NotifierOut, error) { func (r *NotifierRepository) GetByGroup(ctx context.Context, groupID uuid.UUID) ([]NotifierOut, error) {
notifier, err := r.db.Notifier.Query().Where(notifier.GroupID(groupID)).All(ctx) notifier, err := r.db.Notifier.Query().
Where(notifier.GroupID(groupID)).
Order(ent.Asc(notifier.FieldName)).
All(ctx)
return r.mapper.MapEachErr(notifier, err) return r.mapper.MapEachErr(notifier, err)
} }