|
|
|
@ -5,25 +5,24 @@ import static de.srsoftware.umbrella.core.Constants.*; |
|
|
|
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException; |
|
|
|
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException; |
|
|
|
|
|
|
|
|
|
|
|
import de.srsoftware.tools.Mappable; |
|
|
|
import de.srsoftware.tools.Mappable; |
|
|
|
import org.json.JSONObject; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.sql.ResultSet; |
|
|
|
import java.sql.ResultSet; |
|
|
|
import java.sql.SQLException; |
|
|
|
import java.sql.SQLException; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
import org.json.JSONObject; |
|
|
|
|
|
|
|
|
|
|
|
public record Contact(long id, String vcard) implements Mappable { |
|
|
|
public record Contact(long id, String vcard) implements Mappable { |
|
|
|
public static Contact of(ResultSet rs) throws SQLException { |
|
|
|
public static Contact of(ResultSet rs) throws SQLException { |
|
|
|
return new Contact(rs.getLong(ID),rs.getString(DATA)); |
|
|
|
return new Contact(rs.getLong(ID),rs.getString(DATA)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public Map<String, Object> toMap() { |
|
|
|
|
|
|
|
return Map.of(ID,id,VCARD,vcard); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Contact patch(JSONObject json) { |
|
|
|
public Contact patch(JSONObject json) { |
|
|
|
if (!(json.get(FROM) instanceof String from)) throw missingFieldException(FROM); |
|
|
|
if (!(json.get(FROM) instanceof String from)) throw missingFieldException(FROM); |
|
|
|
if (!(json.get(TO) instanceof String to)) throw missingFieldException(TO); |
|
|
|
if (!(json.get(TO) instanceof String to)) throw missingFieldException(TO); |
|
|
|
return new Contact(id,vcard.replace(from, to)); |
|
|
|
return new Contact(id,vcard.replace(from, to)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public Map<String, Object> toMap() { |
|
|
|
|
|
|
|
return Map.of(ID,id,VCARD,vcard); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|