Commit 49a50f2f authored by Øyvin Halfdan Thuv's avatar Øyvin Halfdan Thuv
Browse files

Returning list of incidents instead of single incident.

parent 50fe14b6
......@@ -5,6 +5,7 @@ import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
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.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
......@@ -29,20 +30,20 @@ public class IncidentController {
session = cluster.connect("storage");
}
/*
* USE storage;
* CREATE TABLE incident ( id uuid PRIMARY KEY, name text );
* INSERT INTO incident (id, name) VALUES (0, 'Great incident');
*/
@RequestMapping("/incidents")
public Incident incident() {
ResultSet incidents = session.execute("SELECT * FROM incident");
Row incident = incidents.one();
return new Incident(incident.getUUID("id"),
incident.getString("name"));
public ArrayList<Incident> incidents() {
ResultSet rows =
session.execute("SELECT * FROM incident");
ArrayList<Incident> incidents = new ArrayList<Incident>();
for (Row row : rows) {
incidents.add(new Incident(row.getUUID("id"),
row.getString("name")));
}
return incidents;
}
}
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