change user type from int to uuid string

This commit is contained in:
2025-03-27 20:33:48 -04:00
parent 732fbacc61
commit 9d7ad260f2
5 changed files with 35 additions and 29 deletions

View File

@@ -4,7 +4,6 @@ import (
"context"
"encoding/json"
"net/http"
"strconv"
"github.com/go-chi/chi/v5"
"github.com/go-chi/render"
@@ -110,15 +109,14 @@ func newMessageID() string {
}
func NewMessage(w http.ResponseWriter, r *http.Request) {
err := r.ParseMultipartForm(32 << 20)
err := r.ParseMultipartForm(64 << 10)
if err != nil {
http.Error(w, "Unable to parse form", http.StatusBadRequest)
return
}
userIDStr := r.FormValue("user_id")
userID, err := strconv.ParseInt(userIDStr, 10, 64)
if err != nil {
userID := r.FormValue("user_id")
if userID == "" {
http.Error(w, "Invalid user ID", http.StatusBadRequest)
return
}
@@ -150,7 +148,7 @@ type messageKey struct{}
type Message struct {
ID string `json:"id"`
UserID int64 `json:"user_id"`
UserID string `json:"user_id"`
Body string `json:"body"`
Timestamp time.Time `json:"timestamp"`
Edited time.Time `json:"edited"`
@@ -175,7 +173,7 @@ type MessageResponse struct {
func (m MessageResponse) MarshalJSON() ([]byte, error) {
type OrderedMessageResponse struct {
ID string `json:"id"`
UserID int64 `json:"user_id"`
UserID string `json:"user_id"`
Body string `json:"body"`
Timestamp string `json:"timestamp"`
Edited *string `json:"edited,omitempty"` // Use a pointer to allow null values