Skip to content

Initial Commit #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
11 changes: 11 additions & 0 deletions MyWebAPI/.vs/MyWebAPI/project-colors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"Version": 1,
"ProjectMap": {
"dcdbfa01-0f3e-43a5-8c69-99eb8cecc796": {
"ProjectGuid": "dcdbfa01-0f3e-43a5-8c69-99eb8cecc796",
"DisplayName": "MyWebAPI",
"ColorIndex": 0
}
},
"NextColorIndex": 1
}
Binary file added MyWebAPI/.vs/MyWebAPI/v17/.futdcache.v1
Binary file not shown.
Binary file added MyWebAPI/.vs/MyWebAPI/v17/.suo
Binary file not shown.
25 changes: 25 additions & 0 deletions MyWebAPI/MyWebAPI.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31919.166
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyWebAPI", "MyWebAPI\MyWebAPI.csproj", "{DCDBFA01-0F3E-43A5-8C69-99EB8CECC796}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{DCDBFA01-0F3E-43A5-8C69-99EB8CECC796}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DCDBFA01-0F3E-43A5-8C69-99EB8CECC796}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DCDBFA01-0F3E-43A5-8C69-99EB8CECC796}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DCDBFA01-0F3E-43A5-8C69-99EB8CECC796}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4F30E5BC-8FDF-4964-BB23-D7A956B0CC21}
EndGlobalSection
EndGlobal
33 changes: 33 additions & 0 deletions MyWebAPI/MyWebAPI/Controllers/WeatherForecastController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Microsoft.AspNetCore.Mvc;

namespace MyWebAPI.Controllers
{
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};

private readonly ILogger<WeatherForecastController> _logger;

public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}

[HttpGet(Name = "GetWeatherForecast")]
public IEnumerable<WeatherForecast> Get()
{
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
}
}
}
55 changes: 55 additions & 0 deletions MyWebAPI/MyWebAPI/Controllers/response1Controller.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#nullable disable
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using MyWebAPI.Models;
using Microsoft.Extensions.Configuration;

namespace MyWebAPI.Controllers
{
[Route("api/moduit/response1")]
[ApiController]
public class response1Controller : ControllerBase
{
private readonly response1Context _context;

private HttpClient httpclient = new HttpClient();

public response1Controller(response1Context context)
{
_context = context;
}

// GET: api/response1
[HttpGet]
public async Task<ActionResult<response1>> Getresponse1()
{
try
{
response1 response1Content = null;

string strEndPoint = "https://screening.moduit.id/backend/question/one";

HttpResponseMessage response = await httpclient.GetAsync(strEndPoint);

if (response.IsSuccessStatusCode)
{
response1Content = await response.Content.ReadAsAsync<response1>();
return response1Content;
}
else
{
return NotFound();
}
}
catch (Exception)
{
return StatusCode(500, "Internal Server Error");
}
}
}
}
68 changes: 68 additions & 0 deletions MyWebAPI/MyWebAPI/Controllers/response2Controller.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#nullable disable
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using MyWebAPI.Models;

namespace MyWebAPI.Controllers
{
[Route("api/moduit/response2")]
[ApiController]
public class response2Controller : ControllerBase
{
private readonly response2Context _context;

private HttpClient httpclient = new HttpClient();

public response2Controller(response2Context context)
{
_context = context;
}

// GET: api/response2
[HttpGet]
public async Task<ActionResult<List<response2>>> Getresponse2Items()
{
try
{
List<response2> response2Content = null;
IEnumerable<response2> filteredList = null;
List<response2> returnedList = null;
List<response2> finalreturnedList = null;

string strEndPoint = "https://screening.moduit.id/backend/question/two";

HttpResponseMessage response = await httpclient.GetAsync(strEndPoint);

if (response.IsSuccessStatusCode)
{
response2Content = await response.Content.ReadAsAsync<List<response2>>();

//check count result
if(response2Content.Count() > 0)
{
//filter
filteredList = response2Content.Where(x => x.description.Contains("Ergonomic") || x.title.Contains("Ergonomic"));

returnedList = filteredList.Where(z => z.tags != null).ToList();

finalreturnedList = returnedList.Where(z => z.tags.Contains("Sports")).Take(3).OrderByDescending(x => x.id).ToList();
}
else
{
return NotFound();
}
}
return finalreturnedList;
}
catch (Exception)
{
return StatusCode(500, "internal server error");
}
}
}
}
77 changes: 77 additions & 0 deletions MyWebAPI/MyWebAPI/Controllers/response3Controller.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#nullable disable
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using MyWebAPI.Models;

namespace MyWebAPI.Controllers
{
[Route("api/moduit/response3")]
[ApiController]
public class response3Controller : ControllerBase
{
private HttpClient httpclient = new HttpClient();

// GET: api/response3
[HttpGet]
public async Task<ActionResult<List<flatten>>> Getresponse3Items()
{
//try
//{
string strEndPoint = "https://screening.moduit.id/backend/question/three";

List<response3> response3Content = null;
List<flatten> flattenList = new List<flatten>();

HttpResponseMessage response = await httpclient.GetAsync(strEndPoint);

if (response.IsSuccessStatusCode)
{

response3Content = await response.Content.ReadAsAsync<List<response3>>();

//if count > 0
if(response3Content.Count > 0)
{
foreach (response3 responseItem in response3Content.ToList())
{
//if item is not null
if(responseItem.items != null)
{
foreach (item objItem in responseItem.items)
{
//fill flatten object
flatten objFlatten = new flatten();

objFlatten.id = responseItem.id;
objFlatten.category = responseItem.category;
objFlatten.title = objItem.title;
objFlatten.description = objItem.description;
objFlatten.footer = objItem.footer;
objFlatten.createdAt = responseItem.createdAt;

//add
flattenList.Add(objFlatten);
}
}

}
}
}
else
{
return NotFound();
}
return flattenList;
//}
//catch (Exception)
//{
// return StatusCode(500, "internal server error");
//}
}
}
}
13 changes: 13 additions & 0 deletions MyWebAPI/MyWebAPI/Models/response1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace MyWebAPI.Models
{
public class response1
{
public int id { get; set; }
public int category { get; set; }
public string? title { get; set; }
public string? description { get; set; }
public string? footer { get; set; }
public DateTime createdAt { get; set; }

}
}
15 changes: 15 additions & 0 deletions MyWebAPI/MyWebAPI/Models/response1Context.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Microsoft.EntityFrameworkCore;
using System.Diagnostics.CodeAnalysis;

namespace MyWebAPI.Models
{
public class response1Context : DbContext
{
public response1Context(DbContextOptions<response1Context> options)
: base(options)
{
}

public DbSet<response1> response1Items { get; set; } = null!;
}
}
14 changes: 14 additions & 0 deletions MyWebAPI/MyWebAPI/Models/response2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace MyWebAPI.Models
{
public class response2
{
public int id { get; set; }
public int category { get; set; }
public string? title { get; set; }
public string? description { get; set; }
public string? footer { get; set; }
public DateTime createdAt { get; set; }
public List<string> tags { get; set; }

}
}
13 changes: 13 additions & 0 deletions MyWebAPI/MyWebAPI/Models/response2Context.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Microsoft.EntityFrameworkCore;
using System.Diagnostics.CodeAnalysis;

namespace MyWebAPI.Models
{
public class response2Context : DbContext
{
public response2Context(DbContextOptions<response2Context> options)
: base(options) { }

public DbSet<response2> response2Items { get; set; } = null!;
}
}
29 changes: 29 additions & 0 deletions MyWebAPI/MyWebAPI/Models/response3.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace MyWebAPI.Models
{
public class response3
{
public int id { get; set; }
public int category { get; set; }
public List<item> items { get; set; }
public List<string> tags { get; set; }
public DateTime createdAt { get; set; }
}

public class item
{
public int id { get; set; }
public string? title { get; set; }
public string? description { get; set; }
public string? footer { get; set; }
}

public class flatten
{
public int id { get; set; }
public int category { get; set; }
public string? title { get; set; }
public string? description { get; set; }
public string? footer { get; set; }
public DateTime createdAt { get; set; }
}
}
13 changes: 13 additions & 0 deletions MyWebAPI/MyWebAPI/Models/response3Context.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Microsoft.EntityFrameworkCore;
using System.Diagnostics.CodeAnalysis;

namespace MyWebAPI.Models
{
public class response3Context : DbContext
{
public response3Context(DbContextOptions<response3Context> options)
: base(options) { }

public DbSet<response3> response3Items { get; set; } = null!;
}
}
Loading