//get value for key (name) public object Get(ValueDto req) { var value = new Value ().PopulateWith (req); value.Hash=DHTServerCtx.HashFunction.apply (req.Key); var redir = this.checkRedirect (value.Hash, req.Key); if (redir != null) { return redir; } var found = Db.Select<Value> (q => q.HashHexString == value.HashHexString); if (found.IsEmpty()) { return new HttpResult { StatusCode = HttpStatusCode.NotFound }; } var valueDto = found.Select (v => new ValueDto ().PopulateWith (v)).First (); return new ValueDtoResponse (valueDto); }
//create or update value for key (name) public object Put(ValueDto req) { var value = new Value ().PopulateWith (req); value.Hash=DHTServerCtx.HashFunction.apply (req.Key); var redir = this.checkRedirect (value.Hash, req.Key); if (redir != null) { return redir; } var found = Db.Select<Value> (q => q.HashHexString == value.HashHexString); if (found.IsEmpty()) { Db.Insert<Value> (value); } else { Db.Save<Value> (value); } return new HttpResult { StatusCode = HttpStatusCode.Accepted }; }
//delete value for key (name) public object Delete(ValueDto req) { var value = new Value ().PopulateWith (req); value.Hash=DHTServerCtx.HashFunction.apply (req.Key); var redir = this.checkRedirect (value.Hash, req.Key); if (redir != null) { return redir; } var found = Db.Select<Value> (q => q.HashHexString == value.HashHexString); if (found.IsEmpty()) { return new HttpResult { StatusCode = HttpStatusCode.NotFound }; } Db.Delete<Value> (q => q.HashHexString == value.HashHexString); return new HttpResult { StatusCode = HttpStatusCode.NoContent }; }