|
|
@ -19,53 +19,46 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
package org.libresonic.player.controller; |
|
|
|
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.domain.MediaFile; |
|
|
|
import org.libresonic.player.service.MediaFileService; |
|
|
|
import org.libresonic.player.service.MediaFileService; |
|
|
|
import org.libresonic.player.service.RatingService; |
|
|
|
import org.libresonic.player.service.RatingService; |
|
|
|
import org.libresonic.player.service.SecurityService; |
|
|
|
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. |
|
|
|
* Controller for updating music file ratings. |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Sindre Mehus |
|
|
|
* @author Sindre Mehus |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class SetRatingController extends AbstractController { |
|
|
|
@Controller |
|
|
|
|
|
|
|
@RequestMapping("/setRating") |
|
|
|
|
|
|
|
public class SetRatingController { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
private RatingService ratingService; |
|
|
|
private RatingService ratingService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private SecurityService securityService; |
|
|
|
private SecurityService securityService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private MediaFileService mediaFileService; |
|
|
|
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"); |
|
|
|
int id = ServletRequestUtils.getRequiredIntParameter(request, "id"); |
|
|
|
Integer rating = ServletRequestUtils.getIntParameter(request, "rating"); |
|
|
|
Integer rating = ServletRequestUtils.getIntParameter(request, "rating"); |
|
|
|
if (rating == 0) { |
|
|
|
if (rating == 0) { |
|
|
|
rating = null; |
|
|
|
rating = null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
MediaFile mediaFile = mediaFileService.getMediaFile(id); |
|
|
|
MediaFile mediaFile = mediaFileService.getMediaFile(id); |
|
|
|
String username = securityService.getCurrentUsername(request); |
|
|
|
String username = securityService.getCurrentUsername(request); |
|
|
|
ratingService.setRatingForUser(username, mediaFile, rating); |
|
|
|
ratingService.setRatingForUser(username, mediaFile, rating); |
|
|
|
|
|
|
|
|
|
|
|
return new ModelAndView(new RedirectView("main.view?id=" + id)); |
|
|
|
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; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|