ContentDetailRequest.ets 1.5 KB
import { Logger, ResourcesUtils } from 'wdKit';
import { ResponseDTO, WDHttp } from 'wdNetwork'
import { ContentDetailDTO } from 'wdBean'

const TAG = 'ContentDetailRequest';

const mock_switch = false;

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

export class ContentDetailRequest {
  static getContentDetailDataMock(context: Context): Promise<ResponseDTO<ContentDetailDTO[]>> {
    Logger.info(TAG, `getContentDetailDataMock start`);
    return ResourcesUtils.getResourcesJson<ResponseDTO<ContentDetailDTO[]>>(context, 'content_detail.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 = ContentDetailRequest.HOST2 + ContentDetailRequest.CONTENT_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)
    return WDHttp.get<ResponseDTO<ContentDetailDTO[]>>(url)
  }
}