Skip to content

Commit

Permalink
Merge pull request #48 from igh9410/dev
Browse files Browse the repository at this point in the history
Fixed GET /api/chatroom/:id endpoint
  • Loading branch information
igh9410 authored May 5, 2024
2 parents 08c4bd8 + 7ce728e commit 7be92a8
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 33 deletions.
3 changes: 2 additions & 1 deletion backend/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
.docker_commands.txt
./index.html
./index2.html
./kubernetes/*
./kubernetes/*
postgres-data/
2 changes: 1 addition & 1 deletion backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ dockerbuild.sh
*.sh

# Python test scripts
scripts/
#scripts/

# Database migrations
#db/migrations/*
Expand Down
5 changes: 1 addition & 4 deletions backend/Dockerfile.multistage
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the application from source
FROM golang:1.21 AS build-stage
FROM golang:1.22 AS build-stage

WORKDIR /app

Expand All @@ -12,9 +12,6 @@ RUN go mod download
# Copy the entire application
COPY . .

# Run the tests
RUN CGO_ENABLED=1 GOOS=linux go test -v ./...

# Build the application
RUN CGO_ENABLED=1 GOOS=linux go build -o blabber-hive ./cmd/blabber-hive/main.go

Expand Down
11 changes: 6 additions & 5 deletions backend/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ run:
@go run cmd/blabber-hive/main.go

# Build the application using Docker
docker-build:
@echo "Generating Swagger documentation before building the application..."
@swag init -g cmd/blabber-hive/main.go
@echo "Building the application using Docker..."
@./scripts/docker-build.sh
docker-push:
#@echo "Generating Swagger documentation before building the application..."
# @swag init -g cmd/blabber-hive/main.go
# @echo "Building the application using Docker..."
@./scripts/docker-push.sh


# Run the application using Docker Compose
docker-run:
Expand Down
2 changes: 1 addition & 1 deletion backend/internal/chat/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (h *Handler) GetChatRoom(c *gin.Context) {
if err != nil {
log.Printf("Error occured with chat room ID %v: %v", chatRoomID, err.Error())
}
res, err := h.Service.GetChatRoomInfoByID(c.Request.Context(), chatRoomID)
res, err := h.Service.GetChatRoomByID(c.Request.Context(), chatRoomID)
if err != nil {
c.JSON(http.StatusNotFound, gin.H{"error": fmt.Sprintf("Chat ID %s not found", chatRoomID)})
return
Expand Down
31 changes: 15 additions & 16 deletions backend/internal/chat/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,40 +89,39 @@ func (r *repository) FindChatRoomByID(ctx context.Context, id uuid.UUID) (*ChatR
// FindChatRoomInfoByID implements Repository.
func (r *repository) FindChatRoomInfoByID(ctx context.Context, chatRoomID uuid.UUID) (*ChatRoomInfo, error) {
chatRoomInfo := &ChatRoomInfo{}

query := "SELECT uicr.user_id, uicr.chat_room_id FROM users_in_chat_rooms AS uicr INNER JOIN chat_rooms AS cr ON uicr.chat_room_id = cr.id WHERE cr.id = $1"

query := `
SELECT
uicr.id,
uicr.user_id,
uicr.chat_room_id,
cr.created_at
FROM users_in_chat_rooms AS uicr
INNER JOIN chat_rooms AS cr ON uicr.chat_room_id = cr.id
WHERE cr.id = $1
GROUP BY uicr.id, uicr.user_id, uicr.chat_room_id, cr.created_at
`
rows, err := r.db.QueryContext(ctx, query, chatRoomID)
if err != nil {
log.Printf("Failed to fetch chat room info, err: %v", err)
return nil, err
}

defer rows.Close()

// Create a slice to store user IDs associated with the chat room.
usersInChatRoom := make([]UserInChatRoom, 0)

var createdAt time.Time
for rows.Next() {
var userInChatRoom UserInChatRoom
err := rows.Scan(&userInChatRoom.UserID, &userInChatRoom.ChatRoomID)
err := rows.Scan(&userInChatRoom.ID, &userInChatRoom.UserID, &userInChatRoom.ChatRoomID, &createdAt)
if err != nil {
log.Printf("Failed to scan chat room info, err: %v", err)
return nil, err
}
log.Printf("User ID: %v", userInChatRoom.UserID)
usersInChatRoom = append(usersInChatRoom, userInChatRoom)
}

// Set the chat room ID in the chat room info.
chatRoomInfo.ID = chatRoomID

// Set the user IDs in the chat room info.
chatRoomInfo.UserList = make([]UserInChatRoom, 0, len(usersInChatRoom))
for _, userInChatRoom := range usersInChatRoom {
chatRoomInfo.UserList = append(chatRoomInfo.UserList, UserInChatRoom{ID: userInChatRoom.ID, UserID: userInChatRoom.UserID, ChatRoomID: userInChatRoom.ChatRoomID})
}

chatRoomInfo.UserList = usersInChatRoom
chatRoomInfo.CreatedAt = createdAt
return chatRoomInfo, nil

}
Expand Down
5 changes: 3 additions & 2 deletions backend/internal/chat/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
type Service interface {
CreateChatRoom(ctx context.Context, req *CreateChatRoomReq) (*CreateChatRoomRes, error)
GetChatRoomByID(ctx context.Context, chatRoomID uuid.UUID) (*ChatRoom, error)
GetChatRoomInfoByID(ctx context.Context, chatRoomID uuid.UUID) (*ChatRoomInfo, error)
//GetChatRoomInfoByID(ctx context.Context, chatRoomID uuid.UUID) (*ChatRoomInfo, error)
JoinChatRoomByID(ctx context.Context, chatRoomID uuid.UUID, userID uuid.UUID) (*ChatRoom, error)
GetChatRoomList(ctx context.Context) ([]*ChatRoom, error)
RegisterClient(ctx context.Context, hub *Hub, conn *websocket.Conn, chatroomID uuid.UUID, userID uuid.UUID, kafkaProducer *confluentKafka.Producer) (*Client, error)
Expand Down Expand Up @@ -84,6 +84,7 @@ func (s *service) JoinChatRoomByID(ctx context.Context, chatroomId uuid.UUID, us

}

/*
// GetChatRoomInfoByID implements Service.
func (s *service) GetChatRoomInfoByID(ctx context.Context, chatRoomID uuid.UUID) (*ChatRoomInfo, error) {
chatRoomInfo, err := s.Repository.FindChatRoomInfoByID(ctx, chatRoomID)
Expand All @@ -92,7 +93,7 @@ func (s *service) GetChatRoomInfoByID(ctx context.Context, chatRoomID uuid.UUID)
return nil, err
}
return chatRoomInfo, nil
}
} */

// GetChatRoomList implements Service.
func (s *service) GetChatRoomList(ctx context.Context) ([]*ChatRoom, error) {
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
blabber-hive:
image: igh9410/blabber-hive:v1
image: blabber-hive:v1
container_name: blabber-hive
ports:
- "8080:8080"
Expand Down
4 changes: 2 additions & 2 deletions nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ http {
proxy_intercept_errors off;
}

location /ml/ {
proxy_pass http://fastapi;
location /ml/api/ {
proxy_pass http://fastapi/api/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Expand Down

0 comments on commit 7be92a8

Please sign in to comment.