Skip to content

Commit

Permalink
Merge pull request #59 from NCAR/properties
Browse files Browse the repository at this point in the history
Properties
  • Loading branch information
JoshHare authored Nov 11, 2024
2 parents 99c8438 + b9c18b9 commit 15c4573
Show file tree
Hide file tree
Showing 17 changed files with 382 additions and 1,364 deletions.
13 changes: 13 additions & 0 deletions backend/Controllers/PropertiesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ public async Task<ActionResult<Property>> GetPropertyById(Guid id)

return Ok(property);
}
// GET: api/Properties/id/{species_id}/{mechanism_id}
[HttpGet("id/{species_id}/{mechanism_id}")]
public async Task<ActionResult<Property>> GetPropertyBySandM(Guid species_id, Guid mechanism_id)
{
var property = await _propertyService.GetPropertyBySandMAsync(species_id,mechanism_id);

if (property == null)
{
return NotFound();
}

return Ok(property);
}

// POST: api/Properties
[HttpPost]
Expand Down
10 changes: 9 additions & 1 deletion backend/Models/Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public partial class Property
[Column("species_id")]
public Guid SpeciesId { get; set; }

[Column("mechanism_id")]
public Guid MechanismId { get; set; }

[Column("tolerance")]
public double Tolerance { get; set; }

Expand All @@ -28,6 +31,11 @@ public partial class Property
public double Diffusion { get; set; }

[ForeignKey(nameof(SpeciesId))]
[InverseProperty("Properties")] // Assuming you have a `Species` model with a collection of `Property`
[InverseProperty("Properties")] // Assuming you have a `Species` model with a collection of `Property`\
public virtual Species Species { get; set; } = null!;


[ForeignKey(nameof(MechanismId))]
[InverseProperty("Properties")] // Assuming you have a `Species` model with a collection of `Property`
public virtual Mechanism Mechanism { get; set; } = null!;
}
21 changes: 19 additions & 2 deletions backend/Services/PropertyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ public async Task<IReadOnlyList<Property>> GetPropertiesAsync()
return result.FirstOrDefault();
}

public async Task<Property?> GetPropertyBySandMAsync(Guid species, Guid mechanism)
{
using var connection = await _database.OpenConnectionAsync();
using var command = connection.CreateCommand();

command.CommandText = "SELECT * FROM properties WHERE species_id = @species AND mechanism_id = @mechanism";
command.Parameters.AddWithValue("@species", species);
command.Parameters.AddWithValue("@mechanism", mechanism);

var result = await ReadAllAsync(await command.ExecuteReaderAsync());
return result.FirstOrDefault();
}

public async Task<Property> CreatePropertyAsync(Property property)
{
using var connection = await _database.OpenConnectionAsync();
Expand All @@ -49,11 +62,12 @@ public async Task<Property> CreatePropertyAsync(Property property)
{
insertCommand.Transaction = transaction;
insertCommand.CommandText = @"
INSERT INTO properties (id, species_id, tolerance, weight, concentration, diffusion)
VALUES (@id, @species_id, @tolerance, @weight, @concentration, @diffusion);";
INSERT INTO properties (id, species_id, mechanism_id, tolerance, weight, concentration, diffusion)
VALUES (@id, @species_id, @mechanism_id, @tolerance, @weight, @concentration, @diffusion);";

insertCommand.Parameters.AddWithValue("@id", property.Id.ToString());
insertCommand.Parameters.AddWithValue("@species_id", property.SpeciesId.ToString());
insertCommand.Parameters.AddWithValue("@mechanism_id", property.MechanismId.ToString());
insertCommand.Parameters.AddWithValue("@tolerance", property.Tolerance);
insertCommand.Parameters.AddWithValue("@weight", property.Weight);
insertCommand.Parameters.AddWithValue("@concentration", property.Concentration);
Expand Down Expand Up @@ -82,6 +96,7 @@ public async Task UpdatePropertyAsync(Property property)
command.CommandText = @"
UPDATE properties
SET species_id = @species_id,
mechanism_id = @mechanism_id,
tolerance = @tolerance,
weight = @weight,
concentration = @concentration,
Expand All @@ -90,6 +105,7 @@ UPDATE properties

command.Parameters.AddWithValue("@id", property.Id.ToString());
command.Parameters.AddWithValue("@species_id", property.SpeciesId.ToString());
command.Parameters.AddWithValue("@mechanism_id", property.MechanismId.ToString());
command.Parameters.AddWithValue("@tolerance", property.Tolerance);
command.Parameters.AddWithValue("@weight", property.Weight);
command.Parameters.AddWithValue("@concentration", property.Concentration);
Expand Down Expand Up @@ -120,6 +136,7 @@ private async Task<IReadOnlyList<Property>> ReadAllAsync(DbDataReader reader)
{
Id = reader.GetGuid(reader.GetOrdinal("id")),
SpeciesId = reader.GetGuid(reader.GetOrdinal("species_id")),
MechanismId = reader.GetGuid(reader.GetOrdinal("mechanism_id")),
Tolerance = reader.GetDouble(reader.GetOrdinal("tolerance")),
Weight = reader.GetDouble(reader.GetOrdinal("weight")),
Concentration = reader.GetDouble(reader.GetOrdinal("concentration")),
Expand Down
Empty file removed backend/Services/test.txt
Empty file.
18 changes: 9 additions & 9 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ services:
- app-network
# test code by britt to enable live updates to frontend with docker
# use docker compose up w--watch
develop:
watch:
- action: sync
path: ./frontend
target: /app
ignore:
- node_modules/
- action: rebuild
path: package.json
# develop:
# watch:
# - action: sync
# path: ./frontend
# target: /app
# ignore:
# - node_modules/
# - action: rebuild
# path: package.json


backend:
Expand Down
Loading

0 comments on commit 15c4573

Please sign in to comment.