tsk-62: Modify how the Response from event.MessageEventResponse is handled (#63)
Closes #62 Reviewed-on: phoenix/textsender-api#63 Co-authored-by: phoenix <kundeng00@pm.me> Co-committed-by: phoenix <kundeng00@pm.me>
This commit is contained in:
@@ -1,13 +1,11 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"git.kundeng.us/phoenix/textsender-models/tx0/message"
|
||||
"git.kundeng.us/phoenix/textsender-models/tx0/types"
|
||||
"git.kundeng.us/phoenix/textsender-models/tx0/message/event"
|
||||
"github.com/google/uuid"
|
||||
|
||||
"git.kundeng.us/phoenix/textsender-api/internal/app"
|
||||
@@ -24,18 +22,18 @@ func NewEventResponseHandler(apiApp *app.App, str store.MessageEventResponseStor
|
||||
}
|
||||
|
||||
type RecordEventRequest struct {
|
||||
ScheduledMessageEventId uuid.UUID `json:"scheduled_message_event_id"`
|
||||
Response types.JSONB `json:"response"`
|
||||
UserId uuid.UUID `json:"user_id"`
|
||||
Sent *time.Time `json:"sent,omitempty"`
|
||||
Status string `json:"status"`
|
||||
ContactId *uuid.UUID `json:"contact_id"`
|
||||
MessageId *uuid.UUID `json:"message_id"`
|
||||
ScheduledMessageEventId uuid.UUID `json:"scheduled_message_event_id"`
|
||||
Response map[string]any `json:"response"`
|
||||
UserId uuid.UUID `json:"user_id"`
|
||||
Sent *time.Time `json:"sent,omitempty"`
|
||||
Status string `json:"status"`
|
||||
ContactId *uuid.UUID `json:"contact_id"`
|
||||
MessageId *uuid.UUID `json:"message_id"`
|
||||
}
|
||||
|
||||
type RecordEventResponse struct {
|
||||
Message string `json:"message"`
|
||||
Data []*message.MessageEventResponse `json:"data"`
|
||||
Message string `json:"message"`
|
||||
Data []*event.MessageEventResponse `json:"data"`
|
||||
}
|
||||
|
||||
func (e *EventResponseHandler) RecordResponse(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -46,11 +44,9 @@ func (e *EventResponseHandler) RecordResponse(w http.ResponseWriter, r *http.Req
|
||||
defer r.Body.Close()
|
||||
|
||||
var statusCode int
|
||||
var rp message.MessageEventResponse
|
||||
var rp event.MessageEventResponse
|
||||
var resp RecordEventResponse
|
||||
|
||||
defer RespondWithJSON(w, statusCode, &resp)
|
||||
|
||||
if req.Sent == nil {
|
||||
statusCode = http.StatusBadRequest
|
||||
resp.Message = "Sent time is empty"
|
||||
@@ -66,20 +62,19 @@ func (e *EventResponseHandler) RecordResponse(w http.ResponseWriter, r *http.Req
|
||||
} else {
|
||||
log.Println("Starting process to record Message Event Response")
|
||||
rp.ScheduledMessageEventId = req.ScheduledMessageEventId
|
||||
fmt.Println(req.Response)
|
||||
rp.Response = req.Response
|
||||
rp.UserId = req.UserId
|
||||
rp.Sent = *req.Sent
|
||||
|
||||
switch req.Status {
|
||||
case message.Message_Event_Response_Status_Instant:
|
||||
case event.Message_Event_Response_Status_Instant:
|
||||
{
|
||||
log.Println("Status:", req.Status)
|
||||
rp.Status = req.Status
|
||||
rp.MessageId = req.MessageId
|
||||
rp.ContactId = req.ContactId
|
||||
}
|
||||
case message.Message_Event_Response_Status_Scheduled:
|
||||
case event.Message_Event_Response_Status_Scheduled:
|
||||
{
|
||||
log.Println("Status:", req.Status)
|
||||
rp.Status = req.Status
|
||||
@@ -103,11 +98,13 @@ func (e *EventResponseHandler) RecordResponse(w http.ResponseWriter, r *http.Req
|
||||
resp.Data = append(resp.Data, &rp)
|
||||
}
|
||||
}
|
||||
|
||||
RespondWithJSON(w, statusCode, &resp)
|
||||
}
|
||||
|
||||
type GetMessageEventResponseFetchedResponse struct {
|
||||
Message string `json:"message"`
|
||||
Data []*message.MessageEventResponse `json:"data"`
|
||||
Message string `json:"message"`
|
||||
Data []*event.MessageEventResponse `json:"data"`
|
||||
}
|
||||
|
||||
func (e *EventResponseHandler) Fetch(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
Reference in New Issue
Block a user