Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
marcussss1 committed Jun 2, 2023
1 parent febe05a commit 443f0fe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
3 changes: 3 additions & 0 deletions internal/microservices/chat/delivery/http/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package http
import (
"context"
"github.com/labstack/echo/v4"
log "github.com/sirupsen/logrus"
"net/http"
"net/url"
"project/internal/microservices/chat"
Expand Down Expand Up @@ -53,10 +54,12 @@ func (u chatHandler) GetChatInfoHandler(ctx echo.Context) error {

func (u chatHandler) GetCurrentUserChatsHandler(ctx echo.Context) error {
session := ctx.Get("session").(model.Session)
log.Info("1")
listUserChats, err := u.chatUsecase.GetListUserChats(context.TODO(), session.UserId)
if err != nil {
return err
}
log.Info(" END ")

return ctx.JSON(http.StatusOK, model.Chats{Chats: listUserChats})
}
Expand Down
12 changes: 7 additions & 5 deletions internal/microservices/chat/usecase/usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package usecase

import (
"context"
log "github.com/sirupsen/logrus"
"project/internal/config"
"project/internal/microservices/chat"
"project/internal/microservices/messages"
Expand Down Expand Up @@ -256,7 +257,7 @@ func (u usecase) DeleteChatById(ctx context.Context, chatID uint64) error {
func (u usecase) GetListUserChats(ctx context.Context, userID uint64) ([]model.ChatInListUser, error) {
var chatsInListUser []model.ChatInListUser
userChats, err := u.chatRepo.GetChatsByUserId(ctx, userID)

log.Info("1 2")
if err != nil {
return nil, err
}
Expand All @@ -266,30 +267,31 @@ func (u usecase) GetListUserChats(ctx context.Context, userID uint64) ([]model.C
if err != nil {
return nil, err
}

log.Info("1 2 3")
chatMembers, err := u.chatRepo.GetChatMembersByChatId(ctx, chat.Id)
if err != nil {
return nil, err
}

log.Info("1 2 3 4")
var members []model.User
for _, chatMember := range chatMembers {
user, err := u.userRepo.GetUserById(ctx, chatMember.MemberId)
if err != nil {
return nil, err
}

log.Info("1 2 3 4 5")
members = append(members, model_conversion.FromAuthorizedUserToUser(user))
}

lastMessage, err := u.messagesRepo.GetLastChatMessage(ctx, chat.Id)
if err != nil {
return nil, err
}

log.Info("1 2 3 4 5 6")
var lastMessageAuthor model.AuthorizedUser
if lastMessage.AuthorId != 0 {
lastMessageAuthor, err = u.userRepo.GetUserById(ctx, lastMessage.AuthorId)
log.Info("1 2 3 4 5 6 7")
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 443f0fe

Please sign in to comment.