Skip to content

Commit

Permalink
4.3.2 update. Inject Config directly into Module method.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilya authored and Ilya committed Apr 10, 2017
1 parent 5c4932b commit 4cec9bd
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<packaging>jar</packaging>
<url>https://mangoo.io</url>
<properties>
<mangooio.version>4.3.0</mangooio.version>
<mangooio.version>4.3.2</mangooio.version>
<jooq.version>3.9.1</jooq.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<db.url>jdbc:h2:mem:todobackend;INIT=runscript from 'src/main/resources/db/init.sql';</db.url>
Expand Down
19 changes: 8 additions & 11 deletions src/main/java/conf/Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.google.inject.Singleton;
import filters.CorsFilter;
import io.mangoo.configuration.Config;
import io.mangoo.core.Application;
import io.mangoo.interfaces.MangooLifecycle;
import io.mangoo.interfaces.MangooRequestFilter;
import org.h2.jdbcx.JdbcDataSource;
Expand All @@ -24,18 +23,16 @@ protected void configure() {
}

@Provides @Singleton
DSLContext provideJooqContext() {
Config CONFIG = Application.getConfig();

DSLContext provideJooqContext(Config config) {
JdbcDataSource h2ds = new JdbcDataSource();
h2ds.setURL(CONFIG.getString("application.db.url"));
h2ds.setUser(CONFIG.getString("application.db.username"));
h2ds.setPassword(CONFIG.getString("application.db.password"));
h2ds.setURL(config.getString("application.db.url"));
h2ds.setUser(config.getString("application.db.username"));
h2ds.setPassword(config.getString("application.db.password"));

DefaultConfiguration config = new DefaultConfiguration();
config.setDataSource(h2ds);
config.setSQLDialect(SQLDialect.H2);
DefaultConfiguration defConfig = new DefaultConfiguration();
defConfig.setDataSource(h2ds);
defConfig.setSQLDialect(SQLDialect.H2);

return DSL.using(config);
return DSL.using(defConfig);
}
}
14 changes: 13 additions & 1 deletion src/main/java/controllers/ApplicationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.inject.Inject;
import io.mangoo.routing.Response;
import io.mangoo.routing.bindings.Session;
import model.Todo;
import org.jooq.DSLContext;

Expand All @@ -20,11 +21,22 @@ public Response index() {
return Response.withOk().andJsonBody(result);
}

public Response todo() {
public Response todo(Session session) {
session.put("1", "2");

return Response.withOk().andJsonBody("TODO");
}

public Response options() {
return Response.withOk().andEmptyBody();
}

//POST: {"title":"a todo"}
//{"title":"a todo","completed":false,"url":"http://todobackend-spring.herokuapp.com//28","order":null}

//DELETE: / - deletes all todos
//

//GET: / - returns all as an array
//[{"id":1,"title":"walk the dog","completed":false,"order":0,"url":"https://todo-backend-spring4-java8.herokuapp.com/todos/1"}]
}
2 changes: 1 addition & 1 deletion src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ dev:
# cryptex[XnrslCZdmq9BW27skRxH5g==]
# master password: sderokfoksm458349034rkwelkw34njk
password: $2a$12$dLSHOqKzDEt6tictTGbn8epV0kTEbiWpHx/VVRDoUVpFiS2bu6I6y #12345 - JBcrypt
masterkey: /Users/ilya/Work/Projects/todobackend-mangooio/master.txt
masterkey: /Users/ilya/Work/Projects/todobackend-mangooio/master.txt
connector:
http:
host : localhost
Expand Down

0 comments on commit 4cec9bd

Please sign in to comment.