33 lines
1.1 KiB
Go
33 lines
1.1 KiB
Go
package routers
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"net/http"
|
|
"serverctl/pkg/api/middleware"
|
|
"serverctl/pkg/infrastructure/dependencies"
|
|
)
|
|
|
|
func applicationsRouter(router *gin.Engine, d *dependencies.Dependencies) {
|
|
applications := router.Group("/applications", middleware.BasicAuthMiddleware(d.Logger, d.UsersService))
|
|
applications.POST("/", func(c *gin.Context) {
|
|
type CreateApplicationRequest struct {
|
|
ProjectId int `json:"projectId" binding:"required"`
|
|
Name string `json:"name" binding:"required"`
|
|
}
|
|
|
|
var createApplicationRequest CreateApplicationRequest
|
|
if err := c.BindJSON(&createApplicationRequest); err != nil {
|
|
return
|
|
}
|
|
|
|
userId, _ := c.Get("userId")
|
|
applicationId, err := d.ApplicationsService.CreateApplication(c.Request.Context(), createApplicationRequest.Name, userId.(int), createApplicationRequest.ProjectId)
|
|
if err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"message": "you have provided invalid input"})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusCreated, gin.H{"message": "application has been created", "applicationId": applicationId})
|
|
})
|
|
}
|