2026-01-31 15:23:18 +05:30
|
|
|
// lib/features/events/services/events_service.dart
|
|
|
|
|
import '../../../core/api/api_client.dart';
|
|
|
|
|
import '../../../core/api/api_endpoints.dart';
|
|
|
|
|
import '../models/event_models.dart';
|
|
|
|
|
|
|
|
|
|
class EventsService {
|
|
|
|
|
final ApiClient _api = ApiClient();
|
|
|
|
|
|
2026-03-30 10:05:23 +05:30
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
// In-memory caches with TTL
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
static List<EventTypeModel>? _cachedTypes;
|
|
|
|
|
static DateTime? _typesCacheTime;
|
|
|
|
|
static const _typesCacheTTL = Duration(minutes: 30);
|
|
|
|
|
|
|
|
|
|
static List<EventModel>? _cachedAllEvents;
|
|
|
|
|
static DateTime? _eventsCacheTime;
|
|
|
|
|
static const _eventsCacheTTL = Duration(minutes: 5);
|
|
|
|
|
|
2026-01-31 15:23:18 +05:30
|
|
|
/// Get event types (POST to /events/type-list/)
|
2026-03-30 10:05:23 +05:30
|
|
|
/// Cached for 30 minutes since event types rarely change.
|
2026-01-31 15:23:18 +05:30
|
|
|
Future<List<EventTypeModel>> getEventTypes() async {
|
2026-03-30 10:05:23 +05:30
|
|
|
if (_cachedTypes != null &&
|
|
|
|
|
_typesCacheTime != null &&
|
|
|
|
|
DateTime.now().difference(_typesCacheTime!) < _typesCacheTTL) {
|
|
|
|
|
return _cachedTypes!;
|
|
|
|
|
}
|
|
|
|
|
|
feat: rebuild desktop UI to match Figma + website, hero slider improvements
- Desktop sidebar (262px, blue gradient, white pill nav), topbar (search + bell + avatar), responsive shell rewritten
- Desktop homepage: immersive hero with Ken Burns animation, pill category chips, date badge cards matching mvnew.eventifyplus.com/home
- Desktop calendar: 60/40 two-column layout with white background
- Desktop profile: full-width banner + 3-column event grids
- Desktop learn more: hero image + about/venue columns + gallery strip
- Desktop settings/contribute: polished to match design system
- Mobile hero slider: RepaintBoundary, animated dots with 44px tap targets, 5s auto-scroll, 8s post-swipe delay, shimmer loading, dynamic event type badge, human-readable dates
- Guest access: requiresAuth false on read endpoints
- Location fix: show place names instead of lat/lng coordinates
- Version 1.6.1+17
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-21 13:28:19 +05:30
|
|
|
final res = await _api.post(ApiEndpoints.eventTypes, requiresAuth: false);
|
2026-01-31 15:23:18 +05:30
|
|
|
final list = <EventTypeModel>[];
|
2026-03-30 10:05:23 +05:30
|
|
|
final data = res['event_types'] ?? res;
|
2026-01-31 15:23:18 +05:30
|
|
|
if (data is List) {
|
|
|
|
|
for (final e in data) {
|
|
|
|
|
if (e is Map<String, dynamic>) list.add(EventTypeModel.fromJson(e));
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-03-30 10:05:23 +05:30
|
|
|
|
|
|
|
|
_cachedTypes = list;
|
|
|
|
|
_typesCacheTime = DateTime.now();
|
2026-01-31 15:23:18 +05:30
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-30 10:05:23 +05:30
|
|
|
/// Get events filtered by pincode with pagination.
|
|
|
|
|
/// [page] starts at 1. [pageSize] defaults to 50.
|
|
|
|
|
/// Returns a list of events for the requested page.
|
|
|
|
|
Future<List<EventModel>> getEventsByPincode(String pincode, {int page = 1, int pageSize = 50, int perType = 5}) async {
|
|
|
|
|
// Use cache for 'all' pincode queries (first page only for initial load)
|
|
|
|
|
if (pincode == 'all' &&
|
|
|
|
|
page == 1 &&
|
|
|
|
|
_cachedAllEvents != null &&
|
|
|
|
|
_eventsCacheTime != null &&
|
|
|
|
|
DateTime.now().difference(_eventsCacheTime!) < _eventsCacheTTL) {
|
|
|
|
|
return _cachedAllEvents!;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final Map<String, dynamic> body = {'pincode': pincode, 'page': page, 'page_size': pageSize};
|
|
|
|
|
// Diverse mode: fetch a few events per type so all categories are represented
|
|
|
|
|
if (perType > 0 && page == 1) body['per_type'] = perType;
|
|
|
|
|
|
|
|
|
|
final res = await _api.post(
|
|
|
|
|
ApiEndpoints.eventsByPincode,
|
|
|
|
|
body: body,
|
|
|
|
|
requiresAuth: false,
|
|
|
|
|
);
|
2026-01-31 15:23:18 +05:30
|
|
|
final list = <EventModel>[];
|
|
|
|
|
final events = res['events'] ?? res['data'] ?? [];
|
|
|
|
|
if (events is List) {
|
|
|
|
|
for (final e in events) {
|
|
|
|
|
if (e is Map<String, dynamic>) list.add(EventModel.fromJson(Map<String, dynamic>.from(e)));
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-03-30 10:05:23 +05:30
|
|
|
|
|
|
|
|
if (pincode == 'all' && page == 1) {
|
|
|
|
|
_cachedAllEvents = list;
|
|
|
|
|
_eventsCacheTime = DateTime.now();
|
|
|
|
|
}
|
2026-01-31 15:23:18 +05:30
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Event details
|
|
|
|
|
Future<EventModel> getEventDetails(int eventId) async {
|
2026-03-29 19:25:40 +05:30
|
|
|
final res = await _api.post(ApiEndpoints.eventDetails, body: {'event_id': eventId}, requiresAuth: true);
|
2026-01-31 15:23:18 +05:30
|
|
|
return EventModel.fromJson(Map<String, dynamic>.from(res));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Events by month and year for calendar (POST to /events/events-by-month-year/)
|
|
|
|
|
Future<Map<String, dynamic>> getEventsByMonthYear(String month, int year) async {
|
feat: rebuild desktop UI to match Figma + website, hero slider improvements
- Desktop sidebar (262px, blue gradient, white pill nav), topbar (search + bell + avatar), responsive shell rewritten
- Desktop homepage: immersive hero with Ken Burns animation, pill category chips, date badge cards matching mvnew.eventifyplus.com/home
- Desktop calendar: 60/40 two-column layout with white background
- Desktop profile: full-width banner + 3-column event grids
- Desktop learn more: hero image + about/venue columns + gallery strip
- Desktop settings/contribute: polished to match design system
- Mobile hero slider: RepaintBoundary, animated dots with 44px tap targets, 5s auto-scroll, 8s post-swipe delay, shimmer loading, dynamic event type badge, human-readable dates
- Guest access: requiresAuth false on read endpoints
- Location fix: show place names instead of lat/lng coordinates
- Version 1.6.1+17
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-21 13:28:19 +05:30
|
|
|
final res = await _api.post(ApiEndpoints.eventsByMonth, body: {'month': month, 'year': year}, requiresAuth: false);
|
2026-01-31 15:23:18 +05:30
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-30 10:05:23 +05:30
|
|
|
/// Convenience: get events for a specific date (YYYY-MM-DD).
|
|
|
|
|
/// Uses the cached events list when available to avoid redundant API calls.
|
2026-01-31 15:23:18 +05:30
|
|
|
Future<List<EventModel>> getEventsForDate(String date) async {
|
|
|
|
|
final all = await getEventsByPincode('all');
|
|
|
|
|
return all.where((e) {
|
|
|
|
|
try {
|
2026-03-30 10:05:23 +05:30
|
|
|
return e.startDate == date ||
|
|
|
|
|
e.endDate == date ||
|
|
|
|
|
(DateTime.parse(e.startDate).isBefore(DateTime.parse(date)) &&
|
|
|
|
|
DateTime.parse(e.endDate).isAfter(DateTime.parse(date)));
|
2026-01-31 15:23:18 +05:30
|
|
|
} catch (_) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}).toList();
|
|
|
|
|
}
|
|
|
|
|
}
|