Skip to content
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

User Story: Save linearized graph #85

Merged
merged 43 commits into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
348f07a
Create LinearizedGraph.cs
Apr 14, 2022
2c4a7f6
Add LinearizedGraph to FlooqContext.cs #78
Apr 14, 2022
9da86f1
Create LinearizedGraphController.cs
Apr 14, 2022
7dae1ae
Some Clean Code
Apr 14, 2022
7240242
Create ILinearizedGraphService.cs
Apr 14, 2022
92e4b5b
Create LinearizedGraphService.cs
Apr 14, 2022
8ffd0ae
Unify naming in GraphController
Apr 14, 2022
70c423c
Add TODO (Delete LinearizedGraph in PUT)
Apr 14, 2022
d527bc0
Merge branch 'main' into user-story/save-linearized-graph
floomm Apr 14, 2022
f0660a7
Merge branch 'user-story/save-linearized-graph' of https://github.com…
Apr 17, 2022
904dde3
Clean Code DataFlowService.cs
Apr 17, 2022
805bd7a
Create LinearizedGraphServiceTest.cs
Apr 17, 2022
0be892b
Implement LinearizedGraphService.cs
Apr 17, 2022
6d25daf
Use GraphService in GraphController
Apr 17, 2022
b56302a
Remove unused imports
Apr 17, 2022
ddb00bd
Delete matching LinearizedGraph on PUT of a DataFlow
Apr 17, 2022
b2587b1
Merge branch 'main' into user-story/save-linearized-graph
Apr 17, 2022
f22d5b1
Merge branch 'main' into user-story/save-linearized-graph
Apr 17, 2022
2a2e790
Create LinearizedGraphControllerTest.cs
Apr 17, 2022
7359cc6
Clean Code (remove code smells / add documentation)
Apr 17, 2022
3786347
Small Bugfix in VersionController (null check)
Apr 17, 2022
a20cb73
Merge branch 'main' into user-story/save-linearized-graph
Apr 17, 2022
ed6a8ce
Additional DataFlowController.cs tests for PUT and POST
Apr 18, 2022
298a67f
Add Put_DeletesMatchingLinearizedGraph test
Apr 18, 2022
4583a41
Update LinearizedGraphControllerTest.cs
Apr 18, 2022
a686291
get Graph from API
Geissemanu Apr 19, 2022
e024822
Added post to executor
Geissemanu Apr 19, 2022
41cac30
corrected API address for graph
Geissemanu Apr 19, 2022
4e18b63
Comment and format fixed
Geissemanu Apr 19, 2022
2ad1f5b
removed code smells
Geissemanu Apr 19, 2022
9739fff
formating
Geissemanu Apr 19, 2022
0fccb83
Merge branch 'main' into user-story/save-linearized-graph
Apr 20, 2022
25a3963
Add integration tests
Apr 20, 2022
202ecf2
Fix Integration tests & add more
floomm Apr 21, 2022
d2b02ca
Fixed code smells
S4nvers Apr 22, 2022
f06022f
Renamed getGraph to getLinearizedDataflow for clarity, added some tests
S4nvers Apr 22, 2022
136f1a1
Remove Code Smell (Id may be null)
Apr 22, 2022
8ef82cf
Changes according to @DuplosFidibuss
Apr 24, 2022
1882f69
Added test for last line not covered by tests
S4nvers Apr 25, 2022
a534816
Updated tests
Geissemanu Apr 26, 2022
ae18499
format code
Geissemanu Apr 26, 2022
d0aa757
format code
Geissemanu Apr 26, 2022
f6e1b7d
Fixed spacing
S4nvers Apr 26, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 17 additions & 7 deletions src/api/Flooq.Api/Controllers/DataFlowController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ namespace Flooq.Api.Controllers
public class DataFlowController : ControllerBase
{
private readonly IDataFlowService _dataFlowService;
private readonly ILinearizedGraphService _graphService;

public DataFlowController(IDataFlowService dataFlowService)
public DataFlowController(IDataFlowService dataFlowService, ILinearizedGraphService graphService)
{
_dataFlowService = dataFlowService;
_graphService = graphService;
}

// GET: api/DataFlow
Expand All @@ -37,10 +39,9 @@ public async Task<ActionResult<IEnumerable<DataFlow>>> GetDataFlows()
/// or <see cref="NotFoundResult"/> if no <see cref="DataFlow"/> was identified by the id.
/// </returns>
[HttpGet("{id}")]
public async Task<ActionResult<DataFlow>> GetDataFlow(Guid? id)
public async Task<ActionResult<DataFlow?>> GetDataFlow(Guid? id)
{
var actionResult = await _dataFlowService.GetDataFlow(id);

return actionResult.Value == null ? NotFound() : actionResult;
}

Expand All @@ -59,14 +60,14 @@ public async Task<ActionResult<DataFlow>> GetDataFlow(Guid? id)
[HttpPut("{id}")]
public async Task<ActionResult<DataFlow>> PutDataFlow(Guid? id, DataFlow dataFlow)
{
if (id != dataFlow.Id)
if (id == null || id != dataFlow.Id)
{
return BadRequest();
}

dataFlow.LastEdited = DateTime.UtcNow;

var actionResult = _dataFlowService.PutDataFlow(dataFlow);
var actionResultDataFlow = _dataFlowService.PutDataFlow(dataFlow);

try
{
Expand All @@ -80,8 +81,17 @@ public async Task<ActionResult<DataFlow>> PutDataFlow(Guid? id, DataFlow dataFlo
}
throw;
}

// Delete LinearizedGraph of changed DataFlow
var actionResultGraph = await _graphService.GetGraph(id.Value);
var graph = actionResultGraph?.Value; // Conditional access qualifier is needed!
if (graph != null)
{
_graphService.RemoveGraph(graph);
await _graphService.SaveChangesAsync();
}

return actionResult;
return actionResultDataFlow;
}

// POST: api/DataFlow
Expand All @@ -107,7 +117,7 @@ public async Task<ActionResult<DataFlow>> PostDataFlow(DataFlow dataFlow)
_dataFlowService.AddDataFlow(dataFlow);
await _dataFlowService.SaveChangesAsync();

return CreatedAtAction("GetDataFlow", new { id = dataFlow.Id }, dataFlow);
return CreatedAtAction(nameof(GetDataFlow), new { id = dataFlow.Id }, dataFlow);
}

// DELETE: api/DataFlow/5
Expand Down
55 changes: 55 additions & 0 deletions src/api/Flooq.Api/Controllers/LinearizedGraphController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#nullable disable
using Microsoft.AspNetCore.Mvc;
using Flooq.Api.Models;
using Flooq.Api.Services;

namespace Flooq.Api.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class LinearizedGraphController : ControllerBase
{
private readonly ILinearizedGraphService _graphService;

public LinearizedGraphController(ILinearizedGraphService graphService)
{
_graphService = graphService;
}

// GET: api/LinearizedGraph
[HttpGet]
public async Task<ActionResult<IEnumerable<LinearizedGraph>>> GetGraphs()
{
return await _graphService.GetGraphs();
}

// GET: api/LinearizedGraph/5
[HttpGet("{id}")]
public async Task<ActionResult<LinearizedGraph>> GetGraph(Guid id)
{
var actionResult = await _graphService.GetGraph(id);
return actionResult.Value == null ? NotFound() : actionResult;
}

// POST: api/LinearizedGraph
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPost]
public async Task<ActionResult<LinearizedGraph>> PostGraph(LinearizedGraph linearizedGraph)
{
if (LinearizedGraphExists(linearizedGraph.Id))
{
return BadRequest();
}

_graphService.AddGraph(linearizedGraph);
await _graphService.SaveChangesAsync();

return CreatedAtAction(nameof(GetGraph), new { id = linearizedGraph.Id }, linearizedGraph);
}

private bool LinearizedGraphExists(Guid id)
{
return _graphService.LinearizedGraphExists(id);
}
}
}
2 changes: 1 addition & 1 deletion src/api/Flooq.Api/Controllers/VersionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public async Task<ActionResult<Models.Version>> GetVersion()
{
var version = await _versionService.GetLatestVersion();

return version == null ? NotFound() : version;
return version.Value == null ? NotFound() : version;
}
}
}
1 change: 1 addition & 0 deletions src/api/Flooq.Api/Domain/FlooqContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public FlooqContext(DbContextOptions<FlooqContext> options) : base(options)
{ }
public DbSet<DataFlow> DataFlows => Set<DataFlow>();
public DbSet<Version> Versions => Set<Version>();
public DbSet<LinearizedGraph> Graphs => Set<LinearizedGraph>();

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
Expand Down

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

51 changes: 51 additions & 0 deletions src/api/Flooq.Api/Migrations/20220414121539_AddLinearizedGraph.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace api.Migrations
{
public partial class AddLinearizedGraph : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DeleteData(
table: "DataFlows",
keyColumn: "Id",
keyValue: new Guid("493dd34c-55e2-4b2f-9b46-f4f8cf1e8eb7"));

migrationBuilder.CreateTable(
name: "Graphs",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
Graph = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Graphs", x => x.Id);
});

migrationBuilder.InsertData(
table: "DataFlows",
columns: new[] { "Id", "Definition", "Name", "Status" },
values: new object[] { new Guid("7b72d6dc-23cc-4b01-ad14-98938f65e2f6"), "{\r\n \"nodes\": [\r\n {\r\n \"id\": \"1\",\r\n \"dragHandle\": \".custom-drag-handle\",\r\n \"type\": \"httpIn\",\r\n \"data\": {\r\n \"title\": \"Http Input\",\r\n \"input\": {\r\n \"url\": \"https://executor.dataflow.ch/IJF9K2\",\r\n \"method\": \"post\",\r\n \"contentType\": \"application/json\",\r\n \"sampleBody\": \"{}\"\r\n },\r\n \"incomingHandles\": [],\r\n \"outgoingHandles\": [\r\n {\r\n \"id\": \"11\",\r\n \"name\": \"a\"\r\n }\r\n ]\r\n },\r\n \"position\": {\r\n \"x\": 0,\r\n \"y\": 0\r\n }\r\n },\r\n {\r\n \"id\": \"2\",\r\n \"dragHandle\": \".custom-drag-handle\",\r\n \"type\": \"filter\",\r\n \"data\": {\r\n \"title\": \"Filter\",\r\n \"filter\": {\r\n \"field\": \"tags\",\r\n \"value\": \"secret\",\r\n \"condition\": \"ne\"\r\n },\r\n \"incomingHandles\": [\r\n {\r\n \"id\": \"21\",\r\n \"name\": \"a\"\r\n }\r\n ],\r\n \"outgoingHandles\": [\r\n {\r\n \"id\": \"21\",\r\n \"name\": \"a\"\r\n }\r\n ]\r\n },\r\n \"position\": {\r\n \"x\": 400,\r\n \"y\": 100\r\n }\r\n },\r\n {\r\n \"id\": \"3\",\r\n \"dragHandle\": \".custom-drag-handle\",\r\n \"type\": \"httpOut\",\r\n \"data\": {\r\n \"title\": \"Http Output\",\r\n \"output\": {\r\n \"url\": \"\",\r\n \"method\": \"post\",\r\n \"contentType\": \"application/json\",\r\n \"sampleBody\": \"{}\"\r\n },\r\n \"incomingHandles\": [\r\n {\r\n \"id\": \"3a\",\r\n \"name\": \"a\"\r\n }\r\n ],\r\n \"outgoingHandles\": []\r\n },\r\n \"position\": {\r\n \"x\": 800,\r\n \"y\": 0\r\n }\r\n }\r\n ],\r\n \"edges\": [\r\n {\r\n \"id\": \"e1-2\",\r\n \"fromNode\": \"1\",\r\n \"fromHandle\": \"11\",\r\n \"toNode\": \"2\",\r\n \"toHandle\": \"2a\"\r\n },\r\n {\r\n \"id\": \"e2-3\",\r\n \"fromNode\": \"2\",\r\n \"fromHandle\": \"21\",\r\n \"toNode\": \"3\",\r\n \"toHandle\": \"3a\"\r\n }\r\n ]\r\n}", "Demo Flow #1", "Active" });
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Graphs");

migrationBuilder.DeleteData(
table: "DataFlows",
keyColumn: "Id",
keyValue: new Guid("7b72d6dc-23cc-4b01-ad14-98938f65e2f6"));

migrationBuilder.InsertData(
table: "DataFlows",
columns: new[] { "Id", "Definition", "LastEdited", "Name", "Status" },
values: new object[] { new Guid("493dd34c-55e2-4b2f-9b46-f4f8cf1e8eb7"), "{\r\n \"nodes\": [\r\n {\r\n \"id\": \"1\",\r\n \"dragHandle\": \".custom-drag-handle\",\r\n \"type\": \"httpIn\",\r\n \"data\": {\r\n \"title\": \"Http Input\",\r\n \"input\": {\r\n \"url\": \"https://executor.dataflow.ch/IJF9K2\",\r\n \"method\": \"post\",\r\n \"contentType\": \"application/json\",\r\n \"sampleBody\": \"{}\"\r\n },\r\n \"incomingHandles\": [],\r\n \"outgoingHandles\": [\r\n {\r\n \"id\": \"11\",\r\n \"name\": \"a\"\r\n }\r\n ]\r\n },\r\n \"position\": {\r\n \"x\": 0,\r\n \"y\": 0\r\n }\r\n },\r\n {\r\n \"id\": \"2\",\r\n \"dragHandle\": \".custom-drag-handle\",\r\n \"type\": \"filter\",\r\n \"data\": {\r\n \"title\": \"Filter\",\r\n \"filter\": {\r\n \"field\": \"tags\",\r\n \"value\": \"secret\",\r\n \"condition\": \"ne\"\r\n },\r\n \"incomingHandles\": [\r\n {\r\n \"id\": \"21\",\r\n \"name\": \"a\"\r\n }\r\n ],\r\n \"outgoingHandles\": [\r\n {\r\n \"id\": \"21\",\r\n \"name\": \"a\"\r\n }\r\n ]\r\n },\r\n \"position\": {\r\n \"x\": 400,\r\n \"y\": 100\r\n }\r\n },\r\n {\r\n \"id\": \"3\",\r\n \"dragHandle\": \".custom-drag-handle\",\r\n \"type\": \"httpOut\",\r\n \"data\": {\r\n \"title\": \"Http Output\",\r\n \"output\": {\r\n \"url\": \"\",\r\n \"method\": \"post\",\r\n \"contentType\": \"application/json\",\r\n \"sampleBody\": \"{}\"\r\n },\r\n \"incomingHandles\": [\r\n {\r\n \"id\": \"3a\",\r\n \"name\": \"a\"\r\n }\r\n ],\r\n \"outgoingHandles\": []\r\n },\r\n \"position\": {\r\n \"x\": 800,\r\n \"y\": 0\r\n }\r\n }\r\n ],\r\n \"edges\": [\r\n {\r\n \"id\": \"e1-2\",\r\n \"fromNode\": \"1\",\r\n \"fromHandle\": \"11\",\r\n \"toNode\": \"2\",\r\n \"toHandle\": \"2a\"\r\n },\r\n {\r\n \"id\": \"e2-3\",\r\n \"fromNode\": \"2\",\r\n \"fromHandle\": \"21\",\r\n \"toNode\": \"3\",\r\n \"toHandle\": \"3a\"\r\n }\r\n ]\r\n}", new DateTime(2022, 3, 5, 13, 45, 12, 0, DateTimeKind.Utc), "Demo Flow #1", "Active" });
}
}
}
14 changes: 14 additions & 0 deletions src/api/Flooq.Api/Migrations/FlooqContextModelSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.ToTable("DataFlows");
});

modelBuilder.Entity("Flooq.Api.Models.LinearizedGraph", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");

b.Property<string>("Graph")
.HasColumnType("text");

b.HasKey("Id");

b.ToTable("Graphs");
});

modelBuilder.Entity("Flooq.Api.Models.Version", b =>
{
b.Property<string>("Tag")
Expand Down
10 changes: 10 additions & 0 deletions src/api/Flooq.Api/Models/LinearizedGraph.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.ComponentModel.DataAnnotations;

namespace Flooq.Api.Models;

public class LinearizedGraph
{
[Key]
public Guid Id { get; set; }
public string? Graph { get; set; }
}
3 changes: 2 additions & 1 deletion src/api/Flooq.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

builder.Services.AddScoped<IVersionService, VersionService>();
builder.Services.AddScoped<IDataFlowService, DataFlowService>();
builder.Services.AddScoped<ILinearizedGraphService, LinearizedGraphService>();

builder.Configuration.AddEnvironmentVariables();
var app = builder.Build();
Expand All @@ -36,7 +37,7 @@
{
app.UseDeveloperExceptionPage();
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "Flooq API v1"));
app.UseSwaggerUI(options => options.SwaggerEndpoint("/swagger/v1/swagger.json", "Flooq API v1"));
}

app.UseHttpsRedirection();
Expand Down
8 changes: 3 additions & 5 deletions src/api/Flooq.Api/Services/DataFlowService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,15 @@ public async Task<ActionResult<IEnumerable<DataFlow>>> GetDataFlows()
return await _context.DataFlows.ToListAsync();
}

public async Task<ActionResult<DataFlow>> GetDataFlow(Guid? id)
public async Task<ActionResult<DataFlow?>> GetDataFlow(Guid? id)
{
var dataFlows = _context.DataFlows;
var actionResult = await dataFlows.FindAsync(id);
return actionResult;
var dataFlow = await _context.DataFlows.FindAsync(id);
return new ActionResult<DataFlow?>(dataFlow);
}

public ActionResult<DataFlow> PutDataFlow(DataFlow dataFlow)
{
_context.Entry(dataFlow).State = EntityState.Modified;

return new ActionResult<DataFlow>(dataFlow);
}

Expand Down