diff --git a/src/main/groovy/com/jdbernard/nlsongs/rest/PingResource.groovy b/src/main/groovy/com/jdbernard/nlsongs/rest/PingResource.groovy new file mode 100644 index 0000000..58a37a8 --- /dev/null +++ b/src/main/groovy/com/jdbernard/nlsongs/rest/PingResource.groovy @@ -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" } } diff --git a/src/main/groovy/com/jdbernard/nlsongs/rest/ServicesResource.java b/src/main/groovy/com/jdbernard/nlsongs/rest/ServicesResource.java new file mode 100644 index 0000000..8bf3dc5 --- /dev/null +++ b/src/main/groovy/com/jdbernard/nlsongs/rest/ServicesResource.java @@ -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 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 getServicesForSong(@PathParam("songId") int songId) { + return NLSongsContext.songsDB.findServicesForSongId(songId); } + + @GET @Path("/byDate/after/{date}") + public List getServicesAfter(@PathParam("date") Date date) { + return NLSongsContext.songsDB.findServicesAfter(date); } + + @GET @Path("/byDate/before/{date}") + public List getServicesBefore(@PathParam("date") Date date) { + return NLSongsContext.songsDB.findServicesBefore(date); } + + @GET @Path("/byDate/between/{b}/{e}") + public List getServicesBetween + (@PathParam("b") Date b, @PathParam("e") Date e) { + return NLSongsContext.songsDB.findServicesBetween(b, e); } +} diff --git a/src/main/groovy/com/jdbernard/nlsongs/rest/SongsResource.java b/src/main/groovy/com/jdbernard/nlsongs/rest/SongsResource.java new file mode 100644 index 0000000..64df964 --- /dev/null +++ b/src/main/groovy/com/jdbernard/nlsongs/rest/SongsResource.java @@ -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 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 getSongsForService(@PathParam("serviceId") int serviceId) { + return NLSongsContext.songsDB.findSongsForServiceId(serviceId); } + + @GET @Path("/byArtist/{artist}") + public List getSongsForArtist(@PathParam("artist") String artist) { + return NLSongsContext.songsDB.findSongsByArtist(artist); } +} diff --git a/src/main/groovy/com/jdbernard/nlsongs/servlet/NLSongsContext.groovy b/src/main/groovy/com/jdbernard/nlsongs/servlet/NLSongsContext.groovy new file mode 100644 index 0000000..f9970c1 --- /dev/null +++ b/src/main/groovy/com/jdbernard/nlsongs/servlet/NLSongsContext.groovy @@ -0,0 +1,7 @@ +package com.jdbernard.nlsongs.servlet + +import com.jdbernard.nlsongs.db.NLSongsDB + +public class NLSongsContext { + + public static NLSongsDB songsDB } diff --git a/src/main/webapp/WEB-INF/classes/newlifesongs.properties b/src/main/webapp/WEB-INF/classes/newlifesongs.properties new file mode 100644 index 0000000..3f892ab --- /dev/null +++ b/src/main/webapp/WEB-INF/classes/newlifesongs.properties @@ -0,0 +1,9 @@ +dataSourceClassName=com.impossibl.postgres.jdbc.PGDataSource +dataSource.user=jdbernard +dataSource.password=wh!73bl@k +dataSource.database=nlsongs +dataSource.host=localhost +#dataSource.cachePrepStmts=true +#dataSource.prepStmtCacheSize=250 +#dataSource.prepStmtCacheSqlLimit=2048 +#dataSource.useServerPrepStmts=true diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..b5081e7 --- /dev/null +++ b/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,32 @@ + + + + + context.config.file + /newlifesongs.properties + + + + com.jdbernard.nlsongs.servlet.NLSongsContextListener + + + + + New Life Songs REST API + org.glassfish.jersey.servlet.ServletContainer + + + jersey.config.server.provider.packages + com.jdbernard.nlsongs.rest + + + 1 + + + + New Life Songs REST API + /api/* + + +