tsk-59: Get MessageEventResponse endpoint (#61)

Closes #59

Reviewed-on: phoenix/textsender-api#61
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
This commit is contained in:
phoenix
2026-01-01 05:28:49 +00:00
committed by phoenix
parent 6641f384ab
commit 59c9aa0ff1
10 changed files with 712 additions and 113 deletions
@@ -38,7 +38,7 @@ func (m *PGMessageEventResponseStore) Create(ctx context.Context, mer *event.Mes
func (m *PGMessageEventResponseStore) GetWithUserId(ctx context.Context, userId uuid.UUID) ([]*event.MessageEventResponse, error) {
query := "SELECT id, scheduled_message_event_id, response, user_id, sent, contact_id, message_id, status FROM message_event_responses WHERE user_id = $1"
rows, err := m.db.Query(ctx, query)
rows, err := m.db.Query(ctx, query, userId)
if err != nil {
return nil, fmt.Errorf("Error querying: %w", err)
}
@@ -11,7 +11,7 @@ import (
)
type ScheduledMessageEventKey struct {
RecipientId uuid.UUID
ContactId uuid.UUID
MessageId uuid.UUID
ScheduledMessageId uuid.UUID
}
@@ -94,7 +94,7 @@ func (m *MockScheduledMessageEventStore) Delete(ctx context.Context, id uuid.UUI
copiedEventsKey := make(map[ScheduledMessageEventKey]*scheduling.ScheduledMessageEvent)
for i, schMsgEvent := range m.ScheduledMessageEvents {
key := ScheduledMessageEventKey{RecipientId: schMsgEvent.RecipientId, MessageId: schMsgEvent.MessageId, ScheduledMessageId: schMsgEvent.ScheduledMessageId}
key := ScheduledMessageEventKey{ContactId: schMsgEvent.ContactId, MessageId: schMsgEvent.MessageId, ScheduledMessageId: schMsgEvent.ScheduledMessageId}
if schMsgEvent.Id != id {
copiedEvents[i] = schMsgEvent
copiedEventsKey[key] = schMsgEvent
@@ -132,7 +132,7 @@ func (m *MockScheduledMessageEventStore) CreateScheduledMessageEvent(ctx context
event.Id = uuid.New()
}
key := ScheduledMessageEventKey{RecipientId: event.RecipientId, MessageId: event.MessageId, ScheduledMessageId: event.ScheduledMessageId}
key := ScheduledMessageEventKey{ContactId: event.ContactId, MessageId: event.MessageId, ScheduledMessageId: event.ScheduledMessageId}
if _, exists := m.ScheduledMessageEventsByKey[key]; exists {
return fmt.Errorf("Already exists")
@@ -152,7 +152,7 @@ func (m *MockScheduledMessageEventStore) Exists(ctx context.Context, event *sche
return false, m.Error
}
key := ScheduledMessageEventKey{RecipientId: event.RecipientId, MessageId: event.MessageId, ScheduledMessageId: event.ScheduledMessageId}
key := ScheduledMessageEventKey{ContactId: event.ContactId, MessageId: event.MessageId, ScheduledMessageId: event.ScheduledMessageId}
_, exists := m.ScheduledMessageEventsByKey[key]
return exists, nil
+7 -5
View File
@@ -36,16 +36,18 @@ func (m *MockMessageStore) CreateMessage(ctx context.Context, msg *message.Messa
return m.Error
}
if msg.Id == uuid.Nil {
msg.Id = uuid.New()
var id uuid.UUID
if msg.Id != nil && msg.Id == uuid.Nil {
id = uuid.New()
msg.Id = &id
}
key := MessageKey{Content: msg.Content, UserId: msg.UserId}
key := MessageKey{Content: msg.Content, UserId: *msg.UserId}
if _, exists := m.MessagesByKey[key]; exists {
return errors.New("Message already exists")
}
m.Messages[msg.Id] = msg
m.Messages[*msg.Id] = msg
m.MessagesByKey[key] = msg
return nil
}
@@ -88,7 +90,7 @@ func (m *MockMessageStore) MessageExists(ctx context.Context, msg *message.Messa
return false, m.Error
}
_, exists := m.MessagesByKey[MessageKey{Content: msg.Content, UserId: msg.UserId}]
_, exists := m.MessagesByKey[MessageKey{Content: msg.Content, UserId: *msg.UserId}]
return exists, nil
}