mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
Shorten API URLs, add more documentation for swaggo
This commit is contained in:
parent
0c4c60c1ce
commit
34eebbab88
10 changed files with 673 additions and 372 deletions
|
@ -3,6 +3,7 @@ package file
|
|||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
@ -11,21 +12,23 @@ import (
|
|||
)
|
||||
|
||||
func RegisterFileEndpoints(r *gin.RouterGroup){
|
||||
r.GET("/:simulationID/models/:modelID/files", GetFilesOfModel)
|
||||
r.POST ("/:simulationID/models/:modelID/file", AddFileToModel)
|
||||
r.GET("/:simulationID/models/:modelID/file", GetFileOfModel)
|
||||
r.PUT("/:simulationID/models/:modelID/file", UpdateFileOfModel)
|
||||
r.DELETE("/:simulationID/models/:modelID/file", DeleteFileOfModel)
|
||||
r.GET("/:simulationID/visualizations/:visualizationID/widgets/:widgetID/files", GetFilesOfWidget)
|
||||
r.POST ("/:simulationID/visualizations/:visualizationID/widgets/:widgetID/file", AddFileToWidget)
|
||||
r.GET("/:simulationID/visualizations/:visualizationID/widgets/:widgetID/file", GetFileOfWidget)
|
||||
r.PUT("/:simulationID/visualizations/:visualizationID/widgets/:widgetID/file", UpdateFileOfWidget)
|
||||
r.DELETE("/:simulationID/visualizations/:visualizationID/widgets/:widgetID/file", DeleteFileOfWidget)
|
||||
r.GET("/", GetFiles)
|
||||
r.POST ("/", AddFile)
|
||||
r.GET("/:fileID", GetFile)
|
||||
r.PUT("/:fileID", UpdateFile)
|
||||
r.DELETE("/:fileID", DeleteFile)
|
||||
//r.GET("/:simulationID/visualizations/:visualizationID/widgets/:widgetID/files", GetFilesOfWidget)
|
||||
//r.POST ("/:simulationID/visualizations/:visualizationID/widgets/:widgetID/file", AddFileToWidget)
|
||||
//r.GET("/:simulationID/visualizations/:visualizationID/widgets/:widgetID/file", GetFileOfWidget)
|
||||
//r.PUT("/:simulationID/visualizations/:visualizationID/widgets/:widgetID/file", UpdateFileOfWidget)
|
||||
//r.DELETE("/:simulationID/visualizations/:visualizationID/widgets/:widgetID/file", DeleteFileOfWidget)
|
||||
}
|
||||
|
||||
// GetFilesOfModel godoc
|
||||
// @Summary Get all parameters of files of model
|
||||
// @ID GetFilesOfModel
|
||||
|
||||
|
||||
// GetFiles godoc
|
||||
// @Summary Get all files of a specific model or widget
|
||||
// @ID GetFiles
|
||||
// @Tags files
|
||||
// @Produce json
|
||||
// @Success 200 {array} common.FileResponse "File parameters requested by user"
|
||||
|
@ -33,9 +36,140 @@ func RegisterFileEndpoints(r *gin.RouterGroup){
|
|||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Param simulationID path int true "Simulation ID"
|
||||
// @Param modelID path int true "Model ID"
|
||||
// @Router /simulations/{simulationID}/models/{modelID}/files [get]
|
||||
// @Param originType query string true "Set to model for files of model, set to widget for files of widget"
|
||||
// @Param originID query int true "ID of either model or widget of which files are requested"
|
||||
// @Router /files [get]
|
||||
func GetFiles(c *gin.Context) {
|
||||
|
||||
// TODO if originType == "model" --> GetFilesOfModel, if originType == "vis" --> GetFilesOfWidget
|
||||
|
||||
}
|
||||
|
||||
// AddFile godoc
|
||||
// @Summary Add a file to a specific model or widget
|
||||
// @ID AddFile
|
||||
// @Tags files
|
||||
// @Produce json
|
||||
// @Accept text/plain
|
||||
// @Accept png
|
||||
// @Accept jpeg
|
||||
// @Accept gif
|
||||
// @Accept model/x-cim
|
||||
// @Accept model/x-cim.zip
|
||||
// @Success 200 "OK"
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Param inputFile formData file true "File to be uploaded"
|
||||
// @Param originType query string true "Set to model for files of model, set to widget for files of widget"
|
||||
// @Param originID query int true "ID of either model or widget of which files are requested"
|
||||
// @Router /files [post]
|
||||
func AddFile(c *gin.Context){
|
||||
// TODO if originType == "model" --> AddFileToModel, if originType == "vis" --> AddFileToWidget
|
||||
}
|
||||
|
||||
// GetFile godoc
|
||||
// @Summary Download a file
|
||||
// @ID GetFile
|
||||
// @Tags files
|
||||
// @Produce text/plain
|
||||
// @Produce png
|
||||
// @Produce jpeg
|
||||
// @Produce gif
|
||||
// @Produce model/x-cim
|
||||
// @Produce model/x-cim.zip
|
||||
// @Success 200 "OK"
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Param fileID path int true "ID of the file to download"
|
||||
// @Router /files/{fileID} [get]
|
||||
func GetFile(c *gin.Context){
|
||||
// TODO
|
||||
}
|
||||
|
||||
// UpdateFile godoc
|
||||
// @Summary Update a file
|
||||
// @ID UpdateFile
|
||||
// @Tags files
|
||||
// @Produce json
|
||||
// @Accept text/plain
|
||||
// @Accept png
|
||||
// @Accept jpeg
|
||||
// @Accept gif
|
||||
// @Accept model/x-cim
|
||||
// @Accept model/x-cim.zip
|
||||
// @Success 200 "OK"
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Param fileID path int true "ID of the file to update"
|
||||
// @Router /files/{fileID} [put]
|
||||
func UpdateFile(c *gin.Context){
|
||||
|
||||
//TODO parse this info based on fileID parameter
|
||||
simulationID := 1
|
||||
modelID := 1
|
||||
widgetID := 1
|
||||
|
||||
|
||||
// Extract file from PUT request form
|
||||
err := c.Request.ParseForm()
|
||||
if err != nil {
|
||||
errormsg := fmt.Sprintf("Bad request. Get form error: %s", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": errormsg,
|
||||
})
|
||||
return;
|
||||
}
|
||||
|
||||
file_header, err := c.FormFile("file")
|
||||
if err != nil {
|
||||
errormsg := fmt.Sprintf("Bad request. Get form error: %s", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": errormsg,
|
||||
})
|
||||
return;
|
||||
}
|
||||
|
||||
filename := filepath.Base(file_header.Filename)
|
||||
filetype := file_header.Header.Get("Content-Type") // TODO make sure this is properly set in file header
|
||||
size := file_header.Size
|
||||
foldername := getFolderName(simulationID, modelID, widgetID)
|
||||
|
||||
err = modifyFileOnDisc(file_header, filename, foldername, uint(size), false)
|
||||
if err != nil {
|
||||
errormsg := fmt.Sprintf("Internal Server Error. Error saving file: %s", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"error": errormsg,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
saveFileInDB(c, filename, foldername, filetype, uint(size), widgetID, modelID, false)
|
||||
}
|
||||
|
||||
|
||||
// DeleteFile godoc
|
||||
// @Summary Delete a file
|
||||
// @ID DeleteFile
|
||||
// @Tags files
|
||||
// @Produce json
|
||||
// @Success 200 "OK"
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Param fileID path int true "ID of the file to update"
|
||||
// @Router /files/{fileID} [delete]
|
||||
func DeleteFile(c *gin.Context){
|
||||
// TODO
|
||||
}
|
||||
|
||||
|
||||
func GetFilesOfModel(c *gin.Context) {
|
||||
|
||||
simulationID, modelID, err := getRequestParams(c)
|
||||
|
@ -55,20 +189,7 @@ func GetFilesOfModel(c *gin.Context) {
|
|||
|
||||
}
|
||||
|
||||
// AddFileToModel godoc
|
||||
// @Summary Get all parameters of files of model
|
||||
// @ID AddFileToModel
|
||||
// @Tags files
|
||||
// @Accept text/plain
|
||||
// @Produce json
|
||||
// @Success 200 "OK."
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Param simulationID path int true "Simulation ID"
|
||||
// @Param modelID path int true "Model ID"
|
||||
// @Router /simulations/{simulationID}/models/{modelID}/file [post]
|
||||
|
||||
func AddFileToModel(c *gin.Context) {
|
||||
|
||||
simulationID, modelID, err := getRequestParams(c)
|
||||
|
@ -89,19 +210,7 @@ func CloneFileOfModel(c *gin.Context) {
|
|||
|
||||
}
|
||||
|
||||
// GetFileOfModel godoc
|
||||
// @Summary Download a file that belongs to a model
|
||||
// @ID GetFileOfModel
|
||||
// @Tags files
|
||||
// @Produce text/plain
|
||||
// @Success 200 "OK, File included in response."
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Param simulationID path int true "Simulation ID"
|
||||
// @Param modelID path int true "Model ID"
|
||||
// @Router /simulations/{simulationID}/models/{modelID}/file [get]
|
||||
|
||||
func GetFileOfModel(c *gin.Context) {
|
||||
|
||||
simulationID, modelID, err := getRequestParams(c)
|
||||
|
@ -113,71 +222,31 @@ func GetFileOfModel(c *gin.Context) {
|
|||
ReadFile(c, -1, modelID, simulationID)
|
||||
}
|
||||
|
||||
// UpdateFileOfModel godoc
|
||||
// @Summary Update (overwrite) a file that belongs to a model
|
||||
// @ID UpdateFileOfModel
|
||||
// @Tags files
|
||||
// @Accept text/plain
|
||||
// @Produce json
|
||||
// @Success 200 "OK."
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Param simulationID path int true "Simulation ID"
|
||||
// @Param modelID path int true "Model ID"
|
||||
// @Router /simulations/{simulationID}/models/{modelID}/file [put]
|
||||
|
||||
func UpdateFileOfModel(c *gin.Context) {
|
||||
|
||||
simulationID, modelID, err := getRequestParams(c)
|
||||
if err != nil{
|
||||
return
|
||||
}
|
||||
//simulationID, modelID, err := getRequestParams(c)
|
||||
//if err != nil{
|
||||
// return
|
||||
//}
|
||||
|
||||
// Update file locally and update file entry in DB, HTTP response is set by this method
|
||||
UpdateFile(c,-1, modelID, simulationID)
|
||||
//UpdateFile(c,-1, modelID, simulationID)
|
||||
}
|
||||
|
||||
// DeleteFileOfModel godoc
|
||||
// @Summary Delete a file that belongs to a model
|
||||
// @ID DeleteFileOfModel
|
||||
// @Tags files
|
||||
// @Produce json
|
||||
// @Success 200 "OK."
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Param simulationID path int true "Simulation ID"
|
||||
// @Param modelID path int true "Model ID"
|
||||
// @Router /simulations/{simulationID}/models/{modelID}/file [delete]
|
||||
func DeleteFileOfModel(c *gin.Context) {
|
||||
|
||||
simulationID, modelID, err := getRequestParams(c)
|
||||
if err != nil{
|
||||
return
|
||||
}
|
||||
//simulationID, modelID, err := getRequestParams(c)
|
||||
//if err != nil{
|
||||
// return
|
||||
//}
|
||||
|
||||
// Delete file from disk and remove entry from DB, HTTP response is set by this method
|
||||
DeleteFile(c, -1, modelID, simulationID)
|
||||
//DeleteFile(c, -1, modelID, simulationID)
|
||||
|
||||
|
||||
}
|
||||
|
||||
// GetFilesOfWidget godoc
|
||||
// @Summary Get all parameters of files of widget
|
||||
// @ID GetFilesOfWidget
|
||||
// @Tags files
|
||||
// @Produce json
|
||||
// @Success 200 {array} common.WidgetResponse "File parameters requested by user"
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Param simulationID path int true "Simulation ID"
|
||||
// @Param visualizationID path int true "Visualization ID"
|
||||
// @Param widgetID path int true "Widget ID"
|
||||
// @Router /simulations/{simulationID}/visualizations/{visualizationID}/widgets/{widgetID}/files [get]
|
||||
func GetFilesOfWidget(c *gin.Context) {
|
||||
|
||||
simulationID, widgetID, err := getRequestParams(c)
|
||||
|
@ -197,21 +266,7 @@ func GetFilesOfWidget(c *gin.Context) {
|
|||
|
||||
}
|
||||
|
||||
// AddFileToWidget godoc
|
||||
// @Summary Get all parameters of files of widget
|
||||
// @ID AddFileToWidget
|
||||
// @Tags files
|
||||
// @Accept text/plain
|
||||
// @Produce json
|
||||
// @Success 200 "OK."
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Param simulationID path int true "Simulation ID"
|
||||
// @Param visualizationID path int true "Visualization ID"
|
||||
// @Param widgetID path int true "Widget ID"
|
||||
// @Router /simulations/{simulationID}/visualizations/{visualizationID}/widgets/{widgetID}/file [post]
|
||||
|
||||
func AddFileToWidget(c *gin.Context) {
|
||||
|
||||
simulationID, widgetID, err := getRequestParams(c)
|
||||
|
@ -232,20 +287,7 @@ func CloneFileOfWidget(c *gin.Context) {
|
|||
|
||||
}
|
||||
|
||||
// GetFileOfWidget godoc
|
||||
// @Summary Download a file that belongs to a widget
|
||||
// @ID GetFileOfWidget
|
||||
// @Tags files
|
||||
// @Produce text/plain
|
||||
// @Success 200 "OK, File included in response."
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Param simulationID path int true "Simulation ID"
|
||||
// @Param visualizationID path int true "Visualization ID"
|
||||
// @Param widgetID path int true "Widget ID"
|
||||
// @Router /simulations/{simulationID}/visualizations/{visualizationID}/widgets/{widgetID}/file [get]
|
||||
|
||||
func GetFileOfWidget(c *gin.Context) {
|
||||
|
||||
simulationID, widgetID, err := getRequestParams(c)
|
||||
|
@ -257,55 +299,28 @@ func GetFileOfWidget(c *gin.Context) {
|
|||
ReadFile(c, widgetID, -1, simulationID)
|
||||
}
|
||||
|
||||
// UpdateFileOfWidget godoc
|
||||
// @Summary Update (overwrite) a file that belongs to a widget
|
||||
// @ID UpdateFileOfWidget
|
||||
// @Tags files
|
||||
// @Accept text/plain
|
||||
// @Produce json
|
||||
// @Success 200 "OK."
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Param simulationID path int true "Simulation ID"
|
||||
// @Param visualizationID path int true "Visualization ID"
|
||||
// @Param widgetID path int true "Widget ID"
|
||||
// @Router /simulations/{simulationID}/visualizations/{visualizationID}/widgets/{widgetID}/file [put]
|
||||
|
||||
func UpdateFileOfWidget(c *gin.Context) {
|
||||
|
||||
simulationID, widgetID, err := getRequestParams(c)
|
||||
if err != nil{
|
||||
return
|
||||
}
|
||||
|
||||
// Update file locally and update file entry in DB, HTTP response is set by this method
|
||||
UpdateFile(c,widgetID, -1, simulationID)
|
||||
//simulationID, widgetID, err := getRequestParams(c)
|
||||
//if err != nil{
|
||||
// return
|
||||
//}
|
||||
//
|
||||
//// Update file locally and update file entry in DB, HTTP response is set by this method
|
||||
//UpdateFile(c,widgetID, -1, simulationID)
|
||||
}
|
||||
|
||||
// DeleteFileOfWidget godoc
|
||||
// @Summary Delete a file that belongs to a widget
|
||||
// @ID DeleteFileOfWidget
|
||||
// @Tags files
|
||||
// @Produce json
|
||||
// @Success 200 "OK."
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Param simulationID path int true "Simulation ID"
|
||||
// @Param visualizationID path int true "Visualization ID"
|
||||
// @Param widgetID path int true "Widget ID"
|
||||
// @Router /simulations/{simulationID}/visualizations/{visualizationID}/widgets/{widgetID}/file [delete]
|
||||
|
||||
func DeleteFileOfWidget(c *gin.Context) {
|
||||
|
||||
simulationID, widgetID, err := getRequestParams(c)
|
||||
if err != nil{
|
||||
return
|
||||
}
|
||||
|
||||
// Delete file from disk and remove entry from DB, HTTP response is set by this method
|
||||
DeleteFile(c, widgetID, -1, simulationID)
|
||||
//simulationID, widgetID, err := getRequestParams(c)
|
||||
//if err != nil{
|
||||
// return
|
||||
//}
|
||||
//
|
||||
//// Delete file from disk and remove entry from DB, HTTP response is set by this method
|
||||
//DeleteFile(c, widgetID, -1, simulationID)
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -138,43 +138,7 @@ func RegisterFile(c *gin.Context, widgetID int, modelID int, simulationID int){
|
|||
|
||||
}
|
||||
|
||||
func UpdateFile(c *gin.Context, widgetID int, modelID int, simulationID int){
|
||||
|
||||
// Extract file from PUT request form
|
||||
err := c.Request.ParseForm()
|
||||
if err != nil {
|
||||
errormsg := fmt.Sprintf("Bad request. Get form error: %s", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": errormsg,
|
||||
})
|
||||
return;
|
||||
}
|
||||
|
||||
file_header, err := c.FormFile("file")
|
||||
if err != nil {
|
||||
errormsg := fmt.Sprintf("Bad request. Get form error: %s", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"error": errormsg,
|
||||
})
|
||||
return;
|
||||
}
|
||||
|
||||
filename := filepath.Base(file_header.Filename)
|
||||
filetype := file_header.Header.Get("Content-Type") // TODO make sure this is properly set in file header
|
||||
size := file_header.Size
|
||||
foldername := getFolderName(simulationID, modelID, widgetID)
|
||||
|
||||
err = modifyFileOnDisc(file_header, filename, foldername, uint(size), false)
|
||||
if err != nil {
|
||||
errormsg := fmt.Sprintf("Internal Server Error. Error saving file: %s", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"error": errormsg,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
saveFileInDB(c, filename, foldername, filetype, uint(size), widgetID, modelID, false)
|
||||
}
|
||||
|
||||
func ReadFile(c *gin.Context, widgetID int, modelID int, simulationID int){
|
||||
|
||||
|
@ -223,13 +187,6 @@ func ReadFile(c *gin.Context, widgetID int, modelID int, simulationID int){
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
func DeleteFile(c *gin.Context, widgetID int, nmodelID int, simulationID int){
|
||||
// TODO
|
||||
}
|
||||
|
||||
|
||||
func saveFileInDB(c *gin.Context, filename string, foldername string, filetype string, size uint, widgetID int, modelID int, createObj bool) {
|
||||
|
||||
filesavepath := filepath.Join(foldername, filename)
|
||||
|
|
|
@ -12,29 +12,30 @@ import (
|
|||
)
|
||||
|
||||
func RegisterModelEndpoints(r *gin.RouterGroup){
|
||||
r.GET("/:simulationID/models/", GetModels)
|
||||
r.POST("/:simulationID/models/", AddModel)
|
||||
r.POST("/:simulationID/models/:modelID", CloneModel)
|
||||
r.PUT("/:simulationID/models/:modelID", UpdateModel)
|
||||
r.GET("/:simulationID/models/:modelID", GetModel)
|
||||
r.DELETE("/:simulationID/models/:modelID", DeleteModel)
|
||||
r.PUT("/:simulationID/models/:modelID/simulator", UpdateSimulator)
|
||||
r.GET("/:simulationID/models/:modelID/simulator", GetSimulator)
|
||||
r.POST("/:simulationID/models/:modelID/signals/:direction", UpdateSignals)
|
||||
r.GET("/:simulationID/models/:modelID/signals/:direction", GetSignals)
|
||||
r.GET("/", GetModels)
|
||||
r.POST("/", AddModel)
|
||||
//r.POST("/:modelID", CloneModel)
|
||||
r.PUT("/:modelID", UpdateModel)
|
||||
r.GET("/:modelID", GetModel)
|
||||
r.DELETE("/:modelID", DeleteModel)
|
||||
//r.PUT("/:modelID/simulator", UpdateSimulator)
|
||||
//r.GET("/:modelID/simulator", GetSimulator)
|
||||
//r.POST("/:modelID/signals/:direction", UpdateSignals)
|
||||
//r.GET("/:modelID/signals/:direction", GetSignals)
|
||||
}
|
||||
|
||||
// GetModels godoc
|
||||
// @Summary Get all models of simulation
|
||||
// @ID GetModels
|
||||
// @Produce json
|
||||
// @Tags model
|
||||
// @Tags models
|
||||
// @Success 200 {array} common.ModelResponse "Array of models to which belong to simulation"
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Router /simulations/{simulationID}/models [get]
|
||||
// @Param simulationID query int true "Simulation ID"
|
||||
// @Router /models [get]
|
||||
func GetModels(c *gin.Context) {
|
||||
|
||||
simID, err := common.GetSimulationID(c)
|
||||
|
@ -56,14 +57,16 @@ func GetModels(c *gin.Context) {
|
|||
// AddModel godoc
|
||||
// @Summary Add a model to a simulation
|
||||
// @ID AddModel
|
||||
// @Tags model
|
||||
// @Param inputModel body common.ModelResponse true "Model to be added"
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Tags models
|
||||
// @Param inputModel body common.ModelResponse true "Model to be added incl. IDs of simulation and simulator"
|
||||
// @Success 200 "OK."
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Router /simulations/{simulationID}/models [post]
|
||||
// @Router /models [post]
|
||||
func AddModel(c *gin.Context) {
|
||||
|
||||
simID, err := common.GetSimulationID(c)
|
||||
|
@ -125,6 +128,20 @@ func CloneModel(c *gin.Context) {
|
|||
|
||||
}
|
||||
|
||||
// UpdateModel godoc
|
||||
// @Summary Update a model
|
||||
// @ID UpdateModel
|
||||
// @Tags models
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param inputModel body common.ModelResponse true "Model to be updated"
|
||||
// @Success 200 "OK."
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Param modelID path int true "Model ID"
|
||||
// @Router /models/{modelID} [put]
|
||||
func UpdateModel(c *gin.Context) {
|
||||
|
||||
modelID, err := common.GetModelID(c)
|
||||
|
@ -151,6 +168,18 @@ func UpdateModel(c *gin.Context) {
|
|||
|
||||
}
|
||||
|
||||
// GetModel godoc
|
||||
// @Summary Get a model
|
||||
// @ID GetModel
|
||||
// @Tags models
|
||||
// @Produce json
|
||||
// @Success 200 {object} common.ModelResponse "Requested model."
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Param modelID path int true "Model ID"
|
||||
// @Router /models/{modelID} [get]
|
||||
func GetModel(c *gin.Context) {
|
||||
|
||||
modelID, err := common.GetModelID(c)
|
||||
|
@ -169,6 +198,18 @@ func GetModel(c *gin.Context) {
|
|||
})
|
||||
}
|
||||
|
||||
// DeleteModel godoc
|
||||
// @Summary Delete a model
|
||||
// @ID DeleteModel
|
||||
// @Tags models
|
||||
// @Produce json
|
||||
// @Success 200 "OK."
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Param modelID path int true "Model ID"
|
||||
// @Router /models/{modelID} [delete]
|
||||
func DeleteModel(c *gin.Context) {
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
|
|
|
@ -36,6 +36,11 @@ func (m *Model) addToSimulation(simID int) error {
|
|||
return err
|
||||
}
|
||||
|
||||
err = db.Create(m).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = db.Model(&sim).Association("Models").Append(m).Error
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package simulation
|
||||
|
||||
import (
|
||||
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/user"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
@ -11,17 +12,21 @@ import (
|
|||
func RegisterSimulationEndpoints(r *gin.RouterGroup){
|
||||
r.GET("/", GetSimulations)
|
||||
r.POST("/", AddSimulation)
|
||||
r.POST("/:simulationID", CloneSimulation)
|
||||
//r.POST("/:simulationID", CloneSimulation)
|
||||
r.PUT("/:simulationID", UpdateSimulation)
|
||||
r.GET("/:simulationID", GetSimulation)
|
||||
r.DELETE("/:simulationID", DeleteSimulation)
|
||||
|
||||
r.GET("/:simulationID/users", GetUsersOfSimulation)
|
||||
r.PUT("/:simulationID/users/:userID", AddUserToSimulation)
|
||||
r.DELETE("/:simulationID/users/:userID", DeleteUserFromSimulation)
|
||||
}
|
||||
|
||||
// GetSimulations godoc
|
||||
// @Summary Get all simulations
|
||||
// @ID GetSimulations
|
||||
// @Produce json
|
||||
// @Tags simulation
|
||||
// @Tags simulations
|
||||
// @Success 200 {array} common.SimulationResponse "Array of simulations to which user has access"
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
|
@ -39,10 +44,22 @@ func GetSimulations(c *gin.Context) {
|
|||
})
|
||||
}
|
||||
|
||||
// AddSimulation godoc
|
||||
// @Summary Add a simulation
|
||||
// @ID AddSimulation
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Tags simulations
|
||||
// @Param inputModel body common.ModelResponse true "Simulation to be added"
|
||||
// @Success 200 "OK."
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Router /simulations [post]
|
||||
func AddSimulation(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "NOT implemented",
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
|
||||
func CloneSimulation(c *gin.Context) {
|
||||
|
@ -51,6 +68,20 @@ func CloneSimulation(c *gin.Context) {
|
|||
})
|
||||
}
|
||||
|
||||
// UpdateSimulation godoc
|
||||
// @Summary Update a simulation
|
||||
// @ID UpdateSimulation
|
||||
// @Tags simulations
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param inputSimulation body common.SimulationResponse true "Simulation to be updated"
|
||||
// @Success 200 "OK."
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Param simulationID path int true "Simulation ID"
|
||||
// @Router /simulations/{simulationID} [put]
|
||||
func UpdateSimulation(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "NOT implemented",
|
||||
|
@ -61,7 +92,7 @@ func UpdateSimulation(c *gin.Context) {
|
|||
// @Summary Get simulation
|
||||
// @ID GetSimulation
|
||||
// @Produce json
|
||||
// @Tags simulation
|
||||
// @Tags simulations
|
||||
// @Success 200 {object} common.SimulationResponse "Simulation requested by user"
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
|
@ -87,6 +118,18 @@ func GetSimulation(c *gin.Context) {
|
|||
})
|
||||
}
|
||||
|
||||
// DeleteSimulation godoc
|
||||
// @Summary Delete a simulation
|
||||
// @ID DeleteSimulation
|
||||
// @Tags simulations
|
||||
// @Produce json
|
||||
// @Success 200 "OK."
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Param simulationID path int true "Simulation ID"
|
||||
// @Router /simulations/{simulationID} [delete]
|
||||
func DeleteSimulation(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "NOT implemented",
|
||||
|
@ -94,3 +137,122 @@ func DeleteSimulation(c *gin.Context) {
|
|||
}
|
||||
|
||||
|
||||
// GetUsersOfSimulation godoc
|
||||
// @Summary Get users of simulation
|
||||
// @ID GetUsersOfSimulation
|
||||
// @Produce json
|
||||
// @Tags simulations
|
||||
// @Success 200 {array} common.UserResponse "Array of users that have access to the simulation"
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Param simulationID path int true "Simulation ID"
|
||||
// @Router /simulations/{simulationID}/users/ [get]
|
||||
func GetUsersOfSimulation(c *gin.Context) {
|
||||
|
||||
simID, err := common.GetSimulationID(c)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
sim, err := FindSimulation(simID)
|
||||
if common.ProvideErrorResponse(c, err) {
|
||||
return
|
||||
}
|
||||
|
||||
// Find all users of simulation
|
||||
allUsers, _, err := user.FindAllUsersSim(&sim)
|
||||
if common.ProvideErrorResponse(c, err) {
|
||||
return
|
||||
}
|
||||
|
||||
serializer := common.UsersSerializer{c, allUsers}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"users": serializer.Response(),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// AddUserToSimulation godoc
|
||||
// @Summary Add a user to a asimulation
|
||||
// @ID AddUserToSimulation
|
||||
// @Tags simulations
|
||||
// @Produce json
|
||||
// @Success 200 "OK."
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Param simulationID path int true "Simulation ID"
|
||||
// @Param userID path int true "User ID"
|
||||
// @Router /simulations/{simulationID}/users/{userID} [put]
|
||||
func AddUserToSimulation(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "NOT implemented",
|
||||
})
|
||||
|
||||
simID, err := common.GetSimulationID(c)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
sim, err := FindSimulation(simID)
|
||||
if common.ProvideErrorResponse(c, err) {
|
||||
return
|
||||
}
|
||||
|
||||
username := c.Param("username")
|
||||
|
||||
u, err := user.FindUserByName(username)
|
||||
if common.ProvideErrorResponse(c, err) {
|
||||
return
|
||||
}
|
||||
|
||||
err = user.AddUserToSim(&sim, &u)
|
||||
if common.ProvideErrorResponse(c, err){
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "OK.",
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteUserFromSimulation godoc
|
||||
// @Summary Delete a user from asimulation
|
||||
// @ID DeleteUserFromSimulation
|
||||
// @Tags simulations
|
||||
// @Produce json
|
||||
// @Success 200 "OK."
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Param simulationID path int true "Simulation ID"
|
||||
// @Param userID path int true "User ID"
|
||||
// @Router /simulations/{simulationID}/users/{userID} [delete]
|
||||
func DeleteUserFromSimulation(c *gin.Context) {
|
||||
simID, err := common.GetSimulationID(c)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
sim, err := FindSimulation(simID)
|
||||
if common.ProvideErrorResponse(c, err) {
|
||||
return
|
||||
}
|
||||
|
||||
username := c.Param("username")
|
||||
|
||||
err = user.RemoveUserFromSim(&sim, username)
|
||||
if common.ProvideErrorResponse(c, err) {
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "OK.",
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ func RegisterSimulatorEndpoints(r *gin.RouterGroup){
|
|||
r.PUT("/:simulatorID", UpdateSimulator)
|
||||
r.GET("/:simulatorID", GetSimulator)
|
||||
r.DELETE("/:simulatorID", DeleteSimulator)
|
||||
r.POST("/:simulatorID", SendActionToSimulator)
|
||||
r.POST("/:simulatorID/action", SendActionToSimulator)
|
||||
}
|
||||
|
||||
// GetSimulators godoc
|
||||
|
@ -27,8 +27,6 @@ func RegisterSimulatorEndpoints(r *gin.RouterGroup){
|
|||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Param simulationID path int true "Simulation ID"
|
||||
// @Param modelID path int true "Model ID"
|
||||
// @Router /simulators [get]
|
||||
func GetSimulators(c *gin.Context) {
|
||||
allSimulators, _, _ := FindAllSimulators()
|
||||
|
@ -38,30 +36,95 @@ func GetSimulators(c *gin.Context) {
|
|||
})
|
||||
}
|
||||
|
||||
// AddSimulator godoc
|
||||
// @Summary Add a simulator
|
||||
// @ID AddSimulator
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Tags simulators
|
||||
// @Param inputSimulator body common.SimulatorResponse true "Simulator to be added"
|
||||
// @Success 200 "OK."
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Router /simulators [post]
|
||||
func AddSimulator(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "NOT implemented",
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// UpdateSimulator godoc
|
||||
// @Summary Update a simulator
|
||||
// @ID UpdateSimulator
|
||||
// @Tags simulators
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param inputSimulator body common.SimulatorResponse true "Simulator to be updated"
|
||||
// @Success 200 "OK."
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Param simulatorID path int true "Simulator ID"
|
||||
// @Router /simulators/{simulatorID} [put]
|
||||
func UpdateSimulator(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "NOT implemented",
|
||||
})
|
||||
}
|
||||
|
||||
// GetSimulator godoc
|
||||
// @Summary Get simulator
|
||||
// @ID GetSimulator
|
||||
// @Produce json
|
||||
// @Tags simulators
|
||||
// @Success 200 {object} common.SimulatorResponse "Simulator requested by user"
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Param simulatorID path int true "Simulator ID"
|
||||
// @Router /simulators/{simulatorID} [get]
|
||||
func GetSimulator(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "NOT implemented",
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteSimulator godoc
|
||||
// @Summary Delete a simulator
|
||||
// @ID DeleteSimulator
|
||||
// @Tags simulators
|
||||
// @Produce json
|
||||
// @Success 200 "OK."
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Param simulatorID path int true "Simulator ID"
|
||||
// @Router /simulators/{simulatorID} [delete]
|
||||
func DeleteSimulator(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "NOT implemented",
|
||||
})
|
||||
}
|
||||
|
||||
// SendActionToSimulator godoc
|
||||
// @Summary Send an action to simulator
|
||||
// @ID SendActionToSimulator
|
||||
// @Tags simulators
|
||||
// @Produce json
|
||||
// @Param inputAction query string true "Action for simulator"
|
||||
// @Success 200 "OK."
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Param simulatorID path int true "Simulator ID"
|
||||
// @Router /simulators/{simulatorID}/action [post]
|
||||
func SendActionToSimulator(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "NOT implemented",
|
||||
|
|
|
@ -6,27 +6,28 @@ import (
|
|||
"github.com/gin-gonic/gin"
|
||||
|
||||
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/common"
|
||||
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/simulation"
|
||||
)
|
||||
|
||||
|
||||
func RegisterUserEndpoints(r *gin.RouterGroup){
|
||||
r.GET("/", GetUsers)
|
||||
r.POST("/", AddUser)
|
||||
r.PUT("/:userID", UpdateUser)
|
||||
r.GET("/:userID", GetUser)
|
||||
r.GET("/:userID/simulations", GetSimulationsOfUser)
|
||||
r.DELETE("/:userID", DeleteUser)
|
||||
//r.GET("/me", userSelfEp) // TODO redirect to users/:userID
|
||||
}
|
||||
|
||||
func RegisterUserEndpointsForSimulation(r *gin.RouterGroup){
|
||||
r.GET("/:simulationID/users", GetUsersOfSimulation)
|
||||
r.PUT("/:simulationID/user/:username", UpdateUserOfSimulation)
|
||||
r.DELETE("/:simulationID/user/:username", DeleteUserOfSimulation)
|
||||
|
||||
}
|
||||
|
||||
// GetUsers godoc
|
||||
// @Summary Get all users
|
||||
// @ID GetUsers
|
||||
// @Produce json
|
||||
// @Tags users
|
||||
// @Success 200 {array} common.UserResponse "Array of users"
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Router /users [get]
|
||||
func GetUsers(c *gin.Context) {
|
||||
allUsers, _, _ := FindAllUsers()
|
||||
serializer := common.UsersSerializer{c, allUsers}
|
||||
|
@ -35,146 +36,77 @@ func GetUsers(c *gin.Context) {
|
|||
})
|
||||
}
|
||||
|
||||
// GetUsersOfSimulation godoc
|
||||
// @Summary Get users of simulation
|
||||
// @ID GetUsersOfSimulation
|
||||
// @Produce json
|
||||
// @Tags user
|
||||
// @Success 200 {array} common.UserResponse "Array of users that have access to the simulation"
|
||||
// AddUser godoc
|
||||
// @Summary Add a user
|
||||
// @ID AddUser
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Tags users
|
||||
// @Param inputUser body common.UserResponse true "User to be added"
|
||||
// @Success 200 "OK."
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Param simulationID path int true "Simulation ID"
|
||||
// @Router /simulations/{simulationID}/users [get]
|
||||
func GetUsersOfSimulation(c *gin.Context) {
|
||||
|
||||
simID, err := common.GetSimulationID(c)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
sim, err := simulation.FindSimulation(simID)
|
||||
if common.ProvideErrorResponse(c, err) {
|
||||
return
|
||||
}
|
||||
|
||||
// Find all users of simulation
|
||||
allUsers, _, err := FindAllUsersSim(&sim)
|
||||
if common.ProvideErrorResponse(c, err) {
|
||||
return
|
||||
}
|
||||
|
||||
serializer := common.UsersSerializer{c, allUsers}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"users": serializer.Response(),
|
||||
})
|
||||
}
|
||||
|
||||
// @Router /users [post]
|
||||
func AddUser(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "NOT implemented",
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateUser godoc
|
||||
// @Summary Update a user
|
||||
// @ID UpdateUser
|
||||
// @Tags users
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param inputUser body common.UserResponse true "User to be updated"
|
||||
// @Success 200 "OK."
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Param userID path int true "User ID"
|
||||
// @Router /users/{userID} [put]
|
||||
func UpdateUser(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "NOT implemented",
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateUserOfSimulation godoc
|
||||
// @Summary Add user to simulation
|
||||
// @ID UpdateUserOfSimulation
|
||||
// @Tags user
|
||||
// @Success 200 "OK."
|
||||
// GetUser godoc
|
||||
// @Summary Get user
|
||||
// @ID GetUser
|
||||
// @Produce json
|
||||
// @Tags users
|
||||
// @Success 200 {object} common.UserResponse "User requested by user"
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Param simulationID path int true "Simulation ID"
|
||||
// @Param username path int true "Username of user to be added"
|
||||
// @Router /simulations/{simulationID}/users/{username} [put]
|
||||
func UpdateUserOfSimulation(c *gin.Context) {
|
||||
|
||||
|
||||
simID, err := common.GetSimulationID(c)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
sim, err := simulation.FindSimulation(simID)
|
||||
if common.ProvideErrorResponse(c, err) {
|
||||
return
|
||||
}
|
||||
|
||||
username := c.Param("username")
|
||||
|
||||
user, err := FindUserByName(username)
|
||||
if common.ProvideErrorResponse(c, err) {
|
||||
return
|
||||
}
|
||||
|
||||
err = AddUserToSim(&sim, &user)
|
||||
if common.ProvideErrorResponse(c, err){
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "OK.",
|
||||
})
|
||||
}
|
||||
|
||||
// @Param userID path int true "User ID"
|
||||
// @Router /users/{userID} [get]
|
||||
func GetUser(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "NOT implemented",
|
||||
})
|
||||
}
|
||||
|
||||
func GetSimulationsOfUser(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "NOT implemented",
|
||||
})
|
||||
}
|
||||
|
||||
func DeleteUser(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "NOT implemented",
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteUserOfSimulation godoc
|
||||
// @Summary Delete user from simulation
|
||||
// @ID DeleteUserOfSimulation
|
||||
// @Tags user
|
||||
// DeleteUser godoc
|
||||
// @Summary Delete a user
|
||||
// @ID DeleteUser
|
||||
// @Tags users
|
||||
// @Produce json
|
||||
// @Success 200 "OK."
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Param simulationID path int true "Simulation ID"
|
||||
// @Param username path int true "Username of user"
|
||||
// @Router /simulations/{simulationID}/users/{username} [delete]
|
||||
func DeleteUserOfSimulation(c *gin.Context) {
|
||||
|
||||
simID, err := common.GetSimulationID(c)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
sim, err := simulation.FindSimulation(simID)
|
||||
if common.ProvideErrorResponse(c, err) {
|
||||
return
|
||||
}
|
||||
|
||||
username := c.Param("username")
|
||||
|
||||
err = RemoveUserFromSim(&sim, username)
|
||||
if common.ProvideErrorResponse(c, err) {
|
||||
return
|
||||
}
|
||||
|
||||
// @Param userID path int true "User ID"
|
||||
// @Router /users/{userID} [delete]
|
||||
func DeleteUser(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "OK.",
|
||||
"message": "NOT implemented",
|
||||
})
|
||||
}
|
||||
|
|
|
@ -11,15 +11,27 @@ import (
|
|||
|
||||
func RegisterVisualizationEndpoints(r *gin.RouterGroup){
|
||||
|
||||
r.GET("/:simulationID/visualizations", GetVisualizations)
|
||||
r.POST("/:simulationID/visualization", AddVisualization)
|
||||
r.POST("/:simulationID/visualization/:visualizationID", CloneVisualization)
|
||||
r.PUT("/:simulationID/visualization/:visualizationID", UpdateVisualization)
|
||||
r.GET("/:simulationID/visualization/:visualizationID", GetVisualization)
|
||||
r.DELETE("/:simulationID/visualization/:visualizationID", DeleteVisualization)
|
||||
r.GET("/", GetVisualizations)
|
||||
r.POST("/", AddVisualization)
|
||||
//r.POST("/:visualizationID", CloneVisualization)
|
||||
r.PUT("/:visualizationID", UpdateVisualization)
|
||||
r.GET("/:visualizationID", GetVisualization)
|
||||
r.DELETE("/:visualizationID", DeleteVisualization)
|
||||
|
||||
}
|
||||
|
||||
// GetVisualizations godoc
|
||||
// @Summary Get all visualizations of simulation
|
||||
// @ID GetVisualizations
|
||||
// @Produce json
|
||||
// @Tags visualizations
|
||||
// @Success 200 {array} common.VisualizationResponse "Array of visualizations to which belong to simulation"
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Param simulationID query int true "Simulation ID"
|
||||
// @Router /visualizations [get]
|
||||
func GetVisualizations(c *gin.Context) {
|
||||
|
||||
simID, err := common.GetSimulationID(c)
|
||||
|
@ -39,6 +51,19 @@ func GetVisualizations(c *gin.Context) {
|
|||
})
|
||||
}
|
||||
|
||||
// AddVisualization godoc
|
||||
// @Summary Add a visualization to a simulation
|
||||
// @ID AddVisualization
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Tags visualizations
|
||||
// @Param inputVis body common.VisualizationResponse true "Visualization to be added incl. ID of simulation"
|
||||
// @Success 200 "OK."
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Router /visualizations [post]
|
||||
func AddVisualization(c *gin.Context) {
|
||||
|
||||
simID, err := common.GetSimulationID(c)
|
||||
|
@ -76,6 +101,20 @@ func CloneVisualization(c *gin.Context) {
|
|||
})
|
||||
}
|
||||
|
||||
// UpdateVisualization godoc
|
||||
// @Summary Update a visualization
|
||||
// @ID UpdateVisualization
|
||||
// @Tags visualizations
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param inputVis body common.VisualizationResponse true "Visualization to be updated"
|
||||
// @Success 200 "OK."
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Param visualizationID path int true "Visualization ID"
|
||||
// @Router /visualizations/{visualizationID} [put]
|
||||
func UpdateVisualization(c *gin.Context) {
|
||||
|
||||
simID, err := common.GetSimulationID(c)
|
||||
|
@ -111,6 +150,18 @@ func UpdateVisualization(c *gin.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
// GetVisualization godoc
|
||||
// @Summary Get a visualization
|
||||
// @ID GetVisualization
|
||||
// @Tags visualizations
|
||||
// @Produce json
|
||||
// @Success 200 {object} common.VisualizationResponse "Requested visualization."
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Param visualizationID path int true "Visualization ID"
|
||||
// @Router /visualizations/{visualizationID} [get]
|
||||
func GetVisualization(c *gin.Context) {
|
||||
|
||||
simID, err := common.GetSimulationID(c)
|
||||
|
@ -139,6 +190,18 @@ func GetVisualization(c *gin.Context) {
|
|||
})
|
||||
}
|
||||
|
||||
// DeleteVisualization godoc
|
||||
// @Summary Delete a visualization
|
||||
// @ID DeleteVisualization
|
||||
// @Tags visualizations
|
||||
// @Produce json
|
||||
// @Success 200 "OK."
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Param visualizationID path int true "Visualization ID"
|
||||
// @Router /visualizations/{visualizationID} [delete]
|
||||
func DeleteVisualization(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "NOT implemented",
|
||||
|
|
|
@ -11,14 +11,26 @@ import (
|
|||
)
|
||||
|
||||
func RegisterWidgetEndpoints(r *gin.RouterGroup){
|
||||
r.GET("/:simulationID/visualization/:visualizationID/widgets", GetWidgets)
|
||||
r.POST("/:simulationID/visualization/:visualizationID/widget", AddWidget)
|
||||
r.POST("/:simulationID/visualization/:visualizationID/widget:widgetID", CloneWidget)
|
||||
r.PUT("/:simulationID/visualization/:visualizationID/widget/:widgetID", UpdateWidget)
|
||||
r.GET("/:simulationID/visualization/:visualizationID/widget/:widgetID", GetWidget)
|
||||
r.DELETE("/:simulationID/visualization/:visualizationID/widget/:widgetID", DeleteWidget)
|
||||
r.GET("/", GetWidgets)
|
||||
r.POST("/", AddWidget)
|
||||
//r.POST("/:widgetID", CloneWidget)
|
||||
r.PUT("/:widgetID", UpdateWidget)
|
||||
r.GET("/:widgetID", GetWidget)
|
||||
r.DELETE("/:widgetID", DeleteWidget)
|
||||
}
|
||||
|
||||
// GetWidgets godoc
|
||||
// @Summary Get all widgets of visualization
|
||||
// @ID GetWidgets
|
||||
// @Produce json
|
||||
// @Tags widgets
|
||||
// @Success 200 {array} common.WidgetResponse "Array of widgets to which belong to visualization"
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Param visualizationID query int true "Visualization ID"
|
||||
// @Router /widgets [get]
|
||||
func GetWidgets(c *gin.Context) {
|
||||
|
||||
simID, err := common.GetSimulationID(c)
|
||||
|
@ -52,6 +64,19 @@ func GetWidgets(c *gin.Context) {
|
|||
})
|
||||
}
|
||||
|
||||
// AddWidget godoc
|
||||
// @Summary Add a widget to a visualization
|
||||
// @ID AddWidget
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Tags widgets
|
||||
// @Param inputWidget body common.WidgetResponse true "Widget to be added incl. ID of visualization"
|
||||
// @Success 200 "OK."
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Router /widgets [post]
|
||||
func AddWidget(c *gin.Context) {
|
||||
|
||||
simID, err := common.GetSimulationID(c)
|
||||
|
@ -100,6 +125,20 @@ func CloneWidget(c *gin.Context) {
|
|||
})
|
||||
}
|
||||
|
||||
// UpdateWidget godoc
|
||||
// @Summary Update a widget
|
||||
// @ID UpdateWidget
|
||||
// @Tags widgets
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param inputWidget body common.WidgetResponse true "Widget to be updated"
|
||||
// @Success 200 "OK."
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Param widgetID path int true "Widget ID"
|
||||
// @Router /widgets/{widgetID} [put]
|
||||
func UpdateWidget(c *gin.Context) {
|
||||
simID, err := common.GetSimulationID(c)
|
||||
if err != nil {
|
||||
|
@ -144,6 +183,18 @@ func UpdateWidget(c *gin.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
// GetWidget godoc
|
||||
// @Summary Get a widget
|
||||
// @ID GetWidget
|
||||
// @Tags widgets
|
||||
// @Produce json
|
||||
// @Success 200 {object} common.WidgetResponse "Requested widget."
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Param widgetID path int true "Widget ID"
|
||||
// @Router /widgets/{widgetID} [get]
|
||||
func GetWidget(c *gin.Context) {
|
||||
|
||||
simID, err := common.GetSimulationID(c)
|
||||
|
@ -178,6 +229,19 @@ func GetWidget(c *gin.Context) {
|
|||
})
|
||||
}
|
||||
|
||||
|
||||
// DeleteWidget godoc
|
||||
// @Summary Delete a widget
|
||||
// @ID DeleteWidget
|
||||
// @Tags widgets
|
||||
// @Produce json
|
||||
// @Success 200 "OK."
|
||||
// @Failure 401 "Unauthorized Access"
|
||||
// @Failure 403 "Access forbidden."
|
||||
// @Failure 404 "Not found"
|
||||
// @Failure 500 "Internal server error"
|
||||
// @Param widgetID path int true "Widget ID"
|
||||
// @Router /widgets/{widgetID} [delete]
|
||||
func DeleteWidget(c *gin.Context) {
|
||||
|
||||
// simID, err := GetSimulationID(c)
|
||||
|
|
15
start.go
15
start.go
|
@ -1,13 +1,13 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/file"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/swaggo/gin-swagger"
|
||||
"github.com/swaggo/gin-swagger/swaggerFiles"
|
||||
|
||||
_ "git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/doc/autoapi" // apidocs folder is generated by Swag CLI, you have to import it
|
||||
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/common"
|
||||
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/file"
|
||||
_ "git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/doc/autoapi" // apidocs folder is generated by Swag CLI, you have to import it
|
||||
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/model"
|
||||
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/simulation"
|
||||
"git.rwth-aachen.de/acs/public/villas/villasweb-backend-go/routes/simulator"
|
||||
|
@ -32,7 +32,7 @@ import (
|
|||
// @license.url http://www.gnu.de/documents/gpl-3.0.en.html
|
||||
|
||||
// @host localhost:8080
|
||||
// @BasePath /api/v2
|
||||
// @BasePath /api
|
||||
func main() {
|
||||
// Testing
|
||||
db := common.InitDB()
|
||||
|
@ -45,11 +45,10 @@ func main() {
|
|||
|
||||
// use ginSwagger middleware to
|
||||
simulation.RegisterSimulationEndpoints(api.Group("/simulations"))
|
||||
file.RegisterFileEndpoints(api.Group("/simulations"))
|
||||
model.RegisterModelEndpoints(api.Group("/simulations"))
|
||||
visualization.RegisterVisualizationEndpoints(api.Group("/simulations"))
|
||||
widget.RegisterWidgetEndpoints(api.Group("/simulations"))
|
||||
user.RegisterUserEndpointsForSimulation(api.Group("/simulations"))
|
||||
model.RegisterModelEndpoints(api.Group("/models"))
|
||||
visualization.RegisterVisualizationEndpoints(api.Group("/visualizations"))
|
||||
widget.RegisterWidgetEndpoints(api.Group("/widgets"))
|
||||
file.RegisterFileEndpoints(api.Group("/files"))
|
||||
|
||||
user.RegisterUserEndpoints(api.Group("/users"))
|
||||
simulator.RegisterSimulatorEndpoints(api.Group("/simulators"))
|
||||
|
|
Loading…
Add table
Reference in a new issue