Seguimientos
Endpoints para gestionar relaciones de seguimiento entre usuarios.
Modelos de Datos
Section titled “Modelos de Datos”El siguiente modelo de Prisma pertenece al schema social:
Follow
Section titled “Follow”model Follow { id String @id @default(cuid()) followerId String @map("follower_id") followingId String @map("following_id")
follower UserProfile @relation("UserFollows", fields: [followerId], references: [id], onDelete: Cascade) following UserProfile @relation("UserFollowers", fields: [followingId], references: [id], onDelete: Cascade)
createdAt DateTime @default(now()) @map("created_at")
@@unique([followerId, followingId]) @@map("follows") @@schema("social")}Endpoints
Section titled “Endpoints”Seguir Usuario
Section titled “Seguir Usuario”Seguir a otro usuario.
- URL:
/api/v1/social/follow - Método:
POST - Autenticación Requerida: Sí
Descripción Interna
Section titled “Descripción Interna”Este endpoint crea una relación de seguimiento:
-
Validaciones:
- No puede seguirse a sí mismo: “No puedes seguirte a ti mismo”
- El usuario a seguir debe existir: “Usuario no encontrado”
- No debe estar siguiendo ya al usuario: “Ya sigues a este usuario”
-
Crea Follow con:
- followerId: Usuario autenticado
- followingId: Usuario a seguir
-
Retorna el follow con información del usuario seguido
Cuerpo de Solicitud
Section titled “Cuerpo de Solicitud”{ "followingId": "user_id_to_follow"}Ejemplo de Cliente Hono
Section titled “Ejemplo de Cliente Hono”import { hcWithType } from '@vitality-gym/api/client'
const client = hcWithType('http://localhost:3000')
const res = await client.api.v1.social.follow.$post({ json: { followingId: 'user_id_to_follow' }})Dejar de Seguir Usuario
Section titled “Dejar de Seguir Usuario”Dejar de seguir a un usuario.
- URL:
/api/v1/social/follow/:id - Método:
DELETE - Autenticación Requerida: Sí
Descripción Interna
Section titled “Descripción Interna”Este endpoint elimina una relación de seguimiento:
- Busca Follow con compound key (followerId + followingId)
- Si no existe: Lanza error “No sigues a este usuario”
- Si existe: Elimina el registro Follow
Ejemplo de Cliente Hono
Section titled “Ejemplo de Cliente Hono”import { hcWithType } from '@vitality-gym/api/client'
const client = hcWithType('http://localhost:3000')
const res = await client.api.v1.social.follow[':id'].$delete({ param: { id: 'user_id_to_unfollow' }})Obtener Seguidores
Section titled “Obtener Seguidores”Obtener lista de seguidores de un usuario.
- URL:
/api/v1/social/followers/:userId - Método:
GET - Autenticación Requerida: Sí
Descripción Interna
Section titled “Descripción Interna”Este endpoint obtiene los seguidores de un usuario:
- Busca Follows donde
followingId= userId - Incluye información del follower (id, name)
- Ordena por createdAt descendente (más recientes primero)
Respuesta
Section titled “Respuesta”{ "data": [ { "id": "...", "createdAt": "2023-10-27T10:00:00Z", "follower": { "id": "...", "name": "Jane Doe" } } ], "pagination": {...}}Obtener Siguiendo
Section titled “Obtener Siguiendo”Obtener lista de usuarios que sigue.
- URL:
/api/v1/social/following/:userId - Método:
GET - Autenticación Requerida: Sí
Descripción Interna
Section titled “Descripción Interna”Este endpoint obtiene a quiénes sigue un usuario:
- Busca Follows donde
followerId= userId - Incluye información del following (id, name)
- Ordena por createdAt descendente
Respuesta
Section titled “Respuesta”{ "data": [ { "id": "...", "createdAt": "2023-10-27T10:00:00Z", "following": { "id": "...", "name": "John Doe" } } ], "pagination": {...}}Verificar Status de Seguimiento
Section titled “Verificar Status de Seguimiento”Verificar si el usuario actual sigue a otro usuario.
- URL:
/api/v1/social/follow/status/:userId - Método:
GET - Autenticación Requerida: Sí
Respuesta
Section titled “Respuesta”{ "data": { "isFollowing": true }}Obtener Estadísticas Sociales del Usuario
Section titled “Obtener Estadísticas Sociales del Usuario”Obtener estadísticas sociales para un usuario.
- URL:
/api/v1/social/stats/:userId - Método:
GET - Autenticación Requerida: Sí
Descripción Interna
Section titled “Descripción Interna”Este endpoint calcula estadísticas sociales:
-
Ejecuta 4 consultas en transacción:
- Conteo de posts del usuario
- Conteo de seguidores
- Conteo de seguidos
- Conteo de likes recibidos en sus posts
-
Retorna objeto con las estadísticas
Respuesta
Section titled “Respuesta”{ "data": { "postsCount": 15, "followersCount": 120, "followingCount": 85, "likesReceived": 350 }}