Search API

  • Thread starter Thread starter Rajat Bajpai
  • Start date Start date
R

Rajat Bajpai

Guest
/*



Sample Input 0


{ "Post": { "UserId": { "SearchValues": ["91705fa7-9b16-401f-a1b8-ea8c434549d9", "ae7fb877-b247-4d3a-87b2-2dc83f690fb5"] } } }


Sample Output 0


{"Posts":[{"Id":"ef6927d0-5d35-446d-9e42-dd32edfe229f","UserId":"91705fa7-9b16-401f-a1b8-ea8c434549d9","Text":"Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts."},{"Id":"08110c05-febf-4fb2-a554-5040bae408d6","UserId":"91705fa7-9b16-401f-a1b8-ea8c434549d9","Text":"Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean."},{"Id":"ac7c5759-6e04-4401-addc-2b94e6828dbe","UserId":"91705fa7-9b16-401f-a1b8-ea8c434549d9","Text":"A small river named Duden flows by their place and supplies it with the necessary regelialia."},{"Id":"705266b5-71bc-4afc-9294-5898829719aa","UserId":"ae7fb877-b247-4d3a-87b2-2dc83f690fb5","Text":"When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane."}]}


Explanation 0


You can search for a Post by multiple UserIds. This request fetches all posts that have the UserId as either '91705fa7-9b16-401f-a1b8-ea8c434549d9' or 'ae7fb877-b247-4d3a-87b2-2dc83f690fb5'.


Sample Input 1


{ "Post": { "Id": { "SearchValues": ["ef6927d0-5d35-446d-9e42-dd32edfe229f", "08110c05-febf-4fb2-a554-5040bae408d6"] } } }


Sample Output 1


{"Posts":[{"Id":"ef6927d0-5d35-446d-9e42-dd32edfe229f","UserId":"91705fa7-9b16-401f-a1b8-ea8c434549d9","Text":"Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts."},{"Id":"08110c05-febf-4fb2-a554-5040bae408d6","UserId":"91705fa7-9b16-401f-a1b8-ea8c434549d9","Text":"Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean."}]}


Explanation 1


Similarly, you can search for multiple Posts by its Ids.


Sample Input 2


{ "User": { "Id": { "SearchValues": ["91705fa7-9b16-401f-a1b8-ea8c434549d9", "ae7fb877-b247-4d3a-87b2-2dc83f690fb5"] } } }


Sample Output 2


{"Users":[{"Id":"91705fa7-9b16-401f-a1b8-ea8c434549d9","Name":"John"},{"Id":"ae7fb877-b247-4d3a-87b2-2dc83f690fb5","Name":"Randy"}]}


Explanation 2


Just as you did for Posts, you can also search the User objects using either the Id property or its Name property (see next example).


Sample Input 3


{ "User": { "Name": { "SearchValues": ["Ron", "Randy"] } } }


Sample Output 3


{"Users":[{"Id":"ae7fb877-b247-4d3a-87b2-2dc83f690fb5","Name":"Randy"},{"Id":"2d325aa4-a74e-4550-994e-5154a25bc848","Name":"Randy"}]}


Explanation 3


Searching for Users using their Name property.





*/







using System;
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

class Solution {
static void Main(String[] args) {
string input = Console.ReadLine();

JObject request = JsonConvert.DeserializeObject<JObject>(input); // request object
List<User> users = UserRepository.GetUsers(); // users collection
List<Post> posts = PostRepository.GetPosts(); // posts collection

JObject response = new JObject();

// start your code below, do NOT change the code above




// add your search results to the response JObject above







Console.WriteLine(JsonConvert.SerializeObject(response)); // do not change this line
}
}

// DO NOT CHANGE ANY CODE BELOW THIS LINE

class User {
public string Id { get; set; }
public string Name { get; set; }
}

class Post {
public string Id { get; set; }
public string UserId { get; set; }
public string Text { get; set; }
}

static class UserRepository {
public static List<User> GetUsers() {
List<User> users = new List<User>();

users.Add(new User() {Id = "91705fa7-9b16-401f-a1b8-ea8c434549d9", Name = "John"});
users.Add(new User() {Id = "ae7fb877-b247-4d3a-87b2-2dc83f690fb5", Name = "Randy"});
users.Add(new User() {Id = "2d325aa4-a74e-4550-994e-5154a25bc848", Name = "Randy"});
users.Add(new User() {Id = "ee654f8b-21cb-4653-aec5-285cee4123e3", Name = "Rob"});
users.Add(new User() {Id = "6787e397-4340-444c-ac54-ad3219427de9", Name = "Jon"});
users.Add(new User() {Id = "35fa0cdc-303e-4683-95ee-c0f097c92e5b", Name = "Jett"});
users.Add(new User() {Id = "329d8efd-d3b4-4e50-be79-f8887aa66262", Name = "Alice"});
users.Add(new User() {Id = "4cfb034a-ecbb-49b7-922a-8b621590e790", Name = "Raj"});
users.Add(new User() {Id = "d3a09680-4fdb-4aa8-a098-409ab956fdf1", Name = "Maya"});
users.Add(new User() {Id = "cb09367a-3e4a-4601-ae7f-a7db515decdb", Name = "Rey"});
users.Add(new User() {Id = "67f40346-7ade-42d2-bdcd-1156942b4c8f", Name = "Rishi"});
users.Add(new User() {Id = "10fef3bf-bed2-420d-a5de-65782b9d01d5", Name = "Abhishek"});

return users;
}
}

static class PostRepository {
public static List<Post> GetPosts() {
List<Post> posts = new List<Post>();

posts.Add(new Post() {Id = "ef6927d0-5d35-446d-9e42-dd32edfe229f", UserId = "91705fa7-9b16-401f-a1b8-ea8c434549d9", Text = "Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts."});
posts.Add(new Post() {Id = "08110c05-febf-4fb2-a554-5040bae408d6", UserId = "91705fa7-9b16-401f-a1b8-ea8c434549d9", Text = "Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean."});
posts.Add(new Post() {Id = "ac7c5759-6e04-4401-addc-2b94e6828dbe", UserId = "91705fa7-9b16-401f-a1b8-ea8c434549d9", Text = "A small river named Duden flows by their place and supplies it with the necessary regelialia."});
posts.Add(new Post() {Id = "12bb3d4f-956d-4c56-b599-7b6d4f54109a", UserId = "d3a09680-4fdb-4aa8-a098-409ab956fdf1", Text = "It is a paradisematic country, in which roasted parts of sentences fly into your mouth."});
posts.Add(new Post() {Id = "90fe28c3-ba92-4064-bda4-64c0543efd1e", UserId = "d3a09680-4fdb-4aa8-a098-409ab956fdf1", Text = "Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life."});
posts.Add(new Post() {Id = "05c82a25-7ad4-4e88-9c34-936e4061ef25", UserId = "6787e397-4340-444c-ac54-ad3219427de9", Text = "One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar."});
posts.Add(new Post() {Id = "3ccb91e3-4b5f-4739-84fe-285becb3b44c", UserId = "4cfb034a-ecbb-49b7-922a-8b621590e790", Text = "The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen."});
posts.Add(new Post() {Id = "e1149d91-7787-4b5c-8866-7b2de84925ab", UserId = "4cfb034a-ecbb-49b7-922a-8b621590e790", Text = "She packed her seven versalia, put her initial into the belt and made herself on the way."});
posts.Add(new Post() {Id = "705266b5-71bc-4afc-9294-5898829719aa", UserId = "ae7fb877-b247-4d3a-87b2-2dc83f690fb5", Text = "When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane."});
posts.Add(new Post() {Id = "4ef124e7-d418-4d05-aa88-15634354acd5", UserId = "ee654f8b-21cb-4653-aec5-285cee4123e3", Text = "Pityful a rethoric question ran over her cheek."});

return posts;
}
}

Continue reading...
 
Back
Top