Browse Source

En cours de développement

master
losyme 4 months ago
parent
commit
76f991d6dd
  1. 2
      go.mod
  2. 4
      go.sum
  3. 12
      internal/http/api/api.go
  4. 47
      internal/http/api/workflows.go

2
go.mod

@ -4,7 +4,7 @@ go 1.17
require (
forge.chapril.org/dune/jw v0.0.0-20220402171022-78a0af2d89e2
forge.chapril.org/dune/sdk v0.0.0-20220402171041-80d22f1eb7d4
forge.chapril.org/dune/sdk v0.0.0-20220402174222-056eadbd63d5
forge.chapril.org/losyme/application v0.0.0-20220318165027-1c2084a5d0d4
forge.chapril.org/losyme/cmdline v0.0.0-20220402170453-8473b9f105a6
forge.chapril.org/losyme/config v0.0.0-20220402170505-1cc5a44f9031

4
go.sum

@ -1,7 +1,7 @@
forge.chapril.org/dune/jw v0.0.0-20220402171022-78a0af2d89e2 h1:FNlXafGJUlMnaOxlMY5jKORmjS/ApOOJqYKhYxikRj0=
forge.chapril.org/dune/jw v0.0.0-20220402171022-78a0af2d89e2/go.mod h1:KKp6KuWUFgAFSFe5SEhK6zz3JcDrPELOEY1q5YIxvPs=
forge.chapril.org/dune/sdk v0.0.0-20220402171041-80d22f1eb7d4 h1:kwHD9uty2ozyFYs9r56CTdB6d3HNrqN8SAgmbxkLABE=
forge.chapril.org/dune/sdk v0.0.0-20220402171041-80d22f1eb7d4/go.mod h1:9mnwUZ8msvqLZ5KVVzcqWzOEG1G3NbDCuk8pJjbScYo=
forge.chapril.org/dune/sdk v0.0.0-20220402174222-056eadbd63d5 h1:0viRQfyrTxGrBkwlQejOG82P2Ray0/BD6QB8qwFjyv0=
forge.chapril.org/dune/sdk v0.0.0-20220402174222-056eadbd63d5/go.mod h1:9mnwUZ8msvqLZ5KVVzcqWzOEG1G3NbDCuk8pJjbScYo=
forge.chapril.org/losyme/application v0.0.0-20220318165027-1c2084a5d0d4 h1:6m40mSnKlfdYq0OlzWRWacxdYn37D4S/lkR4gz6Y+Hs=
forge.chapril.org/losyme/application v0.0.0-20220318165027-1c2084a5d0d4/go.mod h1:uyAFfy0yGgNMG+PTGsQKCbLYlsAC0Zvf/T0IuEE2UYs=
forge.chapril.org/losyme/breaker v0.0.0-20220303162905-537603f2067c/go.mod h1:1vBH8Q+vML8EBZj1Pvcpzxx+eEBK+f24QzcXT5Bo+MY=

12
internal/http/api/api.go

@ -51,10 +51,14 @@ func Setup(cs *components.Components) error {
g.Get("/status", api.status)
g.Get("/state", api.state)
g.New("/jobs", func(jobs *router.Group) { // /api/jobs..........................................................
jobs.Get("/next/:namespace", api.nextJob)
jobs.Post("", api.createJob)
jobs.Put("", api.updateJob)
g.New("/jobs", func(g *router.Group) { // /api/jobs.............................................................
g.Get("/next/:namespace", api.nextJob)
g.Post("", api.createJob)
g.Put("", api.updateJob)
})
g.New("/workflows", func(g *router.Group) { // /api/workflows...................................................
g.Post("", api.createWorkflow)
})
})

47
internal/http/api/workflows.go

@ -0,0 +1,47 @@
/*
------------------------------------------------------------------------------------------------------------------------
####### dune ####### Copyright (c) 2021-2022 losyme ################################################ MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package api
import (
"errors"
"net/http"
"forge.chapril.org/dune/jw"
"forge.chapril.org/losyme/kong/context"
"forge.chapril.org/losyme/kong/decode"
"forge.chapril.org/dune/dune/internal/model"
)
func (api *API) createWorkflow(c *context.Context) error {
wf := new(jw.Workflow)
if err := decode.JSON(c, 1024*32, wf); err != nil { // @FIXME
return err
}
if wf.ID == "" {
wf.ID = c.RequestID()
}
wf, err := api.cs.Model().CreateWorkflow(wf)
if err != nil {
status := http.StatusInternalServerError
if errors.Is(err, model.ErrValidation) {
status = http.StatusBadRequest
}
return c.Error(status, err)
}
return c.Render(http.StatusCreated, wf)
}
/*
######################################################################################################## @(°_°)@ #######
*/
Loading…
Cancel
Save