Files
bamort/backend/bmrt/character/image_handler.go
T
Bardioc26 042a1d4773 Learncost frontend (#42)
* introduced central package  registry by package init function
* dynamic registration of routes, model, migrations and initializers.
* setting a docker compose project name to prevent shutdown of other containers with the same (composer)name
* ai documentation
* app template
* Create tests for ALL API entpoints in ALL packages Based on current data. Ensure that all API endpoints used in frontend are tested. These tests are crucial for the next refactoring tasks.
* adopting agent instructions for a more consistent coding style
* added desired module layout and debugging information
* Fix All Failing tests All failing tests are fixed now that makes the refactoring more easy since all tests must pass
* restored routes for maintenance
* added common translations
* added new tests for API Endpoint
* Merge branch 'separate_business_logic'
* added lern and skill improvement cost editing
* Set Docker image tag when building to prevent rebuild when nothing has changed
* add and remove PP for Weaponskill fixed
* add and remove PP for same named skills fixed
* add new task
2026-05-01 18:15:31 +02:00

51 lines
1.3 KiB
Go

package character
import (
"bamort/database"
"bamort/logger"
"bamort/bmrt/models"
"net/http"
"github.com/gin-gonic/gin"
)
type ImageUpdateRequest struct {
Image string `json:"image" binding:"required"`
}
func UpdateCharacterImage(c *gin.Context) {
id := c.Param("id")
logger.Debug("UpdateCharacterImage called for character ID: %s", id)
var character models.Char
err := character.FirstID(id)
if err != nil {
logger.Error("Character not found: %s", err.Error())
respondWithError(c, http.StatusNotFound, "Character not found")
return
}
// Check ownership
if !checkCharacterOwnership(c, &character) {
return
}
var request ImageUpdateRequest
if err := c.ShouldBindJSON(&request); err != nil {
logger.Error("Invalid request data: %s", err.Error())
respondWithError(c, http.StatusBadRequest, "Invalid request data")
return
}
character.Image = request.Image
if err := database.DB.Save(&character).Error; err != nil {
logger.Error("Failed to update character image: %s", err.Error())
respondWithError(c, http.StatusInternalServerError, "Failed to update character image")
return
}
logger.Info("Character image updated successfully for ID: %s", id)
c.JSON(http.StatusOK, gin.H{"message": "Image updated successfully", "image": character.Image})
}