Migration of SearchController + unit test.

master
Rémi Cocula 8 years ago
parent c46416834b
commit 0c265e2f3d
  1. 2
      libresonic-main/src/main/java/org/libresonic/player/controller/PlayerSettingsController.java
  2. 43
      libresonic-main/src/main/java/org/libresonic/player/controller/SearchController.java
  3. 10
      libresonic-main/src/main/webapp/WEB-INF/libresonic-servlet.xml

@ -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<Player> players = getPlayers(request);

@ -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;
}
}

@ -161,15 +161,6 @@
<property name="mediaFileDao" ref="mediaFileDao"/>
<property name="mediaFileService" ref="mediaFileService"/>
</bean>
<bean id="searchController" class="org.libresonic.player.controller.SearchController">
<property name="commandClass" value="org.libresonic.player.command.SearchCommand"/>
<property name="successView" value="search"/>
<property name="formView" value="search"/>
<property name="searchService" ref="searchService"/>
<property name="securityService" ref="securityService"/>
<property name="settingsService" ref="settingsService"/>
<property name="playerService" ref="playerService"/>
</bean>
<bean id="settingsController" class="org.libresonic.player.controller.SettingsController">
<property name="securityService" ref="securityService"/>
</bean>
@ -413,7 +404,6 @@
<prop key="/videoPlayer.view">videoPlayerController</prop>
<prop key="/nowPlaying.view">nowPlayingController</prop>
<prop key="/starred.view">starredController</prop>
<prop key="/search.view">searchController</prop>
<prop key="/settings.view">settingsController</prop>
<prop key="/dlnaSettings.view">dlnaSettingsController</prop>
<prop key="/sonosSettings.view">sonosSettingsController</prop>

Loading…
Cancel
Save