added functionality to show own votes in polls
This commit is contained in:
22
lib/api/marianumcloud/talk/getPoll/getPollState.dart
Normal file
22
lib/api/marianumcloud/talk/getPoll/getPollState.dart
Normal file
@@ -0,0 +1,22 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import '../talkApi.dart';
|
||||
import 'getPollStateResponse.dart';
|
||||
|
||||
class GetPollState extends TalkApi<GetPollStateResponse> {
|
||||
String token;
|
||||
int pollId;
|
||||
GetPollState({required this.token, required this.pollId}) : super('v1/poll/$token/$pollId', null);
|
||||
|
||||
@override
|
||||
GetPollStateResponse assemble(String raw) {
|
||||
log(raw);
|
||||
return GetPollStateResponse.fromJson(jsonDecode(raw)['ocs']);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<http.Response> request(Uri uri, Object? body, Map<String, String>? headers) => http.get(uri, headers: headers);
|
||||
}
|
50
lib/api/marianumcloud/talk/getPoll/getPollStateResponse.dart
Normal file
50
lib/api/marianumcloud/talk/getPoll/getPollStateResponse.dart
Normal file
@@ -0,0 +1,50 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import '../../../apiResponse.dart';
|
||||
|
||||
part 'getPollStateResponse.g.dart';
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class GetPollStateResponse extends ApiResponse {
|
||||
GetPollStateResponseObject data;
|
||||
|
||||
GetPollStateResponse(this.data);
|
||||
|
||||
factory GetPollStateResponse.fromJson(Map<String, dynamic> json) => _$GetPollStateResponseFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetPollStateResponseToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class GetPollStateResponseObject {
|
||||
int id;
|
||||
String question;
|
||||
List<String> options;
|
||||
dynamic votes;
|
||||
String actorType;
|
||||
String actorId;
|
||||
String actorDisplayName;
|
||||
int status;
|
||||
int resultMode;
|
||||
int maxVotes;
|
||||
List<int> votedSelf;
|
||||
int? numVoters;
|
||||
List<String>? details;
|
||||
|
||||
GetPollStateResponseObject(
|
||||
this.id,
|
||||
this.question,
|
||||
this.options,
|
||||
this.votes,
|
||||
this.actorType,
|
||||
this.actorId,
|
||||
this.actorDisplayName,
|
||||
this.status,
|
||||
this.resultMode,
|
||||
this.maxVotes,
|
||||
this.votedSelf,
|
||||
this.numVoters,
|
||||
this.details);
|
||||
|
||||
factory GetPollStateResponseObject.fromJson(Map<String, dynamic> json) => _$GetPollStateResponseObjectFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetPollStateResponseObjectToJson(this);
|
||||
}
|
@@ -0,0 +1,60 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'getPollStateResponse.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
GetPollStateResponse _$GetPollStateResponseFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
GetPollStateResponse(
|
||||
GetPollStateResponseObject.fromJson(json['data'] as Map<String, dynamic>),
|
||||
)..headers = (json['headers'] as Map<String, dynamic>?)?.map(
|
||||
(k, e) => MapEntry(k, e as String),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$GetPollStateResponseToJson(
|
||||
GetPollStateResponse instance) =>
|
||||
<String, dynamic>{
|
||||
if (instance.headers case final value?) 'headers': value,
|
||||
'data': instance.data.toJson(),
|
||||
};
|
||||
|
||||
GetPollStateResponseObject _$GetPollStateResponseObjectFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
GetPollStateResponseObject(
|
||||
(json['id'] as num).toInt(),
|
||||
json['question'] as String,
|
||||
(json['options'] as List<dynamic>).map((e) => e as String).toList(),
|
||||
json['votes'],
|
||||
json['actorType'] as String,
|
||||
json['actorId'] as String,
|
||||
json['actorDisplayName'] as String,
|
||||
(json['status'] as num).toInt(),
|
||||
(json['resultMode'] as num).toInt(),
|
||||
(json['maxVotes'] as num).toInt(),
|
||||
(json['votedSelf'] as List<dynamic>)
|
||||
.map((e) => (e as num).toInt())
|
||||
.toList(),
|
||||
(json['numVoters'] as num?)?.toInt(),
|
||||
(json['details'] as List<dynamic>?)?.map((e) => e as String).toList(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$GetPollStateResponseObjectToJson(
|
||||
GetPollStateResponseObject instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'question': instance.question,
|
||||
'options': instance.options,
|
||||
'votes': instance.votes,
|
||||
'actorType': instance.actorType,
|
||||
'actorId': instance.actorId,
|
||||
'actorDisplayName': instance.actorDisplayName,
|
||||
'status': instance.status,
|
||||
'resultMode': instance.resultMode,
|
||||
'maxVotes': instance.maxVotes,
|
||||
'votedSelf': instance.votedSelf,
|
||||
'numVoters': instance.numVoters,
|
||||
'details': instance.details,
|
||||
};
|
Reference in New Issue
Block a user