fix(store): return ErrRecordNotFound when updating non-existent template

RowsAffected == 0 now returns gorm.ErrRecordNotFound so the handler can respond with 404 instead of silently returning 200.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
dailz
2026-04-10 09:21:03 +08:00
parent 4ff02d4a80
commit 1359730300
2 changed files with 15 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
package handler
import (
"errors"
"strconv"
"gcy_hpc_server/internal/model"
@@ -9,6 +10,7 @@ import (
"github.com/gin-gonic/gin"
"go.uber.org/zap"
"gorm.io/gorm"
)
type TemplateHandler struct {
@@ -111,8 +113,13 @@ func (h *TemplateHandler) UpdateTemplate(c *gin.Context) {
}
if err := h.store.Update(c.Request.Context(), id, &req); err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
h.logger.Warn("template not found for update", zap.Int64("id", id))
server.NotFound(c, "template not found")
return
}
h.logger.Error("failed to update template", zap.Int64("id", id), zap.Error(err))
server.InternalError(c, err.Error())
server.InternalError(c, "failed to update template")
return
}