Skip to content

Commit f207eb4

Browse files
authored
Merge pull request #1080 from peviitor-ro/sebiboga-patch-23
Align random endpoint response with Job Model Schema
2 parents 7186c5a + 9b9f71c commit f207eb4

2 files changed

Lines changed: 83 additions & 6 deletions

File tree

v1/random/README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Random Job Endpoint
2+
3+
**Route:** `GET /v1/random/`
4+
5+
## Description
6+
7+
Returns a single random job from the Solr `job` core. Useful for discovery, widgets, or "job of the day" features.
8+
9+
## How It Works
10+
11+
1. Queries Solr with `q=*:*&rows=0` to get the total number of indexed jobs (`numFound`).
12+
2. Picks a random offset: `start = rand(0, numFound - 1)`.
13+
3. Fetches one document at that offset: `q=*:*&rows=1&start={random}&omitHeader=true`.
14+
4. Returns the job fields mapped to the peviitor Job Model Schema.
15+
16+
## Response Format
17+
18+
### Success (200)
19+
20+
```json
21+
{
22+
"title": "Inginer IT",
23+
"company": "COMPANY SRL",
24+
"location": ["București", "Cluj-Napoca"],
25+
"workmode": "remote",
26+
"url": "https://example.com/job/123",
27+
"salary": "5000-8000 RON",
28+
"tags": ["python", "java"],
29+
"cif": "12345678",
30+
"date": "2026-06-15T10:00:00Z",
31+
"status": "published"
32+
}
33+
```
34+
35+
### No Jobs Found (404)
36+
37+
```json
38+
{
39+
"error": "No jobs found"
40+
}
41+
```
42+
43+
### Service Unavailable (503)
44+
45+
```json
46+
{
47+
"error": "Job core unavailable",
48+
"details": "PROD_SERVER not set"
49+
}
50+
```
51+
52+
## Response Fields
53+
54+
| Field | Type | Description |
55+
|------------|----------|--------------------------------------------------|
56+
| title | string | Job title |
57+
| company | string | Company name (uppercase) |
58+
| location | string[] | Array of cities |
59+
| workmode | string | "remote", "on-site", or "hybrid" |
60+
| url | string | Full URL to the job detail page |
61+
| salary | string | Salary interval with currency (e.g. "5000-8000 RON") |
62+
| tags | string[] | Array of skill tags |
63+
| cif | string | CIF/CUI |
64+
| date | string | ISO8601 UTC timestamp |
65+
| status | string | "scraped", "tested", "published", or "verified" |
66+
67+
## Requirements
68+
69+
- **Method:** `GET` only
70+
- **Environment variables:**
71+
- `PROD_SERVER` — Solr server host
72+
- `SOLR_USER` — Solr basic auth username
73+
- `SOLR_PASS` — Solr basic auth password
74+
- **Dependencies:** `util/loadEnv.php`

v1/random/index.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,16 @@ function fetchJson(string $url, ?string $user = null, ?string $pass = null, int
7171
}
7272

7373
echo json_encode([
74-
'job_title' => $job['title'] ?? null,
74+
'title' => $job['title'] ?? null,
7575
'company' => $job['company'] ?? null,
76-
'city' => $job['location'] ?? [],
77-
'county' => $job['location'] ?? [],
78-
'remote' => $job['workmode'] ?? '',
79-
'job_link' => $job['url'] ?? null,
80-
'id' => md5($job['url'] ?? '')
76+
'location' => $job['location'] ?? [],
77+
'workmode' => $job['workmode'] ?? '',
78+
'url' => $job['url'] ?? null,
79+
'salary' => $job['salary'] ?? null,
80+
'tags' => $job['tags'] ?? [],
81+
'cif' => $job['cif'] ?? '',
82+
'date' => $job['date'] ?? null,
83+
'status' => $job['status'] ?? null,
8184
], JSON_UNESCAPED_UNICODE);
8285

8386
} catch (Exception $e) {

0 commit comments

Comments
 (0)