For You live streams — backend
For You feed backend endpoint'leri
For You Live Streams - Backend Dokumani
Bu doküman, kullanıcının interests alanina gore kisisellestirilmis yayin listelerini anlatır.
For You alani tek response dönmez; mobil/web tarafinin ayri ayri tuketebilmesi için 3 endpoint vardir.
Endpoint Ozeti
Base path: /api/v1/live-stream
| Alan | Endpoint | Auth | Data tipi |
|---|---|---|---|
| Live | GET /for-you/live | Bearer <JWT> zorunlu | PaginatedResponseDto<LiveStreamResponseDto> |
| Scheduled | GET /for-you/scheduled | Bearer <JWT> zorunlu | PaginatedResponseDto<LiveStreamResponseDto> |
| Crowdfunding | GET /for-you/crowdfunding | Bearer <JWT> zorunlu | PaginatedResponseDto<LiveStreamResponseDto> |
Tüm endpointler Role.USER ile korunur. Kullanıcı onboarding/registration guard'larindan gecmelidir.
Query Parametreleri
Tüm endpointlerde ayni query kullanılır:
page?: number- Default:
1 - Gecersiz veya
0/negatif gelirse backend1olarak normalize eder.
- Default:
limit?: number- Default:
10 - Maksimum:
100 - Gecersiz veya
0/negatif gelirse backend10olarak normalize eder.
- Default:
Ornek:
GET /api/v1/live-stream/for-you/live?page=1&limit=10
Authorization: Bearer <JWT>Response Sozlesmesi
Global interceptor nedeniyle yanitlar BaseResponseDto zarfi ile gelir:
type BaseResponseDto<T> = {
isSuccess: boolean;
statusCode: number;
data: T;
errors?: string[];
timestamp: string;
};Endpointlerin data alani:
type PaginatedResponseDto<T> = {
list: T[];
pagination: {
currentPage: number;
totalPages: number;
totalItems: number;
itemsPerPage: number;
hasNextPage?: boolean;
hasPrevPage?: boolean;
};
};list içindeki item tipi mevcut LiveStreamResponseDto ile aynidir. Onemli alanlar:
type LiveStreamResponseDto = {
id: string;
title: string;
liveStreamType: 'solo' | 'duocrowd' | 'duoself';
channelName: string;
broadcasters: Array<{
user: string;
role: 'host' | 'guest';
uid?: number | null;
hasJoined: boolean;
}>;
guests: UserSummaryDto[];
creator?: UserSummaryDto | null;
thumbnailUrl?: string | null;
recording: boolean;
recordingUrl?: string | null;
status:
| 'active'
| 'scheduled'
| 'preparing'
| 'ended'
| 'expired'
| 'cancelled_by_host'
| 'cancelled_by_guest';
accessType: 'free' | 'paid';
price?: number;
interest: Interest;
durationGoal?: number | null;
motivation?: string | null;
startedAt?: string | null;
plannedStartDate?: string | null;
endedAt?: string | null;
plannedEndDate?: string | null;
fundingGoal?: number | null;
collectedFunding?: number | null;
fundingPercentage?: number | null;
role: 'host' | 'guest' | 'audience' | null;
createdAt: string;
updatedAt: string;
};Kisisellestirme Kurallari
Backend current user kaydini UserRepository.findById(userId) ile okur ve user.interests dizisini kullanir.
- Sadece gecerli
Interestenum degerleri kullanılır. - Duplicate interest degerleri tekillestirilir.
- Kullanıcı bulunamazsa
404 Kullanıcı bulunamadidöner. - Kullanıcı interest listesi bos ise stream query calistirilmaz; bos pagination döner.
- Tüm sorgularda
deletedAt: nullfiltresi uygulanır. - DTO mapping sirasinda
rolealani current user'a gore hesaplanır.
Alan Bazli Filtreler
1) Live
GET /api/v1/live-stream/for-you/live
Filtre:
{
deletedAt: null,
status: 'active',
interest: { $in: user.interests }
}Siralama:
{ startedAt: -1, createdAt: -1 }2) Scheduled
GET /api/v1/live-stream/for-you/scheduled
Bu alan planli ve baslamaya hazir yayinlari gösterir.
Filtre:
{
deletedAt: null,
status: { $in: ['scheduled', 'preparing'] },
interest: { $in: user.interests },
plannedStartDate: { $ne: null },
$or: [
{ liveStreamType: { $ne: 'duocrowd' } },
{
liveStreamType: 'duocrowd',
$expr: {
$gte: [
{ $ifNull: ['$collectedFunding', 0] },
{ $ifNull: ['$fundingGoal', 0] }
]
}
}
]
}Kural:
soloveduoselfplanli yayinlar direkt bu alana girer.duocrowdyayinlar sadece hedefe ulastiysa bu alana girer.
Siralama:
{ plannedStartDate: 1, createdAt: -1 }3) Crowdfunding
GET /api/v1/live-stream/for-you/crowdfunding
Bu alan hedefe ulasmamis DuoCrowd yayinlari gösterir.
Filtre:
{
deletedAt: null,
status: 'scheduled',
liveStreamType: 'duocrowd',
interest: { $in: user.interests },
plannedStartDate: { $ne: null },
$expr: {
$lt: [
{ $ifNull: ['$collectedFunding', 0] },
{ $ifNull: ['$fundingGoal', 0] }
]
}
}Siralama:
{ plannedStartDate: 1, createdAt: -1 }Ornek Response
{
"isSuccess": true,
"statusCode": 200,
"data": {
"list": [
{
"id": "664f0d9e2e6c8f4d5a123456",
"title": "Muzik sohbeti",
"liveStreamType": "solo",
"channelName": "muzik-sohbeti-abc123",
"broadcasters": [],
"guests": [],
"creator": {
"_id": "664f0d9e2e6c8f4d5a999999",
"username": "creator",
"name": "Creator",
"surname": null,
"availabilityStatus": "available",
"profilePhoto": null
},
"thumbnailUrl": "https://s.allminelive.com/interest-covers/interest-example-1.png",
"recording": false,
"recordingUrl": null,
"status": "active",
"accessType": "free",
"price": 0,
"interest": "music",
"durationGoal": null,
"motivation": null,
"startedAt": "2026-05-11T10:00:00.000Z",
"plannedStartDate": null,
"endedAt": null,
"plannedEndDate": null,
"createdAt": "2026-05-11T09:58:00.000Z",
"updatedAt": "2026-05-11T10:00:00.000Z",
"fundingGoal": null,
"collectedFunding": null,
"fundingPercentage": null,
"role": "audience",
"miniCrowdFundings": []
}
],
"pagination": {
"currentPage": 1,
"totalPages": 1,
"totalItems": 1,
"itemsPerPage": 10,
"hasNextPage": false,
"hasPrevPage": false
}
},
"errors": [],
"timestamp": "2026-05-11T10:01:00.000Z"
}Index Notlari
For You sorgulari için LiveStreamSchema tarafında asagidaki indexler vardir:
LiveStreamSchema.index({
deletedAt: 1,
interest: 1,
status: 1,
liveStreamType: 1,
plannedStartDate: 1,
createdAt: -1,
});
LiveStreamSchema.index({
deletedAt: 1,
interest: 1,
status: 1,
startedAt: -1,
createdAt: -1,
});MongoDB autoIndex kapali ortamlarda bu indexlerin migration/ops sureciyle olusturuldugunu kontrol edin.
Test Kapsami
Eklenen testler:
src/live-stream/repository/live-stream.repository.spec.ts- Bos interest listesinde stream query calismamasi
- Live filtre ve siralama
- Scheduled için hedefe ulasmis DuoCrowd kurali
- Crowdfunding için hedefe ulasmamis DuoCrowd kurali
src/live-stream/use-cases/get-for-you-live-streams.usecase.spec.ts- Current user interestlerinin tekillestirilmesi
- Endpointlerin dogru repository metoduna gitmesi
- Interest yoksa bos pagination
- Kullanıcı yoksa
NotFoundException
src/live-stream/live-stream.controller.auth.spec.ts- 3 For You endpointinin
Role.USERauth istemesi
- 3 For You endpointinin
Calistirilan dogrulamalar:
npm test -- --runInBand live-stream.controller.auth.spec.ts live-stream.repository.spec.ts get-for-you-live-streams.usecase.spec.ts
npm run build