Added web deployment description, context configuration, service, and song endpoint implementations.
This commit is contained in:
		@@ -0,0 +1,12 @@
 | 
			
		||||
package com.jdbernard.nlsongs.rest
 | 
			
		||||
 | 
			
		||||
import javax.ws.rs.GET;
 | 
			
		||||
import javax.ws.rs.Path;
 | 
			
		||||
import javax.ws.rs.Produces;
 | 
			
		||||
 | 
			
		||||
@Path("v1/ping")
 | 
			
		||||
public class PingResource {
 | 
			
		||||
 | 
			
		||||
    @GET
 | 
			
		||||
    @Produces("text/plain")
 | 
			
		||||
    public String ping() { return "pong" } }
 | 
			
		||||
@@ -0,0 +1,57 @@
 | 
			
		||||
package com.jdbernard.nlsongs.rest;
 | 
			
		||||
 | 
			
		||||
import java.util.Date;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import javax.ws.rs.GET;
 | 
			
		||||
import javax.ws.rs.POST;
 | 
			
		||||
import javax.ws.rs.PUT;
 | 
			
		||||
import javax.ws.rs.Consumes;
 | 
			
		||||
import javax.ws.rs.Path;
 | 
			
		||||
import javax.ws.rs.PathParam;
 | 
			
		||||
import javax.ws.rs.Produces;
 | 
			
		||||
import javax.ws.rs.core.MediaType;
 | 
			
		||||
 | 
			
		||||
import com.jdbernard.nlsongs.servlet.NLSongsContext;
 | 
			
		||||
import com.jdbernard.nlsongs.model.Service;
 | 
			
		||||
 | 
			
		||||
@Path("v1/services")
 | 
			
		||||
@Produces({MediaType.APPLICATION_JSON})
 | 
			
		||||
@Consumes({MediaType.APPLICATION_JSON})
 | 
			
		||||
public class ServicesResource {
 | 
			
		||||
 | 
			
		||||
    @GET
 | 
			
		||||
    public List<Service> getServices() {
 | 
			
		||||
        return NLSongsContext.songsDB.findAllServices(); }
 | 
			
		||||
 | 
			
		||||
    @POST
 | 
			
		||||
    public Service postService(Service service) {
 | 
			
		||||
        return NLSongsContext.songsDB.create(service); }
 | 
			
		||||
 | 
			
		||||
    @GET @Path("/{serviceId}")
 | 
			
		||||
    public Service getService(@PathParam("serviceId") int serviceId) {
 | 
			
		||||
        return NLSongsContext.songsDB.findService(serviceId); }
 | 
			
		||||
 | 
			
		||||
    @PUT @Path("/{serviceId}")
 | 
			
		||||
    public Service putService(@PathParam("serviceId") int serviceId,
 | 
			
		||||
    Service service) {
 | 
			
		||||
        service.setId(serviceId);
 | 
			
		||||
        NLSongsContext.songsDB.update(service);
 | 
			
		||||
        return service; }
 | 
			
		||||
 | 
			
		||||
    @GET @Path("/withSong/{songId}")
 | 
			
		||||
    public List<Service> getServicesForSong(@PathParam("songId") int songId) {
 | 
			
		||||
        return NLSongsContext.songsDB.findServicesForSongId(songId); }
 | 
			
		||||
 | 
			
		||||
    @GET @Path("/byDate/after/{date}")
 | 
			
		||||
    public List<Service> getServicesAfter(@PathParam("date") Date date) {
 | 
			
		||||
        return NLSongsContext.songsDB.findServicesAfter(date); }
 | 
			
		||||
 | 
			
		||||
    @GET @Path("/byDate/before/{date}")
 | 
			
		||||
    public List<Service> getServicesBefore(@PathParam("date") Date date) {
 | 
			
		||||
        return NLSongsContext.songsDB.findServicesBefore(date); }
 | 
			
		||||
 | 
			
		||||
    @GET @Path("/byDate/between/{b}/{e}")
 | 
			
		||||
    public List<Service> getServicesBetween
 | 
			
		||||
    (@PathParam("b") Date b, @PathParam("e") Date e) {
 | 
			
		||||
        return NLSongsContext.songsDB.findServicesBetween(b, e); }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,46 @@
 | 
			
		||||
package com.jdbernard.nlsongs.rest;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import javax.ws.rs.GET;
 | 
			
		||||
import javax.ws.rs.POST;
 | 
			
		||||
import javax.ws.rs.PUT;
 | 
			
		||||
import javax.ws.rs.Consumes;
 | 
			
		||||
import javax.ws.rs.Path;
 | 
			
		||||
import javax.ws.rs.PathParam;
 | 
			
		||||
import javax.ws.rs.Produces;
 | 
			
		||||
import javax.ws.rs.core.MediaType;
 | 
			
		||||
 | 
			
		||||
import com.jdbernard.nlsongs.servlet.NLSongsContext;
 | 
			
		||||
import com.jdbernard.nlsongs.model.Song;
 | 
			
		||||
 | 
			
		||||
@Path("v1/songs")
 | 
			
		||||
@Produces({MediaType.APPLICATION_JSON})
 | 
			
		||||
@Consumes({MediaType.APPLICATION_JSON})
 | 
			
		||||
public class SongsResource {
 | 
			
		||||
 | 
			
		||||
    @GET
 | 
			
		||||
    public List<Song> getSongs() {
 | 
			
		||||
        return NLSongsContext.songsDB.findAllSongs(); }
 | 
			
		||||
 | 
			
		||||
    @POST
 | 
			
		||||
    public Song postSong(Song song) {
 | 
			
		||||
        return NLSongsContext.songsDB.create(song); }
 | 
			
		||||
 | 
			
		||||
    @GET @Path("/{songId}")
 | 
			
		||||
    public Song getSong(@PathParam("songId") int songId) {
 | 
			
		||||
        return NLSongsContext.songsDB.findSong(songId); }
 | 
			
		||||
 | 
			
		||||
    @PUT @Path("/{songId}")
 | 
			
		||||
    public Song putSong(@PathParam("songId") int songId, Song song) {
 | 
			
		||||
        song.setId(songId);
 | 
			
		||||
        NLSongsContext.songsDB.update(song);
 | 
			
		||||
        return song; }
 | 
			
		||||
 | 
			
		||||
    @GET @Path("/forService/{serviceId}")
 | 
			
		||||
    public List<Song> getSongsForService(@PathParam("serviceId") int serviceId) {
 | 
			
		||||
        return NLSongsContext.songsDB.findSongsForServiceId(serviceId); }
 | 
			
		||||
 | 
			
		||||
    @GET @Path("/byArtist/{artist}")
 | 
			
		||||
    public List<Song> getSongsForArtist(@PathParam("artist") String artist) {
 | 
			
		||||
        return NLSongsContext.songsDB.findSongsByArtist(artist); }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,7 @@
 | 
			
		||||
package com.jdbernard.nlsongs.servlet
 | 
			
		||||
 | 
			
		||||
import com.jdbernard.nlsongs.db.NLSongsDB
 | 
			
		||||
 | 
			
		||||
public class NLSongsContext {
 | 
			
		||||
 | 
			
		||||
    public static NLSongsDB songsDB }
 | 
			
		||||
		Reference in New Issue
	
	Block a user