Skip to content

Commit aac6e33

Browse files
anjaanjaa10sntntn
authored andcommitted
Doxygen - NutrtionService
1 parent db463d6 commit aac6e33

3 files changed

Lines changed: 176 additions & 13 deletions

File tree

Fitness/Backend/Services/NutritionService/NutritionService.API/Controllers/FoodController.cs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,44 @@
55

66
namespace NutritionService.API.Controllers
77
{
8+
/// <summary>
9+
/// Provides REST API endpoints for managing food items in the nutrition database.
10+
/// </summary>
11+
/// <remarks>
12+
/// This controller supports CRUD operations for foods, allowing administrators and trainers
13+
/// to add new food entries, and all authorized users (including clients) to view the list of foods.
14+
///
15+
/// The controller interacts directly with a MongoDB collection named <c>Food</c>.
16+
/// </remarks>
817
[Authorize]
918
[ApiController]
1019
[Route("api/v1/[controller]")]
1120
public class FoodController : ControllerBase
1221
{
1322
private readonly IMongoCollection<Food> _foods;
1423

24+
/// <summary>
25+
/// Initializes a new instance of the <see cref="FoodController"/> class.
26+
/// </summary>
27+
/// <param name="db">The MongoDB database instance used to access the <c>Food</c> collection.</param>
1528
public FoodController(IMongoDatabase db)
1629
{
1730
_foods = db.GetCollection<Food>("Food");
1831
}
19-
32+
33+
/// <summary>
34+
/// Adds a new food item to the database.
35+
/// </summary>
36+
/// <param name="food">The <see cref="Food"/> object to be inserted into the database.</param>
37+
/// <returns>
38+
/// Returns:
39+
/// <list type="bullet">
40+
/// <item><description><c>200 OK</c> — if the food item was successfully added.</description></item>
41+
/// <item><description><c>400 Bad Request</c> — if the food name is missing or invalid.</description></item>
42+
/// </list>
43+
/// </returns>
44+
/// <response code="200">The food item was successfully added to the database.</response>
45+
/// <response code="400">Invalid input — the food name is required.</response>
2046
[Authorize(Roles = "Admin, Trainer")]
2147
[HttpPost]
2248
public async Task<IActionResult> AddFood([FromBody] Food food)
@@ -27,7 +53,17 @@ public async Task<IActionResult> AddFood([FromBody] Food food)
2753
await _foods.InsertOneAsync(food);
2854
return Ok(food);
2955
}
30-
56+
57+
/// <summary>
58+
/// Retrieves all available food items from the database.
59+
/// </summary>
60+
/// <returns>
61+
/// Returns:
62+
/// <list type="bullet">
63+
/// <item><description><c>200 OK</c> — a list of all food items currently stored in the database.</description></item>
64+
/// </list>
65+
/// </returns>
66+
/// <response code="200">List of food items successfully retrieved.</response>
3167
[Authorize(Roles = "Admin, Trainer, Client")]
3268
[HttpGet]
3369
public async Task<IActionResult> GetAllFoods()

Fitness/Backend/Services/NutritionService/NutritionService.API/Controllers/GoalsController.cs

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,44 @@
44
using NutritionService.API.Models;
55

66
namespace NutritionService.API.Controllers
7-
{
7+
{
8+
/// <summary>
9+
/// Provides REST API endpoints for setting and retrieving client nutrition and fitness goals.
10+
/// </summary>
11+
/// <remarks>
12+
/// This controller handles client-specific goal calculations based on biometric data,
13+
/// activity levels, and desired goal types (lose, gain, maintain).
14+
/// It interacts with the MongoDB <c>Goals</c> collection and calculates BMR, TDEE, BMI, and target calories.
15+
/// </remarks>
816
[Authorize]
917
[ApiController]
1018
[Route("api/v1/[controller]")]
1119
public class GoalsController : ControllerBase
1220
{
1321
private readonly IMongoCollection<UserGoal> _goals;
1422

23+
/// <summary>
24+
/// Initializes a new instance of the <see cref="GoalsController"/> class.
25+
/// </summary>
26+
/// <param name="db">The MongoDB database instance used to access the <c>Goals</c> collection.</param>
1527
public GoalsController(IMongoDatabase db)
1628
{
1729
_goals = db.GetCollection<UserGoal>("Goals");
1830
}
19-
31+
32+
/// <summary>
33+
/// Creates and stores a new goal for a client based on biometric and lifestyle data.
34+
/// </summary>
35+
/// <param name="goal">The <see cref="UserGoal"/> object containing the client's details and preferences.</param>
36+
/// <returns>
37+
/// Returns:
38+
/// <list type="bullet">
39+
/// <item><description><c>200 OK</c> — if the goal was calculated and saved successfully.</description></item>
40+
/// <item><description><c>400 Bad Request</c> — if the goal data is incomplete or invalid.</description></item>
41+
/// </list>
42+
/// </returns>
43+
/// <response code="200">Goal successfully created and saved.</response>
44+
/// <response code="400">Invalid or missing goal data.</response>
2045
[Authorize(Roles = "Client")]
2146
[HttpPost]
2247
public async Task<IActionResult> SetGoal([FromBody] UserGoal goal)
@@ -35,6 +60,7 @@ public async Task<IActionResult> SetGoal([FromBody] UserGoal goal)
3560
"veryActive" => 1.9,
3661
_ => 1.2,
3762
};
63+
3864
int tdee = (int)(bmr * activityFactor);
3965

4066
int adjust = goal.Intensity switch
@@ -64,7 +90,20 @@ public async Task<IActionResult> SetGoal([FromBody] UserGoal goal)
6490
await _goals.InsertOneAsync(goal);
6591
return Ok(goal);
6692
}
67-
93+
94+
/// <summary>
95+
/// Retrieves the most recent goal plan for a specific client.
96+
/// </summary>
97+
/// <param name="clientId">The unique identifier of the client.</param>
98+
/// <returns>
99+
/// Returns:
100+
/// <list type="bullet">
101+
/// <item><description><c>200 OK</c> — if a goal was found and returned successfully.</description></item>
102+
/// <item><description><c>404 Not Found</c> — if no goal exists for the specified client.</description></item>
103+
/// </list>
104+
/// </returns>
105+
/// <response code="200">Latest goal retrieved successfully.</response>
106+
/// <response code="404">No goal found for the specified client.</response>
68107
[Authorize(Roles = "Client")]
69108
[HttpGet("plan/{clientId}")]
70109
public async Task<IActionResult> GetPlan(string clientId)
@@ -76,9 +115,22 @@ public async Task<IActionResult> GetPlan(string clientId)
76115

77116
if (goal == null)
78117
return NotFound("No goal found for this client.");
118+
79119
return Ok(goal);
80120
}
81-
121+
122+
/// <summary>
123+
/// Retrieves all goals stored in the database (admin or trainer overview).
124+
/// </summary>
125+
/// <returns>
126+
/// Returns:
127+
/// <list type="bullet">
128+
/// <item><description><c>200 OK</c> — list of all goals in simplified form (ClientId, BMI, TargetKcal).</description></item>
129+
/// <item><description><c>404 Not Found</c> — if there are no stored goals.</description></item>
130+
/// </list>
131+
/// </returns>
132+
/// <response code="200">List of goals retrieved successfully.</response>
133+
/// <response code="404">No goals found in the database.</response>
82134
[Authorize(Roles = "Admin, Trainer, Client")]
83135
[HttpGet("all")]
84136
public async Task<IActionResult> GetAllGoals()

Fitness/Backend/Services/NutritionService/NutritionService.API/Controllers/MealPlansController.cs

Lines changed: 82 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@
44
using NutritionService.API.Models;
55

66
namespace NutritionService.API.Controllers
7-
{
7+
{
8+
/// <summary>
9+
/// Provides REST API endpoints for creating, retrieving, and deleting meal plans for clients based on their goals.
10+
/// </summary>
11+
/// <remarks>
12+
/// Trainers can create personalized meal plans for different goal types (lose, gain, maintain),
13+
/// while admins, trainers, and clients can retrieve existing plans.
14+
/// Each meal plan consists of predefined meals (breakfast, lunch, dinner, snacks) composed of available foods.
15+
/// </remarks>
816
[Authorize]
917
[ApiController]
1018
[Route("api/v1/[controller]")]
@@ -13,12 +21,29 @@ public class MealPlansController : ControllerBase
1321
private readonly IMongoCollection<MealPlan> _plans;
1422
private readonly IMongoCollection<Food> _foods;
1523

24+
/// <summary>
25+
/// Initializes a new instance of the <see cref="MealPlansController"/> class.
26+
/// </summary>
27+
/// <param name="db">The MongoDB database instance used to access the <c>MealPlans</c> and <c>Food</c> collections.</param>
1628
public MealPlansController(IMongoDatabase db)
1729
{
1830
_plans = db.GetCollection<MealPlan>("MealPlans");
1931
_foods = db.GetCollection<Food>("Food");
2032
}
21-
33+
34+
/// <summary>
35+
/// Creates or updates a meal plan for a specific trainer and goal type.
36+
/// </summary>
37+
/// <param name="plan">The <see cref="MealPlan"/> object containing meals and trainer information.</param>
38+
/// <returns>
39+
/// Returns:
40+
/// <list type="bullet">
41+
/// <item><description><c>200 OK</c> — if the plan was successfully created or updated.</description></item>
42+
/// <item><description><c>400 Bad Request</c> — if required fields (TrainerId, TrainerName, or GoalType) are missing.</description></item>
43+
/// </list>
44+
/// </returns>
45+
/// <response code="200">Meal plan created or updated successfully.</response>
46+
/// <response code="400">Required data missing or invalid.</response>
2247
[Authorize(Roles = "Trainer")]
2348
[HttpPost]
2449
public async Task<IActionResult> CreatePlan([FromBody] MealPlan plan)
@@ -47,7 +72,6 @@ async Task<List<Food>> FillFoodsAsync(List<Food> foods)
4772
plan.Snacks = await FillFoodsAsync(plan.Snacks);
4873
plan.CreatedAt = DateTime.UtcNow;
4974

50-
5175
var existing = await _plans
5276
.Find(p => p.TrainerId == plan.TrainerId && p.GoalType == plan.GoalType)
5377
.FirstOrDefaultAsync();
@@ -60,7 +84,21 @@ async Task<List<Food>> FillFoodsAsync(List<Food> foods)
6084
await _plans.InsertOneAsync(plan);
6185
return Ok(plan);
6286
}
63-
87+
88+
/// <summary>
89+
/// Retrieves a specific meal plan created by a trainer for a given goal type.
90+
/// </summary>
91+
/// <param name="trainerId">The unique identifier of the trainer.</param>
92+
/// <param name="goalType">The goal type associated with the plan (lose, gain, maintain).</param>
93+
/// <returns>
94+
/// Returns:
95+
/// <list type="bullet">
96+
/// <item><description><c>200 OK</c> — the corresponding meal plan was found.</description></item>
97+
/// <item><description><c>404 Not Found</c> — no plan exists for the specified trainer and goal type.</description></item>
98+
/// </list>
99+
/// </returns>
100+
/// <response code="200">Meal plan successfully retrieved.</response>
101+
/// <response code="404">No matching plan found.</response>
64102
[Authorize(Roles = "Admin, Trainer, Client")]
65103
[HttpGet("trainer/{trainerId}/goal/{goalType}")]
66104
public async Task<IActionResult> GetPlanByTrainerAndGoal(string trainerId, string goalType)
@@ -75,15 +113,38 @@ public async Task<IActionResult> GetPlanByTrainerAndGoal(string trainerId, strin
75113

76114
return Ok(plan);
77115
}
78-
116+
117+
/// <summary>
118+
/// Retrieves all meal plans available in the system.
119+
/// </summary>
120+
/// <returns>
121+
/// Returns:
122+
/// <list type="bullet">
123+
/// <item><description><c>200 OK</c> — all existing meal plans retrieved successfully.</description></item>
124+
/// </list>
125+
/// </returns>
126+
/// <response code="200">List of all meal plans retrieved.</response>
79127
[Authorize(Roles = "Admin, Trainer, Client")]
80128
[HttpGet]
81129
public async Task<IActionResult> GetAllPlans()
82130
{
83131
var plans = await _plans.Find(_ => true).ToListAsync();
84132
return Ok(plans);
85133
}
86-
134+
135+
/// <summary>
136+
/// Retrieves all meal plans associated with a specific trainer.
137+
/// </summary>
138+
/// <param name="trainerId">The unique identifier of the trainer.</param>
139+
/// <returns>
140+
/// Returns:
141+
/// <list type="bullet">
142+
/// <item><description><c>200 OK</c> — list of all plans created by the specified trainer.</description></item>
143+
/// <item><description><c>404 Not Found</c> — no plans found for the trainer.</description></item>
144+
/// </list>
145+
/// </returns>
146+
/// <response code="200">Trainer’s plans retrieved successfully.</response>
147+
/// <response code="404">No plans found for the specified trainer.</response>
87148
[Authorize(Roles = "Admin, Trainer, Client")]
88149
[HttpGet("trainer/{trainerId}")]
89150
public async Task<IActionResult> GetPlansForTrainer(string trainerId)
@@ -95,7 +156,21 @@ public async Task<IActionResult> GetPlansForTrainer(string trainerId)
95156

96157
return Ok(trainerPlans);
97158
}
98-
159+
160+
/// <summary>
161+
/// Deletes a specific meal plan for a trainer and goal type.
162+
/// </summary>
163+
/// <param name="trainerId">The unique identifier of the trainer.</param>
164+
/// <param name="goalType">The goal type of the plan to be deleted.</param>
165+
/// <returns>
166+
/// Returns:
167+
/// <list type="bullet">
168+
/// <item><description><c>200 OK</c> — if the plan was deleted successfully.</description></item>
169+
/// <item><description><c>404 Not Found</c> — if no plan was found for the specified trainer and goal type.</description></item>
170+
/// </list>
171+
/// </returns>
172+
/// <response code="200">Plan deleted successfully.</response>
173+
/// <response code="404">No plan found for the given trainer and goal type.</response>
99174
[Authorize(Roles = "Trainer")]
100175
[HttpDelete("trainer/{trainerId}/goal/{goalType}")]
101176
public async Task<IActionResult> DeletePlan(string trainerId, string goalType)

0 commit comments

Comments
 (0)