Register merged routes in Main
This commit is contained in:
parent
65177b21fc
commit
3693352e92
7 changed files with 32 additions and 30 deletions
|
@ -7,7 +7,10 @@ import java.sql.DriverManager;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import be.jeffcheasey88.peeratcode.routes.PuzzleList;
|
||||
import be.jeffcheasey88.peeratcode.repository.DatabaseRepository;
|
||||
import be.jeffcheasey88.peeratcode.routes.ChapterElement;
|
||||
import be.jeffcheasey88.peeratcode.routes.ChapterList;
|
||||
import be.jeffcheasey88.peeratcode.routes.PuzzleElement;
|
||||
import be.jeffcheasey88.peeratcode.webserver.Client;
|
||||
import be.jeffcheasey88.peeratcode.webserver.HttpReader;
|
||||
import be.jeffcheasey88.peeratcode.webserver.HttpUtil;
|
||||
|
@ -40,7 +43,7 @@ public class Main {
|
|||
}
|
||||
});
|
||||
|
||||
initRoutes(router, con);
|
||||
initRoutes(router, new DatabaseRepository(con));
|
||||
|
||||
|
||||
ServerSocket server = new ServerSocket(80);
|
||||
|
@ -52,8 +55,10 @@ public class Main {
|
|||
}
|
||||
|
||||
}
|
||||
private static void initRoutes(Router router, Connection con){
|
||||
router.register(new PuzzleList(con));
|
||||
private static void initRoutes(Router router, DatabaseRepository repo){
|
||||
router.register(new ChapterElement(repo));
|
||||
router.register(new ChapterList(repo));
|
||||
router.register(new PuzzleElement(repo));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package be.jeffcheasey88.peeratcode.model;
|
|||
import java.util.List;
|
||||
|
||||
public class Chapter {
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
private List<Puzzle> puzzles;
|
||||
|
@ -37,13 +38,10 @@ public class Chapter {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
Chapter chapter = (Chapter) o;
|
||||
|
||||
return id == chapter.id;
|
||||
public boolean equals(Object object){
|
||||
if(this == object) return true;
|
||||
if(!(object instanceof Chapter)) return false;
|
||||
return this.id == (((Chapter)object).id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package be.jeffcheasey88.peeratcode.model;
|
||||
|
||||
public class Puzzle {
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
private String content;
|
||||
|
@ -36,13 +37,10 @@ public class Puzzle {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
Puzzle puzzle = (Puzzle) o;
|
||||
|
||||
return id == puzzle.id;
|
||||
public boolean equals(Object object) {
|
||||
if(this == object) return true;
|
||||
if(!(object instanceof Puzzle)) return false;
|
||||
return this.id == (((Puzzle)object).id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -10,14 +10,15 @@ import java.sql.SQLException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DatabaseRepo {
|
||||
public class DatabaseRepository {
|
||||
|
||||
private static final String SPECIFIC_PUZZLE_QUERY = "SELECT * FROM puzzle WHERE id_puzzle = ?";
|
||||
private static final String SPECIFIC_CHAPTER_QUERY = "SELECT * FROM chapter WHERE id_chapter = ?";
|
||||
private static final String PUZZLES_IN_CHAPTER_QUERY = "SELECT * FROM puzzle WHERE fk_chapter = ?";
|
||||
public static final String ALL_CHAPTERS_QUERY = "SELECT * FROM chapter";
|
||||
private static final String ALL_CHAPTERS_QUERY = "SELECT * FROM chapter";
|
||||
private final Connection con;
|
||||
|
||||
public DatabaseRepo(Connection con) {
|
||||
public DatabaseRepository(Connection con) {
|
||||
this.con = con;
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@ package be.jeffcheasey88.peeratcode.routes;
|
|||
|
||||
import be.jeffcheasey88.peeratcode.model.Chapter;
|
||||
import be.jeffcheasey88.peeratcode.model.Puzzle;
|
||||
import be.jeffcheasey88.peeratcode.repository.DatabaseRepo;
|
||||
import be.jeffcheasey88.peeratcode.repository.DatabaseRepository;
|
||||
import be.jeffcheasey88.peeratcode.webserver.HttpReader;
|
||||
import be.jeffcheasey88.peeratcode.webserver.HttpUtil;
|
||||
import be.jeffcheasey88.peeratcode.webserver.HttpWriter;
|
||||
|
@ -15,9 +15,9 @@ import java.util.regex.Pattern;
|
|||
|
||||
public class ChapterElement implements Response {
|
||||
|
||||
private final DatabaseRepo databaseRepo;
|
||||
private final DatabaseRepository databaseRepo;
|
||||
|
||||
public ChapterElement(DatabaseRepo databaseRepo) {
|
||||
public ChapterElement(DatabaseRepository databaseRepo) {
|
||||
this.databaseRepo = databaseRepo;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package be.jeffcheasey88.peeratcode.routes;
|
||||
|
||||
import be.jeffcheasey88.peeratcode.model.Chapter;
|
||||
import be.jeffcheasey88.peeratcode.repository.DatabaseRepo;
|
||||
import be.jeffcheasey88.peeratcode.repository.DatabaseRepository;
|
||||
import be.jeffcheasey88.peeratcode.webserver.HttpReader;
|
||||
import be.jeffcheasey88.peeratcode.webserver.HttpUtil;
|
||||
import be.jeffcheasey88.peeratcode.webserver.HttpWriter;
|
||||
|
@ -15,9 +15,9 @@ import java.util.regex.Pattern;
|
|||
|
||||
public class ChapterList implements Response {
|
||||
|
||||
private final DatabaseRepo databaseRepo;
|
||||
private final DatabaseRepository databaseRepo;
|
||||
|
||||
public ChapterList(DatabaseRepo databaseRepo) {
|
||||
public ChapterList(DatabaseRepository databaseRepo) {
|
||||
this.databaseRepo = databaseRepo;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package be.jeffcheasey88.peeratcode.routes;
|
||||
|
||||
import be.jeffcheasey88.peeratcode.model.Puzzle;
|
||||
import be.jeffcheasey88.peeratcode.repository.DatabaseRepo;
|
||||
import be.jeffcheasey88.peeratcode.repository.DatabaseRepository;
|
||||
import be.jeffcheasey88.peeratcode.webserver.HttpReader;
|
||||
import be.jeffcheasey88.peeratcode.webserver.HttpUtil;
|
||||
import be.jeffcheasey88.peeratcode.webserver.HttpWriter;
|
||||
|
@ -13,9 +13,9 @@ import java.util.regex.Pattern;
|
|||
|
||||
public class PuzzleElement implements Response {
|
||||
|
||||
private final DatabaseRepo databaseRepo;
|
||||
private final DatabaseRepository databaseRepo;
|
||||
|
||||
public PuzzleElement(DatabaseRepo databaseRepo) {
|
||||
public PuzzleElement(DatabaseRepository databaseRepo) {
|
||||
this.databaseRepo = databaseRepo;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue