Skip to content

Commit

Permalink
fix integration tests, upgrade pkg registration, fix controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
krustowski committed Jun 19, 2024
1 parent 04dcfdd commit 40f8664
Show file tree
Hide file tree
Showing 16 changed files with 54 additions and 56 deletions.
2 changes: 1 addition & 1 deletion cmd/swis-api/main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @title swis-api (swapi) v5
// @version 5.16.3
// @version 5.16.4
// @description sakalWeb Information System v5 RESTful API documentation
// @termsOfService http://swagger.io/terms/

Expand Down
2 changes: 1 addition & 1 deletion deployments/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ volumes:

services:
swis-api-prod:
image: ${DOCKER_IMAGE_TAG}
image: ${REGISTRY}${DOCKER_IMAGE_TAG}
container_name: ${DOCKER_CONTAINER_NAME}
build:
context: ..
Expand Down
6 changes: 3 additions & 3 deletions pkg/alvax/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func GetConfigs(ctx *gin.Context) {
// @Success 200 {object} alvax.ConfigRoot
// @Router /alvax/{key} [get]
func GetConfigByKey(ctx *gin.Context) {
core.PrintItemByParam[ConfigRoot](ctx, Cache, pkgName)
core.PrintItemByParam[ConfigRoot](ctx, Cache, pkgName, ConfigRoot{})
return
}

Expand All @@ -51,7 +51,7 @@ func GetConfigByKey(ctx *gin.Context) {
// @Success 200 {object} alvax.ConfigRoot
// @Router /alvax/{key} [post]
func PostNewConfigByKey(ctx *gin.Context) {
core.AddNewItemByParam[ConfigRoot](ctx, Cache, pkgName)
core.AddNewItemByParam[ConfigRoot](ctx, Cache, pkgName, ConfigRoot{})
return
}

Expand All @@ -63,7 +63,7 @@ func PostNewConfigByKey(ctx *gin.Context) {
// @Success 200 {object} alvax.ConfigRoot
// @Router /alvax/{key} [put]
func UpdateConfigByKey(ctx *gin.Context) {
core.UpdateItemByParam[ConfigRoot](ctx, Cache, pkgName)
core.UpdateItemByParam[ConfigRoot](ctx, Cache, pkgName, ConfigRoot{})
return
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/backups/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func GetBackups(ctx *gin.Context) {
// @Success 200 {string} string "ok"
// @Router /backups/{key} [get]
func GetBackedupStatusByServiceKey(ctx *gin.Context) {
core.PrintItemByParam[Backup](ctx, Cache, pkgName)
core.PrintItemByParam[Backup](ctx, Cache, pkgName, Backup{})
return
}

Expand All @@ -52,7 +52,7 @@ func GetBackedupStatusByServiceKey(ctx *gin.Context) {
// @Success 200 {object} backups.Backup
// @Router /backups/{key} [post]
func PostBackedupServiceByServiceKey(ctx *gin.Context) {
core.AddNewItemByParam[Backup](ctx, Cache, pkgName)
core.AddNewItemByParam[Backup](ctx, Cache, pkgName, Backup{})
return
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/business/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func GetBusinessEntities(ctx *gin.Context) {
// @Success 200 {object} business.Business
// @Router /business/{key} [get]
func GetBusinessByKey(ctx *gin.Context) {
core.PrintItemByParam[Business](ctx, Cache, pkgName)
core.PrintItemByParam[Business](ctx, Cache, pkgName, Business{})
return
}

Expand All @@ -49,7 +49,7 @@ func GetBusinessByKey(ctx *gin.Context) {
// @Success 200 {object} business.Business
// @Router /business/{key} [post]
func PostBusinessByKey(ctx *gin.Context) {
core.AddNewItemByParam[Business](ctx, Cache, pkgName)
core.AddNewItemByParam[Business](ctx, Cache, pkgName, Business{})
return
}

Expand All @@ -61,7 +61,7 @@ func PostBusinessByKey(ctx *gin.Context) {
// @Success 200 {object} business.Business
// @Router /business/{key} [put]
func UpdateBusinessByKey(ctx *gin.Context) {
core.UpdateItemByParam[Business](ctx, Cache, pkgName)
core.UpdateItemByParam[Business](ctx, Cache, pkgName, Business{})
return
}

Expand Down
10 changes: 3 additions & 7 deletions pkg/core/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func PrintAllRootItems(ctx *gin.Context, cache *Cache, pkgName string) {
return
}

func PrintItemByParam[T any](ctx *gin.Context, cache *Cache, pkgName string) {
func PrintItemByParam[T any](ctx *gin.Context, cache *Cache, pkgName string, model T) {
key := ctx.Param("key")

rawItem, ok := cache.Get(key)
Expand Down Expand Up @@ -62,12 +62,10 @@ func PrintItemByParam[T any](ctx *gin.Context, cache *Cache, pkgName string) {
return
}

func AddNewItemByParam[T any](ctx *gin.Context, cache *Cache, pkgName string) {
func AddNewItemByParam[T any](ctx *gin.Context, cache *Cache, pkgName string, model T) {
//key := model.Name | model.ID
key := ctx.Param("key")

model := new(T)

if err := ctx.BindJSON(&model); err != nil {
ctx.IndentedJSON(http.StatusBadRequest, gin.H{
"code": http.StatusBadRequest,
Expand Down Expand Up @@ -110,7 +108,7 @@ func AddNewItemByParam[T any](ctx *gin.Context, cache *Cache, pkgName string) {
return
}

func UpdateItemByParam[T any](ctx *gin.Context, cache *Cache, pkgName string) {
func UpdateItemByParam[T any](ctx *gin.Context, cache *Cache, pkgName string, model T) {
key := ctx.Param("key")

if _, found := cache.Get(key); !found {
Expand All @@ -123,8 +121,6 @@ func UpdateItemByParam[T any](ctx *gin.Context, cache *Cache, pkgName string) {
return
}

model := new(T)

if err := ctx.BindJSON(&model); err != nil {
ctx.IndentedJSON(http.StatusBadRequest, gin.H{
"code": http.StatusBadRequest,
Expand Down
6 changes: 3 additions & 3 deletions pkg/depots/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func GetAllDepotItems(ctx *gin.Context) {
// @Success 200 {object} depots.DepotItem
// @Router /depots/items/{key} [get]
func GetDepotItemByKey(ctx *gin.Context) {
core.PrintItemByParam[DepotItem](ctx, Cache, pkgName)
core.PrintItemByParam[DepotItem](ctx, Cache, pkgName, DepotItem{})
return
}

Expand All @@ -57,7 +57,7 @@ func GetDepotItemByKey(ctx *gin.Context) {
// @Success 200 {object} depots.DepotItem
// @Router /depots/items/{key} [post]
func PostNewDepotItemByKey(ctx *gin.Context) {
core.AddNewItemByParam[DepotItem](ctx, Cache, pkgName)
core.AddNewItemByParam[DepotItem](ctx, Cache, pkgName, DepotItem{})
return
}

Expand All @@ -69,7 +69,7 @@ func PostNewDepotItemByKey(ctx *gin.Context) {
// @Success 200 {object} depots.DepotItem
// @Router /depots/items/{key} [put]
func UpdateDepotItemByKey(ctx *gin.Context) {
core.UpdateItemByParam[DepotItem](ctx, Cache, pkgName)
core.UpdateItemByParam[DepotItem](ctx, Cache, pkgName, DepotItem{})
return
}

Expand Down
10 changes: 6 additions & 4 deletions pkg/dish/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func GetSocketList(ctx *gin.Context) {
// @Success 200 {object} dish.Socket
// @Router /dish/sockets/{key} [post]
func PostNewSocketByKey(ctx *gin.Context) {
core.AddNewItemByParam[Socket](ctx, CacheSockets, pkgName)
core.AddNewItemByParam[Socket](ctx, CacheSockets, pkgName, Socket{})
return
}

Expand All @@ -68,7 +68,7 @@ func PostNewSocketByKey(ctx *gin.Context) {
// @Success 200 {object} dish.Socket
// @Router /dish/sockets/{key} [put]
func UpdateSocketByKey(ctx *gin.Context) {
core.UpdateItemByParam[Socket](ctx, CacheSockets, pkgName)
core.UpdateItemByParam[Socket](ctx, CacheSockets, pkgName, Socket{})
return
}

Expand Down Expand Up @@ -244,7 +244,9 @@ func BatchPostHealthyStatus(ctx *gin.Context) {
}

// emit an server-sent event to subscribers
Dispatcher.NewMessage(msg)
if Dispatcher != nil {
Dispatcher.NewMessage(msg)
}
}
}

Expand Down Expand Up @@ -566,7 +568,7 @@ func PostNewIncident(ctx *gin.Context) {
// @Failure 500 {object} dish.Incident
// @Router /dish/incidents/{key} [put]
func UpdateIncidentByKey(ctx *gin.Context) {
core.UpdateItemByParam[Incident](ctx, CacheIncidents, pkgName)
core.UpdateItemByParam[Incident](ctx, CacheIncidents, pkgName, Incident{})
return
}

Expand Down
12 changes: 6 additions & 6 deletions pkg/finance/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func GetAccounts(ctx *gin.Context) {
// @Success 200 {object} finance.Account
// @Router /finance/accounts/{key} [post]
func PostNewAccountByKey(ctx *gin.Context) {
core.AddNewItemByParam[Account](ctx, CacheAccounts, pkgName)
core.AddNewItemByParam[Account](ctx, CacheAccounts, pkgName, Account{})
return
}

Expand All @@ -60,7 +60,7 @@ func PostNewAccountByKey(ctx *gin.Context) {
// @Success 200 {object} finance.Account
// @Router /finance/accounts/{key} [get]
func GetAccountByKey(ctx *gin.Context) {
core.PrintItemByParam[Account](ctx, CacheAccounts, pkgName)
core.PrintItemByParam[Account](ctx, CacheAccounts, pkgName, Account{})
return
}

Expand All @@ -72,7 +72,7 @@ func GetAccountByKey(ctx *gin.Context) {
// @Success 200 {object} finance.Account
// @Router /finance/accounts/{key} [put]
func UpdateAccountByKey(ctx *gin.Context) {
core.UpdateItemByParam[Account](ctx, CacheAccounts, pkgName)
core.UpdateItemByParam[Account](ctx, CacheAccounts, pkgName, Account{})
return
}

Expand Down Expand Up @@ -149,7 +149,7 @@ func GetItems(ctx *gin.Context) {
// @Success 200 {object} finance.Item
// @Router /finance/items/{key} [post]
func PostNewItemByKey(ctx *gin.Context) {
core.AddNewItemByParam[Item](ctx, CacheItems, pkgName)
core.AddNewItemByParam[Item](ctx, CacheItems, pkgName, Item{})
return
}

Expand All @@ -160,7 +160,7 @@ func PostNewItemByKey(ctx *gin.Context) {
// @Success 200 {object} finance.Item
// @Router /finance/items/{key} [get]
func GetItemByKey(ctx *gin.Context) {
core.PrintItemByParam[Item](ctx, CacheItems, pkgName)
core.PrintItemByParam[Item](ctx, CacheItems, pkgName, Item{})
return
}

Expand All @@ -172,7 +172,7 @@ func GetItemByKey(ctx *gin.Context) {
// @Success 200 {object} finance.Item
// @Router /finance/items/{key} [put]
func UpdateItemByKey(ctx *gin.Context) {
core.UpdateItemByParam[Item](ctx, CacheItems, pkgName)
core.UpdateItemByParam[Item](ctx, CacheItems, pkgName, Item{})
return
}

Expand Down
18 changes: 9 additions & 9 deletions pkg/infra/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func GetDomains(ctx *gin.Context) {
// @Success 200 {object} infra.Domain
// @Router /infra/domains/{key} [get]
func GetDomainByKey(ctx *gin.Context) {
core.PrintItemByParam[Domain](ctx, CacheDomains, pkgName)
core.PrintItemByParam[Domain](ctx, CacheDomains, pkgName, Domain{})
return
}

Expand All @@ -82,7 +82,7 @@ func GetDomainByKey(ctx *gin.Context) {
// @Success 200 {object} infra.Domain
// @Router /infra/domains/{key} [post]
func PostNewDomainByKey(ctx *gin.Context) {
core.AddNewItemByParam[Domain](ctx, CacheDomains, pkgName)
core.AddNewItemByParam[Domain](ctx, CacheDomains, pkgName, Domain{})
return
}

Expand All @@ -94,7 +94,7 @@ func PostNewDomainByKey(ctx *gin.Context) {
// @Success 200 {object} infra.Domain
// @Router /infra/domains/{key} [put]
func UpdateDomainByKey(ctx *gin.Context) {
core.UpdateItemByParam[Domain](ctx, CacheDomains, pkgName)
core.UpdateItemByParam[Domain](ctx, CacheDomains, pkgName, Domain{})
return
}

Expand Down Expand Up @@ -218,7 +218,7 @@ func GetHosts(ctx *gin.Context) {
// @Success 200 {object} infra.Host
// @Router /infra/hosts/{key} [get]
func GetHostByKey(ctx *gin.Context) {
core.PrintItemByParam[Host](ctx, CacheHosts, pkgName)
core.PrintItemByParam[Host](ctx, CacheHosts, pkgName, Host{})
return
}

Expand Down Expand Up @@ -518,7 +518,7 @@ func PostHostFactsByKey(ctx *gin.Context) {
// @Success 200 {object} infra.Host
// @Router /infra/hosts/{key} [post]
func PostNewHostByKey(ctx *gin.Context) {
core.AddNewItemByParam[Host](ctx, CacheHosts, pkgName)
core.AddNewItemByParam[Host](ctx, CacheHosts, pkgName, Host{})
return
}

Expand All @@ -530,7 +530,7 @@ func PostNewHostByKey(ctx *gin.Context) {
// @Success 200 {object} infra.Host
// @Router /infra/hosts/{key} [put]
func UpdateHostByKey(ctx *gin.Context) {
core.UpdateItemByParam[Host](ctx, CacheHosts, pkgName)
core.UpdateItemByParam[Host](ctx, CacheHosts, pkgName, Host{})
return
}

Expand Down Expand Up @@ -570,7 +570,7 @@ func GetNetworks(ctx *gin.Context) {
// @Success 200 {object} infra.Network
// @Router /infra/networks/{key} [get]
func GetNetworkByKey(ctx *gin.Context) {
core.PrintItemByParam[Network](ctx, CacheNetworks, pkgName)
core.PrintItemByParam[Network](ctx, CacheNetworks, pkgName, Network{})
return
}

Expand All @@ -582,7 +582,7 @@ func GetNetworkByKey(ctx *gin.Context) {
// @Success 200 {object} infra.Network
// @Router /infra/networks/{key} [post]
func PostNewNetworkByKey(ctx *gin.Context) {
core.AddNewItemByParam[Network](ctx, CacheNetworks, pkgName)
core.AddNewItemByParam[Network](ctx, CacheNetworks, pkgName, Network{})
return
}

Expand All @@ -594,7 +594,7 @@ func PostNewNetworkByKey(ctx *gin.Context) {
// @Success 200 {object} infra.Network
// @Router /infra/networks/{key} [put]
func UpdateNetworkByKey(ctx *gin.Context) {
core.UpdateItemByParam[Network](ctx, CacheNetworks, pkgName)
core.UpdateItemByParam[Network](ctx, CacheNetworks, pkgName, Network{})
return
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/links/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func GetLinks(ctx *gin.Context) {
// @Success 200 {object} links.Link
// @Router /links/{key} [get]
func GetLinkByKey(ctx *gin.Context) {
core.PrintItemByParam[Link](ctx, Cache, pkgName)
core.PrintItemByParam[Link](ctx, Cache, pkgName, Link{})
return
}

Expand All @@ -54,7 +54,7 @@ func GetLinkByKey(ctx *gin.Context) {
// @Success 200 {object} links.Link
// @Router /links/{key} [post]
func PostNewLinkByKey(ctx *gin.Context) {
core.AddNewItemByParam[Link](ctx, Cache, pkgName)
core.AddNewItemByParam[Link](ctx, Cache, pkgName, Link{})
return
}

Expand All @@ -77,7 +77,7 @@ func PostDumpRestore(ctx *gin.Context) {
// @Success 200 {object} links.Link
// @Router /links/{key} [put]
func UpdateLinkByKey(ctx *gin.Context) {
core.UpdateItemByParam[Link](ctx, Cache, pkgName)
core.UpdateItemByParam[Link](ctx, Cache, pkgName, Link{})
return
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/news/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func GetSources(ctx *gin.Context) {
// @Success 200 {object} news.Source
// @Router /news/sources/{key} [get]
func GetSourcesByUserKey(ctx *gin.Context) {
core.PrintItemByParam[[]Source](ctx, Cache, pkgName)
core.PrintItemByParam[[]Source](ctx, Cache, pkgName, []Source{})
return
}

Expand All @@ -55,7 +55,7 @@ func GetSourcesByUserKey(ctx *gin.Context) {
// @Success 200 {object} news.Source
// @Router /news/sources/{key} [post]
func PostNewSourcesByUserKey(ctx *gin.Context) {
core.AddNewItemByParam[[]Source](ctx, Cache, pkgName)
core.AddNewItemByParam[[]Source](ctx, Cache, pkgName, []Source{})
return
}

Expand All @@ -67,7 +67,7 @@ func PostNewSourcesByUserKey(ctx *gin.Context) {
// @Success 200 {object} news.Source
// @Router /news/sources/{key} [put]
func UpdateSourcesByUserKey(ctx *gin.Context) {
core.UpdateItemByParam[[]Source](ctx, Cache, pkgName)
core.UpdateItemByParam[[]Source](ctx, Cache, pkgName, []Source{})
return
}

Expand Down
Loading

0 comments on commit 40f8664

Please sign in to comment.