-
Notifications
You must be signed in to change notification settings - Fork 2
STD - 39 | Realize Tag Controller #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Evenya
wants to merge
6
commits into
dev
Choose a base branch
from
STD-39
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2a9329f
Query Task added
Evenya cc6f1ba
Merge remote-tracking branch 'origin/dev' into dev
Evenya f253469
Add TagController.cs
Evenya 9bc9409
TagController.cs
Evenya 4db6d1f
Add GetTagsQuery (hotfix)
zefirlover 44dff11
Merge remote-tracking branch 'origin/STD-39' into STD-39
zefirlover File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| using System.Threading.Tasks; | ||
| using AutoMapper; | ||
| using MediatR; | ||
| using Microsoft.AspNetCore.Mvc; | ||
| using StudySharp.API.Requests.Tags; | ||
| using StudySharp.API.Responses.Tags; | ||
| using StudySharp.ApplicationServices.Commands; | ||
| using StudySharp.ApplicationServices.Queries; | ||
| using StudySharp.Domain.General; | ||
|
|
||
| namespace StudySharp.API.Controllers | ||
| { | ||
| // [Authorize] | ||
| [ApiController] | ||
| [Route("api/tags")] | ||
|
|
||
| public class GetTagsController : ControllerBase | ||
| { | ||
| private readonly IMediator _mediator; | ||
| private readonly IMapper _mapper; | ||
|
|
||
| public GetTagsController(IMediator mediator, IMapper mapper) | ||
| { | ||
| _mediator = mediator; | ||
| _mapper = mapper; | ||
| } | ||
|
|
||
| [HttpPost] | ||
| public async Task<OperationResult> Add([FromBody] AddTagRequest addTagRequest) | ||
| { | ||
| var addTagCommand = _mapper.Map<AddTagCommand>(addTagRequest); | ||
| return await _mediator.Send(addTagCommand); | ||
| } | ||
|
|
||
| [HttpGet("{id:int}")] | ||
| public async Task<OperationResult<GetTagByIdResponse>> GetTagById([FromRoute] GetTagByIdRequest getTagByIdRequest) | ||
| { | ||
| var getTagByIdQuery = _mapper.Map<GetTagByIdQuery>(getTagByIdRequest); | ||
| var operationResult = await _mediator.Send(getTagByIdQuery); | ||
|
|
||
| if (!operationResult.IsSucceeded) | ||
| { | ||
| return OperationResult.Fail<GetTagByIdResponse>(operationResult.Errors); | ||
| } | ||
|
|
||
| var response = _mapper.Map<GetTagByIdResponse>(operationResult.Result); | ||
| return OperationResult.Ok(response); | ||
| } | ||
|
|
||
| [HttpDelete("{id:int}")] | ||
| public async Task<OperationResult> Remove([FromBody] RemoveTagByIdRequest removeTagByIdRequest) | ||
| { | ||
| var removeTagByIdCommand = _mapper.Map<RemoveTagByIdCommand>(removeTagByIdRequest); | ||
| return await _mediator.Send(removeTagByIdCommand); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| namespace StudySharp.API.Requests.Tags | ||
| { | ||
| public class AddTagRequest | ||
| { | ||
| public string Name { get; set; } | ||
| public int TeacherId { get; set; } | ||
| public int CourseId { get; set; } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| using Microsoft.AspNetCore.Mvc; | ||
|
|
||
| namespace StudySharp.API.Requests.Tags | ||
| { | ||
| public class GetTagByIdRequest | ||
| { | ||
| [BindProperty(Name = "id", SupportsGet = true)] | ||
| public int Id { get; set; } | ||
| } | ||
| } |
10 changes: 10 additions & 0 deletions
10
server/StudySharp.API/Requests/Tags/RemoveTagByIdRequest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| using Microsoft.AspNetCore.Mvc; | ||
|
|
||
| namespace StudySharp.API.Requests.Tags | ||
| { | ||
| public class RemoveTagByIdRequest | ||
| { | ||
| [BindProperty(Name = "id", SupportsGet = true)] | ||
| public int Id { get; set; } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| namespace StudySharp.API.Responses.Tags | ||
| { | ||
| public class AddTagResponse | ||
| { | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
server/StudySharp.API/Responses/Tags/GetTagByIdResponse.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using StudySharp.Domain.Models; | ||
|
|
||
| namespace StudySharp.API.Responses.Tags | ||
| { | ||
| public class GetTagByIdResponse | ||
| { | ||
| public int Id { get; set; } | ||
| public string Name { get; set; } | ||
| public int TeacherId { get; set; } | ||
| public Teacher Teacher { get; set; } | ||
| public List<TheoryBlock> TheoryBlocks { get; set; } | ||
| public List<PracticalBlock> PracticalBlocks { get; set; } | ||
| public DateTimeOffset DateCreated { get; private set; } | ||
| public DateTimeOffset? DateModified { get; private set; } | ||
| } | ||
| } |
6 changes: 6 additions & 0 deletions
6
server/StudySharp.API/Responses/Tags/RemoveTagByIdResponse.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| namespace StudySharp.API.Responses.Tags | ||
| { | ||
| public class RemoveTagByIdResponse | ||
| { | ||
| } | ||
| } |
31 changes: 31 additions & 0 deletions
31
server/StudySharp.ApplicationServices/Queries/GetTagsQuery.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| using System.Collections.Generic; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using MediatR; | ||
| using Microsoft.EntityFrameworkCore; | ||
| using StudySharp.Domain.General; | ||
| using StudySharp.Domain.Models; | ||
| using StudySharp.DomainServices; | ||
|
|
||
| namespace StudySharp.ApplicationServices.Queries | ||
| { | ||
| public sealed class GetTagsQuery : IRequest<OperationResult<List<Tag>>> | ||
| { | ||
| } | ||
|
|
||
| public sealed class GetTagsQueryHandler : IRequestHandler<GetTagsQuery, OperationResult<List<Tag>>> | ||
| { | ||
| private readonly StudySharpDbContext _context; | ||
|
|
||
| public GetTagsQueryHandler(StudySharpDbContext studySharpDbContext) | ||
| { | ||
| _context = studySharpDbContext; | ||
| } | ||
|
|
||
| public async Task<OperationResult<List<Tag>>> Handle(GetTagsQuery request, CancellationToken cancellationToken) | ||
| { | ||
| var tags = await _context.Tags.ToListAsync(cancellationToken); | ||
| return OperationResult.Ok(tags); | ||
| } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetTagsController => TagController
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Я имел в виду, что метод, который должен возвращать все теги, отсутствует
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Его нужно добавить