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

45 lines
1.5 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 CreateProviderCredentials(c *gin.Context) {
logger := c.MustGet("LOGGER").(*logrus.Entry)
databaseRepo := c.MustGet("REPOSITORY").(database.DatabaseRepository)
providerCred := models.ProviderCredential{}
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.CreateProviderCredentials(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 ListProviderCredentials(c *gin.Context) {
logger := c.MustGet("LOGGER").(*logrus.Entry)
databaseRepo := c.MustGet("REPOSITORY").(database.DatabaseRepository)
providerCredentials, err := databaseRepo.GetProviderCredentials(c)
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})
}