-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from m-riley04/T-21
T-21 Create data accessors
- Loading branch information
Showing
46 changed files
with
1,499 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using System.Diagnostics.Eventing.Reader; | ||
using TWISTServer.DatabaseComponents.DataAccessors; | ||
using TWISTServer.DatabaseComponents.Records; | ||
|
||
namespace TWISTServer.Controllers | ||
{ | ||
[ApiController] | ||
[Route("api/asks-concessions")] | ||
public class AsksConcessionsController(ILogger<AsksConcessionsController> logger) | ||
{ | ||
private readonly AsksDataAccessor asksAccessor = new(); | ||
private readonly ConcessionsDataAccessor concessionsAccessor = new(); | ||
|
||
private readonly ILogger<AsksConcessionsController> _logger = logger; | ||
|
||
[HttpGet] | ||
[Route("asks")] | ||
public IEnumerable<AskRecord> GetAsks([FromQuery(Name = "id")] int? id, [FromQuery(Name = "team")] int? teamId) | ||
{ | ||
// Check for both | ||
if (id.HasValue && teamId.HasValue) | ||
{ | ||
asksAccessor.GetAsksBySimulationAndTeam(id.Value, teamId.Value); | ||
} | ||
|
||
// Check for ID | ||
if (id.HasValue) | ||
{ | ||
return asksAccessor.Get(id.Value); | ||
} | ||
|
||
// Check for team ID | ||
if (teamId.HasValue) | ||
{ | ||
return asksAccessor.GetAsksByTeam(teamId.Value); | ||
} | ||
|
||
return asksAccessor.GetAll(); | ||
} | ||
|
||
[HttpGet] | ||
[Route("concessions")] | ||
public IEnumerable<ConcessionRecord> GetConcessions([FromQuery(Name = "id")] int? id, [FromQuery(Name = "team")] int? teamId) | ||
{ | ||
// Check for both | ||
if (id.HasValue && teamId.HasValue) | ||
{ | ||
concessionsAccessor.GetConcessionsBySimulationAndTeam(id.Value, teamId.Value); | ||
} | ||
|
||
// Check for ID | ||
if (id.HasValue) | ||
{ | ||
return concessionsAccessor.Get(id.Value); | ||
} | ||
|
||
// Check for team ID | ||
if (teamId.HasValue) | ||
{ | ||
return concessionsAccessor.GetConcessionsByTeam(teamId.Value); | ||
} | ||
|
||
return concessionsAccessor.GetAll(); | ||
} | ||
|
||
[HttpPut] | ||
[Route("asks")] | ||
public JsonResult AddAsk([FromBody] AskRecord ask) | ||
{ | ||
asksAccessor.Insert(ask); | ||
return new JsonResult($"Successfully added ask (TeamId = {ask.TeamId})"); | ||
} | ||
|
||
[HttpPut] | ||
[Route("concessions")] | ||
public JsonResult AddConcession([FromBody] ConcessionRecord concession) | ||
{ | ||
concessionsAccessor.Insert(concession); | ||
return new JsonResult($"Successfully added ask (TeamId = {concession.TeamId})"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using TWISTServer.DatabaseComponents.DataAccessors; | ||
using TWISTServer.DatabaseComponents.Records; | ||
|
||
namespace TWISTServer.Controllers | ||
{ | ||
[ApiController] | ||
[Route("api/connections")] | ||
public class ConnectionsController(ILogger<ConnectionsController> logger) | ||
{ | ||
private readonly ConnectionsDataAccessor dataAccessor = new(); | ||
|
||
private readonly ILogger<ConnectionsController> _logger = logger; | ||
|
||
[HttpGet] | ||
[Route("")] | ||
public IEnumerable<ConnectionRecord> GetMessages([FromQuery] int? id) | ||
{ | ||
if (id.HasValue) | ||
{ | ||
return dataAccessor.Get(id.Value); | ||
} | ||
|
||
return dataAccessor.GetAll(); | ||
} | ||
|
||
[HttpPut] | ||
[Route("")] | ||
public JsonResult AddMessage([FromBody] ConnectionRecord connection) | ||
{ | ||
dataAccessor.Insert(connection); | ||
return new JsonResult($"Successfully added connection (for simulation #{connection.SimulationId})."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using TWISTServer.DatabaseComponents.DataAccessors; | ||
using TWISTServer.DatabaseComponents.Records; | ||
|
||
namespace TWISTServer.Controllers | ||
{ | ||
[ApiController] | ||
[Route("api/documents")] | ||
public class DocumentsController(ILogger<DocumentsController> logger) | ||
{ | ||
private readonly DocumentsDataAccessor dataAccessor = new(); | ||
|
||
private readonly ILogger<DocumentsController> _logger = logger; | ||
|
||
[HttpGet] | ||
[Route("")] | ||
public IEnumerable<DocumentRecord> GetDocuments() | ||
{ | ||
return dataAccessor.GetAll(); | ||
} | ||
|
||
[HttpGet] | ||
[Route("{id}")] | ||
public IEnumerable<DocumentRecord> GetDocument([FromRoute] int id) | ||
{ | ||
return dataAccessor.Get(id); | ||
} | ||
|
||
[HttpPut] | ||
[Route("")] | ||
public JsonResult Put([FromBody] DocumentRecord document) | ||
{ | ||
dataAccessor.Insert(document); | ||
return new JsonResult($"Successfully added document {document.Type}!"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using TWISTServer.DatabaseComponents.DataAccessors; | ||
using TWISTServer.DatabaseComponents.Records; | ||
|
||
namespace TWISTServer.Controllers | ||
{ | ||
[ApiController] | ||
[Route("api/messages")] | ||
public class MessagesController(ILogger<MessagesController> logger) | ||
{ | ||
private readonly MessagesDataAccessor dataAccessor = new(); | ||
|
||
private readonly ILogger<MessagesController> _logger = logger; | ||
|
||
[HttpGet] | ||
[Route("")] | ||
public IEnumerable<MessageRecord> GetMessages([FromQuery] int? id) | ||
{ | ||
if (id.HasValue) | ||
{ | ||
return dataAccessor.Get(id.Value); | ||
} | ||
|
||
return dataAccessor.GetAll(); | ||
} | ||
|
||
[HttpPut] | ||
[Route("")] | ||
public JsonResult AddMessage([FromBody] MessageRecord message) | ||
{ | ||
dataAccessor.Insert(message); | ||
return new JsonResult($"Successfully added message (from participant #{message.ParticipantId})."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using TWISTServer.DatabaseComponents.DataAccessors; | ||
using TWISTServer.DatabaseComponents.Records; | ||
|
||
namespace TWISTServer.Controllers | ||
{ | ||
[ApiController] | ||
[Route("api/participants")] | ||
public class ParticipantsController(ILogger<ParticipantsController> logger) | ||
{ | ||
private readonly ParticipantsDataAccessor dataAccessor = new(); | ||
|
||
private readonly ILogger<ParticipantsController> _logger = logger; | ||
|
||
[HttpGet] | ||
[Route("")] | ||
public IEnumerable<ParticipantRecord> GetParticipants([FromQuery(Name = "id")] int? id, | ||
[FromQuery(Name = "team")] int? teamId, [FromQuery(Name = "simulation")] int? simulationId) | ||
{ | ||
if (id.HasValue) | ||
{ | ||
return dataAccessor.Get(id.Value); | ||
} | ||
|
||
if (simulationId.HasValue) | ||
{ | ||
return dataAccessor.GetParticipantsBySimulation(simulationId.Value); | ||
} | ||
|
||
if (teamId.HasValue) | ||
{ | ||
return dataAccessor.GetParticipantsByTeam(teamId.Value); | ||
} | ||
|
||
return dataAccessor.GetAll(); | ||
} | ||
|
||
[HttpPut] | ||
[Route("")] | ||
public JsonResult AddParticipant([FromBody] ParticipantRecord participant) | ||
{ | ||
dataAccessor.Insert(participant); | ||
return new JsonResult($"Successfully added participant '{participant.Username}'."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using TWISTServer.DatabaseComponents.DataAccessors; | ||
using TWISTServer.DatabaseComponents.Records; | ||
using TWISTServer.Enums; | ||
|
||
namespace TWISTServer.Controllers | ||
{ | ||
[ApiController] | ||
[Route("api/responses")] | ||
public class ResponsesController(ILogger<ResponsesController> logger) | ||
{ | ||
private readonly ResponsesDataAccessor dataAccessor = new(); | ||
|
||
private readonly ILogger<ResponsesController> _logger = logger; | ||
|
||
[HttpGet] | ||
[Route("")] | ||
public IEnumerable<ResponseRecord> GetResponses([FromQuery] int? id) | ||
{ | ||
if (id.HasValue) | ||
{ | ||
return dataAccessor.Get(id.Value); | ||
} | ||
|
||
return dataAccessor.GetAll(); | ||
} | ||
|
||
[HttpGet] | ||
[Route("pre")] | ||
public IEnumerable<ResponseRecord> GetPreResponses() | ||
{ | ||
return dataAccessor.GetResponsesByType(SurveyTypeEnum.Pre); | ||
} | ||
|
||
[HttpGet] | ||
[Route("post")] | ||
public IEnumerable<ResponseRecord> GetPostResponses() | ||
{ | ||
return dataAccessor.GetResponsesByType(SurveyTypeEnum.Post); | ||
} | ||
|
||
[HttpPut] | ||
[Route("")] | ||
public JsonResult AddResponse([FromBody] ResponseRecord response) | ||
{ | ||
dataAccessor.Insert(response); | ||
return new JsonResult($"Successfully added response (Type = {response.SurveyType})."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using TWISTServer.DatabaseComponents.DataAccessors; | ||
using TWISTServer.DatabaseComponents.Records; | ||
|
||
namespace TWISTServer.Controllers | ||
{ | ||
[ApiController] | ||
[Route("api/scores")] | ||
public class ScoresController(ILogger<ScoresController> logger) | ||
{ | ||
private readonly ScoreDataAccessor dataAccessor = new(); | ||
|
||
private readonly ILogger<ScoresController> _logger = logger; | ||
|
||
[HttpGet] | ||
[Route("")] | ||
public IEnumerable<ScoreRecord> GetScores([FromQuery] int? id) | ||
{ | ||
if (id.HasValue) | ||
{ | ||
return dataAccessor.Get(id.Value); | ||
} | ||
|
||
return dataAccessor.GetAll(); | ||
} | ||
|
||
[HttpPut] | ||
[Route("")] | ||
public JsonResult AddScore([FromBody] ScoreRecord score) | ||
{ | ||
dataAccessor.Insert(score); | ||
return new JsonResult($"Successfully added score of value {score.TotalScore})."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using TWISTServer.DatabaseComponents.DataAccessors; | ||
using TWISTServer.DatabaseComponents.Records; | ||
|
||
namespace TWISTServer.Controllers | ||
{ | ||
[ApiController] | ||
[Route("api/simulations")] | ||
public class SimulationsController(ILogger<SimulationsController> logger) | ||
{ | ||
private readonly SimulationsDataAccessor dataAccessor = new(); | ||
|
||
private readonly ILogger<SimulationsController> _logger = logger; | ||
|
||
[HttpGet] | ||
[Route("")] | ||
public IEnumerable<SimulationRecord> GetSimulations([FromQuery] int? id) | ||
{ | ||
if (id.HasValue) | ||
{ | ||
return dataAccessor.Get(id.Value); | ||
} | ||
|
||
return dataAccessor.GetAll(); | ||
} | ||
|
||
[HttpPut] | ||
[Route("")] | ||
public JsonResult AddSimulation([FromBody] SimulationRecord simulation) | ||
{ | ||
dataAccessor.Insert(simulation); | ||
return new JsonResult($"Successfully added simulation {simulation.Name}."); | ||
} | ||
} | ||
} |
Oops, something went wrong.