tsk-51: Send message endpoint (#52)

Closes #51

Reviewed-on: phoenix/textsender-api#52
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
This commit is contained in:
phoenix
2025-12-10 21:35:02 +00:00
committed by phoenix
parent 20ffc45f89
commit 0d252bc261
32 changed files with 753 additions and 96 deletions
+8 -4
View File
@@ -2,11 +2,13 @@ package handler
import (
"fmt"
"log"
"net/http"
"git.kundeng.us/phoenix/textsender-models/tx0/message"
"github.com/google/uuid"
"git.kundeng.us/phoenix/textsender-api/internal/app"
"git.kundeng.us/phoenix/textsender-api/internal/store"
)
@@ -21,11 +23,12 @@ type AddMessageResponse struct {
}
type MessageHandler struct {
App *app.App
MessageStore store.MessageStore
}
func NewMessageHandler(str store.MessageStore) *MessageHandler {
return &MessageHandler{MessageStore: str}
func NewMessageHandler(apiApp *app.App, str store.MessageStore) *MessageHandler {
return &MessageHandler{App: apiApp, MessageStore: str}
}
const Message_Limit = 200
@@ -143,7 +146,7 @@ func (c *MessageHandler) GetMessage(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
if id != uuid.Nil {
fmt.Println("Checking with Id")
log.Println("Checking with Id")
if con, err := c.MessageStore.GetMessageByID(ctx, id); err == nil {
statusCode = http.StatusOK
resp.Message = "Successful"
@@ -153,8 +156,9 @@ func (c *MessageHandler) GetMessage(w http.ResponseWriter, r *http.Request) {
resp.Message = err.Error()
}
} else if userId != uuid.Nil {
fmt.Println("Checking with User Id")
log.Println("Checking with User Id")
if messages, err := c.MessageStore.GetAllMessages(ctx); err == nil {
log.Println("Amount of messages:", len(messages))
for _, msg := range messages {
if msg.UserId == userId {
resp.Data = append(resp.Data, *msg)