-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(webapp): add go controller for packages endpoint
RHINENG-13557
- Loading branch information
Showing
4 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package controllers | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/redhatinsights/vmaas-lib/vmaas" | ||
"github.com/redhatinsights/vmaas/base/core" | ||
"github.com/redhatinsights/vmaas/base/utils" | ||
) | ||
|
||
func PackagesHandler(c *gin.Context) { | ||
if !isCacheLoaded(c) { | ||
return | ||
} | ||
pkg := c.Param("package") | ||
req := vmaas.PackagesRequest{Packages: []string{pkg}} | ||
|
||
res, err := core.VmaasAPI.Packages(&req) | ||
if err != nil { | ||
utils.LogAndRespError(c, err) | ||
return | ||
} | ||
c.JSON(http.StatusOK, res) | ||
|
||
// TODO: bump up vmaas-lib version after it's merged: | ||
} | ||
|
||
func PackagesPostHandler(c *gin.Context) { | ||
if !isCacheLoaded(c) { | ||
return | ||
} | ||
req := vmaas.PackagesRequest{} | ||
err := bindValidateJSON(c, &req) | ||
if err != nil { | ||
utils.LogAndRespBadRequest(c, err) | ||
return | ||
} | ||
|
||
pkgs, err := core.VmaasAPI.Packages(&req) | ||
if err != nil { | ||
utils.LogAndRespError(c, err) | ||
return | ||
} | ||
c.JSON(http.StatusOK, pkgs) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters