Merge pull request 'feature/getcurrentdate' (#12) from feature/getcurrentdate into main

Reviewed-on: #12
This commit is contained in:
v4l3n71n 2024-11-11 11:51:16 +01:00
commit c8bcd254dd
2 changed files with 12 additions and 7 deletions

View File

@ -50,6 +50,7 @@ class _MyHomePageState extends State<ListItemMenu> {
// Fetching events from API
static Future<List<Events>> getPosts() async {
PermissionStatus status = await Permission.location.status;
var url = Uri.parse("${globals.api}/events");
if (status.isGranted) {
print("Location permission granted");
@ -74,10 +75,10 @@ class _MyHomePageState extends State<ListItemMenu> {
double maxLat = position.latitude + latDistance;
double minLon = position.longitude - lonDistance;
double maxLon = position.longitude + lonDistance;
DateTime currentDatetime = DateTime.now();
url = Uri.parse("${globals.api}/events/search"
"?min_lat=$minLat&max_lat=$maxLat"
"&min_lon=$minLon&max_lon=$maxLon");
"&min_lon=$minLon&max_lon=$maxLon&current_datetime=${currentDatetime.toString()}");
}
SharedPreferences prefs = await SharedPreferences.getInstance();
var accessToken = prefs.getString("access_token") ?? "";
@ -99,7 +100,9 @@ class _MyHomePageState extends State<ListItemMenu> {
var accessToken = prefs.getString("access_token") ?? "";
final List<Events> body = [];
if (accessToken.isNotEmpty) {
var url = Uri.parse("${globals.api}/events");
DateTime currentDateTime = new DateTime.now();
var url = Uri.parse(
"${globals.api}/events?current_datetime=${currentDateTime.toString()}");
final response = await http.get(url, headers: {
"Content-Type": "application/json",
HttpHeaders.cookieHeader: "access_token=${accessToken}"
@ -262,10 +265,10 @@ class _MyHomePageState extends State<ListItemMenu> {
double maxLat = latitude + latDistance;
double minLon = longitude - lonDistance;
double maxLon = longitude + lonDistance;
DateTime currentDate = DateTime.now();
var url = Uri.parse("${globals.api}/events/search"
"?min_lat=$minLat&max_lat=$maxLat"
"&min_lon=$minLon&max_lon=$maxLon");
"&min_lon=$minLon&max_lon=$maxLon&current_datetime=${currentDate.toString()}");
final response = await http.get(url, headers: {
"Content-Type": "application/json",

View File

@ -84,7 +84,9 @@ class SearchDelegateExample extends SearchDelegate {
var accessToken = prefs.getString("access_token") ?? "";
final List<Events> body = [];
if (accessToken.isNotEmpty) {
var url = Uri.parse("${globals.api}/events/search?item=$query");
DateTime currentDate = DateTime.now();
var url = Uri.parse(
"${globals.api}/events/search?item=${query}&current_dateime=${currentDate.toString()}");
if (geoQuery.isNotEmpty) {
await dotenv.load(
fileName: ".env"); // Load your .env for the Mapbox access token
@ -113,7 +115,7 @@ class SearchDelegateExample extends SearchDelegate {
// Construct the search URL with the item query and latitude/longitude bounds
url = Uri.parse(
"${globals.api}/events/search?item=$query&min_lat=$minLat&max_lat=$maxLat&min_lon=$minLon&max_lon=$maxLon");
"${globals.api}/events/search?item=${query}&min_lat=${minLat}&max_lat=${maxLat}&min_lon=${minLon}&max_lon=${maxLon}&current_dateime=${currentDate.toString()}");
}
}
}