Skip to content
Snippets Groups Projects
Commit af139589 authored by Thomas Mewily's avatar Thomas Mewily
Browse files

clean up code

parent 4130b9ba
Branches
No related tags found
No related merge requests found
Showing
with 25 additions and 82 deletions
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -235,16 +235,20 @@ public class StartServer {
post("/gommettes/update", (req,res)->{
String couleur = req.queryParams("couleur");
Couleur c = Couleur.retrieve(couleur);
String couleurStr = req.queryParams("couleur");
Couleur couleur = Couleur.retrieve(couleurStr);
String description = req.queryParams("description");
String nom = req.queryParams("nom");
String id = req.queryParams("id_selection");
String nom = req.queryParams("nom");
String description = req.queryParams("description");
GommetteEntity gommette = Core.Gommette.getById(Integer.parseInt(id));
gommette.setNom(nom.length() > 0 ? nom : gommette.getNom());
gommette.setCouleur(couleurStr != null ? couleur : gommette.getCouleur());
gommette.setDescription(description.length() > 0 ? description : gommette.getDescription());
Core.Gommette.update(Integer.parseInt(id),nom,c, description);
Core.Gommette.push(gommette);
res.redirect("/gommettes");
return null;
......
......@@ -5,9 +5,11 @@ import com.uca.dao.*;
import com.uca.entity.*;
import java.util.*;
public class GommetteCore extends _DefaultCore<GommetteEntity> {
public static final GommetteCore Instance = new GommetteCore();
private GommetteCore()
{
super(new GommetteDAO());
......@@ -20,50 +22,4 @@ public class GommetteCore extends _DefaultCore<GommetteEntity> {
entity.setDescription(description);
return dao.create(entity);
}
public void update(int id, String nom, Couleur couleur, String description) {
GommetteEntity entity = new GommetteEntity();
GommetteEntity previous = dao.getById(id);
System.out.println(previous.getNom());
if (nom.length() > 0)
{
entity.setNom(nom);
}
else
{
entity.setNom(previous.getNom());
}
if (couleur != null)
{
entity.setCouleur(couleur);
}
else
{
Couleur prev_couleur = previous.getCouleur();
System.out.println(prev_couleur);
entity.setCouleur(previous.getCouleur());
}
if (description.length() > 0)
{
entity.setDescription(description);
}
else
{
entity.setDescription(previous.getDescription());
}
entity.setId(id);
dao.push(entity);
}
}
\ No newline at end of file
......@@ -5,9 +5,11 @@ import com.uca.dao.*;
import com.uca.entity.*;
import java.util.*;
public class ProfCore extends _DefaultCore<ProfEntity> {
public static final ProfCore Instance = new ProfCore();
private ProfCore()
{
super(new ProfDAO());
......
......@@ -5,6 +5,7 @@ import com.uca.dao.*;
import com.uca.entity.*;
import java.util.*;
public class UserCore extends _DefaultCore<UserEntity> {
public static final UserCore Instance = new UserCore();
......
......@@ -12,11 +12,8 @@ import java.sql.SQLException;
public class _Connector {
private static String url = "jdbc:h2:~/test";
private static String user = "sa";
private static String passwd = "";
private static Connection connect;
public static Connection getInstance(){
......@@ -29,6 +26,4 @@ public class _Connector {
}
return connect;
}
}
\ No newline at end of file
......@@ -55,8 +55,7 @@ public abstract class _DefaultDAO<T extends Entity> extends _Generic<T> {
{
ArrayList<T> entities = new ArrayList<>();
try {
PreparedStatement preparedStatement = this.connect
.prepareStatement("SELECT * FROM "+getDefaultTableName()+" ORDER BY id ASC;");
PreparedStatement preparedStatement = this.connect.prepareStatement("SELECT * FROM "+getDefaultTableName()+" ORDER BY id ASC;");
ResultSet resultSet = preparedStatement.executeQuery();
while(true)
......@@ -123,5 +122,4 @@ public abstract class _DefaultDAO<T extends Entity> extends _Generic<T> {
e.printStackTrace();
}
}
}
\ No newline at end of file
......@@ -14,6 +14,4 @@ public class EleveGUI
input.put("eleves", Core.Eleve.getAll());
return DefaultGUI.getDefaultGUI(input, "eleves.ftl");
}
}
......@@ -14,10 +14,6 @@ public class GommetteGUI
Map<String, Object> input = new HashMap<>();
input.put("gommettes", Core.Gommette.getAll());
return DefaultGUI.getDefaultGUI(input, "gommettes.ftl");
}
}
......@@ -16,7 +16,6 @@ public class ProfGUI
}
public static String getWelcomePage(ProfEntity prof)
{
Map<String, Object> input = new HashMap<>();
......@@ -24,6 +23,4 @@ public class ProfGUI
return DefaultGUI.getDefaultGUI(input, "welcome.ftl");
}
}
......@@ -13,8 +13,4 @@ public class UserGUI
input.put("users", Core.User.getAll());
return DefaultGUI.getDefaultGUI(input, "users.ftl");
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment