fix(filters): replace newline with comma (#1052)

This commit is contained in:
ze0s 2023-08-18 00:46:56 +02:00 committed by GitHub
parent 668e1dbc35
commit ea35ef7fe8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -164,6 +164,10 @@ func (s *service) Update(ctx context.Context, filter *domain.Filter) error {
return errors.New("validation: name can't be empty")
}
// replace newline with comma
filter.Shows = strings.ReplaceAll(filter.Shows, "\n", ",")
filter.Shows = strings.ReplaceAll(filter.Shows, ",,", ",")
// update
if err := s.repo.Update(ctx, filter); err != nil {
s.log.Error().Err(err).Msgf("could not update filter: %s", filter.Name)
@ -195,6 +199,14 @@ func (s *service) Update(ctx context.Context, filter *domain.Filter) error {
}
func (s *service) UpdatePartial(ctx context.Context, filter domain.FilterUpdate) error {
// cleanup
if filter.Shows != nil {
// replace newline with comma
clean := strings.ReplaceAll(*filter.Shows, "\n", ",")
clean = strings.ReplaceAll(clean, ",,", ",")
filter.Shows = &clean
}
// update
if err := s.repo.UpdatePartial(ctx, filter); err != nil {