puntaje pro

This commit is contained in:
Juan Felipe Duarte
2023-04-26 16:55:58 -05:00
parent 0a70d40d2d
commit c1747a45b9
12 changed files with 781 additions and 436 deletions
+6 -6
View File
@@ -13,7 +13,7 @@ class EventoService {
) async {
try {
await FirebaseFirestore.instance.collection('services').add({
'profesional_id': uid,
'user_id': uid,
'title': title,
'description': description,
'day': day,
@@ -34,7 +34,7 @@ Future<List<Event>> getByProId(String day) async {
try {
var snapshot = await FirebaseFirestore.instance
.collection('services')
.where('profesional_id', isEqualTo: uid)
.where('user_id', isEqualTo: uid)
.where('day', isEqualTo: day.toString())
.get();
@@ -56,7 +56,7 @@ class Event {
String? day;
String? range1Hour1;
String? range1Hour2;
String? profesionalId;
String? userId;
Event({
this.title,
@@ -64,7 +64,7 @@ class Event {
this.day,
this.range1Hour1,
this.range1Hour2,
this.profesionalId,
this.userId,
});
factory Event.fromJson(Map<String, dynamic> json) {
@@ -74,7 +74,7 @@ class Event {
day: json['day'],
range1Hour1: json['range1Hour1'],
range1Hour2: json['range1Hour2'],
profesionalId: json['profesional_id'],
userId: json['user_id'],
);
}
@@ -82,7 +82,7 @@ class Event {
try {
var snapshot = await FirebaseFirestore.instance
.collection('services')
.where('profesional_id', isEqualTo: uid)
.where('user_id', isEqualTo: uid)
.get();
List<Event> eventos = [];
+95
View File
@@ -0,0 +1,95 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:prosappco/src/models/user_model.dart';
class ScoresModel {
late int total;
late double average;
final List<ScoreModel2> scores;
ScoresModel(this.scores) {
total = scores.length;
average = averageScore(scores);
}
double averageScore(List<ScoreModel2> scores) {
if (scores.isEmpty) {
return 0.0;
}
final sum = scores.map((score) => score.score).reduce((a, b) => a + b);
return sum / scores.length;
}
// Me
static Future<ScoresModel> scoreTo(String userReceived, bool userInfo) async {
final receivedScoresQuery = FirebaseFirestore.instance
.collection('scores')
.where('to_user', isEqualTo: userReceived);
final receivedScoresSnapshot = await receivedScoresQuery.get();
final receivedScores = await Future.wait(receivedScoresSnapshot.docs
.map((doc) async =>
await ScoreModel2.fromDocumentSnapshot(doc, userInfo))
.toList());
return ScoresModel(receivedScores);
}
// You
static Future<ScoresModel> scoreFrom(String userGiven, bool userInfo) async {
final givenScoresQuery = FirebaseFirestore.instance
.collection('scores')
.where('from_user', isEqualTo: userGiven);
final givenScoresSnapshot = await givenScoresQuery.get();
final givenScores = await Future.wait(givenScoresSnapshot.docs
.map((doc) async =>
await ScoreModel2.fromDocumentSnapshot(doc, userInfo))
.toList());
return ScoresModel(givenScores);
}
}
class ScoreModel2 {
final String id;
final double score;
final String fromUser;
final String toUser;
final String comment;
final String name;
final Reference? avatar;
ScoreModel2({
required this.id,
required this.score,
required this.fromUser,
required this.toUser,
required this.comment,
required this.name,
required this.avatar,
});
static Future<ScoreModel2> fromDocumentSnapshot(
DocumentSnapshot<Map<String, dynamic>> snapshot, bool userInfo) async {
try {
final Map<String, dynamic> data = snapshot.data()!;
final user = userInfo ? await UserModel.getUser(data['from_user']) : null;
return ScoreModel2(
id: snapshot.id,
score: double.parse(data['score'].toString()),
fromUser: data['from_user'],
toUser: data['to_user'],
comment: data['comment'],
name: user?.name ?? "...",
avatar: user?.photo);
} catch (e) {
print('error en score $e');
rethrow;
}
}
}