Package com.pugh.sockso.web.action.api

Source Code of com.pugh.sockso.web.action.api.GenresAction

package com.pugh.sockso.web.action.api;

import com.pugh.sockso.music.Genre;
import com.pugh.sockso.templates.api.TGenres;
import com.pugh.sockso.web.Request;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

public class GenresAction extends BaseApiAction {

    @Override
    public boolean canHandle( final Request req ) {

        return req.getParamCount() == 2
            && req.getUrlParam( 1 ).equals( "genres" );

    }

    /**
     *  Shows the requested list of genres
     *
     *  @throws IOException
     *
     */

    public void handleRequest() throws SQLException, IOException {

        final List<Genre> genres = Genre.findAll(
            getDatabase(), getLimit(), getOffset()
        );

        showGenres( genres.toArray( new Genre[] {} ) );

    }

    /**
     * Shows the specified genres
     *
     * @param genres
     *
     * @throws IOException
     *
     */

    protected void showGenres( final Genre[] genres ) throws IOException {

        TGenres tpl = new TGenres();
        tpl.setGenres( genres );

        getResponse().showJson( tpl.makeRenderer() );

    }

}
TOP

Related Classes of com.pugh.sockso.web.action.api.GenresAction

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.