working on patching vcards
This commit is contained in:
@@ -99,6 +99,7 @@ public class Constants {
|
||||
public static final String FIELD_TYPE_PREFIX = "type_prefix";
|
||||
public static final String FIELD_TYPE_SUFFIX = "type_suffix";
|
||||
public static final String FIELD_UNIT = "unit";
|
||||
public static final String FROM = "from";
|
||||
public static final String FULLTEXT = "fulltext";
|
||||
|
||||
public static final String GET = "GET";
|
||||
@@ -168,6 +169,7 @@ public class Constants {
|
||||
public static final String THEME = "theme";
|
||||
public static final String TITLE = "title";
|
||||
public static final String TIMESTAMP = "timestamp";
|
||||
public static final String TO = "to";
|
||||
public static final String TOKEN = "token";
|
||||
public static final String TOTAL_PRIO = "total_prio";
|
||||
public static final String TYPE = "type";
|
||||
|
||||
@@ -2,8 +2,11 @@
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Map;
|
||||
@@ -17,4 +20,10 @@ public record Contact(long id, String vcard) implements Mappable {
|
||||
public Map<String, Object> toMap() {
|
||||
return Map.of(ID,id,VCARD,vcard);
|
||||
}
|
||||
|
||||
public Contact patch(JSONObject json) {
|
||||
if (!(json.get(FROM) instanceof String from)) throw missingFieldException(FROM);
|
||||
if (!(json.get(TO) instanceof String to)) throw missingFieldException(TO);
|
||||
return new Contact(id,vcard.replace(from, to));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user