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

πŸ› μƒν’ˆ API μ μš©μ— λ”°λ₯Έ 둜직 μˆ˜μ • #12

Merged
merged 1 commit into from
Feb 28, 2024

Conversation

changhwan77
Copy link
Collaborator

@changhwan77 changhwan77 commented Feb 22, 2024

Title

πŸ› μƒν’ˆ API μ μš©μ— λ”°λ₯Έ 둜직 μˆ˜μ •

What type of PR is this?

  • πŸ• Feature ( μƒˆλ‘œμš΄ κΈ°λŠ₯ μΆ”κ°€ )
  • πŸ› Bug Fix ( 버그 μˆ˜μ • )
  • πŸ“ Documentation Update ( 개발자 κ΄€λ ¨ λ¬Έμ„œ μ—…λ°μ΄νŠΈ )
  • 🎨 Style ( μ½”λ“œ ν¬λ§·νŒ…, μ„Έλ―Έμ½œλ‘  λˆ„λ½, μ½”λ“œ 변경이 μ—†λŠ” 경우 )
  • πŸ§‘β€πŸ’» Code Refactor ( μ½”λ“œ λ¦¬νŽ™ν† λ§ )
  • πŸ”₯ Performance Improvements ( μ„±λŠ₯ ν–₯상 )
  • βœ… Test ( ν…ŒμŠ€νŠΈ μ½”λ“œ, λ¦¬νŽ™ν† λ§ ν…ŒμŠ€νŠΈ μ½”λ“œ μΆ”κ°€ )
  • πŸ€– Build ( λΉŒλ“œ )
  • πŸ” CI
  • πŸ“¦ Chore (Release) (λΉŒλ“œ 업무 μˆ˜μ •, νŒ¨ν‚€μ§€ λ§€λ‹ˆμ € μˆ˜μ • )
  • ⏩ Revert ( 컀밋을 λ‚ λ¦° 경우 )

Description

  1. 토큰 ν”„λ‘œλ°”μ΄λ” 둜직 μˆ˜μ •
  • As-is: enum 으둜 토큰이 있음, μ—†μŒ μƒμˆ˜κ°’(μƒνƒœ)둜 토큰 μƒνƒœλ₯Ό κ΄€λ¦¬ν–ˆμŒ.
  • To-Be: μ‹€μ œ 토큰 값을 κΈ°μ€€μœΌλ‘œ μƒνƒœλ₯Ό κ΄€λ¦¬ν•˜λ„λ‘ μˆ˜μ •
  1. μƒν’ˆ API 연동해 λ™μ μœΌλ‘œ μΉ΄λ“œ μƒμ„±ν•˜λ„λ‘ 둜직 μˆ˜μ •
  • As-is: 더미 μƒν’ˆ 객체λ₯Ό 생성해 κ΅¬ν˜„λ˜μ–΄ 있던 μƒνƒœ
  • To-Be: μƒν’ˆ APIλ₯Ό 연동해 μ‹€μ œ μƒν’ˆ 객체λ₯Ό λ™μ μœΌλ‘œ μƒμ„±ν•˜λ„λ‘ 둜직 μˆ˜μ •

Related Issue number and link

  • Jira :
  • Issue :

Mobile & Desktop Screenshots/Recordings

product-.api-.mp4

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Any dependent changes have been merged and published in downstream modules

To Reviewers

final response = await dio.get('${StringConstants.baseUrl}/products');

if (response.statusCode == 200) {
final List<dynamic> goods = response.data['data'];
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μƒν’ˆ api의 data keyμ—λŠ” value의 νƒ€μž…μ΄ Listμ΄λ―€λ‘œ List 으둜 νƒ€μž… μ„€μ •ν•˜μ—¬ λ³€μˆ˜μ— ν• λ‹Ή.

if (response.statusCode == 200) {
final List<dynamic> goods = response.data['data'];
final goodsList = goods.map((e) => Goods.fromJson(e)).toList();
return goodsList;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

list μ•ˆμ— λ“  μƒν’ˆλ“€μ„ Goods 객체둜 λ§€ν•‘ν•˜μ—¬ List의 μš”μ†Œλ‘œ μΆ”κ°€

absent,
}

final tokenProvider = StateProvider((ref) => TokenState.absent);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TokenStateλ₯Ό μƒμˆ˜λ‘œ 쑴재, μ‘΄μž¬ν•˜μ§€ μ•ŠμŒμœΌλ‘œ κ΄€λ¦¬ν•˜λ €κ³  ν–ˆμœΌλ‚˜ μ‹€μ œ 토큰을 μ €μž₯ν•˜λŠ” 것이 μ•„λ‹ˆλΌ μƒνƒœ 반영 νŠΈλž˜ν‚Ήμ΄ μ΄μ€‘μœΌλ‘œ λ°œμƒν•΄ μ‹€μ œ 토큰을 μ €μž₯ν•΄ isEmpty λ˜λŠ” 토큰 κ°’μœΌλ‘œ μƒνƒœλ₯Ό κ΄€λ¦¬ν•˜λŠ” κ²ƒμœΌλ‘œ λ³€κ²½

final token = await CustomTokenManager.getToken();
print('둜그인 μ‹œ μ €μž₯λ˜λŠ” 토큰: $token');

ref.read(tokenProvider.notifier).state = token;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

νšŒμ›κ°€μž… μ™„λ£Œμ‹œ login λ©”μ„œλ“œμ— μ„œλ²„μ—μ„œ λ°›μ•„μ˜¨ 토큰을 local storage에 μ €μž₯ν•˜κΈ° λ•Œλ¬Έμ— getToken λ©”μ„œλ“œλ₯Ό 톡해 뢈러온 λ‹€μŒ

tokenProvider의 μƒνƒœμ— μ €μž₯.

ref.read(tokenProvider.notifier).state = TokenState.present;
final token = await CustomTokenManager.getToken();

ref.read(tokenProvider.notifier).state = token;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μœ„ νšŒμ›κ°€μž…μ— μ μš©ν•œ 둜직과 동일.

regularPrice: json['price'],
discountRate: json['discountValue'],
discountedPrice: json['discountedPrice'],
discountPolicy: json['discountPolicy']);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μƒν’ˆ API의 κ°œλ³„ μƒν’ˆ 객체의 ꡬ쑰와 맞게 μˆ˜μ •.

Widget build(BuildContext context) {
Widget build(BuildContext context, WidgetRef ref) {
final AsyncValue<List<Goods>> goodsList = ref.watch(goodsProvider);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

goodsProviderλŠ” FutureProvider둜 비동기 κ°’(AsyncValue)을 μ²˜λ¦¬ν•˜λ―€λ‘œ μœ„μ™€ 같이 λ³€μˆ˜ 생성.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

λ˜ν•œ 이λ₯Ό watchν•΄ goodsProvider의 μƒνƒœκ°€ 변경될 λ•Œλ§ˆλ‹€(μƒν’ˆ λ³€κ²½) ν•΄λ‹Ή νŽ˜μ΄μ§€ rebuild.

children: [
RSizedBox(height: 35.w),
RSizedBox(height: 35.w),
],
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ„œλ²„μ—μ„œ λ°˜μ˜ν•œ λ‘œμ§μ— 따라 즉, μ •λ₯ μ˜ 값에 따라 λ°˜μ˜ν•˜λŠ” 둜직 κ΅¬ν˜„

} else if (name.length == 2) {
String firstName = name.substring(0, 1);
String maskName = firstName + "*";
return maskName;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μœ μ €μ˜ 이름이 두 κΈ€μž μΌλ•Œμ˜ κ²½μš°μ— λŒ€ν•œ μ²˜λ¦¬λ„ 적용.

return const SizedBox();
}
if (snapshot.connectionState == ConnectionState.done) {
if (snapshot.hasData) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

future의 μƒνƒœ(connectionState)κ°€ waiting일 λ•Œμ™€ done일 λ•Œλ₯Ό λ°˜μ˜ν•˜κΈ° μœ„ν•΄ μˆ˜μ •.

@changhwan77 changhwan77 merged commit 12fe2f1 into master Feb 28, 2024
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant