Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
WebBack
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
websystem
WebBack
Commits
8300ebdc
Commit
8300ebdc
authored
3 months ago
by
심재엽
Browse files
Options
Downloads
Patches
Plain Diff
feat: 채팅 컨트롤러 (
#9
)
parent
84096ad2
No related branches found
Branches containing commit
No related tags found
2 merge requests
!31
Develop
,
!11
[#9] 번개모임, 채팅 로직 구현
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
controllers/chatController.js
+105
-0
105 additions, 0 deletions
controllers/chatController.js
with
105 additions
and
0 deletions
controllers/chatController.js
+
105
−
0
View file @
8300ebdc
const
chatService
=
require
(
'
../services/chatService
'
);
// 내부용 채팅방 생성
exports
.
createChatRoomInternal
=
async
(
params
)
=>
{
try
{
return
await
chatService
.
createChatRoom
(
params
);
}
catch
(
err
)
{
console
.
error
(
'
Error in createChatRoomInternal:
'
,
err
);
return
{
success
:
false
,
error
:
err
.
message
};
}
};
// 새 채팅방 생성
exports
.
createChatRoom
=
async
(
req
,
res
)
=>
{
try
{
const
chatRoomId
=
await
chatService
.
createChatRoom
();
res
.
json
({
chatRoomId
});
}
catch
(
err
)
{
console
.
error
(
'
Error creating room:
'
,
err
);
res
.
status
(
500
).
json
({
error
:
'
Failed to create room
'
});
}
};
// 채팅방 목록 조회
exports
.
getChatRooms
=
async
(
req
,
res
)
=>
{
try
{
const
roomData
=
await
chatService
.
getChatRooms
();
res
.
json
(
roomData
);
}
catch
(
err
)
{
console
.
error
(
'
Error fetching rooms:
'
,
err
);
res
.
status
(
500
).
json
({
error
:
'
Failed to fetch rooms
'
});
}
};
// 사용자 상태 업데이트
exports
.
updateStatus
=
async
(
req
,
res
)
=>
{
const
{
chatRoomId
,
nickname
,
isOnline
}
=
req
.
body
;
try
{
await
chatService
.
updateStatus
(
chatRoomId
,
nickname
,
isOnline
);
res
.
status
(
200
).
json
({
message
:
'
User status updated successfully
'
});
}
catch
(
err
)
{
console
.
error
(
'
Error updating user status:
'
,
err
);
res
.
status
(
500
).
json
({
error
:
'
Failed to update user status
'
});
}
};
// 읽음 상태 업데이트
exports
.
updateReadStatus
=
async
(
req
,
res
)
=>
{
const
{
chatRoomId
,
nickname
}
=
req
.
body
;
try
{
await
chatService
.
updateReadStatus
(
chatRoomId
,
nickname
);
res
.
status
(
200
).
json
({
message
:
'
Read status updated
'
});
}
catch
(
err
)
{
console
.
error
(
'
Error updating read status:
'
,
err
);
res
.
status
(
500
).
json
({
error
:
'
Failed to update read status
'
});
}
};
// 읽지 않은 메시지 조회
exports
.
getUnreadMessages
=
async
(
req
,
res
)
=>
{
const
{
nickname
}
=
req
.
params
;
try
{
const
unreadMessages
=
await
chatService
.
getUnreadMessages
(
nickname
);
res
.
status
(
200
).
json
(
unreadMessages
);
}
catch
(
err
)
{
console
.
error
(
'
Error fetching unread messages:
'
,
err
);
res
.
status
(
500
).
json
({
error
:
'
Failed to fetch unread messages
'
});
}
};
// 읽지 않은 메시지 수 조회
exports
.
getUnreadCount
=
async
(
req
,
res
)
=>
{
const
{
chatRoomId
}
=
req
.
params
;
try
{
const
unreadCountMap
=
await
chatService
.
getUnreadCount
(
chatRoomId
);
res
.
status
(
200
).
json
(
unreadCountMap
);
}
catch
(
err
)
{
console
.
error
(
'
Error fetching unread counts:
'
,
err
);
res
.
status
(
500
).
json
({
error
:
'
Failed to fetch unread counts
'
});
}
};
// 읽은 로그 ID 업데이트
exports
.
updateReadLogId
=
async
(
req
,
res
)
=>
{
const
{
chatRoomId
,
nickname
,
logId
}
=
req
.
body
;
try
{
await
chatService
.
updateReadLogId
(
chatRoomId
,
nickname
,
logId
);
res
.
status
(
200
).
json
({
message
:
'
Last read logID updated
'
});
}
catch
(
err
)
{
console
.
error
(
'
Error updating last read logID:
'
,
err
);
res
.
status
(
500
).
json
({
error
:
'
Failed to update last read logID
'
});
}
};
// 상태와 로그 ID 동시 업데이트
exports
.
updateStatusAndLogId
=
async
(
req
,
res
)
=>
{
const
{
chatRoomId
,
nickname
,
isOnline
,
logId
}
=
req
.
body
;
try
{
await
chatService
.
updateStatusAndLogId
(
chatRoomId
,
nickname
,
isOnline
,
logId
);
res
.
status
(
200
).
json
({
message
:
'
User status and lastReadLogId updated successfully
'
});
}
catch
(
err
)
{
console
.
error
(
'
Error updating user status and lastReadLogId:
'
,
err
);
res
.
status
(
500
).
json
({
error
:
'
Failed to update user status and lastReadLogId
'
});
}
};
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment