Added uuid middleware

This commit is contained in:
Nedim
2023-11-21 18:28:30 +01:00
parent a7ab058d01
commit d54b643378
11 changed files with 133 additions and 27 deletions

View File

@@ -9,6 +9,7 @@ import (
"time"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
"gitlab.com/pactual1/backend/database/contract"
"gitlab.com/pactual1/backend/models"
"gitlab.com/pactual1/backend/shared"
@@ -36,6 +37,7 @@ func GetLatestContracts(c *gin.Context) {
iDsStr := c.QueryArray("ids[]")
company := c.GetInt("companyID")
uuid := c.Query("uuid")
// Convert limit and offset to int
limit, err := strconv.Atoi(limitStr)
@@ -95,7 +97,7 @@ func GetLatestContracts(c *gin.Context) {
}
// Fetch contracts
contracts, total, st, err := contract.GetContracts(status, companyName, companyAddress, companyEmail, companyPhone, &startTime, &endTime, contractName, deviceIDs, contractIDs, nil, company, limit, offset)
contracts, total, st, err := contract.GetContracts(status, companyName, companyAddress, companyEmail, companyPhone, &startTime, &endTime, contractName, deviceIDs, contractIDs, nil, uuid, company, limit, offset)
if err != nil {
c.JSON(st, gin.H{"error": err.Error()})
@@ -178,7 +180,7 @@ func GetBuyerContracts(c *gin.Context) {
}
// Fetch contracts
contracts, total, st, err := contract.GetContracts(status, "", "", "", "", startTime, endTime, qStr, nil, contractIDs, &dateCreated, company, limit, offset)
contracts, total, st, err := contract.GetContracts(status, "", "", "", "", startTime, endTime, qStr, nil, contractIDs, &dateCreated, "", company, limit, offset)
if err != nil {
c.JSON(st, gin.H{"error": err.Error()})
return
@@ -207,6 +209,7 @@ func CreateContract(c *gin.Context) {
db := shared.GetDb()
newContract := models.Contract{
UUID: uuid.New().String(),
BuyerID: payload.BuyerID,
SellerID: payload.SellerID,
Description: payload.Description,
@@ -256,7 +259,7 @@ func GetContractByID(c *gin.Context) {
}
// Fetch contract
contract, st, err := contract.GetContractByID(uint(contractID))
contract, st, err := contract.GetContractByID(uint(contractID), "")
if err != nil {
c.JSON(st, gin.H{"error": err.Error()})
return