Skip to content

Commit

Permalink
[extapi] fixed missing participations returning error
Browse files Browse the repository at this point in the history
  • Loading branch information
DictumMortuum committed Oct 20, 2024
1 parent c5a8e26 commit 8365a16
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/servus-extapi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

func Version(c *gin.Context) {
rs := map[string]any{
"version": "v0.0.31",
"version": "v0.0.32",
}
c.AbortWithStatusJSON(200, rs)
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/model/eurovisionparticipations.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package model

import (
"encoding/json"
"errors"

"gorm.io/gorm"
"gorm.io/gorm/clause"
Expand Down Expand Up @@ -98,6 +99,10 @@ func GetEurovisionParticipationsByUserId(req *Map, res *Map) error {

var data EurovisionParticipation
rs := DB.Preload("Boardgame").First(&data, "user_id = ? ", id)
if errors.Is(rs.Error, gorm.ErrRecordNotFound) {
res.Set("data", EurovisionParticipation{})
return nil
}
if rs.Error != nil {
return rs.Error
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/model/eurovisionvotes.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ func GetEurovisionVoteByUserId(req *Map, res *Map) error {
var data EurovisionVote
rs := DB.First(&data, "user_id = ? ", id)
if errors.Is(rs.Error, gorm.ErrRecordNotFound) {
res.Set("data", nil)
res.Set("data", EurovisionVote{
Votes: datatypes.JSON([]byte(`[]`)),
})
return nil
}
if rs.Error != nil {
Expand Down

0 comments on commit 8365a16

Please sign in to comment.