From 0c265e2f3dee016b2bd00263c2ca41ea0b0f34a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Thu, 1 Dec 2016 22:19:28 +0100 Subject: [PATCH] Migration of SearchController + unit test. --- .../controller/PlayerSettingsController.java | 2 +- .../player/controller/SearchController.java | 43 +++++++++---------- .../webapp/WEB-INF/libresonic-servlet.xml | 10 ----- 3 files changed, 21 insertions(+), 34 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/PlayerSettingsController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/PlayerSettingsController.java index 50baca35..875a7cc8 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/PlayerSettingsController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/PlayerSettingsController.java @@ -60,7 +60,7 @@ public class PlayerSettingsController { private TranscodingService transcodingService; @RequestMapping(method = RequestMethod.GET) - protected Object formBackingObject(HttpServletRequest request, Model model) throws Exception { + protected String formBackingObject(HttpServletRequest request, Model model) throws Exception { handleRequestParameters(request); List players = getPlayers(request); diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/SearchController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/SearchController.java index a357b120..3c5144d1 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/SearchController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/SearchController.java @@ -25,7 +25,12 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; import org.springframework.validation.BindException; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.SimpleFormController; @@ -45,24 +50,30 @@ import org.libresonic.player.service.SettingsService; * * @author Sindre Mehus */ -public class SearchController extends SimpleFormController { +@Controller +@RequestMapping("/search") +public class SearchController { private static final int MATCH_COUNT = 25; + @Autowired private SecurityService securityService; + @Autowired private SettingsService settingsService; + @Autowired private PlayerService playerService; + @Autowired private SearchService searchService; - @Override - protected Object formBackingObject(HttpServletRequest request) throws Exception { - return new SearchCommand(); + @RequestMapping(method = RequestMethod.GET) + protected String formBackingObject(HttpServletRequest request, Model model) throws Exception { + model.addAttribute("command",new SearchCommand()); + return "search"; } - @Override - protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object com, BindException errors) + @RequestMapping(method = RequestMethod.POST) + protected String onSubmit(HttpServletRequest request, HttpServletResponse response, SearchCommand command, Model model) throws Exception { - SearchCommand command = (SearchCommand) com; User user = securityService.getCurrentUser(request); UserSettings userSettings = settingsService.getUserSettings(user.getUsername()); @@ -90,22 +101,8 @@ public class SearchController extends SimpleFormController { command.setPlayer(playerService.getPlayer(request, response)); } - return new ModelAndView(getSuccessView(), errors.getModel()); + model.addAttribute("command",command); + return "search"; } - public void setSecurityService(SecurityService securityService) { - this.securityService = securityService; - } - - public void setSettingsService(SettingsService settingsService) { - this.settingsService = settingsService; - } - - public void setPlayerService(PlayerService playerService) { - this.playerService = playerService; - } - - public void setSearchService(SearchService searchService) { - this.searchService = searchService; - } } diff --git a/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml b/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml index 7c7d01c7..afbf083e 100644 --- a/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml +++ b/libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml @@ -161,15 +161,6 @@ - - - - - - - - - @@ -413,7 +404,6 @@ videoPlayerController nowPlayingController starredController - searchController settingsController dlnaSettingsController sonosSettingsController