diff --git a/apiGo/api/Video.go b/apiGo/api/Video.go index 3ca7de7..4412bc4 100644 --- a/apiGo/api/Video.go +++ b/apiGo/api/Video.go @@ -22,11 +22,12 @@ func getVideoHandlers() { * @apiName GetMovies * @apiGroup video * - * @apiParam {int} [Tag=all] id of VideoTag to get videos + * @apiParam {int} [Tag=1] id of VideoTag to get videos (1=all) * - * @apiSuccess {Object[]} . List of Videos - * @apiSuccess {number} .MovieId Id of Video - * @apiSuccess {String} .MovieName Name of video + * @apiSuccess {Object[]} Videos List of Videos + * @apiSuccess {number} Videos.MovieId Id of Video + * @apiSuccess {String} Videos.MovieName Name of video + * @apiSuccess {String} TagName Name of the Tag returned */ AddHandler("getMovies", VideoNode, func(info *HandlerInfo) []byte { var args struct { @@ -40,16 +41,42 @@ func getVideoHandlers() { var query string // 1 is the id of the ALL tag if args.Tag != 1 { - query = fmt.Sprintf(`SELECT movie_id,movie_name FROM videos + query = fmt.Sprintf(`SELECT movie_id,movie_name,t.tag_name FROM videos INNER JOIN video_tags vt on videos.movie_id = vt.video_id INNER JOIN tags t on vt.tag_id = t.tag_id - WHERE t.tag_id = '%d' + WHERE t.tag_id = %d ORDER BY likes DESC, create_date, movie_name`, args.Tag) } else { - query = "SELECT movie_id,movie_name FROM videos ORDER BY create_date DESC, movie_name" + query = "SELECT movie_id,movie_name, (SELECT 'All' as tag_name) FROM videos ORDER BY create_date DESC, movie_name" } - result := readVideosFromResultset(database.Query(query)) + var result struct { + Videos []types.VideoUnloadedType + TagName string + } + + rows := database.Query(query) + vids := []types.VideoUnloadedType{} + var name string + for rows.Next() { + var vid types.VideoUnloadedType + err := rows.Scan(&vid.MovieId, &vid.MovieName, &name) + if err != nil { + return nil + } + vids = append(vids, vid) + } + if rows.Close() != nil { + return nil + } + + // if the tag id doesn't exist the query won't return a name + if name == "" { + return nil + } + + result.Videos = vids + result.TagName = name // jsonify results str, _ := json.Marshal(result) return str diff --git a/src/pages/ActorPage/ActorPage.tsx b/src/pages/ActorPage/ActorPage.tsx index 3899873..0672228 100644 --- a/src/pages/ActorPage/ActorPage.tsx +++ b/src/pages/ActorPage/ActorPage.tsx @@ -72,6 +72,10 @@ export class ActorPage extends React.Component { data: result.Videos ? result.Videos : [], actor: result.Info }); + }, + (_) => { + // if there is an load error redirect to home page + this.props.history.push('/'); } ); } diff --git a/src/pages/CategoryPage/CategoryView.test.js b/src/pages/CategoryPage/CategoryView.test.js index 2fbcde2..583df8a 100644 --- a/src/pages/CategoryPage/CategoryView.test.js +++ b/src/pages/CategoryPage/CategoryView.test.js @@ -4,7 +4,9 @@ import {CategoryView} from './CategoryView'; describe('', function () { function instance() { - return shallow(); + const inst = shallow(); + inst.setState({loaded: true}); + return inst; } it('renders without crashing ', function () { diff --git a/src/pages/CategoryPage/CategoryView.tsx b/src/pages/CategoryPage/CategoryView.tsx index 16cd655..1ac5de9 100644 --- a/src/pages/CategoryPage/CategoryView.tsx +++ b/src/pages/CategoryPage/CategoryView.tsx @@ -10,12 +10,14 @@ import Tag from '../../elements/Tag/Tag'; import {DefaultTags, GeneralSuccess} from '../../types/GeneralTypes'; import {Button} from '../../elements/GPElements/Button'; import SubmitPopup from '../../elements/Popups/SubmitPopup/SubmitPopup'; +import {Spinner} from 'react-bootstrap'; interface CategoryViewProps extends RouteComponentProps<{id: string}> {} interface CategoryViewState { loaded: boolean; submitForceDelete: boolean; + TagName: string; } /** @@ -29,7 +31,8 @@ export class CategoryView extends React.Component; + } + return ( <> - + Default Tags: @@ -105,10 +112,18 @@ export class CategoryView extends React.Component(APINode.Video, {action: 'getMovies', Tag: id}, (result) => { - this.videodata = result; - this.setState({loaded: true}); - }); + callAPI( + APINode.Video, + {action: 'getMovies', Tag: id}, + (result: {Videos: VideoTypes.VideoUnloadedType[]; TagName: string}) => { + this.videodata = result.Videos; + this.setState({loaded: true, TagName: result.TagName}); + }, + (_) => { + // if there is an load error redirect to home page + this.props.history.push('/'); + } + ); } /** diff --git a/src/pages/HomePage/HomePage.test.js b/src/pages/HomePage/HomePage.test.js index aa8abe2..ff493b4 100644 --- a/src/pages/HomePage/HomePage.test.js +++ b/src/pages/HomePage/HomePage.test.js @@ -23,23 +23,6 @@ describe('', function () { expect(wrapper.find('PageTitle').props().subtitle).toBe('testsubtitle - 42'); }); - it('test search field', done => { - global.fetch = global.prepareFetchApi([{}, {}]); - - const wrapper = shallow(); - - wrapper.find('[data-testid="searchtextfield"]').simulate('change', {target: {value: 'testvalue'}}); - wrapper.find('[data-testid="searchbtnsubmit"]').simulate('click'); - - process.nextTick(() => { - // state to be set correctly with response - expect(wrapper.state().selectionnr).toBe(2); - - global.fetch.mockClear(); - done(); - }); - }); - it('test form submit', () => { const func = jest.fn(); const wrapper = shallow(); @@ -72,7 +55,7 @@ describe('', function () { }); it('test tag click', done => { - global.fetch = prepareFetchApi(['test1', 'test2']); + global.fetch = prepareFetchApi({Videos: ['test1', 'test2'], TagName: 'all'}); const wrapper = shallow(); diff --git a/src/pages/HomePage/HomePage.tsx b/src/pages/HomePage/HomePage.tsx index c191725..21ce863 100644 --- a/src/pages/HomePage/HomePage.tsx +++ b/src/pages/HomePage/HomePage.tsx @@ -59,15 +59,19 @@ export class HomePage extends React.Component { * @param tag tag to fetch videos */ fetchVideoData(tag: number): void { - callAPI(APINode.Video, {action: 'getMovies', Tag: tag}, (result: VideoTypes.VideoUnloadedType[]) => { - this.setState({ - data: [] - }); - this.setState({ - data: result, - selectionnr: result.length - }); - }); + callAPI( + APINode.Video, + {action: 'getMovies', Tag: tag}, + (result: {Videos: VideoTypes.VideoUnloadedType[]; TagName: string}) => { + this.setState({ + data: [] + }); + this.setState({ + data: result.Videos, + selectionnr: result.Videos.length + }); + } + ); } /** diff --git a/src/pages/Player/Player.tsx b/src/pages/Player/Player.tsx index 342ec9c..82c86f8 100644 --- a/src/pages/Player/Player.tsx +++ b/src/pages/Player/Player.tsx @@ -286,6 +286,10 @@ export class Player extends React.Component { suggesttag: result.SuggestedTag, actors: result.Actors }); + }, + (_) => { + // if there is an load error redirect to home page + this.props.history.push('/'); } ); } diff --git a/src/pages/TVShowPage/TVPlayer.tsx b/src/pages/TVShowPage/TVPlayer.tsx index 6885e32..7d179a5 100644 --- a/src/pages/TVShowPage/TVPlayer.tsx +++ b/src/pages/TVShowPage/TVPlayer.tsx @@ -46,6 +46,10 @@ export class TVPlayer extends React.Component { console.log(data); this.data = data; this.setState({loaded: true}); + }, + (_) => { + // if there is an load error redirect to home page + this.props.history.push('/'); } ); } diff --git a/src/utils/Api.ts b/src/utils/Api.ts index 0b15abd..a4f3d39 100644 --- a/src/utils/Api.ts +++ b/src/utils/Api.ts @@ -37,9 +37,12 @@ export function callAPI( .then((response) => { if (response.status === 200) { // success - response.json().then((result: T) => { - callback(result); - }); + response + .json() + .then((result: T) => { + callback(result); + }) + .catch((reason) => errorcallback(reason)); } else if (response.status === 400) { // Bad Request --> invalid token console.log('loading Password page.');