post dev
This commit is contained in:
@@ -223,4 +223,46 @@ public class Routes {
|
||||
if (root_post.isEmpty()) throw new ResponseStatusException(HttpStatus.NOT_FOUND, "No post found");
|
||||
return root_post.get();
|
||||
}
|
||||
|
||||
@PostMapping("/posts")
|
||||
public JodelPost postPost(@RequestBody JodelPost post) {
|
||||
// DB connection and statement
|
||||
Connection c = null;
|
||||
PreparedStatement stmt = null;
|
||||
|
||||
System.out.println(post);
|
||||
|
||||
// try to get data from db
|
||||
try {
|
||||
// check for the driver
|
||||
Class.forName("org.postgresql.Driver");
|
||||
// get the connection with credentials from env variables
|
||||
c = DriverManager
|
||||
.getConnection("jdbc:postgresql://"+
|
||||
System.getenv("POSTGRES_IP")+"/"+System.getenv("POSTGRES_DB"),
|
||||
System.getenv("POSTGRES_USER"), System.getenv("POSTGRES_PASSWORD"));
|
||||
// disable auto commits
|
||||
c.setAutoCommit(false);
|
||||
|
||||
// create a new statement
|
||||
stmt = c.prepareStatement("");
|
||||
|
||||
//stmt.setObject();
|
||||
|
||||
// query recursively for posts inside a 10km radius
|
||||
stmt.execute();
|
||||
|
||||
// close all connections to db
|
||||
stmt.close();
|
||||
c.close();
|
||||
}
|
||||
|
||||
// else log the error
|
||||
catch ( Exception e ) {
|
||||
System.err.println( e.getClass().getName()+": "+ e.getMessage() );
|
||||
throw new ResponseStatusException(HttpStatus.SERVICE_UNAVAILABLE, "Database is offline");
|
||||
}
|
||||
|
||||
return post;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user