package com.engine.htsc.cube.web;

import com.engine.common.util.ServiceUtil;
import com.engine.htsc.cube.service.PortalFavoriteService;
import com.engine.htsc.cube.service.impl.PortalFavoriteServiceImpl;
import com.engine.htsc.trip.util.AjaxResult;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import java.util.Map;

/**
 * 门户收藏接口对接
 * 添加,删除p
 */
public class PortalFavouriteAction {

  private PortalFavoriteService getServices() {
    return ServiceUtil.getService(PortalFavoriteServiceImpl.class);
  }

  @POST
  @Path("/favourite/add")
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.APPLICATION_JSON)
  public AjaxResult<String> addFavourite(Map<String, String> params) {
    try {
      return AjaxResult.ok(getServices().favouriteOperate(params, "add"));
    } catch (Exception e) {
      e.printStackTrace();
      return AjaxResult.error(e.getMessage());
    }
  }

  @POST
  @Path("/favourite/cancel")
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.APPLICATION_JSON)
  public AjaxResult<String> cancelFavourite(Map<String, String> params) {
    try {
      return AjaxResult.ok(getServices().favouriteOperate(params, "cancel"));
    } catch (Exception e) {
      e.printStackTrace();
      return AjaxResult.error(e.getMessage());
    }
  }
}
