Skip to content

Commit

Permalink
mariadb: fix UserStorage.All query to return results when there is no…
Browse files Browse the repository at this point in the history
… theme set
  • Loading branch information
Wessie committed Feb 4, 2024
1 parent bc3d373 commit cd95db4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
28 changes: 15 additions & 13 deletions storage/mariadb/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
radio "github.com/R-a-dio/valkyrie"
"github.com/R-a-dio/valkyrie/errors"
"github.com/jmoiron/sqlx"
"github.com/rs/zerolog"
)

// UserStorage implements radio.UserStorage
Expand Down Expand Up @@ -282,20 +281,23 @@ func (us UserStorage) LookupName(name string) (*radio.User, error) {
continue
}

re, err := regexp.Compile(`(?i)` + user.DJ.Regex)
if err != nil {
zerolog.Ctx(us.handle.ctx).Error().Err(err).Str("regular_expression", user.DJ.Regex).Msg("invalid regex")
continue
}

if re.MatchString(name) {
if MatchName(user.DJ.Regex, name) {
return &user, nil
}
}

return nil, errors.E(op, errors.UserUnknown, errors.Info(name))
}

func MatchName(regex, name string) bool {
re, err := regexp.Compile(`(?i)` + regex)
if err != nil {
return false
}

return re.MatchString(name)
}

func (us UserStorage) All() ([]radio.User, error) {
const op errors.Op = "mariadb/UserStorage.All"

Expand Down Expand Up @@ -323,15 +325,15 @@ func (us UserStorage) All() ([]radio.User, error) {
djs.css AS 'dj.css',
djs.djcolor AS 'dj.color',
themes.id AS 'dj.theme.id',
themes.name AS 'dj.theme.name',
themes.display_name AS 'dj.theme.displayname',
themes.author AS 'dj.theme.author'
IFNULL(themes.id, 0) AS 'dj.theme.id',
IFNULL(themes.name, 'default') AS 'dj.theme.name',
IFNULL(themes.display_name, 'default') AS 'dj.theme.displayname',
IFNULL(themes.author, 'unknown') AS 'dj.theme.author'
FROM
djs
JOIN
users ON djs.id = users.djid
JOIN
LEFT JOIN
themes ON djs.theme_id = themes.id;
`
var users []radio.User
Expand Down
8 changes: 5 additions & 3 deletions templates/default/home.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@
</div>
</div>
<div class="column is-3">
<div id="dj-image">
<img src="{{.Status.User.DJ.Image}}" style="max-height: 180px;">
<h4>{{.Status.User.DJ.Name}}</h4>
<div id="dj-image" class="md-5">
<figure class="image is-square">
<img src="/api/dj-image/{{.Status.User.DJ.Image}}">
</figure>
<h4 class="title has-text-centered">{{.Status.User.DJ.Name}}</h4>
</div>
</div>
</div>
Expand Down

0 comments on commit cd95db4

Please sign in to comment.