Skip to content

Commit

Permalink
Merge pull request #26 from OpenPecha/develop
Browse files Browse the repository at this point in the history
add festival to search and update festival column name
  • Loading branch information
CodingWithTashi authored Nov 25, 2024
2 parents cc53acd + f1b5a4c commit ce7a8d5
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 49 deletions.
18 changes: 10 additions & 8 deletions lib/config/go_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ final router = GoRouter(
initialLocation: '/',
routes: [
GoRoute(
path: '/',
builder: (context, state) {
return const SkeletonScreen();
}),
path: '/',
builder: (context, state) {
return const SkeletonScreen();
},
),
GoRoute(
path: DeitiesListScreen.routeName,
builder: (context, state) {
Expand Down Expand Up @@ -47,9 +48,10 @@ final router = GoRouter(
},
),
GoRoute(
path: FestivalDetailScreen.routeName,
builder: (context, state) {
return const FestivalDetailScreen();
}),
path: FestivalDetailScreen.routeName,
builder: (context, state) {
return const FestivalDetailScreen();
},
),
],
);
48 changes: 24 additions & 24 deletions lib/models/festival_model.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
class Festival {
final int id;
final int uid;
final String? eventTbname;
final String? eventEnname;
final String? tbTitle;
final String? enTitle;
final DateTime? startDate;
final DateTime? endDate;
final String? tbDescription;
final String? enDescription;
final String? tbContent;
final String? enContent;
final String categories;
final String? location;
final String pic;
Expand All @@ -18,12 +18,12 @@ class Festival {
Festival({
required this.id,
required this.uid,
this.eventTbname,
this.eventEnname,
this.tbTitle,
this.enTitle,
this.startDate,
this.endDate,
this.tbDescription,
this.enDescription,
this.tbContent,
this.enContent,
required this.categories,
this.location,
required this.pic,
Expand All @@ -37,12 +37,12 @@ class Festival {
return Festival(
id: map['id'] as int,
uid: map['uid'] as int,
eventTbname: map['event_tbname'] as String?,
eventEnname: map['event_enname'] as String?,
tbTitle: map['tbtitle'] as String?,
enTitle: map['entitle'] as String?,
startDate: DateTime.parse(map['start_date'] as String),
endDate: DateTime.parse(map['end_date'] as String),
tbDescription: map['tb_description'] as String?,
enDescription: map['en_description'] as String?,
tbContent: map['tbcontent'] as String?,
enContent: map['encontent'] as String?,
categories: map['categories'] as String,
location: map['location'] as String?,
pic: map['pic'] as String,
Expand All @@ -57,12 +57,12 @@ class Festival {
return {
'id': id,
'uid': uid,
'event_tbname': eventTbname,
'event_enname': eventEnname,
'tbtitle': tbTitle,
'entitle': enTitle,
'start_date': startDate.toString(),
'end_date': endDate.toString(),
'tb_description': tbDescription,
'en_description': enDescription,
'tbcontent': tbContent,
'encontent': enContent,
'categories': categories,
'location': location,
'pic': pic,
Expand All @@ -76,12 +76,12 @@ class Festival {
Festival copyWith({
int? id,
int? uid,
String? eventTbname,
String? eventEnname,
String? tbTitle,
String? enTitle,
DateTime? startDate,
DateTime? endDate,
String? tbDescription,
String? enDescription,
String? tbContent,
String? enContent,
String? categories,
String? location,
String? pic,
Expand All @@ -93,12 +93,12 @@ class Festival {
return Festival(
id: id ?? this.id,
uid: uid ?? this.uid,
eventTbname: eventTbname ?? this.eventTbname,
eventEnname: eventEnname ?? this.eventEnname,
tbTitle: tbTitle ?? this.tbTitle,
enTitle: enTitle ?? this.enTitle,
startDate: startDate ?? this.startDate,
endDate: endDate ?? this.endDate,
tbDescription: tbDescription ?? this.tbDescription,
enDescription: enDescription ?? this.enDescription,
tbContent: tbContent ?? this.tbContent,
enContent: enContent ?? this.enContent,
categories: categories ?? this.categories,
location: location ?? this.location,
pic: pic ?? this.pic,
Expand Down
24 changes: 23 additions & 1 deletion lib/repo/database_repository.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:gompa_tour/models/festival_model.dart';
import 'package:sqflite/sqflite.dart';

import '../helper/database_helper.dart';
Expand Down Expand Up @@ -141,10 +142,24 @@ class SearchRepository {
OR LOWER(enContent) LIKE LOWER('%$escapedQuery%')
''';

// Query festivals with score
final festivalQuery = '''
SELECT *,
CASE
WHEN LOWER(enTitle) LIKE LOWER('%$escapedQuery%') THEN 1
WHEN LOWER(enContent) LIKE LOWER('%$escapedQuery%') THEN 2
ELSE 3
END as match_score
FROM events
WHERE LOWER(enTitle) LIKE LOWER('%$escapedQuery%')
OR LOWER(enContent) LIKE LOWER('%$escapedQuery%')
''';

final db = await dbHelper.database;

final organizationMaps = await db.rawQuery(organizationQuery);
final deityMaps = await db.rawQuery(deityQuery);
final festivalMaps = await db.rawQuery(festivalQuery);

// Convert to models while preserving scores
final organizations = organizationMaps.map((map) {
Expand All @@ -161,8 +176,15 @@ class SearchRepository {
return (Deity.fromMap(mapWithoutScore), score);
}).toList();

final festivals = festivalMaps.map((map) {
final score = map['match_score'] as int;
final mapWithoutScore = Map<String, dynamic>.from(map)
..remove('match_score');
return (Festival.fromMap(mapWithoutScore), score);
}).toList();

// Combine and sort by score
final combinedResults = [...organizations, ...deities];
final combinedResults = [...organizations, ...deities, ...festivals];
combinedResults.sort((a, b) => a.$2.compareTo(b.$2)); // Sort by score

// Return just the models in sorted order
Expand Down
12 changes: 6 additions & 6 deletions lib/ui/screen/festival_detail_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class FestivalDetailScreen extends ConsumerWidget {
return Scaffold(
appBar: GonpaAppBar(
title: context.localizedText(
enText: selectedFestival.eventEnname!,
boText: selectedFestival.eventTbname!,
enText: selectedFestival.enTitle!,
boText: selectedFestival.tbTitle!,
)),
body: SingleChildScrollView(
physics: const BouncingScrollPhysics(),
Expand All @@ -38,8 +38,8 @@ class FestivalDetailScreen extends ConsumerWidget {
Center(
child: Text(
context.localizedText(
enText: selectedFestival.eventEnname!,
boText: selectedFestival.eventTbname!,
enText: selectedFestival.enTitle!,
boText: selectedFestival.tbTitle!,
),
style: const TextStyle(
fontSize: 24,
Expand All @@ -60,8 +60,8 @@ class FestivalDetailScreen extends ConsumerWidget {
const SizedBox(height: 16),
Text(
context.localizedText(
enText: selectedFestival.enDescription!,
boText: selectedFestival.tbDescription!,
enText: selectedFestival.enContent!,
boText: selectedFestival.tbContent!,
),
style: TextStyle(
fontSize: 16, height: context.getLocalizedHeight()),
Expand Down
19 changes: 9 additions & 10 deletions lib/ui/widget/festival_card_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class FestivalCardItem extends ConsumerWidget {
children: [
Text(
context.localizedText(
enText: festival.eventEnname!,
boText: festival.eventTbname!,
enText: festival.enTitle!,
boText: festival.tbTitle!,
),
style: const TextStyle(
fontSize: 18,
Expand All @@ -58,15 +58,14 @@ class FestivalCardItem extends ConsumerWidget {
),
const SizedBox(width: 16),
Expanded(
child: Text(
context.localizedText(
enText: festival.enDescription!,
boText: festival.tbDescription!,
maxLength: kDescriptionMaxLength,
),
style: const TextStyle(fontSize: 16),
child: Text(
context.localizedText(
enText: festival.enContent!,
boText: festival.tbContent!,
maxLength: kDescriptionMaxLength,
),
),
style: const TextStyle(fontSize: 16),
)),
],
),
],
Expand Down

0 comments on commit ce7a8d5

Please sign in to comment.