Renamed some of the goal fields to align with business logic

This commit is contained in:
ivan-pelly
2026-03-14 16:30:17 -07:00
parent 7f91e2e557
commit 4d9b83c327
50 changed files with 279 additions and 149 deletions
+3 -2
View File
@@ -1,10 +1,11 @@
{
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5123",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
+47
View File
@@ -405,4 +405,51 @@ public class AuthController : BaseController
Message = "Logged out successfully."
});
}
// *****************************************************************
// Sets the password hash and salt for an existing user.
// Accepts a user ID and plaintext password, hashes it, and stores
// the result in the user table.
// *****************************************************************
[HttpPost("SetPassword")]
[ProducesResponseType(typeof(ResponseResult<object>), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ResponseResult<object>), StatusCodes.Status400BadRequest)]
public async Task<ActionResult<ResponseResult<object>>> SetPassword([FromBody] SetPasswordDto dto)
{
if (string.IsNullOrWhiteSpace(dto.UserId) || string.IsNullOrWhiteSpace(dto.Password))
{
return BadRequest(new ResponseResult<object>
{
Success = false,
Message = "User ID and password are required."
});
}
if (!Guid.TryParse(dto.UserId, out Guid userId))
{
return BadRequest(new ResponseResult<object>
{
Success = false,
Message = "Invalid user ID format."
});
}
var (hash, salt) = PasswordHasher.HashPassword(dto.Password);
var updated = await _userRepo.SetPasswordAsync(userId, hash, salt);
if (!updated)
{
return Ok(new ResponseResult<object>
{
Success = false,
Message = "User not found."
});
}
return Ok(new ResponseResult<object>
{
Success = true,
Message = "Password set successfully."
});
}
}
@@ -2,8 +2,8 @@ namespace WinStudentGoalTracker.DataAccess;
public class CreateGoalDto
{
public string? Title { get; set; }
public string? Description { get; set; }
public string? Category { get; set; }
public string? Baseline { get; set; }
public Guid? GoalParentId { get; set; }
}
@@ -0,0 +1,7 @@
namespace WinStudentGoalTracker.DataAccess;
public class SetPasswordDto
{
public string? UserId { get; set; }
public string? Password { get; set; }
}
@@ -2,7 +2,7 @@ namespace WinStudentGoalTracker.DataAccess;
public class UpdateGoalDto
{
public string? Title { get; set; }
public string? Description { get; set; }
public string? Category { get; set; }
public string? Baseline { get; set; }
}
@@ -5,7 +5,7 @@ public class dbStudentBenchmarkRow
public string? StudentIdentifier { get; set; }
public required Guid BenchmarkId { get; set; }
public required Guid GoalId { get; set; }
public string? GoalTitle { get; set; }
public string? GoalCategory { get; set; }
public string? Benchmark { get; set; }
public string? CreatedByName { get; set; }
public DateTime CreatedAt { get; set; }
@@ -5,9 +5,9 @@ public class dbStudentGoalRow
public string? StudentIdentifier { get; set; }
public required Guid GoalId { get; set; }
public Guid? GoalParentId { get; set; }
public string? Title { get; set; }
public string? Description { get; set; }
public string? Category { get; set; }
public string? Baseline { get; set; }
public int ProgressEventCount { get; set; }
public int BenchmarkCount { get; set; }
}
@@ -144,9 +144,9 @@ public class StudentRepository
p_id_goal_parent = dto.GoalParentId?.ToString(),
p_id_student = idStudent.ToString(),
p_id_user_created = userId.ToString(),
p_title = dto.Title,
p_description = dto.Description,
p_category = dto.Category
p_category = dto.Category,
p_baseline = dto.Baseline
},
commandType: CommandType.StoredProcedure);
@@ -156,9 +156,9 @@ public class StudentRepository
{
GoalId = newGoalId,
GoalParentId = dto.GoalParentId,
Title = dto.Title,
Description = dto.Description,
Category = dto.Category,
Baseline = dto.Baseline,
ProgressEventCount = 0
};
}
@@ -191,9 +191,9 @@ public class StudentRepository
{
GoalId = r.GoalId,
GoalParentId = r.GoalParentId,
Title = r.Title,
Description = r.Description,
Category = r.Category,
Baseline = r.Baseline,
ProgressEventCount = r.ProgressEventCount,
BenchmarkCount = r.BenchmarkCount
}).ToList()
@@ -201,7 +201,7 @@ public class StudentRepository
}
// *****************************************************************
// Updates a goal's title, description, and category.
// Updates a goal's description, category, and baseline.
// *****************************************************************
public async Task<bool> UpdateGoalAsync(Guid goalId, UpdateGoalDto dto)
{
@@ -214,9 +214,9 @@ public class StudentRepository
p_id_goal_parent = (string?)null,
p_id_student = (string?)null,
p_id_user_created = (string?)null,
p_title = dto.Title,
p_description = dto.Description,
p_category = dto.Category
p_category = dto.Category,
p_baseline = dto.Baseline
},
commandType: CommandType.StoredProcedure);
return rowsAffected > 0;
@@ -254,7 +254,7 @@ public class StudentRepository
{
BenchmarkId = r.BenchmarkId,
GoalId = r.GoalId,
GoalTitle = r.GoalTitle,
GoalCategory = r.GoalCategory,
Benchmark = r.Benchmark,
CreatedByName = r.CreatedByName,
CreatedAt = r.CreatedAt,
@@ -43,4 +43,23 @@ public class UserRepository
new { p_id_user = idUser.ToString() },
commandType: CommandType.StoredProcedure);
}
// *****************************************************************
// Updates the password hash and salt for the given user.
// Returns true if the user was found and updated.
// *****************************************************************
public async Task<bool> SetPasswordAsync(Guid userId, string passwordHash, string passwordSalt)
{
using var db = Connection;
var rowsAffected = await db.QuerySingleOrDefaultAsync<int>(
"sp_User_SetPassword",
new
{
p_id_user = userId.ToString(),
p_password_hash = passwordHash,
p_password_salt = passwordSalt
},
commandType: CommandType.StoredProcedure);
return rowsAffected > 0;
}
}
@@ -4,7 +4,7 @@ public class StudentBenchmarkItem
{
public Guid BenchmarkId { get; set; }
public Guid GoalId { get; set; }
public string? GoalTitle { get; set; }
public string? GoalCategory { get; set; }
public string? Benchmark { get; set; }
public string? CreatedByName { get; set; }
public DateTime CreatedAt { get; set; }
@@ -4,9 +4,9 @@ public class StudentGoalItem
{
public Guid GoalId { get; set; }
public Guid? GoalParentId { get; set; }
public string? Title { get; set; }
public string? Description { get; set; }
public string? Category { get; set; }
public string? Baseline { get; set; }
public int ProgressEventCount { get; set; }
public int BenchmarkCount { get; set; }
}