fix adding and removing favorites

This commit is contained in:
Jonas Heinrich 2020-11-09 10:46:10 +01:00
parent f3a65ae93a
commit 1337754515
3 changed files with 12 additions and 3 deletions

View File

@ -98,7 +98,7 @@ return [
// Api // Api
[ [
'name' => 'station_api#preflighted_cors', 'name' => 'favorite_api#preflighted_cors',
'url' => '/api/0.1/{path}', 'url' => '/api/0.1/{path}',
'verb' => 'OPTIONS', 'verb' => 'OPTIONS',
'requirements' => ['path' => '.+'] 'requirements' => ['path' => '.+']

View File

@ -15,6 +15,8 @@ class FavoriteController extends Controller {
/** @var string */ /** @var string */
private $userId; private $userId;
use Errors;
public function __construct(IRequest $request, public function __construct(IRequest $request,
StationService $service, StationService $service,
$userId) { $userId) {

View File

@ -108,7 +108,7 @@ export default {
await axios await axios
.delete(generateUrl(`/apps/radio/api/favorites/${stationid}`)) .delete(generateUrl(`/apps/radio/api/favorites/${stationid}`))
.then(response => { .then(response => {
this.favorites = this.favorites.filter(item => item !== station.stationuuid) this.favorites = this.favorites.filter(item => item[1] !== station.stationuuid)
}) })
} catch (error) { } catch (error) {
showError(t('radio', 'Could not remove station from favorites')) showError(t('radio', 'Could not remove station from favorites'))
@ -118,7 +118,7 @@ export default {
await axios await axios
.post(generateUrl('/apps/radio/api/favorites'), station) .post(generateUrl('/apps/radio/api/favorites'), station)
.then(response => { .then(response => {
this.favorites.push(station.stationuuid) this.favorites.push([response.data.id, station.stationuuid])
}) })
} catch (error) { } catch (error) {
showError(t('radio', 'Could not favor station')) showError(t('radio', 'Could not favor station'))
@ -230,9 +230,16 @@ export default {
} }
} }
}, },
loadSettings() { loadSettings() {
axios.defaults.headers.common = {
'User-Agent': 'Nextcloud Radio App/1.0', // FIXME: Reference global version number
}
this.$store.dispatch('getVolumeState') this.$store.dispatch('getVolumeState')
}, },
async loadFavorites() { async loadFavorites() {
const vm = this const vm = this
await axios.get(generateUrl('/apps/radio/api/favorites')) await axios.get(generateUrl('/apps/radio/api/favorites'))