tsk-54: Tweak instant message endpoint to save contact and message identification (#56)

Closes #54

Reviewed-on: phoenix/textsender-api#56
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
This commit is contained in:
phoenix
2025-12-22 22:39:29 +00:00
committed by phoenix
parent f5f753fe02
commit 6fa5ede358
10 changed files with 45 additions and 28 deletions
+3 -3
View File
@@ -54,14 +54,14 @@ func (c *ContactHandler) AddContact(w http.ResponseWriter, r *http.Request) {
}
defer r.Body.Close()
newContact := contact.Contact{PhoneNumber: req.PhoneNumber, UserId: req.UserId}
newContact := contact.Contact{PhoneNumber: req.PhoneNumber, UserId: &req.UserId}
var statusCode int
var resp AddContactResponse
ctx := r.Context()
if exists, err := c.ContactStore.ContactExists(ctx, newContact.PhoneNumber, newContact.UserId); err != nil {
if exists, err := c.ContactStore.ContactExists(ctx, newContact.PhoneNumber, *newContact.UserId); err != nil {
fmt.Printf("Error: %v", err)
statusCode = http.StatusInternalServerError
resp.Message = err.Error()
@@ -157,7 +157,7 @@ func (c *ContactHandler) GetContact(w http.ResponseWriter, r *http.Request) {
fmt.Println("Checking with User Id")
if contacts, err := c.ContactStore.GetAllContacts(ctx); err == nil {
for _, con := range contacts {
if con.UserId == userId {
if *con.UserId == userId {
resp.Data = append(resp.Data, *con)
}
}