11 Commits
v2.0 ... v2.4

14 changed files with 281 additions and 55 deletions

8
README.md Normal file
View File

@ -0,0 +1,8 @@
# New Life Songs Database
This is Jonathan's database of worship songs performed at New Life Austin. The
service lives online at http://newlifesongs.jdbernard.com
API Documentation is [maintained online with the service](http://newlifesongs.jdbernard.com/doc/api/v1/).
You can also view the [annotated source code](https://doc.jdb-labs.com/new-life-songs/current/).

View File

@ -42,9 +42,9 @@ dependencies {
war { war {
from "resources/webapp" from "resources/webapp"
from "build/webapp" from "build/webapp"
version = project.version.releaseVersion
filter(ReplaceTokens, tokens: [version: version]) filter(ReplaceTokens, tokens: [version: version])
rename '(.+)(\\..*(css|js))', '$1-' + version + '$2' rename '(.+)(\\..*(css|js))', '$1-' + version + '$2'
version = project.version.releaseVersion
webInf { from 'resources/main/WEB-INF' } webInf { from 'resources/main/WEB-INF' }
exclude "**/.*.swp", "**/.sass-cache" exclude "**/.*.swp", "**/.sass-cache"
} }
@ -53,9 +53,9 @@ test { testLogging { events 'failed' } }
task testWar(type: War) { task testWar(type: War) {
from 'resources/webapp' from 'resources/webapp'
version = project.version.releaseVersion
filter(ReplaceTokens, tokens: [version: version]) filter(ReplaceTokens, tokens: [version: version])
rename '(.+)(\\..*(css|js))', '$1-' + version + '$2' rename '(.+)(\\..*(css|js))', '$1-' + version + '$2'
version = project.version.releaseVersion
webInf { from 'resources/test/WEB-INF' } webInf { from 'resources/test/WEB-INF' }
classifier 'test' } classifier 'test' }

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View File

@ -315,7 +315,7 @@ public class NLSongsDB {
return buildToken(row, user) } return buildToken(row, user) }
public static List<String> unwrapArtists(String artists) { public static List<String> unwrapArtists(String artists) {
return artists.split(';') as List<String> } return artists.split(':') as List<String> }
public static String wrapArtists(List<String> artists) { public static String wrapArtists(List<String> artists) {
return artists.join(':') } return artists.join(':') }

View File

@ -7,6 +7,7 @@ public class Service implements Serializable {
int id int id
private LocalDate date private LocalDate date
ServiceType serviceType ServiceType serviceType
String description
public boolean equals(Object thatObj) { public boolean equals(Object thatObj) {
if (thatObj == null) return false if (thatObj == null) return false

View File

@ -13,5 +13,5 @@ public class NLSongsContext {
public static String makeUrl(Service service, Song song) { public static String makeUrl(Service service, Song song) {
return mediaBaseUrl + '/' + service.@date.toString('yyyy-MM-dd') + '_' + return mediaBaseUrl + '/' + service.@date.toString('yyyy-MM-dd') + '_' +
service.serviceType.name().toLowerCase() + '_' + service.serviceType.name().toLowerCase() + '_' +
song.name.replaceAll(/[\s'"\\\/\?!]/, '') + '.ogg' } song.name.replaceAll(/[\s'"\\\/\?!]/, '') + '.mp3' }
} }

View File

@ -9,6 +9,7 @@ CREATE TABLE IF NOT EXISTS services (
id SERIAL, id SERIAL,
date DATE NOT NULL, date DATE NOT NULL,
service_type VARCHAR(16) DEFAULT NULL, service_type VARCHAR(16) DEFAULT NULL,
description VARCHAR(255) DEFAULT NULL,
CONSTRAINT uc_serviceTypeAndDate UNIQUE (date, service_type), CONSTRAINT uc_serviceTypeAndDate UNIQUE (date, service_type),
PRIMARY KEY (id)); PRIMARY KEY (id));

View File

@ -65,7 +65,11 @@ table {
pre { margin-left: 1rem; } pre { margin-left: 1rem; }
h3 { margin: 1rem 0; } h2 {
border-bottom: solid 2px $dark;
margin-top: 2em; }
h3 { margin: 2rem 0 1rem 0; }
dl { dl {
margin: 1rem; margin: 1rem;
@ -75,7 +79,20 @@ table {
font-family: $monoFont; font-family: $monoFont;
font-weight: bold; } font-weight: bold; }
& > dd { padding: 0 0 0.5rem 1rem; } } } & > dd { padding: 0 0 0.5rem 1rem; } }
table.method-summary {
padding: 0 2rem;
width: 100%;
th {
border-bottom: solid thin $dark;
text-align: left; }
th.action, td.action { width: 6em; }
th.path, td.path { width: 17em; }
th.public, td.public { width: 4em; }
} }
@include forSize(notSmall) { @include forSize(notSmall) {
@ -109,7 +126,7 @@ table {
text-align: center; text-align: center;
& > h2 { display: none; } & > h2 { display: none; }
& > h2.song-name, & > h2.service-date { display: block; } & > h2.song-name, & > h2.service-desc { display: block; }
& > nav > ul > li { & > nav > ul > li {
display: inline-block; display: inline-block;

View File

@ -21,8 +21,8 @@
</header> </header>
<section id=api-overview> <section id=api-overview>
The New Life Songs database exposes a REST API. This allows The New Life Songs database exposes a REST API. This allows
programatic access and modification to the data. Version 1 of the programatic access to and modification of the data. Version 1 of
API defines several endpoints, all of which are built off of the API defines several endpoints, all of which are built off of
<code>http://newlifesongs.jdbernard.com/api/v1</code> as a base <code>http://newlifesongs.jdbernard.com/api/v1</code> as a base
URL. URL.
@ -64,6 +64,46 @@
"Michael W. Smith" "Michael W. Smith"
] ]
}</pre> }</pre>
<h3>Method Summary</h3>
<table class=method-summary>
<thead>
<tr><th class=action>HTTP Action</th>
<th class=path>Path</th>
<th class=desc>Description</th>
<th class=public>Public?</th></tr>
</thead>
<tbody>
<tr><td class=action>GET</td>
<td class=path><code>/songs</code></td>
<td class=desc>Retrieve all songs.</td>
<td class=public>yes</td></tr>
<tr><td class=acion>POST</td>
<td class=path><code>/songs</code></td>
<td class=desc>Create a new song record.</td>
<td class=public>no</td></tr>
<tr><td class=acion>GET</td>
<td class=path><code>/songs/&lt;songId&gt;</code></td>
<td class=desc>Retrieve a single record.</td>
<td class=public>yes</td></tr>
<tr><td class=acion>PUT</td>
<td class=path><code>/songs/&lt;songId&gt;</code></td>
<td class=desc>Update a song record.</td>
<td class=public>no</td></tr>
<tr><td class=acion>DELETE</td>
<td class=path><code>/songs/&lt;songId&gt;</code></td>
<td class=desc>Delete a song record.</td>
<td class=public>no</td></tr>
<tr><td class=acion>GET</td>
<td class=path><code>/songs/forService/&lt;serviceId&gt;</code></td>
<td class=desc>Retrieve all songs performed in a given service.</td>
<td class=public>yes</td></tr>
<tr><td class=acion>GET</td>
<td class=path><code>/songs/byArtist/&lt;artist&gt;</code></td>
<td class=desc>Retrieve all songs performed by a given artist.</td>
<td class=public>yes</td></tr>
</tbody>
</table>
<ul class=method-list> <ul class=method-list>
<li><h3><code>GET /songs</code></h3> <li><h3><code>GET /songs</code></h3>
@ -71,22 +111,22 @@
<p><h4>Response</h4> <p><h4>Response</h4>
A list of <a href="song-object">song objects</a> A list of <a href="song-object">song objects</a>
<h4>Example</h4> <p><h4>Example</h4>
<pre> <pre>
GET http://newlifesongs.jdbernard.com/api/v1/songs</pre> GET http://newlifesongs.jdbernard.com/api/v1/songs</pre>
<p><pre> <p><pre>
HTTP/1.1 200 OK HTTP/1.1 200 OK
Content-Length: 5146 Content-Length: 433
Content-Type: application/json Content-Type: application/json
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
Server: Jetty(6.1.25)
[{"id":1,"name":"Welcome Holy Spirit","artists":["Mark Condon"]}, [{"id":1,"name":"Welcome Holy Spirit","artists":["Mark Condon"]},
{"id":3,"name":"Let's Sing Praises to our God","artists":["Traditional"]}, {"id":3,"name":"Let's Sing Praises to our God","artists":["Traditional"]},
{"id":5,"name":"Blessed Assurance","artists":["Frances J. Crosby"]}, {"id":5,"name":"Blessed Assurance","artists":["Frances J. Crosby"]},
{"id":8,"name":"Here I Am To Worship","artists":["Tim Hughes", "Chris Tomlin", "Michael W. Smith"]}, {"id":8,"name":"Here I Am To Worship","artists":["Tim Hughes", "Chris Tomlin", "Michael W. Smith"]},
{"id":12,"name":"Healer","artists":["Kari Jobe", "Hillsong"]}, {"id":12,"name":"Healer","artists":["Kari Jobe", "Hillsong"]},
{"id":15,"name":"I Am Free","artists":["Newsboys"]}]</pre></li> {"id":15,"name":"I Am Free","artists":["Newsboys"]}]
</pre></li>
<li><h3><code>POST /songs</code></h3> <li><h3><code>POST /songs</code></h3>
@ -102,13 +142,203 @@ Server: Jetty(6.1.25)
in with the request will be ignored. in with the request will be ignored.
<p><h4>Reponse</h4> <p><h4>Reponse</h4>
The newly-created song record. The newly-created song record. If a value is given in the
request for the <tt>id</tt> attribute it is ignored. The
attribute for new records is determined by the service and
returned as part of the response.
<p><h4>Example</h4> <p><h4>Example</h4>
<pre>
POST http://newlifesongs.jdbernard.com/api/v1/songs
Content-Length: 60
Content-Type: application/json
{"id":22,"name":"This is How We Praise Him","artists":[""]}
</pre>
<p><pre>
HTTP/1.1 201 Created
Content-Length:
Content-Type: application/json
</pre></li>
<li><h3><code>GET /songs/&lt;songId&gt;</code></h3>
<p>Retrieve song data for the given song id.
<p><h4>Response</h4>
A <a href="song-object">song object</a>.
<p><h4>Example</h4>
<pre>
GET http://newlifesongs.jdbernard.com/api/v1/songs/1</pre>
<p><pre>
HTTP/1.1 200 OK
Content-Length: 63
Content-Type: application/json
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
{"id":1,"name":"Welcome Holy Spirit","artists":["Mark Condon"]}
</pre></li>
</li>
<li><h3><code>PUT /songs/&lt;songId&gt;</code></h3>
<p>Method description
<p><h4>Request Body</h4>
Request body description
<p><h4>Response</h4>
Return value description
<p><h4>Example</h4>
<pre>
</pre></li>
</li>
<li><h3><code>DELETE /songs/&lt;songId&gt;</code></h3>
<p>Method description
<p><h4>Request Body</h4>
Request body description
<p><h4>Response</h4>
Return value description
<p><h4>Example</h4>
<pre>
</pre></li>
</li>
<li><h3><code>GET /songs/forService/&lt;serviceId&gt;</code></h3>
<p>Method description
<p><h4>Request Body</h4>
Request body description
<p><h4>Response</h4>
Return value description
<p><h4>Example</h4>
<pre>
GET /api/v1/songs/forService/1 HTTP/1.1</pre>
<p><pre>
HTTP/1.1 200 OK
Content-Length: 256
Content-Type: application/json
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
[{"id":7,"name":"Mighty God","artists":[""]},
{"id":8,"name":"Here I Am To Worship","artists":["Tim Hughes: Chris Tomlin, Michael W. Smith"]},
{"id":9,"name":"Worthy","artists":[""]},
{"id":4,"name":"I Am A Friend Of God","artists":["Israel Houghton"]}]j
</pre></li>
</li>
<li><h3><code>GET /songs/byArtist/&lt;artist&gt;</code></h3>
<p>Method description
<p><h4>Request Body</h4>
Request body description
<p><h4>Response</h4>
Return value description
<p><h4>Example</h4>
<pre>
</pre></li>
</li>
</section> </section>
<section id=services> <section id=services>
<h2><code>/services</code></h2> <h2><code>/services</code></h2>
<h3 id=service-object>Service object</h3>
A Service object is defined with the following fields:
<dl><dt>id</dt>
<dd>An identifier unique to this service record among all
service records. <em>Type: integer</em></dd>
<dt>date</dt>
<dd>The date of the service. <em>Type: Date</em></dd>
<dt>serviceType</dt>
<dd>Service type. <em>Type: string</em> Valid values:
<table><thead><tr><th>Value</th><th>Description</th></tr></thead>
<tbody>
<tr><td><code>SUN_AM</code></td>
<td>Sunday morning service.</td></tr>
<tr><td><code>SUN_PM</code></td>
<td>Sunday evening service</td></tr>
<tr><td><code>WED</code></td>
<td>Wednesday, midweek Bible study.</td></tr>
</tbody>
</table>
</dd>
</dl>
<h4>Example</h4>
<pre>
{
"id": 1,
"date": 1235887200000,
"serviceType": "SUN_PM"
}</pre>
<h3>Method Summary</h3>
<table class=method-summary>
<thead>
<tr><th class=action>HTTP Action</th>
<th class=path>Path</th>
<th class=desc>Description</th>
<th class=public>Public?</th></tr>
</thead>
<tbody>
<tr><td class=action>GET</td>
<td class=path><code>/services</code></td>
<td class=desc>Retrieve all services.</td>
<td class=public>yes</td></tr>
<tr><td class=acion>POST</td>
<td class=path><code>/services</code></td>
<td class=desc>Create a new service record.</td>
<td class=public>no</td></tr>
<tr><td class=acion>GET</td>
<td class=path><code>/services/&lt;serviceId&gt;</code></td>
<td class=desc>Retrieve a single service record.</td>
<td class=public>yes</td></tr>
<tr><td class=acion>PUT</td>
<td class=path><code>/services/&lt;serviceId&gt;</code></td>
<td class=desc>Update a service record.</td>
<td class=public>no</td></tr>
<tr><td class=acion>DELETE</td>
<td class=path><code>/services/&lt;serviceId&gt;</code></td>
<td class=desc>Delete a service record.</td>
<td class=public>no</td></tr>
<tr><td class=acion>GET</td>
<td class=path><code>/services/withSong/&lt;serviceId&gt;</code></td>
<td class=desc>Retrieve all services in which the given song was performed.</td>
<td class=public>yes</td></tr>
<tr><td class=acion>GET</td>
<td class=path><code>/services/byDate/after/&lt;date&gt;</code></td>
<td class=desc>Retrieve all services after the given date.</td>
<td class=public>yes</td></tr>
<tr><td class=acion>GET</td>
<td class=path><code>/services/byDate/before/&lt;date&gt;</code></td>
<td class=desc>Retrieve all services before the given date.</td>
<td class=public>yes</td></tr>
<tr><td class=acion>GET</td>
<td class=path><code>/services/byDate/between/&lt;date1&gt;/&lt;date2&gt;</code></td>
<td class=desc>Retrieve all services between the two given dates.</td>
<td class=public>yes</td></tr>
</tbody>
</table>
</section> </section>
<section id=users> <section id=users>
<h2><code>/users</code></h2> <h2><code>/users</code></h2>

View File

@ -38,8 +38,8 @@ if (!service) { response.sendError(response.SC_NOT_FOUND); return }
<body> <body>
<header> <header>
<h1><a href="../">New Life Songs</a></h1> <h1><a href="../">New Life Songs</a></h1>
<h2 class=service-date><%= service.@date.toString("yyyy-MM-dd") %> (<%= <h2 class=service-desc><%= service.@date.toString("yyyy-MM-dd") %>: (<%=
service.serviceType.displayName %>)</h2> service.description ?: service.serviceType.displayName %>)</h2>
<nav><ul> <nav><ul>
<li><a href="../admin/">Admin</a></li> <li><a href="../admin/">Admin</a></li>

View File

@ -45,7 +45,8 @@ songsDB = NLSongsContext.songsDB
<% songsDB.findAllServices().sort { it.date }.reverse().each { service -> %> <% songsDB.findAllServices().sort { it.date }.reverse().each { service -> %>
<tr><td class=date><a href="../service/<%= service.id %>"><%= <tr><td class=date><a href="../service/<%= service.id %>"><%=
service.@date.toString("yyyy-MM-dd") %></a></td> service.@date.toString("yyyy-MM-dd") %></a></td>
<td class=service-type><%= service.serviceType.displayName %></td></tr><% } %> <td class=service-type><%= service.description ?:
service.serviceType.displayName %></td></tr><% } %>
</tbody> </tbody>
<!--<tfoot><tr> <!--<tfoot><tr>
<th class="dt-left">Date</th> <th class="dt-left">Date</th>
@ -56,7 +57,8 @@ songsDB = NLSongsContext.songsDB
<script type="application/javascript"> <script type="application/javascript">
window.onload = function() { \$("#services-table"). window.onload = function() { \$("#services-table").
dataTable({ "paging": false }); }; dataTable({ "paging": false,
"order": [[0, "desc"]]}); };
</script> </script>
</body> </body>
</html> </html>

View File

@ -5,8 +5,7 @@ import com.jdbernard.nlsongs.model.*
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
sdf = new SimpleDateFormat('yyyy-MM-dd') sdf = new SimpleDateFormat('yyyy-MM-dd')
hcfg = new hcfg = new HikariConfig("/home/jdbernard/projects/new-life-songs/src/main/webapp/WEB-INF/classes/datasource.properties")
HikariConfig("/home/jdbernard/projects/new-life-songs/src/main/webapp/WEB-INF/classes/datasource.properties")
makeService = { svcRow -> makeService = { svcRow ->
Service svc = new Service() Service svc = new Service()

View File

@ -1,32 +0,0 @@
package com.jdbernard.nlsongs.db
public class GenerateQueries {
public static void main(String[] args) {
}
public static Map<String, Map<String, String> > generateQueries(String ddl) {
def tables = [:]
// Find the table definitions
String tableRegex = /(?ms)(?:CREATE TABLE (?:IF NOT EXISTS )?([^\s]+) \(([^\s]+);.+?)+/
ddl.eachMatch(tableRegex) { matchGroups ->
String tableName = matchGroups[1]
// Parse the column definitions.
// Create new record insert statements.
// Create insert queries.
// Create update queries.
// Create delete queries.
// Create ID lookup queries.
}
}

View File

@ -1,6 +1,6 @@
# #
#Mon Mar 23 03:03:08 CDT 2015 #Tue Jul 21 19:08:16 CDT 2015
major=2 major=2
version.release=true version.release=true
minor=0 minor=4
build=101 build=6