i'm sorry guys it's stupid commit...
This commit is contained in:
parent
77cfacb95e
commit
4b4739ce89
13 changed files with 174 additions and 1 deletions
|
|
@ -0,0 +1,48 @@
|
|||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SurveyBackend.Contexts;
|
||||
using SurveyBackend.Core.Contexts;
|
||||
using SurveyBackend.DTOs.Completion;
|
||||
using SurveyBackend.Mappers;
|
||||
using SurveyLib.Core.Models;
|
||||
using SurveyLib.Core.Services;
|
||||
|
||||
namespace SurveyBackend.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/surveys/{surveyId:int}/completions")]
|
||||
public class CompletionController : ControllerBase
|
||||
{
|
||||
private readonly ICompletionService _completionService;
|
||||
private readonly IUserContext _userContext;
|
||||
|
||||
public CompletionController(ICompletionService completionService, IUserContext userContext)
|
||||
{
|
||||
_completionService = completionService;
|
||||
_userContext = userContext;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Authorize]
|
||||
public async Task<IActionResult> GetCompletionsAsync(int surveyId)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
[HttpGet("{id:int}")]
|
||||
[Authorize]
|
||||
public async Task<IActionResult> GetCompletionAsync(int id)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[AllowAnonymous]
|
||||
public async Task<IActionResult> PostCompletionAsync([FromBody] CompletionCreateDto dto, [FromRoute] int surveyId)
|
||||
{
|
||||
var userId = _userContext.NullableUserId;
|
||||
var model = CompletionMapper.CreateDtoToModel(dto, surveyId, userId);
|
||||
await _completionService.AddCompletionAsync(model);
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
namespace SurveyBackend.DTOs.Answer;
|
||||
|
||||
public class AnswerCreateDto
|
||||
{
|
||||
public int QuestionId { get; set; }
|
||||
public required string AnswerText { get; set; }
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
namespace SurveyBackend.DTOs.Answer;
|
||||
|
||||
public class AnswerOutputDto
|
||||
{
|
||||
public int QuestionId { get; set; }
|
||||
public int CompletionId { get; set; }
|
||||
public required string AnswerText { get; set; }
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
using SurveyBackend.DTOs.Answer;
|
||||
|
||||
namespace SurveyBackend.DTOs.Completion;
|
||||
|
||||
public class CompletionCreateDto
|
||||
{
|
||||
public List<AnswerCreateDto> Answers { get; set; }
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
using SurveyBackend.DTOs.Answer;
|
||||
|
||||
namespace SurveyBackend.DTOs.Completion;
|
||||
|
||||
public class CompletionOutputDto
|
||||
{
|
||||
public int? CompletedBy { get; set; }
|
||||
public DateTime FinishedAt { get; set; }
|
||||
public List<AnswerOutputDto> Answers { get; set; }
|
||||
}
|
||||
20
SurveyBackend/SurveyBackend.API/Mappers/AnswerMapper.cs
Normal file
20
SurveyBackend/SurveyBackend.API/Mappers/AnswerMapper.cs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
using SurveyBackend.DTOs.Answer;
|
||||
using SurveyLib.Core.Models;
|
||||
|
||||
namespace SurveyBackend.Mappers;
|
||||
|
||||
public static class AnswerMapper
|
||||
{
|
||||
public static Answer CreateDtoToModel(AnswerCreateDto dto) => new Answer
|
||||
{
|
||||
QuestionId = dto.QuestionId,
|
||||
AnswerText = dto.AnswerText,
|
||||
};
|
||||
|
||||
public static AnswerOutputDto ModelToOutputDto(Answer model) => new AnswerOutputDto
|
||||
{
|
||||
QuestionId = model.QuestionId,
|
||||
AnswerText = model.AnswerText,
|
||||
CompletionId = model.CompletionId,
|
||||
};
|
||||
}
|
||||
21
SurveyBackend/SurveyBackend.API/Mappers/CompletionMapper.cs
Normal file
21
SurveyBackend/SurveyBackend.API/Mappers/CompletionMapper.cs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
using SurveyBackend.DTOs.Completion;
|
||||
using SurveyLib.Core.Models;
|
||||
|
||||
namespace SurveyBackend.Mappers;
|
||||
|
||||
public static class CompletionMapper
|
||||
{
|
||||
public static Completion CreateDtoToModel(CompletionCreateDto dto, int surveyId, int? performerId) => new Completion
|
||||
{
|
||||
SurveyId = surveyId,
|
||||
CompletedBy = performerId,
|
||||
Answers = dto.Answers.Select(AnswerMapper.CreateDtoToModel).ToList(),
|
||||
};
|
||||
|
||||
public static CompletionOutputDto ModelToOutputDto(Completion model) => new CompletionOutputDto
|
||||
{
|
||||
CompletedBy = model.CompletedBy,
|
||||
FinishedAt = model.FinishedAt,
|
||||
Answers = model.Answers.Select(AnswerMapper.ModelToOutputDto).ToList(),
|
||||
};
|
||||
}
|
||||
|
|
@ -12,6 +12,7 @@ using SurveyBackend.Infrastructure.Data;
|
|||
using SurveyBackend.Infrastructure.Repositories;
|
||||
using SurveyBackend.Middlewares;
|
||||
using SurveyBackend.Services;
|
||||
using SurveyBackend.Services.Helpers;
|
||||
using SurveyBackend.Services.Services;
|
||||
using SurveyLib.Core.Repositories;
|
||||
using SurveyLib.Core.Services;
|
||||
|
|
@ -49,10 +50,12 @@ public class Program
|
|||
builder.Services.AddScoped<ISurveyRepository, SurveyRepository>();
|
||||
builder.Services.AddScoped<IQuestionRepository, QuestionRepository>();
|
||||
builder.Services.AddScoped<IAnswerVariantsRepository, AnswerVariantsRepository>();
|
||||
builder.Services.AddScoped<ICompletionRepository, CompletionRepository>();
|
||||
|
||||
builder.Services.AddScoped<ISurveyService, SurveyService>();
|
||||
builder.Services.AddScoped<IQuestionService, QuestionService>();
|
||||
builder.Services.AddScoped<IAnswerVariantsService, AnswerVariantsService>();
|
||||
builder.Services.AddScoped<ICompletionService, CompletionService>();
|
||||
|
||||
|
||||
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
||||
|
|
|
|||
|
|
@ -15,26 +15,31 @@ public class AnswerVariantsService : IAnswerVariantsService
|
|||
|
||||
public async Task AddAnswerVariantAsync(AnswerVariant answerVariant)
|
||||
{
|
||||
// TODO: проверка существования такого вопроса
|
||||
await _answerVariantsRepository.AddAsync(answerVariant);
|
||||
}
|
||||
|
||||
public async Task UpdateAnswerVariantAsync(AnswerVariant answerVariant)
|
||||
{
|
||||
// TODO: опять проверка существования, но еще и варианта
|
||||
await _answerVariantsRepository.UpdateAsync(answerVariant);
|
||||
}
|
||||
|
||||
public async Task DeleteAnswerVariantAsync(int id)
|
||||
{
|
||||
// TODO: проверка существования варианта
|
||||
await _answerVariantsRepository.DeleteAsync(id);
|
||||
}
|
||||
|
||||
public async Task<AnswerVariant> GetAnswerVariantByIdAsync(int id)
|
||||
{
|
||||
// TODO: проверка существования варианта
|
||||
return await _answerVariantsRepository.GetByIdAsync(id);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<AnswerVariant>> GetAnswerVariantsByQuestionIdAsync(int questionId)
|
||||
{
|
||||
// TODO: проверка существования вопроса
|
||||
return await _answerVariantsRepository.GetAnswerVariantsByQuestionIdAsync(questionId);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
using SurveyLib.Core.Models;
|
||||
using SurveyLib.Core.Repositories;
|
||||
using SurveyLib.Core.Services;
|
||||
|
||||
namespace SurveyBackend.Services.Services;
|
||||
|
||||
public class CompletionService : ICompletionService
|
||||
{
|
||||
private readonly ICompletionRepository _completionRepository;
|
||||
|
||||
public CompletionService(ICompletionRepository completionRepository)
|
||||
{
|
||||
_completionRepository = completionRepository;
|
||||
}
|
||||
|
||||
public async Task AddCompletionAsync(Completion completion)
|
||||
{
|
||||
// TODO: проверить существование опроса
|
||||
await _completionRepository.AddAsync(completion);
|
||||
}
|
||||
|
||||
public async Task UpdateCompletionAsync(Completion completion)
|
||||
{
|
||||
// TODO: лол а что вообще значит ОбновитьВыполнение, надо выпилить из SurveyLib
|
||||
await _completionRepository.UpdateAsync(completion);
|
||||
}
|
||||
|
||||
public async Task DeleteCompletionAsync(int id)
|
||||
{
|
||||
// TODO: да и удалять их как-то бессмысленно
|
||||
await _completionRepository.DeleteAsync(id);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Completion>> GetCompletionsBySurveyIdAsync(int surveyId)
|
||||
{
|
||||
// TODO: проверить существование опроса
|
||||
// TODO: проверить что запрашивает создатель (хз как)
|
||||
return await _completionRepository.GetCompletionsBySurveyIdAsync(surveyId);
|
||||
}
|
||||
}
|
||||
|
|
@ -22,11 +22,13 @@ public class QuestionService : IQuestionService
|
|||
|
||||
public async Task AddQuestionAsync(QuestionBase question)
|
||||
{
|
||||
// TODO: проверить существование опроса
|
||||
await _questionRepository.AddAsync(question);
|
||||
}
|
||||
|
||||
public async Task UpdateQuestionAsync(QuestionBase question)
|
||||
{
|
||||
// TODO: проверить существование вопроса
|
||||
await _questionRepository.UpdateAsync(question);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ public class SurveyService : ISurveyService
|
|||
|
||||
public async Task<IEnumerable<Survey>> GetSurveysByUserIdAsync(int userId)
|
||||
{
|
||||
// TODO: проверить существование юзера
|
||||
return await _surveyRepository.GetSurveysByUserIdAsync(userId);
|
||||
}
|
||||
}
|
||||
|
|
@ -1 +1 @@
|
|||
Subproject commit 7d47ab9e60645032bc41daee5535aba2b7eeebdf
|
||||
Subproject commit 14d0f36cb801c707104af14d6cebe6da866d848a
|
||||
Loading…
Add table
Add a link
Reference in a new issue