completed new contact creation, implemented contact deletion

This commit is contained in:
2025-10-10 10:24:38 +02:00
parent e5227c3e19
commit 3e8f90c5bc
6 changed files with 72 additions and 15 deletions

View File

@@ -5,25 +5,24 @@ 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;
import org.json.JSONObject;
public record Contact(long id, String vcard) implements Mappable {
public static Contact of(ResultSet rs) throws SQLException {
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) {
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));
}
@Override
public Map<String, Object> toMap() {
return Map.of(ID,id,VCARD,vcard);
}
}