Skip to content

Commit

Permalink
Merge branch 'refs/heads/main' into prod/festapp
Browse files Browse the repository at this point in the history
  • Loading branch information
miakh committed Aug 26, 2024
2 parents fbe11a5 + a97a012 commit cd97b92
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 34 deletions.
5 changes: 3 additions & 2 deletions lib/dataServices/DbEvents.dart
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ class DbEvents {
.select(
"${Tb.events.id},"
"${Tb.events.updated_at}")
.eq(Tb.events.is_hidden, false)
.eq(Tb.events.occasion, RightsService.currentOccasion!);

return List<EventModel>.from(
Expand Down Expand Up @@ -574,7 +575,7 @@ class DbEvents {
}
else
{
upsertObj.addAll({Tb.events.occasion: RightsService.currentOccasion});
upsertObj.addAll({Tb.events.occasion: RightsService.currentOccasion!});
eventData = await _supabase.from(Tb.events.table).insert(upsertObj).select().single();
}
return EventModel.fromJson(eventData);
Expand Down Expand Up @@ -654,7 +655,7 @@ class DbEvents {
}
else
{
upsertObj.addAll({Tb.exclusive_groups.occasion: RightsService.currentOccasion});
upsertObj.addAll({Tb.exclusive_groups.occasion: RightsService.currentOccasion!});
eventData = await _supabase.from(Tb.exclusive_groups.table).insert(upsertObj).select().single();
}
var updated = ExclusiveGroupModel.fromJson(eventData);
Expand Down
37 changes: 15 additions & 22 deletions lib/dataServices/DbInformation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,17 @@ import 'package:supabase_flutter/supabase_flutter.dart';
class DbInformation {
static final _supabase = Supabase.instance.client;

static Future<List<InformationModel>> getAllInformation() async {
var data = await _supabase.from(Tb.information.table).select();
var infoList = List<InformationModel>.from(
data.map((x) => InformationModel.fromJson(x)));
infoList.sortBy((element) => element.title??"".toLowerCase());
infoList.sort((a,b) => (a.getOrder().compareTo(b.getOrder())));
return infoList;
}

static Future<List<InformationModel>> getAllInformationForDataGrid() async {
var data = await _supabase.from(Tb.information.table).select(
"${Tb.information.id},"
"${Tb.information.occasion},"
"${Tb.information.created_at},"
"${Tb.information.updated_at},"
"${Tb.information.is_hidden},"
"${Tb.information.title},"
"${Tb.information.order},"
"${Tb.information.type}"
);
"${Tb.information.occasion},"
"${Tb.information.created_at},"
"${Tb.information.updated_at},"
"${Tb.information.is_hidden},"
"${Tb.information.title},"
"${Tb.information.order},"
"${Tb.information.type}")
.eq(Tb.information.occasion, RightsService.currentOccasion!);
var infoList = List<InformationModel>.from(
data.map((x) => InformationModel.fromJson(x)));
infoList.sortBy((element) => element.title??"".toLowerCase());
Expand All @@ -52,7 +43,8 @@ class DbInformation {
"${Tb.information.title},"
"${Tb.information.id}"
)
.eq(Tb.information.is_hidden, false);
.eq(Tb.information.is_hidden, false)
.eq(Tb.information.occasion, RightsService.currentOccasion!);

var infoList = List<InformationModel>.from(
data.map((x) => InformationModel.fromJson(x)));
Expand All @@ -74,9 +66,10 @@ class DbInformation {
var data = await _supabase
.from(Tb.information.table)
.select(
"${Tb.information.id},"
"${Tb.information.updated_at}"
);
"${Tb.information.id},"
"${Tb.information.updated_at}")
.eq(Tb.information.is_hidden, false)
.eq(Tb.information.occasion, RightsService.currentOccasion!);

return List<InformationModel>.from(
data.map((x) => InformationModel.fromJson(x)));
Expand All @@ -98,6 +91,7 @@ class DbInformation {
}
else
{
upsertObj.addAll({Tb.information.occasion: RightsService.currentOccasion!});
await _supabase.from(Tb.information.table).insert(upsertObj);
}
}
Expand Down Expand Up @@ -138,5 +132,4 @@ class DbInformation {
}
}
}

}
23 changes: 20 additions & 3 deletions lib/dataServices/DbNews.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:easy_localization/easy_localization.dart';
import 'package:fstapp/dataModels/NewsModel.dart';
import 'package:fstapp/dataModels/Tb.dart';
import 'package:fstapp/dataServices/AuthService.dart';
import 'package:fstapp/dataServices/RightsService.dart';
import 'package:fstapp/services/ToastHelper.dart';
import 'package:supabase_flutter/supabase_flutter.dart';
import 'package:html/parser.dart';
Expand All @@ -16,6 +17,7 @@ class DbNews {
// from some reason lower than is behaving like lower and equal than on web platform
// therefore additional check
.neq(Tb.news.id, message.id)
.eq(Tb.news.occasion, RightsService.currentOccasion!)
.order(Tb.news.created_at)
.limit(1)
.maybeSingle();
Expand Down Expand Up @@ -66,6 +68,7 @@ class DbNews {
var messageForNews = heading != null ? "<strong>$heading</strong><br>$message" : message;
await _supabase.from(Tb.news.table).insert(
{
Tb.news.occasion: RightsService.currentOccasion!,
Tb.news.message: messageForNews,
Tb.news.created_by: AuthService.currentUserId()
}
Expand All @@ -86,6 +89,7 @@ class DbNews {
await _supabase.from(Tb.log_notifications.table)
.insert(
{
Tb.log_notifications.occasion: RightsService.currentOccasion!,
Tb.log_notifications.to: to,
Tb.log_notifications.content: basicMessage,
Tb.log_notifications.heading: heading ?? headingDefault
Expand All @@ -107,6 +111,7 @@ class DbNews {
var result = await _supabase
.from(Tb.news.table)
.select()
.eq(Tb.news.occasion, RightsService.currentOccasion!)
.gt(Tb.news.id, lastMessageId)
.count();
return result.count;
Expand All @@ -117,8 +122,11 @@ class DbNews {
int lastMessageId = 0;
var lastMessage = await _supabase
.from(Tb.user_news.table)
.select(Tb.user_news.news_id)
.select(
"${Tb.user_news.news_id},"
"${Tb.news.table}!inner(id)")
.eq(Tb.user_news.user, AuthService.currentUserId())
.eq("${Tb.news.table}.${Tb.news.occasion}", RightsService.currentOccasion!)
.maybeSingle();
if (lastMessage != null) {
lastMessageId = lastMessage[Tb.user_news.news_id];
Expand All @@ -130,7 +138,15 @@ class DbNews {
AuthService.ensureUserIsLoggedIn();
await _supabase
.from(Tb.user_news.table)
.upsert({Tb.user_news.user: AuthService.currentUserId(), Tb.user_news.news_id: newsId}).select();
.delete()
.eq(Tb.user_news.user, AuthService.currentUserId())
.eq("${Tb.news.table}.${Tb.news.occasion}", RightsService.currentOccasion!);

await _supabase
.from(Tb.user_news.table)
.insert(
{Tb.user_news.user: AuthService.currentUserId(), Tb.user_news.news_id: newsId}
).select();
}

static Future<List<NewsModel>> getAllNewsMessages() async {
Expand All @@ -141,11 +157,12 @@ class DbNews {
var data = await _supabase
.from(Tb.news.table)
.select(
"${Tb.news.id},"
"${Tb.news.id},"
"${Tb.news.created_at},"
"${Tb.news.message},"
"${Tb.user_info_public.table}(${Tb.user_info_public.name},${Tb.user_info_public.surname}),"
"${Tb.user_news_views.table}(count)")
.eq(Tb.news.occasion, RightsService.currentOccasion!)
.order(Tb.news.created_at);

List<NewsModel> loadedMessages = List<NewsModel>.from(data.map((x) => NewsModel.fromJson(x)));
Expand Down
26 changes: 19 additions & 7 deletions lib/dataServices/DbPlaces.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,21 @@ import 'package:supabase_flutter/supabase_flutter.dart';
class DbPlaces {
static final _supabase = Supabase.instance.client;
static Future<List<PlaceModel>> getMapPlaces() async {
var data = await _supabase.from(Tb.places.table).select().eq(Tb.places.is_hidden, false);
var data = await _supabase
.from(Tb.places.table)
.select()
.eq(Tb.places.is_hidden, false)
.eq(Tb.places.occasion, RightsService.currentOccasion!);
var toReturn = List<PlaceModel>.from(data.map((x) => PlaceModel.fromJson(x)));
toReturn.sortPlaces(false);
return toReturn;
}

static Future<List<PlaceModel>> getAllPlaces() async {
var data = await _supabase.from(Tb.places.table).select();
var data = await _supabase
.from(Tb.places.table)
.select()
.eq(Tb.places.occasion, RightsService.currentOccasion!);
var toReturn = List<PlaceModel>.from(data.map((x) => PlaceModel.fromJson(x)));
toReturn.sortPlaces();
return toReturn;
Expand All @@ -40,7 +47,11 @@ class DbPlaces {
}

static Future<PlaceModel> getPlace(int id) async {
var data = await _supabase.from(Tb.places.table).select().eq(Tb.places.id, id).single();
var data = await _supabase
.from(Tb.places.table)
.select()
.eq(Tb.places.id, id)
.single();
return PlaceModel.fromJson(data);
}

Expand All @@ -50,15 +61,16 @@ class DbPlaces {

static Future<PlaceModel> updatePlace(PlaceModel placeModel) async
{
var json = placeModel.toJson();
var upsertObj = placeModel.toJson();
Map<String, dynamic> data;
if(placeModel.id!=null) {
data = await _supabase.from(Tb.places.table).update(json).eq(Tb.places.id, placeModel.id!).select().single();
data = await _supabase.from(Tb.places.table).update(upsertObj).eq(Tb.places.id, placeModel.id!).select().single();
}
else
{
json.remove(Tb.places.id);
data = await _supabase.from(Tb.places.table).insert(json).select().single();
upsertObj.remove(Tb.places.id);
upsertObj.addAll({Tb.places.occasion: RightsService.currentOccasion!});
data = await _supabase.from(Tb.places.table).insert(upsertObj).select().single();
}
return PlaceModel.fromJson(data);
}
Expand Down

0 comments on commit cd97b92

Please sign in to comment.