55 lines
984 B
Go
55 lines
984 B
Go
package controllers
|
|
|
|
import (
|
|
"api/database"
|
|
"api/models"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
// AddServer - Adds a server to the database
|
|
func AddCorporation(c *fiber.Ctx) error {
|
|
|
|
var data map[string]string
|
|
|
|
if err := c.BodyParser(&data); err != nil {
|
|
return fiber.ErrBadRequest
|
|
}
|
|
|
|
if data["name"] == "" || data["description"] == "" || data["id"] == "" {
|
|
return fiber.ErrBadRequest
|
|
}
|
|
|
|
corp := models.Corporation{
|
|
Name: data["name"],
|
|
Description: data["description"],
|
|
CorporationId: data["id"],
|
|
}
|
|
|
|
database.DB.Create(&corp)
|
|
|
|
if corp.ID == 0 {
|
|
return fiber.ErrNotAcceptable
|
|
}
|
|
|
|
return c.JSON(corp)
|
|
}
|
|
|
|
// GetAllServers - Returns all servers
|
|
func GetCorporation(c *fiber.Ctx) error {
|
|
|
|
u := c.Locals("user").(models.User)
|
|
|
|
id := c.Params("id")
|
|
|
|
if u.UserType != "A" {
|
|
return fiber.NewError(fiber.StatusUnauthorized, "Unauthorized: User is not admin")
|
|
}
|
|
|
|
var corp models.Corporation
|
|
|
|
database.DB.Find(&corp, "id = ?", id)
|
|
|
|
return c.JSON(corp)
|
|
}
|