Skip to content

Commit

Permalink
add more scenarios (#1139)
Browse files Browse the repository at this point in the history
  • Loading branch information
ElizabethOkerio authored Jan 15, 2024
1 parent b2546c3 commit 55dc8bd
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
33 changes: 33 additions & 0 deletions sample/BenchmarkServer/Controllers/ProductsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//------------------------------------------------------------------------------

using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.OData.Formatter;
using Microsoft.AspNetCore.OData.Query;
using Microsoft.AspNetCore.OData.Routing.Controllers;
using ODataPerformanceProfile.Models;
Expand All @@ -29,6 +30,7 @@ public ProductsController(ProductsContext context)
Id = i,
Category = "Goods" + i,
Color = Color.Red,
Others = new List<string> {"Others1", "Others2", "Others3"},
CreatedDate = new DateTimeOffset(2001, 4, 15, 16, 24, 8, TimeSpan.FromHours(-8)),
UpdatedDate = new DateTimeOffset(2011, 2, 15, 16, 24, 8, TimeSpan.FromHours(-8)),
Detail = new ProductDetail { Id = "Id" + i, Info = "Info" + i },
Expand All @@ -52,6 +54,12 @@ public ProductsController(ProductsContext context)
Address = "SupAddre"+i
}
}
},
Properties = new Dictionary<string, object>
{
{ "Prop1", new DateTimeOffset(2014, 7, 3, 0, 0, 0, 0, new TimeSpan(0))},
{ "Prop2", new [] { "Leonard G. Lobel", "Eric D. Boyd" }},
{ "Prop3", "Others"}
}
};

Expand All @@ -65,5 +73,30 @@ public IActionResult Get()
{
return Ok(products);
}

[HttpGet("odata/Products/mostRecent()")]
public IActionResult MostRecent()
{
var maxProductId = products.Max(x => x.Id);
return Ok(maxProductId);
}

[HttpPost("odata/Products({key})/Rate")]
public IActionResult Rate([FromODataUri] string key, ODataActionParameters parameters)
{
if (!ModelState.IsValid)
{
return BadRequest();
}

int rating = (int)parameters["rating"];

if (rating < 0)
{
return BadRequest();
}

return Ok(new ProductRating() { Id = key, Rating = rating });
}
}
}
13 changes: 12 additions & 1 deletion sample/BenchmarkServer/EdmModelBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,18 @@ public static IEdmModel GetEdmModel()
builder.EntitySet<Supplier>("Suppliers");
builder.EntitySet<Order>("Orders");

return builder.GetEdmModel();
builder.EntityType<Product>().Collection
.Function("mostRecent")
.Returns<string>();

builder.EntityType<Product>()
.Action("rate")
.Parameter<int>("rating");

var model = builder.GetEdmModel();
model.MarkAsImmutable();

return model;
}
}
}
14 changes: 13 additions & 1 deletion sample/BenchmarkServer/Models/Product.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,24 @@
// </copyright>
//------------------------------------------------------------------------------

using System.ComponentModel.DataAnnotations;

namespace ODataPerformanceProfile.Models
{
public class Product
{
public int Id { get; set; }
public string Category { get; set; }
public Color Color { get; set; }
public IList<string> Others { get; set; }
public DateTimeOffset CreatedDate { get; set; }

[ConcurrencyCheck]
public DateTimeOffset? UpdatedDate { get; set; }
public virtual ProductDetail Detail { get; set; }
public virtual ICollection<Supplier> ProductSuppliers { get; set; }
public virtual ICollection<Order> ProductOrders { get; set; }
public virtual ICollection<Order> ProductOrders { get; set; }
public IDictionary<string, object> Properties { get; set; }
}

public class ProductDetail
Expand Down Expand Up @@ -51,4 +57,10 @@ public class Order
public int Id { get; set; }
public string OrderNo { get; set; }
}

public class ProductRating
{
public string Id { get; set; }
public int Rating { get; set; }
}
}

0 comments on commit 55dc8bd

Please sign in to comment.