Skip to content

Commit a810766

Browse files
committed
Fixed issues on property managemen
1 parent d2597db commit a810766

File tree

4 files changed

+93
-10
lines changed

4 files changed

+93
-10
lines changed

microservice-common/src/main/java/io/vertx/easyerp/microservice/common/RestAPIVerticle.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,18 @@ protected <T> Handler<AsyncResult<T>> resultHandler(RoutingContext context) {
154154
};
155155
}
156156

157+
protected <T> Handler<AsyncResult<T>> resultHandler(RoutingContext context, int status) {
158+
return ar -> {
159+
if (ar.succeeded()) {
160+
T res = ar.result();
161+
context.response()
162+
.setStatusCode(status == 0 ? 200 : status)
163+
.putHeader("Content-type", "application/json")
164+
.end(res == null ? "{}" : new JsonObject().put("msg", res.toString()).encodePrettily());
165+
}
166+
};
167+
}
168+
157169
protected <T> Handler<AsyncResult<T>> resultHandler(RoutingContext context, Function<T, String> converter) {
158170
return ar -> {
159171
if (ar.succeeded()) {
@@ -227,6 +239,7 @@ protected <T> Handler<AsyncResult<T>> rawResultHandler(RoutingContext context) {
227239
};
228240
}
229241

242+
230243
/**
231244
* This method generates handler for jooq.async methods in REST APIs.
232245
* The result is not needed. Only the state of the jooq.async result is required.
@@ -250,6 +263,8 @@ protected Handler<AsyncResult<Void>> resultVoidHandler(RoutingContext context, J
250263
};
251264
}
252265

266+
267+
253268
protected Handler<AsyncResult<Void>> resultVoidHandler(RoutingContext context, int status) {
254269
return ar -> {
255270
if (ar.succeeded()) {
@@ -276,7 +291,8 @@ protected Handler<AsyncResult<Void>> resultVoidHandler(RoutingContext context, i
276291
* @param context routing context instance
277292
* @return generated handler
278293
*/
279-
protected Handler<AsyncResult<Void>> deleteResultHandler(RoutingContext context) {
294+
295+
protected<T> Handler<AsyncResult<T>> deleteResultHandler(RoutingContext context) {
280296
return res -> {
281297
if (res.succeeded()) {
282298
context.response().setStatusCode(204)
@@ -289,6 +305,8 @@ protected Handler<AsyncResult<Void>> deleteResultHandler(RoutingContext context)
289305
};
290306
}
291307

308+
309+
292310
// helper method dealing with failure
293311

294312
protected void internalError(RoutingContext context, Throwable ex) {

microservice-common/src/main/java/io/vertx/easyerp/microservice/common/service/JooqRepositoryWrapper.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,4 @@ protected Future<SQLConnection> getConnection() {
5959
this.nonShared.getConnection(promise);
6060
return promise.future();
6161
}
62-
63-
protected AsyncClassicGenericQueryExecutor queryExecutor(){
64-
return this.executor;
65-
}
66-
6762
}

property-management-microservice/src/main/java/io/vertx/easyerp/microservice/propertymanagement/api/PropertyManagementRestVerticle.java

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
import io.vertx.core.Promise;
44
import io.vertx.easyerp.microservice.common.RestAPIVerticle;
55
import io.vertx.easyerp.microservice.propertymanagement.PropertyManagementService;
6+
import io.vertx.easyerp.microservice.propertymanagement.jpojo.Accommodation;
7+
import io.vertx.easyerp.microservice.propertymanagement.jpojo.PropertyAmenity;
8+
import io.vertx.easyerp.microservice.propertymanagement.jpojo.PropertyProfile;
69
import io.vertx.ext.web.Router;
10+
import io.vertx.ext.web.RoutingContext;
711
import org.slf4j.Logger;
812
import org.slf4j.LoggerFactory;
913

@@ -42,17 +46,83 @@ public void start(Promise<Void> startPromise) throws Exception {
4246
final Router router = enableRouteLoggingSupport(Router.router(vertx));
4347

4448
// api route handler
45-
/*router.post(API_ADD).handler(this::apiAddUser);
49+
/*
50+
router.post(API_ADD).handler(this::apiAddUser);
4651
router.get(API_RETRIEVE).handler(this::apiRetrieveUser);
4752
router.get(API_RETRIEVE_ALL).handler(this::apiRetrieveAll);
4853
router.patch(API_UPDATE).handler(this::apiUpdateUser);
4954
router.delete(API_DELETE).handler(this::apiDeleteUser);
50-
*/
55+
*/
56+
57+
router.post(API_PROFILE_ADD).handler(this::addPropProfile);
58+
5159
String host = config().getString("property.http.address", "0.0.0.0");
5260
int port = config().getInteger("property.http.port", 8085);
5361

5462
createHttpServer(router, host, port)
5563
.compose(serverCreated -> publishHttpEndpoint(SERVICE_NAME, host, port))
5664
.onComplete(startPromise);
5765
}
66+
67+
private void addPropProfile(RoutingContext context){
68+
PropertyProfile profile = new PropertyProfile(context.getBodyAsJson());
69+
service.createProfile(profile, resultHandler(context, 201));
70+
}
71+
72+
private void editPropProfile(RoutingContext context){
73+
notImplemented(context);
74+
}
75+
76+
private void fetcPropProfile(RoutingContext context){
77+
String id = context.request().getParam("id");
78+
service.retrieveProfile(id, resultHandlerNonEmpty(context));
79+
}
80+
81+
private void deletePropProfile(RoutingContext context){
82+
String serialNo = context.request().getParam("Id");
83+
service.deleteProfile(serialNo, deleteResultHandler(context));
84+
}
85+
86+
private void addPropAmenity(RoutingContext context){
87+
PropertyAmenity propertyAmenity = new PropertyAmenity((context.getBodyAsJson()));
88+
service.createAmenity(propertyAmenity, resultHandler(context, 201));
89+
}
90+
91+
private void editPropAmenity(RoutingContext context){
92+
notImplemented(context);
93+
}
94+
95+
private void fetchPropAmenities(RoutingContext context){
96+
service.retrieveAmenities(resultHandlerNonEmpty(context));
97+
}
98+
99+
100+
private void deletePropAmenity(RoutingContext context){
101+
String serialNo = context.request().getParam("Id");
102+
service.deleteAmenity(serialNo, deleteResultHandler(context));
103+
}
104+
105+
private void addAccommodation(RoutingContext context){
106+
Accommodation accommodation = new Accommodation(context.getBodyAsJson());
107+
service.createAccommodation(accommodation, resultHandler(context, 201));
108+
}
109+
110+
111+
private void fetchAccommodations(RoutingContext context){
112+
service.retrieveAllAccommodations(resultHandlerNonEmpty(context));
113+
}
114+
115+
private void fetchAccommodation(RoutingContext context){
116+
String id = context.request().getParam("id");
117+
service.retrieveAccommodation(id , resultHandlerNonEmpty(context));
118+
}
119+
120+
121+
private void deleteAccommodation(RoutingContext context){
122+
String serialNo = context.request().getParam("Id");
123+
service.deleteAccommodation(serialNo, deleteResultHandler(context));
124+
}
125+
58126
}
127+
128+

property-management-microservice/src/main/java/io/vertx/easyerp/microservice/propertymanagement/jpojo/Accommodation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ public class Accommodation {
1818
private String createdBy;
1919

2020
public Accommodation(JsonObject json) {
21-
// PropertyProfileConverter.fromJson(json, this);
21+
AccomodationConverter.fromJson(json, this);
2222
}
2323

2424
public JsonObject toJson() {
2525
JsonObject json = new JsonObject();
26-
//PropertyProfileConverter.toJson(this, json);
26+
AccomodationConverter.toJson(this, json);
2727
return json;
2828
}
2929

0 commit comments

Comments
 (0)