-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ezgi Yaman
committed
Jan 5, 2022
1 parent
0a5b104
commit 492c9cd
Showing
9 changed files
with
373 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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,24 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> | ||
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies> | ||
<DocumentationFile>C:\Users\YAMAN\source\repos\Content-Management-System\src\API\CMS.API\CMS.API.xml</DocumentationFile> | ||
<NoWarn>1701;1702;1591</NoWarn> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.2.3" /> | ||
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.2.3" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\Web\CMS.Application\CMS.Application.csproj" /> | ||
<ProjectReference Include="..\..\Web\CMS.Infrastructure\CMS.Infrastructure.csproj" /> | ||
</ItemGroup> | ||
|
||
|
||
</Project> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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,111 @@ | ||
using CMS.Application.Models.DTOs; | ||
using CMS.Application.Models.VMs; | ||
using CMS.Application.Services.Interface; | ||
using CMS.Domain.Entities.Concrete; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace CMS.API.Controllers | ||
{ | ||
[Produces("application/json")] //Sadece tanımlanan türlerle sınırlanır.XML ile çalışmasını isteseydim ; "application/xml")] yazılırdı. | ||
[Route("api/[controller]")] | ||
[ApiController] | ||
public class CategoryController : ControllerBase | ||
{ | ||
private readonly ICategoryService _categoryService; | ||
|
||
public CategoryController(ICategoryService categoryService) | ||
{ | ||
_categoryService = categoryService; | ||
} | ||
|
||
/// <summary> | ||
/// Get All Categories | ||
/// </summary> | ||
/// <returns></returns> | ||
[HttpGet] | ||
public async Task<List<GetCategoryVM>> GetCategories() | ||
{ | ||
//Getcategories methoddu zaten bana list döndürüyor o yüzden direk list döndük getcategories git bak | ||
var categoryList = await _categoryService.GetCategories(); | ||
|
||
return categoryList; | ||
} | ||
|
||
/// <summary> | ||
/// Get Category By Id | ||
/// </summary> | ||
/// <param name="id"></param> | ||
/// <returns></returns> | ||
[HttpGet("{id:int}", Name = "GetCategoryById")] | ||
[ProducesResponseType(200)] //status code ok başarılı dönmesi için ekledik. | ||
|
||
//category ıd'sinden yakalayı getirme işlemi | ||
public async Task<UpdateCategoryDTO> GetCategoryById(int id) | ||
{ | ||
var category = await _categoryService.GetById(id); | ||
return category; | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Get one category by slug | ||
/// </summary> | ||
/// <param name="slug"></param> | ||
/// <returns></returns> | ||
[HttpGet("{slug}", Name = "GetCategoryBySlug")] | ||
public async Task<Category> GetCategoryBySlug(string slug) | ||
{ | ||
var category = await _categoryService.GetBySlug(slug); | ||
|
||
return category; | ||
} | ||
/// <summary> | ||
/// Create a category | ||
/// </summary> | ||
/// <param name="model"> | ||
/// Please check category model in the schemas table | ||
/// </param> | ||
/// <returns></returns> | ||
[HttpPost] | ||
public async Task<ActionResult<Category>> CreateCategory([FromBody] CreateCategoryDTO model) | ||
{ //action result olarak işaretleyince bad request ve ok kabul görüyor yazmsak bize kızıyor."[FromBody]" atacağımız request'in gövdesinde veriyi göndereceğimiz zaman tercih ediyoruz. | ||
if (ModelState.IsValid) | ||
{ | ||
await _categoryService.Create(model); | ||
return Ok(); | ||
} | ||
return BadRequest(); | ||
} | ||
|
||
/// <summary> | ||
/// Update one category.Category slug must be uniqe. | ||
/// </summary> | ||
/// <param name="model"> | ||
/// Please check category model in the shemas table | ||
/// </param> | ||
/// <returns></returns> | ||
[HttpPut] | ||
public async Task<ActionResult<Category>> UpdateCategory([FromBody] UpdateCategoryDTO model) | ||
{ | ||
if (ModelState.IsValid) | ||
{ | ||
await _categoryService.Update(model); | ||
return Ok(model); | ||
} | ||
return BadRequest(model); | ||
|
||
} | ||
|
||
[HttpDelete("{id}")] | ||
public async Task<IActionResult> DeleteCategory(int id) | ||
{ | ||
await _categoryService.Delete(id); | ||
return Ok(); | ||
} | ||
} | ||
} |
This file contains 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,34 @@ | ||
using Autofac; | ||
using Autofac.Extensions.DependencyInjection; | ||
using CMS.Application.IoC; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace CMS.API | ||
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
CreateHostBuilder(args).Build().Run(); | ||
} | ||
|
||
public static IHostBuilder CreateHostBuilder(string[] args) => | ||
Host.CreateDefaultBuilder(args) | ||
.UseServiceProviderFactory(new AutofacServiceProviderFactory()) | ||
.ConfigureContainer<ContainerBuilder>(builder => | ||
{ | ||
builder.RegisterModule(new DependencyResolver()); | ||
}) | ||
.ConfigureWebHostDefaults(webBuilder => | ||
{ | ||
webBuilder.UseStartup<Startup>(); | ||
}); | ||
} | ||
} |
This file contains 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,29 @@ | ||
{ | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:24461", | ||
"sslPort": 0 | ||
} | ||
}, | ||
"$schema": "http://json.schemastore.org/launchsettings.json", | ||
"profiles": { | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"CMS.API": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"launchUrl": "weatherforecast", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
}, | ||
"applicationUrl": "http://localhost:5000" | ||
} | ||
} | ||
} |
This file contains 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,96 @@ | ||
using CMS.Infrastructure.Context; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.OpenApi.Models; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Threading.Tasks; | ||
|
||
namespace CMS.API | ||
{ | ||
public class Startup | ||
{ | ||
public Startup(IConfiguration configuration) | ||
{ | ||
Configuration = configuration; | ||
} | ||
|
||
public IConfiguration Configuration { get; } | ||
|
||
// This method gets called by the runtime. Use this method to add services to the container. | ||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
services.AddControllers(); | ||
|
||
services.AddDbContext<AppDbContext>(options => | ||
{ | ||
|
||
options.UseSqlServer(Configuration.GetConnectionString("ProjectContext")); | ||
}); | ||
|
||
//Swagger Resolve | ||
services.AddSwaggerGen(options => | ||
{ | ||
options.SwaggerDoc("CMSAPI", new OpenApiInfo() | ||
{ | ||
Title = "CMS API", | ||
Version = "v1.1", | ||
Description = "Restful API E", | ||
Contact = new OpenApiContact() | ||
{ | ||
Email = "[email protected]", | ||
Name = "Ezgi Yaman", | ||
Url = new Uri("https://github.com/ezgiyaman") | ||
}, | ||
License = new OpenApiLicense() | ||
{ | ||
Name = "MIT Licanse", | ||
Url = new Uri("https://opensource.org/licenses/MIT") | ||
} | ||
}); | ||
|
||
|
||
//summary için ekledim. | ||
var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; | ||
options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename)); | ||
}); | ||
|
||
} | ||
|
||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | ||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | ||
{ | ||
if (env.IsDevelopment()) | ||
{ | ||
app.UseDeveloperExceptionPage(); | ||
} | ||
|
||
//swagger kullandýðým için endpoint'ini ekledim. | ||
|
||
app.UseSwagger(); | ||
app.UseSwaggerUI(options => | ||
{ | ||
options.SwaggerEndpoint("/swagger/CMSAPI/swagger.json", "Restful API"); | ||
options.RoutePrefix = string.Empty; | ||
}); | ||
|
||
app.UseRouting(); | ||
|
||
app.UseAuthorization(); | ||
|
||
app.UseEndpoints(endpoints => | ||
{ | ||
endpoints.MapControllers(); | ||
}); | ||
} | ||
} | ||
} |
This file contains 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 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft": "Warning", | ||
"Microsoft.Hosting.Lifetime": "Information" | ||
} | ||
} | ||
} |
Oops, something went wrong.