From 8365a16eca3f765b06331fb21cf506b761d44a60 Mon Sep 17 00:00:00 2001 From: DictumMortuum Date: Sun, 20 Oct 2024 13:59:07 +0300 Subject: [PATCH] [extapi] fixed missing participations returning error --- cmd/servus-extapi/main.go | 2 +- pkg/model/eurovisionparticipations.go | 5 +++++ pkg/model/eurovisionvotes.go | 4 +++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cmd/servus-extapi/main.go b/cmd/servus-extapi/main.go index 5d8918a..6d5b959 100644 --- a/cmd/servus-extapi/main.go +++ b/cmd/servus-extapi/main.go @@ -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) } diff --git a/pkg/model/eurovisionparticipations.go b/pkg/model/eurovisionparticipations.go index 679dd47..7b9d095 100644 --- a/pkg/model/eurovisionparticipations.go +++ b/pkg/model/eurovisionparticipations.go @@ -2,6 +2,7 @@ package model import ( "encoding/json" + "errors" "gorm.io/gorm" "gorm.io/gorm/clause" @@ -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 } diff --git a/pkg/model/eurovisionvotes.go b/pkg/model/eurovisionvotes.go index 33ee35d..f74ebe0 100644 --- a/pkg/model/eurovisionvotes.go +++ b/pkg/model/eurovisionvotes.go @@ -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 {