fasten-onprem/backend/pkg/web/handler/source.go

45 lines
1.4 KiB
Go
Raw Normal View History

2022-08-25 19:26:29 -06:00
package handler
import (
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/database"
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/models"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
"net/http"
)
func CreateSource(c *gin.Context) {
2022-08-25 19:26:29 -06:00
logger := c.MustGet("LOGGER").(*logrus.Entry)
databaseRepo := c.MustGet("REPOSITORY").(database.DatabaseRepository)
providerCred := models.Source{}
2022-08-25 19:26:29 -06:00
if err := c.ShouldBindJSON(&providerCred); err != nil {
logger.Errorln("An error occurred while parsing posted provider credential", err)
c.JSON(http.StatusBadRequest, gin.H{"success": false})
return
}
logger.Infof("Parsed Create Provider Credentials Payload: %v", providerCred)
err := databaseRepo.CreateSource(c, &providerCred)
2022-08-25 19:26:29 -06:00
if err != nil {
logger.Errorln("An error occurred while storing provider credential", err)
c.JSON(http.StatusInternalServerError, gin.H{"success": false})
return
}
c.JSON(http.StatusOK, gin.H{"success": true, "data": providerCred})
}
2022-08-27 20:34:48 -06:00
func ListSource(c *gin.Context) {
2022-08-27 20:34:48 -06:00
logger := c.MustGet("LOGGER").(*logrus.Entry)
databaseRepo := c.MustGet("REPOSITORY").(database.DatabaseRepository)
providerCredentials, err := databaseRepo.GetSources(c)
2022-08-27 20:34:48 -06:00
if err != nil {
logger.Errorln("An error occurred while storing provider credential", err)
c.JSON(http.StatusInternalServerError, gin.H{"success": false})
return
}
c.JSON(http.StatusOK, gin.H{"success": true, "data": providerCredentials})
}