{"action":"created","comment":{"url":"https://api.github.com/repos/osu-mist/catalog-api-test/pulls/comments/35055384","id":35055384,"diff_hunk":"@@ -1,42 +1,166 @@\n package edu.oregonstate.mist.catalogapitest.resources\n \n+import edu.oregonstate.mist.catalogapitest.core.ErrorPOJO\n import edu.oregonstate.mist.catalogapitest.core.Course\n import edu.oregonstate.mist.catalogapitest.db.CourseDAO\n import io.dropwizard.jersey.params.IntParam\n+import com.google.common.base.Optional\n+import javassist.NotFoundException\n+import org.eclipse.jetty.server.Response\n+import javax.validation.Valid\n import javax.validation.constraints.NotNull\n import javax.ws.rs.Consumes\n+import javax.ws.rs.DELETE\n import javax.ws.rs.GET\n import javax.ws.rs.POST\n+import javax.ws.rs.PUT\n import javax.ws.rs.Path\n import javax.ws.rs.PathParam\n import javax.ws.rs.Produces\n import javax.ws.rs.QueryParam\n import javax.ws.rs.WebApplicationException\n+import javax.ws.rs.core.Context\n import javax.ws.rs.core.MediaType\n-import com.google.common.base.Optional\n-import javassist.NotFoundException\n-import org.eclipse.jetty.server.Response\n+import javax.ws.rs.core.Response\n+import javax.ws.rs.core.UriInfo\n \n @Path(\"/course\")\n @Produces(MediaType.APPLICATION_JSON)\n class CourseResource {\n \n+    // Instantiate DAO -------------------------------------------------------------------------------------------------\n     private final CourseDAO courseDAO\n \n+    @Context\n+    UriInfo uriInfo\n+\n     public CourseResource(CourseDAO courseDAO) {\n         this.courseDAO = courseDAO\n     }\n \n+    // POST to /course ------------------------------------------------------------------------------------------------\n+    @POST\n+    @Consumes(MediaType.APPLICATION_JSON)\n+    @Produces(MediaType.APPLICATION_JSON)\n+    public Response postUser(@Valid Course newCourse) {\n+\n+        Response returnResponse\n+        def createdURI\n+\n+        try {\n+            courseDAO.postCourse(newCourse.getCrn(), newCourse.getCourseName(), newCourse.getInstructor(),\n+            newCourse.getDay(), newCourse.getTime(), newCourse.getLocation())\n+\n+            // TODO add in the URI of newly created resource\n+            createdURI = URI.create(uriInfo.getPath() + \"/\" + courseDAO.getLatestCidNumber())\n+            returnResponse = Response.created(createdURI).build()\n+\n+        } catch (org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException e) {\n+\n+            def constraintError = e.cause.toString()\n+            def returnError\n+\n+            if(constraintError.contains(\"COURSES_UK_CRN\")) {\n+                //CRN number is not unique\n+                returnError = new ErrorPOJO(\"CRN is not unique\", Response.Status.CONFLICT.getStatusCode())\n+            } else {\n+                //Some other error, should be logged\n+                System.out.println(e.localizedMessage)\n+                returnError = new ErrorPOJO(\"Unknown error.\", Response.Status.INTERNAL_SERVER_ERROR.getStatusCode())\n+            }\n+\n+            //return Response.status(Response.Status.CONFLICT).entity(returnError).build()\n+\n+            System.out.println(returnError.getErrorMessage())\n+        }\n+\n+        return returnResponse;\n+    }\n+\n+    // List all courses ------------------------------------------------------------------------------------------------\n     @GET\n     @Path('/all')\n+    @Produces(MediaType.APPLICATION_JSON)\n     public List<Course> getByCrn() {\n         return courseDAO.allCourses\n     }\n \n+    // CRN specific requests -------------------------------------------------------------------------------------------\n     @GET\n     @Path('{crn}')\n-    public List<Course> getByCrn(@PathParam('crn') IntParam crn) {\n-        final List<Course> courses = courseDAO.findByCrn(crn.get())\n+    @Produces(MediaType.APPLICATION_JSON)\n+    public Response getByCrn(@PathParam('crn') IntParam crn) {\n+\n+        Course courses = courseDAO.getByCrn(crn.get())\n+\n+        def returnResponse\n+\n+        if (courses == null) {\n+            def returnError = new ErrorPOJO(\"Resource Not Found.\", Response.Status.NOT_FOUND.getStatusCode())\n+            returnResponse = Response.status(Response.Status.NOT_FOUND).entity(returnError).build()\n+        } else {\n+            returnResponse = Response.ok(courses).build()\n+        }\n+\n+        return returnResponse\n+    }\n+\n+    @Path(\"{crn}\")\n+    @PUT\n+    @Produces(MediaType.APPLICATION_JSON)\n+    @Consumes(MediaType.APPLICATION_JSON)\n+    public Response putByCrn(@PathParam(\"crn\") Integer crn , Course newCourse) {\n+\n+        def returnResponse","path":"src/main/groovy/edu/oregonstate/mist/catalogapitest/resources/CourseResource.groovy","position":119,"original_position":119,"commit_id":"fcf4654f688a2161028e76a94ea6fc7f255a8ee8","original_commit_id":"fcf4654f688a2161028e76a94ea6fc7f255a8ee8","user":{"login":"browtayl","id":8976764,"avatar_url":"https://avatars.githubusercontent.com/u/8976764?v=3","gravatar_id":"","url":"https://api.github.com/users/browtayl","html_url":"https://github.com/browtayl","followers_url":"https://api.github.com/users/browtayl/followers","following_url":"https://api.github.com/users/browtayl/following{/other_user}","gists_url":"https://api.github.com/users/browtayl/gists{/gist_id}","starred_url":"https://api.github.com/users/browtayl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/browtayl/subscriptions","organizations_url":"https://api.github.com/users/browtayl/orgs","repos_url":"https://api.github.com/users/browtayl/repos","events_url":"https://api.github.com/users/browtayl/events{/privacy}","received_events_url":"https://api.github.com/users/browtayl/received_events","type":"User","site_admin":false},"body":"type","created_at":"2015-07-20T23:16:21Z","updated_at":"2015-07-20T23:16:21Z","html_url":"https://github.com/osu-mist/catalog-api-test/pull/7#discussion_r35055384","pull_request_url":"https://api.github.com/repos/osu-mist/catalog-api-test/pulls/7","_links":{"self":{"href":"https://api.github.com/repos/osu-mist/catalog-api-test/pulls/comments/35055384"},"html":{"href":"https://github.com/osu-mist/catalog-api-test/pull/7#discussion_r35055384"},"pull_request":{"href":"https://api.github.com/repos/osu-mist/catalog-api-test/pulls/7"}}},"pull_request":{"url":"https://api.github.com/repos/osu-mist/catalog-api-test/pulls/7","id":40403737,"html_url":"https://github.com/osu-mist/catalog-api-test/pull/7","diff_url":"https://github.com/osu-mist/catalog-api-test/pull/7.diff","patch_url":"https://github.com/osu-mist/catalog-api-test/pull/7.patch","issue_url":"https://api.github.com/repos/osu-mist/catalog-api-test/issues/7","number":7,"state":"open","locked":false,"title":"Feature/cat 37 implement more requests","user":{"login":"brandonlee503","id":6958498,"avatar_url":"https://avatars.githubusercontent.com/u/6958498?v=3","gravatar_id":"","url":"https://api.github.com/users/brandonlee503","html_url":"https://github.com/brandonlee503","followers_url":"https://api.github.com/users/brandonlee503/followers","following_url":"https://api.github.com/users/brandonlee503/following{/other_user}","gists_url":"https://api.github.com/users/brandonlee503/gists{/gist_id}","starred_url":"https://api.github.com/users/brandonlee503/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brandonlee503/subscriptions","organizations_url":"https://api.github.com/users/brandonlee503/orgs","repos_url":"https://api.github.com/users/brandonlee503/repos","events_url":"https://api.github.com/users/brandonlee503/events{/privacy}","received_events_url":"https://api.github.com/users/brandonlee503/received_events","type":"User","site_admin":false},"body":"Second major merge...","created_at":"2015-07-20T22:19:12Z","updated_at":"2015-07-20T23:16:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"04ab0f94fd4d7283681b606e465c6629ea7fa422","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/osu-mist/catalog-api-test/pulls/7/commits","review_comments_url":"https://api.github.com/repos/osu-mist/catalog-api-test/pulls/7/comments","review_comment_url":"https://api.github.com/repos/osu-mist/catalog-api-test/pulls/comments{/number}","comments_url":"https://api.github.com/repos/osu-mist/catalog-api-test/issues/7/comments","statuses_url":"https://api.github.com/repos/osu-mist/catalog-api-test/statuses/fcf4654f688a2161028e76a94ea6fc7f255a8ee8","head":{"label":"osu-mist:feature/CAT-37-Implement-More-Requests","ref":"feature/CAT-37-Implement-More-Requests","sha":"fcf4654f688a2161028e76a94ea6fc7f255a8ee8","user":{"login":"osu-mist","id":6473936,"avatar_url":"https://avatars.githubusercontent.com/u/6473936?v=3","gravatar_id":"","url":"https://api.github.com/users/osu-mist","html_url":"https://github.com/osu-mist","followers_url":"https://api.github.com/users/osu-mist/followers","following_url":"https://api.github.com/users/osu-mist/following{/other_user}","gists_url":"https://api.github.com/users/osu-mist/gists{/gist_id}","starred_url":"https://api.github.com/users/osu-mist/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/osu-mist/subscriptions","organizations_url":"https://api.github.com/users/osu-mist/orgs","repos_url":"https://api.github.com/users/osu-mist/repos","events_url":"https://api.github.com/users/osu-mist/events{/privacy}","received_events_url":"https://api.github.com/users/osu-mist/received_events","type":"Organization","site_admin":false},"repo":{"id":35060768,"name":"catalog-api-test","full_name":"osu-mist/catalog-api-test","owner":{"login":"osu-mist","id":6473936,"avatar_url":"https://avatars.githubusercontent.com/u/6473936?v=3","gravatar_id":"","url":"https://api.github.com/users/osu-mist","html_url":"https://github.com/osu-mist","followers_url":"https://api.github.com/users/osu-mist/followers","following_url":"https://api.github.com/users/osu-mist/following{/other_user}","gists_url":"https://api.github.com/users/osu-mist/gists{/gist_id}","starred_url":"https://api.github.com/users/osu-mist/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/osu-mist/subscriptions","organizations_url":"https://api.github.com/users/osu-mist/orgs","repos_url":"https://api.github.com/users/osu-mist/repos","events_url":"https://api.github.com/users/osu-mist/events{/privacy}","received_events_url":"https://api.github.com/users/osu-mist/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/osu-mist/catalog-api-test","description":"Test application to learn dropwizard. Pulls data on computer science courses.  Makes data accessible through REST.","fork":false,"url":"https://api.github.com/repos/osu-mist/catalog-api-test","forks_url":"https://api.github.com/repos/osu-mist/catalog-api-test/forks","keys_url":"https://api.github.com/repos/osu-mist/catalog-api-test/keys{/key_id}","collaborators_url":"https://api.github.com/repos/osu-mist/catalog-api-test/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/osu-mist/catalog-api-test/teams","hooks_url":"https://api.github.com/repos/osu-mist/catalog-api-test/hooks","issue_events_url":"https://api.github.com/repos/osu-mist/catalog-api-test/issues/events{/number}","events_url":"https://api.github.com/repos/osu-mist/catalog-api-test/events","assignees_url":"https://api.github.com/repos/osu-mist/catalog-api-test/assignees{/user}","branches_url":"https://api.github.com/repos/osu-mist/catalog-api-test/branches{/branch}","tags_url":"https://api.github.com/repos/osu-mist/catalog-api-test/tags","blobs_url":"https://api.github.com/repos/osu-mist/catalog-api-test/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/osu-mist/catalog-api-test/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/osu-mist/catalog-api-test/git/refs{/sha}","trees_url":"https://api.github.com/repos/osu-mist/catalog-api-test/git/trees{/sha}","statuses_url":"https://api.github.com/repos/osu-mist/catalog-api-test/statuses/{sha}","languages_url":"https://api.github.com/repos/osu-mist/catalog-api-test/languages","stargazers_url":"https://api.github.com/repos/osu-mist/catalog-api-test/stargazers","contributors_url":"https://api.github.com/repos/osu-mist/catalog-api-test/contributors","subscribers_url":"https://api.github.com/repos/osu-mist/catalog-api-test/subscribers","subscription_url":"https://api.github.com/repos/osu-mist/catalog-api-test/subscription","commits_url":"https://api.github.com/repos/osu-mist/catalog-api-test/commits{/sha}","git_commits_url":"https://api.github.com/repos/osu-mist/catalog-api-test/git/commits{/sha}","comments_url":"https://api.github.com/repos/osu-mist/catalog-api-test/comments{/number}","issue_comment_url":"https://api.github.com/repos/osu-mist/catalog-api-test/issues/comments{/number}","contents_url":"https://api.github.com/repos/osu-mist/catalog-api-test/contents/{+path}","compare_url":"https://api.github.com/repos/osu-mist/catalog-api-test/compare/{base}...{head}","merges_url":"https://api.github.com/repos/osu-mist/catalog-api-test/merges","archive_url":"https://api.github.com/repos/osu-mist/catalog-api-test/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/osu-mist/catalog-api-test/downloads","issues_url":"https://api.github.com/repos/osu-mist/catalog-api-test/issues{/number}","pulls_url":"https://api.github.com/repos/osu-mist/catalog-api-test/pulls{/number}","milestones_url":"https://api.github.com/repos/osu-mist/catalog-api-test/milestones{/number}","notifications_url":"https://api.github.com/repos/osu-mist/catalog-api-test/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/osu-mist/catalog-api-test/labels{/name}","releases_url":"https://api.github.com/repos/osu-mist/catalog-api-test/releases{/id}","created_at":"2015-05-04T21:29:22Z","updated_at":"2015-07-14T21:54:38Z","pushed_at":"2015-07-20T22:19:12Z","git_url":"git://github.com/osu-mist/catalog-api-test.git","ssh_url":"git@github.com:osu-mist/catalog-api-test.git","clone_url":"https://github.com/osu-mist/catalog-api-test.git","svn_url":"https://github.com/osu-mist/catalog-api-test","homepage":null,"size":912,"stargazers_count":2,"watchers_count":2,"language":"Groovy","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":2,"default_branch":"develop"}},"base":{"label":"osu-mist:develop","ref":"develop","sha":"94f7e31c886991af06be7fbffb8b439260780ab3","user":{"login":"osu-mist","id":6473936,"avatar_url":"https://avatars.githubusercontent.com/u/6473936?v=3","gravatar_id":"","url":"https://api.github.com/users/osu-mist","html_url":"https://github.com/osu-mist","followers_url":"https://api.github.com/users/osu-mist/followers","following_url":"https://api.github.com/users/osu-mist/following{/other_user}","gists_url":"https://api.github.com/users/osu-mist/gists{/gist_id}","starred_url":"https://api.github.com/users/osu-mist/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/osu-mist/subscriptions","organizations_url":"https://api.github.com/users/osu-mist/orgs","repos_url":"https://api.github.com/users/osu-mist/repos","events_url":"https://api.github.com/users/osu-mist/events{/privacy}","received_events_url":"https://api.github.com/users/osu-mist/received_events","type":"Organization","site_admin":false},"repo":{"id":35060768,"name":"catalog-api-test","full_name":"osu-mist/catalog-api-test","owner":{"login":"osu-mist","id":6473936,"avatar_url":"https://avatars.githubusercontent.com/u/6473936?v=3","gravatar_id":"","url":"https://api.github.com/users/osu-mist","html_url":"https://github.com/osu-mist","followers_url":"https://api.github.com/users/osu-mist/followers","following_url":"https://api.github.com/users/osu-mist/following{/other_user}","gists_url":"https://api.github.com/users/osu-mist/gists{/gist_id}","starred_url":"https://api.github.com/users/osu-mist/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/osu-mist/subscriptions","organizations_url":"https://api.github.com/users/osu-mist/orgs","repos_url":"https://api.github.com/users/osu-mist/repos","events_url":"https://api.github.com/users/osu-mist/events{/privacy}","received_events_url":"https://api.github.com/users/osu-mist/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/osu-mist/catalog-api-test","description":"Test application to learn dropwizard. Pulls data on computer science courses.  Makes data accessible through REST.","fork":false,"url":"https://api.github.com/repos/osu-mist/catalog-api-test","forks_url":"https://api.github.com/repos/osu-mist/catalog-api-test/forks","keys_url":"https://api.github.com/repos/osu-mist/catalog-api-test/keys{/key_id}","collaborators_url":"https://api.github.com/repos/osu-mist/catalog-api-test/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/osu-mist/catalog-api-test/teams","hooks_url":"https://api.github.com/repos/osu-mist/catalog-api-test/hooks","issue_events_url":"https://api.github.com/repos/osu-mist/catalog-api-test/issues/events{/number}","events_url":"https://api.github.com/repos/osu-mist/catalog-api-test/events","assignees_url":"https://api.github.com/repos/osu-mist/catalog-api-test/assignees{/user}","branches_url":"https://api.github.com/repos/osu-mist/catalog-api-test/branches{/branch}","tags_url":"https://api.github.com/repos/osu-mist/catalog-api-test/tags","blobs_url":"https://api.github.com/repos/osu-mist/catalog-api-test/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/osu-mist/catalog-api-test/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/osu-mist/catalog-api-test/git/refs{/sha}","trees_url":"https://api.github.com/repos/osu-mist/catalog-api-test/git/trees{/sha}","statuses_url":"https://api.github.com/repos/osu-mist/catalog-api-test/statuses/{sha}","languages_url":"https://api.github.com/repos/osu-mist/catalog-api-test/languages","stargazers_url":"https://api.github.com/repos/osu-mist/catalog-api-test/stargazers","contributors_url":"https://api.github.com/repos/osu-mist/catalog-api-test/contributors","subscribers_url":"https://api.github.com/repos/osu-mist/catalog-api-test/subscribers","subscription_url":"https://api.github.com/repos/osu-mist/catalog-api-test/subscription","commits_url":"https://api.github.com/repos/osu-mist/catalog-api-test/commits{/sha}","git_commits_url":"https://api.github.com/repos/osu-mist/catalog-api-test/git/commits{/sha}","comments_url":"https://api.github.com/repos/osu-mist/catalog-api-test/comments{/number}","issue_comment_url":"https://api.github.com/repos/osu-mist/catalog-api-test/issues/comments{/number}","contents_url":"https://api.github.com/repos/osu-mist/catalog-api-test/contents/{+path}","compare_url":"https://api.github.com/repos/osu-mist/catalog-api-test/compare/{base}...{head}","merges_url":"https://api.github.com/repos/osu-mist/catalog-api-test/merges","archive_url":"https://api.github.com/repos/osu-mist/catalog-api-test/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/osu-mist/catalog-api-test/downloads","issues_url":"https://api.github.com/repos/osu-mist/catalog-api-test/issues{/number}","pulls_url":"https://api.github.com/repos/osu-mist/catalog-api-test/pulls{/number}","milestones_url":"https://api.github.com/repos/osu-mist/catalog-api-test/milestones{/number}","notifications_url":"https://api.github.com/repos/osu-mist/catalog-api-test/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/osu-mist/catalog-api-test/labels{/name}","releases_url":"https://api.github.com/repos/osu-mist/catalog-api-test/releases{/id}","created_at":"2015-05-04T21:29:22Z","updated_at":"2015-07-14T21:54:38Z","pushed_at":"2015-07-20T22:19:12Z","git_url":"git://github.com/osu-mist/catalog-api-test.git","ssh_url":"git@github.com:osu-mist/catalog-api-test.git","clone_url":"https://github.com/osu-mist/catalog-api-test.git","svn_url":"https://github.com/osu-mist/catalog-api-test","homepage":null,"size":912,"stargazers_count":2,"watchers_count":2,"language":"Groovy","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":2,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/osu-mist/catalog-api-test/pulls/7"},"html":{"href":"https://github.com/osu-mist/catalog-api-test/pull/7"},"issue":{"href":"https://api.github.com/repos/osu-mist/catalog-api-test/issues/7"},"comments":{"href":"https://api.github.com/repos/osu-mist/catalog-api-test/issues/7/comments"},"review_comments":{"href":"https://api.github.com/repos/osu-mist/catalog-api-test/pulls/7/comments"},"review_comment":{"href":"https://api.github.com/repos/osu-mist/catalog-api-test/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/osu-mist/catalog-api-test/pulls/7/commits"},"statuses":{"href":"https://api.github.com/repos/osu-mist/catalog-api-test/statuses/fcf4654f688a2161028e76a94ea6fc7f255a8ee8"}}}}