C
C#4mo ago
Joszko

✅ [SOLVED] Weird DTO response

Hi! I'm working with Dotnet8 and im creating a web app with Vue. I wanted console.log a DTO which looks like this: { "contentType": null, "serializerSettings": null, "statusCode": null, "value": { "data": { "nickname": "Joszko", "money": 1000, "energy": 100, "rank": "Silver_I", "level": 10, "experience": 500, "levelPoints": 50, "healthPoints": 200, "attackPoints": 150, "defensePoints": 100, "luckPoints": 80, "intelligencePoints": 70 }, "success": true, "message": "" } } Instead im getting this object which is the full object 0_0: Proxy(Object) [[Target]]: Object account: null accountId: 1 armour: null attackPoints: 150 defensePoints: 100 energy: 100 eqArmourId: null eqWeaponId: null experience: 500 healthPoints: 200 id: 1 intelligencePoints: 70 level: 10 levelPoints: 50 luckPoints: 80 money: 1000 rank: "Silver_I" stats: null student_Armours: [] student_Foods: [] student_Weapons: [] weapon: null
10 Replies
Joszko
JoszkoOP4mo ago
i mean, why account, id or even weapon is showing if it is not in the DTO data
Pobiega
Pobiega4mo ago
I see no C# or .NET in this question. Can you perhaps show the C# code for the endpoint you are getting this data from?
Jimmacle
Jimmacle4mo ago
well, whatever object you're logging has that data in it it doesn't just come from thin air
Joszko
JoszkoOP4mo ago
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; } 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))); } and Dto in swagger looks like it should but idk why it is showing this odd things when consol.logging it in browser i mean, i even showed you output from swagger xD
Pobiega
Pobiega4mo ago
And what does GetStudentProfileDTO look like?
Joszko
JoszkoOP4mo ago
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; }
Pobiega
Pobiega4mo ago
you are not loggign what yhou think you are loggign then your "error" is somewhere in your vue code
Joszko
JoszkoOP4mo ago
hmmm, weird cause im using the GetStudentProfile 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); } } call looks like that profile: { nickname: 'none', money: 0, energy: 0, rank: 'none', level: 0, experience: 0, levelPoints: 0, healthPoints: 0, attackPoints: 0, defensePoints: 0, luckPoints: 0, intelligencePoints: 0 } }; and thats profile that's why i don't like frontend ;.; Ok, found the issue, axios.get is getting the wrong thing because of param
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX4mo ago
If you have no further questions, please use /close to mark the forum thread as answered

Did you find this page helpful?