我正在搜索游戏名称并想从外部 api 获取游戏数据.. 如果游戏名称丢失,请将其保存到数据库

编程入门 行业动态 更新时间:2024-10-07 12:26:41

我正在搜索<a href=https://www.elefans.com/category/jswz/34/1351964.html style=游戏名称并想从外部 api 获取游戏数据.. 如果游戏名称丢失,请将其保存到数据库"/>

我正在搜索游戏名称并想从外部 api 获取游戏数据.. 如果游戏名称丢失,请将其保存到数据库

我是 loopback4 上的新手,并通过使用 loopback 连接器 rest 包做了一切来处理来自外部 API 的数据,如果 s-game 名称搜索是 api 它成功但如果不是,应该将名称保存到 postgresql ..在这一点上我需要帮助。

这是我的模特:

@model()
export class Games extends Entity {
  @property({
    type: 'number',
    id: true,
    generated: true,
  })
  id?: number;

  @property({
    type: 'number',
  })
  cheapest: number;

  @property({
    type: 'string',
  })
  cheapestID?: string;

  @property({
    type: 'string',
  })
  external?: string;

  @property({
    type: 'string',
  })
  internalName?: string;

  @property({
    type: 'string',
  })
  thumb?: string;

这是我的外部 api rest 数据源配置:

const config = {
  name: 'rest',
  connector: 'rest',
  options: {
    headers: {
      accept: 'application/json',
      'content-type': 'application/json',
    },
  },
  operations: [
    {
      template: {
        method: 'GET',
        url: '.0/stores',
      },
      functions: {
        AllStores: [],
      },
    },
    {
      template: {
        method: 'GET',
        url: '.0/games?title={title}',
      },
      functions: {
        findByTitle: ['title'],
      },
    },
  ],
};

这是控制器:

export class GamesController {
  constructor(
    @repository(GamesRepository)
    public gamesRepository: GamesRepository,
    @inject('service.GameService')
    protected gameService: GameService,
  ) {}

  @get('/games')
  async findByTitle(
    @param.query.string('title') title: string,
  ): Promise<Games> {
    let game = await this.gameService.findByTitle(title);
    if (!game) {
      // create a new game if it doesn't exist
      game = new Games({
        external: title,
      });
      await this.gamesRepository.create(game);
    }

    return game;
  }

谢谢你的建议

我正在尝试保存数据库游戏名称,如果它缺少 api 数据但它是空的

回答如下:

更多推荐

我正在搜索游戏名称并想从外部 api 获取游戏数据.. 如果游戏名称丢失,请将其保存到数据库

本文发布于:2024-05-13 16:39:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1760123.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:游戏名称   将其   数据库   数据   游戏

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!