APIv3/src/main/java/net/frozenorb/apiv3/model/User.java

67 lines
1.9 KiB
Java
Raw Normal View History

2016-02-12 02:40:06 +01:00
package net.frozenorb.apiv3.model;
import lombok.Getter;
import lombok.ToString;
2016-02-12 06:31:57 +01:00
import net.frozenorb.apiv3.accessor.Users;
2016-02-12 02:40:06 +01:00
import org.bson.Document;
2016-02-23 13:14:42 +01:00
import java.time.Instant;
import java.util.Map;
import java.util.UUID;
2016-02-12 02:40:06 +01:00
@ToString
2016-02-12 06:31:57 +01:00
public final class User extends BaseModel {
2016-02-12 02:40:06 +01:00
2016-02-23 13:14:42 +01:00
@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;
2016-02-12 02:40:06 +01:00
public User(Document json) {
2016-02-12 06:31:57 +01:00
super(Users.COLLECTION_NAME);
2016-02-23 13:14:42 +01:00
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");
2016-02-12 06:31:57 +01:00
2016-02-23 13:14:42 +01:00
setId(id.toString());
2016-02-12 02:40:06 +01:00
}
public Document toLiteJson() {
Document json = new Document();
2016-02-23 13:14:42 +01:00
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());
2016-02-12 02:40:06 +01:00
return json;
}
public Document toFullJson() {
Document json = toLiteJson();
2016-02-23 13:14:42 +01:00
json.put("aliases", aliases);
2016-02-12 02:40:06 +01:00
return json;
}
}