-
Notifications
You must be signed in to change notification settings - Fork 2
fix: repair CreateDispute and UpdateDispute #237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,11 +63,37 @@ func CreateDispute(c *gin.Context) { | |
| return | ||
| } | ||
|
|
||
| disputeCount, err := q.CheckDisputeExistsByTxnIdQuery(ctx, tx, txnId) | ||
| if err != nil { | ||
| c.JSON(http.StatusInternalServerError, gin.H{ | ||
| "message": "Oops! Something happened. Please try again later", | ||
| }) | ||
| pkg.Log.ErrorCtx(c, "[DISPUTE-ERROR]: Failed to check if dispute exists by transaction ID", err) | ||
| return | ||
| } | ||
| if disputeCount > 0 { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't send bad request ? Send conflict ? Will it cause issue with the frontend team ? |
||
| c.JSON(http.StatusBadRequest, gin.H{ | ||
| "message": "Dispute already exists for this transaction", | ||
| }) | ||
| pkg.Log.ErrorCtx(c, "[DISPUTE-ERROR]: Attempted to create duplicate dispute for transaction ID", nil) | ||
| return | ||
| } | ||
|
|
||
| studentEmail, err := q.GetEmailByTxnIdQuery(ctx, tx, txnId) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Once the dispute check is pushed to the top, the dispute creation flow can happen in a single shot with a sub-query that joins on student table, event table using transaction id and then runs the insert. No need to use separate queries. |
||
| if err != nil { | ||
| c.JSON(http.StatusInternalServerError, gin.H{ | ||
| "message": "Oops! Something happened. Please try again later", | ||
| }) | ||
| pkg.Log.ErrorCtx(c, "[DISPUTE-ERROR]: Failed to fetch student email by transaction ID", err) | ||
| return | ||
| } | ||
|
|
||
| if event.EventStatus == "ACTIVE" { | ||
|
|
||
| err = q.CreateDisputeQuery(ctx, tx, db.CreateDisputeQueryParams{ | ||
| EventID: event.EventID, | ||
| TxnID: txnId, | ||
| EventID: event.EventID, | ||
| TxnID: txnId, | ||
| StudentEmail: pkg.ToPgText(studentEmail), | ||
| }) | ||
| if err != nil { | ||
| c.JSON(http.StatusInternalServerError, gin.H{ | ||
|
|
@@ -136,9 +162,8 @@ func UpdateDispute(c *gin.Context) { | |
| q := db.New() | ||
|
|
||
| row, err := q.UpdateDisputeQuery(ctx, conn, db.UpdateDisputeQueryParams{ | ||
| ID: disputeId, | ||
| StudentEmail: pkg.ToPgText(req.StudentEmail), | ||
| Description: pkg.ToPgText(req.Description), | ||
| ID: disputeId, | ||
| Description: pkg.ToPgText(req.Description), | ||
| }) | ||
| if err != nil { | ||
| c.JSON(http.StatusInternalServerError, gin.H{ | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dispute check must happen before we grabeventIdByTxnId