Skip to content

Commit

Permalink
Merge pull request #421 from cmu-sei/v8
Browse files Browse the repository at this point in the history
updates social graph to use DB
  • Loading branch information
sei-dupdyke authored Oct 8, 2024
2 parents 9f17b06 + 70757b6 commit 681b03f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
23 changes: 12 additions & 11 deletions src/Ghosts.Api/Controllers/ViewSocialController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ghosts.Api;
using Ghosts.Api.Infrastructure;
using Ghosts.Api.Infrastructure.Data;
using ghosts.api.Infrastructure.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using NLog;

Expand All @@ -20,10 +22,12 @@ public class ViewSocialController : Controller
{
private static readonly Logger _log = LogManager.GetCurrentClassLogger();
private readonly ApplicationSettings _configuration;
private readonly ApplicationDbContext _context;

public ViewSocialController(ApplicationSettings configuration)
public ViewSocialController(ApplicationDbContext context)
{
_configuration = configuration;
_configuration = Program.ApplicationSettings;
_context = context;
}

[HttpGet]
Expand Down Expand Up @@ -94,14 +98,11 @@ private bool IsSocialGraphEnabled()

private async Task<List<NpcSocialGraph>> LoadSocialGraphsAsync()
{
var path = SocialGraphJob.GetSocialGraphFile();
if (!System.IO.File.Exists(path))
{
return null; // File not found, return null
}

var json = await System.IO.File.ReadAllTextAsync(path);
return JsonConvert.DeserializeObject<List<NpcSocialGraph>>(json);
var graphs = await _context.Npcs
.Where(x => x.NpcSocialGraph != null)
.Select(x => x.NpcSocialGraph)
.ToListAsync();
return graphs;
}

private async Task<NpcSocialGraph> LoadGraphByIdAsync(Guid id)
Expand Down
2 changes: 1 addition & 1 deletion src/Ghosts.Api/Views/ViewSocial/Index.cshtml

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

0 comments on commit 681b03f

Please sign in to comment.