This repository was archived by the owner on Dec 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
User
André devkcud Albanese edited this page Jul 30, 2024
·
3 revisions
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:
Um equivalente em Typescript seria: Record<string, 0> que é o mesmo que { [x: string]: 0 }
- 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"
}- Bearer/Authorization (Autenticação JWT)
- Statuses possíveis:
200,404,500
string[]{
"error": "string"
}- Nenhum
-
:page:number- Página atual -
:perpage:number- Quantidade de itens por página
- 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"
}- Bearer/Authorization (Autenticação JWT)
-
:page:number- Página atual -
:perpage:number- Quantidade de itens por página
- 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"
}- Bearer/Authorization (Autenticação JWT)
- Statuses possíveis:
200,400,401,409,500
{
"message": "string"
}{
"error": "string"
}- Bearer/Authorization (Autenticação JWT)
- Statuses possíveis:
200,400,401,409,500
{
"message": "string"
}{
"error": "string"
}- Bearer/Authorization (Autenticação JWT)
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);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;
};
};
{ // Aqui `"string"` será uma chave volátil (poderá mudar, não será fixo). Diferente de `0`, que será seu valor fixo. "string": 0 }