-
Notifications
You must be signed in to change notification settings - Fork 0
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:[공통] Pagination 마지막 페이지 체크 로직 보완 #85 #88
Conversation
class BreedsPaginationResponse extends PaginationResponse<Breed> { | ||
BreedsPaginationResponse({ | ||
required this.page, | ||
required this.size, | ||
required this.items, | ||
required super.page, | ||
required super.size, | ||
required super.items, | ||
required super.isLastPage, | ||
}); | ||
|
||
BreedsPaginationResponse.fromJson( | ||
Map<String, dynamic> json, | ||
) : page = json['page'] as int, | ||
size = json['size'] as int, | ||
items = (json['items'] as List<dynamic>) | ||
.map((e) => Breed.fromJson(e)) | ||
.toList(); | ||
|
||
@override | ||
final int page; | ||
|
||
@override | ||
final int size; | ||
|
||
@override | ||
final List<Breed> items; | ||
|
||
@override | ||
bool operator ==(Object other) { | ||
if (identical(this, other)) return true; | ||
|
||
return other is BreedsPaginationResponse && | ||
other.page == page && | ||
other.size == size; | ||
} | ||
|
||
@override | ||
int get hashCode => page.hashCode ^ size.hashCode; | ||
|
||
@override | ||
Map<String, dynamic> toJson() { | ||
// TODO: implement toJson | ||
throw UnimplementedError(); | ||
} | ||
) : super.fromJson(json, (e) => Breed.fromJson(e)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
개별 PaginationResponse들이 기본 PaginationResponse들을 기존에 implements
하던 것을 extends
하도록 변경해 불필요하게 반복되는 로직들을 제거했습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PaginationResponse가 다른 클래스들의 순수한 is-a 관계인 것 같아 상속으로 바꿔도 좋을 것 같습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
불필요하게 반복되는 코드를 줄여보자는 관점으로 접근 했었는데 is-a
와 has-a
로 extends
와 implements
를 판단할 수 있군요.
} | ||
bool operator ==(Object other) => | ||
identical(this, other) || | ||
other is PaginationResponse && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
요 비교 로직에서 other is PaginationResponse<T>
로 비교하지 않아도 괜찮을까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
별 생각없이 IDE 자동 완성 기능으로 작성한 부분이었는데 Generic 타입이 달라도 같은 값이라고 판단하고 있었네요.
class BreedsPaginationResponse extends PaginationResponse<Breed> { | ||
BreedsPaginationResponse({ | ||
required this.page, | ||
required this.size, | ||
required this.items, | ||
required super.page, | ||
required super.size, | ||
required super.items, | ||
required super.isLastPage, | ||
}); | ||
|
||
BreedsPaginationResponse.fromJson( | ||
Map<String, dynamic> json, | ||
) : page = json['page'] as int, | ||
size = json['size'] as int, | ||
items = (json['items'] as List<dynamic>) | ||
.map((e) => Breed.fromJson(e)) | ||
.toList(); | ||
|
||
@override | ||
final int page; | ||
|
||
@override | ||
final int size; | ||
|
||
@override | ||
final List<Breed> items; | ||
|
||
@override | ||
bool operator ==(Object other) { | ||
if (identical(this, other)) return true; | ||
|
||
return other is BreedsPaginationResponse && | ||
other.page == page && | ||
other.size == size; | ||
} | ||
|
||
@override | ||
int get hashCode => page.hashCode ^ size.hashCode; | ||
|
||
@override | ||
Map<String, dynamic> toJson() { | ||
// TODO: implement toJson | ||
throw UnimplementedError(); | ||
} | ||
) : super.fromJson(json, (e) => Breed.fromJson(e)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PaginationResponse가 다른 클래스들의 순수한 is-a 관계인 것 같아 상속으로 바꿔도 좋을 것 같습니다!
- is_last_page 적용 - 개별 PaginationResponse가 기본 PaginationResponse를 implements -> extends 하도록 변경
6dfa845
to
49665d4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
좋은 코드로 고쳐주셔서 감사합니다! 페이지네이션을 구현해주신 덕에 저도 돌봄급구 리스트를 금방 구현할 수 있었네요. 감사합니다! 👍
Description
is_last_page
을 적용했습니다.extends
하도록 변경했습니다.Type of Change