Skip to content

Instantly share code, notes, and snippets.

@hugithordarson
Created January 19, 2017 22:57
Show Gist options
  • Save hugithordarson/ae1f924dba293adcf58d49276d2ef16f to your computer and use it in GitHub Desktop.
Save hugithordarson/ae1f924dba293adcf58d49276d2ef16f to your computer and use it in GitHub Desktop.
package stuffmaker;
import static spark.Spark.*;
import java.util.List;
import org.apache.cayenne.query.ObjectSelect;
import com.google.gson.GsonBuilder;
import strimillinn.core.StrimillinnCore;
import strimillinn.core.model.Chain;
import strimillinn.core.model.Entry;
import strimillinn.core.model.Receipt;
import strimillinn.core.model.Shop;
import strimillinn.core.model.User;
public class HelloWorld {
public static void main( String[] args ) {
get( "/user/:name", ( req, res ) -> {
List<Object[]> list = ObjectSelect
.query( Entry.class )
.where( Entry.RECEIPT.dot( Receipt.USER ).dot( User.NAME ).eq( req.params( "name" ) ) )
.columns( Entry.TEXT, Entry.PRICE, Entry.RECEIPT.dot( Receipt.SHOP ).dot( Shop.CHAIN ).dot( Chain.NAME ) )
.orderBy( Entry.TEXT.desc() )
.select( StrimillinnCore.newContext() );
res.header( "content-type", "text-html" );
return "<pre style=\"color:red\">" + new GsonBuilder().setPrettyPrinting().create().toJson( list ) + "</pre>";
} );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment