From 51ce826de6fa7ec5e464902f0eeb8f0a08b4014d Mon Sep 17 00:00:00 2001 From: odweta Date: Thu, 2 Apr 2026 19:58:41 +0200 Subject: [PATCH] added correct sorting of quotes in the list; set up a testing environment --- backend/main.go | 2 ++ frontend/lib/provider/quote_provider.dart | 7 ++++++- frontend/lib/repository/quote_repository.dart | 7 +++---- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/backend/main.go b/backend/main.go index 213b0b6..ea5b665 100644 --- a/backend/main.go +++ b/backend/main.go @@ -3,6 +3,7 @@ package main import ( "net/http" "os" + "fmt" "github.com/go-chi/chi/v5" ) @@ -25,5 +26,6 @@ func main() { port = "8080" } + fmt.Println("started and listening on localhost:" + port) http.ListenAndServe(":"+port, r) } \ No newline at end of file diff --git a/frontend/lib/provider/quote_provider.dart b/frontend/lib/provider/quote_provider.dart index a21cee0..6c9d758 100644 --- a/frontend/lib/provider/quote_provider.dart +++ b/frontend/lib/provider/quote_provider.dart @@ -18,7 +18,7 @@ class QuoteProvider extends ChangeNotifier { List get filteredQuotes { final query = filterController.text.toLowerCase(); - return _quotes.where((quote) { + final filtered = _quotes.where((quote) { switch (filterBy) { case 0: return quote.author.toLowerCase().contains(query); @@ -28,6 +28,11 @@ class QuoteProvider extends ChangeNotifier { return true; } }).toList(); + + // sort descending + filtered.sort((a, b) => b.id.compareTo(a.id)); + + return filtered; } final QuoteRepository repo = QuoteRepository(); diff --git a/frontend/lib/repository/quote_repository.dart b/frontend/lib/repository/quote_repository.dart index 4440277..1996225 100644 --- a/frontend/lib/repository/quote_repository.dart +++ b/frontend/lib/repository/quote_repository.dart @@ -1,13 +1,12 @@ -// talks to the DB itself -// TODO: implement the real one - import 'dart:convert'; import 'package:http/http.dart' as http; import 'package:frontend/model/quote.dart'; class QuoteRepository { - static final String _apiBaseUrl = 'https://hlaskovnik-reimagined-latest.onrender.com'; + //static final String _realApiBaseUrl = 'https://hlaskovnik-reimagined-latest.onrender.com'; + static final String _testApiBaseUrl = 'http://localhost:8080'; + static final String _apiBaseUrl = _testApiBaseUrl; static final String _apiKey = "2ogD5kc4sw3JVZoouQSV0w3LGRjSj5IjVFnAnk7IRCIK0ktONCeoOYinbNLSIHuU"; static final String _quotesEndpoint = '/quotes';