/src/main/java/com/google/ie/web/controller/HomeController.java

http://thoughtsite.googlecode.com/ · Java · 65 lines · 26 code · 11 blank · 28 comment · 0 complexity · 19a573bd9db2686621e759d18cdca79a MD5 · raw file

  1. /* Copyright 2010 Google Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS.
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License
  14. */
  15. package com.google.ie.web.controller;
  16. import com.google.ie.business.domain.Idea;
  17. import com.google.ie.business.service.IdeaService;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.stereotype.Controller;
  20. import org.springframework.ui.Model;
  21. import org.springframework.web.bind.annotation.RequestMapping;
  22. import java.util.List;
  23. /**
  24. * Controller for handling the data required for home page.
  25. *
  26. * @author aksrivastava
  27. *
  28. */
  29. @Controller
  30. public class HomeController {
  31. @Autowired
  32. private IdeaService ideaService;
  33. public HomeController() {
  34. }
  35. /**
  36. * Handles the request for serving home page.
  37. *
  38. * @return View name.
  39. */
  40. @RequestMapping("/")
  41. public String home(Model model) {
  42. /* Retrieve the recent idea list and put it into the Model */
  43. List<Idea> recentIdeas = ideaService.getRecentIdeas();
  44. model.addAttribute(WebConstants.RECENT_IDEAS_MODEL_KEY, recentIdeas);
  45. /* Retrieve the popular idea list and put it into the Model */
  46. List<Idea> popularIdeas = ideaService.getPopularIdeas();
  47. model.addAttribute(WebConstants.POPULAR_IDEAS_MODEL_KEY, popularIdeas);
  48. /* Retrieve the recently picked idea list and put it into the Model */
  49. List<Idea> recentlyPickedIdeas = ideaService.getRecentlyPickedIdeas();
  50. model.addAttribute(WebConstants.RECENTLY_PICKED_IDEA_MODEL_KEY,
  51. recentlyPickedIdeas);
  52. return "home";
  53. }
  54. }