update api

This commit is contained in:
henrydays 2018-08-18 23:55:13 +01:00
parent e7e7465c72
commit ef661a1ea6
37 changed files with 20194 additions and 4 deletions

46
api/.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,46 @@
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/netcoreapp2.1/api.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart",
"launchBrowser": {
"enabled": true,
"args": "${auto-detect-url}",
"windows": {
"command": "cmd.exe",
"args": "/C start ${auto-detect-url}"
},
"osx": {
"command": "open"
},
"linux": {
"command": "xdg-open"
}
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
,]
}

15
api/.vscode/tasks.json vendored Normal file
View File

@ -0,0 +1,15 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/api.csproj"
],
"problemMatcher": "$msCompile"
}
]
}

View File

@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using api.Data;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
namespace api.Controllers
{
[Authorize]
[Route("api/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
{
private readonly DataContext context;
public ValuesController(DataContext context)
{
this.context = context;
}
// GET api/values
[HttpGet]
public async Task<IActionResult> GetValues()
{
var values= await context.Values.ToListAsync();
return Ok(values);
}
// GET api/values/5
[HttpGet("{id}")]
public async Task<IActionResult> GetValue(int id)
{
//procura o primeiro ou o default (que é null)
var value= await context.Values.FirstOrDefaultAsync(x => x.id == id);
return Ok(value);
}
// POST api/values
[HttpPost]
public void Post([FromBody] string value)
{
}
// PUT api/values/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
{
}
// DELETE api/values/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}
}
}

View File

@ -1,7 +1,7 @@
using System;
using System.Threading.Tasks;
using api.Models;
using API.Data;
using api.Data;
using Microsoft.EntityFrameworkCore;
namespace api.Data

15
api/Data/DataContext.cs Normal file
View File

@ -0,0 +1,15 @@
using api.Models;
using Microsoft.EntityFrameworkCore;
namespace api.Data
{
public class DataContext : DbContext
{
public DataContext(DbContextOptions<DataContext> options):base(options) { }
public DbSet<Value> Values{get;set;}
public DbSet<User> Users { get; set;}
}
}

View File

@ -1,12 +1,12 @@
// <auto-generated />
using System;
using API.Data;
using api.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace API.Migrations
namespace api.Migrations
{
[DbContext(typeof(DataContext))]
[Migration("20180817200459_AddedUserEntity")]

View File

@ -1,7 +1,7 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace API.Migrations
namespace api.Migrations
{
public partial class AddedUserEntity : Migration
{

11
api/Models/Value.cs Normal file
View File

@ -0,0 +1,11 @@
namespace api.Models
{
public class Value
{
public int id{get;set;}
public string Name{ get;set;}
}
}

24
api/Program.cs Normal file
View File

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace api
{
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
}
}

View File

@ -0,0 +1,30 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:40138",
"sslPort": 44339
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "api/values",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"api": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "api/values",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

79
api/Startup.cs Normal file
View File

@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using api.Data;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.IdentityModel.Tokens;
namespace 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)
{
//define a connection string indicada em appsettings.json
services.AddDbContext<DataContext>(x=>x.UseSqlite(Configuration.GetConnectionString("DefaultConnection")));
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
//cors support
services.AddCors();
//cria uma instancia para cada request do cliente (mantem instancia entre CORS)
services.AddScoped<IAuthRepository, AuthRepository>();
//autenticação para o token
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options=> {
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuerSigningKey = true,
IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(Configuration.GetSection("AppSettings:Token").Value)),
ValidateIssuer = false,
ValidateAudience= false,
};
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
// app.UseHsts();
}
// app.UseHttpsRedirection();
//cores supporte
app.UseCors(x=>x.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
app.UseAuthentication();
app.UseMvc();
}
}
}

11
api/api.csproj Normal file
View File

@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\"/>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.0" /> <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.1"/>
</ItemGroup>
</Project>

BIN
api/api.db Normal file

Binary file not shown.

View File

@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}

18
api/appsettings.json Normal file
View File

@ -0,0 +1,18 @@
{
"AppSettings":
{
"Token":"NbTSjGOaBMfweUyCvINv23Tt9jHhiEz2MBcYrYPhd24xWsztIV3bgDGOsWfRJFb8"
},
"ConnectionStrings":
{
"DefaultConnection":"Data Source= api.db"
},
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "*"
}

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,9 @@
{
"runtimeOptions": {
"additionalProbingPaths": [
"/Users/henrique/.dotnet/store/|arch|/|tfm|",
"/Users/henrique/.nuget/packages",
"/usr/local/share/dotnet/sdk/NuGetFallbackFolder"
]
}
}

View File

@ -0,0 +1,12 @@
{
"runtimeOptions": {
"tfm": "netcoreapp2.1",
"framework": {
"name": "Microsoft.AspNetCore.All",
"version": "2.1.0"
},
"configProperties": {
"System.GC.Server": true
}
}
}

View File

@ -0,0 +1,16 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Generated by the MSBuild WriteCodeFragment class.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("api")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("api")]
[assembly: System.Reflection.AssemblyTitleAttribute("api")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@ -0,0 +1 @@
9f2c22d9dbbfb3187a717a253ae3cd497f2f7c77

View File

@ -0,0 +1 @@
be6c2f1957e37581aa7c268c3491629cc5b53cc0

View File

@ -0,0 +1,13 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Generated by the MSBuild WriteCodeFragment class.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: Microsoft.AspNetCore.Mvc.ApplicationParts.RelatedAssemblyAttribute("api.Views")]
[assembly: Microsoft.AspNetCore.Razor.Hosting.RazorLanguageVersionAttribute("2.1")]
[assembly: Microsoft.AspNetCore.Razor.Hosting.RazorConfigurationNameAttribute("MVC-2.1")]
[assembly: Microsoft.AspNetCore.Razor.Hosting.RazorExtensionAssemblyNameAttribute("MVC-2.1", "Microsoft.AspNetCore.Mvc.Razor.Extensions")]

View File

@ -0,0 +1 @@
f371bf350f1693230a2f85e8f0a8e7cb3e2deca4

Binary file not shown.

View File

@ -0,0 +1 @@
c978743fb7bb4bd8de2773d42c543ecf6a79f27c

View File

@ -0,0 +1,14 @@
/Users/henrique/enei2019/api/bin/Debug/netcoreapp2.1/api.deps.json
/Users/henrique/enei2019/api/bin/Debug/netcoreapp2.1/api.runtimeconfig.json
/Users/henrique/enei2019/api/bin/Debug/netcoreapp2.1/api.runtimeconfig.dev.json
/Users/henrique/enei2019/api/bin/Debug/netcoreapp2.1/api.dll
/Users/henrique/enei2019/api/bin/Debug/netcoreapp2.1/api.pdb
/Users/henrique/enei2019/api/obj/Debug/netcoreapp2.1/api.csprojAssemblyReference.cache
/Users/henrique/enei2019/api/obj/Debug/netcoreapp2.1/api.csproj.CoreCompileInputs.cache
/Users/henrique/enei2019/api/obj/Debug/netcoreapp2.1/api.RazorAssemblyInfo.cache
/Users/henrique/enei2019/api/obj/Debug/netcoreapp2.1/api.RazorAssemblyInfo.cs
/Users/henrique/enei2019/api/obj/Debug/netcoreapp2.1/api.AssemblyInfoInputs.cache
/Users/henrique/enei2019/api/obj/Debug/netcoreapp2.1/api.AssemblyInfo.cs
/Users/henrique/enei2019/api/obj/Debug/netcoreapp2.1/api.RazorTargetAssemblyInfo.cache
/Users/henrique/enei2019/api/obj/Debug/netcoreapp2.1/api.dll
/Users/henrique/enei2019/api/obj/Debug/netcoreapp2.1/api.pdb

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="GetEFProjectMetadata" Condition="">
<MSBuild Condition=" '$(TargetFramework)' == '' "
Projects="$(MSBuildProjectFile)"
Targets="GetEFProjectMetadata"
Properties="TargetFramework=$(TargetFrameworks.Split(';')[0]);EFProjectMetadataFile=$(EFProjectMetadataFile)" />
<ItemGroup Condition=" '$(TargetFramework)' != '' ">
<EFProjectMetadata Include="AssemblyName: $(AssemblyName)" />
<EFProjectMetadata Include="Language: $(Language)" />
<EFProjectMetadata Include="OutputPath: $(OutputPath)" />
<EFProjectMetadata Include="Platform: $(Platform)" />
<EFProjectMetadata Include="PlatformTarget: $(PlatformTarget)" />
<EFProjectMetadata Include="ProjectAssetsFile: $(ProjectAssetsFile)" />
<EFProjectMetadata Include="ProjectDir: $(ProjectDir)" />
<EFProjectMetadata Include="RootNamespace: $(RootNamespace)" />
<EFProjectMetadata Include="RuntimeFrameworkVersion: $(RuntimeFrameworkVersion)" />
<EFProjectMetadata Include="TargetFileName: $(TargetFileName)" />
<EFProjectMetadata Include="TargetFrameworkMoniker: $(TargetFrameworkMoniker)" />
</ItemGroup>
<WriteLinesToFile Condition=" '$(TargetFramework)' != '' "
File="$(EFProjectMetadataFile)"
Lines="@(EFProjectMetadata)" />
</Target>
</Project>

View File

@ -0,0 +1,5 @@
{
"version": 1,
"dgSpecHash": "Ifnq9Fh8VEzrOLQIjuwLS9T+Qa9IyUhxLbg2/sjYDpPJs08FyW3Fp2VuBlQAHYsawJVDMuu3YGMWdwyABNmeQQ==",
"success": true
}

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">/Users/henrique/enei2019/api/obj/project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">/Users/henrique/.nuget/packages/</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">/Users/henrique/.nuget/packages/;/usr/local/share/dotnet/sdk/NuGetFallbackFolder</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">4.7.0</NuGetToolVersion>
</PropertyGroup>
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>
<ImportGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<Import Project="/usr/local/share/dotnet/sdk/NuGetFallbackFolder/microsoft.netcore.app/2.1.0/build/netcoreapp2.1/Microsoft.NETCore.App.props" Condition="Exists('/usr/local/share/dotnet/sdk/NuGetFallbackFolder/microsoft.netcore.app/2.1.0/build/netcoreapp2.1/Microsoft.NETCore.App.props')" />
<Import Project="$(NuGetPackageRoot)microsoft.extensions.fileproviders.embedded/2.1.0/build/netstandard2.0/Microsoft.Extensions.FileProviders.Embedded.props" Condition="Exists('$(NuGetPackageRoot)microsoft.extensions.fileproviders.embedded/2.1.0/build/netstandard2.0/Microsoft.Extensions.FileProviders.Embedded.props')" />
<Import Project="$(NuGetPackageRoot)microsoft.extensions.configuration.usersecrets/2.1.0/build/netstandard2.0/Microsoft.Extensions.Configuration.UserSecrets.props" Condition="Exists('$(NuGetPackageRoot)microsoft.extensions.configuration.usersecrets/2.1.0/build/netstandard2.0/Microsoft.Extensions.Configuration.UserSecrets.props')" />
<Import Project="$(NuGetPackageRoot)microsoft.entityframeworkcore.design/2.1.0/build/netcoreapp2.0/Microsoft.EntityFrameworkCore.Design.props" Condition="Exists('$(NuGetPackageRoot)microsoft.entityframeworkcore.design/2.1.0/build/netcoreapp2.0/Microsoft.EntityFrameworkCore.Design.props')" />
<Import Project="$(NuGetPackageRoot)microsoft.aspnetcore.mvc.razor.extensions/2.1.0/build/netstandard2.0/Microsoft.AspNetCore.Mvc.Razor.Extensions.props" Condition="Exists('$(NuGetPackageRoot)microsoft.aspnetcore.mvc.razor.extensions/2.1.0/build/netstandard2.0/Microsoft.AspNetCore.Mvc.Razor.Extensions.props')" />
<Import Project="$(NuGetPackageRoot)microsoft.aspnetcore.razor.design/2.1.0/build/netstandard2.0/Microsoft.AspNetCore.Razor.Design.props" Condition="Exists('$(NuGetPackageRoot)microsoft.aspnetcore.razor.design/2.1.0/build/netstandard2.0/Microsoft.AspNetCore.Razor.Design.props')" />
<Import Project="$(NuGetPackageRoot)microsoft.aspnetcore.all/2.1.0/build/netcoreapp2.1/Microsoft.AspNetCore.All.props" Condition="Exists('$(NuGetPackageRoot)microsoft.aspnetcore.all/2.1.0/build/netcoreapp2.1/Microsoft.AspNetCore.All.props')" />
</ImportGroup>
</Project>

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>
<ImportGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<Import Project="/usr/local/share/dotnet/sdk/NuGetFallbackFolder/netstandard.library/2.0.3/build/netstandard2.0/NETStandard.Library.targets" Condition="Exists('/usr/local/share/dotnet/sdk/NuGetFallbackFolder/netstandard.library/2.0.3/build/netstandard2.0/NETStandard.Library.targets')" />
<Import Project="/usr/local/share/dotnet/sdk/NuGetFallbackFolder/microsoft.netcore.app/2.1.0/build/netcoreapp2.1/Microsoft.NETCore.App.targets" Condition="Exists('/usr/local/share/dotnet/sdk/NuGetFallbackFolder/microsoft.netcore.app/2.1.0/build/netcoreapp2.1/Microsoft.NETCore.App.targets')" />
<Import Project="$(NuGetPackageRoot)microsoft.extensions.fileproviders.embedded/2.1.0/build/netstandard2.0/Microsoft.Extensions.FileProviders.Embedded.targets" Condition="Exists('$(NuGetPackageRoot)microsoft.extensions.fileproviders.embedded/2.1.0/build/netstandard2.0/Microsoft.Extensions.FileProviders.Embedded.targets')" />
<Import Project="$(NuGetPackageRoot)microsoft.extensions.configuration.usersecrets/2.1.0/build/netstandard2.0/Microsoft.Extensions.Configuration.UserSecrets.targets" Condition="Exists('$(NuGetPackageRoot)microsoft.extensions.configuration.usersecrets/2.1.0/build/netstandard2.0/Microsoft.Extensions.Configuration.UserSecrets.targets')" />
<Import Project="$(NuGetPackageRoot)microsoft.aspnetcore.mvc.razor.extensions/2.1.0/build/netstandard2.0/Microsoft.AspNetCore.Mvc.Razor.Extensions.targets" Condition="Exists('$(NuGetPackageRoot)microsoft.aspnetcore.mvc.razor.extensions/2.1.0/build/netstandard2.0/Microsoft.AspNetCore.Mvc.Razor.Extensions.targets')" />
<Import Project="$(NuGetPackageRoot)microsoft.aspnetcore.mvc.razor.viewcompilation/2.1.0/build/netstandard2.0/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.targets" Condition="Exists('$(NuGetPackageRoot)microsoft.aspnetcore.mvc.razor.viewcompilation/2.1.0/build/netstandard2.0/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.targets')" />
<Import Project="$(NuGetPackageRoot)microsoft.aspnetcore.all/2.1.0/build/netcoreapp2.1/Microsoft.AspNetCore.All.targets" Condition="Exists('$(NuGetPackageRoot)microsoft.aspnetcore.all/2.1.0/build/netcoreapp2.1/Microsoft.AspNetCore.All.targets')" />
</ImportGroup>
</Project>

13623
api/obj/project.assets.json Normal file

File diff suppressed because it is too large Load Diff