implement Scylla database

This commit is contained in:
2025-05-17 21:45:18 -04:00
parent 252b49ae6a
commit f8a550883d
199 changed files with 71243 additions and 424 deletions

View File

@@ -65,7 +65,8 @@ func EditMessage(w http.ResponseWriter, r *http.Request) {
}
message.Body = body
message.Edited = time.Now()
editedTime := time.Now()
message.Edited = &editedTime
err = dbUpdateMessage(message)
if err != nil {
@@ -85,7 +86,7 @@ func DeleteMessage(w http.ResponseWriter, r *http.Request) {
render.Render(w, r, ErrNotFound)
return
}
dbDeleteMessage(message.ID)
dbDeleteMessage(message.ID.String())
if err := render.Render(w, r, NewMessageResponse(message)); err != nil {
render.Render(w, r, ErrRender(err))
return
@@ -104,8 +105,8 @@ func ListMessages(w http.ResponseWriter, r *http.Request) {
}
}
func newMessageID() string {
return "msg_" + uuid.New().String()
func newMessageID() uuid.UUID {
return uuid.New()
}
func NewMessage(w http.ResponseWriter, r *http.Request) {
@@ -135,7 +136,6 @@ func NewMessage(w http.ResponseWriter, r *http.Request) {
UserID: user.ID,
Body: body,
Timestamp: time.Now(),
Edited: time.Time{},
}
err = dbAddMessage(&msg)
@@ -150,11 +150,11 @@ func NewMessage(w http.ResponseWriter, r *http.Request) {
type messageKey struct{}
type Message struct {
ID string `json:"id"`
UserID string `json:"user_id"`
Body string `json:"body"`
Timestamp time.Time `json:"timestamp"`
Edited time.Time `json:"edited"`
ID uuid.UUID `json:"id"`
UserID uuid.UUID `json:"user_id"`
Body string `json:"body"`
Timestamp time.Time `json:"timestamp"`
Edited *time.Time `json:"edited"`
}
type MessageRequest struct {
@@ -175,8 +175,8 @@ type MessageResponse struct {
func (m MessageResponse) MarshalJSON() ([]byte, error) {
type OrderedMessageResponse struct {
ID string `json:"id"`
UserID string `json:"user_id"`
ID uuid.UUID `json:"id"`
UserID uuid.UUID `json:"user_id"`
Body string `json:"body"`
Timestamp string `json:"timestamp"`
Edited *string `json:"edited,omitempty"` // Use a pointer to allow null values
@@ -185,7 +185,7 @@ func (m MessageResponse) MarshalJSON() ([]byte, error) {
}
var edited *string
if !m.Message.Edited.IsZero() { // Check if Edited is not the zero value
if m.Message.Edited != nil { // Check if Edited is not the zero value
editedStr := m.Message.Edited.Format(time.RFC3339)
edited = &editedStr
}