├── AwesomeDevEvents.API ├── appsettings.Development.json ├── Models │ ├── DevEventInputModel.cs │ ├── DevEventSpeakerInputModel.cs │ └── DevEventViewModel.cs ├── WeatherForecast.cs ├── appsettings.json ├── Entities │ ├── DevEventSpeaker.cs │ └── DevEvent.cs ├── Mappers │ └── DevEventProfile.cs ├── AwesomeDevEvents.API.csproj ├── Properties │ └── launchSettings.json ├── Persistence │ ├── DevEventsDbContext.cs │ └── Migrations │ │ ├── 20230219142414_FirstMigration.cs │ │ ├── DevEventsDbContextModelSnapshot.cs │ │ └── 20230219142414_FirstMigration.Designer.cs ├── Program.cs └── Controllers │ └── DevEventsController.cs ├── README.md ├── LICENSE ├── AwesomeDevEvents.sln └── .gitignore /AwesomeDevEvents.API/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /AwesomeDevEvents.API/Models/DevEventInputModel.cs: -------------------------------------------------------------------------------- 1 | namespace AwesomeDevEvents.API.Models 2 | { 3 | public class DevEventInputModel 4 | { 5 | public string Title { get; set; } 6 | public string Description { get; set; } 7 | public DateTime StartDate { get; set; } 8 | public DateTime EndDate { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /AwesomeDevEvents.API/WeatherForecast.cs: -------------------------------------------------------------------------------- 1 | namespace AwesomeDevEvents.API 2 | { 3 | public class WeatherForecast 4 | { 5 | public DateOnly Date { get; set; } 6 | 7 | public int TemperatureC { get; set; } 8 | 9 | public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); 10 | 11 | public string? Summary { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /AwesomeDevEvents.API/Models/DevEventSpeakerInputModel.cs: -------------------------------------------------------------------------------- 1 | namespace AwesomeDevEvents.API.Models 2 | { 3 | public class DevEventSpeakerInputModel 4 | { 5 | public string Name { get; set; } 6 | public string TalkTitle { get; set; } 7 | public string TalkDescription { get; set; } 8 | public string LinkedInProfile { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /AwesomeDevEvents.API/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*", 9 | "ConnectionStrings": { 10 | "DevEventsCs": "Server=DESKTOP-GOK6BOV\\SQLEXPRESS; Database=DevEvents; Integrated Security=True; trustServerCertificate=true" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /AwesomeDevEvents.API/Entities/DevEventSpeaker.cs: -------------------------------------------------------------------------------- 1 | namespace AwesomeDevEvents.API.Entities 2 | { 3 | public class DevEventSpeaker 4 | { 5 | public Guid Id { get; set; } 6 | public string Name { get; set; } 7 | public string TalkTitle { get; set; } 8 | public string TalkDescription { get; set; } 9 | public string LinkedInProfile { get; set; } 10 | public Guid DevEventId { get; set; } 11 | } 12 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AwesomeDevEvents - Curso Criando REST APIs com ASP.NET Core 2 | 3 | Está sendo desenvolvido um projeto de eventos de programação, utilizando ASP.NET Core 7. 4 | 5 | ## Tecnologias e ferramentas utilizadas 6 | - Visual Studio 2022 7 | - ASP.NET Core 7 8 | - EF Core 9 | - Swagger 10 | - AutoMapper 11 | 12 | 13 | ## Funcionalidades 14 | - Cadastro, Listagem, Detalhes, Atualização, e Remoção de Evento 15 | - Cadastro de palestrantes 16 | 17 | -------------------------------------------------------------------------------- /AwesomeDevEvents.API/Mappers/DevEventProfile.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using AwesomeDevEvents.API.Entities; 3 | using AwesomeDevEvents.API.Models; 4 | 5 | namespace AwesomeDevEvents.API.Mappers 6 | { 7 | public class DevEventProfile : Profile 8 | { 9 | public DevEventProfile() 10 | { 11 | CreateMap(); 12 | CreateMap(); 13 | 14 | CreateMap(); 15 | CreateMap(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /AwesomeDevEvents.API/Models/DevEventViewModel.cs: -------------------------------------------------------------------------------- 1 | namespace AwesomeDevEvents.API.Models 2 | { 3 | public class DevEventViewModel 4 | { 5 | public Guid Id { get; set; } 6 | public string Title { get; set; } 7 | public string Description { get; set; } 8 | public DateTime StartDate { get; set; } 9 | public DateTime EndDate { get; set; } 10 | public List Speakers { get; set; } 11 | } 12 | 13 | public class DevEventSpeakerViewModel 14 | { 15 | public Guid Id { get; set; } 16 | public string Name { get; set; } 17 | public string TalkTitle { get; set; } 18 | public string TalkDescription { get; set; } 19 | public string LinkedInProfile { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /AwesomeDevEvents.API/Entities/DevEvent.cs: -------------------------------------------------------------------------------- 1 | namespace AwesomeDevEvents.API.Entities 2 | { 3 | public class DevEvent 4 | { 5 | public DevEvent() 6 | { 7 | Speakers = new List(); 8 | IsDeleted = false; 9 | } 10 | 11 | public Guid Id { get; set; } 12 | public string Title { get; set; } 13 | public string Description { get; set; } 14 | public DateTime StartDate { get; set; } 15 | public DateTime EndDate { get; set; } 16 | public List Speakers { get; set; } 17 | public bool IsDeleted { get; set; } 18 | 19 | public void Update(string title, string description, DateTime startDate, DateTime endDate) 20 | { 21 | Title = title; 22 | Description = description; 23 | StartDate = startDate; 24 | EndDate = endDate; 25 | } 26 | 27 | public void Delete() 28 | { 29 | IsDeleted = true; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Luis Felipe de Oliveira 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /AwesomeDevEvents.API/AwesomeDevEvents.API.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | true 8 | $(NoWarn);1591 9 | 10 | 11 | 12 | 13 | 14 | 15 | all 16 | runtime; build; native; contentfiles; analyzers; buildtransitive 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /AwesomeDevEvents.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.4.33110.190 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AwesomeDevEvents.API", "AwesomeDevEvents.API\AwesomeDevEvents.API.csproj", "{EAF68F2D-BC8A-40F2-AB1B-B22FC553EC90}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {EAF68F2D-BC8A-40F2-AB1B-B22FC553EC90}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {EAF68F2D-BC8A-40F2-AB1B-B22FC553EC90}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {EAF68F2D-BC8A-40F2-AB1B-B22FC553EC90}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {EAF68F2D-BC8A-40F2-AB1B-B22FC553EC90}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {398F7AF5-92F4-4641-8A43-1FB14BD7F654} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /AwesomeDevEvents.API/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:51104", 8 | "sslPort": 44312 9 | } 10 | }, 11 | "profiles": { 12 | "http": { 13 | "commandName": "Project", 14 | "dotnetRunMessages": true, 15 | "launchBrowser": true, 16 | "launchUrl": "swagger", 17 | "applicationUrl": "http://localhost:5210", 18 | "environmentVariables": { 19 | "ASPNETCORE_ENVIRONMENT": "Development" 20 | } 21 | }, 22 | "https": { 23 | "commandName": "Project", 24 | "dotnetRunMessages": true, 25 | "launchBrowser": true, 26 | "launchUrl": "swagger", 27 | "applicationUrl": "https://localhost:7065;http://localhost:5210", 28 | "environmentVariables": { 29 | "ASPNETCORE_ENVIRONMENT": "Development" 30 | } 31 | }, 32 | "IIS Express": { 33 | "commandName": "IISExpress", 34 | "launchBrowser": true, 35 | "launchUrl": "swagger", 36 | "environmentVariables": { 37 | "ASPNETCORE_ENVIRONMENT": "Development" 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /AwesomeDevEvents.API/Persistence/DevEventsDbContext.cs: -------------------------------------------------------------------------------- 1 | using AwesomeDevEvents.API.Entities; 2 | using Microsoft.EntityFrameworkCore; 3 | 4 | namespace AwesomeDevEvents.API.Persistence 5 | { 6 | public class DevEventsDbContext : DbContext 7 | { 8 | public DevEventsDbContext(DbContextOptions options) : base(options) 9 | { 10 | 11 | } 12 | 13 | public DbSet DevEvents { get; set; } 14 | public DbSet DevEventSpeakers { get; set; } 15 | 16 | protected override void OnModelCreating(ModelBuilder builder) 17 | { 18 | builder.Entity(e => 19 | { 20 | e.HasKey(de => de.Id); 21 | 22 | e.Property(de => de.Title).IsRequired(false); 23 | 24 | e.Property(de => de.Description) 25 | .HasMaxLength(200) 26 | .HasColumnType("varchar(200)"); 27 | 28 | e.Property(de => de.StartDate) 29 | .HasColumnName("Start_Date"); 30 | 31 | e.Property(de => de.EndDate) 32 | .HasColumnName("End_Date"); 33 | 34 | e.HasMany(de => de.Speakers) 35 | .WithOne() 36 | .HasForeignKey(s => s.DevEventId); 37 | }); 38 | 39 | builder.Entity(e => 40 | { 41 | e.HasKey(de => de.Id); 42 | }); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /AwesomeDevEvents.API/Program.cs: -------------------------------------------------------------------------------- 1 | using AwesomeDevEvents.API.Mappers; 2 | using AwesomeDevEvents.API.Persistence; 3 | using Microsoft.EntityFrameworkCore; 4 | using Microsoft.OpenApi.Models; 5 | 6 | var builder = WebApplication.CreateBuilder(args); 7 | 8 | // Add services to the container. 9 | var connectionString = builder.Configuration.GetConnectionString("DevEventsCs"); 10 | 11 | // builder.Services.AddDbContext(o => o.UseInMemoryDatabase("DevEventsDb")); 12 | 13 | builder.Services.AddDbContext(o => o.UseSqlServer(connectionString)); 14 | 15 | builder.Services.AddAutoMapper(typeof(DevEventProfile).Assembly); 16 | 17 | builder.Services.AddControllers(); 18 | // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle 19 | builder.Services.AddEndpointsApiExplorer(); 20 | builder.Services.AddSwaggerGen(c => 21 | { 22 | c.SwaggerDoc("v1", new OpenApiInfo 23 | { 24 | Title = "AwesomeDevEvents.API", 25 | Version = "v1", 26 | Contact = new OpenApiContact 27 | { 28 | Name = "LuisDev", 29 | Email = "luisdev@mail.com", 30 | Url = new Uri("https://luisdev.com.br") 31 | } 32 | }); 33 | 34 | var xmlFile = "AwesomeDevEvents.API.xml"; 35 | var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); 36 | c.IncludeXmlComments(xmlPath); 37 | }); 38 | 39 | var app = builder.Build(); 40 | 41 | // Configure the HTTP request pipeline. 42 | if (app.Environment.IsDevelopment()) 43 | { 44 | app.UseSwagger(); 45 | app.UseSwaggerUI(); 46 | } 47 | 48 | app.UseHttpsRedirection(); 49 | 50 | app.UseAuthorization(); 51 | 52 | app.MapControllers(); 53 | 54 | app.Run(); 55 | -------------------------------------------------------------------------------- /AwesomeDevEvents.API/Persistence/Migrations/20230219142414_FirstMigration.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.EntityFrameworkCore.Migrations; 3 | 4 | #nullable disable 5 | 6 | namespace AwesomeDevEvents.API.Persistence.Migrations 7 | { 8 | /// 9 | public partial class FirstMigration : Migration 10 | { 11 | /// 12 | protected override void Up(MigrationBuilder migrationBuilder) 13 | { 14 | migrationBuilder.CreateTable( 15 | name: "DevEvents", 16 | columns: table => new 17 | { 18 | Id = table.Column(type: "uniqueidentifier", nullable: false), 19 | Title = table.Column(type: "nvarchar(max)", nullable: true), 20 | Description = table.Column(type: "varchar(200)", maxLength: 200, nullable: false), 21 | Start_Date = table.Column(type: "datetime2", nullable: false), 22 | End_Date = table.Column(type: "datetime2", nullable: false), 23 | IsDeleted = table.Column(type: "bit", nullable: false) 24 | }, 25 | constraints: table => 26 | { 27 | table.PrimaryKey("PK_DevEvents", x => x.Id); 28 | }); 29 | 30 | migrationBuilder.CreateTable( 31 | name: "DevEventSpeakers", 32 | columns: table => new 33 | { 34 | Id = table.Column(type: "uniqueidentifier", nullable: false), 35 | Name = table.Column(type: "nvarchar(max)", nullable: false), 36 | TalkTitle = table.Column(type: "nvarchar(max)", nullable: false), 37 | TalkDescription = table.Column(type: "nvarchar(max)", nullable: false), 38 | LinkedInProfile = table.Column(type: "nvarchar(max)", nullable: false), 39 | DevEventId = table.Column(type: "uniqueidentifier", nullable: false) 40 | }, 41 | constraints: table => 42 | { 43 | table.PrimaryKey("PK_DevEventSpeakers", x => x.Id); 44 | table.ForeignKey( 45 | name: "FK_DevEventSpeakers_DevEvents_DevEventId", 46 | column: x => x.DevEventId, 47 | principalTable: "DevEvents", 48 | principalColumn: "Id", 49 | onDelete: ReferentialAction.Cascade); 50 | }); 51 | 52 | migrationBuilder.CreateIndex( 53 | name: "IX_DevEventSpeakers_DevEventId", 54 | table: "DevEventSpeakers", 55 | column: "DevEventId"); 56 | } 57 | 58 | /// 59 | protected override void Down(MigrationBuilder migrationBuilder) 60 | { 61 | migrationBuilder.DropTable( 62 | name: "DevEventSpeakers"); 63 | 64 | migrationBuilder.DropTable( 65 | name: "DevEvents"); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /AwesomeDevEvents.API/Persistence/Migrations/DevEventsDbContextModelSnapshot.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using AwesomeDevEvents.API.Persistence; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.EntityFrameworkCore.Infrastructure; 6 | using Microsoft.EntityFrameworkCore.Metadata; 7 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 8 | 9 | #nullable disable 10 | 11 | namespace AwesomeDevEvents.API.Persistence.Migrations 12 | { 13 | [DbContext(typeof(DevEventsDbContext))] 14 | partial class DevEventsDbContextModelSnapshot : ModelSnapshot 15 | { 16 | protected override void BuildModel(ModelBuilder modelBuilder) 17 | { 18 | #pragma warning disable 612, 618 19 | modelBuilder 20 | .HasAnnotation("ProductVersion", "7.0.3") 21 | .HasAnnotation("Relational:MaxIdentifierLength", 128); 22 | 23 | SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); 24 | 25 | modelBuilder.Entity("AwesomeDevEvents.API.Entities.DevEvent", b => 26 | { 27 | b.Property("Id") 28 | .ValueGeneratedOnAdd() 29 | .HasColumnType("uniqueidentifier"); 30 | 31 | b.Property("Description") 32 | .IsRequired() 33 | .HasMaxLength(200) 34 | .HasColumnType("varchar(200)"); 35 | 36 | b.Property("EndDate") 37 | .HasColumnType("datetime2") 38 | .HasColumnName("End_Date"); 39 | 40 | b.Property("IsDeleted") 41 | .HasColumnType("bit"); 42 | 43 | b.Property("StartDate") 44 | .HasColumnType("datetime2") 45 | .HasColumnName("Start_Date"); 46 | 47 | b.Property("Title") 48 | .HasColumnType("nvarchar(max)"); 49 | 50 | b.HasKey("Id"); 51 | 52 | b.ToTable("DevEvents"); 53 | }); 54 | 55 | modelBuilder.Entity("AwesomeDevEvents.API.Entities.DevEventSpeaker", b => 56 | { 57 | b.Property("Id") 58 | .ValueGeneratedOnAdd() 59 | .HasColumnType("uniqueidentifier"); 60 | 61 | b.Property("DevEventId") 62 | .HasColumnType("uniqueidentifier"); 63 | 64 | b.Property("LinkedInProfile") 65 | .IsRequired() 66 | .HasColumnType("nvarchar(max)"); 67 | 68 | b.Property("Name") 69 | .IsRequired() 70 | .HasColumnType("nvarchar(max)"); 71 | 72 | b.Property("TalkDescription") 73 | .IsRequired() 74 | .HasColumnType("nvarchar(max)"); 75 | 76 | b.Property("TalkTitle") 77 | .IsRequired() 78 | .HasColumnType("nvarchar(max)"); 79 | 80 | b.HasKey("Id"); 81 | 82 | b.HasIndex("DevEventId"); 83 | 84 | b.ToTable("DevEventSpeakers"); 85 | }); 86 | 87 | modelBuilder.Entity("AwesomeDevEvents.API.Entities.DevEventSpeaker", b => 88 | { 89 | b.HasOne("AwesomeDevEvents.API.Entities.DevEvent", null) 90 | .WithMany("Speakers") 91 | .HasForeignKey("DevEventId") 92 | .OnDelete(DeleteBehavior.Cascade) 93 | .IsRequired(); 94 | }); 95 | 96 | modelBuilder.Entity("AwesomeDevEvents.API.Entities.DevEvent", b => 97 | { 98 | b.Navigation("Speakers"); 99 | }); 100 | #pragma warning restore 612, 618 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /AwesomeDevEvents.API/Persistence/Migrations/20230219142414_FirstMigration.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using AwesomeDevEvents.API.Persistence; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.EntityFrameworkCore.Infrastructure; 6 | using Microsoft.EntityFrameworkCore.Metadata; 7 | using Microsoft.EntityFrameworkCore.Migrations; 8 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 9 | 10 | #nullable disable 11 | 12 | namespace AwesomeDevEvents.API.Persistence.Migrations 13 | { 14 | [DbContext(typeof(DevEventsDbContext))] 15 | [Migration("20230219142414_FirstMigration")] 16 | partial class FirstMigration 17 | { 18 | /// 19 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 20 | { 21 | #pragma warning disable 612, 618 22 | modelBuilder 23 | .HasAnnotation("ProductVersion", "7.0.3") 24 | .HasAnnotation("Relational:MaxIdentifierLength", 128); 25 | 26 | SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); 27 | 28 | modelBuilder.Entity("AwesomeDevEvents.API.Entities.DevEvent", b => 29 | { 30 | b.Property("Id") 31 | .ValueGeneratedOnAdd() 32 | .HasColumnType("uniqueidentifier"); 33 | 34 | b.Property("Description") 35 | .IsRequired() 36 | .HasMaxLength(200) 37 | .HasColumnType("varchar(200)"); 38 | 39 | b.Property("EndDate") 40 | .HasColumnType("datetime2") 41 | .HasColumnName("End_Date"); 42 | 43 | b.Property("IsDeleted") 44 | .HasColumnType("bit"); 45 | 46 | b.Property("StartDate") 47 | .HasColumnType("datetime2") 48 | .HasColumnName("Start_Date"); 49 | 50 | b.Property("Title") 51 | .HasColumnType("nvarchar(max)"); 52 | 53 | b.HasKey("Id"); 54 | 55 | b.ToTable("DevEvents"); 56 | }); 57 | 58 | modelBuilder.Entity("AwesomeDevEvents.API.Entities.DevEventSpeaker", b => 59 | { 60 | b.Property("Id") 61 | .ValueGeneratedOnAdd() 62 | .HasColumnType("uniqueidentifier"); 63 | 64 | b.Property("DevEventId") 65 | .HasColumnType("uniqueidentifier"); 66 | 67 | b.Property("LinkedInProfile") 68 | .IsRequired() 69 | .HasColumnType("nvarchar(max)"); 70 | 71 | b.Property("Name") 72 | .IsRequired() 73 | .HasColumnType("nvarchar(max)"); 74 | 75 | b.Property("TalkDescription") 76 | .IsRequired() 77 | .HasColumnType("nvarchar(max)"); 78 | 79 | b.Property("TalkTitle") 80 | .IsRequired() 81 | .HasColumnType("nvarchar(max)"); 82 | 83 | b.HasKey("Id"); 84 | 85 | b.HasIndex("DevEventId"); 86 | 87 | b.ToTable("DevEventSpeakers"); 88 | }); 89 | 90 | modelBuilder.Entity("AwesomeDevEvents.API.Entities.DevEventSpeaker", b => 91 | { 92 | b.HasOne("AwesomeDevEvents.API.Entities.DevEvent", null) 93 | .WithMany("Speakers") 94 | .HasForeignKey("DevEventId") 95 | .OnDelete(DeleteBehavior.Cascade) 96 | .IsRequired(); 97 | }); 98 | 99 | modelBuilder.Entity("AwesomeDevEvents.API.Entities.DevEvent", b => 100 | { 101 | b.Navigation("Speakers"); 102 | }); 103 | #pragma warning restore 612, 618 104 | } 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /AwesomeDevEvents.API/Controllers/DevEventsController.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using AwesomeDevEvents.API.Entities; 3 | using AwesomeDevEvents.API.Models; 4 | using AwesomeDevEvents.API.Persistence; 5 | using Microsoft.AspNetCore.Mvc; 6 | using Microsoft.EntityFrameworkCore; 7 | 8 | namespace AwesomeDevEvents.API.Controllers 9 | { 10 | [Route("api/dev-events")] 11 | [ApiController] 12 | public class DevEventsController : ControllerBase 13 | { 14 | private readonly DevEventsDbContext _context; 15 | private readonly IMapper _mapper; 16 | public DevEventsController( 17 | DevEventsDbContext context, 18 | IMapper mapper) 19 | { 20 | _context = context; 21 | _mapper = mapper; 22 | } 23 | 24 | /// 25 | /// Obter todos os eventos 26 | /// 27 | /// Coleção de eventos 28 | /// Sucesso 29 | [HttpGet] 30 | [ProducesResponseType(StatusCodes.Status200OK)] 31 | public IActionResult GetAll() 32 | { 33 | var devEvents = _context.DevEvents.Where(d => !d.IsDeleted).ToList(); 34 | 35 | var viewModel = _mapper.Map>(devEvents); 36 | 37 | return Ok(viewModel); 38 | } 39 | 40 | /// 41 | /// Obter um evento 42 | /// 43 | /// Identificador do evento 44 | /// Dados do evento 45 | /// Sucesso 46 | /// Não encontrado 47 | [HttpGet("{id}")] 48 | [ProducesResponseType(StatusCodes.Status200OK)] 49 | [ProducesResponseType(StatusCodes.Status404NotFound)] 50 | public IActionResult GetById(Guid id) 51 | { 52 | var devEvent = _context.DevEvents 53 | .Include(de => de.Speakers) 54 | .SingleOrDefault(d => d.Id == id); 55 | 56 | if (devEvent == null) 57 | { 58 | return NotFound(); 59 | } 60 | 61 | var viewModel = _mapper.Map(devEvent); 62 | 63 | return Ok(viewModel); 64 | } 65 | 66 | /// 67 | /// Cadastrar um evento 68 | /// 69 | /// 70 | /// {"title":"string","description":"string","startDate":"2023-02-27T17:59:14.141Z","endDate":"2023-02-27T17:59:14.141Z"} 71 | /// 72 | /// Dados do evento 73 | /// Objeto recém-criado 74 | /// Sucesso 75 | [HttpPost] 76 | [ProducesResponseType(StatusCodes.Status201Created)] 77 | public IActionResult Post(DevEventInputModel input) 78 | { 79 | var devEvent = _mapper.Map(input); 80 | 81 | _context.DevEvents.Add(devEvent); 82 | _context.SaveChanges(); 83 | 84 | return CreatedAtAction(nameof(GetById), new { id = devEvent.Id }, devEvent); 85 | } 86 | 87 | /// 88 | /// Atualizar um evento 89 | /// 90 | /// 91 | /// {"title":"string","description":"string","startDate":"2023-02-27T17:59:14.141Z","endDate":"2023-02-27T17:59:14.141Z"} 92 | /// 93 | /// Identificador do evento 94 | /// Dados do evento 95 | /// Nada. 96 | /// Não encontrado. 97 | /// Sucesso 98 | [HttpPut("{id}")] 99 | [ProducesResponseType(StatusCodes.Status404NotFound)] 100 | [ProducesResponseType(StatusCodes.Status204NoContent)] 101 | public IActionResult Update(Guid id, DevEventInputModel input) 102 | { 103 | var devEvent = _context.DevEvents.SingleOrDefault(d => d.Id == id); 104 | 105 | if (devEvent == null) 106 | { 107 | return NotFound(); 108 | } 109 | 110 | devEvent.Update(input.Title, input.Description, input.StartDate, input.EndDate); 111 | 112 | _context.DevEvents.Update(devEvent); 113 | _context.SaveChanges(); 114 | 115 | return NoContent(); 116 | } 117 | 118 | /// 119 | /// Deletar um evento 120 | /// 121 | /// Identificador de evento 122 | /// Nada 123 | /// Não encontrado 124 | /// Sucesso 125 | [HttpDelete("{id}")] 126 | [ProducesResponseType(StatusCodes.Status404NotFound)] 127 | [ProducesResponseType(StatusCodes.Status204NoContent)] 128 | public IActionResult Delete(Guid id) 129 | { 130 | var devEvent = _context.DevEvents.SingleOrDefault(d => d.Id == id); 131 | 132 | if (devEvent == null) 133 | { 134 | return NotFound(); 135 | } 136 | 137 | devEvent.Delete(); 138 | 139 | _context.SaveChanges(); 140 | 141 | return NoContent(); 142 | } 143 | 144 | /// 145 | /// Cadastrar palestrante 146 | /// 147 | /// 148 | /// {"name":"string","talkTitle":"string","talkDescription":"string","linkedInProfile":"string"} 149 | /// 150 | /// Identificador do evento 151 | /// Dados do palestrante 152 | /// Nada 153 | /// Sucesso 154 | /// Evento não encontrado 155 | [HttpPost("{id}/speakers")] 156 | [ProducesResponseType(StatusCodes.Status404NotFound)] 157 | [ProducesResponseType(StatusCodes.Status204NoContent)] 158 | public IActionResult PostSpeaker(Guid id, DevEventSpeakerInputModel input) 159 | { 160 | var speaker = _mapper.Map(input); 161 | 162 | speaker.DevEventId = id; 163 | 164 | var devEvent = _context.DevEvents.Any(d => d.Id == id); 165 | 166 | if (!devEvent) 167 | { 168 | return NotFound(); 169 | } 170 | 171 | _context.DevEventSpeakers.Add(speaker); 172 | _context.SaveChanges(); 173 | 174 | return NoContent(); 175 | } 176 | } 177 | } 178 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Aa][Rr][Mm]/ 27 | [Aa][Rr][Mm]64/ 28 | bld/ 29 | [Bb]in/ 30 | [Oo]bj/ 31 | [Ll]og/ 32 | [Ll]ogs/ 33 | 34 | # Visual Studio 2015/2017 cache/options directory 35 | .vs/ 36 | # Uncomment if you have tasks that create the project's static files in wwwroot 37 | #wwwroot/ 38 | 39 | # Visual Studio 2017 auto generated files 40 | Generated\ Files/ 41 | 42 | # MSTest test Results 43 | [Tt]est[Rr]esult*/ 44 | [Bb]uild[Ll]og.* 45 | 46 | # NUnit 47 | *.VisualState.xml 48 | TestResult.xml 49 | nunit-*.xml 50 | 51 | # Build Results of an ATL Project 52 | [Dd]ebugPS/ 53 | [Rr]eleasePS/ 54 | dlldata.c 55 | 56 | # Benchmark Results 57 | BenchmarkDotNet.Artifacts/ 58 | 59 | # .NET Core 60 | project.lock.json 61 | project.fragment.lock.json 62 | artifacts/ 63 | 64 | # StyleCop 65 | StyleCopReport.xml 66 | 67 | # Files built by Visual Studio 68 | *_i.c 69 | *_p.c 70 | *_h.h 71 | *.ilk 72 | *.meta 73 | *.obj 74 | *.iobj 75 | *.pch 76 | *.pdb 77 | *.ipdb 78 | *.pgc 79 | *.pgd 80 | *.rsp 81 | *.sbr 82 | *.tlb 83 | *.tli 84 | *.tlh 85 | *.tmp 86 | *.tmp_proj 87 | *_wpftmp.csproj 88 | *.log 89 | *.vspscc 90 | *.vssscc 91 | .builds 92 | *.pidb 93 | *.svclog 94 | *.scc 95 | 96 | # Chutzpah Test files 97 | _Chutzpah* 98 | 99 | # Visual C++ cache files 100 | ipch/ 101 | *.aps 102 | *.ncb 103 | *.opendb 104 | *.opensdf 105 | *.sdf 106 | *.cachefile 107 | *.VC.db 108 | *.VC.VC.opendb 109 | 110 | # Visual Studio profiler 111 | *.psess 112 | *.vsp 113 | *.vspx 114 | *.sap 115 | 116 | # Visual Studio Trace Files 117 | *.e2e 118 | 119 | # TFS 2012 Local Workspace 120 | $tf/ 121 | 122 | # Guidance Automation Toolkit 123 | *.gpState 124 | 125 | # ReSharper is a .NET coding add-in 126 | _ReSharper*/ 127 | *.[Rr]e[Ss]harper 128 | *.DotSettings.user 129 | 130 | # TeamCity is a build add-in 131 | _TeamCity* 132 | 133 | # DotCover is a Code Coverage Tool 134 | *.dotCover 135 | 136 | # AxoCover is a Code Coverage Tool 137 | .axoCover/* 138 | !.axoCover/settings.json 139 | 140 | # Visual Studio code coverage results 141 | *.coverage 142 | *.coveragexml 143 | 144 | # NCrunch 145 | _NCrunch_* 146 | .*crunch*.local.xml 147 | nCrunchTemp_* 148 | 149 | # MightyMoose 150 | *.mm.* 151 | AutoTest.Net/ 152 | 153 | # Web workbench (sass) 154 | .sass-cache/ 155 | 156 | # Installshield output folder 157 | [Ee]xpress/ 158 | 159 | # DocProject is a documentation generator add-in 160 | DocProject/buildhelp/ 161 | DocProject/Help/*.HxT 162 | DocProject/Help/*.HxC 163 | DocProject/Help/*.hhc 164 | DocProject/Help/*.hhk 165 | DocProject/Help/*.hhp 166 | DocProject/Help/Html2 167 | DocProject/Help/html 168 | 169 | # Click-Once directory 170 | publish/ 171 | 172 | # Publish Web Output 173 | *.[Pp]ublish.xml 174 | *.azurePubxml 175 | # Note: Comment the next line if you want to checkin your web deploy settings, 176 | # but database connection strings (with potential passwords) will be unencrypted 177 | *.pubxml 178 | *.publishproj 179 | 180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 181 | # checkin your Azure Web App publish settings, but sensitive information contained 182 | # in these scripts will be unencrypted 183 | PublishScripts/ 184 | 185 | # NuGet Packages 186 | *.nupkg 187 | # NuGet Symbol Packages 188 | *.snupkg 189 | # The packages folder can be ignored because of Package Restore 190 | **/[Pp]ackages/* 191 | # except build/, which is used as an MSBuild target. 192 | !**/[Pp]ackages/build/ 193 | # Uncomment if necessary however generally it will be regenerated when needed 194 | #!**/[Pp]ackages/repositories.config 195 | # NuGet v3's project.json files produces more ignorable files 196 | *.nuget.props 197 | *.nuget.targets 198 | 199 | # Microsoft Azure Build Output 200 | csx/ 201 | *.build.csdef 202 | 203 | # Microsoft Azure Emulator 204 | ecf/ 205 | rcf/ 206 | 207 | # Windows Store app package directories and files 208 | AppPackages/ 209 | BundleArtifacts/ 210 | Package.StoreAssociation.xml 211 | _pkginfo.txt 212 | *.appx 213 | *.appxbundle 214 | *.appxupload 215 | 216 | # Visual Studio cache files 217 | # files ending in .cache can be ignored 218 | *.[Cc]ache 219 | # but keep track of directories ending in .cache 220 | !?*.[Cc]ache/ 221 | 222 | # Others 223 | ClientBin/ 224 | ~$* 225 | *~ 226 | *.dbmdl 227 | *.dbproj.schemaview 228 | *.jfm 229 | *.pfx 230 | *.publishsettings 231 | orleans.codegen.cs 232 | 233 | # Including strong name files can present a security risk 234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 235 | #*.snk 236 | 237 | # Since there are multiple workflows, uncomment next line to ignore bower_components 238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 239 | #bower_components/ 240 | 241 | # RIA/Silverlight projects 242 | Generated_Code/ 243 | 244 | # Backup & report files from converting an old project file 245 | # to a newer Visual Studio version. Backup files are not needed, 246 | # because we have git ;-) 247 | _UpgradeReport_Files/ 248 | Backup*/ 249 | UpgradeLog*.XML 250 | UpgradeLog*.htm 251 | ServiceFabricBackup/ 252 | *.rptproj.bak 253 | 254 | # SQL Server files 255 | *.mdf 256 | *.ldf 257 | *.ndf 258 | 259 | # Business Intelligence projects 260 | *.rdl.data 261 | *.bim.layout 262 | *.bim_*.settings 263 | *.rptproj.rsuser 264 | *- [Bb]ackup.rdl 265 | *- [Bb]ackup ([0-9]).rdl 266 | *- [Bb]ackup ([0-9][0-9]).rdl 267 | 268 | # Microsoft Fakes 269 | FakesAssemblies/ 270 | 271 | # GhostDoc plugin setting file 272 | *.GhostDoc.xml 273 | 274 | # Node.js Tools for Visual Studio 275 | .ntvs_analysis.dat 276 | node_modules/ 277 | 278 | # Visual Studio 6 build log 279 | *.plg 280 | 281 | # Visual Studio 6 workspace options file 282 | *.opt 283 | 284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 285 | *.vbw 286 | 287 | # Visual Studio LightSwitch build output 288 | **/*.HTMLClient/GeneratedArtifacts 289 | **/*.DesktopClient/GeneratedArtifacts 290 | **/*.DesktopClient/ModelManifest.xml 291 | **/*.Server/GeneratedArtifacts 292 | **/*.Server/ModelManifest.xml 293 | _Pvt_Extensions 294 | 295 | # Paket dependency manager 296 | .paket/paket.exe 297 | paket-files/ 298 | 299 | # FAKE - F# Make 300 | .fake/ 301 | 302 | # CodeRush personal settings 303 | .cr/personal 304 | 305 | # Python Tools for Visual Studio (PTVS) 306 | __pycache__/ 307 | *.pyc 308 | 309 | # Cake - Uncomment if you are using it 310 | # tools/** 311 | # !tools/packages.config 312 | 313 | # Tabs Studio 314 | *.tss 315 | 316 | # Telerik's JustMock configuration file 317 | *.jmconfig 318 | 319 | # BizTalk build output 320 | *.btp.cs 321 | *.btm.cs 322 | *.odx.cs 323 | *.xsd.cs 324 | 325 | # OpenCover UI analysis results 326 | OpenCover/ 327 | 328 | # Azure Stream Analytics local run output 329 | ASALocalRun/ 330 | 331 | # MSBuild Binary and Structured Log 332 | *.binlog 333 | 334 | # NVidia Nsight GPU debugger configuration file 335 | *.nvuser 336 | 337 | # MFractors (Xamarin productivity tool) working folder 338 | .mfractor/ 339 | 340 | # Local History for Visual Studio 341 | .localhistory/ 342 | 343 | # BeatPulse healthcheck temp database 344 | healthchecksdb 345 | 346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 347 | MigrationBackup/ 348 | 349 | # Ionide (cross platform F# VS Code tools) working folder 350 | .ionide/ 351 | --------------------------------------------------------------------------------