Skip to content

Commit

Permalink
feat: link ownerID to function
Browse files Browse the repository at this point in the history
  • Loading branch information
WoodenMaiden committed Apr 11, 2024
1 parent 27e0c14 commit 463f2c6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
11 changes: 6 additions & 5 deletions database/functionState.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import (
type FunctionState struct {
gorm.Model
ID uuid.UUID `json:"id" ,gorm:"primarykey;type:uuid;default:gen_random_uuid()"`
Code string `json:"code"`
Status string `json:"status"`
Address string `json:"address"`
Port uint16 `json:"port"`
// OwnerID
Code string `json:"code"`
Status string `json:"status"`
Address string `json:"address"`
Port uint16 `json:"port"`
OwnerID int `json:"owner_id"`
Owner User `json:"-"`
}

func (FunctionState) TableName() string {
Expand Down
8 changes: 6 additions & 2 deletions routes/function/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ func (c *Controller) RunFunction(ctx *gin.Context) {
//var fnBody any; // because the body is entirely defined by the user, we just forward it to the function without checking it

if err != nil {
ctx.AbortWithStatusJSON(400, gin.H{"error": "Invalid function ID"})
ctx.AbortWithStatusJSON(400, gin.H{"error": "Invalid format for function ID"})
return
}

var fn database.FunctionState
var fn database.FunctionState = database.FunctionState{} //will be used later to store the function state

err = c.DB.Where(&database.FunctionState{ID: fnID}).First(&fn).Error

if err != nil && errors.Is(err, gorm.ErrRecordNotFound) {
Expand Down Expand Up @@ -62,5 +63,8 @@ func (c *Controller) RunFunction(ctx *gin.Context) {
}

// TODO: forward the body to fn.Address:fn.Port
// right here!

// + we should define what we exactly want to return
ctx.JSON(200, fn)
}

0 comments on commit 463f2c6

Please sign in to comment.