completed new contact creation, implemented contact deletion
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user