master
Harald Wolff 2019-06-19 12:31:28 +02:00
parent 32c0967cce
commit f8275974b1
3 changed files with 56 additions and 4 deletions

View File

@ -9,8 +9,8 @@ namespace ln.http.resources.collections
{ {
public JSONConvert JSONConvert { get; set; } public JSONConvert JSONConvert { get; set; }
Dictionary<string, FieldInfo> publicFields = new Dictionary<string, FieldInfo>(); public Dictionary<string, FieldInfo> publicFields = new Dictionary<string, FieldInfo>();
Dictionary<string, PropertyInfo> publicProperties = new Dictionary<string, PropertyInfo>(); public Dictionary<string, PropertyInfo> publicProperties = new Dictionary<string, PropertyInfo>();
public EntityMapper() public EntityMapper()
{ {

View File

@ -19,6 +19,7 @@ using System.ComponentModel;
using ln.types.odb.mapped; using ln.types.odb.mapped;
using ln.types.threads; using ln.types.threads;
using ln.types.json; using ln.types.json;
using System.Reflection;
namespace ln.http.resources.collections namespace ln.http.resources.collections
{ {
@ -61,7 +62,11 @@ namespace ln.http.resources.collections
object documentID = collection.Mapper.GetDocumentID(ni); object documentID = collection.Mapper.GetDocumentID(ni);
httpResponse.SetHeader("Location", String.Format("/{0}/{1}", String.Join("/", this.Path), documentID.ToString())); httpResponse.SetHeader("Location", String.Format("/{0}/{1}", String.Join("/", this.Path), documentID.ToString()));
httpResponse.StatusCode = 201; httpResponse.StatusCode = 201;
responseValue = ni;*/ responseValue = ni;
*/
break;
case "DESC":
collectionResult = Describe(httpRequest);
break; break;
default: default:
throw new NotSupportedException(); throw new NotSupportedException();
@ -90,6 +95,40 @@ namespace ln.http.resources.collections
return httpResponse; return httpResponse;
} }
private CollectionResult Describe(HttpRequest request)
{
CollectionResult collectionResult = new CollectionResult();
collectionResult.Descriptor = new JObject();
JArray jProperties = new JArray();
foreach (FieldInfo fieldInfo in EntityMapper.publicFields.Values)
{
String skyType = JSONConvert.GetSkyType(fieldInfo.FieldType);
if (skyType != null)
{
JObject field = new JObject();
field.Add("name", JToken.FromObject(fieldInfo.Name));
field.Add("type", JToken.FromObject(skyType));
jProperties.Add(field);
}
}
foreach (PropertyInfo propertyInfo in EntityMapper.publicProperties.Values)
{
String skyType = JSONConvert.GetSkyType(propertyInfo.PropertyType);
if (skyType != null)
{
JObject field = new JObject();
field.Add("name", JToken.FromObject(propertyInfo.Name));
field.Add("type", JToken.FromObject(skyType));
jProperties.Add(field);
}
}
collectionResult.Descriptor.Add("properties", jProperties);
return collectionResult;
}
private CollectionResult Query(HttpRequest request) private CollectionResult Query(HttpRequest request)
{ {
CollectionResult collectionResult = new CollectionResult(); CollectionResult collectionResult = new CollectionResult();
@ -120,13 +159,17 @@ namespace ln.http.resources.collections
surround.Add("values", jvalues); surround.Add("values", jvalues);
JObject jfailed = new JObject(); JObject jfailed = new JObject();
foreach (TIDENT id in collectionResult.Failed.Keys) foreach (TIDENT id in collectionResult.Failed.Keys)
{ {
jfailed.Add(id.ToString(), collectionResult.Failed[id]); jfailed.Add(id.ToString(), collectionResult.Failed[id]);
} }
surround.Add("failed", jfailed); surround.Add("failed", jfailed);
if (collectionResult.Descriptor != null)
{
surround.Add("desc", collectionResult.Descriptor);
}
response.SetHeader("content-type", "application/json"); response.SetHeader("content-type", "application/json");
response.ContentWriter.Write(surround.ToString()); response.ContentWriter.Write(surround.ToString());
@ -137,6 +180,8 @@ namespace ln.http.resources.collections
{ {
public List<TENTITY> Values { get; } = new List<TENTITY>(); public List<TENTITY> Values { get; } = new List<TENTITY>();
public Dictionary<TIDENT, String> Failed { get; } = new Dictionary<TIDENT, string>(); public Dictionary<TIDENT, String> Failed { get; } = new Dictionary<TIDENT, string>();
public JObject Descriptor { get; set; }
} }
} }

View File

@ -1,5 +1,6 @@
# Unterstützte Methoden: # Unterstützte Methoden:
DESC /collection Abruf der Objektbeschreibung für diese Collection
GET /collection Abruf von Elementen aus der Kollektion, optional mit Filter GET /collection Abruf von Elementen aus der Kollektion, optional mit Filter
GET /collection/<element identifier> Abruf eines definierten Element der Kollektion GET /collection/<element identifier> Abruf eines definierten Element der Kollektion
POST /collection Hinzufügen neuer Elemente zur Kollektion POST /collection Hinzufügen neuer Elemente zur Kollektion
@ -18,6 +19,12 @@ DELETE /collection/<element identifier> Entfernen eines Elements der Kollekt
<IDENTIFIER0>: <ELEMENTURL0>, // Element <IDENTIFIER0> wurde erfolgreich hinzugefügt / geändert <IDENTIFIER0>: <ELEMENTURL0>, // Element <IDENTIFIER0> wurde erfolgreich hinzugefügt / geändert
<IDENTIFIER1>: null, // Element <IDENTIFIER1> wurde erfolgreich gelöscht <IDENTIFIER1>: null, // Element <IDENTIFIER1> wurde erfolgreich gelöscht
}, },
desc: {
properties: [
{ name: <PROP0NAME>, type: <PROPTYPE>, readonly: true/false, },
...
],
},
} }
# Anfrageschemata # Anfrageschemata