Joszko
✅ [SOLVED] Weird DTO response
async fetchProfile() {
try {
const response = await axios.get('http://localhost:5033/api/Student/GetStudentProfile', {
params: {
StudentId: 1 // tutaj ustalamy jakiego uzytkownika id chcemy
}
});
if (response.data.value.success) {
this.profile = response.data.value.data;
console.log("Profil:", this.profile);
} else {
console.error("Failed to fetch profile: ", response.data.value.message);
}
} catch (error) {
console.error("Error fetching profile: ", error);
}
}
22 replies
✅ [SOLVED] Weird DTO response
public class GetStudentProfileDTO
{
public string Nickname { get; set;} = string.Empty;
public int Money { get; set; } = 0;
public int Energy { get; set; } = 100;
public Ranks Rank { get; set; } = Ranks.Silver_I;
public int Level { get; set; } = 1;
public int Experience { get; set; } = 0;
public int LevelPoints { get; set; } = 0;
public int HealthPoints { get; set; } = 100;
public int AttackPoints { get; set; } = 1;
public int DefensePoints { get; set; } = 1;
public int LuckPoints { get; set; } = 1;
public int IntelligencePoints { get; set; } = 1;
}
22 replies
✅ [SOLVED] Weird DTO response
it's service call which later im passing to controller:
[HttpGet("GetStudentProfile{StudentId}")]
public async Task<IActionResult> GetStudentProfile(int StudentId)
{
return Ok(new JsonResult(await _studentService.GetStudentProfile(StudentId)));
}
22 replies
✅ [SOLVED] Weird DTO response
public async Task<ServiceResponse<GetStudentProfileDTO>> GetStudentProfile(int StudentId)
{
var serviceResponse = new ServiceResponse<GetStudentProfileDTO>();
try
{
var student = await _context.Students
.Include(c => c.Account)
.FirstOrDefaultAsync(x => x.Id == StudentId);
if (student is not null)
{
GetStudentProfileDTO response = student.Adapt<GetStudentProfileDTO>();
response.Nickname = student.Account.Nickname;
serviceResponse.Data = response;
}
else{
serviceResponse.Success = false;
serviceResponse.Message = $"Brak studenta o {StudentId} id";
}
}
catch (Exception ex)
{
serviceResponse.Success = false;
serviceResponse.Message = $"Error: {ex.Message}";
return serviceResponse;
}
return serviceResponse;
}
22 replies