Skip to content

Commit

Permalink
backend: add a job_offer_id field to the payment_records table
Browse files Browse the repository at this point in the history
  • Loading branch information
elhmn committed May 23, 2023
1 parent 9107d35 commit 45c8674
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 16 deletions.
23 changes: 18 additions & 5 deletions backend/internal/handlers/pay_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"net/http"
"strconv"
"strings"

"github.com/gin-gonic/gin"
Expand Down Expand Up @@ -63,16 +64,28 @@ func PostPay(c *gin.Context) {
gin.H{"error": "failed to get db client"})
return
}

//parse query.JobOfferID to an int64
jobOfferID, err := strconv.ParseInt(query.JobOfferID, 10, 64)
if err != nil {
log.Error(err)
c.JSON(http.StatusInternalServerError,
gin.H{"error": "failed to parse JobOfferID"})
return
}

url := fmt.Sprintf("%s%s-%d", payment.OPEN_COLLECTIVE_CONTRIBUTE, response.CreateTier.Slug, response.CreateTier.LegacyID)
err = db.CreatePaymentRecord(&v1beta.PaymentRecord{
TierId: response.CreateTier.ID,
LegacyId: response.CreateTier.LegacyID,
Slug: response.CreateTier.Slug,
Email: query.Email,
TierUrl: url,
TierId: response.CreateTier.ID,
JobOfferID: jobOfferID,
LegacyId: response.CreateTier.LegacyID,
Slug: response.CreateTier.Slug,
Email: query.Email,
TierUrl: url,
})
if err != nil {
log.Error(err)
//TODO: if we fail to record the payment, we should delete the tier
c.JSON(http.StatusInternalServerError,
gin.H{"error": "could not find job titles"})
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
CREATE TABLE IF NOT EXISTS payment_records (
id BIGSERIAL NOT NULL PRIMARY KEY,
email VARCHAR(255) NOT NULL,
job_offer_id BIGINT NOT NULL,
tier_id VARCHAR(255) NOT NULL,
legacy_id INTEGER NOT NULL,
slug VARCHAR(255) NOT NULL,
tier_url VARCHAR(255) NOT NULL,
createdat DATE,
updatedat DATE
updatedat DATE,
CONSTRAINT fk_job_offers
FOREIGN KEY(job_offer_id)
REFERENCES job_offers(id)
);

-- +goose StatementEnd
Expand Down
5 changes: 3 additions & 2 deletions backend/pkg/models/v1beta/pay.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (

type PayPostQuery struct {
// The email of the user making the payment
Email string `json:"email"`
Tier string `json:"tier"`
Email string `json:"email"`
Tier string `json:"tier"`
JobOfferID string `json:"job_offer_id"`
}

// Validate check if the mandatory fields are filled
Expand Down
17 changes: 9 additions & 8 deletions backend/pkg/models/v1beta/payment_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package v1beta
import "time"

type PaymentRecord struct {
Id int64 `json:"id" gorm:"column:id;auto_increment;primary_key"`
Email string `json:"email" gorm:"column:email"`
TierId string `json:"tier_id" gorm:"column:tier_id"`
LegacyId int64 `json:"legacy_id" gorm:"column:legacy_id"`
Slug string `json:"slug" gorm:"column:slug"`
TierUrl string `json:"tier_url" gorm:"column:tier_url"`
CreatedAt time.Time `json:"created_at" gorm:"column:createdat"`
UpdatedAt time.Time `json:"updated_at" gorm:"column:updatedat"`
Id int64 `json:"id" gorm:"column:id;auto_increment;primary_key"`
Email string `json:"email" gorm:"column:email"`
TierId string `json:"tier_id" gorm:"column:tier_id"`
JobOfferID int64 `json:"job_offer_id" gorm:"column:job_offer_id"`
LegacyId int64 `json:"legacy_id" gorm:"column:legacy_id"`
Slug string `json:"slug" gorm:"column:slug"`
TierUrl string `json:"tier_url" gorm:"column:tier_url"`
CreatedAt time.Time `json:"created_at" gorm:"column:createdat"`
UpdatedAt time.Time `json:"updated_at" gorm:"column:updatedat"`
}

0 comments on commit 45c8674

Please sign in to comment.