Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,61 @@ const docTemplate = `{
}
}
},
"/chat/direct/{chatId}": {
"get": {
"security": [
{
"BearerAuth": []
}
],
"description": "Devuelve los detalles de un chat directo específico",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Chat"
],
"summary": "Obtiene un chat directo por ID",
"parameters": [
{
"type": "string",
"description": "ID del chat directo",
"name": "chatId",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "Detalles del chat directo",
"schema": {
"$ref": "#/definitions/models.DirectChat"
}
},
"401": {
"description": "No autorizado",
"schema": {
"type": "string"
}
},
"404": {
"description": "Chat no encontrado",
"schema": {
"type": "string"
}
},
"500": {
"description": "Error interno del servidor",
"schema": {
"type": "string"
}
}
}
}
},
"/chat/direct/{chatId}/messages": {
"get": {
"security": [
Expand Down
55 changes: 55 additions & 0 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,61 @@
}
}
},
"/chat/direct/{chatId}": {
"get": {
"security": [
{
"BearerAuth": []
}
],
"description": "Devuelve los detalles de un chat directo específico",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Chat"
],
"summary": "Obtiene un chat directo por ID",
"parameters": [
{
"type": "string",
"description": "ID del chat directo",
"name": "chatId",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "Detalles del chat directo",
"schema": {
"$ref": "#/definitions/models.DirectChat"
}
},
"401": {
"description": "No autorizado",
"schema": {
"type": "string"
}
},
"404": {
"description": "Chat no encontrado",
"schema": {
"type": "string"
}
},
"500": {
"description": "Error interno del servidor",
"schema": {
"type": "string"
}
}
}
}
},
"/chat/direct/{chatId}/messages": {
"get": {
"security": [
Expand Down
35 changes: 35 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,41 @@ paths:
summary: Registra un nuevo usuario
tags:
- Auth
/chat/direct/{chatId}:
get:
consumes:
- application/json
description: Devuelve los detalles de un chat directo específico
parameters:
- description: ID del chat directo
in: path
name: chatId
required: true
type: string
produces:
- application/json
responses:
"200":
description: Detalles del chat directo
schema:
$ref: '#/definitions/models.DirectChat'
"401":
description: No autorizado
schema:
type: string
"404":
description: Chat no encontrado
schema:
type: string
"500":
description: Error interno del servidor
schema:
type: string
security:
- BearerAuth: []
summary: Obtiene un chat directo por ID
tags:
- Chat
/chat/direct/{chatId}/messages:
get:
consumes:
Expand Down
47 changes: 47 additions & 0 deletions internal/handlers/chat_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,3 +376,50 @@ func (h *ChatHandler) GetRoomMessagesSimple(w http.ResponseWriter, r *http.Reque

json.NewEncoder(w).Encode(messages)
}

// GetChat obtiene un chat directo por ID
//
// @Summary Obtiene un chat directo por ID
// @Description Devuelve los detalles de un chat directo específico
// @Tags Chat
// @Accept json
// @Produce json
// @Security BearerAuth
// @Param chatId path string true "ID del chat directo"
// @Success 200 {object} models.DirectChat "Detalles del chat directo"
// @Failure 401 {string} string "No autorizado"
// @Failure 404 {string} string "Chat no encontrado"
// @Failure 500 {string} string "Error interno del servidor"
// @Router /chat/direct/{chatId} [get]
func (h *ChatHandler) GetChat(w http.ResponseWriter, r *http.Request) {
chatID := chi.URLParam(r, "chatId")

// Obtener el ID del usuario del contexto
userID, ok := r.Context().Value("userID").(string)
if !ok {
http.Error(w, "User ID not found in context", http.StatusInternalServerError)
return
}

chat, err := h.DirectChatService.GetDirectChat(chatID)
if err != nil {
http.Error(w, "Error getting chat: "+err.Error(), http.StatusInternalServerError)
return
}

// Verificar si el usuario tiene acceso a este chat
hasAccess := false
for _, id := range chat.UserIDs {
if id == userID {
hasAccess = true
break
}
}

if !hasAccess {
http.Error(w, "Unauthorized access to this chat", http.StatusForbidden)
return
}

json.NewEncoder(w).Encode(chat)
}
1 change: 1 addition & 0 deletions internal/routes/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func NewRouter(
r.Route("/direct", func(r chi.Router) {
r.Post("/{otherUserId}", chatHandler.CreateDirectChat)
r.Get("/me", chatHandler.GetUserDirectChats)
r.Get("/{chatId}", chatHandler.GetChat)
r.Get("/{chatId}/messages", chatHandler.GetDirectChatMessages)
})
})
Expand Down