33 lines
804 B
Go
33 lines
804 B
Go
package chat
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/labstack/echo/v4"
|
|
|
|
"gitflic.ru/akselbant/mtusi2026lab1-fork/dto"
|
|
"gitflic.ru/akselbant/mtusi2026lab1-fork/internal/pkg/domain"
|
|
)
|
|
|
|
func (h *Chat) getChat(c echo.Context) error {
|
|
request := dto.GetChatRequest{ChatID: c.Param("chat_id")}
|
|
chat, ok, err := h.authorizedChat(c, getChatRequestToDomain(request))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if !ok {
|
|
return nil
|
|
}
|
|
return c.JSON(http.StatusOK, getChatResponseFromDomain(chat))
|
|
}
|
|
|
|
func getChatRequestToDomain(request dto.GetChatRequest) domain.Chat {
|
|
return domain.Chat{ID: request.ChatID}
|
|
}
|
|
|
|
func getChatResponseFromDomain(chat domain.Chat) dto.GetChatResponse {
|
|
return dto.GetChatResponse{
|
|
ID: chat.ID, Title: chat.Title, MemberIDs: chat.MemberIDs, CreatedAt: dto.Timestamp(chat.CreatedAt),
|
|
}
|
|
}
|