wiki:UseCaseImplementation

Version 9 (modified by 222077, 5 days ago) ( diff )

--

Implementation of user scenarios in the prototype

In the technical prototype of the application implemented so far, the following scenarios have been implemented:

ID UseCase
1Search Routes
2Organize Trip
3Manage Trip
4View My Trips
5Login
6Register

ID 1 - Search Routes

The /search-routes endpoint provides users with the ability to search for available transport routes from different organizers. It supports both viewing all routes by default and filtering routes based on user input (departure and arrival locations). The request is handled by UserRouteController, which interacts with RouteService to retrieve the relevant data.

Here is an example of a search query: -/search-routes?from=sk&to=ohrid

    @RequestMapping("/search-routes")
    public class UserRouteController {
        
        private final RouteService routeService;

        public UserRouteController(RouteService routeService) {
            this.routeService = routeService;
        }

        @GetMapping
        public String findRoutesByFromAndTo(@RequestParam(required = false) String from,
                                            @RequestParam(required = false) String to,
                                            Model model) {
            
            List<Route> filteredRoutes = ((from == null || from.isBlank()) && (to == null || to.isBlank()))
                    ? routeService.findAll()
                    : routeService.findRouteByFromAndToDest(from, to);

            model.addAttribute(filteredRoutes.isEmpty() ? "noRoutesMessage" : "routes",
                    filteredRoutes.isEmpty() ? "No routes found for your search." : filteredRoutes);
            model.addAttribute("display", "user/search-routes");

            return "master";
        }
    }

Controller Details:

  • URL Mapping: /search-routes
  • Method: GET
  • Functionality:
    • Displays all routes when the page is accessed without search criteria.
    • Filters results based on the user's input (from and to).
  • View: Uses the master template and dynamically embeds user/search-routes.

Breakdown:

  • When users first visit /search-routes, the controller calls routeService.findAll() to display all available routes.
  • When users provide search criteria (from and/or to), it filters results using routeService.findRouteByFromAndToDest(from, to).
  • If no matching routes are found, a "No routes found for your search." message is displayed instead of an empty table.
  • The retrieved data is added to the Model, ensuring the front-end can render the appropriate content.

Result of /search-routes

Result of /search-routes?from=sk&to=ohrid

Attachments (15)

Download all attachments as: .zip

Note: See TracWiki for help on using the wiki.