1:n relationships in Azure and Xamarin - entity-framework

I am working on the following tables :
BadgesGroup table: contains a list of badges that are grouped together -> group A have badge 1 and 2 , Gruop B have badge 3 and 4 ...etc also contain information such as group logo
Badges table: contains information about a specific badge such as title and description
CustomerBadges table: contains the progress of each badge and to which customer it belong to
Following this tutorial :
https://blogs.msdn.microsoft.com/azuremobile/2014/05/27/retrieving-data-from-1n-relationship-using-net-backend-azure-mobile-services/
I managed to work it out successfully and retrieve all information of a given group with one API request.
Example :
[
{
"deleted": false,
"updatedAt": null,
"createdAt": "2019-07-07T17:47:32.043Z",
"version": "AAAAAAAAJyQ=",
"id": "4CD03F1F-BDB2-47BC-9084-35B5DF7E1530",
"levels": 4,
"logo": "img.png",
"badges": [
{
"customerBadge": [
{
"progress": 1,
"id": "037EC616-A17C-4E89-B4F5-F4DE960AB3B5",
"version": "AAAAAAAAJz4=",
"createdAt": "2019-07-07T17:51:21.253Z",
"updatedAt": null,
"deleted": false
}
],
"title": "Noob",
"description": "redeem 1",
"currentLevel": 1,
"id": "0F63CFD2-6679-4D25-AB40-280003555676",
"version": "AAAAAAAAJyw=",
"createdAt": "2019-07-07T17:48:24.429Z",
"updatedAt": null,
"deleted": false
},
{
"customerBadge": [
{
"progress": 4,
"id": "545B769C-FCA1-4C5D-BB5A-4D31BD724340",
"version": "AAAAAAAAJ0Q=",
"createdAt": "2019-07-07T17:51:32.035Z",
"updatedAt": null,
"deleted": false
}
],
"title": "King",
"description": "redeem 4",
"currentLevel": 4,
"id": "39E8E825-9196-43BC-890A-7E7833615818",
"version": "AAAAAAAAJy0=",
"createdAt": "2019-07-07T17:49:45.13Z",
"updatedAt": null,
"deleted": false
},
{
"customerBadge": [
{
"progress": 3,
"id": "24E30749-78A5-4AA9-B097-073C8E7162FD",
"version": "AAAAAAAAJ0Y=",
"createdAt": "2019-07-07T17:51:40.076Z",
"updatedAt": null,
"deleted": false
}
],
"title": "Master",
"description": "Redeem 3",
"currentLevel": 3,
"id": "935FE343-A6EC-43DD-8E50-6461A69CC757",
"version": "AAAAAAAAJy4=",
"createdAt": "2019-07-07T17:49:22.741Z",
"updatedAt": null,
"deleted": false
},
{
"customerBadge": [
{
"progress": 2,
"id": "0723DB30-D7AF-41C5-8E6F-3B3A174805B9",
"version": "AAAAAAAAJ0U=",
"createdAt": "2019-07-07T17:51:15.04Z",
"updatedAt": null,
"deleted": false
}
],
"title": "Pro",
"description": "redeem 2",
"currentLevel": 2,
"id": "9E169884-11FC-4893-8465-3D4792CCEEBC",
"version": "AAAAAAAAJy8=",
"createdAt": "2019-07-07T17:49:05.011Z",
"updatedAt": null,
"deleted": false
}
]
},
{
"deleted": false,
"updatedAt": null,
"createdAt": "2019-07-07T17:47:53.101Z",
"version": "AAAAAAAAJyU=",
"id": "602BBB5D-06D4-4685-AB65-5514CA73884B",
"levels": 2,
"logo": "img2.png",
"badges": [
{
"customerBadge": [
{
"progress": 22,
"id": "C236C1AB-37DC-47C9-B0CF-2825A916E77E",
"version": "AAAAAAAAJ0g=",
"createdAt": "2019-07-07T17:51:26.765Z",
"updatedAt": null,
"deleted": false
}
],
"title": "Old",
"description": "buy 4",
"currentLevel": 2,
"id": "74818583-1BC3-4FC5-81A2-4846C752CC8E",
"version": "AAAAAAAAJzE=",
"createdAt": "2019-07-07T17:50:23.947Z",
"updatedAt": null,
"deleted": false
},
{
"customerBadge": [
{
"progress": 11,
"id": "6D541809-1775-49AA-83AE-F434E3CC0E08",
"version": "AAAAAAAAJ0c=",
"createdAt": "2019-07-07T17:51:07.33Z",
"updatedAt": null,
"deleted": false
}
],
"title": "New",
"description": "buy 1",
"currentLevel": 1,
"id": "81DE6DFB-D6F8-49D6-A62B-3F5AF018DE40",
"version": "AAAAAAAAJzA=",
"createdAt": "2019-07-07T17:50:09.621Z",
"updatedAt": null,
"deleted": false
}
]
}
]
These are my models in the Azure backend using C# and one Azure mobile controller named AchievementGroupController auto generated :
public class AchievementGroup : EntityData
{
public AchievementGroup()
{
Badges = new List<Badge>();
}
public string Logo { get; set; }
public int Levels { get; set; }
public virtual ICollection<Badge> Badges { get; set; }
}
public class Badge : EntityData
{
public Badge()
{
CustomerBadge = new List<CustomerBadge>();
}
public string Title { get; set; }
public string description { get; set; }
public int CurrentLevel { get; set; }
public virtual AchievementGroup AchievementGroup { get; set; }
public virtual ICollection<CustomerBadge> CustomerBadge { get; set; }
}
public class CustomerBadge : EntityData
{
public int Progress { get; set; }
[Required]
public virtual Badge Badge { get; set; }
}
Now what my issue is I can not distinguish which customer has which progress.
I want to tell the API give me All badge groups and their progress for this given customer.

Related

Strapi multi-level population with field selection

I want to populate a multilevel relational field on strapi with REST API with specific field selection, but only the id comes up at the response.
When I populate the field without field selections with a GET request at: localhost:1337/api/home?populate[0]=Reasons&populate[1]=Reasons.IconsList&populate[2]=Reasons.IconsList.Icon, I
get this JSON response:
{
"data": {
"id": 1,
"attributes": {
"createdAt": "2022-10-31T11:24:55.202Z",
"updatedAt": "2022-11-09T13:50:40.445Z",
"publishedAt": "2022-10-31T11:26:30.944Z",
"PageInfo": "Homepage",
"Reasons": {
"id": 1,
"IconsList": [
{
"id": 1,
"Content": "Free cancellation on most bookings",
"Icon": {
"data": {
"id": 3,
"attributes": {
"name": "cancellation.svg",
"alternativeText": "Free cancellation on most bookings",
"caption": "cancellation.svg",
"width": 21,
"height": 21,
"formats": null,
"hash": "cancellation_b2308d4b63",
"ext": ".svg",
"mime": "image/svg+xml",
"size": 1.57,
"url": "/uploads/cancellation_b2308d4b63.svg",
"previewUrl": null,
"provider": "local",
"provider_metadata": null,
"createdAt": "2022-10-20T12:02:37.735Z",
"updatedAt": "2022-10-31T11:23:48.326Z"
}
}
}
},
{
"id": 2,
"Content": "No credit card fees",
"Icon": {
"data": {
"id": 5,
"attributes": {
"name": "credit-card.svg",
"alternativeText": "credit-card.svg",
"caption": "credit-card.svg",
"width": 22,
"height": 16,
"formats": null,
"hash": "credit_card_06b9eca40f",
"ext": ".svg",
"mime": "image/svg+xml",
"size": 0.89,
"url": "/uploads/credit_card_06b9eca40f.svg",
"previewUrl": null,
"provider": "local",
"provider_metadata": null,
"createdAt": "2022-10-20T12:21:46.342Z",
"updatedAt": "2022-10-20T12:21:46.342Z"
}
}
}
},
{
"id": 3,
"Content": "24/7 Customer care",
"Icon": {
"data": {
"id": 2,
"attributes": {
"name": "customer-care.svg",
"alternativeText": "24/7 Customer care",
"caption": "customer-care.svg",
"width": 20,
"height": 22,
"formats": null,
"hash": "customer_care_6aa8ac8eea",
"ext": ".svg",
"mime": "image/svg+xml",
"size": 1.48,
"url": "/uploads/customer_care_6aa8ac8eea.svg",
"previewUrl": null,
"provider": "local",
"provider_metadata": null,
"createdAt": "2022-10-20T12:02:37.734Z",
"updatedAt": "2022-10-20T12:04:39.792Z"
}
}
}
}
]
}
}
},
"meta": {}
}
Following this guide: https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/rest/populating-fields.html#combining-population-with-other-operators, when I try to define the fields I want from the response: localhost:1337/api/home?fields[0]=PageInfo&populate[Reasons][IconsList]fields]=Content, I only get this JSON:
{
"data": {
"id": 1,
"attributes": {
"PageInfo": "Homepage",
"Reasons": {
"id": 1
}
}
},
"meta": {}
}
I want to get IconsList's Content and Icon.alternativeText and Icon.url but I cannot find how to build my query parameters.
For future reference to this problem, my question was answered on Strapi forum: https://forum.strapi.io/t/strapi-multi-level-population-with-field-selection/23473
This tutorial explains the reasoning behind deep populating and filtering and it's really interesting.
The problem was that you need to pupulate the relational field again like that: localhost:1337/api/home?fields[0]=PageInfo&populate[Reasons][populate][IconsList][fields][0]=Content to be able to access its data.

Query nested object in mongodb without key

I have multiple documents saved which look like the one shown below, how would I query against a nested object without the ID to receive the right document?
Here is what I current, but this doesnt work, as I dont have the ID at the start.
db.collection.find({
"details.hardware.id": 5,
})
This is what ive tested and know works but I dont know the ID -
db.collection.find({
"100201.details.hardware.id": 5,
})
Document example -
[
{
"_id": {
"$oid": "6338b69062433c04642d26ca"
},
"100201": {
"broken": true,
"details": {
"build": {
"id": 1018458,
},
"hardware": {
"id": 5,
"model": {
"id": 131,
},
},
"id": 2811302,
"view": {
"id": 781,
}
},
"id": "100201",
"links": [
{
"details": {
"id": 7832,
},
"id": 15012,
},
{
"description": null,
"details": {
"id": 6528,
"model": {
"id": 530
}
},
"id": 15076,
}
],
"ref": false,
}
}
]
any help would be appreciated

How to Return data passing two parameters in a GET request using #Compoundindex?

I need to return set of objects using #Compoundindex.
I've tried with Jdk 8
The Following class is the entity class
#Document("filter")
#CompoundIndex(def = "{'spaceCategory': 1, 'eventType': 1}")
public class Filter extends BaseEntity {
#Indexed
private String spaceCategory;
#Indexed
private String eventType;
#DBRef(lazy = true)
private List<UiFilter> uiFilters;
public Filter(){}
public Filter(String id){
super(id);
}
public Filter(String spaceCategory, String eventType) {
this.spaceCategory = spaceCategory;
this.eventType = eventType;
}
//Getters and Setters
}
What I need to return is UiFilters of particular spaceCategory and eventType
Following code is to return UiFilters (The Restcontroller ) class
#GetMapping("/by-space")
public Filter findBySpaceCategoryAndEventType(#RequestParam String spaceCategory, #RequestParam String eventType ){
// return filterService.findBySpaceCategoryAndEventType(UiFilter);
// return null;
}
While using a url such as xxxx?spaceCategory=Work&eventType=Hot%20Desk I need to get only the uiFilter from following data set '
Data from the Collection
[
{
"id": "1",
"status": 1,
"spaceCategory": "Work",
"eventType": "Hot Desk",
"uiFilters": [
{
"id": "1",
"status": 1,
"label": "Duration",
"type": {
"id": "1",
"status": 1,
"name": "SINGLE_SELECT"
},
"value": [
"Daily",
"Weekly",
"Monthly"
]
},
{
"id": "2",
"status": 1,
"label": "Start Date",
"type": {
"id": "3",
"status": 1,
"name": "DATE_PICKER"
},
"value": ""
},
{
"id": "3",
"status": 1,
"label": "Price",
"type": {
"id": "3",
"status": 1,
"name": "RANGE_SELECT"
},
"value": {
"min": 1,
"max": 100,
"default": 50
}
},
{
"id": "4",
"status": 1,
"label": "Wi-Fi",
"type": {
"id": "4",
"status": 1,
"name": "SWITCH"
},
"value": "true"
}
]
}
]
Found the answer by using custom query as Following
#Override
public List<Filter> findFilterBySpaceCategoryAndEventType(String spaceCategory, String eventType) {
Query query = new Query();
query.addCriteria(Criteria.where("spaceCategory").is(spaceCategory));
query.addCriteria(Criteria.where("eventType").is(eventType));
List<Filter> filters= super.mongoOperations.find(query, Filter.class);
return filters;
}

Grouping select with partial

Hello i have here this code:
public function getConversations($user, $limit, $page)
{
$offset = ($page - 1) * $limit;
$qb = $this->createQueryBuilder('message');
$qb
->select('message, partial o.{id}, partial userFrom.{id, username, avatar}, partial userTo.{id, username, avatar}, partial availability.{id, timeFrom}')
->leftJoin('message.from', 'userFrom')
->leftJoin('message.to', 'userTo')
->leftJoin('message.order', 'o')
->leftJoin('o.availabilities', 'availability')
->where($qb->expr()->orX(
$qb->expr()->eq('message.from', ':user'),
$qb->expr()->eq('message.to', ':user')
))
->setParameter('user', $user)
->setFirstResult($offset)
->setMaxResults($limit)
->addOrderBy('message.created', Criteria::DESC);
return $qb->getQuery()->getArrayResult();
}
I want to get only last message connected to each order. If i have 2 messages to order it gives me 2 rows but i need only one (the last one). I tried to use GROUP BY but it didn't work well. It wanted me to put all foreign ids to group by and then the result was really bad.
Result for this is:
{
"id": "813fa986-f89b-411d-8324-727e427cbc01",
"isRead": false,
"created": {
"date": "2016-12-12 18:01:00.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"content": "Hello to you too",
"contentType": "text",
"from": {
"id": "3e1806d6-f47e-48b4-afdb-1081d9555a3f",
"avatar": "",
"username": "User two"
},
"to": {
"id": "52ead9fa-b498-400b-967d-b49886ab3118",
"avatar": "",
"username": "User one"
},
"order": {
"id": "8349e718-405a-4e88-8155-3896e9a89fdf",
"availabilities": [
{
"id": "9ddc07e0-be3d-453c-b12f-0ee31bfce444",
"timeFrom": {
"date": "2016-12-03 12:00:00.000000",
"timezone_type": 3,
"timezone": "UTC"
}
}
]
}
},
{
"id": "813fa986-f89b-411d-8324-727e427cbc00",
"isRead": false,
"created": {
"date": "2016-12-12 18:00:00.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"content": "Helllooooooo",
"contentType": "text",
"from": {
"id": "52ead9fa-b498-400b-967d-b49886ab3118",
"avatar": "",
"username": "User one"
},
"to": {
"id": "3e1806d6-f47e-48b4-afdb-1081d9555a3f",
"avatar": "",
"username": "User two"
},
"order": {
"id": "8349e718-405a-4e88-8155-3896e9a89fdf",
"availabilities": [
{
"id": "9ddc07e0-be3d-453c-b12f-0ee31bfce444",
"timeFrom": {
"date": "2016-12-03 12:00:00.000000",
"timezone_type": 3,
"timezone": "UTC"
}
}
]
}
and should be just like this:
{
"id": "813fa986-f89b-411d-8324-727e427cbc01",
"isRead": false,
"created": {
"date": "2016-12-12 18:01:00.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"content": "Hello to you too",
"contentType": "text",
"from": {
"id": "3e1806d6-f47e-48b4-afdb-1081d9555a3f",
"avatar": "",
"username": "User two"
},
"to": {
"id": "52ead9fa-b498-400b-967d-b49886ab3118",
"avatar": "",
"username": "User one"
},
"order": {
"id": "8349e718-405a-4e88-8155-3896e9a89fdf",
"availabilities": [
{
"id": "9ddc07e0-be3d-453c-b12f-0ee31bfce444",
"timeFrom": {
"date": "2016-12-03 12:00:00.000000",
"timezone_type": 3,
"timezone": "UTC"
}
}
]
}
}

Domino 9.x calendar service create meeting

I have been following this guide to work on Domino 9.0.1
Domino Calendar services
I am using JSON and the POST command works but creates an appointment, what I want to do is create a meeting. I have tried setting other fields like event['x-lotus-appttype'].data or event.AppointmentType = 3 but I still get an appointment.
JSON I am sending
{
"events": [
{
"summary":"Meeting 1",
"location":"Location 1",
"start": {
"date":"2013-12-01",
"time":"13:00:00",
"utc":true
},
"end": {
"date":"2013-12-01",
"time":"14:00:00",
"utc":true
}
}
]
}
What is the correct JSON format to create a meeting ?
Take a look at the following documentation: Event with attendees represented in JSON format
EXAMPLE 4. Event with attendees and time zone array:
{
"x-lotus-charset": {
"data": "UTF-8"
},
"timezones": [
{
"tzid": "Eastern",
"standard": {
"start": {
"date": "1950-11-05",
"time": "02:00:00"
},
"offsetFrom": "-0400",
"offsetTo": "-0500",
"recurrenceRule": "FREQ=YEARLY;BYMONTH=11;BYDAY=1SU;BYHOUR=2;BYMINUTE=0"
},
"daylight": {
"start": {
"date": "1950-03-12",
"time": "02:00:00"
},
"offsetFrom": "-0500",
"offsetTo": "-0400",
"recurrenceRule": "FREQ=YEARLY;BYMONTH=3;BYDAY=2SU;BYHOUR=2;BYMINUTE=0"
}
}
],
"events": [
{
"href": "/mail/dlawson.nsf/api/calendar/events/DB7E0BAC21EC322A85257BD200756E26-Lotus_Notes_Generated",
"id": "DB7E0BAC21EC322A85257BD200756E26-Lotus_Notes_Generated",
"summary": "Staff meeting",
"location": "Ray's office",
"description": "Please email your status update 24 hours before the meeting.",
"start": {
"date": "2013-09-12",
"time": "09:00:00",
"tzid": "Eastern"
},
"end": {
"date": "2013-09-12",
"time": "10:00:00",
"tzid": "Eastern"
},
"class": "public",
"transparency": "opaque",
"sequence": 0,
"last-modified": "20130825T212457Z",
"attendees": [
{
"role": "chair",
"status": "accepted",
"rsvp": false,
"displayName": "Duke Lawson/Peaks",
"email": "DukeLawson#swg.usma.ibm.com"
},
{
"role": "req-participant",
"status": "needs-action",
"rsvp": true,
"displayName": "Dean Melnyk/Peaks",
"email": "DeanMelnyk#swg.usma.ibm.com"
},
{
"role": "req-participant",
"status": "needs-action",
"rsvp": true,
"displayName": "Raymond Chan/Peaks",
"email": "RaymondChan#swg.usma.ibm.com"
}
],
"organizer": {
"displayName": "Duke Lawson/Peaks",
"email": "DukeLawson#swg.usma.ibm.com"
},
"x-lotus-broadcast": {
"data": "FALSE"
},
"x-lotus-notesversion": {
"data": "2"
},
"x-lotus-appttype": {
"data": "3"
}
}
]
}
I hope this can help :)