Commit 606a4405 by Denys Tito Urbano

[CREATE] Api Academia y DAO agregados

parent b663908b
package pe.edu.sacooliveros.trismegisto.mongo.api.api;
import javax.ws.rs.BadRequestException;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.Consumes;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
import org.json.JSONObject;
import pe.edu.sacooliveros.trismegisto.mongo.api.service.AcademiaService;
@Path("academia")
@Produces("application/json")
@Consumes("application/json")
public class AcademiaApi {
@POST
@Path("aula")
public Response aulaCrear(String json) {
JSONObject salida = new JSONObject();
try {
JSONObject entrada = new JSONObject(json);
salida = new AcademiaService().aulaCrear(entrada);
return Response.status(200).entity(salida.toString()).build();
} catch (Exception ex) {
salida
.put("status", false)
.put("message", ex.getMessage())
.put("data", JSONObject.NULL);
throw new WebApplicationException(Response.status(500).entity(salida.toString()).build());
}
}
}
...@@ -16,6 +16,8 @@ public class ApplicationConfig extends Application { ...@@ -16,6 +16,8 @@ public class ApplicationConfig extends Application {
corsFilter.getAllowedOrigins().add("*"); corsFilter.getAllowedOrigins().add("*");
corsFilter.setAllowedMethods("OPTIONS, GET, POST, DELETE, PUT, PATCH"); corsFilter.setAllowedMethods("OPTIONS, GET, POST, DELETE, PUT, PATCH");
singletons.add(corsFilter); singletons.add(corsFilter);
classes.add(AcademiaApi.class);
} }
@Override @Override
......
package pe.edu.sacooliveros.trismegisto.mongo.api.dao;
import org.json.JSONObject;
public interface AcademiaDAO {
public JSONObject aulaCrear(JSONObject entrada) throws Exception;
}
package pe.edu.sacooliveros.trismegisto.mongo.api.dao;
import org.json.JSONObject;
public abstract class DAO {
protected static JSONObject query() throws Exception {
return new JSONObject();
}
}
package pe.edu.sacooliveros.trismegisto.mongo.api.dao;
import pe.edu.sacooliveros.trismegisto.mongo.api.mongodbdao.MongoDBFactoryDAO;
public abstract class FactoryDAO extends DAO {
public static final int MONGODB = 1;
public static final int POSTGRESQL = 2;
public static FactoryDAO getFactoryDAO(int whichFactory) {
switch (whichFactory) {
case MONGODB:
return new MongoDBFactoryDAO();
/*case POSTGRESQL:
return new PostgreSqlFactoryDAO();*/
default:
return null;
}
}
public abstract AcademiaDAO getAcademiaDAO();
}
package pe.edu.sacooliveros.trismegisto.mongo.api.mongodbdao;
import org.json.JSONObject;
import pe.edu.sacooliveros.trismegisto.mongo.api.dao.AcademiaDAO;
public class AcademiaMongoDB implements AcademiaDAO {
@Override
public JSONObject aulaCrear(JSONObject entrada) throws Exception {
return new JSONObject()
.put("status", true)
.put("message", "Éxito")
.put("data", entrada);
}
}
package pe.edu.sacooliveros.trismegisto.mongo.api.mongodbdao;
import pe.edu.sacooliveros.trismegisto.mongo.api.dao.AcademiaDAO;
import pe.edu.sacooliveros.trismegisto.mongo.api.dao.FactoryDAO;
public class MongoDBFactoryDAO extends FactoryDAO {
@Override
public AcademiaDAO getAcademiaDAO() {
return new AcademiaMongoDB();
}
}
package pe.edu.sacooliveros.trismegisto.mongo.api.service;
import org.json.JSONException;
import org.json.JSONObject;
import pe.edu.sacooliveros.trismegisto.mongo.api.dao.AcademiaDAO;
import pe.edu.sacooliveros.trismegisto.mongo.api.dao.FactoryDAO;
public class AcademiaService {
AcademiaDAO dao = FactoryDAO.getFactoryDAO(FactoryDAO.MONGODB).getAcademiaDAO();
public JSONObject aulaCrear(JSONObject entrada) throws JSONException, Exception {
return dao.aulaCrear(entrada);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment