Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] 대화 히스토리 조회 추가 #16

Merged
merged 4 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/data/entities/character_entity.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// data/entities/character_entity.dart
// data/model/character_entity.dart
import 'package:floor/floor.dart';

@Entity(tableName: 'characters')
Expand Down
2 changes: 1 addition & 1 deletion lib/data/entities/character_quest_entity.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// data/entities/character_quest_entity.dart
// data/model/character_quest_entity.dart
import 'package:floor/floor.dart';

@Entity(tableName: 'character_quests')
Expand Down
57 changes: 32 additions & 25 deletions lib/data/mapper/ai_response_mapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import 'package:palink_v2/data/models/ai_response/ai_response.dart';
import 'package:palink_v2/data/models/ai_response/liking_response.dart';
import 'package:palink_v2/data/models/ai_response/rejection_response.dart';
import 'package:palink_v2/data/models/chat/message_request.dart';
import 'package:palink_v2/domain/entities/character/character.dart';
import 'package:palink_v2/domain/model/character/character.dart';

extension AIResponseMapper on AIResponse {
MessageRequest toMessageRequest() {
return MessageRequest(
sender: false,
messageText: text, // AIResponse의 텍스트 사용
timestamp: DateTime.now().toIso8601String(), // 현재 시간을 타임스탬프로 변환
aiResponse: this, // AIResponse를 그대로 매핑
messageText: text, // AIResponse의 텍스트 사용
timestamp: DateTime.now().toIso8601String(), // 현재 시간을 타임스탬프로 변환
aiResponse: this, // AIResponse를 그대로 매핑
);
}
}
Expand All @@ -20,51 +20,59 @@ extension InitialAIResponseMapper on AIResponse {
MessageRequest toInitialMessageRequest() {
return MessageRequest(
sender: true,
messageText: text, // AIResponse의 텍스트 사용
timestamp: DateTime.now().toIso8601String(), // 현재 시간을 타임스탬프로 변환
aiResponse: this, // AIResponse를 그대로 매핑
messageText: text, // AIResponse의 텍스트 사용
timestamp: DateTime.now().toIso8601String(), // 현재 시간을 타임스탬프로 변환
aiResponse: this, // AIResponse를 그대로 매핑
);
}
}


extension InitialAIMessageResponseMapper on AIMessageResponse {
AIResponse toInitialAIResponse(LikingResponse likingResponse) {
return AIResponse(
text: message,
feeling: likingResponse.feeling, // LikabilityResponse의 feeling을 AIResponse의 feeling으로 매핑
affinityScore: likingResponse.likability, // 호감도 점수 매핑
feeling: likingResponse.feeling,
// LikabilityResponse의 feeling을 AIResponse의 feeling으로 매핑
affinityScore: likingResponse.likability,
// 호감도 점수 매핑
rejectionScore: [],
rejectionContent: [], // 거절 카테고리 리스트 그대로 매핑
finalRejectionScore: 0, // 최종 거절 점수 (거절 카테고리 수로 계산)
finalAffinityScore: 0, // 최종 호감도 점수 그대로 사용
rejectionContent: [],
// 거절 카테고리 리스트 그대로 매핑
finalRejectionScore: 0,
// 최종 거절 점수 (거절 카테고리 수로 계산)
finalAffinityScore: 0, // 최종 호감도 점수 그대로 사용
);
}
}

extension AIMessageResponseMapper on AIMessageResponse {
AIResponse toAIResponse(LikingResponse likingResponse, RejectionResponse rejectionResponse, Character character) {
AIResponse toAIResponse(LikingResponse likingResponse,
RejectionResponse rejectionResponse, Character character) {
final rejectionScores = getRejectionScoresByCharacter(character);

// rejectionContent 리스트를 기반으로 rejectionScore 리스트 생성
List<int> rejectionScoreList = rejectionResponse.rejectionContent
.map((category) => rejectionScores[category] ?? 0) // 점수를 찾고, 없으면 0으로 설정
.map((category) => rejectionScores[category] ?? 0) // 점수를 찾고, 없으면 0으로 설정
.toList();

return AIResponse(
text: message, // ChatResponse의 텍스트를 AIResponse의 텍스트로 설정
feeling: likingResponse.feeling, // 감정 분석 결과를 그대로 매핑
affinityScore: likingResponse.likability, // 호감도 점수 매핑
rejectionScore: rejectionScoreList, // 계산된 rejectionScore 리스트
rejectionContent: rejectionResponse.rejectionContent, // 거절 카테고리 리스트
finalRejectionScore: 0, // 계산된 최종 거절 점수
finalAffinityScore: 0, // 최종 호감도 점수 그대로 사용
text: message,
// ChatResponse의 텍스트를 AIResponse의 텍스트로 설정
feeling: likingResponse.feeling,
// 감정 분석 결과를 그대로 매핑
affinityScore: likingResponse.likability,
// 호감도 점수 매핑
rejectionScore: rejectionScoreList,
// 계산된 rejectionScore 리스트
rejectionContent: rejectionResponse.rejectionContent,
// 거절 카테고리 리스트
finalRejectionScore: 0,
// 계산된 최종 거절 점수
finalAffinityScore: 0, // 최종 호감도 점수 그대로 사용
);
}
}



Map<String, int> getRejectionScoresByCharacter(Character character) {
// 캐릭터별 거절 점수표를 반환하는 함수
switch (character.name) {
Expand Down Expand Up @@ -147,4 +155,3 @@ Map<String, int> getRejectionScoresByCharacter(Character character) {
return {};
}
}

3 changes: 1 addition & 2 deletions lib/data/mapper/character_mapper.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// data/mappers/character_mapper.dart


import 'package:palink_v2/data/entities/character_entity.dart';
import 'package:palink_v2/domain/entities/character/character.dart';
import 'package:palink_v2/domain/model/character/character.dart';

class CharacterMapper {
static Character fromEntity(CharacterEntity entity) {
Expand Down
13 changes: 13 additions & 0 deletions lib/data/mapper/conversation_mapper.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'package:palink_v2/data/models/chat/conversation_response.dart';
import 'package:palink_v2/domain/model/chat/conversation.dart';

extension ConversationMapper on ConversationResponse {
Conversation toDomain() {
return Conversation(
conversationId: conversationId,
day: DateTime.parse(day),
userId: userId,
characterId: characterId,
);
}
}
3 changes: 1 addition & 2 deletions lib/data/mapper/login_mapper.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// data/mappers/login_mapper.dart
import 'package:palink_v2/data/models/user/user_login_request.dart';
import 'package:palink_v2/domain/entities/auth/login_model.dart';

import 'package:palink_v2/domain/model/auth/login_model.dart';

extension LoginMapper on LoginModel {
UserLoginRequest toData() {
Expand Down
4 changes: 1 addition & 3 deletions lib/data/mapper/message_response_mapper.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:palink_v2/data/models/chat/message_response.dart';
import 'package:palink_v2/domain/entities/chat/message.dart';

import 'package:palink_v2/domain/model/chat/message.dart';

extension MessageResponseMapper on MessageResponse {
Message toDomain() {
Expand All @@ -12,4 +11,3 @@ extension MessageResponseMapper on MessageResponse {
);
}
}

5 changes: 2 additions & 3 deletions lib/data/mapper/message_util.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

import 'package:palink_v2/data/models/chat/message_response.dart';
import 'package:palink_v2/domain/entities/chat/message.dart';
import 'package:palink_v2/domain/model/chat/message.dart';

class MessageResponseMapper {
// MessageResponse를 Message로 변환하는 메서드
Expand All @@ -12,4 +11,4 @@ class MessageResponseMapper {
timestamp: response.timestamp,
);
}
}
}
2 changes: 1 addition & 1 deletion lib/data/mapper/signup_mapper.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// data/mappers/signup_mapper.dart
import 'package:palink_v2/data/models/user/user_create_request.dart';
import 'package:palink_v2/domain/entities/auth/signup_model.dart';
import 'package:palink_v2/domain/model/auth/signup_model.dart';

extension SignupMapper on SignupModel {
UserCreateRequest toData() {
Expand Down
4 changes: 1 addition & 3 deletions lib/data/mapper/user_mapper.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// data/mappers/user_mapper.dart
import 'package:palink_v2/domain/entities/user/user.dart';

import 'package:palink_v2/domain/model/user/user.dart';
import '../models/user/user_response.dart';

extension UserMapper on UserResponse {
Expand All @@ -13,4 +12,3 @@ extension UserMapper on UserResponse {
);
}
}

1 change: 1 addition & 0 deletions lib/data/models/chat/conversation_response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ class ConversationResponse {
factory ConversationResponse.fromJson(Map<String, dynamic> json) => _$ConversationResponseFromJson(json);
Map<String, dynamic> toJson() => _$ConversationResponseToJson(this);
}

2 changes: 1 addition & 1 deletion lib/data/models/user/user_collection_request.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// data/entities/user_create_request.dart
// data/model/user_create_request.dart
import 'package:json_annotation/json_annotation.dart';

part 'user_collection_request.g.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/data/models/user/user_collection_response.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// data/entities/user_response.dart
// data/model/user_response.dart
import 'package:json_annotation/json_annotation.dart';

part 'user_collection_response.g.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/data/models/user/user_create_request.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// data/entities/user_create_request.dart
// data/model/user_create_request.dart
import 'package:json_annotation/json_annotation.dart';

part 'user_create_request.g.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/data/models/user/user_login_request.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// data/entities/user_create_request.dart
// data/model/user_create_request.dart
import 'package:json_annotation/json_annotation.dart';

part 'user_login_request.g.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/data/models/user/user_response.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// data/entities/user_response.dart
// data/model/user_response.dart
import 'package:json_annotation/json_annotation.dart';

part 'user_response.g.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/data/models/user/user_update_request.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// data/entities/user_create_request.dart
// data/model/user_create_request.dart
import 'package:json_annotation/json_annotation.dart';

part 'user_update_request.g.dart';
Expand Down
16 changes: 5 additions & 11 deletions lib/data/repository/auth_repositoryImpl.dart
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@

import 'package:palink_v2/data/api/auth/auth_api.dart';
import 'package:palink_v2/data/api/user/user_api.dart';
import 'package:palink_v2/data/mapper/login_mapper.dart';
import 'package:palink_v2/data/mapper/signup_mapper.dart';
import 'package:palink_v2/data/mapper/user_mapper.dart';
import 'package:palink_v2/domain/entities/auth/login_model.dart';
import 'package:palink_v2/domain/entities/auth/signup_model.dart';
import 'package:palink_v2/domain/entities/user/user.dart';
import 'package:palink_v2/domain/model/auth/login_model.dart';
import 'package:palink_v2/domain/model/auth/signup_model.dart';
import 'package:palink_v2/domain/model/user/user.dart';
import 'package:palink_v2/domain/repository/auth_repository.dart';
import 'package:shared_preferences/shared_preferences.dart';

import '../../domain/repository/auth_repository.dart';


class AuthRepositoryImpl implements AuthRepository {

final AuthApi _authApi;
final UserApi _userApi;
final SharedPreferences _prefs;

AuthRepositoryImpl(this._authApi, this._userApi, this._prefs);


@override
Future<User?> login(LoginModel loginModel) async {
try {
Expand Down Expand Up @@ -70,5 +65,4 @@ class AuthRepositoryImpl implements AuthRepository {
await _prefs.remove('userId');
await _prefs.remove('isLoggedIn');
}

}
}
12 changes: 7 additions & 5 deletions lib/data/repository/character_quest_repositoryImpl.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// data/repositories/character_quest_repository_impl.dart

import 'package:palink_v2/data/dao/character_quest_dao.dart';
import 'package:palink_v2/domain/entities/character/character_quest.dart';
import 'package:palink_v2/domain/model/character/character_quest.dart';
import 'package:palink_v2/domain/repository/character_quest_repository.dart';

class CharacterQuestRepositoryImpl implements CharacterQuestRepository {
Expand All @@ -12,10 +12,12 @@ class CharacterQuestRepositoryImpl implements CharacterQuestRepository {
@override
Future<List<CharacterQuest>> getAllCharacterQuests() async {
final entities = await characterQuestDao.getAllCharacterQuests();
return entities.map((entity) => CharacterQuest(
characterId: entity.characterId,
quests: entity.quests.split(','),
)).toList();
return entities
.map((entity) => CharacterQuest(
characterId: entity.characterId,
quests: entity.quests.split(','),
))
.toList();
}

@override
Expand Down
2 changes: 1 addition & 1 deletion lib/data/repository/character_repositoryImpl.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:palink_v2/data/dao/character_dao.dart';
import 'package:palink_v2/data/mapper/character_mapper.dart';
import 'package:palink_v2/di/locator.dart';
import 'package:palink_v2/domain/entities/character/character.dart';
import 'package:palink_v2/domain/model/character/character.dart';
import 'package:palink_v2/domain/repository/character_repository.dart';

class CharacterRepositoryImpl implements CharacterRepository {
Expand Down
27 changes: 19 additions & 8 deletions lib/data/repository/chat_repositoryImpl.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

import 'package:palink_v2/data/api/chat/chat_api.dart';
import 'package:palink_v2/data/models/chat/ai_response_response.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';
Expand All @@ -16,12 +16,14 @@ class ChatRepositoryImpl implements ChatRepository {
ChatRepositoryImpl(this.chatApi);

@override
Future<ConversationResponse> createConversation(ConversationRequest conversationRequest) {
Future<ConversationResponse> createConversation(
ConversationRequest conversationRequest) {
return chatApi.createConversation(conversationRequest);
}

@override
Future<MessageResponse?> saveMessage(int conversationId, MessageRequest messageRequest) {
Future<MessageResponse?> saveMessage(
int conversationId, MessageRequest messageRequest) {
return chatApi.saveMessage(conversationId, messageRequest);
}

Expand All @@ -31,20 +33,29 @@ class ChatRepositoryImpl implements ChatRepository {
}

@override
Future<ConversationResponse> fetchConversationByChatRoomId(int conversationId) {
Future<ConversationResponse> fetchConversationByChatRoomId(
int conversationId) {
return chatApi.getConversationById(conversationId);
}

@override
Future<List<AIResponseResponse>> fetchAIResponseByMessageId(int conversationId, int messageId) {
Future<List<AIResponseResponse>> fetchAIResponseByMessageId(
int conversationId, int messageId) {
return chatApi.getAIResponsesByMessageId(conversationId, messageId);
}

@override
Future<List<AIResponseResponse>> fetchAIResponsesByConversationId(int conversationId) {
Future<List<AIResponseResponse>> fetchAIResponsesByConversationId(
int conversationId) {
return chatApi.getAIResponsesByConversationId(conversationId);
}


@override
Future<List<ConversationResponse>> fetchConversationsByUserId(
int userId) async {
ConversationsResponse response =
await chatApi.getConversationsByUserId(userId);
return response
.conversations; // ConversationsResponse에서 conversations 리스트 추출
}
}

6 changes: 1 addition & 5 deletions lib/data/repository/mindset_repositoryImpl.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@


import 'package:palink_v2/data/api/mindset/mindset_api.dart';
import 'package:palink_v2/data/models/mindset/mindset_response.dart';
import 'package:palink_v2/domain/entities/mindset/mindset.dart';
import 'package:palink_v2/domain/model/mindset/mindset.dart';
import 'package:palink_v2/domain/repository/mindset_repository.dart';


class MindsetRepositoryImpl implements MindsetRepository {
final MindsetApi mindsetApi;

Expand All @@ -15,5 +12,4 @@ class MindsetRepositoryImpl implements MindsetRepository {
Future<MindsetResponse?> getRandomMindset() async {
return mindsetApi.getRandomMindset();
}

}
Loading
Loading