complete Album + AlbumRating store
parent
58655e1086
commit
14ce07b9ab
|
|
@ -0,0 +1,19 @@
|
||||||
|
import types from './types'
|
||||||
|
|
||||||
|
const getAll = item => ({
|
||||||
|
type: types.GET_ALL, item
|
||||||
|
})
|
||||||
|
|
||||||
|
const getOne = item => ({
|
||||||
|
type: types.GET_ONE, item
|
||||||
|
})
|
||||||
|
|
||||||
|
const getRatings = item => ({
|
||||||
|
rype: types.GET_RATINGS, item
|
||||||
|
})
|
||||||
|
|
||||||
|
export default {
|
||||||
|
getAll,
|
||||||
|
getOne,
|
||||||
|
getRatings
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,71 @@
|
||||||
|
import AppService from '../../AppService'
|
||||||
|
|
||||||
|
import actions from './actions'
|
||||||
|
|
||||||
|
const endpoint = 'album/'
|
||||||
|
|
||||||
|
// Album CRUD
|
||||||
|
|
||||||
|
export const getAllAlbum = () => async (dispatch) => {
|
||||||
|
return await AppService._getList(
|
||||||
|
endpoint
|
||||||
|
).then( response => {
|
||||||
|
dispatch( actions.getAll( response ) )
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getOneAlbum = (id) => async( dispatch ) => {
|
||||||
|
return await AppService._getOne(
|
||||||
|
endpoint + id
|
||||||
|
).then( response => {
|
||||||
|
dispatch( actions.getOne( response ) )
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export const createAlbum = async (album, token) => {
|
||||||
|
return await AppService._post(
|
||||||
|
endpoint,
|
||||||
|
album,
|
||||||
|
token
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const updateAlbum = async (album, token) => {
|
||||||
|
return await AppService._patch(
|
||||||
|
endpoint,
|
||||||
|
album,
|
||||||
|
token
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const deleteAlbum = async (id, token) => {
|
||||||
|
return await AppService._delete(
|
||||||
|
endpoint + id,
|
||||||
|
token
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Album Ratings CRUD
|
||||||
|
|
||||||
|
export const getAllAlbumRating = (id) => async ( dispatch ) => {
|
||||||
|
return await AppService._getList(
|
||||||
|
endpoint + id + '/ratings/'
|
||||||
|
).then( response => {
|
||||||
|
dispatch( actions.getRatings( response ) )
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export const createAlbumRating = (album_id, rating, token) => async ( dispatch ) => {
|
||||||
|
return await AppService._post(
|
||||||
|
endpoint + album_id + '/rating/',
|
||||||
|
rating,
|
||||||
|
token
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const deleteAlbumRating = (album_id, rating_id, token) => async ( dispatch ) => {
|
||||||
|
return await AppService._delete(
|
||||||
|
endpoint + album_id + '/rating/' + rating_id,
|
||||||
|
token
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,51 @@
|
||||||
|
import types from './types'
|
||||||
|
|
||||||
|
const INITIAL_STATE = {
|
||||||
|
actualAlbum: {
|
||||||
|
id: -1,
|
||||||
|
user_id: -1,
|
||||||
|
title: '',
|
||||||
|
description: '',
|
||||||
|
image: '',
|
||||||
|
url_code: '',
|
||||||
|
tracks: [],
|
||||||
|
ratings: []
|
||||||
|
},
|
||||||
|
albums: []
|
||||||
|
}
|
||||||
|
|
||||||
|
const albumReducer = ( state = INITIAL_STATE, action ) => {
|
||||||
|
switch(action.type) {
|
||||||
|
case types.GET_ALL:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
albums: action.item
|
||||||
|
}
|
||||||
|
case types.GET_ONE:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
actualAlbum: {
|
||||||
|
...state.actualAlbum,
|
||||||
|
id: action.item.id,
|
||||||
|
user_id: action.item.user_id,
|
||||||
|
title: action.item.title,
|
||||||
|
description: action.item.description,
|
||||||
|
image: action.item.image,
|
||||||
|
url_code: action.item.url_code,
|
||||||
|
tracks: action.item.tracks,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case types.GET_RATINGS:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
actualAlbum: {
|
||||||
|
...state.actualAlbum,
|
||||||
|
ratings: action.item
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return state
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default albumReducer
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
const GET_ALL = 'GET_ALL'
|
||||||
|
const GET_ONE = 'GET_ONE'
|
||||||
|
const GET_RATINGS = 'GET_RATINGS'
|
||||||
|
|
||||||
|
export default ({
|
||||||
|
GET_ALL,
|
||||||
|
GET_ONE,
|
||||||
|
GET_RATINGS
|
||||||
|
})
|
||||||
|
|
@ -60,7 +60,7 @@ export const deleteAuth = (token) => async (dispatch) => {
|
||||||
|
|
||||||
export const registerUser = async (user) => {
|
export const registerUser = async (user) => {
|
||||||
response = await AppService._post(
|
response = await AppService._post(
|
||||||
this.endpoint,
|
endpoint,
|
||||||
user,
|
user,
|
||||||
AppService.defaultToken
|
AppService.defaultToken
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue