Skip to content

Commit

Permalink
deployer: use user_id for records
Browse files Browse the repository at this point in the history
  • Loading branch information
inciner8r committed Apr 22, 2024
1 parent ad3184a commit dd772f4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
12 changes: 6 additions & 6 deletions api/v1/deployer/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func ApplyRoutes(r *gin.RouterGroup) {
func Deploy(c *gin.Context) {
db := dbconfig.GetDb()
walletAddress := c.GetString(paseto.CTX_WALLET_ADDRESS)
userId := c.GetString(paseto.CTX_USER_ID)
fmt.Println(walletAddress)

var count int64
Expand Down Expand Up @@ -108,6 +109,7 @@ func Deploy(c *gin.Context) {
FirewallEndpoint: fwEndpoint,
Password: string(req.Password),
Firewall: string(req.Firewall),
UserId: userId,
}
result := db.Create(&instance)
if result.Error != nil {
Expand All @@ -123,26 +125,24 @@ func Deploy(c *gin.Context) {

func getMyDeployments(c *gin.Context) {
db := dbconfig.GetDb()
walletAddress := c.GetString(paseto.CTX_WALLET_ADDRESS)
userId := c.GetString(paseto.CTX_USER_ID)
var instances []models.Sotreus
if err := db.Model(&models.Sotreus{}).Where("wallet_address = ?", walletAddress).Find(&instances).Error; err != nil {
if err := db.Model(&models.Sotreus{}).Where("user_id = ?", userId).Find(&instances).Error; err != nil {
logwrapper.Errorf("failed to fetch DB : %s", err)
httpo.NewErrorResponse(http.StatusInternalServerError, "failed to fetch DB").SendD(c)
return

}
httpo.NewSuccessResponseP(200, "VPN's fetched successfully", instances).SendD(c)

}

func deleteDeployment(c *gin.Context) {
db := dbconfig.GetDb()
walletAddress := c.GetString(paseto.CTX_WALLET_ADDRESS)
userId := c.GetString(paseto.CTX_USER_ID)
sotreusName := c.Query("id")
fmt.Println(walletAddress)

var instance models.Sotreus
err := db.Model(&models.Sotreus{}).Where("wallet_address = ? and name = ?", walletAddress, sotreusName).First(&instance).Error
err := db.Model(&models.Sotreus{}).Where("user_id = ? and name = ?", userId, sotreusName).First(&instance).Error
if err != nil {
logwrapper.Errorf("failed to fetch data from database: %s", err)
httpo.NewErrorResponse(http.StatusInternalServerError, err.Error()).SendD(c)
Expand Down
1 change: 1 addition & 0 deletions models/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package models
type Sotreus struct {
Name string `gorm:"primary_key" json:"name"`
WalletAddress string `json:"walletAddress"`
UserId string `json:"userId,omitempty"`
Region string `json:"region"`
VpnEndpoint string `json:"VpnEndpoint"`
FirewallEndpoint string `json:"firewallEndpoint"`
Expand Down

0 comments on commit dd772f4

Please sign in to comment.