io.github.autsia.crowly.controllers.rest.MentionsController.java Source code

Java tutorial

Introduction

Here is the source code for io.github.autsia.crowly.controllers.rest.MentionsController.java

Source

/*
 * Copyright 2014 Dmytro Titov
 *
 * 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 io.github.autsia.crowly.controllers.rest;

import io.github.autsia.crowly.model.Mention;
import io.github.autsia.crowly.repositories.MentionRepository;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.Collections;
import java.util.List;

/**
 * Created by Dmytro on 04.01.14 at 21:02
 * Project: crowly
 */
@RestController("restMentionsController")
@RequestMapping("/rest/mentions")
public class MentionsController {

    private static final Logger logger = Logger.getLogger(MentionsController.class);

    private MentionRepository mentionRepository;

    @RequestMapping(value = "/getByCampaign", method = RequestMethod.GET)
    public List<Mention> getCampaignsForCurrentUser(@RequestParam String campaignId, HttpServletResponse response) {
        try {
            return mentionRepository.findByCampaignId(campaignId);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return Collections.emptyList();
        }
    }

    @Autowired
    public void setMentionRepository(MentionRepository mentionRepository) {
        this.mentionRepository = mentionRepository;
    }

}