Skip to content

Commit

Permalink
Merge pull request #2 from donoftime2018/backend
Browse files Browse the repository at this point in the history
Backend
  • Loading branch information
donoftime2018 committed Nov 22, 2023
2 parents ed10a9f + 969a7bb commit 7259bf3
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 6 deletions.
91 changes: 91 additions & 0 deletions vueapp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vueapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
"dependencies": {
"@vue/compiler-sfc": "^3.3.8",
"axios": "^1.6.2",
"vue": "^3.3.4",
"vue-router": "^4.2.5"
},
Expand Down
27 changes: 23 additions & 4 deletions vueapp/src/components/Dashboard.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
<template>
<h1 class="text-blue-600 dark:text-blue-500">
Dashboard
</h1>
</template>
{{trainData}}
</template>

<script>
import { onMounted } from "vue";
import axios from "axios";
export default {
data() {
return {
trainData: []
};
},
mounted() {
console.log("Mounted!")
axios.get("http://localhost:5118/api/getJsonData").then(response => {
console.log(response);
this.trainData = response.data
})
}
}
</script>
39 changes: 39 additions & 0 deletions webapi/Controllers/ApiController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System.Threading.Tasks;
using Newtonsoft.Json;
using System.Net.Http;
using System.Xml;
using Microsoft.AspNetCore.Mvc;

namespace webapi.Controllers
{
[Route("api/getJsonData")]
[ApiController]
public class ApiController : ControllerBase
{
[HttpGet]
public async Task<ActionResult<String>> GetData()
{
using (HttpClient client = new HttpClient())
{
HttpResponseMessage res = await client.GetAsync("https://lapi.transitchicago.com/api/1.0/ttarrivals.aspx?key=f3668ac334484bc88b6b2e7778a013bd&mapid=40380");

if (res.IsSuccessStatusCode)
{
string XMLData = await res.Content.ReadAsStringAsync();
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(XMLData);
string jsonData = JsonConvert.SerializeXmlNode(xmlDoc);
return Ok(jsonData);
}

else
{
return StatusCode((int)res.StatusCode, "Error fetching XML data");
}
}

}


}
}
12 changes: 10 additions & 2 deletions webapi/Program.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
using Newtonsoft.Json.Serialization;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
builder.Services.AddControllers(options =>
{
options.RespectBrowserAcceptHeader = true;
}).AddJsonOptions(options =>
{
options.JsonSerializerOptions.PropertyNamingPolicy = null;
}).AddXmlSerializerFormatters().AddNewtonsoftJson(options=>options.SerializerSettings.ContractResolver = new DefaultContractResolver());
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

app.UseCors(c => c.AllowAnyHeader().AllowAnyOrigin().AllowAnyMethod());
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
Expand Down
3 changes: 3 additions & 0 deletions webapi/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"ConnectionStrings": {
"CTAString": "https://lapi.transitchicago.com/api/1.0/ttarrivals.aspx?key=f3668ac334484bc88b6b2e7778a013bd&mapid=40380"
},
"Logging": {
"LogLevel": {
"Default": "Information",
Expand Down
1 change: 1 addition & 0 deletions webapi/webapi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.13" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.10" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

Expand Down

0 comments on commit 7259bf3

Please sign in to comment.