-
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.
Added first API endpoints for Metrics
- Loading branch information
Showing
14 changed files
with
75 additions
and
42 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
33 changes: 33 additions & 0 deletions
33
GainsTracker.CoreAPI/Components/HealthMetrics/Controllers/HealthMetricController.cs
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,33 @@ | ||
using GainsTracker.CoreAPI.Components.HealthMetrics.Models; | ||
using GainsTracker.CoreAPI.Components.HealthMetrics.Services; | ||
using GainsTracker.CoreAPI.Components.HealthMetrics.Services.Dto; | ||
using GainsTracker.CoreAPI.Configurations.Controllers; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace GainsTracker.CoreAPI.Components.HealthMetrics.Controllers; | ||
|
||
[ApiController] | ||
[Authorize] | ||
[Route("gains/health-metric")] | ||
public class HealthMetricController : ExtendedControllerBase | ||
{ | ||
private readonly IHealthMetricService _metricService; | ||
|
||
public HealthMetricController(IHealthMetricService metricService) | ||
{ | ||
_metricService = metricService; | ||
} | ||
|
||
[HttpGet] | ||
public List<Metric> GetAllMetrics() | ||
{ | ||
return _metricService.GetAllMetricsByUsername(CurrentUsername); | ||
} | ||
|
||
[HttpPost] | ||
public void CreateMetric(MetricDto metricDto) | ||
{ | ||
_metricService.AddMetricToGainsAccount(CurrentUsername, metricDto); | ||
} | ||
} |
18 changes: 0 additions & 18 deletions
18
GainsTracker.CoreAPI/Components/HealthMetrics/Controllers/HealthMetricControllerBase.cs
This file was deleted.
Oops, something went wrong.
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
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
16 changes: 7 additions & 9 deletions
16
GainsTracker.CoreAPI/Components/HealthMetrics/Models/ProteinMetric.cs
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 |
---|---|---|
@@ -1,20 +1,18 @@ | ||
using GainsTracker.Common.Models; | ||
using GainsTracker.Common.Models.Generic; | ||
|
||
namespace GainsTracker.CoreAPI.Components.HealthMetrics.Models; | ||
|
||
public class ProteinMetric : Metric | ||
public class ProteinMetric : Metric, ITrackableGoal<ProteinMetric> | ||
{ | ||
public ProteinMetric() | ||
{ | ||
Date = DateTime.UtcNow; | ||
} | ||
|
||
public string Id { get; set; } = Guid.NewGuid().ToString(); | ||
public DateTime Date { get; init; } | ||
public long TotalProteinIntake { get; set; } | ||
|
||
public Goal<ProteinMetric> CreateAsGoal() | ||
{ | ||
throw new NotImplementedException(); | ||
if (_isInGoal) | ||
throw new ArgumentException("Already in a goal!"); | ||
_isInGoal = true; | ||
|
||
return new Goal<ProteinMetric>(this); | ||
} | ||
} |
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
2 changes: 2 additions & 0 deletions
2
GainsTracker.CoreAPI/Components/HealthMetrics/Services/IHealthMetricService.cs
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 |
---|---|---|
@@ -1,8 +1,10 @@ | ||
using GainsTracker.CoreAPI.Components.HealthMetrics.Models; | ||
using GainsTracker.CoreAPI.Components.HealthMetrics.Services.Dto; | ||
|
||
namespace GainsTracker.CoreAPI.Components.HealthMetrics.Services; | ||
|
||
public interface IHealthMetricService | ||
{ | ||
void AddMetricToGainsAccount(string userHandle, MetricDto metricDto); | ||
List<Metric> GetAllMetricsByUsername(string currentUsername); | ||
} |
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
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
5 changes: 0 additions & 5 deletions
5
GainsTracker.CoreAPI/Components/Workouts/Controllers/Examples/GainsExamplesController.cs
This file was deleted.
Oops, something went wrong.
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
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
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