-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
1,394 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# AuthService API | ||
|
||
## POST /auth/signup | ||
|
||
Creates a new user account. | ||
|
||
### Parameters | ||
|
||
- `email` (string, required): The email address of the user. | ||
- `password` (string, required): The password for the user. | ||
- `username` (string, required): The username for the user. | ||
|
||
### Returns | ||
|
||
If successful, returns a JSON object with the following properties: | ||
|
||
- `session` (object): The session information. | ||
- `user` (object): The user information. | ||
|
||
If unsuccessful, returns a JSON object with the following property: | ||
|
||
- `error` (string): The error message. | ||
|
||
## POST /auth/login | ||
|
||
Logs in an existing user. | ||
|
||
### Parameters | ||
|
||
- `email` (string, required): The email address of the user. | ||
- `password` (string, required): The password for the user. | ||
|
||
### Returns | ||
|
||
If successful, returns a JSON object with the following properties: | ||
|
||
- `session` (object): The session information. | ||
- `user` (object): The user information. | ||
|
||
If unsuccessful, returns a JSON object with the following property: | ||
|
||
- `error` (string): The error message. | ||
|
||
## POST /auth/logout | ||
|
||
Logs out the current user. | ||
|
||
### Returns | ||
|
||
No content. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# ChatService API | ||
|
||
## GET /chats/{userId} | ||
|
||
Retrieves a list of chats for a specific user. | ||
|
||
### Parameters | ||
|
||
- `userId` (string, required): The ID of the user to retrieve chats for. | ||
|
||
### Returns | ||
|
||
If successful, returns a JSON array of chats. Each chat is an object with the following properties: | ||
|
||
- `id` (string): The ID of the chat. | ||
- `participants` (array): An array of user IDs participating in the chat. | ||
- `lastMessage` (object): The last message sent in the chat, with `content` (string) and `timestamp` (string) properties. | ||
|
||
If unsuccessful, returns an empty array. | ||
|
||
## POST /chats | ||
|
||
Starts a new chat. | ||
|
||
### Parameters | ||
|
||
- `participants` (array, required): An array of user IDs to participate in the chat. | ||
|
||
### Returns | ||
|
||
If successful, returns a JSON object with the following properties: | ||
|
||
- `id` (string): The ID of the newly created chat. | ||
|
||
If unsuccessful, returns `null`. | ||
|
||
## GET /chats/{chatId}/messages | ||
|
||
Retrieves a list of messages for a specific chat. | ||
|
||
### Parameters | ||
|
||
- `chatId` (string, required): The ID of the chat to retrieve messages for. | ||
|
||
### Returns | ||
|
||
If successful, returns a JSON array of messages. Each message is an object with the following properties: | ||
|
||
- `id` (string): The ID of the message. | ||
- `sender` (string): The ID of the user who sent the message. | ||
- `content` (string): The content of the message. | ||
- `timestamp` (string): The timestamp when the message was sent. | ||
|
||
If unsuccessful, returns an empty array. | ||
|
||
## POST /chats/{chatId}/messages | ||
|
||
Sends a new message in a specific chat. | ||
|
||
### Parameters | ||
|
||
- `chatId` (string, required): The ID of the chat to send the message in. | ||
- `content` (string, required): The content of the message to send. | ||
|
||
### Returns | ||
|
||
If successful, returns a JSON object with the following properties: | ||
|
||
- `id` (string): The ID of the newly sent message. | ||
|
||
If unsuccessful, returns `null`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# ConnectionsService API | ||
|
||
## GET /connections | ||
|
||
Retrieves a list of connections for the current user. | ||
|
||
### Returns | ||
|
||
If successful, returns a JSON array of connections. Each connection is an object with the following properties: | ||
|
||
- `(id, username)` (object): The profile information of the connected user. | ||
|
||
If unsuccessful, returns an empty array. | ||
|
||
## DELETE /connections/{id} | ||
|
||
Deletes a connection for the current user. | ||
|
||
### Parameters | ||
|
||
- `id` (string, required): The ID of the connection to delete. | ||
|
||
### Returns | ||
|
||
No content. | ||
|
||
## POST /connections | ||
|
||
Adds a new connection for the current user. | ||
|
||
### Parameters | ||
|
||
- `id` (string, required): The ID of the user to connect with. | ||
|
||
### Returns | ||
|
||
No content. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# ProfileService API | ||
|
||
## GET /profiles/{id} | ||
|
||
Retrieves a profile by ID. | ||
|
||
### Parameters | ||
|
||
- `id` (string, required): The ID of the profile to retrieve. | ||
|
||
### Returns | ||
|
||
If successful, returns a JSON object with the following properties: | ||
|
||
- `id` (string): The ID of the profile. | ||
- `username` (string): The username of the profile. | ||
- `tags` (array): An array of tags associated with the profile. | ||
- `isFollowing` (boolean): Whether the current user is following this profile. | ||
|
||
If unsuccessful, returns `null`. | ||
|
||
## GET /profiles/recommended | ||
|
||
Retrieves a list of recommended profile IDs for the current user. | ||
|
||
### Returns | ||
|
||
If successful, returns a JSON array of strings, where each string is a profile ID. | ||
|
||
If unsuccessful, returns an empty array. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# SearchService API | ||
|
||
## GET /search/users/{query} | ||
|
||
Searches for users based on a query string. | ||
|
||
### Parameters | ||
|
||
- `query` (string, required): The search query string. | ||
|
||
### Returns | ||
|
||
If successful, returns a JSON array of users. Each user is an object with the following properties: | ||
|
||
- `id` (string): The ID of the user. | ||
- `username` (string): The username of the user. | ||
|
||
If unsuccessful, returns an empty array. | ||
|
||
## GET /search/tags/{query} | ||
|
||
Searches for tags based on a query string. | ||
|
||
### Parameters | ||
|
||
- `query` (string, required): The search query string. | ||
|
||
### Returns | ||
|
||
If successful, returns a JSON array of tags. Each tag is an object with the following properties: | ||
|
||
- `id` (string): The ID of the tag. | ||
- `tag` (string): The tag text. | ||
|
||
If unsuccessful, returns an empty array. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# TagService API | ||
|
||
## GET /tags/{userId} | ||
|
||
Retrieves a list of tags for a specific user. | ||
|
||
### Parameters | ||
|
||
- `userId` (string, required): The ID of the user to retrieve tags for. | ||
|
||
### Returns | ||
|
||
If successful, returns a JSON array of tags. Each tag is an object with the following properties: | ||
|
||
- `id` (string): The ID of the tag. | ||
- `tag` (string): The tag text. | ||
- `isConnected` (boolean): Whether the current user is connected to this tag. | ||
|
||
If unsuccessful, returns `null`. | ||
|
||
## GET /tags/currentUser | ||
|
||
Retrieves a list of tags for the current user. | ||
|
||
### Returns | ||
|
||
If successful, returns a JSON array of tags. Each tag is an object with the following properties: | ||
|
||
- `id` (string): The ID of the tag. | ||
- `tag` (string): The tag text. | ||
- `isConnected` (boolean): Always `true` for this endpoint. | ||
|
||
If unsuccessful, returns `null`. | ||
|
||
## DELETE /tags/{tagId} | ||
|
||
Deletes a tag for the current user. | ||
|
||
### Parameters | ||
|
||
- `tagId` (string, required): The ID of the tag to delete. | ||
|
||
### Returns | ||
|
||
No content. | ||
|
||
## POST /tags | ||
|
||
Adds a new tag for the current user. | ||
|
||
### Parameters | ||
|
||
- `tag` (string, required): The tag text to add. | ||
|
||
### Returns | ||
|
||
No content. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:study_match/chat/services/chat_service.dart'; | ||
import 'package:study_match/core/models/chat_message.dart'; | ||
import 'package:supabase_flutter/supabase_flutter.dart'; | ||
|
||
part 'chat_screen_state.dart'; | ||
|
||
class ChatScreenCubit extends Cubit<ChatScreenState> { | ||
final ChatService _chatService = ChatService.instance; | ||
final String chatId; | ||
late final StreamSubscription _chatSubscription; | ||
|
||
ChatScreenCubit(this.chatId) : super(const ChatScreenState([])) { | ||
loadChatMessages(chatId); | ||
_chatSubscription = Supabase.instance.client | ||
.from('chat_messages') | ||
.stream(primaryKey: ['id']) | ||
.order('created_at', ascending: true) | ||
.eq('chat_id', chatId) | ||
.listen( | ||
(List<Map<String, dynamic>> data) { | ||
emit( | ||
ChatScreenState( | ||
data | ||
.map((e) => ChatMessage( | ||
id: e['id'] as String, | ||
senderId: e['sender_id'] as String, | ||
senderUserName: e['sender_name'] as String?, | ||
chatId: e['chat_id'] as String, | ||
message: e['message'] as String, | ||
)) | ||
.toList(), | ||
), | ||
); | ||
}, | ||
); | ||
} | ||
|
||
void addMessage(ChatMessage message) { | ||
final newChatMessages = List<ChatMessage>.from(state.chatMessages) | ||
..add(message); | ||
emit(ChatScreenState(newChatMessages)); | ||
} | ||
|
||
Future<void> loadChatMessages(String chatId) async { | ||
final newChatMessages = await _chatService.loadChatMessages(chatId); | ||
emit(ChatScreenState(newChatMessages)); | ||
} | ||
|
||
Future<void> sendMessage(String message) async { | ||
final currentUserId = Supabase.instance.client.auth.currentUser!.id; | ||
await _chatService.sendMessage(chatId, currentUserId, message); | ||
} | ||
|
||
@override | ||
Future<void> close() { | ||
_chatSubscription.cancel(); | ||
return super.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
part of 'chat_screen_cubit.dart'; | ||
|
||
class ChatScreenState extends Equatable { | ||
const ChatScreenState(this.chatMessages); | ||
|
||
final List<ChatMessage> chatMessages; | ||
|
||
@override | ||
List<Object> get props => [chatMessages]; | ||
} |
Oops, something went wrong.