Commit current changes
This commit is contained in:
parent
f8f23e7de6
commit
2884ce209a
@ -9,6 +9,7 @@ import lombok.Getter;
|
||||
import net.frozenorb.apiv3.accessor.AuditLog;
|
||||
import net.frozenorb.apiv3.accessor.Grants;
|
||||
import net.frozenorb.apiv3.accessor.Servers;
|
||||
import net.frozenorb.apiv3.accessor.Users;
|
||||
import net.frozenorb.apiv3.util.ErrorUtils;
|
||||
import net.frozenorb.apiv3.util.JsonUtils;
|
||||
import net.frozenorb.apiv3.util.MongoUtils;
|
||||
@ -54,6 +55,20 @@ public final class APIv3 extends AbstractVerticle {
|
||||
});
|
||||
});
|
||||
|
||||
coreHttpRouter.get("/user/:user").handler(ctx -> {
|
||||
UUID target = UUID.fromString(ctx.request().getParam("user"));
|
||||
|
||||
Users.findById(target.toString(), (user, error) -> {
|
||||
if (error != null) {
|
||||
ctx.response().end(ErrorUtils.createResponse(error).toJson());
|
||||
} else if (user != null) {
|
||||
ctx.response().end(JsonUtils.toLiteJsonString(user));
|
||||
} else {
|
||||
ctx.response().end(ErrorUtils.createResponse("User '" + target + "' not found.").toJson());
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
coreHttpRouter.get("/user/:user/grants").handler(ctx -> {
|
||||
UUID target = UUID.fromString(ctx.request().getParam("user"));
|
||||
|
||||
|
@ -12,6 +12,7 @@ import org.bson.types.ObjectId;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
@UtilityClass
|
||||
public class AuditLog {
|
||||
@ -35,7 +36,7 @@ public class AuditLog {
|
||||
MongoUtils.findAndTransform(COLLECTION_NAME, new Document("actionType", actionType), TIME_BASED_SORT, AuditLogEntry::new, callback);
|
||||
}
|
||||
|
||||
public static void log(UUID user, String userIp, String actionType, Document data) {
|
||||
public static void log(UUID user, String userIp, String actionType, Document data, SingleResultCallback<Void> callback) {
|
||||
Document insert = new Document();
|
||||
|
||||
insert.put("_id", new ObjectId().toString());
|
||||
@ -45,7 +46,7 @@ public class AuditLog {
|
||||
insert.put("actionType", actionType);
|
||||
insert.put("actionData", data);
|
||||
|
||||
APIv3.getMongo().getCollection(COLLECTION_NAME).insertOne(insert, (result, error) -> {});
|
||||
APIv3.getMongo().getCollection(COLLECTION_NAME).insertOne(insert, callback);
|
||||
}
|
||||
|
||||
}
|
@ -2,11 +2,17 @@ package net.frozenorb.apiv3.accessor;
|
||||
|
||||
import com.mongodb.async.SingleResultCallback;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import net.frozenorb.apiv3.APIv3;
|
||||
import net.frozenorb.apiv3.model.EmailTemplate;
|
||||
import net.frozenorb.apiv3.util.IPUtils;
|
||||
import net.frozenorb.apiv3.util.MongoUtils;
|
||||
import org.bson.Document;
|
||||
import org.bson.types.ObjectId;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
@UtilityClass
|
||||
public class EmailTemplates {
|
||||
@ -21,4 +27,16 @@ public class EmailTemplates {
|
||||
MongoUtils.findOneAndTransform(COLLECTION_NAME, new Document("_id", id), EmailTemplate::new, callback);
|
||||
}
|
||||
|
||||
public static void createTemplate(String id, String title, String body, UUID creator, SingleResultCallback<Void> callback) {
|
||||
Document insert = new Document();
|
||||
|
||||
insert.put("_id", id);
|
||||
insert.put("title", title);
|
||||
insert.put("body", body);
|
||||
insert.put("lastUpdatedAt", Instant.now());
|
||||
insert.put("lastUpdatedBy", creator.toString());
|
||||
|
||||
APIv3.getMongo().getCollection(COLLECTION_NAME).insertOne(insert, callback);
|
||||
}
|
||||
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package net.frozenorb.apiv3.accessor;
|
||||
|
||||
import com.mongodb.async.SingleResultCallback;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import net.frozenorb.apiv3.model.MaxMindCacheEntry;
|
||||
import net.frozenorb.apiv3.util.MongoUtils;
|
||||
import org.bson.Document;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@UtilityClass
|
||||
public class MaxMindCache {
|
||||
|
||||
public static final String COLLECTION_NAME = "maxMindCache";
|
||||
|
||||
public static void findAll(SingleResultCallback<Collection<MaxMindCacheEntry>> callback) {
|
||||
MongoUtils.findAndTransform(COLLECTION_NAME, new Document(), MaxMindCacheEntry::new, callback);
|
||||
}
|
||||
|
||||
public static void findById(String id, SingleResultCallback<MaxMindCacheEntry> callback) {
|
||||
MongoUtils.findOneAndTransform(COLLECTION_NAME, new Document("_id", id), MaxMindCacheEntry::new, callback);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package net.frozenorb.apiv3.model;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import net.frozenorb.apiv3.accessor.MaxMindCache;
|
||||
import org.bson.Document;
|
||||
|
||||
@ToString
|
||||
public final class MaxMindCacheEntry extends BaseModel {
|
||||
|
||||
@Getter private String id;
|
||||
|
||||
public MaxMindCacheEntry(Document json) {
|
||||
super(MaxMindCache.COLLECTION_NAME);
|
||||
|
||||
this.id = json.getString("_id");
|
||||
|
||||
setId(id);
|
||||
}
|
||||
|
||||
public Document toLiteJson() {
|
||||
Document json = new Document();
|
||||
|
||||
json.put("_id", id);
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
public Document toFullJson() {
|
||||
Document json = toLiteJson();
|
||||
|
||||
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
}
|
@ -20,7 +20,7 @@ public final class Server extends BaseModel {
|
||||
@Getter private String displayName;
|
||||
@Getter private String secret;
|
||||
@Getter private String group;
|
||||
@Getter private String internalIp;
|
||||
@Getter private String ip;
|
||||
@Getter private Instant lastUpdate;
|
||||
@Getter private double lastTps;
|
||||
@Getter private List<UUID> players;
|
||||
@ -33,7 +33,7 @@ public final class Server extends BaseModel {
|
||||
this.displayName = json.getString("displayName");
|
||||
this.secret = json.getString("secret");
|
||||
this.group = json.getString("group");
|
||||
this.internalIp = json.getString("internalIp");
|
||||
this.ip = json.getString("ip");
|
||||
this.lastUpdate = (Instant) json.get("lastUpdate");
|
||||
this.lastTps = ((Number) json.get("lastTps")).doubleValue();
|
||||
this.players = new ArrayList<>();
|
||||
@ -52,7 +52,7 @@ public final class Server extends BaseModel {
|
||||
json.put("bungeeId", bungeeId);
|
||||
json.put("displayName", displayName);
|
||||
json.put("group", group);
|
||||
json.put("internalIp", internalIp);
|
||||
json.put("ip", ip);
|
||||
|
||||
return json;
|
||||
}
|
||||
|
@ -5,23 +5,53 @@ import lombok.ToString;
|
||||
import net.frozenorb.apiv3.accessor.Users;
|
||||
import org.bson.Document;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@ToString
|
||||
public final class User extends BaseModel {
|
||||
|
||||
@Getter private String id;
|
||||
@Getter private UUID id;
|
||||
@Getter private String lastName;
|
||||
@Getter private Map<String, Instant> aliases;
|
||||
@Getter private String otpCode;
|
||||
@Getter private String password;
|
||||
@Getter private String passwordSalt;
|
||||
@Getter private String email;
|
||||
@Getter private int phoneNumber;
|
||||
@Getter private String lastSeenOn;
|
||||
@Getter private Instant lastSeenAt;
|
||||
@Getter private Instant firstSeen;
|
||||
|
||||
public User(Document json) {
|
||||
super(Users.COLLECTION_NAME);
|
||||
|
||||
this.id = json.getString("_id");
|
||||
this.id = UUID.fromString(json.getString("_id"));
|
||||
this.lastName = json.getString("lastName");
|
||||
this.aliases = (Map<String, Instant>) json.get("aliases");
|
||||
this.otpCode = json.getString("otpCode");
|
||||
this.password = json.getString("password");
|
||||
this.passwordSalt = json.getString("passwordSalt");
|
||||
this.email = json.getString("email");
|
||||
this.phoneNumber = json.getInteger("phoneNumber");
|
||||
this.lastSeenOn = json.getString("lastSeenOn");
|
||||
this.lastSeenAt = (Instant) json.get("lastSeenAt");
|
||||
this.firstSeen = (Instant) json.get("firstSeen");
|
||||
|
||||
setId(id);
|
||||
setId(id.toString());
|
||||
}
|
||||
|
||||
public Document toLiteJson() {
|
||||
Document json = new Document();
|
||||
|
||||
json.put("_id", id);
|
||||
json.put("id", id.toString());
|
||||
json.put("lastName", lastName);
|
||||
json.put("email", email);
|
||||
json.put("phoneNumber", phoneNumber);
|
||||
json.put("lastSeenOn", lastSeenOn);
|
||||
json.put("lastSeenAt", lastSeenAt.toString());
|
||||
json.put("firstSeen", firstSeen.toString());
|
||||
|
||||
return json;
|
||||
}
|
||||
@ -29,7 +59,7 @@ public final class User extends BaseModel {
|
||||
public Document toFullJson() {
|
||||
Document json = toLiteJson();
|
||||
|
||||
|
||||
json.put("aliases", aliases);
|
||||
|
||||
return json;
|
||||
}
|
||||
|
@ -70,8 +70,12 @@ public class MongoUtils {
|
||||
if (error != null) {
|
||||
callback.onResult(null, error);
|
||||
} else if (result != null) {
|
||||
T transformed = transformation.apply(result);
|
||||
callback.onResult(transformed, null);
|
||||
try {
|
||||
T transformed = transformation.apply(result);
|
||||
callback.onResult(transformed, null);
|
||||
} catch (Exception ex) {
|
||||
callback.onResult(null, ex);
|
||||
}
|
||||
} else {
|
||||
callback.onResult(null, null);
|
||||
}
|
||||
@ -87,8 +91,12 @@ public class MongoUtils {
|
||||
if (error != null) {
|
||||
callback.onResult(null, error);
|
||||
} else if (!result.isEmpty()) {
|
||||
Collection<T> transformed = Collections2.transform(result, transformation);
|
||||
callback.onResult(transformed, null);
|
||||
try {
|
||||
Collection<T> transformed = Collections2.transform(result, transformation);
|
||||
callback.onResult(transformed, null);
|
||||
} catch (Exception ex) {
|
||||
callback.onResult(null, ex);
|
||||
}
|
||||
} else {
|
||||
callback.onResult(ImmutableList.of(), null);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user