44using NutritionService . API . Models ;
55
66namespace 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