replace: swap prosappweb content for prosapp_web_app (more complete version)
prosapp_web_app has chat, dashboard, calendar, support, 13 providers and Fluro URL routing. Keep Dockerfile + nginx.conf from previous prosappweb. Upgrade google_fonts 6.2.1 → 8.1.0 (Dart 3.12 compat fix). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
74a4f41902
commit
15175c1b91
@@ -0,0 +1,43 @@
|
||||
import 'dart:developer';
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:prosapp_web_app/models/chat_entity.dart';
|
||||
import 'package:prosapp_web_app/models/message_entity.dart';
|
||||
|
||||
class FirebaseChatRepository {
|
||||
final chatCollection = FirebaseFirestore.instance.collection('chats');
|
||||
|
||||
Stream<ChatEntity?> getChatById(String chatId) {
|
||||
return chatCollection.doc(chatId).snapshots().map((snapshot) {
|
||||
try {
|
||||
if (snapshot.exists) {
|
||||
return ChatEntity.fromDocument(snapshot.data()!);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (e) {
|
||||
log(e.toString());
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future<ChatEntity> createNewChat(
|
||||
String chatId, String userId, String professionalId) async {
|
||||
ChatEntity chat = ChatEntity(
|
||||
id: chatId,
|
||||
userId: userId,
|
||||
professionalId: professionalId,
|
||||
messages: const [],
|
||||
);
|
||||
|
||||
await chatCollection.doc(chatId).set(chat.toDocument());
|
||||
|
||||
return chat;
|
||||
}
|
||||
|
||||
sendMessage(String chatId, MessageEntity message) {
|
||||
chatCollection.doc(chatId).update({
|
||||
'messages': FieldValue.arrayUnion([message.toDocument()])
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:prosapp_web_app/models/comment_entity.dart';
|
||||
import 'package:prosapp_web_app/models/score_entity.dart';
|
||||
|
||||
class FirebaseScoreRepository {
|
||||
final reputationsCollection =
|
||||
FirebaseFirestore.instance.collection('reputations');
|
||||
|
||||
final commentsCollection = FirebaseFirestore.instance.collection('comments');
|
||||
|
||||
Future<ReputationEntity> getReputationByUserId(String userId) async {
|
||||
try {
|
||||
final snap = await reputationsCollection.doc(userId).get();
|
||||
return ReputationEntity.fromDocument(snap.data()!);
|
||||
} catch (e) {
|
||||
return const ReputationEntity(
|
||||
total: 0,
|
||||
average: 0,
|
||||
totalPro: 0,
|
||||
averagePro: 0,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Stream<ReputationEntity> streamReputation() {
|
||||
return FirebaseAuth.instance.userChanges().asyncMap((user) async {
|
||||
if (user != null) {
|
||||
return await getReputationByUserId(user.uid);
|
||||
} else {
|
||||
return const ReputationEntity(
|
||||
total: 0,
|
||||
average: 0,
|
||||
totalPro: 0,
|
||||
averagePro: 0,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Stream<List<CommentEntity>> getScoresForUser(String userId) {
|
||||
return commentsCollection
|
||||
.where('destination_id', isEqualTo: userId)
|
||||
.where('is_from_user', isEqualTo: false)
|
||||
.snapshots()
|
||||
.map((querySnapshot) => querySnapshot.docs
|
||||
.map((doc) => CommentEntity.fromDocument(doc.data()))
|
||||
.toList());
|
||||
}
|
||||
|
||||
Stream<List<CommentEntity>> getScoresForProfessional(String userId) {
|
||||
return commentsCollection
|
||||
.where('destination_id', isEqualTo: userId)
|
||||
.where('is_from_user', isEqualTo: true)
|
||||
.snapshots()
|
||||
.map((querySnapshot) => querySnapshot.docs
|
||||
.map((doc) => CommentEntity.fromDocument(doc.data()))
|
||||
.toList());
|
||||
}
|
||||
|
||||
Future<void> addComment(CommentEntity comment) async {
|
||||
await commentsCollection.add(comment.toDocument());
|
||||
|
||||
final query = await commentsCollection
|
||||
.where('destination_id', isEqualTo: comment.destinationId)
|
||||
.where('is_from_user', isEqualTo: comment.isFromUser)
|
||||
.get();
|
||||
|
||||
var total = 0.0;
|
||||
var count = 0;
|
||||
for (var doc in query.docs) {
|
||||
final comment = CommentEntity.fromDocument(doc.data());
|
||||
total += comment.score;
|
||||
count++;
|
||||
}
|
||||
|
||||
if (count > 0) {
|
||||
final average = total / count;
|
||||
if (comment.isFromUser) {
|
||||
await reputationsCollection.doc(comment.destinationId).set(
|
||||
{'total_pro': count, 'average_pro': average},
|
||||
SetOptions(merge: true));
|
||||
} else {
|
||||
await reputationsCollection.doc(comment.destinationId).set({
|
||||
'total': count,
|
||||
'average': average,
|
||||
}, SetOptions(merge: true));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user