source: iknow-api/Controllers/UserController.cs@ b38c39c

Last change on this file since b38c39c was b38c39c, checked in by stefansaveski <stefansaveski19@…>, 11 months ago

Add user-related entities and enforce one-to-one mappings

Enhanced the User model with new entities: ContactInfo,
EnrollmentInfo, and HighSchool, establishing one-to-one
relationships. Updated UserDTO with additional fields and
introduced enums for type, quota, and major. Modified
UserRepository and AuthService to handle new entities.

Updated database schema with unique constraints on UserId
for related tables and added EF Core migration
20251027191028_dbRelations. Adjusted JSON serialization
to prevent circular references.

  • Property mode set to 100644
File size: 1.0 KB
RevLine 
[cab02ad]1using iknow_api.DTOs;
2using Microsoft.AspNetCore.Authorization;
3using Microsoft.AspNetCore.Mvc;
4using iknow_api.Services;
5
6namespace iknow_api.Controllers
7{
8 [ApiController]
9 [Route("api/[controller]")]
10 public class UserController : Controller
11 {
12 IUserService _userService;
13 public UserController(IUserService userService)
14 {
15 _userService = userService;
16 }
17 [Authorize]
18 [HttpGet("getUser")]
19 public async Task<IActionResult> getUser()
20 {
21 var authHeader = Request.Headers["Authorization"].ToString();
22 if (authHeader.StartsWith("Bearer "))
23 {
24 var token = authHeader.Substring("Bearer ".Length).Trim();
25 // token = your JWT
26 var userData = await _userService.GetUserData(token);
27 if (userData == null) return Ok(new { info = "can't get info" });
[b38c39c]28 return Ok(new { User = userData });
[cab02ad]29 }
30 return null;
31
32 }
33 }
34}
Note: See TracBrowser for help on using the repository browser.