From 42709b0e0d3ad6e63dbb894efb85e1c92d61f3dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Cocula?= Date: Sun, 18 Dec 2016 01:07:35 +0100 Subject: [PATCH] Controllers migration. --- .../controller/ChangeCoverArtController.java | 16 ++++---- .../controller/SetRatingController.java | 39 ++++++++----------- .../src/main/resources/libresonic-servlet.xml | 11 ------ 3 files changed, 24 insertions(+), 42 deletions(-) diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/ChangeCoverArtController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/ChangeCoverArtController.java index 9e977ea2..fed59892 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/ChangeCoverArtController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/ChangeCoverArtController.java @@ -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; - } } diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/SetRatingController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/SetRatingController.java index d7962dfc..091e23ad 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/SetRatingController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/SetRatingController.java @@ -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; - } } diff --git a/libresonic-main/src/main/resources/libresonic-servlet.xml b/libresonic-main/src/main/resources/libresonic-servlet.xml index f26e2ccd..7d3c42bf 100644 --- a/libresonic-main/src/main/resources/libresonic-servlet.xml +++ b/libresonic-main/src/main/resources/libresonic-servlet.xml @@ -15,15 +15,6 @@ - - - - - - - - - @@ -178,8 +169,6 @@ multiController - setRatingController - changeCoverArtController multiController multiController multiController