-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MoneyTransfer example API ready, w/o database part and validation
- Loading branch information
Showing
16 changed files
with
655 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#template: Hello, %s! | ||
#defaultName: ${DW_DEFAULT_NAME:-Stranger} | ||
|
||
# Database settings. | ||
database: | ||
# the name of your JDBC driver | ||
driverClass: org.h2.Driver | ||
# the username | ||
user: sa | ||
# the password | ||
password: | ||
# the JDBC URL | ||
url: jdbc:h2:mem:~/money;DB_CLOSE_ON_EXIT=FALSE | ||
|
||
# use the simple server factory if you only want to run on a single port | ||
#server: | ||
# type: simple | ||
# connector: | ||
# type: http | ||
# port: 8080 | ||
|
||
server: | ||
# softNofileLimit: 1000 | ||
# hardNofileLimit: 1000 | ||
applicationConnectors: | ||
- type: http | ||
port: 8080 | ||
adminConnectors: | ||
- type: http | ||
port: 8081 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
money_transfer_api/src/main/java/net/iryndin/mtapi/MTAPIApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package net.iryndin.mtapi; | ||
|
||
import io.dropwizard.Application; | ||
import io.dropwizard.db.DataSourceFactory; | ||
import io.dropwizard.hibernate.HibernateBundle; | ||
import io.dropwizard.setup.Bootstrap; | ||
import io.dropwizard.setup.Environment; | ||
import net.iryndin.mtapi.core.AccountEntity; | ||
import net.iryndin.mtapi.resources.AccountResource; | ||
import net.iryndin.mtapi.resources.TransactionResource; | ||
|
||
/** | ||
* @author iryndin | ||
* @since 10/04/17 | ||
*/ | ||
public class MTAPIApplication extends Application<MTAPIConfiguration> { | ||
|
||
public static void main(String[] args) throws Exception { | ||
new MTAPIApplication().run(args); | ||
} | ||
|
||
private final HibernateBundle<MTAPIConfiguration> hibernateBundle = | ||
new HibernateBundle<MTAPIConfiguration>(AccountEntity.class) { | ||
@Override | ||
public DataSourceFactory getDataSourceFactory(MTAPIConfiguration configuration) { | ||
return configuration.getDataSourceFactory(); | ||
} | ||
}; | ||
|
||
@Override | ||
public String getName() { | ||
return "Money Transfer API"; | ||
} | ||
|
||
@Override | ||
public void initialize(Bootstrap<MTAPIConfiguration> bootstrap) { | ||
bootstrap.addBundle(hibernateBundle); | ||
} | ||
|
||
@Override | ||
public void run(MTAPIConfiguration configuration, Environment environment) { | ||
environment.jersey().register(new AccountResource()); | ||
environment.jersey().register(new TransactionResource()); | ||
/* | ||
environment.healthChecks().register("template", new TemplateHealthCheck(template)); | ||
environment.admin().addTask(new EchoTask()); | ||
environment.jersey().register(DateRequiredFeature.class); | ||
environment.jersey().register(new AuthDynamicFeature(new BasicCredentialAuthFilter.Builder<User>() | ||
.setAuthenticator(new ExampleAuthenticator()) | ||
.setAuthorizer(new ExampleAuthorizer()) | ||
.setRealm("SUPER SECRET STUFF") | ||
.buildAuthFilter())); | ||
environment.jersey().register(new AuthValueFactoryProvider.Binder<>(User.class)); | ||
environment.jersey().register(RolesAllowedDynamicFeature.class); | ||
environment.jersey().register(new HelloWorldResource(template)); | ||
environment.jersey().register(new ViewResource()); | ||
environment.jersey().register(new ProtectedResource()); | ||
environment.jersey().register(new PeopleResource(dao)); | ||
environment.jersey().register(new PersonResource(dao)); | ||
environment.jersey().register(new FilteredResource());*/ | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
money_transfer_api/src/main/java/net/iryndin/mtapi/MTAPIConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package net.iryndin.mtapi; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import io.dropwizard.Configuration; | ||
import io.dropwizard.db.DataSourceFactory; | ||
|
||
import javax.validation.Valid; | ||
import javax.validation.constraints.NotNull; | ||
|
||
/** | ||
* @author iryndin | ||
* @since 10/04/17 | ||
*/ | ||
public class MTAPIConfiguration extends Configuration { | ||
|
||
@Valid | ||
@NotNull | ||
private DataSourceFactory database = new DataSourceFactory(); | ||
|
||
@JsonProperty("database") | ||
public DataSourceFactory getDataSourceFactory() { | ||
return database; | ||
} | ||
|
||
@JsonProperty("database") | ||
public void setDataSourceFactory(DataSourceFactory dataSourceFactory) { | ||
this.database = dataSourceFactory; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
money_transfer_api/src/main/java/net/iryndin/mtapi/api/ApiResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package net.iryndin.mtapi.api; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* @author iryndin | ||
* @since 11/04/17 | ||
*/ | ||
public class ApiResponse { | ||
public static String STATUS_OK = "OK"; | ||
public static String STATUS_FAIL = "FAIL"; | ||
|
||
private String status; | ||
|
||
public ApiResponse() { | ||
} | ||
|
||
public ApiResponse(String status) { | ||
this.status = status; | ||
|
||
} | ||
|
||
|
||
|
||
@JsonProperty | ||
public String getStatus() { | ||
return status; | ||
} | ||
|
||
|
||
} |
27 changes: 27 additions & 0 deletions
27
money_transfer_api/src/main/java/net/iryndin/mtapi/api/ApiResponseError.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package net.iryndin.mtapi.api; | ||
|
||
/** | ||
* @author iryndin | ||
* @since 11/04/17 | ||
*/ | ||
public class ApiResponseError extends ApiResponse { | ||
private String errorMessage; | ||
private Integer errorCode; | ||
|
||
public ApiResponseError() { | ||
} | ||
|
||
public ApiResponseError(String errorMessage, Integer errorCode) { | ||
super(STATUS_FAIL); | ||
this.errorMessage = errorMessage; | ||
this.errorCode = errorCode; | ||
} | ||
|
||
public String getErrorMessage() { | ||
return errorMessage; | ||
} | ||
|
||
public Integer getErrorCode() { | ||
return errorCode; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
money_transfer_api/src/main/java/net/iryndin/mtapi/api/ApiResponseOK.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package net.iryndin.mtapi.api; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
/** | ||
* @author iryndin | ||
* @since 11/04/17 | ||
*/ | ||
public class ApiResponseOK<T> extends ApiResponse { | ||
private T data; | ||
|
||
public ApiResponseOK() { | ||
} | ||
|
||
public ApiResponseOK(T data) { | ||
super(STATUS_OK); | ||
this.data = data; | ||
} | ||
|
||
@JsonProperty | ||
public T getData() { | ||
return data; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
money_transfer_api/src/main/java/net/iryndin/mtapi/api/BalanceResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package net.iryndin.mtapi.api; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
/** | ||
* @author iryndin | ||
* @since 11/04/17 | ||
*/ | ||
public class BalanceResponse { | ||
private long balance; | ||
|
||
public BalanceResponse() { | ||
} | ||
|
||
public BalanceResponse(long balance) { | ||
this.balance = balance; | ||
} | ||
|
||
@JsonProperty | ||
public long getBalance() { | ||
return balance; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
money_transfer_api/src/main/java/net/iryndin/mtapi/api/TransferRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package net.iryndin.mtapi.api; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
/** | ||
* @author iryndin | ||
* @since 11/04/17 | ||
*/ | ||
public class TransferRequest { | ||
private Long amount; | ||
private Integer type; | ||
private String description; | ||
|
||
public TransferRequest() { | ||
} | ||
|
||
public TransferRequest(Long amount, Integer type, String description) { | ||
this.amount = amount; | ||
this.type = type; | ||
this.description = description; | ||
} | ||
|
||
@JsonProperty | ||
public Long getAmount() { | ||
return amount; | ||
} | ||
|
||
@JsonProperty | ||
public Integer getType() { | ||
return type; | ||
} | ||
|
||
@JsonProperty | ||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "TransferRequest{" + | ||
"amount=" + amount + | ||
", type=" + type + | ||
", description='" + description + '\'' + | ||
'}'; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
money_transfer_api/src/main/java/net/iryndin/mtapi/api/TransferResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package net.iryndin.mtapi.api; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
/** | ||
* @author iryndin | ||
* @since 11/04/17 | ||
*/ | ||
public class TransferResponse { | ||
private long txId; | ||
|
||
public TransferResponse() { | ||
} | ||
|
||
public TransferResponse(long txId) { | ||
this.txId = txId; | ||
} | ||
|
||
@JsonProperty | ||
public long getTxId() { | ||
return txId; | ||
} | ||
} |
Oops, something went wrong.