Prechádzať zdrojové kódy

Configure ProductionPlan endpoint and handle computation in
specific spoptim package.

Aurelien 5 rokov pred
rodič
commit
00d4bd42ca
2 zmenil súbory, kde vykonal 17 pridanie a 0 odobranie
  1. 5 0
      restapi/configure_spaas.go
  2. 12 0
      spoptim/production_planner.go

+ 5 - 0
restapi/configure_spaas.go

@@ -11,6 +11,7 @@ import (
 	"github.com/go-openapi/runtime/middleware"
 
 	"gem-spaas-coding-challenge/restapi/operations"
+	"gem-spaas-coding-challenge/spoptim"
 )
 
 //go:generate swagger generate server --target ../../gem-spaas-coding-challenge --name Spaas --spec ../swagger.yml --principal interface{}
@@ -37,6 +38,10 @@ func configureAPI(api *operations.SpaasAPI) http.Handler {
 
 	api.JSONProducer = runtime.JSONProducer()
 
+    api.ProductionPlanHandler = operations.ProductionPlanHandlerFunc(func(params operations.ProductionPlanParams) middleware.Responder {
+            return operations.NewProductionPlanOK().WithPayload(spoptim.ProductionPlanner(params.PayloadFormat))
+    })
+
 	if api.ProductionPlanHandler == nil {
 		api.ProductionPlanHandler = operations.ProductionPlanHandlerFunc(func(params operations.ProductionPlanParams) middleware.Responder {
 			return middleware.NotImplemented("operation operations.ProductionPlan has not yet been implemented")

+ 12 - 0
spoptim/production_planner.go

@@ -0,0 +1,12 @@
+package spoptim
+
+import (
+	"gem-spaas-coding-challenge/models"
+)
+
+func ProductionPlanner(payload *models.Payload) []interface{} {
+    return []interface{}{map[string]interface{}{"name": "windpark1", "p": 75},
+        map[string]interface{}{"name": "windpark2", "p": 25},
+        map[string]interface{}{"name": "gasfiredbig1", "p": 200}}
+}
+