-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* Empiria Land ********************************************************************************************** | ||
* * | ||
* Module : Land Messaging services Component : Web Api * | ||
* Assembly : Empiria.Land.WebApi.dll Pattern : Response methods * | ||
* Type : SubscriptionModels License : Please read LICENSE.txt file * | ||
* * | ||
* Summary : Models for Subscription responses. * | ||
* * | ||
************************* Copyright(c) La Vía Óntica SC, Ontica LLC and contributors. All rights reserved. **/ | ||
using System; | ||
|
||
using Empiria.Land.Messaging; | ||
|
||
namespace Empiria.Land.WebApi { | ||
|
||
/// <summary>Response models for SignEvent entities.</summary> | ||
static internal class SubscriptionModels { | ||
|
||
#region Response models | ||
|
||
static internal object ToResponse(this Subscription subscription) { | ||
return new { | ||
uid = subscription.UID, | ||
type = subscription.SubscriptionType, | ||
subscribedObjectUID = subscription.SubscribedObjectUID, | ||
sendTo = new { | ||
name = subscription.SendTo.Name, | ||
address = subscription.SendTo.Address, | ||
}, | ||
status = subscription.Status | ||
}; | ||
} | ||
|
||
#endregion Response models | ||
|
||
} // class SubscriptionModels | ||
|
||
} // namespace Empiria.OnePoint.WebApi | ||
|
105 changes: 105 additions & 0 deletions
105
Land.WebAPI/SearchServices/SubscriptionServicesController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* Empiria Land ********************************************************************************************** | ||
* * | ||
* Module : Subscription services Component : Web Api * | ||
* Assembly : Empiria.Land.WebApi.dll Pattern : Controller * | ||
* Type : SubscriptionServicesController License : Please read LICENSE.txt file * | ||
* * | ||
* Summary : Subscription services used to follow changes on resources and documents. * | ||
* * | ||
************************* Copyright(c) La Vía Óntica SC, Ontica LLC and contributors. All rights reserved. **/ | ||
using System; | ||
using System.Web.Http; | ||
|
||
using Empiria.Json; | ||
using Empiria.WebApi; | ||
|
||
using Empiria.Land.Messaging; | ||
|
||
namespace Empiria.Land.WebApi { | ||
|
||
/// <summary>Subscription services used to follow changes on resources and documents.</summary> | ||
public class SubscriptionServicesController : WebApiController { | ||
|
||
#region Public APIs | ||
|
||
|
||
[HttpPost, AllowAnonymous] | ||
[Route("v1/online-services/subscriptions/{subscriptionUID}/confirm")] | ||
public SingleObjectModel ConfirmSubscription([FromUri] string subscriptionUID, | ||
[FromBody] object body) { | ||
try { | ||
SubscriptionRequest subscriptionRequest = | ||
this.BuildSubscriptionRequestFromBody(SubscriptionRequestCommand.ConfirmSubscription, body); | ||
|
||
Subscription subscription = SubscriptionServices.ConfirmSubscription(subscriptionRequest); | ||
|
||
return new SingleObjectModel(this.Request, subscription.ToResponse(), | ||
typeof(Subscription).ToString()); | ||
|
||
} catch (Exception e) { | ||
throw base.CreateHttpException(e); | ||
} | ||
} | ||
|
||
|
||
[HttpPost, AllowAnonymous] | ||
[Route("v1/online-services/subscriptions")] | ||
public SingleObjectModel Subscribe([FromBody] object body) { | ||
try { | ||
SubscriptionRequest subscriptionRequest = | ||
this.BuildSubscriptionRequestFromBody(SubscriptionRequestCommand.Subscribe, body); | ||
|
||
Subscription subscription = SubscriptionServices.Subscribe(subscriptionRequest); | ||
|
||
return new SingleObjectModel(this.Request, subscription.ToResponse(), | ||
typeof(Subscription).ToString()); | ||
|
||
} catch (Exception e) { | ||
throw base.CreateHttpException(e); | ||
} | ||
} | ||
|
||
|
||
[HttpPost, AllowAnonymous] | ||
[Route("v1/online-services/subscriptions/{subscriptionUID}/unsubscribe")] | ||
public SingleObjectModel Unsubscribe([FromUri] string subscriptionUID, | ||
[FromBody] object body) { | ||
try { | ||
base.RequireResource(subscriptionUID, "subscriptionUID"); | ||
|
||
SubscriptionRequest subscriptionRequest = | ||
this.BuildSubscriptionRequestFromBody(SubscriptionRequestCommand.Unsubscribe, body); | ||
|
||
Subscription subscription = SubscriptionServices.Unsubscribe(subscriptionUID, subscriptionRequest); | ||
|
||
return new SingleObjectModel(this.Request, subscription.ToResponse(), | ||
typeof(Subscription).ToString()); | ||
|
||
} catch (Exception e) { | ||
throw base.CreateHttpException(e); | ||
} | ||
} | ||
|
||
|
||
#endregion Public APIs | ||
|
||
#region Private methods | ||
|
||
|
||
private SubscriptionRequest BuildSubscriptionRequestFromBody(SubscriptionRequestCommand command, | ||
object body) { | ||
base.RequireBody(body); | ||
|
||
var bodyAsJson = JsonObject.Parse(body); | ||
|
||
bodyAsJson.Add("command", command.ToString()); | ||
|
||
return SubscriptionRequest.Parse(bodyAsJson); | ||
} | ||
|
||
|
||
#endregion Private methods | ||
|
||
} // class SubscriptionServicesController | ||
|
||
} // namespace Empiria.Land.WebApi |