Added two routes to get all and one admiralty targets from kube

This commit is contained in:
pb
2025-02-20 12:46:24 +01:00
parent 3c313171c3
commit d26f0d6b1b
3 changed files with 95 additions and 2 deletions

View File

@@ -1,6 +1,9 @@
package controllers
import (
"oc-datacenter/infrastructure"
"slices"
beego "github.com/beego/beego/v2/server/web"
)
@@ -11,8 +14,47 @@ type AdmiraltyController struct {
// @Title GetAllTargets
// @Description find all Admiralty Target
// @Success 200 {booking} models.booking
// @router /admiralty/targets [get]
// @Success 200
// @router /targets [get]
func (c *AdmiraltyController) GetAllTargets() {
serv, err := infrastructure.NewService()
if err != nil {
// change code to 500
c.Ctx.Output.SetStatus(500)
c.ServeJSON()
c.Data["json"] = map[string]string{"error": err.Error()}
return
}
res, err := serv.GetTargets(c.Ctx.Request.Context())
c.Data["json"] = res
c.ServeJSON()
}
// @Title GetOneTarget
// @Description find one Admiralty Target
// @Param id path string true "the name of the target to get"
// @Success 200
// @router /targets/:id [get]
func (c *AdmiraltyController) GetOneTarget() {
id := c.Ctx.Input.Param(":id")
serv, err := infrastructure.NewService()
if err != nil {
// change code to 500
c.Ctx.Output.SetStatus(500)
c.ServeJSON()
c.Data["json"] = map[string]string{"error": err.Error()}
return
}
res, err := serv.GetTargets(c.Ctx.Request.Context())
id = "target-"+id
found := slices.Contains(res,id)
if !found {
c.Ctx.Output.SetStatus(404)
c.ServeJSON()
}
c.Data["json"] = id
c.ServeJSON()
}