Skip to content
Snippets Groups Projects
Commit 470aa26f authored by Martin Schmollinger's avatar Martin Schmollinger
Browse files

Change state of donation after successful bank transaction in myaktion service.

parent 019b4db8
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@ import (
log "github.com/sirupsen/logrus"
"gitlab.reutlingen-university.de/go-exercises/myaktion-go-ss25/src/myaktion/client"
"gitlab.reutlingen-university.de/go-exercises/myaktion-go-ss25/src/myaktion/client/banktransfer"
"gitlab.reutlingen-university.de/go-exercises/myaktion-go-ss25/src/myaktion/service"
)
func monitortransactions() {
......@@ -42,7 +43,14 @@ func connectandmonitor() {
continue
}
entry := log.WithField("transaction", transaction)
entry.Info("Received transaction. Sending processing response")
entry.Info("Received transaction")
err = service.MarkDonation(uint(transaction.DonationId))
if err != nil {
entry.WithError(err).Error("error changing donation status")
continue
}
entry.Info("Sending processing response")
err = watcher.Send(&banktransfer.ProcessingResponse{Id: transaction.Id})
if err != nil {
entry.WithError(err).Error("error sending processing response")
......
......
......@@ -72,3 +72,23 @@ func deleteDonation(donation *model.Donation) error {
entry.Info("Successfully deleted campaign.")
return nil
}
func MarkDonation(id uint) error {
entry := log.WithField("donationId", id)
donation := new(model.Donation)
result := db.DB.First(donation, id)
if result.Error != nil {
entry.WithError(result.Error).Error("Can't retrieve donation")
return result.Error
}
entry = entry.WithField("donation", donation)
entry.Trace("Retrieved donation")
donation.Status = model.TRANSFERRED
result = db.DB.Save(donation)
if result.Error != nil {
entry.WithError(result.Error).Error("Can't update donation")
return result.Error
}
entry.Info("Successfully updated status of donation.")
return nil
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment