Skip to content
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

feat: add response received column #93

Merged
merged 8 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions internal/nostr/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@ type OnReceiveEOSFunc func(ctx context.Context, subscription *Subscription)
type HandleEventFunc func(event *nostr.Event, subscription *Subscription)

type RequestEvent struct {
ID uint
SubscriptionId *uint
NostrId string `validate:"required"`
Content string
State string
ResponseReceived bool
CreatedAt time.Time
UpdatedAt time.Time
ID uint
SubscriptionId *uint
NostrId string `validate:"required"`
Content string
State string
ResponseReceivedAt time.Time
CreatedAt time.Time
UpdatedAt time.Time
}

type ResponseEvent struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/nostr/nostr.go
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ func (svc *Service) handleResponseEvent(event *nostr.Event, subscription *Subscr
"wallet_pubkey": svc.getWalletPubkey(subscription.Authors),
}).Info("Received response event")
if (subscription.RequestEvent != nil) {
im-adithya marked this conversation as resolved.
Show resolved Hide resolved
subscription.RequestEventDB.ResponseReceived = true
subscription.RequestEventDB.ResponseReceivedAt = time.Now()
svc.db.Save(&subscription.RequestEventDB)
}
responseEvent := ResponseEvent{
Expand Down
33 changes: 0 additions & 33 deletions migrations/202407131920_add_response_state_to_request_events.go

This file was deleted.

33 changes: 33 additions & 0 deletions migrations/202407171220_add_response_state_to_request_events.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package migrations

import (
"github.com/go-gormigrate/gormigrate/v2"
"gorm.io/gorm"
)

// Add response_received_at column to request_events table
var _202407171220_add_response_received_at_to_request_events = &gormigrate.Migration{
im-adithya marked this conversation as resolved.
Show resolved Hide resolved
ID: "202407171220_add_response_received_at_to_request_events",
Migrate: func(tx *gorm.DB) error {
if err := tx.Exec("ALTER TABLE request_events ADD COLUMN response_received_at TIMESTAMP DEFAULT '0001-01-01 00:00:00+00'").Error; err != nil {
im-adithya marked this conversation as resolved.
Show resolved Hide resolved
return err
}

// Update response_received_at if there is a corresponding row in response_events
if err := tx.Exec(`
UPDATE request_events re
SET response_received_at = (SELECT created_at FROM response_events WHERE request_id = re.id)
WHERE id IN (SELECT request_id FROM response_events WHERE request_id IS NOT NULL)
im-adithya marked this conversation as resolved.
Show resolved Hide resolved
`).Error; err != nil {
return err
}

return nil
},
Rollback: func(tx *gorm.DB) error {
if err := tx.Exec("ALTER TABLE request_events DROP COLUMN response_received_at").Error; err != nil {
return err
}
return nil
},
}
2 changes: 1 addition & 1 deletion migrations/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func Migrate(db *gorm.DB) error {
_202402161653_initial_migration,
_202404021628_add_uuid_to_subscriptions,
_202404031539_add_indexes,
_202407131920_add_response_state_to_request_events,
_202407171220_add_response_received_at_to_request_events,
})

return m.Migrate()
Expand Down
Loading