We can add weapons and equipment

This commit is contained in:
2025-12-28 14:48:59 +01:00
parent 4aea3559e6
commit 530931764d
7 changed files with 1294 additions and 22 deletions
+2
View File
@@ -4,6 +4,7 @@ import (
"bamort/character"
"bamort/config"
"bamort/database"
"bamort/equipment"
"bamort/gsmaster"
"bamort/importer"
"bamort/logger"
@@ -73,6 +74,7 @@ func main() {
// Register your module routes
gsmaster.RegisterRoutes(protected)
character.RegisterRoutes(protected)
equipment.RegisterRoutes(protected)
maintenance.RegisterRoutes(protected)
importer.RegisterRoutes(protected)
pdfrender.RegisterRoutes(protected)
+63
View File
@@ -77,3 +77,66 @@ func DeleteAusruestung(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"message": "Ausruestung deleted successfully"})
}
/*
Endpoints for Managing Weapons (Waffen)
*/
func CreateWaffe(c *gin.Context) {
var waffe models.EqWaffe
if err := c.ShouldBindJSON(&waffe); err != nil {
respondWithError(c, http.StatusBadRequest, err.Error())
return
}
if err := database.DB.Create(&waffe).Error; err != nil {
respondWithError(c, http.StatusInternalServerError, "Failed to create Waffe")
return
}
c.JSON(http.StatusCreated, waffe)
}
func ListWaffen(c *gin.Context) {
characterID := c.Param("character_id")
var waffen []models.EqWaffe
if err := database.DB.Where("character_id = ?", characterID).Find(&waffen).Error; err != nil {
respondWithError(c, http.StatusInternalServerError, "Failed to retrieve Waffen")
return
}
c.JSON(http.StatusOK, waffen)
}
func UpdateWaffe(c *gin.Context) {
waffeID := c.Param("waffe_id")
var waffe models.EqWaffe
if err := database.DB.First(&waffe, waffeID).Error; err != nil {
respondWithError(c, http.StatusNotFound, "Waffe not found")
return
}
if err := c.ShouldBindJSON(&waffe); err != nil {
respondWithError(c, http.StatusBadRequest, err.Error())
return
}
if err := database.DB.Save(&waffe).Error; err != nil {
respondWithError(c, http.StatusInternalServerError, "Failed to update Waffe")
return
}
c.JSON(http.StatusOK, waffe)
}
func DeleteWaffe(c *gin.Context) {
waffeID := c.Param("waffe_id")
if err := database.DB.Delete(&models.EqWaffe{}, waffeID).Error; err != nil {
respondWithError(c, http.StatusInternalServerError, "Failed to delete Waffe")
return
}
c.JSON(http.StatusOK, gin.H{"message": "Waffe deleted successfully"})
}
+21
View File
@@ -0,0 +1,21 @@
package equipment
import (
"github.com/gin-gonic/gin"
)
func RegisterRoutes(r *gin.RouterGroup) {
// Equipment (Ausrüstung) routes
equipGrp := r.Group("/equipment")
equipGrp.POST("", CreateAusruestung)
equipGrp.GET("/character/:character_id", ListAusruestung)
equipGrp.PUT("/:ausruestung_id", UpdateAusruestung)
equipGrp.DELETE("/:ausruestung_id", DeleteAusruestung)
// Weapon (Waffen) routes
weaponGrp := r.Group("/weapons")
weaponGrp.POST("", CreateWaffe)
weaponGrp.GET("/character/:character_id", ListWaffen)
weaponGrp.PUT("/:waffe_id", UpdateWaffe)
weaponGrp.DELETE("/:waffe_id", DeleteWaffe)
}