Commit 029883ad authored by Øyvin Halfdan Thuv's avatar Øyvin Halfdan Thuv
Browse files

Adding POST method example.

parent 49a50f2f
......@@ -4,8 +4,12 @@ import java.util.UUID;
public class Incident {
private final UUID id;
private final String name;
private UUID id;
private String name;
public Incident() {
}
public Incident(UUID id, String name) {
this.id = id;
......@@ -13,11 +17,19 @@ public class Incident {
}
public UUID getId() {
return id;
return this.id;
}
public String getName() {
return this.name;
}
public void setId(UUID id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
}
package statelessws;
import com.datastax.driver.core.PreparedStatement;
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
......@@ -7,8 +8,11 @@ import com.datastax.driver.core.Session;
import java.util.concurrent.atomic.AtomicLong;
import java.util.ArrayList;
import java.util.UUID;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
......@@ -31,6 +35,8 @@ public class IncidentController {
}
/*
* Prerequisite for DB:
*
* USE storage;
* CREATE TABLE incident ( id uuid PRIMARY KEY, name text );
*/
......@@ -45,5 +51,22 @@ public class IncidentController {
}
return incidents;
}
/*
* Prerequisite for DB:
*
* USE storage;
* CREATE TABLE incident ( id uuid PRIMARY KEY, name text );
*/
@RequestMapping(value="/incidents", method=RequestMethod.POST)
public Incident newIncident(@RequestBody Incident i) {
UUID id = UUID.randomUUID();
PreparedStatement statement =
session.prepare("INSERT INTO incident (id, name)" +
" VALUES (?, ?)");
session.execute(statement.bind(id, i.getName()));
i.setId(id);
return i;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment