Skip to content

Commit

Permalink
refactor: auth 관련 리팩토링
Browse files Browse the repository at this point in the history
  • Loading branch information
aengzu committed Aug 12, 2024
1 parent f391a93 commit 207258b
Show file tree
Hide file tree
Showing 78 changed files with 322 additions and 234 deletions.
17 changes: 1 addition & 16 deletions lib/core/utils/message_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,9 @@

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,
);
}


class MessageUtils {
// AIResponse 객체를 MessageDto 로 변환
static MessageRequest convertAIMessageToMessageDto(
AIResponse aiResponse, int conversationId) {
Expand Down
15 changes: 7 additions & 8 deletions lib/data/api/auth_api.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:dio/dio.dart';
import 'package:palink_v2/domain/models/user/user.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';

Expand All @@ -8,15 +10,12 @@ part 'auth_api.g.dart';
abstract class AuthApi {
factory AuthApi(Dio dio, {String baseUrl}) = _AuthApi;

static const String _loginEndpoint = "/api/user/login";
static const String _registerEndpoint = "/api/user/register";

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

@POST(_loginEndpoint)
Future<User?> login(@Body() Map<String, dynamic> body);


@POST(_registerEndpoint)
Future<User> signUp(@Body() Map<String, dynamic> body);
@POST("/users")
Future<UserResponse> signUp(@Body() UserCreateRequest body);

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

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

5 changes: 3 additions & 2 deletions lib/data/api/openai_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import 'package:langchain_openai/langchain_openai.dart';
import 'package:palink_v2/core/constants/app_url.dart';
import 'package:palink_v2/core/constants/prompts.dart';
import 'package:palink_v2/data/models/ai_response.dart';
import 'package:palink_v2/domain/models/character/character.dart';
import 'package:palink_v2/domain/models/user/user.dart';
import 'package:palink_v2/domain/entities/character/character.dart';
import 'package:palink_v2/domain/entities/user/user.dart';


class OpenAIService {
String? get apiKey => AppUrl().apiKey;
Expand Down
4 changes: 3 additions & 1 deletion lib/data/mapper/character_mapper.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// data/mappers/character_mapper.dart


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

class CharacterMapper {
static Character fromEntity(CharacterEntity entity) {
Expand Down
13 changes: 13 additions & 0 deletions lib/data/mapper/login_mapper.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 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';


extension LoginMapper on LoginModel {
UserLoginRequest toData() {
return UserLoginRequest(
accountId: accountId,
password: password,
);
}
}
3 changes: 2 additions & 1 deletion lib/data/mapper/mindset_mappder.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:palink_v2/data/entities/mindset_entity.dart';
import 'package:palink_v2/domain/models/mindset/mindset.dart';
import 'package:palink_v2/domain/entities/mindset/mindset.dart';


class MindsetMapper {
static Mindset fromEntity(MindsetEntity entity) {
Expand Down
15 changes: 15 additions & 0 deletions lib/data/mapper/signup_mapper.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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';

extension SignupMapper on SignupModel {
UserCreateRequest toData() {
return UserCreateRequest(
accountId: accountId,
name: name,
age: age,
personalityType: personalityType,
password: password,
);
}
}
17 changes: 17 additions & 0 deletions lib/data/mapper/user_mapper.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// data/mappers/user_mapper.dart
import 'package:palink_v2/domain/entities/user/user.dart';

import '../models/user/user_response.dart';

extension UserMapper on UserResponse {
User toDomain() {
return User(
accountId: accountId,
name: name,
age: age,
personalityType: personalityType,
userId: userId,
);
}
}

2 changes: 0 additions & 2 deletions lib/data/models/message_response.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import 'package:json_annotation/json_annotation.dart';
import 'package:palink_v2/domain/models/chat/message.dart';

part 'message_response.g.dart';

@JsonSerializable()
Expand Down
25 changes: 25 additions & 0 deletions lib/data/models/user/user_create_request.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// data/entities/user_create_request.dart
import 'package:json_annotation/json_annotation.dart';

part 'user_create_request.g.dart';

@JsonSerializable()
class UserCreateRequest {
final String accountId;
final String name;
final int age;
final String personalityType;
final String password;

UserCreateRequest({
required this.accountId,
required this.name,
required this.age,
required this.personalityType,
required this.password,
});

factory UserCreateRequest.fromJson(Map<String, dynamic> json) => _$UserCreateRequestFromJson(json);

Map<String, dynamic> toJson() => _$UserCreateRequestToJson(this);
}

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

19 changes: 19 additions & 0 deletions lib/data/models/user/user_login_request.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// data/entities/user_create_request.dart
import 'package:json_annotation/json_annotation.dart';

part 'user_login_request.g.dart';

@JsonSerializable()
class UserLoginRequest {
final String accountId;
final String password;

UserLoginRequest({
required this.accountId,
required this.password,
});

factory UserLoginRequest.fromJson(Map<String, dynamic> json) => _$UserLoginRequestFromJson(json);

Map<String, dynamic> toJson() => _$UserLoginRequestToJson(this);
}

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

25 changes: 25 additions & 0 deletions lib/data/models/user/user_response.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// data/entities/user_response.dart
import 'package:json_annotation/json_annotation.dart';

part 'user_response.g.dart';

@JsonSerializable()
class UserResponse {
final String accountId;
final String name;
final int age;
final String personalityType;
final int userId;

UserResponse({
required this.accountId,
required this.name,
required this.age,
required this.personalityType,
required this.userId,
});

factory UserResponse.fromJson(Map<String, dynamic> json) => _$UserResponseFromJson(json);

Map<String, dynamic> toJson() => _$UserResponseToJson(this);
}
24 changes: 24 additions & 0 deletions lib/data/models/user/user_response.g.dart

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

6 changes: 2 additions & 4 deletions lib/data/repository/ai_repositoryImpl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import 'package:langchain/langchain.dart';
import 'package:langchain_openai/langchain_openai.dart';
import 'package:palink_v2/core/constants/prompts.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/analysis_dto/analysis_dto.dart';
import 'package:palink_v2/domain/models/chat/message.dart';
import 'package:palink_v2/domain/models/tip/tip_dto.dart';
import 'package:palink_v2/domain/entities/analysis/analysis_dto.dart';
import 'package:palink_v2/domain/entities/tip/tip.dart';
import 'package:palink_v2/domain/repository/ai_repository.dart';

class AIRepositoryImpl implements AIRepository {
Expand Down
Loading

0 comments on commit 207258b

Please sign in to comment.