exam_service
This commit is contained in:
74
TechHelper.Server/Controllers/ExamController.cs
Normal file
74
TechHelper.Server/Controllers/ExamController.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using Entities.Contracts;
|
||||
using Entities.DTO;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using TechHelper.Server.Services;
|
||||
using System.Security.Claims;
|
||||
|
||||
|
||||
namespace TechHelper.Server.Controllers
|
||||
{
|
||||
[Route("api/exam")]
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
|
||||
|
||||
public class ExamController : ControllerBase
|
||||
{
|
||||
private IExamService _examService;
|
||||
private readonly UserManager<User> _userManager;
|
||||
|
||||
public ExamController(IExamService examService, UserManager<User> userManager)
|
||||
{
|
||||
_examService = examService;
|
||||
_userManager = userManager;
|
||||
}
|
||||
|
||||
[HttpPost("add")]
|
||||
public async Task<IActionResult> AddExam(
|
||||
[FromBody] ExamDto examDto)
|
||||
{
|
||||
var result = await _examService.AddAsync(examDto);
|
||||
if (result.Status)
|
||||
{
|
||||
return Ok(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
return BadRequest();
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("get")]
|
||||
public async Task<IActionResult> GetExamById(Guid id)
|
||||
{
|
||||
|
||||
var result = await _examService.GetAsync(id);
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("getAllPreview")]
|
||||
public async Task<IActionResult> GetAllExamPreview(string user)
|
||||
{
|
||||
string? userId = User.Identity.Name;
|
||||
|
||||
var userid = await _userManager.FindByEmailAsync(user);
|
||||
if (userid == null) return BadRequest("用户验证失败, 无效用户");
|
||||
|
||||
|
||||
|
||||
var result = await _examService.GetAllExamPreview(userid.Id);
|
||||
|
||||
if (result.Status)
|
||||
{
|
||||
return Ok(result.Result);
|
||||
}
|
||||
return BadRequest(result);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user