mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00

- rename common package to database - move all code not related to database to new helper package - add more test in database package to improve code coverage - add a new (own) package for AMQP client
37 lines
863 B
Go
37 lines
863 B
Go
package simulator
|
|
|
|
import (
|
|
"fmt"
|
|
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/database"
|
|
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/helper"
|
|
"github.com/gin-gonic/gin"
|
|
"strconv"
|
|
)
|
|
|
|
func checkPermissions(c *gin.Context, modeltype database.ModelName, operation database.CRUD, hasID bool) (bool, Simulator) {
|
|
|
|
var s Simulator
|
|
|
|
err := database.ValidateRole(c, modeltype, operation)
|
|
if err != nil {
|
|
helper.UnprocessableEntityError(c, err.Error())
|
|
return false, s
|
|
}
|
|
|
|
if hasID {
|
|
// Get the ID of the simulator from the context
|
|
simulatorID, err := strconv.Atoi(c.Param("simulatorID"))
|
|
if err != nil {
|
|
helper.BadRequestError(c, fmt.Sprintf("Could not get simulator's ID from context"))
|
|
return false, s
|
|
}
|
|
|
|
err = s.ByID(uint(simulatorID))
|
|
if helper.DBError(c, err) {
|
|
return false, s
|
|
}
|
|
|
|
}
|
|
|
|
return true, s
|
|
}
|