Browse Source

En cours de développement

master
mls-361 5 months ago
parent
commit
a83b40a464
  1. 2
      go.mod
  2. 4
      go.sum
  3. 29
      internal/api/api.go

2
go.mod

@ -11,7 +11,7 @@ require (
forge.chapril.org/mls-361/application v0.0.0-20210507222412-1e7c647c76cd
forge.chapril.org/mls-361/crypto v0.0.0-20210507222429-aa9bfa212956
forge.chapril.org/mls-361/errors v0.0.0-20210507222244-6017b9315140
forge.chapril.org/mls-361/jsonapi v0.0.0-20210507233050-94d433fd6f49
forge.chapril.org/mls-361/jsonapi v0.0.0-20210507235532-6f8ca43c1463
forge.chapril.org/mls-361/logger v0.0.0-20210507222454-9faceb920b06
forge.chapril.org/mls-361/uuid v0.0.0-20210411123640-49d47af267ff
github.com/julienschmidt/httprouter v1.3.0

4
go.sum

@ -20,8 +20,8 @@ forge.chapril.org/mls-361/errors v0.0.0-20210507222244-6017b9315140 h1:uBp4Uz62/
forge.chapril.org/mls-361/errors v0.0.0-20210507222244-6017b9315140/go.mod h1:GBBbrcpLm0Hww05AoFQJY3tTXbNBOQPqV+qTFEWpL20=
forge.chapril.org/mls-361/fqdn v0.0.0-20210507222326-a85c3c19b9af h1:TbPVsBz8TYVmyqcrskFWlheyapWsuNrCVd6HedWuRjc=
forge.chapril.org/mls-361/fqdn v0.0.0-20210507222326-a85c3c19b9af/go.mod h1:AFGBvcK+UEZ9riVN+xN0suL8mVhBrxQIMKK39EX434s=
forge.chapril.org/mls-361/jsonapi v0.0.0-20210507233050-94d433fd6f49 h1:1xVla5UwrjxgR9rMTsTLwYe3ntv+kTq9G0EVihVT+W0=
forge.chapril.org/mls-361/jsonapi v0.0.0-20210507233050-94d433fd6f49/go.mod h1:h7tNGoefr353rJRCt3O5fOMSMCfD8xzMX/ADulKMdq8=
forge.chapril.org/mls-361/jsonapi v0.0.0-20210507235532-6f8ca43c1463 h1:i/vUEM88RqWk9S5q64ugtOLXIVzc6Jq3YE1QXD5eELM=
forge.chapril.org/mls-361/jsonapi v0.0.0-20210507235532-6f8ca43c1463/go.mod h1:h7tNGoefr353rJRCt3O5fOMSMCfD8xzMX/ADulKMdq8=
forge.chapril.org/mls-361/kvfmt v0.0.0-20210507213839-4f18d8b29e73 h1:OKwxmpmkdhy9SWwZcJrz7Fp57LWpY/PNloHdFiDc4Ek=
forge.chapril.org/mls-361/kvfmt v0.0.0-20210507213839-4f18d8b29e73/go.mod h1:bv44R0CAd8lQV4ub1hjLE3kWYwpfsW4Ro9zRnD4YOMU=
forge.chapril.org/mls-361/logger v0.0.0-20210507222454-9faceb920b06 h1:8+774tb3VA3VOgzM5I42JqXUqCRf/q9sMsEwuTqEXuM=

29
internal/api/api.go

@ -7,11 +7,11 @@
package api
import (
"errors"
"net/http"
"forge.chapril.org/armen/jw"
"forge.chapril.org/armen/model"
"forge.chapril.org/mls-361/errors"
"forge.chapril.org/mls-361/jsonapi"
"forge.chapril.org/mls-361/uuid"
@ -35,6 +35,10 @@ func newAPI(ccs *components.Components) *api {
}
}
func (api *api) middleware(hf jsonapi.HandlerFunc) jsonapi.Handler {
return middleware.Trace(hf, api.logger)
}
func (api *api) createJob(r *jsonapi.Request) {
job := new(jw.Job)
@ -54,15 +58,31 @@ func (api *api) createJob(r *jsonapi.Request) {
}
if job == nil {
r.RenderOK()
r.RenderNoContent()
return
}
r.RenderJSON(http.StatusCreated, job, api.logger)
}
func (api *api) middleware(hf jsonapi.HandlerFunc) jsonapi.Handler {
return middleware.Trace(hf, api.logger)
func (api *api) nextJob(r *jsonapi.Request) {
namespace := r.Param("namespace")
if namespace == "" {
r.BadRequest(errors.New("namespace must not be empty")) ////////////////////////////////////////////////////////
}
job, err := api.model.NextJob(namespace)
if err != nil {
r.InternalServerError(err)
return
}
if job == nil {
r.RenderNoContent()
return
}
r.RenderJSON(http.StatusOK, job, api.logger)
}
func Build(ccs *components.Components) {
@ -75,6 +95,7 @@ func Build(ccs *components.Components) {
}))
router.Post("/job/create", api.middleware(api.createJob))
router.Get("/job/next/:namespace", api.middleware(api.nextJob))
}
/*

Loading…
Cancel
Save