-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. AccountApi.login() 추가 2. MockApi를 ApiImpl 상속을 통해 중복 코드 제거
- Loading branch information
1 parent
f14e8ce
commit 52d37a2
Showing
7 changed files
with
77 additions
and
15 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1 +1 @@ | ||
export 'login/response/login_response_dto.dart'; | ||
export 'login/login.dart'; |
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 |
---|---|---|
@@ -1,3 +1,25 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:withu_app/core/core.dart'; | ||
import 'package:withu_app/feature/account/account.dart'; | ||
|
||
class AccountMockApi extends AccountApi {} | ||
class AccountMockApi extends AccountApiImpl with MockAPI { | ||
/// 로그인 API | ||
@override | ||
FutureOr<ApiResponse<LoginResponseDto>> login({ | ||
required LoginRequestDto requestData, | ||
}) async { | ||
/// Mock 응답 등록 | ||
dioAdapter.onPost( | ||
loginPath, | ||
(server) => server.reply( | ||
200, | ||
LoginResponseDtoMock.success().toJson(), | ||
delay: const Duration(seconds: 1), | ||
), | ||
data: requestData.toJson(), | ||
); | ||
|
||
return await super.login(requestData: requestData); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,17 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:withu_app/core/core.dart'; | ||
import 'package:withu_app/feature/account/data/data_sources/dto/dto.dart'; | ||
|
||
abstract class AccountApi extends API { | ||
/// API 주소 | ||
final path = "/api/account"; | ||
|
||
/// 로그인 주소 | ||
late final loginPath = '$path/login'; | ||
|
||
/// 로그인 API | ||
FutureOr<ApiResponse<LoginResponseDto>> login({ | ||
required LoginRequestDto requestData, | ||
}); | ||
} |
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 |
---|---|---|
@@ -1,3 +1,22 @@ | ||
import 'dart:async'; | ||
import 'package:withu_app/core/network/api_response.dart'; | ||
import 'package:withu_app/feature/account/data/data_sources/dto/dto.dart'; | ||
import 'api.dart'; | ||
|
||
class AccountApiImpl extends AccountApi {} | ||
class AccountApiImpl extends AccountApi { | ||
/// 로그인 API | ||
@override | ||
FutureOr<ApiResponse<LoginResponseDto>> login({ | ||
required LoginRequestDto requestData, | ||
}) async { | ||
return dio | ||
.post( | ||
loginPath, | ||
data: requestData.toJson(), | ||
) | ||
.then((response) => ApiResponse.success( | ||
LoginResponseDto.fromJson(response.data), | ||
)) | ||
.catchError((_) => const ApiResponse<LoginResponseDto>.error()); | ||
} | ||
} |