cz.muni.fi.editor.webapp.controllers.NotificationController.java Source code

Java tutorial

Introduction

Here is the source code for cz.muni.fi.editor.webapp.controllers.NotificationController.java

Source

/*
*Copyright  2016 Dominik Szalai (emptulik@gmail.com)
*
*Licensed under the Apache License, Version 2.0 (the "License");
*you may not use this file except in compliance with the License.
*You may obtain a copy of the License at
*
*    http://www.apache.org/licenses/LICENSE-2.0
*
*Unless required by applicable law or agreed to in writing, software
*distributed under the License is distributed on an "AS IS" BASIS,
*WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*See the License for the specific language governing permissions and
*limitations under the License.
*/
/*
 * Copyright  2016 Dominik Szalai (emptulik@gmail.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cz.muni.fi.editor.webapp.controllers;

import cz.muni.fi.editor.api.NotificationService;
import cz.muni.fi.editor.api.dto.NotificationRequest;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.text.MessageFormat;

/**
 * Created by Dominik Szalai - emptulik at gmail.com on 4.9.2016.
 */
@Log4j2
@Controller(value = "NC")
@RequestMapping("/auth/notification")
public class NotificationController {
    @Autowired
    private NotificationService notificationService;

    @RequestMapping("/")
    public String list(Model model) {
        model.addAttribute("notifications", notificationService.getNotifications(new NotificationRequest(0, true)));

        return "notification.list";
    }

    @RequestMapping(value = "/{page}/{includeSeen}/", method = RequestMethod.GET)
    public String listPaginated(@PathVariable int page, @PathVariable boolean includeSeen, Model model) {
        model.addAttribute("notifications",
                notificationService.getNotifications(new NotificationRequest(page, includeSeen)));

        return "notification.list";
    }

    @RequestMapping(value = "/{page}/*/", method = RequestMethod.POST)
    public String listPaginatedPost(@PathVariable int page, @ModelAttribute NotificationRequest request) {
        return MessageFormat.format("redirect:/auth/notification/{0}/{1}/", page, request.getIncludeSeen());
    }
}