Subversion Repositories SmartDukaan

Rev

Rev 23568 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.spice.profitmandi.web.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.spice.profitmandi.common.model.ProfitMandiConstants;
import com.spice.profitmandi.common.web.util.ResponseSender;
import com.spice.profitmandi.dao.model.ContentPojo;
import com.spice.profitmandi.dao.repository.dtr.Mongo;
import com.spice.profitmandi.web.res.EntityResponse;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Controller
public class EntityController {

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

        @Autowired
        private Mongo mongo;

        @Autowired
        private ResponseSender<?> responseSender;

        @RequestMapping(value = ProfitMandiConstants.URL_ENTITY, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
        @ApiImplicitParams({
                        @ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })

        @ApiOperation(value = "Get entity content")
        public ResponseEntity<?> getEntity(HttpServletRequest request, @PathVariable(value = "entityId") long entityId)
                        throws Exception {
                logger.info("Entity Id " + entityId);
                ContentPojo cp = mongo.getEntityById(entityId);
                EntityResponse er = new EntityResponse();
                er.setEntity(cp);
                return responseSender.ok(er);
        }
}