Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PUT endpoint to update chats #2226

Closed
5 tasks
humansinstitute opened this issue Dec 19, 2024 · 2 comments · Fixed by #2227
Closed
5 tasks

Add PUT endpoint to update chats #2226

humansinstitute opened this issue Dec 19, 2024 · 2 comments · Fixed by #2227
Assignees

Comments

@humansinstitute
Copy link
Contributor

humansinstitute commented Dec 19, 2024

Ticket Name: Add PUT Endpoint to Update Chats

Context

This ticket aims to enhance the chat functionality by introducing a PUT endpoint to update chat details. This feature is necessary to allow users to modify existing chat information, such as the title, without creating a new chat. It fits into the larger system by improving the flexibility and usability of the chat service.

This will update the chat object int he DB, not the chatMessage - for example this will allow us to update the title on a chat, which will in turn update the Chat History Component on Workspace and the Chat on the Hivechat main view.

Task

  1. Implement a new PUT endpoint at /hivechat/{chat_id} in the chat.go file.
  2. Ensure the endpoint accepts a payload that includes the chat fields to be updated.
  3. Implement a handler function chatHandler.UpdateChat to manage updates
  4. Update only the fields provided in the payload, along with the update timestamp.
  5. Integrate the new endpoint into the existing router group.

Outcome

The system will have a functional PUT endpoint that allows users to update specific fields of a chat, enhancing the chat management capabilities.

Design

  • Endpoint: PUT /hivechat/{chat_id}
  • Router Group:
    r.Group(func(r chi.Router) {
        r.Use(auth.PubKeyContext)
        r.Get("/", chatHandler.GetChat)
        r.Post("/", chatHandler.CreateChat)
        r.PUT("/", chatHandler.UpdateChat)
        r.Post("/send", chatHandler.SendMessage)
        r.Get("/history/{uuid}", chatHandler.GetChatHistory)
    })
  • Payload: Accepts a JSON object with fields to be updated.
  • Logic:
    • Parse the incoming request to extract the fields.
    • Validate the fields and update the corresponding chat record in the database.
    • Update the timestamp to reflect the modification time.

Payload from the front end will be in the form.

{
  id: string; // Passed as an ID for the chat not a change
  workspaceId: string;  // Passed as an ID for the chat not a change
  title: string; // This is what we will likely be changed
}

Acceptance Criteria

  • The PUT endpoint is accessible at /hivechat/{chat_id}.
  • The endpoint correctly updates only the fields provided in the request payload.
  • The update timestamp is modified upon a successful update.
  • The endpoint returns appropriate success and error responses.
  • Unit tests are written to cover various update scenarios.
@humansinstitute
Copy link
Contributor Author

@Ekep-Obasi - as discussed.

@Ekep-Obasi
Copy link
Contributor

@humansinstitute Please assign

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants