Controllers migration.

master
Rémi Cocula 8 years ago
parent 70ed378ae0
commit 42709b0e0d
  1. 16
      libresonic-main/src/main/java/org/libresonic/player/controller/ChangeCoverArtController.java
  2. 39
      libresonic-main/src/main/java/org/libresonic/player/controller/SetRatingController.java
  3. 11
      libresonic-main/src/main/resources/libresonic-servlet.xml

@ -25,7 +25,10 @@ import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.ParameterizableViewController;
@ -37,11 +40,13 @@ import org.libresonic.player.service.MediaFileService;
*
* @author Sindre Mehus
*/
public class ChangeCoverArtController extends ParameterizableViewController {
@Controller
@RequestMapping("/changeCoverArt")
public class ChangeCoverArtController {
@Autowired
private MediaFileService mediaFileService;
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
int id = ServletRequestUtils.getRequiredIntParameter(request, "id");
@ -61,13 +66,8 @@ public class ChangeCoverArtController extends ParameterizableViewController {
map.put("artist", artist);
map.put("album", album);
ModelAndView result = super.handleRequestInternal(request, response);
result.addObject("model", map);
return result;
return new ModelAndView("changeCoverArt","model",map);
}
public void setMediaFileService(MediaFileService mediaFileService) {
this.mediaFileService = mediaFileService;
}
}

@ -19,53 +19,46 @@
*/
package org.libresonic.player.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;
import org.springframework.web.servlet.view.RedirectView;
import org.libresonic.player.domain.MediaFile;
import org.libresonic.player.service.MediaFileService;
import org.libresonic.player.service.RatingService;
import org.libresonic.player.service.SecurityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;
import javax.servlet.http.HttpServletRequest;
/**
* Controller for updating music file ratings.
*
* @author Sindre Mehus
*/
public class SetRatingController extends AbstractController {
@Controller
@RequestMapping("/setRating")
public class SetRatingController {
@Autowired
private RatingService ratingService;
@Autowired
private SecurityService securityService;
@Autowired
private MediaFileService mediaFileService;
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
protected ModelAndView handleRequestInternal(HttpServletRequest request) throws Exception {
int id = ServletRequestUtils.getRequiredIntParameter(request, "id");
Integer rating = ServletRequestUtils.getIntParameter(request, "rating");
if (rating == 0) {
rating = null;
}
MediaFile mediaFile = mediaFileService.getMediaFile(id);
String username = securityService.getCurrentUsername(request);
ratingService.setRatingForUser(username, mediaFile, rating);
return new ModelAndView(new RedirectView("main.view?id=" + id));
}
public void setRatingService(RatingService ratingService) {
this.ratingService = ratingService;
}
public void setSecurityService(SecurityService securityService) {
this.securityService = securityService;
}
public void setMediaFileService(MediaFileService mediaFileService) {
this.mediaFileService = mediaFileService;
}
}

@ -15,15 +15,6 @@
<mvc:annotation-driven />
<context:component-scan base-package="org.libresonic.player.controller, org.libresonic.player.validator"/>
<bean id="setRatingController" class="org.libresonic.player.controller.SetRatingController">
<property name="ratingService" ref="ratingService"/>
<property name="mediaFileService" ref="mediaFileService"/>
<property name="securityService" ref="securityService"/>
</bean>
<bean id="changeCoverArtController" class="org.libresonic.player.controller.ChangeCoverArtController">
<property name="viewName" value="changeCoverArt"/>
<property name="mediaFileService" ref="mediaFileService"/>
</bean>
<bean id="starredController" class="org.libresonic.player.controller.StarredController">
<property name="viewName" value="starred"/>
<property name="playerService" ref="playerService"/>
@ -178,8 +169,6 @@
<property name="mappings">
<props>
<prop key="/exportPlaylist.view">multiController</prop>
<prop key="/setRating.view">setRatingController</prop>
<prop key="/changeCoverArt.view">changeCoverArtController</prop>
<prop key="/recover.view">multiController</prop>
<prop key="/accessDenied.view">multiController</prop>
<prop key="/notFound.view">multiController</prop>

Loading…
Cancel
Save