working on saving wiki pages
This commit is contained in:
@@ -1,24 +1,24 @@
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.Util.markdown;
|
||||
|
||||
public class WikiPage implements Mappable {
|
||||
|
||||
private final String id;
|
||||
private final int version;
|
||||
private String id;
|
||||
private int version;
|
||||
private final List<Integer> versions = new ArrayList<>();
|
||||
private final Map<Long,Member> members = new HashMap<>();
|
||||
private final String content;
|
||||
private String content;
|
||||
private Set<String> dirtyFields = new HashSet<>();
|
||||
|
||||
public WikiPage(String id, int version, String content) {
|
||||
this.id = id;
|
||||
@@ -38,6 +38,28 @@ public class WikiPage implements Mappable {
|
||||
return new WikiPage(rs.getString(ID),rs.getInt(VERSION),rs.getString(CONTENT));
|
||||
}
|
||||
|
||||
public WikiPage patch(JSONObject json) {
|
||||
for (var key : json.keySet()){
|
||||
var val = json.get(key);
|
||||
var altered = true;
|
||||
switch (key){
|
||||
case ID:
|
||||
if (!(val instanceof String s)) throw UmbrellaException.invalidFieldException(ID,"String");
|
||||
id = s; break;
|
||||
case CONTENT:
|
||||
if (!(val instanceof String s)) throw UmbrellaException.invalidFieldException(CONTENT,"String");
|
||||
content = s; break;
|
||||
default:
|
||||
altered = false;
|
||||
}
|
||||
if (altered) {
|
||||
dirtyFields.add(key);
|
||||
version++;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> toMap() {
|
||||
var memberMap = new HashMap<Long,Map<String,Object>>();
|
||||
|
||||
Reference in New Issue
Block a user