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

Added DELETE method for deleting an episode to the apiv2. #5685

Merged
merged 9 commits into from
Nov 12, 2018
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#### Improvements
- Vueified "config - notifications" page. Improved components: config-textbox, select-list, show-selector, config-textbox-number. Improved responsiveness of the notification page on smaller screens ([#4913](https://github.com/pymedusa/Medusa/pull/4913))
- Allow the use of priorities in the Pushover notifier ([#5567](https://github.com/pymedusa/Medusa/pull/5567))
- Add delete method to EpisodeHandler (apiv2), for deleting a single episode ([#5685](https://github.com/pymedusa/Medusa/pull/5685))

#### Fixes
- Fixed test not working for Download Station ([#5561](https://github.com/pymedusa/Medusa/pull/5561))
Expand Down
35 changes: 35 additions & 0 deletions dredd/api-description.yml
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,34 @@ paths:
{"status": 2, "quality": 4}
path-params:
id: e999
delete:
summary: Delete a specific episode from a given series
description: Delete a specific episode from a given series
parameters:
- $ref: '#/parameters/series-id'
name: seriesid
- $ref: '#/parameters/episode-id-delete'
name: id
responses:
204:
description: Episode is deleted successfully
400:
$ref: '#/responses/error'
description: Invalid id
x-request:
path-params:
seriesid: tvdb301824
id: 123456
404:
$ref: '#/responses/error'
description: Episode not found
x-request:
path-params:
seriesid: tvdb301824
id: s9999e9999
409:
$ref: '#/responses/error'
description: Unable to delete episode
/series/{seriesid}/episodes/{id}/{field}:
get:
summary: Return a specific field from a given episode
Expand Down Expand Up @@ -2342,6 +2370,13 @@ parameters:
description: The episode id to retrieve. E.g. s02e03, e34 or 2016-12-31
x-example: s01e01
type: string
episode-id-delete:
name: episode-id
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this also need -delete?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was an attempt to get the dredd test working.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I mean is the ones above all have it matching with their name where as this one is missing the -delete. Might be related.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh like that, i dont think the name makes any difference.

in: path
required: true
description: The episode id to retrieve. E.g. s02e03, e34 or 2016-12-31
x-example: s01e02
type: string
alias-id:
name: alias-id
in: path
Expand Down
31 changes: 30 additions & 1 deletion medusa/server/api/v2/episodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import logging

from medusa.helper.exceptions import EpisodeDeletedException
from medusa.logger.adapters.style import BraceAdapter
from medusa.server.api.v2.base import (
BaseRequestHandler,
Expand Down Expand Up @@ -36,7 +37,7 @@ class EpisodeHandler(BaseRequestHandler):
#: path param
path_param = ('path_param', r'\w+')
#: allowed HTTP methods
allowed_methods = ('GET', 'PATCH', )
allowed_methods = ('GET', 'PATCH', 'DELETE',)

def http_get(self, series_slug, episode_slug, path_param):
"""Query episode information.
Expand Down Expand Up @@ -156,3 +157,31 @@ def _patch_episode(episode, data):
)

return accepted

def http_delete(self, series_slug, episode_slug, **kwargs):
"""Delete the episode."""
if not series_slug:
return self._method_not_allowed('Deleting multiple series are not allowed')

identifier = SeriesIdentifier.from_slug(series_slug)
if not identifier:
return self._bad_request('Invalid series identifier')

series = Series.find_by_identifier(identifier)
if not series:
return self._not_found('Series not found')

episode_number = EpisodeNumber.from_slug(episode_slug)
if not episode_number:
return self._bad_request('Invalid episode number')

episode = Episode.find_by_series_and_episode(series, episode_number)
if not episode:
return self._not_found('Episode not found')

try:
episode.delete_episode()
except EpisodeDeletedException:
return self._no_content()
else:
return self._conflict('Unable to delete episode')