Skip to content

Commit

Permalink
Merge pull request #6 from aengzu/refactor
Browse files Browse the repository at this point in the history
DB 서버 API 수정
  • Loading branch information
aengzu authored Aug 13, 2024
2 parents f391a93 + a07ef27 commit 034d918
Show file tree
Hide file tree
Showing 162 changed files with 2,706 additions and 959 deletions.
25 changes: 4 additions & 21 deletions lib/core/utils/message_utils.dart
Original file line number Diff line number Diff line change
@@ -1,33 +1,16 @@
// lib/utils/message_utils.dart

import 'package:palink_v2/data/models/ai_response.dart';
import 'package:palink_v2/data/models/message_request.dart';
import 'package:palink_v2/domain/models/chat/message.dart';
import 'package:uuid/uuid.dart';

class MessageUtils {
// 서버에 메시지 저장할 때 MessageDto 로 보내야함
// 서버에서 받은 메시지를 Message로 변환해서 사용해야함

// text 와 conversationId 를 주면 알아서 MessageDto 만드는 것.
static MessageRequest createUserMessageDto(String text, int conversationId) {
return MessageRequest(
sender: true,
messageText: text,
timestamp: DateTime.now().toIso8601String(),
conversationId: conversationId,
);
}
import 'package:palink_v2/data/models/ai_response/ai_response.dart';
import 'package:palink_v2/data/models/chat/message_request.dart';


class MessageUtils {
// AIResponse 객체를 MessageDto 로 변환
static MessageRequest convertAIMessageToMessageDto(
AIResponse aiResponse, int conversationId) {
static MessageRequest convertAIMessageToMessageRequest(AIResponse aiResponse) {
return MessageRequest(
sender: false,
messageText: aiResponse.text,
timestamp: DateTime.now().toIso8601String(),
conversationId: conversationId,
);
}
}
20 changes: 20 additions & 0 deletions lib/data/api/auth/auth_api.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'package:dio/dio.dart';
import 'package:palink_v2/data/models/user/user_create_request.dart';
import 'package:palink_v2/data/models/user/user_login_request.dart';
import 'package:palink_v2/data/models/user/user_response.dart';
import 'package:retrofit/http.dart';
part 'auth_api.g.dart';


@RestApi()
abstract class AuthApi {
factory AuthApi(Dio dio, {String baseUrl}) = _AuthApi;


@POST("/login")
Future<UserResponse?> login(@Body() UserLoginRequest body);

@POST("/users")
Future<UserResponse> signUp(@Body() UserCreateRequest body);

}
25 changes: 13 additions & 12 deletions lib/data/api/auth_api.g.dart → lib/data/api/auth/auth_api.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 0 additions & 22 deletions lib/data/api/auth_api.dart

This file was deleted.

21 changes: 21 additions & 0 deletions lib/data/api/character/character_api.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'package:dio/dio.dart';
import 'package:palink_v2/data/models/character/character_response.dart';
import 'package:palink_v2/data/models/character/characters_response.dart';
import 'package:palink_v2/data/models/tip/tip_request.dart';
import 'package:palink_v2/data/models/tip/tip_response.dart';
import 'package:retrofit/http.dart';

part 'character_api.g.dart';


@RestApi()
abstract class CharacterApi {
factory CharacterApi(Dio dio, {String baseUrl}) = _CharacterApi;

@GET("/characters")
Future<CharactersResponse> getAllCharacters();

@GET("/characters/{character_id}")
Future<CharacterResponse> getCharacterById(@Path("character_id") int characterId);

}
104 changes: 104 additions & 0 deletions lib/data/api/character/character_api.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions lib/data/api/chat/chat_api.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// data/api/chat_api.dart
import 'package:dio/dio.dart';
import 'package:palink_v2/data/models/chat/conversation_request.dart';
import 'package:palink_v2/data/models/chat/conversation_response.dart';
import 'package:palink_v2/data/models/chat/conversations_response.dart';
import 'package:palink_v2/data/models/chat/message_request.dart';
import 'package:palink_v2/data/models/chat/message_response.dart';
import 'package:palink_v2/data/models/chat/messages_response.dart';
import 'package:retrofit/retrofit.dart';

part 'chat_api.g.dart';

@RestApi()
abstract class ChatApi {
factory ChatApi(Dio dio, {String baseUrl}) = _ChatApi;

@POST("/conversations")
Future<ConversationResponse> createConversation(@Body() ConversationRequest conversationRequest);

@GET("/conversations/{conversation_id}")
Future<ConversationResponse> getConversationById(@Path("conversation_id") int conversationId);

@GET("/conversations/users/{user_id}")
Future<ConversationsResponse> getConversationsByUserId(@Path("user_id") int userId);

@POST("/conversations/{conversation_id}/messages")
Future<MessageResponse?> saveMessage(@Path("conversation_id") int conversationId, @Body() MessageRequest messageRequest);

@GET("/conversations/{conversation_id}/messages")
Future<MessagesResponse?> getMessagesByChatRoomId(@Path("conversation_id") int conversationId);

@GET("/conversations/{conversation_id}/messages/{message_id}")
Future<MessageResponse> getMessageById(@Path("conversation_id") int conversationId, @Path("message_id") int messageId);

}
Loading

0 comments on commit 034d918

Please sign in to comment.