Files
Vocasia-LMS-Mobile-apps--TA…/lib/models/qna_model.dart

131 lines
3.1 KiB
Dart

import 'package:initial_folder/models/comment_qna_model.dart';
class QnaModel {
QnaModel({
this.status,
this.error,
required this.data,
});
final int? status;
final bool? error;
final List<List<QnaDataModel>> data;
factory QnaModel.fromJson(Map<String, dynamic> json) => QnaModel(
status: json["status"],
error: json["error"],
data: List<List<QnaDataModel>>.from(json["data"].map((x) =>
List<QnaDataModel>.from(x.map((x) => QnaDataModel.fromJson(x))))),
);
Map<String, dynamic> toJson() => {
"status": status,
"error": error,
"data": List<dynamic>.from(
data.map((x) => List<dynamic>.from(x.map((x) => x.toJson())))),
};
}
class QnaDataModel {
QnaDataModel({
this.idQna,
this.idLesson,
this.sender,
this.username,
this.title,
this.quest,
this.fotoProfile,
this.countComment,
this.countLike,
this.selfLiked,
this.date,
required this.comment,
});
final String? idQna;
final String? idLesson;
final String? sender;
final String? username;
final String? title;
final String? quest;
final String? fotoProfile;
int? countComment;
String? countLike;
bool? selfLiked;
final String? date;
List<Comment> comment;
factory QnaDataModel.fromJson(Map<String, dynamic> json) => QnaDataModel(
idQna: json["id_qna"],
idLesson: json["id_lesson"],
sender: json["sender"],
username: json["username"],
title: json["title"],
quest: json["quest"],
fotoProfile: json["foto_profile"],
countComment: json["count_comment"],
countLike: json["count_up"],
selfLiked: json['status_up'],
date: json["date"],
comment:
List<Comment>.from(json["comment"].map((x) => Comment.fromJson(x)))
.toList(),
);
Map<String, dynamic> toJson() => {
"id_qna": idQna,
"id_lesson": idLesson,
"sender": sender,
"username": username,
"quest": quest,
"foto_profile": fotoProfile,
"date": date,
"comment": List<dynamic>.from(comment.map((x) => x)),
};
}
/// Class untuk response tambah
class QnaPostModel {
QnaPostModel({
this.status,
this.error,
required this.data,
});
final int? status;
final bool? error;
final DataPostQna data;
factory QnaPostModel.fromJson(Map<String, dynamic> json) => QnaPostModel(
status: json["status"],
error: json["error"],
data: DataPostQna.fromJson(json["data"]),
);
Map<String, dynamic> toJson() => {
"status": status,
"error": error,
"data": data.toJson(),
};
}
class DataPostQna {
DataPostQna({this.sender, this.quest, this.idCourse});
final String? sender;
final String? quest;
final String? idCourse;
factory DataPostQna.fromJson(Map<String, dynamic> json) => DataPostQna(
sender: json["sender"],
quest: json["quest"],
idCourse: json["id_course"],
);
Map<String, dynamic> toJson() => {
"messages": sender,
"quest": quest,
"id_course": idCourse,
};
}