Outline
- ASP.NET Web API with Victor Campos
- Setting Up The Solution
- NuGet Package Manager
-
Authentication and Authorization - Registration Part 1
- Introduction
- Security
- Creating The Users Controller
- Exercise - Create Controllers
- Solution - Create Controllers
- Generics
- Create Generic Class
- Create Register Request
- Create User Response
- Create Register User Endpoint
- Interfaces
- Extracting Interfaces
- Injecting Account Repository
- Dependency Injection
- Implementing Dependency Injection
- 400 vs 422
- Modify Model Validation Behavior
-
Authentication and Authorization - Registration Part 2
- DB Context
- Add Person Domain
- Add Account Domain
- Add DB Context
- Add Connection String
- Configure Dependency Injection for DB Context
- Initial Data Migrations
- Async Process
- Implement Async Process
- Extension Methods
- Implement Extension Methods
- Cryptography
- Implement Password Encryption
- Complete Create Account
- Exercise - Install Auto Mapper
- Solution - Install Auto Mapper
- Configure Auto Mapper
- Exercise - Install JWT Bearer
- Solution - Install JWT Bearer
- Configure JWT
- Exercise - Add Configuration DI
- Solution - Add Configuration DI
- Exercise - Auto Mapper DI
- Solution - Auto Mapper DI
- Implement Create User
- Implement Create Token
- Test Register API Endpoint
- Authentication and Authorization - Login
-
Current User
- Introduction
- Exercise - Invalid Credentials Exception
- Solution - Invalid Credentials Exception
- Exercise - IAccountRepository Add Method Signatures
- Solution - IAccountRepository Add Method Signatures
- Exercise - AccountRepository Implement Interface
- Solution - AccountRepository Implement Interface
- Exercise - IAccountRepository Dependency Injection
- Solution - IAccountRepository Dependency Injection
- Exercise - Add CurrentUserAsync
- Solution - Add CurrentUserAsync
- Overview ASP.NET Core Authentication
- Configure Authentication
- Configure OpenAPI
- Implement Swagger Authorization
- Overview HttpContext
- HttpContext Dependency Injection
- Implement GetLoggedInUser
- Test CurrentUser API Endpoint
- Summary
-
Update User
- Introduction
- Exercise - Exception Classes
- Solution - Exception Classes
- Exercise - Implement Interface
- Solution - Implement Interface
- Exercise - UpdateUserAsync
- Solution - UpdateUserAsync
- Exercise - Implement UpdateLoggedInUserAsync
- Solution - Implement UpdateLoggedInUserAsync
- Test UpdateUser API Endpoint
- Summary
-
User Profile
- Introduction
- Exercise - Add Followers
- Solution - Add Followers
- Follows Data Migration
- Exercise - Add Models And Exceptions
- Solution - Add Models And Exceptions
- Exercise - Create Profile Repository
- Solution - Create Profile Repository
- Exercise - Modify ProfilesController
- Solution - Modify ProfilesController
- Implement GetProfileAsync
- Implement GetUserProfileAsync
- Exercise - Follow And Unfollow
- Solution - Follow And Unfollow
- Implement Follow And Unfollow
- Test Follow And Unfollow
- Summary
-
Articles Part 1
- Introduction
- Exercise - Modify Conduit Context
- Solution - Modify Conduit Context Part 1
- Solution - Modify Conduit Context Part 2
- Solution - Modify Conduit Context Part 3
- Solution - Modify Conduit Context Part 4
- Exercise - Create Custom Models
- Solution - Create Custom Models
- API Routes With Variables
- Exercise - Articles API Endpoints
- Solution - Articles API Endpoints
- Exercise - Articles Repository
- Solution - Articles Repository
- Implement Articles Controller
- Exercise - Implement Articles Controller
- Solution - Implement Articles Controller
-
Articles Part 2
- Recap Visualizing The Layers
- Implement Articles Repository Part 1
- Implement Articles Repository Part 2
- Solution - Implement Articles Repository
- Test GetArticles API Endpoint
- Articles Feed
- Articles By Slug
- Create Article
- Debugging
- Update Article
- Include Article Tags Using Linq
- Delete Article
- Add Comments to Article
- Solution - Add Comments To Article
- Get Comments For Article
- Delete Comment From Article
- Favorite And Unfavorite Article
- Tags
Outline
- ASP.NET Web API with Victor Campos
- Setting Up The Solution
- NuGet Package Manager
-
Authentication and Authorization - Registration Part 1
- Introduction
- Security
- Creating The Users Controller
- Exercise - Create Controllers
- Solution - Create Controllers
- Generics
- Create Generic Class
- Create Register Request
- Create User Response
- Create Register User Endpoint
- Interfaces
- Extracting Interfaces
- Injecting Account Repository
- Dependency Injection
- Implementing Dependency Injection
- 400 vs 422
- Modify Model Validation Behavior
-
Authentication and Authorization - Registration Part 2
- DB Context
- Add Person Domain
- Add Account Domain
- Add DB Context
- Add Connection String
- Configure Dependency Injection for DB Context
- Initial Data Migrations
- Async Process
- Implement Async Process
- Extension Methods
- Implement Extension Methods
- Cryptography
- Implement Password Encryption
- Complete Create Account
- Exercise - Install Auto Mapper
- Solution - Install Auto Mapper
- Configure Auto Mapper
- Exercise - Install JWT Bearer
- Solution - Install JWT Bearer
- Configure JWT
- Exercise - Add Configuration DI
- Solution - Add Configuration DI
- Exercise - Auto Mapper DI
- Solution - Auto Mapper DI
- Implement Create User
- Implement Create Token
- Test Register API Endpoint
- Authentication and Authorization - Login
-
Current User
- Introduction
- Exercise - Invalid Credentials Exception
- Solution - Invalid Credentials Exception
- Exercise - IAccountRepository Add Method Signatures
- Solution - IAccountRepository Add Method Signatures
- Exercise - AccountRepository Implement Interface
- Solution - AccountRepository Implement Interface
- Exercise - IAccountRepository Dependency Injection
- Solution - IAccountRepository Dependency Injection
- Exercise - Add CurrentUserAsync
- Solution - Add CurrentUserAsync
- Overview ASP.NET Core Authentication
- Configure Authentication
- Configure OpenAPI
- Implement Swagger Authorization
- Overview HttpContext
- HttpContext Dependency Injection
- Implement GetLoggedInUser
- Test CurrentUser API Endpoint
- Summary
-
Update User
- Introduction
- Exercise - Exception Classes
- Solution - Exception Classes
- Exercise - Implement Interface
- Solution - Implement Interface
- Exercise - UpdateUserAsync
- Solution - UpdateUserAsync
- Exercise - Implement UpdateLoggedInUserAsync
- Solution - Implement UpdateLoggedInUserAsync
- Test UpdateUser API Endpoint
- Summary
-
User Profile
- Introduction
- Exercise - Add Followers
- Solution - Add Followers
- Follows Data Migration
- Exercise - Add Models And Exceptions
- Solution - Add Models And Exceptions
- Exercise - Create Profile Repository
- Solution - Create Profile Repository
- Exercise - Modify ProfilesController
- Solution - Modify ProfilesController
- Implement GetProfileAsync
- Implement GetUserProfileAsync
- Exercise - Follow And Unfollow
- Solution - Follow And Unfollow
- Implement Follow And Unfollow
- Test Follow And Unfollow
- Summary
-
Articles Part 1
- Introduction
- Exercise - Modify Conduit Context
- Solution - Modify Conduit Context Part 1
- Solution - Modify Conduit Context Part 2
- Solution - Modify Conduit Context Part 3
- Solution - Modify Conduit Context Part 4
- Exercise - Create Custom Models
- Solution - Create Custom Models
- API Routes With Variables
- Exercise - Articles API Endpoints
- Solution - Articles API Endpoints
- Exercise - Articles Repository
- Solution - Articles Repository
- Implement Articles Controller
- Exercise - Implement Articles Controller
- Solution - Implement Articles Controller
-
Articles Part 2
- Recap Visualizing The Layers
- Implement Articles Repository Part 1
- Implement Articles Repository Part 2
- Solution - Implement Articles Repository
- Test GetArticles API Endpoint
- Articles Feed
- Articles By Slug
- Create Article
- Debugging
- Update Article
- Include Article Tags Using Linq
- Delete Article
- Add Comments to Article
- Solution - Add Comments To Article
- Get Comments For Article
- Delete Comment From Article
- Favorite And Unfavorite Article
- Tags
Solution: Complete the Articles Controller Imlementation
In the Conduit.Api Project complete the implementation of the follow methods in the ArticlesController.cs file.
Get Article Feed
Return an Ok Response with a new object containing:
- Article array
- Article Count
Fix the errors:
- Make the method async
- Have Visual Studio generate the missing method for you
Here's the code to the GetArticleFeedAsync method:
[HttpGet("feed")]
public async Task<IActionResult> GetArticleFeedAsync([FromQuery] int limit = 20, int offset = 0)
{
try
{
Article[] articles = await ArticlesRepo.GetArticlesFeedAsync(limit, offset);
return Ok(new { articles, articlesCount = articles.Length });
}
catch (Exception e)
{
Logger.LogError(e.Message, e);
return StatusCode(500, e);
}
}
Get Article by Slug
Return an Ok Response with a new object containing:
- A single Article
Fix the errors:
- Make the method async
- Have Visual Studio generate the missing method for you
Add an additional Catch Block to handle ArticleNotFoundException:
- Log as a warning
- Return a 422 Response
Here's the code to the GetArticleBySlugAsync method:
[HttpGet("{slug}")]
public async Task<IActionResult> GetArticleBySlugAsync([FromRoute] string slug)
{
try
{
Article article = await ArticlesRepo.GetArticleBySlugAsync(slug);
return Ok(new { article });
}
catch (ArticleNotFoundException e)
{
Logger.LogWarning(e.Message, e);
return StatusCode(422, new { error = e.ToDictionary() });
}
catch (Exception e)
{
Logger.LogError(e.Message, e);
return StatusCode(500, e);
}
}
Update Article
Return an Ok Response with a new object containing:
- The new Article
Fix the errors:
- Make the method async
- Have Visual Studio generate the missing method for you
Here's the code to the UpdateArticleAsync method:
[HttpPut("{slug}")]
[Authorize]
public async Task<IActionResult> UpdateArticleAsync(
[FromRoute] string slug,
[FromBody] ArticleRequest<ArticleUpdateRequest> req
)
{
try
{
Article article = await ArticlesRepo.UpdateArticleAsync(req.Article);
return Ok(new { article });
}
catch (Exception e)
{
Logger.LogError(e.Message, e);
return StatusCode(500, e);
}
}
Delete Article
Return a NoContent() Response:
- No Parameters are needed
Fix the errors:
- Make the method async
- Have Visual Studio generate the missing method for you
Here's the code to the DeleteArticleAsync method:
[HttpDelete("{slug}")]
[Authorize]
public async Task<IActionResult> DeleteArticleAsync([FromRoute] string slug)
{
try
{
await ArticlesRepo.DeleteArticleAsync(slug);
return NoContent();
}
catch (ArticleNotFoundException e)
{
Logger.LogWarning(e.Message, e);
return StatusCode(422, new { error = e.ToDictionary() });
}
catch (Exception e)
{
Logger.LogError(e.Message, e);
return StatusCode(500, e);
}
}
Get Comments from Article
Return an Ok Response with a new object containing:
- A Comment array
Fix the errors:
- Make the method async
- Have Visual Studio generate the missing method for you
Here's the code to the AddCommentToArticleAsync method:
[HttpPost("{slug}/comments")]
[Authorize]
public async Task<IActionResult> AddCommentToArticleAsync(
[FromRoute] string slug,
[FromBody] CommentRequest<CommentAddRequest> req)
{
try
{
Comment comment = await ArticlesRepo.AddCommenttoArticleAsync(slug, req.Comment);
return Ok(new { comment });
}
catch (ArticleNotFoundException e)
{
Logger.LogWarning(e.Message, e);
return StatusCode(422, new { error = e.ToDictionary() });
}
catch (Exception e)
{
Logger.LogError(e.Message, e);
return StatusCode(500, e);
}
}
Delete Comment for Article
Return a NoContent() Response:
- No Parameters are needed
Fix the errors:
- Make the method async
- Have Visual Studio generate the missing method for you
Here's the code to the DeleteCommentsFromArticleAsync method:
[HttpDelete("{slug}/comments/{id:int}")]
[Authorize]
public async Task<IActionResult> DeleteCommentsFromArticleAsync(
[FromRoute] string slug,
[FromRoute] int id)
{
try
{
await ArticlesRepo.DeleteCommentForArticleAsync(slug, id);
return NoContent();
}
catch (Exception e)
{
Logger.LogError(e.Message, e);
return StatusCode(500, e);
}
}
Favorite Article
Return an Ok Response with a new object containing:
- A single Article
Fix the errors:
- Make the method async
- Have Visual Studio generate the missing method for you
Here's the code to the FavoriteArticleAsync method:
[HttpPost("{slug}/favorite")]
[Authorize]
public async Task<IActionResult> FavoriteArticleAsync([FromRoute] string slug)
{
try
{
Article article = await ArticlesRepo.FavoriteArticleAsync(slug);
return Ok(new { article });
}
catch (Exception e)
{
Logger.LogError(e.Message, e);
return StatusCode(500, e);
}
}
Unfavorite Article
Return an Ok Response with a new object containing:
- A single Article
Fix the errors:
- Make the method async
- Have Visual Studio generate the missing method for you
Here's the code to the UnfavoriteArticleAsync method:
[HttpDelete("{slug}/favorite")]
[Authorize]
public async Task<IActionResult> UnfavoriteArticleAsync([FromRoute] string slug)
{
try
{
Article article = await ArticlesRepo.UnfavoriteArticleAsync(slug);
return Ok(new { article });
}
catch (Exception e)
{
Logger.LogError(e.Message, e);
return StatusCode(500, e);
}
}