Skip to content
This repository was archived by the owner on Dec 4, 2024. It is now read-only.
André devkcud Albanese edited this page Jul 30, 2024 · 3 revisions

👥 User

Esta página é dedicada ao grupo de rotas responsável pelo gerenciamento de usuários.

  • Grupo: /v1/user/:username

  • Exemplos: /v1/user/johndoe/profile, /v1/user/johndoe/followers, ...

  • :username é uma variável na URL. Sendo o nome de usuário que deseja verificar.

Warning

Isso não será explicado novamente: quando houver tipo (string, int etc.) na chave, tal será volátil.
Exemplo:

{
  // Aqui `"string"` será uma chave volátil (poderá mudar, não será fixo). Diferente de `0`, que será seu valor fixo.
  "string": 0
}

Um equivalente em Typescript seria: Record<string, 0> que é o mesmo que { [x: string]: 0 }

GET /profile

Retorno

  • Statuses possíveis: 200, 403, 404, 500
{
  "id": "number",
  "created_at": "date",
  "updated_at": "date",
  "firstname": "string",
  "lastname": "string",
  "username": "string",
  "bio": "string",
  "verified": "boolean",
  "xp": "number",
  "arkhoins": "number",
  "followers": "number",
  "following": "number",
  "notification": {
    "inapp": "1 ou -1", // 1 = True, -1 = False
    "email": "1 ou -1"
  },
  "show": {
    "profile": "1 ou -1",
    "image": "1 ou -1",
    "comments": "1 ou -1",
    "favorites": "1 ou -1",
    "projects": "1 ou -1",
    "components": "1 ou -1",
    "followers": "1 ou -1",
    "following": "1 ou -1",
    "inventory": -"1 ou -1",
    "formations": "1 ou -1"
  }
}
{
  "error": "string"
}

Headers Opcionais

  • Bearer/Authorization (Autenticação JWT)

GET /permissions

Retorno

  • Statuses possíveis: 200, 404, 500
string[]
{
  "error": "string"
}

Headers Obrigatórios

  • Nenhum

GET /followers?page&perpage

Queries URL

  • :page: number - Página atual
  • :perpage: number - Quantidade de itens por página

Retorno

  • Statuses possíveis: 200, 403, 404, 500
{
  "data": [
    {
      "id": "number",
      "created_at": "date",
      "updated_at": "date",
      "firstname": "string",
      "lastname": "string",
      "username": "string",
      "bio": "string",
      "verified": "boolean",
      "xp": "number",
      "arkhoins": "number",
      "followers": "number",
      "following": "number",
      "notification": {
        "inapp": "1 ou -1", // 1 = True, -1 = False
        "email": "1 ou -1"
      },
      "show": {
        "profile": "1 ou -1",
        "image": "1 ou -1",
        "comments": "1 ou -1",
        "favorites": "1 ou -1",
        "projects": "1 ou -1",
        "components": "1 ou -1",
        "followers": "1 ou -1",
        "following": "1 ou -1",
        "inventory": -"1 ou -1",
        "formations": "1 ou -1"
      }
    }
  ],
  "total_records": "number",
  "total_pages": "number",
  "current_page": "number",
  "next_page": "number",
  "previous_page": "number"
}
{
  "error": "string"
}

Headers Opcionais

  • Bearer/Authorization (Autenticação JWT)

GET /following?page&perpage

Queries URL

  • :page: number - Página atual
  • :perpage: number - Quantidade de itens por página

Retorno

  • Statuses possíveis: 200, 403, 404, 500
{
  "data": [
    {
      "id": "number",
      "created_at": "date",
      "updated_at": "date",
      "firstname": "string",
      "lastname": "string",
      "username": "string",
      "bio": "string",
      "verified": "boolean",
      "xp": "number",
      "arkhoins": "number",
      "followers": "number",
      "following": "number",
      "notification": {
        "inapp": "1 ou -1", // 1 = True, -1 = False
        "email": "1 ou -1"
      },
      "show": {
        "profile": "1 ou -1",
        "image": "1 ou -1",
        "comments": "1 ou -1",
        "favorites": "1 ou -1",
        "projects": "1 ou -1",
        "components": "1 ou -1",
        "followers": "1 ou -1",
        "following": "1 ou -1",
        "inventory": -"1 ou -1",
        "formations": "1 ou -1"
      }
    }
  ],
  "total_records": "number",
  "total_pages": "number",
  "current_page": "number",
  "next_page": "number",
  "previous_page": "number"
}
{
  "error": "string"
}

Headers Opcionais

  • Bearer/Authorization (Autenticação JWT)

POST /follow

Retorno

  • Statuses possíveis: 200, 400, 401, 409, 500
{
  "message": "string"
}
{
  "error": "string"
}

Headers Obrigatórios

  • Bearer/Authorization (Autenticação JWT)

POST /unfollow

Retorno

  • Statuses possíveis: 200, 400, 401, 409, 500
{
  "message": "string"
}
{
  "error": "string"
}

Headers Obrigatórios

  • Bearer/Authorization (Autenticação JWT)

📬️ Exemplo de Requisição

Caution

Este exemplo NÃO deve ser usado em ambiente de produção devido à sua origem de demonstração e falta de tratamento de erros.

// Para este exemplo, utilizaremos o pacote `axios`
// que pode ser facilmente instalado via `npm`, `yarn`,
// `pnpm`, `bun` ou similar
//
// Exemplo: `bun i axios`
//
// A tipagem de dados se encontra na seção abaixo, desta Wiki: `RegisterBody`, `Return` etc.

import axios from "axios";

// Definimos uma URL base para todas as nossas operações posteriores
const baseURL = "https://api.swibly.com.br/v1/user";

async function getUserProfile(name: string): Promise<User | null> {
  try {
    const { data } = await axios.get(`${baseURL}/${name}/profile`, {
      // Aqui inserimos o token de acesso do usuário, neste caso não temos nenhuma
      headers: { Authorization: "AUTH.BEARER.TOKEN" },
    });

    return data as User;
  } catch (e) {
    // NOTE: POR FAVOR, em utilização do mundo real, não faça isso...
    return null;
  }
}

console.log((await getUserProfile("andreluis"))?.firstname);
console.log((await getUserProfile("johndoe"))?.firstname);

📄 Tipagem Copy-Paste

type NumericalBoolean = 1 | -1;

type User = {
  id: number;
  created_at: Date;
  updated_at: Date;
  firstname: string;
  lastname: string;
  username: string;
  bio: string;
  verified: boolean;
  xp: number;
  arkhoins: number;
  followers: number;
  following: number;
  notification: {
    inapp: NumericalBoolean;
    email: NumericalBoolean;
  };
  show: {
    profile: NumericalBoolean;
    image: NumericalBoolean;
    comments: NumericalBoolean;
    favorites: NumericalBoolean;
    projects: NumericalBoolean;
    components: NumericalBoolean;
    followers: NumericalBoolean;
    following: NumericalBoolean;
    inventory: NumericalBoolean;
    formations: NumericalBoolean;
  };
};