forked from SteamWar/SteamWar
Add Backend to Monorepo
This commit is contained in:
@@ -21,6 +21,7 @@ package de.steamwar.sql;
|
||||
|
||||
import de.steamwar.sql.internal.Field;
|
||||
import de.steamwar.sql.internal.SelectStatement;
|
||||
import de.steamwar.sql.internal.Statement;
|
||||
import de.steamwar.sql.internal.Table;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
@@ -42,6 +43,11 @@ public class Event {
|
||||
private static final SelectStatement<Event> byId = table.select(Table.PRIMARY);
|
||||
private static final SelectStatement<Event> byName = table.select("eventName");
|
||||
private static final SelectStatement<Event> byComing = new SelectStatement<>(table, "SELECT * FROM Event WHERE Start > now()");
|
||||
private static final SelectStatement<Event> all = new SelectStatement<>(table, "SELECT * FROM Event");
|
||||
|
||||
private static final Statement create = table.insertFields(true, "eventName", "deadline", "start", "end", "maximumTeamMembers", "publicSchemsOnly");
|
||||
private static final Statement update = table.update(Table.PRIMARY, "eventName", "deadline", "start", "end", "schemType", "maximumTeamMembers", "publicSchemsOnly");
|
||||
private static final Statement delete = table.delete(Table.PRIMARY);
|
||||
|
||||
private static Event current = null;
|
||||
|
||||
@@ -53,6 +59,14 @@ public class Event {
|
||||
return current;
|
||||
}
|
||||
|
||||
public static List<Event> getAll(){
|
||||
return all.listSelect();
|
||||
}
|
||||
|
||||
public static Event create(String eventName, Timestamp start, Timestamp end){
|
||||
return get(create.insertGetKey(eventName, start, start, end, 5, false, false));
|
||||
}
|
||||
|
||||
public static Event get(int eventID){
|
||||
return byId.select(eventID);
|
||||
}
|
||||
@@ -87,16 +101,10 @@ public class Event {
|
||||
private final SchematicType schemType;
|
||||
@Field
|
||||
private final boolean publicSchemsOnly;
|
||||
@Deprecated
|
||||
@Field
|
||||
private final boolean spectateSystem;
|
||||
|
||||
public boolean publicSchemsOnly() {
|
||||
return publicSchemsOnly;
|
||||
}
|
||||
public boolean spectateSystem(){
|
||||
return spectateSystem;
|
||||
}
|
||||
|
||||
public SchematicType getSchematicType() {
|
||||
return schemType;
|
||||
@@ -106,4 +114,12 @@ public class Event {
|
||||
Instant now = Instant.now();
|
||||
return now.isAfter(start.toInstant()) && now.isBefore(end.toInstant());
|
||||
}
|
||||
|
||||
public void update(String eventName, Timestamp deadline, Timestamp start, Timestamp end, SchematicType schemType, int maximumTeamMembers, boolean publicSchemsOnly) {
|
||||
update.update(eventName, deadline, start, end, schemType, maximumTeamMembers, publicSchemsOnly, eventID);
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
delete.update(eventID);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import de.steamwar.sql.internal.Statement;
|
||||
import de.steamwar.sql.internal.Table;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.*;
|
||||
@@ -42,6 +43,11 @@ public class EventFight implements Comparable<EventFight> {
|
||||
private static final Statement setResult = table.update(Table.PRIMARY, "Ergebnis");
|
||||
private static final Statement setFight = table.update(Table.PRIMARY, "Fight");
|
||||
|
||||
private static final Statement create = table.insertAll(true);
|
||||
private static final Statement update = table.update(Table.PRIMARY, "startTime", "spielModus", "map", "teamBlue", "teamRed", "spectatePort");
|
||||
private static final Statement delete = table.delete(Table.PRIMARY);
|
||||
|
||||
@Getter
|
||||
private static final Queue<EventFight> fights = new PriorityQueue<>();
|
||||
|
||||
public static EventFight get(int fightID) {
|
||||
@@ -57,8 +63,8 @@ public class EventFight implements Comparable<EventFight> {
|
||||
return event.listSelect(eventID);
|
||||
}
|
||||
|
||||
public static Queue<EventFight> getFights() {
|
||||
return fights;
|
||||
public static EventFight create(int event, Timestamp from, String spielmodus, String map, int blueTeam, int redTeam, Integer spectatePort) {
|
||||
return get(create.insertGetKey(event, from, spielmodus, map, blueTeam, redTeam, spectatePort));
|
||||
}
|
||||
|
||||
@Getter
|
||||
@@ -68,27 +74,29 @@ public class EventFight implements Comparable<EventFight> {
|
||||
@Field(keys = {Table.PRIMARY}, autoincrement = true)
|
||||
private final int fightID;
|
||||
@Getter
|
||||
@Setter
|
||||
@Field
|
||||
private Timestamp startTime;
|
||||
@Getter
|
||||
@Setter
|
||||
@Field
|
||||
private final String spielmodus;
|
||||
private String spielmodus;
|
||||
@Getter
|
||||
@Setter
|
||||
@Field
|
||||
private final String map;
|
||||
private String map;
|
||||
@Getter
|
||||
@Setter
|
||||
@Field
|
||||
private final int teamBlue;
|
||||
private int teamBlue;
|
||||
@Getter
|
||||
@Setter
|
||||
@Field
|
||||
private final int teamRed;
|
||||
private int teamRed;
|
||||
@Getter
|
||||
@Field
|
||||
@Deprecated
|
||||
private final int kampfleiter;
|
||||
@Getter
|
||||
@Field
|
||||
private final int spectatePort;
|
||||
@Setter
|
||||
@Field(nullable = true)
|
||||
private int spectatePort;
|
||||
@Getter
|
||||
@Field(def = "0")
|
||||
private int ergebnis;
|
||||
@@ -133,4 +141,18 @@ public class EventFight implements Comparable<EventFight> {
|
||||
public int compareTo(EventFight o) {
|
||||
return startTime.compareTo(o.startTime);
|
||||
}
|
||||
|
||||
public void update(Timestamp startTime, String spielmodus, String map, int teamBlue, int teamRed, Integer spectatePort) {
|
||||
update.update(startTime, spielmodus, map, teamBlue, teamRed, spectatePort, fightID);
|
||||
this.startTime = startTime;
|
||||
this.spielmodus = spielmodus;
|
||||
this.map = map;
|
||||
this.teamBlue = teamBlue;
|
||||
this.teamRed = teamRed;
|
||||
this.spectatePort = spectatePort;
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
delete.update(fightID);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,9 +20,11 @@
|
||||
package de.steamwar.sql;
|
||||
|
||||
import de.steamwar.sql.internal.Field;
|
||||
import de.steamwar.sql.internal.SelectStatement;
|
||||
import de.steamwar.sql.internal.Statement;
|
||||
import de.steamwar.sql.internal.Table;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
@@ -38,11 +40,21 @@ public class NodeDownload {
|
||||
private static final Table<NodeDownload> table = new Table<>(NodeDownload.class);
|
||||
private static final Statement insert = table.insertFields("NodeId", "Link");
|
||||
|
||||
private static final SelectStatement<NodeDownload> select = table.select("link");
|
||||
|
||||
private static final Statement delete = table.delete(Table.PRIMARY);
|
||||
|
||||
public static NodeDownload get(String link) {
|
||||
return select.select(link);
|
||||
}
|
||||
|
||||
@Getter
|
||||
@Field(keys = {Table.PRIMARY})
|
||||
private final int nodeId;
|
||||
@Field
|
||||
private final String link;
|
||||
@Field(def = "CURRENT_TIMESTAMP")
|
||||
@Getter
|
||||
private final Timestamp timestamp;
|
||||
|
||||
public static String getLink(SchematicNode schem){
|
||||
@@ -60,10 +72,15 @@ public class NodeDownload {
|
||||
insert.update(schem.getId(), hash);
|
||||
return LINK_BASE + hash;
|
||||
}
|
||||
|
||||
public static String base16encode(byte[] byteArray) {
|
||||
StringBuilder hexBuffer = new StringBuilder(byteArray.length * 2);
|
||||
for (byte b : byteArray)
|
||||
hexBuffer.append(HEX[(b >>> 4) & 0xF]).append(HEX[b & 0xF]);
|
||||
return hexBuffer.toString();
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
delete.update(nodeId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,6 +72,10 @@ public class NodeMember {
|
||||
return new NodeMember(node, member, null);
|
||||
}
|
||||
|
||||
public static NodeMember getNodeMember(int node, SteamwarUser member) {
|
||||
return getNodeMember(node, member.getId());
|
||||
}
|
||||
|
||||
public static NodeMember getNodeMember(int node, int member) {
|
||||
return getNodeMember.select(node, member);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ package de.steamwar.sql;
|
||||
|
||||
import de.steamwar.sql.internal.Field;
|
||||
import de.steamwar.sql.internal.SelectStatement;
|
||||
import de.steamwar.sql.internal.Statement;
|
||||
import de.steamwar.sql.internal.Table;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
@@ -33,6 +34,17 @@ public class Referee {
|
||||
private static final Table<Referee> table = new Table<>(Referee.class);
|
||||
private static final SelectStatement<Referee> byEvent = table.selectFields("eventID");
|
||||
|
||||
private static final Statement insert = table.insertAll();
|
||||
private static final Statement delete = table.delete("eventReferee");
|
||||
|
||||
public static void add(int eventID, int userID) {
|
||||
insert.update(eventID, userID);
|
||||
}
|
||||
|
||||
public static void remove(int eventID, int userID) {
|
||||
delete.update(eventID, userID);
|
||||
}
|
||||
|
||||
public static Set<Integer> get(int eventID) {
|
||||
return byEvent.listSelect(eventID).stream().map(referee -> referee.userID).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@@ -443,7 +443,7 @@ public class SchematicNode {
|
||||
return SchemElo.getElo(this, season);
|
||||
}
|
||||
|
||||
public boolean accessibleByUser(int user) {
|
||||
public boolean accessibleByUser(SteamwarUser user) {
|
||||
return NodeMember.getNodeMember(nodeId, user) != null;
|
||||
}
|
||||
|
||||
@@ -506,6 +506,19 @@ public class SchematicNode {
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public List<Map.Entry<String, Integer>> generateBreadcrumbsMap(SteamwarUser user) {
|
||||
List<Map.Entry<String, Integer>> map = new ArrayList<>();
|
||||
Optional<SchematicNode> currentNode = Optional.of(this);
|
||||
if(currentNode.map(SchematicNode::isDir).orElse(false)) {
|
||||
map.add(new AbstractMap.SimpleEntry<>(getName(), getId()));
|
||||
}
|
||||
while (currentNode.isPresent()) {
|
||||
currentNode = currentNode.flatMap(schematicNode -> Optional.ofNullable(NodeMember.getNodeMember(schematicNode.getId(), effectiveOwner)).map(NodeMember::getParent).orElse(schematicNode.getOptionalParent())).map(SchematicNode::getSchematicNode);
|
||||
currentNode.ifPresent(node -> map.add(0, new AbstractMap.SimpleEntry<>(node.getName(), node.getId())));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private static final List<String> FORBIDDEN_NAMES = Collections.unmodifiableList(Arrays.asList("public"));
|
||||
public static boolean invalidSchemName(String[] layers) {
|
||||
for (String layer : layers) {
|
||||
|
||||
@@ -108,7 +108,7 @@ public class SchematicType {
|
||||
return name.toLowerCase();
|
||||
}
|
||||
|
||||
public static SchematicType fromDB(String input){
|
||||
public static SchematicType fromDB(String input) {
|
||||
return fromDB.get(input.toLowerCase());
|
||||
}
|
||||
|
||||
|
||||
@@ -62,6 +62,7 @@ public class SteamwarUser {
|
||||
private static final SelectStatement<SteamwarUser> byDiscord = table.selectFields("DiscordId");
|
||||
private static final SelectStatement<SteamwarUser> byTeam = table.selectFields("Team");
|
||||
private static final SelectStatement<SteamwarUser> getUsersWithPerm = new SelectStatement<>(table, "SELECT S.* FROM UserData S JOIN UserPerm P ON S.id = P.User WHERE P.Perm = ?");
|
||||
private static final SelectStatement<SteamwarUser> getAll = new SelectStatement<SteamwarUser>(table, "SELECT * FROM UserData");
|
||||
|
||||
private static final Statement updateName = table.update(Table.PRIMARY, "UserName");
|
||||
private static final Statement updatePassword = table.update(Table.PRIMARY, "Password");
|
||||
@@ -370,4 +371,8 @@ public class SteamwarUser {
|
||||
permissions = UserPerm.getPerms(id);
|
||||
prefix = permissions.stream().filter(UserPerm.prefixes::containsKey).findAny().map(UserPerm.prefixes::get).orElse(UserPerm.emptyPrefix);
|
||||
}
|
||||
|
||||
public static List<SteamwarUser> getAll() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,10 +19,7 @@
|
||||
|
||||
package de.steamwar.sql;
|
||||
|
||||
import de.steamwar.sql.internal.Field;
|
||||
import de.steamwar.sql.internal.SelectStatement;
|
||||
import de.steamwar.sql.internal.SqlTypeMapper;
|
||||
import de.steamwar.sql.internal.Table;
|
||||
import de.steamwar.sql.internal.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@@ -68,11 +65,21 @@ public enum UserPerm {
|
||||
|
||||
private static final Table<UserPermTable> table = new Table<>(UserPermTable.class, "UserPerm");
|
||||
private static final SelectStatement<UserPermTable> getPerms = table.selectFields("user");
|
||||
private static final Statement addPerm = table.insertFields("user", "perm");
|
||||
private static final Statement removePerm = table.delete(Table.PRIMARY);
|
||||
|
||||
public static Set<UserPerm> getPerms(int user) {
|
||||
return getPerms.listSelect(user).stream().map(up -> up.perm).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
public static void addPerm(SteamwarUser user, UserPerm perm) {
|
||||
addPerm.update(user, perm);
|
||||
}
|
||||
|
||||
public static void removePerm(SteamwarUser user, UserPerm perm) {
|
||||
removePerm.update(user, perm);
|
||||
}
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public static class Prefix {
|
||||
|
||||
@@ -83,7 +83,11 @@ public class Table<T> {
|
||||
}
|
||||
|
||||
public Statement insertAll() {
|
||||
return insertFields(false, Arrays.stream(fields).map(f -> f.identifier).toArray(String[]::new));
|
||||
return insertAll(false);
|
||||
}
|
||||
|
||||
public Statement insertAll(boolean returnGeneratedKeys) {
|
||||
return insertFields(returnGeneratedKeys, Arrays.stream(fields).map(f -> f.identifier).toArray(String[]::new));
|
||||
}
|
||||
|
||||
public Statement insertFields(String... fields) {
|
||||
|
||||
Reference in New Issue
Block a user