|
| 1 | +package org.woehlke.twitterwall.frontend.controller; |
| 2 | + |
| 3 | + |
| 4 | +import org.slf4j.Logger; |
| 5 | +import org.slf4j.LoggerFactory; |
| 6 | +import org.springframework.beans.factory.annotation.Autowired; |
| 7 | +import org.springframework.data.domain.PageRequest; |
| 8 | +import org.springframework.data.domain.Pageable; |
| 9 | +import org.springframework.data.domain.Sort; |
| 10 | +import org.springframework.stereotype.Controller; |
| 11 | +import org.springframework.ui.Model; |
| 12 | +import org.springframework.web.bind.annotation.PathVariable; |
| 13 | +import org.springframework.web.bind.annotation.RequestMapping; |
| 14 | +import org.springframework.web.bind.annotation.RequestParam; |
| 15 | +import org.woehlke.twitterwall.conf.properties.FrontendProperties; |
| 16 | +import org.woehlke.twitterwall.frontend.controller.common.ControllerHelper; |
| 17 | +import org.woehlke.twitterwall.frontend.controller.common.Symbols; |
| 18 | +import org.woehlke.twitterwall.oodm.entities.UserList; |
| 19 | +import org.woehlke.twitterwall.oodm.service.UserListService; |
| 20 | + |
| 21 | +@Controller |
| 22 | +@RequestMapping("/userlist") |
| 23 | +public class UserListController { |
| 24 | + |
| 25 | + private final static String PATH="userlist"; |
| 26 | + |
| 27 | + @RequestMapping("/all") |
| 28 | + public String getAll( |
| 29 | + @RequestParam(name= "page", defaultValue=""+ControllerHelper.FIRST_PAGE_NUMBER) int page, |
| 30 | + Model model |
| 31 | + ) { |
| 32 | + Pageable pageRequest = new PageRequest( |
| 33 | + page, |
| 34 | + frontendProperties.getPageSize(), |
| 35 | + Sort.Direction.ASC, |
| 36 | + "screenName" |
| 37 | + ); |
| 38 | + model.addAttribute("users", userListService.getAll(pageRequest)); |
| 39 | + String symbol = Symbols.USER_ALL.toString(); |
| 40 | + String subtitle = "All Users"; |
| 41 | + model = controllerHelper.setupPage(model, title, subtitle, symbol); |
| 42 | + return "userlist/all"; |
| 43 | + } |
| 44 | + |
| 45 | + @RequestMapping("/{id}") |
| 46 | + public String getUserForId( |
| 47 | + @RequestParam(name= "page", defaultValue=""+ControllerHelper.FIRST_PAGE_NUMBER) int page, |
| 48 | + @PathVariable("id") UserList userList, Model model |
| 49 | + ) { |
| 50 | + Pageable pageRequest = new PageRequest( |
| 51 | + page, |
| 52 | + frontendProperties.getPageSize(), |
| 53 | + Sort.Direction.DESC, |
| 54 | + "createdAt" |
| 55 | + ); |
| 56 | + String symbol = Symbols.PROFILE.toString(); |
| 57 | + String title = userList.getFullName(); |
| 58 | + String subtitle = userList.getDescription(); |
| 59 | + model = controllerHelper.setupPage(model, title, subtitle, symbol); |
| 60 | + model.addAttribute("userList", userList); |
| 61 | + return "userlist/id"; |
| 62 | + } |
| 63 | + |
| 64 | + private static final Logger log = LoggerFactory.getLogger(UserController.class); |
| 65 | + |
| 66 | + private final UserListService userListService; |
| 67 | + |
| 68 | + private final FrontendProperties frontendProperties; |
| 69 | + |
| 70 | + private final ControllerHelper controllerHelper; |
| 71 | + |
| 72 | + private static String title = "User List"; |
| 73 | + |
| 74 | + @Autowired |
| 75 | + public UserListController(UserListService userListService, FrontendProperties frontendProperties, ControllerHelper controllerHelper) { |
| 76 | + this.userListService = userListService; |
| 77 | + this.frontendProperties = frontendProperties; |
| 78 | + this.controllerHelper = controllerHelper; |
| 79 | + } |
| 80 | +} |
0 commit comments