Skip to content

Commit

Permalink
improve and fix infra pkg data restoration, finish redesign
Browse files Browse the repository at this point in the history
  • Loading branch information
krustowski committed Jan 30, 2024
1 parent 7d3eed8 commit f28df81
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

APP_NAME=swis-api
APP_ROOT=/opt/${APP_NAME}
APP_VERSION=5.8.6
APP_VERSION=5.9.0


#
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @title swis-api (swapi) v5
// @version 5.8.6
// @version 5.9.0
// @description sakalWeb Information System v5 RESTful API documentation
// @termsOfService http://swagger.io/terms/

Expand Down
29 changes: 24 additions & 5 deletions pkg/infra/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
)

var (
//infrastructure = Infrastructure{}
CacheHosts *core.Cache
CacheNetworks *core.Cache
CacheDomains *core.Cache
Expand All @@ -33,7 +32,6 @@ func GetInfrastructure(ctx *gin.Context) {
"domains": domains,
"hosts": hosts,
"networks": networks,
//"infrastructure": infrastructure,
})
}

Expand Down Expand Up @@ -254,21 +252,42 @@ func DeleteNetworkByKey(ctx *gin.Context) {
// @Router /infra/restore [post]
// PostDumpRestore
func PostDumpRestore(ctx *gin.Context) {
var importInfrastructure Infrastructures
var counter []int = []int{0, 0, 0}

if err := ctx.BindJSON(&importInfrastructure); err != nil {
var importInfra = struct {
Domains map[string]Domain `json:"domains"`
Hosts map[string]Host `json:"hosts"`
Networks map[string]Network `json:"networks"`
}{}

if err := ctx.BindJSON(&importInfra); err != nil {
ctx.JSON(http.StatusBadRequest, gin.H{
"code": http.StatusBadRequest,
"error": err.Error(),
"message": "cannot parse input JSON stream",
})
return
}

//infrastructure = importInfrastructure.Infrastructure
for key, item := range importInfra.Domains {
CacheDomains.Set(key, item)
counter[0]++
}

for key, item := range importInfra.Hosts {
CacheHosts.Set(key, item)
counter[1]++
}

for key, item := range importInfra.Networks {
CacheNetworks.Set(key, item)
counter[2]++
}

// HTTP 201 Created
ctx.IndentedJSON(http.StatusCreated, gin.H{
"code": http.StatusCreated,
"counter": counter,
"message": "infrastrcture imported successfully",
})
}

0 comments on commit f28df81

Please sign in to comment.