Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved the JobController to the API endpoints #587

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
\Movary\Service\Export\ExportService::class => DI\factory([Factory::class, 'createExportService']),
\Movary\HttpController\Api\OpenApiController::class => DI\factory([Factory::class, 'createOpenApiController']),
\Movary\HttpController\Web\CreateUserController::class => DI\factory([Factory::class, 'createCreateUserController']),
\Movary\HttpController\Web\JobController::class => DI\factory([Factory::class, 'createJobController']),
\Movary\HttpController\Api\JobController::class => DI\factory([Factory::class, 'createJobController']),
\Movary\HttpController\Web\LandingPageController::class => DI\factory([Factory::class, 'createLandingPageController']),
\Movary\HttpController\Web\Middleware\ServerHasRegistrationEnabled::class => DI\factory([Factory::class, 'createMiddlewareServerHasRegistrationEnabled']),
\Movary\ValueObject\Http\Request::class => DI\factory([Factory::class, 'createCurrentHttpRequest']),
Expand Down
270 changes: 270 additions & 0 deletions docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,273 @@
}
}
},
"/job-queue": {
"get": {
"tags": [
"Job management"
],
"summary": "Get all jobs of a specific type",
"description": "Get all jobs in the queue with a specific type, triggered by a specific user",
"parameters": [
{
"in": "query",
"name": "type",
"schema": {
"type": "string"
},
"required": true,
"description": "The type of job that's requested"
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "array",
"description": "The response is an array containing all the jobs with a specific type.",
"example": [
{
"type": "job_type",
"status": "in progress",
"userId": 1,
"createdAt": "2023-08-05 16:44:35",
"updatedAt": null
}
]
}
}
}
},
"403": {
"$ref": "#/components/responses/403"
}
},
"security": [
{
"token": []
}
]
},
"delete": {
"tags": [
"Job management"
],
"summary": "Delete all jobs",
"description": "Delete all jobs, regardless of their status",
"parameters": [
{
"in": "query",
"name": "target",
"description": "Which jobs to delete. It can be either 'all' (meaning that all jobs would be deleted) or 'processed' (meaning only the jobs that have finished running will be deleted). It defaults to 'all'.",
"examples": {
"all": {
"target": "all"
},
"processed": {
"target": "processed"
}
}
}
],
"responses": {
"204": {
"$ref": "#/components/responses/204"
},
"403": {
"$ref": "#/components/responses/403"
}
},
"security": [
{
"token": []
}
]
}
},
"/job-queue/schedule/trakt-history-sync": {
"post": {
"tags": [
"Job management"
],
"summary": "Schedule a movie history import from Trakt.tv",
"description": "Schedule a job to import all watched movies from Trakt.tv, if the user has set Trakt.tv credentials in the settings.",
"responses": {
"204": {
"$ref": "#/components/responses/204-jobs"
},
"403": {
"$ref": "#/components/responses/403"
}
},
"security": [
{
"token": []
}
]
}
},
"/job-queue/schedule/trakt-ratings-sync": {
"post": {
"tags": [
"Job management"
],
"summary": "Schedule a ratings import from Trakt.tv",
"description": "Schedule a job to import all ratings of movies from Trakt.tv, if the user has set Trakt.tv credentials in the settings.",
"responses": {
"204": {
"$ref": "#/components/responses/204-jobs"
},
"403": {
"$ref": "#/components/responses/403"
}
},
"security": [
{
"token": []
}
]
}
},
"/job-queue/schedule/letterboxd-diary-sync": {
"post": {
"tags": [
"Job management"
],
"summary": "Schedule a diary import from Letterboxd",
"description": "Schedule a job to upload and import all diary data from Letterboxd",
"requestBody": {
"content": {
"text/csv": {
"schema": {
"type": "string",
"name": "letterboxdDiaryCsv",
"description": "The file of the letterboxd diary. It has to be in sent in a form parameter named 'letterboxdDiaryCsv', otherwise the request will fail."
}
}
}
},
"responses": {
"204": {
"$ref": "#/components/responses/204-jobs"
},
"400": {
"description": "An invalid Letterboxd diary has been uploaded or no file was uploaded"
},
"403": {
"$ref": "#/components/responses/403"
}
},
"security": [
{
"token": []
}
]
}
},
"/job-queue/schedule/letterboxd-ratings-sync": {
"post": {
"tags": [
"Job management"
],
"summary": "Schedule a rating import from Letterboxd",
"description": "Schedule a job to upload and import all rating data from Letterboxd",
"requestBody": {
"content": {
"text/csv": {
"schema": {
"type": "string",
"name": "letterboxdRatingsCsv",
"description": "The file of the letterboxd ratings. It has to be in sent in a form parameter named 'letterboxdRatingsCsv', otherwise the request will fail."
}
}
}
},
"responses": {
"204": {
"$ref": "#/components/responses/204-jobs"
},
"400": {
"description": "An invalid Letterboxd ratings file been uploaded or no file was uploaded"
},
"403": {
"$ref": "#/components/responses/403"
}
},
"security": [
{
"token": []
}
]
}
},
"/job-queue/schedule/plex-watchlist-sync": {
"post": {
"tags": [
"Job management"
],
"summary": "Schedule a job to import the watchlist from Plex.",
"description": "Schedule a job to import all movies from Plex's watchlist into Movary's watchlist",
"responses": {
"204": {
"$ref": "#/components/responses/204-jobs"
},
"403": {
"$ref": "#/components/responses/403"
}
},
"security": [
{
"token": []
}
]
}
},
"/job-queue/schedule/jellyfin-import-history": {
"post": {
"tags": [
"Job management"
],
"summary": "Schedule a job to import the watch history from Jellyfin.",
"description": "Schedule a job to import all watched movies from Jellyfin",
"responses": {
"204": {
"$ref": "#/components/responses/204-jobs"
},
"403": {
"$ref": "#/components/responses/403"
}
},
"security": [
{
"token": []
}
]
}
},
"/job-queue/schedule/jellyfin-export-history": {
"post": {
"tags": [
"Job management"
],
"summary": "Schedule a job to export the watch history to Jellyfin.",
"description": "Schedule a job to export all watched movies from Movary into Jellyfin",
"responses": {
"204": {
"$ref": "#/components/responses/204-jobs"
},
"403": {
"$ref": "#/components/responses/403"
}
},
"security": [
{
"token": []
}
]
}
},
"/authentication/token": {
"get": {
"tags": [
Expand Down Expand Up @@ -1417,6 +1684,9 @@
"204": {
"description": "Successful operation, response has no content"
},
"204-jobs": {
"description": "No response content. The job has been scheduled, but it hasn't necessarily already started running."
},
"400": {
"description": "The request payload or header are not correct",
"content": {
Expand Down
2 changes: 1 addition & 1 deletion public/js/component/modal-job.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function setJobModalTitle(jobType) {

async function fetchJobs(jobType) {

const response = await fetch('/jobs?type=' + jobType)
const response = await fetch('/api/job-queue?type=' + jobType)

if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`)
Expand Down
4 changes: 2 additions & 2 deletions public/js/settings-integration-jellyfin.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ async function updateSyncOptions() {

async function exportJellyfin() {
const response = await fetch(
'/jobs/schedule/jellyfin-export-history',
'/api/job-queue/schedule/jellyfin-export-history',
{'method': 'get'}
).catch(function (error) {
addAlert('alertJellyfinExportHistoryDiv', 'History export could not be scheduled', 'danger')
Expand Down Expand Up @@ -296,7 +296,7 @@ async function exportJellyfin() {

async function importJellyfin() {
const response = await fetch(
'/jobs/schedule/jellyfin-import-history',
'/api/job-queue/schedule/jellyfin-import-history',
{'method': 'get'}
).catch(function (error) {
addAlert('alertJellyfinImportHistoryDiv', 'History import could not be scheduled', 'danger')
Expand Down
36 changes: 36 additions & 0 deletions public/js/settings-integration-letterboxd.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,39 @@ function toggleTableVisibility() {
document.getElementById('showImportTableButton').disabled = true
console.log(document.getElementById('showImportTableButton').marginBottom)
}

async function triggerLetterboxdDiaryImport() {
let requestFormData = new FormData();
requestFormData.append('letterboxdDiaryCsv', document.getElementById('letterboxdDiaryCsv').files[0]);
await fetch('/api/job-queue/schedule/letterboxd-diary-sync', {
method: 'POST', body: requestFormData
}).then(response => {
if(response.ok) {
addAlert('letterboxdImportDiaryResponse', 'History import scheduled', 'success', true, 0);
} else {
return response.json();
}
}).then(jsonresponse => {
if(jsonresponse !== null) {
addAlert('letterboxdImportDiaryResponse', jsonresponse['message'], 'danger', true, 0);
}
});
}

async function triggerLetterboxdRatingsImport() {
let requestFormData = new FormData();
requestFormData.append('letterboxdDiaryCsv', document.getElementById('letterboxdRatingsCsv').files[0]);
await fetch('/api/job-queue/schedule/letterboxd-ratings-sync', {
method: 'POST', body: requestFormData
}).then(response => {
if(response.ok) {
addAlert('letterboxdImportResponse', 'Ratings import scheduled', 'success', true, 0);
} else {
return response.json();
}
}).then(jsonresponse => {
if(jsonresponse !== null) {
addAlert('letterboxdImportResponse', jsonresponse['message'], 'danger', true, 0);
}
});
}
2 changes: 1 addition & 1 deletion public/js/settings-integration-plex.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ document.getElementById('plexServerUrlInput').addEventListener('input', function

async function importPlexWatchlist() {
const response = await fetch(
'/jobs/schedule/plex-watchlist-sync',
'/api/job-queue/schedule/plex-watchlist-sync',
{'method': 'get'}
).catch(function (error) {
addAlert('alertPlexWatchlistImportDiv', 'Watchlist import could not be scheduled', 'danger')
Expand Down
20 changes: 20 additions & 0 deletions public/js/settings-integration-trakt.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,23 @@ function toggleTableVisibility() {
document.getElementById('importTable').classList.remove('d-none')
document.getElementById('showImportTableButton').disabled = true
}

async function triggerTraktImportRatings(){
await fetch('/api/job-queue/schedule/trakt-ratings-sync', {
method: 'POST',
}).then(response => {
if(response.ok) {
addAlert('#traktScheduleRatingsResponse', 'Ratings import scheduled', 'success', true, 0);
}
})
}

async function triggerTraktImportHistory(){
await fetch('/api/job-queue/schedule/trakt-history-sync', {
method: 'POST',
}).then(response => {
if(response.ok) {
addAlert('#traktScheduleRatingsResponse', 'Ratings import scheduled', 'success', true, 0);
}
})
}
Loading
Loading