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

голосование за публикации #50

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions lib/data/model/publication/publication_common_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ class PublicationCommon extends Publication {
? PublicationAuthor.fromMap(map['author'])
: PublicationAuthor.empty,
statistics: map['statistics'] != null
? PublicationStatistics.fromMap(map['statistics'])
? PublicationStatistics.fromJson(map['statistics'])
: PublicationStatistics.empty,
relatedData: map['relatedData'] != null
? PublicationRelatedData.fromMap(map['relatedData'])
? PublicationRelatedData.fromJson(map['relatedData'])
: PublicationRelatedData.empty,
hubs: map['hubs'] != null
? List<PublicationHub>.from(
Expand Down
4 changes: 2 additions & 2 deletions lib/data/model/publication/publication_post_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class PublicationPost extends Publication {
? PublicationAuthor.fromMap(map['author'])
: PublicationAuthor.empty,
statistics: map['statistics'] != null
? PublicationStatistics.fromMap(map['statistics'])
? PublicationStatistics.fromJson(map['statistics'])
: PublicationStatistics.empty,
relatedData: map['relatedData'] != null
? PublicationRelatedData.fromMap(map['relatedData'])
? PublicationRelatedData.fromJson(map['relatedData'])
: PublicationRelatedData.empty,
hubs: map['hubs'] != null
? List<PublicationHub>.from(
Expand Down
62 changes: 27 additions & 35 deletions lib/data/model/publication/publication_statistics_model.dart
Original file line number Diff line number Diff line change
@@ -1,38 +1,30 @@
import 'package:equatable/equatable.dart';

class PublicationStatistics extends Equatable {
const PublicationStatistics({
this.commentsCount = 0,
this.favoritesCount = 0,
this.readingCount = 0,
this.score = 0,
this.votesCount = 0,
});

final int commentsCount;
final int favoritesCount;
final int readingCount;
final int score;
final int votesCount;

factory PublicationStatistics.fromMap(Map<String, dynamic> map) {
return PublicationStatistics(
commentsCount: map['commentsCount'],
favoritesCount: map['favoritesCount'],
readingCount: map['readingCount'],
score: map['score'],
votesCount: map['votesCount'],
);
}
import 'package:freezed_annotation/freezed_annotation.dart';

static const empty = PublicationStatistics();
part 'publication_statistics_model.freezed.dart';
part 'publication_statistics_model.g.dart';

@freezed
class PublicationStatistics with _$PublicationStatistics {
const PublicationStatistics._();

const factory PublicationStatistics({
@Default(0) int commentsCount,
@Default(0) int favoritesCount,
@Default(0) int readingCount,
@Default(0) int score,

/// Количество голосов за публикацию
@Default(0) int votesCount,

@override
List<Object> get props => [
commentsCount,
favoritesCount,
readingCount,
score,
votesCount,
];
/// Количество голосов за публикацию с плюсом
@Default(0) int votesCountPlus,

/// Количество голосов за публикацию с минусом
@Default(0) int votesCountMinus,
}) = _PublicationStatistics;

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

static const empty = PublicationStatistics();
}
16 changes: 16 additions & 0 deletions lib/data/model/publication/publication_vote_response.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:freezed_annotation/freezed_annotation.dart';

part 'publication_vote_response.freezed.dart';
part 'publication_vote_response.g.dart';

@freezed
class PublicationVoteResponse with _$PublicationVoteResponse {
factory PublicationVoteResponse({
@Default(false) bool canVote,
@Default(0) int score,
@Default(0) int votesCount,
}) = _PublicationVoteResponse;

factory PublicationVoteResponse.fromJson(Map<String, dynamic> json) =>
_$PublicationVoteResponseFromJson(json);
}
66 changes: 22 additions & 44 deletions lib/data/model/related_data/publication_related_data_model.dart
Original file line number Diff line number Diff line change
@@ -1,53 +1,31 @@
import 'package:equatable/equatable.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

import 'publication_vote_model.dart';
import 'related_data_base.dart';

class PublicationRelatedData extends RelatedDataBase with EquatableMixin {
const PublicationRelatedData({
this.unreadCommentsCount = 0,
this.bookmarked = false,
this.canComment = false,
this.canEdit = false,
this.canViewVotes = false,
this.canVotePlus = false,
this.canVoteMinus = false,
});
part 'publication_related_data_model.freezed.dart';
part 'publication_related_data_model.g.dart';

final int unreadCommentsCount;
final bool bookmarked;
// "vote": {
// "value": null,
// "voteTimeExpired": "2022-10-09T15:02:47+00:00"
// },
final bool canComment;
final bool canEdit;
final bool canViewVotes;
final bool canVotePlus;
final bool canVoteMinus;
@freezed
class PublicationRelatedData extends RelatedDataBase
with _$PublicationRelatedData {
const PublicationRelatedData._();

factory PublicationRelatedData.fromMap(Map<String, dynamic> map) {
return PublicationRelatedData(
unreadCommentsCount: (map['unreadCommentsCount'] ?? 0) as int,
bookmarked: (map['bookmarked'] ?? false) as bool,
canComment: (map['canComment'] ?? false) as bool,
canEdit: (map['canEdit'] ?? false) as bool,
canViewVotes: (map['canViewVotes'] ?? false) as bool,
canVotePlus: (map['canVotePlus'] ?? false) as bool,
canVoteMinus: (map['canVoteMinus'] ?? false) as bool,
);
}
const factory PublicationRelatedData({
@Default(0) int unreadCommentsCount,
@Default(false) bool bookmarked,
@Default(false) bool canComment,
@Default(false) bool canEdit,
@Default(false) bool canViewVotes,
@Default(false) bool trackerSubscribed,
@Default(false) bool emailSubscribed,
@Default(PublicationVoteModel.empty) PublicationVoteModel votePlus,
@Default(PublicationVoteModel.empty) PublicationVoteModel voteMinus,
}) = _PublicationRelatedData;

factory PublicationRelatedData.fromJson(Map<String, dynamic> map) =>
_$PublicationRelatedDataFromJson(map);

static const empty = PublicationRelatedData();
bool get isEmpty => this == empty;

@override
List<Object> get props => [
unreadCommentsCount,
bookmarked,
canComment,
canEdit,
canViewVotes,
canVotePlus,
canVoteMinus,
];
}
27 changes: 27 additions & 0 deletions lib/data/model/related_data/publication_vote_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'package:freezed_annotation/freezed_annotation.dart';

part 'publication_vote_model.freezed.dart';
part 'publication_vote_model.g.dart';

@freezed
class PublicationVoteModel with _$PublicationVoteModel {
const PublicationVoteModel._();

const factory PublicationVoteModel({
@Default(false) bool canVote,

/// Исчерпан ли лимит выделенных на день голосов
@Default(false) bool isChargeEnough,

/// Достаточно ли очков профиля для голосования
@Default(false) bool isKarmaEnough,

/// Окончено ли голосование для этого публикации
@Default(false) bool isVotingOver,
}) = _PublicationVoteModel;

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

static const empty = PublicationVoteModel();
}
1 change: 1 addition & 0 deletions lib/data/repository/part.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import '../model/publication/publication.dart';
import '../model/publication/publication_counters_model.dart';
import '../model/publication/publication_flow_enum.dart';
import '../model/publication/publication_source_enum.dart';
import '../model/publication/publication_vote_response.dart';
import '../model/search/search_order_enum.dart';
import '../model/search/search_target_enum.dart';
import '../model/section_enum.dart';
Expand Down
12 changes: 10 additions & 2 deletions lib/data/repository/publication_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ class PublicationRepository {
langArticles: LanguageEncoder.encodeLangs(langArticles),
);

final article = PublicationCommon.fromMap(rawData);
final publication = PublicationCommon.fromMap(rawData);

return article;
return publication;
}

Future<PublicationPost> _fetchPostById(
Expand Down Expand Up @@ -238,4 +238,12 @@ class PublicationRepository {

return articles;
}

Future<PublicationVoteResponse> voteUp(String publicationId) async {
return await service.voteUp(publicationId);
}

Future<PublicationVoteResponse> voteDown(String publicationId) async {
return await service.voteDown(publicationId);
}
}
1 change: 1 addition & 0 deletions lib/data/service/part.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import '../model/list_response/user_comment_list_response.dart';
import '../model/list_response/user_list_response.dart';
import '../model/publication/publication_flow_enum.dart';
import '../model/publication/publication_source_enum.dart';
import '../model/publication/publication_vote_response.dart';
import '../model/query_params/comment_list_params.dart';
import '../model/query_params/company_list_params.dart';
import '../model/query_params/feed_list_params.dart';
Expand Down
32 changes: 32 additions & 0 deletions lib/data/service/publication_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ abstract interface class PublicationService {
required String langUI,
required String langArticles,
});

Future<PublicationVoteResponse> voteUp(String articleId);

Future<PublicationVoteResponse> voteDown(String articleId);
}

@LazySingleton(as: PublicationService)
Expand Down Expand Up @@ -429,4 +433,32 @@ class PublicationServiceImpl implements PublicationService {
Error.throwWithStackTrace(FetchException(), trace);
}
}

@override
Future<PublicationVoteResponse> voteUp(String publicationId) async {
try {
final response = await _mobileClient.post(
'/articles/$publicationId/votes/up',
body: {},
);

return PublicationVoteResponse.fromJson(response.data);
} catch (e, trace) {
Error.throwWithStackTrace(FetchException(), trace);
}
}

@override
Future<PublicationVoteResponse> voteDown(String publicationId) async {
try {
final response = await _mobileClient.post(
'/articles/$publicationId/votes/down',
body: {},
);

return PublicationVoteResponse.fromJson(response.data);
} catch (e, trace) {
Error.throwWithStackTrace(FetchException(), trace);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ class FloatingFilterButton<ListCubit extends PublicationListCubit<ListState>,
onPressed: () {
showModalBottomSheet(
context: context,
showDragHandle: true,
isScrollControlled: true,
constraints: const BoxConstraints(
minWidth: 600,
),
constraints: const BoxConstraints(minWidth: 600),
builder: (_) => Padding(
padding: const EdgeInsets.symmetric(horizontal: 12.0, vertical: 6),
child: BlocProvider.value(
Expand Down
Loading
Loading