From e71146df3deb7b3ba21abf44fe54ad8520b5226e Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Mon, 6 Mar 2023 20:55:40 -0900 Subject: [PATCH] set validate + order fields by name --- backend/internal/data/repo/repo_notifier.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/backend/internal/data/repo/repo_notifier.go b/backend/internal/data/repo/repo_notifier.go index 00446f0..077308d 100644 --- a/backend/internal/data/repo/repo_notifier.go +++ b/backend/internal/data/repo/repo_notifier.go @@ -37,13 +37,13 @@ type ( NotifierCreate struct { Name string `json:"name" validate:"required,min=1,max=255"` IsActive bool `json:"isActive"` - URL string `json:"url" validate:"required"` + URL string `json:"url" validate:"required,shoutrrr"` } NotifierUpdate struct { Name string `json:"name" validate:"required,min=1,max=255"` IsActive bool `json:"isActive"` - URL *string `json:"url" extensions:"x-nullable"` + URL *string `json:"url" extensions:"x-nullable" validate:"omitempty,shoutrrr"` } NotifierOut struct { @@ -60,12 +60,19 @@ type ( ) 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) } 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) }