ContentDetailRequest.ets 2.86 KB
import { Logger, ResourcesUtils } from 'wdKit';
import { HttpUrlUtils, ResponseDTO, WDHttp } from 'wdNetwork';
import { ContentDetailDTO } from 'wdBean';
import HashMap from '@ohos.util.HashMap';

const TAG = 'ContentDetailRequest';

const mock_switch = false;

export interface ContentDetailRequestParams {
  contentId: string
  relId: string
  relType: string
}

export interface recommentVideoListParame {
  pageSize: number;
  refreshCnt: number;
}
 

export class ContentDetailRequest {
  static getContentDetailDataMock(context: Context): Promise<ResponseDTO<ContentDetailDTO[]>> {
    Logger.info(TAG, `getContentDetailDataMock start`);
    return ResourcesUtils.getResourcesJson<ResponseDTO<ContentDetailDTO[]>>(context, 'content_detail2.json')
  }

  // /**
  //  * 现网-新闻内容详情域名
  //  */
  // static readonly HOST2: string = "https://pdapis.pdnews.cn";
  /**
   * 新闻内容详情【get】接口
   */
  // static readonly CONTENT_DETAIL_PATH: string = "/api/rmrb-bff-display-zh/content/zh/c/content/detail";

  static getContentDetailUrl(contentId: string, relId: string, relType: string) {
    let url = HttpUrlUtils.getHost() + HttpUrlUtils.DETAIL_PATH
    url = url + "?&contentId=" + contentId
      + "&relId=" + relId
      + "&relType=" + relType;
    return url;
  }

  static getContentDetail(params: ContentDetailRequestParams): Promise<ResponseDTO<ContentDetailDTO[]>> {
    if (mock_switch) {
      return ContentDetailRequest.getContentDetailDataMock(getContext());
    }
    let url = ContentDetailRequest.getContentDetailUrl(params.contentId, params.relId, params.relType)
    let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders();
    return WDHttp.get<ResponseDTO<ContentDetailDTO[]>>(url, headers)
  }

  /**
   *
   * @returns
   */
  static getContentInteract() {
    let url = HttpUrlUtils.getHost() + HttpUrlUtils.INTERACT_DATA_PATH
    let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders();
    return WDHttp.get(url, headers)
  }

  /**
   *
   * @returns
   */
  static postBatchLikeAndCollectStatus() {
    let url = HttpUrlUtils.getHost() + HttpUrlUtils.INTERACT_DATA_STATUS
    let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders();
    return WDHttp.post(url, headers)
  }

  /**
   *
   * @returns
   */
  static postBatchAttentionStatus() {
    let url = HttpUrlUtils.getHost() + HttpUrlUtils.FOLLOW_LIST_STATUS_DATA_PATH
    let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders();
    return WDHttp.post(url, headers)
  }


  /**
   * 沉浸式視頻查詢近20条数据
   * @returns
   */

  static postRecommendVideoList(params: recommentVideoListParame): Promise<ResponseDTO<ContentDetailDTO[]>> {
    let url = HttpUrlUtils.getHost() + HttpUrlUtils.RECOMMEND_VIDEOLIST
    let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders();
    return WDHttp.post0(url, params, headers)
  }
}