webmarker-server/src/main/java/net/mindoverflow/webmarker/webserver/WebApplication.java

59 lines
1.9 KiB
Java

package net.mindoverflow.webmarker.webserver;
import net.mindoverflow.webmarker.utils.URLMap;
import ro.pippo.controller.ControllerApplication;
import ro.pippo.core.route.TrailingSlashHandler;
import java.util.List;
public class WebApplication extends ControllerApplication {
@Override
protected void onInit() {
GET("/save", routeContext -> routeContext.send("Please append an user ID"));
GET("/save/{id}", routeContext -> routeContext.send("Please append an URL"));
GET("/save/{id}/{url}", routeContext ->
{
int userId = routeContext.getParameter("id").toInt();
String saveUrl = routeContext.getParameter("url").toString();
URLMap.saveUrl(userId, saveUrl);
routeContext.send("Saved!");
});
GET("/get", routeContext -> routeContext.send("Please append an user ID"));
GET("/get/{id}", routeContext ->
{
int userId = routeContext.getParameter("id").toInt();
List<String> urls = URLMap.getUserUrls(userId);
StringBuilder urlsSB = new StringBuilder(" | ");
for(String url : urls)
{
urlsSB.append(url).append(" | ");
}
routeContext.send(urlsSB.toString());
});
GET("/drop", routeContext -> routeContext.send("Please append an user ID"));
GET("/drop/{id}", routeContext ->
{
int userId = routeContext.getParameter("id").toInt();
URLMap.dropUser(userId);
routeContext.send("Dropped!");
});
POST("/post", routeContext -> {
int userId = routeContext.getParameter("id").toInt();
String url = routeContext.getParameter("url").toString();
routeContext.send("AAAAAAAAAAAAA " + url);
});
ANY("/.*", new TrailingSlashHandler(false)); // remove trailing slash
}
}