Skip to content

Commit 92f962b

Browse files
committed
dont show people with no pictures
1 parent 7aa5ded commit 92f962b

File tree

7 files changed

+23
-8
lines changed

7 files changed

+23
-8
lines changed

init.sql

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ CREATE TABLE IF NOT EXISTS users (
1212
height INT,
1313
tags VARCHAR(255),
1414
bio TEXT,
15+
nb_photos INT DEFAULT 0,
1516
location VARCHAR(255),
1617
city VARCHAR(255),
1718
friends VARCHAR(255),

src/app/api/matcha/newGrid/route.ts

+4
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ export async function POST(req: NextRequest) {
194194
FROM unnest(string_to_array(u.tags, ',')) AS user_tag
195195
WHERE user_tag = ANY($8::text[])
196196
)
197+
AND u.nb_photos > 0
197198
) AS matched_users
198199
${sortCondition}
199200
LIMIT $2
@@ -239,6 +240,7 @@ export async function POST(req: NextRequest) {
239240
FROM unnest(string_to_array(u.tags, ',')) AS user_tag
240241
WHERE user_tag = ANY($7::text[])
241242
)
243+
AND u.nb_photos > 0
242244
) AS matched_users
243245
${sortCondition}
244246
LIMIT $2
@@ -279,6 +281,7 @@ export async function POST(req: NextRequest) {
279281
${alreadySelectedIds ? `AND u.id NOT IN (${alreadySelectedIds.join(',')})` : ''}
280282
${genderCondition}
281283
AND (u.fame BETWEEN $8 AND $9)
284+
AND u.nb_photos > 0
282285
) AS matched_users
283286
${sortCondition}
284287
LIMIT $2
@@ -315,6 +318,7 @@ export async function POST(req: NextRequest) {
315318
${alreadySelectedIds ? `AND u.id NOT IN (${alreadySelectedIds.join(',')})` : ''}
316319
${genderCondition}
317320
AND (u.fame BETWEEN $9 AND $10)
321+
AND u.nb_photos > 0
318322
) AS matched_users
319323
${sortCondition}
320324
LIMIT $2

src/app/api/users/deletePicture/route.ts

+5
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ export async function POST(req: NextRequest) {
8282
};
8383
})
8484

85+
await pool.query(
86+
'UPDATE users SET nb_photos = nb_photos - 1 WHERE id = $1',
87+
[userId]
88+
);
89+
8590
return NextResponse.json(filesReturn, { status: 200 });
8691
} catch (error: any) {
8792
if (error.code === 'ENOENT') {

src/app/api/users/downloadGooglePhotos/route.ts

+6-8
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ import { NextRequest, NextResponse } from 'next/server';
22
import fs from 'fs/promises';
33
import path from 'path';
44
import { CryptoService } from '@/server/CryptoService';
5+
import pool from '@/server/db';
56

67
export async function POST(req: NextRequest) {
78
try {
8-
// Ensure the request has a body
99
if (!req.body) {
1010
return NextResponse.json({ error: 'Missing body' }, { status: 400 });
1111
}
1212

13-
// Parse the incoming request body
1413
const { photoUrl, encryptedUserId } = await req.json();
1514

1615
if (!photoUrl || !encryptedUserId) {
@@ -20,7 +19,6 @@ export async function POST(req: NextRequest) {
2019
);
2120
}
2221

23-
// Decrypt user ID from encryptedUserId (reuse your existing CryptoService)
2422
const cryptedUserId = encryptedUserId.split('.');
2523
const cryptedKeyUserId = { encryptedText: cryptedUserId[0], iv: cryptedUserId[1] };
2624

@@ -31,11 +29,9 @@ export async function POST(req: NextRequest) {
3129
return NextResponse.json({ error: 'Invalid User ID' }, { status: 400 });
3230
}
3331

34-
// Create user-specific directory for downloaded images
3532
const downloadPath = path.join(process.cwd(), 'public', 'profileImages', String(userId));
3633
await fs.mkdir(downloadPath, { recursive: true });
3734

38-
// Fetch the photo data from the given URL
3935
const response = await fetch(photoUrl);
4036
if (!response.ok) {
4137
return NextResponse.json(
@@ -44,18 +40,20 @@ export async function POST(req: NextRequest) {
4440
);
4541
}
4642

47-
// Extract file type and name from headers or URL
4843
const contentType = response.headers.get('Content-Type') || 'image/jpeg';
4944
const fileExtension = contentType.split('/')[1] || 'jpg';
5045
const now = Date.now();
5146
const fileName = `${now}_google_photo.${fileExtension}`;
5247
const filePath = path.join(downloadPath, fileName);
5348

54-
// Write the photo data to the file system
5549
const buffer = await response.arrayBuffer();
5650
await fs.writeFile(filePath, Buffer.from(buffer));
5751

58-
// Return success response with the saved file path
52+
await pool.query(
53+
'UPDATE users SET nb_photos = nb_photos + 1 WHERE id = $1',
54+
[userId]
55+
);
56+
5957
return NextResponse.json({
6058
message: 'Photo downloaded and saved successfully!',
6159
path: `/profileImages/${userId}/${fileName}`,

src/app/api/users/getUserInfos/route.ts

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export async function POST(req: NextRequest) {
7979
goal: user.rows[0].goal,
8080
height: user.rows[0].height,
8181
bio: user.rows[0].bio,
82+
nb_photos: user.rows[0].nb_photos,
8283
location: user.rows[0].location,
8384
friends: friends,
8485
locationAccess: user.rows[0].locationaccess,

src/app/api/users/uploadPicture/route.ts

+5
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ export async function POST(req: NextRequest) {
8080

8181
await fs.writeFile(filePath, Buffer.from(fileBuffer));
8282

83+
await pool.query(
84+
'UPDATE users SET nb_photos = nb_photos + 1 WHERE id = $1',
85+
[userId]
86+
);
87+
8388
return NextResponse.json({
8489
message: 'File uploaded successfully!',
8590
path: filePath,

src/types/user.ts

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface UserResponse {
1010
goal: string;
1111
height: number;
1212
bio: string;
13+
nb_photos: number;
1314
location: string;
1415
friends: string;
1516
locationAccess: boolean;

0 commit comments

Comments
 (0)