├── .gitignore
├── FilmesApi.sln
├── FilmesApi
├── Controllers
│ └── FilmeController.cs
├── Data
│ ├── Dtos
│ │ ├── CreateFilmeDto.cs
│ │ ├── ReadFilmeDto.cs
│ │ └── UpdateFilmeDto.cs
│ └── FilmeContext.cs
├── FilmesApi.csproj
├── Migrations
│ ├── 20210424193424_FirstMigration.Designer.cs
│ ├── 20210424193424_FirstMigration.cs
│ ├── 20210424195601_AddingBoxOffice.Designer.cs
│ ├── 20210424195601_AddingBoxOffice.cs
│ └── FilmeContextModelSnapshot.cs
├── Models
│ └── Filme.cs
├── Profiles
│ └── FilmeProfile.cs
├── Program.cs
├── Properties
│ └── launchSettings.json
└── appsettings.json
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | bld/
21 | [Bb]in/
22 | [Oo]bj/
23 | [Ll]og/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | project.fragment.lock.json
46 | artifacts/
47 |
48 | *_i.c
49 | *_p.c
50 | *_i.h
51 | *.ilk
52 | *.meta
53 | *.obj
54 | *.pch
55 | *.pdb
56 | *.pgc
57 | *.pgd
58 | *.rsp
59 | *.sbr
60 | *.tlb
61 | *.tli
62 | *.tlh
63 | *.tmp
64 | *.tmp_proj
65 | *.log
66 | *.vspscc
67 | *.vssscc
68 | .builds
69 | *.pidb
70 | *.svclog
71 | *.scc
72 |
73 | # Chutzpah Test files
74 | _Chutzpah*
75 |
76 | # Visual C++ cache files
77 | ipch/
78 | *.aps
79 | *.ncb
80 | *.opendb
81 | *.opensdf
82 | *.sdf
83 | *.cachefile
84 | *.VC.db
85 | *.VC.VC.opendb
86 |
87 | # Visual Studio profiler
88 | *.psess
89 | *.vsp
90 | *.vspx
91 | *.sap
92 |
93 | # TFS 2012 Local Workspace
94 | $tf/
95 |
96 | # Guidance Automation Toolkit
97 | *.gpState
98 |
99 | # ReSharper is a .NET coding add-in
100 | _ReSharper*/
101 | *.[Rr]e[Ss]harper
102 | *.DotSettings.user
103 |
104 | # JustCode is a .NET coding add-in
105 | .JustCode
106 |
107 | # TeamCity is a build add-in
108 | _TeamCity*
109 |
110 | # DotCover is a Code Coverage Tool
111 | *.dotCover
112 |
113 | # Visual Studio code coverage results
114 | *.coverage
115 | *.coveragexml
116 |
117 | # NCrunch
118 | _NCrunch_*
119 | .*crunch*.local.xml
120 | nCrunchTemp_*
121 |
122 | # MightyMoose
123 | *.mm.*
124 | AutoTest.Net/
125 |
126 | # Web workbench (sass)
127 | .sass-cache/
128 |
129 | # Installshield output folder
130 | [Ee]xpress/
131 |
132 | # DocProject is a documentation generator add-in
133 | DocProject/buildhelp/
134 | DocProject/Help/*.HxT
135 | DocProject/Help/*.HxC
136 | DocProject/Help/*.hhc
137 | DocProject/Help/*.hhk
138 | DocProject/Help/*.hhp
139 | DocProject/Help/Html2
140 | DocProject/Help/html
141 |
142 | # Click-Once directory
143 | publish/
144 |
145 | # Publish Web Output
146 | *.[Pp]ublish.xml
147 | *.azurePubxml
148 | # TODO: Comment the next line if you want to checkin your web deploy settings
149 | # but database connection strings (with potential passwords) will be unencrypted
150 | *.pubxml
151 | *.publishproj
152 |
153 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
154 | # checkin your Azure Web App publish settings, but sensitive information contained
155 | # in these scripts will be unencrypted
156 | PublishScripts/
157 |
158 | # NuGet Packages
159 | *.nupkg
160 | # The packages folder can be ignored because of Package Restore
161 | **/packages/*
162 | # except build/, which is used as an MSBuild target.
163 | !**/packages/build/
164 | # Uncomment if necessary however generally it will be regenerated when needed
165 | #!**/packages/repositories.config
166 | # NuGet v3's project.json files produces more ignoreable files
167 | *.nuget.props
168 | *.nuget.targets
169 |
170 | # Microsoft Azure Build Output
171 | csx/
172 | *.build.csdef
173 |
174 | # Microsoft Azure Emulator
175 | ecf/
176 | rcf/
177 |
178 | # Windows Store app package directories and files
179 | AppPackages/
180 | BundleArtifacts/
181 | Package.StoreAssociation.xml
182 | _pkginfo.txt
183 |
184 | # Visual Studio cache files
185 | # files ending in .cache can be ignored
186 | *.[Cc]ache
187 | # but keep track of directories ending in .cache
188 | !*.[Cc]ache/
189 |
190 | # Others
191 | ClientBin/
192 | ~$*
193 | *~
194 | *.dbmdl
195 | *.dbproj.schemaview
196 | *.jfm
197 | *.pfx
198 | *.publishsettings
199 | node_modules/
200 | orleans.codegen.cs
201 |
202 | # Since there are multiple workflows, uncomment next line to ignore bower_components
203 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
204 | #bower_components/
205 |
206 | # RIA/Silverlight projects
207 | Generated_Code/
208 |
209 | # Backup & report files from converting an old project file
210 | # to a newer Visual Studio version. Backup files are not needed,
211 | # because we have git ;-)
212 | _UpgradeReport_Files/
213 | Backup*/
214 | UpgradeLog*.XML
215 | UpgradeLog*.htm
216 |
217 | # SQL Server files
218 | *.mdf
219 | *.ldf
220 |
221 | # Business Intelligence projects
222 | *.rdl.data
223 | *.bim.layout
224 | *.bim_*.settings
225 |
226 | # Microsoft Fakes
227 | FakesAssemblies/
228 |
229 | # GhostDoc plugin setting file
230 | *.GhostDoc.xml
231 |
232 | # Node.js Tools for Visual Studio
233 | .ntvs_analysis.dat
234 |
235 | # Visual Studio 6 build log
236 | *.plg
237 |
238 | # Visual Studio 6 workspace options file
239 | *.opt
240 |
241 | # Visual Studio LightSwitch build output
242 | **/*.HTMLClient/GeneratedArtifacts
243 | **/*.DesktopClient/GeneratedArtifacts
244 | **/*.DesktopClient/ModelManifest.xml
245 | **/*.Server/GeneratedArtifacts
246 | **/*.Server/ModelManifest.xml
247 | _Pvt_Extensions
248 |
249 | # Paket dependency manager
250 | .paket/paket.exe
251 | paket-files/
252 |
253 | # FAKE - F# Make
254 | .fake/
255 |
256 | # JetBrains Rider
257 | .idea/
258 | *.sln.iml
259 |
260 | # CodeRush
261 | .cr/
262 |
263 | # Python Tools for Visual Studio (PTVS)
264 | __pycache__/
265 | *.pyc
266 |
267 | # Cake - Uncomment if you are using it
268 | # tools/
--------------------------------------------------------------------------------
/FilmesApi.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.31205.134
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FilmesApi", "FilmesApi\FilmesApi.csproj", "{C5BAD384-92D3-4EEF-A1CE-3603CBF45DDF}"
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 | {C5BAD384-92D3-4EEF-A1CE-3603CBF45DDF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {C5BAD384-92D3-4EEF-A1CE-3603CBF45DDF}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {C5BAD384-92D3-4EEF-A1CE-3603CBF45DDF}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {C5BAD384-92D3-4EEF-A1CE-3603CBF45DDF}.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 = {737E4B35-676C-4151-A256-6035D4EAFB43}
24 | EndGlobalSection
25 | EndGlobal
26 |
--------------------------------------------------------------------------------
/FilmesApi/Controllers/FilmeController.cs:
--------------------------------------------------------------------------------
1 | using AutoMapper;
2 | using FilmesApi.Data;
3 | using FilmesAPI.Data.Dtos;
4 | using FilmesAPI.Models;
5 | using Microsoft.AspNetCore.Http;
6 | using Microsoft.AspNetCore.Mvc;
7 | using System.Collections.Generic;
8 | using System.Linq;
9 |
10 | namespace FilmesAPI.Controllers;
11 |
12 | [ApiController]
13 | [Route("[controller]")]
14 | public class FilmeController : ControllerBase
15 | {
16 | private FilmeContext _context;
17 | private IMapper _mapper;
18 |
19 | public FilmeController(FilmeContext context, IMapper mapper)
20 | {
21 | _context = context;
22 | _mapper = mapper;
23 | }
24 |
25 | ///
26 | /// Adiciona um filme ao banco de dados
27 | ///
28 | /// Objeto com os campos necessários para criação de um filme
29 | /// IActionResult
30 | /// Caso inserção seja feita com sucesso
31 | [HttpPost]
32 | [ProducesResponseType(StatusCodes.Status201Created)]
33 | public IActionResult AdicionaFilme([FromBody] CreateFilmeDto filmeDto)
34 | {
35 | Filme filme = _mapper.Map(filmeDto);
36 | _context.Filmes.Add(filme);
37 | _context.SaveChanges();
38 | return CreatedAtAction(nameof(RecuperaFilmesPorId), new { Id = filme.Id }, filme);
39 | }
40 |
41 | ///
42 | /// Recupera uma lista de filmes do banco de dados
43 | ///
44 | /// Número de filmes que serão pulados
45 | /// Número de filmes que serão recuperados
46 | /// Informações dos filmes buscados
47 | /// Com a lista de filmes presentes na base de dados
48 | [HttpGet]
49 | public IEnumerable RecuperaFilmes(int skip = 0, int take = 10)
50 | {
51 | return _context.Filmes.Skip(skip).Take(take);
52 | }
53 |
54 | ///
55 | /// Recupera um filme no banco de dados usando seu id
56 | ///
57 | /// Id do filme a ser recuperado no banco
58 | /// Informações do filme buscado
59 | /// Caso o id seja existente na base de dados
60 | /// Caso o id seja inexistente na base de dados
61 | [HttpGet("{id}")]
62 | public IActionResult RecuperaFilmesPorId(int id)
63 | {
64 | Filme filme = _context.Filmes.FirstOrDefault(filme => filme.Id == id);
65 | if (filme != null)
66 | {
67 | ReadFilmeDto filmeDto = _mapper.Map(filme);
68 | return Ok(filmeDto);
69 | }
70 | return NotFound();
71 | }
72 |
73 | ///
74 | /// Atualiza um filme no banco de dados usando seu id
75 | ///
76 | /// Id do filme a ser atualizado no banco
77 | /// Objeto com os campos necessários para atualização de um filme
78 | /// Sem conteúdo de retorno
79 | /// Caso o id seja existente na base de dados e o filme tenha sido atualizado
80 | /// Caso o id seja inexistente na base de dados
81 | [HttpPut("{id}")]
82 | [ProducesResponseType(StatusCodes.Status204NoContent)]
83 | [ProducesResponseType(StatusCodes.Status404NotFound)]
84 | public IActionResult AtualizaFilme(int id, [FromBody] UpdateFilmeDto filmeDto)
85 | {
86 | Filme filme = _context.Filmes.FirstOrDefault(filme => filme.Id == id);
87 | if (filme != null)
88 | {
89 | _mapper.Map(filmeDto, filme);
90 | _context.SaveChanges();
91 | return NoContent();
92 | }
93 | return NotFound();
94 | }
95 |
96 | ///
97 | /// Deleta um filme do banco de dados usando seu id
98 | ///
99 | /// Id do filme a ser removido do banco
100 | /// Sem conteúdo de retorno
101 | /// Caso o id seja existente na base de dados e o filme tenha sido removido
102 | /// Caso o id seja inexistente na base de dados
103 | [HttpDelete("{id}")]
104 | [ProducesResponseType(StatusCodes.Status204NoContent)]
105 | [ProducesResponseType(StatusCodes.Status404NotFound)]
106 | public IActionResult DeletaFilme(int id)
107 | {
108 | Filme filme = _context.Filmes.FirstOrDefault(filme => filme.Id == id);
109 | if (filme != null)
110 | {
111 | _context.Remove(filme);
112 | _context.SaveChanges();
113 | return NoContent();
114 | }
115 | return NotFound();
116 | }
117 |
118 | }
119 |
--------------------------------------------------------------------------------
/FilmesApi/Data/Dtos/CreateFilmeDto.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel.DataAnnotations;
4 | using System.Linq;
5 | using System.Threading.Tasks;
6 |
7 | namespace FilmesAPI.Data.Dtos;
8 |
9 | public class CreateFilmeDto
10 | {
11 | [Required(ErrorMessage = "O título do filme é obrigatório")]
12 | [StringLength(50, ErrorMessage = "O título do filme não pode exceder 50 caracteres")]
13 | public string Titulo { get; set; }
14 | [Required(ErrorMessage = "O campo de duração é obrigatório")]
15 | [Range(1, 360, ErrorMessage = "A duração deve ter no mínimo 1 minuto e no máximo 360")]
16 | public int Duracao { get; set; }
17 | public string Diretor { get; set; }
18 | public string Genero { get; set; }
19 | }
20 |
--------------------------------------------------------------------------------
/FilmesApi/Data/Dtos/ReadFilmeDto.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel.DataAnnotations;
4 | using System.Linq;
5 | using System.Threading.Tasks;
6 |
7 | namespace FilmesAPI.Data.Dtos;
8 |
9 | public class ReadFilmeDto
10 | {
11 | public int Id { get; set; }
12 | public string Titulo { get; set; }
13 | public string Diretor { get; set; }
14 | public string Genero { get; set; }
15 | public int Duracao { get; set; }
16 | public DateTime HoraDaConsulta { get; set; } = DateTime.Now;
17 | }
18 |
--------------------------------------------------------------------------------
/FilmesApi/Data/Dtos/UpdateFilmeDto.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel.DataAnnotations;
4 | using System.Linq;
5 | using System.Threading.Tasks;
6 |
7 | namespace FilmesAPI.Data.Dtos;
8 |
9 | public class UpdateFilmeDto
10 | {
11 | [Required(ErrorMessage = "O título do filme é obrigatório")]
12 | [StringLength(50, ErrorMessage = "O título do filme não pode exceder 50 caracteres")]
13 | public string Titulo { get; set; }
14 | [Required(ErrorMessage = "O campo de duração é obrigatório")]
15 | [Range(1, 360, ErrorMessage = "A duração deve ter no mínimo 1 minuto e no máximo 360")]
16 | public int Duracao { get; set; }
17 | public string Diretor { get; set; }
18 | public string Genero { get; set; }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/FilmesApi/Data/FilmeContext.cs:
--------------------------------------------------------------------------------
1 | using FilmesAPI.Models;
2 | using Microsoft.EntityFrameworkCore;
3 |
4 | namespace FilmesApi.Data;
5 |
6 | public class FilmeContext : DbContext
7 | {
8 | public FilmeContext(DbContextOptions opt) : base(opt)
9 | {
10 |
11 | }
12 |
13 | public DbSet Filmes { get; set; }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/FilmesApi/FilmesApi.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net6.0
5 |
6 |
7 |
8 | True
9 |
10 |
11 |
12 |
13 |
14 |
15 | all
16 | runtime; build; native; contentfiles; analyzers; buildtransitive
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/FilmesApi/Migrations/20210424193424_FirstMigration.Designer.cs:
--------------------------------------------------------------------------------
1 | //
2 | using System;
3 | using FilmesApi.Data;
4 | using Microsoft.EntityFrameworkCore;
5 | using Microsoft.EntityFrameworkCore.Infrastructure;
6 | using Microsoft.EntityFrameworkCore.Migrations;
7 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
8 |
9 | namespace FilmesApi.Migrations
10 | {
11 | [DbContext(typeof(FilmeContext))]
12 | [Migration("20210424193424_FirstMigration")]
13 | partial class FirstMigration
14 | {
15 | protected override void BuildTargetModel(ModelBuilder modelBuilder)
16 | {
17 | #pragma warning disable 612, 618
18 | modelBuilder
19 | .HasAnnotation("Relational:MaxIdentifierLength", 64)
20 | .HasAnnotation("ProductVersion", "5.0.5");
21 |
22 | modelBuilder.Entity("FilmesAPI.Models.Filme", b =>
23 | {
24 | b.Property("Id")
25 | .ValueGeneratedOnAdd()
26 | .HasColumnType("int");
27 |
28 | b.Property("Diretor")
29 | .HasMaxLength(100)
30 | .HasColumnType("varchar(100)");
31 |
32 | b.Property("Duracao")
33 | .HasColumnType("int");
34 |
35 | b.Property("Genero")
36 | .HasColumnType("text");
37 |
38 | b.Property("Lancamento")
39 | .HasColumnType("datetime");
40 |
41 | b.Property("Titulo")
42 | .IsRequired()
43 | .HasColumnType("text");
44 |
45 | b.HasKey("Id");
46 |
47 | b.ToTable("Filmes");
48 | });
49 | #pragma warning restore 612, 618
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/FilmesApi/Migrations/20210424193424_FirstMigration.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Microsoft.EntityFrameworkCore.Migrations;
3 | using MySql.EntityFrameworkCore.Metadata;
4 |
5 | namespace FilmesApi.Migrations;
6 |
7 | public partial class FirstMigration : Migration
8 | {
9 | protected override void Up(MigrationBuilder migrationBuilder)
10 | {
11 | migrationBuilder.CreateTable(
12 | name: "Filmes",
13 | columns: table => new
14 | {
15 | Id = table.Column(type: "int", nullable: false)
16 | .Annotation("MySQL:ValueGenerationStrategy", MySQLValueGenerationStrategy.IdentityColumn),
17 | Titulo = table.Column(type: "text", nullable: false),
18 | Duracao = table.Column(type: "int", nullable: false),
19 | Diretor = table.Column(type: "varchar(100)", maxLength: 100, nullable: true),
20 | Lancamento = table.Column(type: "datetime", nullable: false),
21 | Genero = table.Column(type: "text", nullable: true)
22 | },
23 | constraints: table =>
24 | {
25 | table.PrimaryKey("PK_Filmes", x => x.Id);
26 | });
27 | }
28 |
29 | protected override void Down(MigrationBuilder migrationBuilder)
30 | {
31 | migrationBuilder.DropTable(
32 | name: "Filmes");
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/FilmesApi/Migrations/20210424195601_AddingBoxOffice.Designer.cs:
--------------------------------------------------------------------------------
1 | //
2 | using System;
3 | using FilmesApi.Data;
4 | using Microsoft.EntityFrameworkCore;
5 | using Microsoft.EntityFrameworkCore.Infrastructure;
6 | using Microsoft.EntityFrameworkCore.Migrations;
7 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
8 |
9 | namespace FilmesApi.Migrations
10 | {
11 | [DbContext(typeof(FilmeContext))]
12 | [Migration("20210424195601_AddingBoxOffice")]
13 | partial class AddingBoxOffice
14 | {
15 | protected override void BuildTargetModel(ModelBuilder modelBuilder)
16 | {
17 | #pragma warning disable 612, 618
18 | modelBuilder
19 | .HasAnnotation("Relational:MaxIdentifierLength", 64)
20 | .HasAnnotation("ProductVersion", "5.0.5");
21 |
22 | modelBuilder.Entity("FilmesAPI.Models.Filme", b =>
23 | {
24 | b.Property("Id")
25 | .ValueGeneratedOnAdd()
26 | .HasColumnType("int");
27 |
28 | b.Property("Diretor")
29 | .HasMaxLength(100)
30 | .HasColumnType("varchar(100)");
31 |
32 | b.Property("Duracao")
33 | .HasColumnType("int");
34 |
35 | b.Property("Faturamento")
36 | .HasColumnType("double");
37 |
38 | b.Property("Genero")
39 | .HasColumnType("text");
40 |
41 | b.Property("Lancamento")
42 | .HasColumnType("datetime");
43 |
44 | b.Property("Titulo")
45 | .IsRequired()
46 | .HasColumnType("text");
47 |
48 | b.HasKey("Id");
49 |
50 | b.ToTable("Filmes");
51 | });
52 | #pragma warning restore 612, 618
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/FilmesApi/Migrations/20210424195601_AddingBoxOffice.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.EntityFrameworkCore.Migrations;
2 |
3 | namespace FilmesApi.Migrations;
4 |
5 | public partial class AddingBoxOffice : Migration
6 | {
7 | protected override void Up(MigrationBuilder migrationBuilder)
8 | {
9 | migrationBuilder.AddColumn(
10 | name: "Faturamento",
11 | table: "Filmes",
12 | type: "double",
13 | nullable: false,
14 | defaultValue: 0.0);
15 | }
16 |
17 | protected override void Down(MigrationBuilder migrationBuilder)
18 | {
19 | migrationBuilder.DropColumn(
20 | name: "Faturamento",
21 | table: "Filmes");
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/FilmesApi/Migrations/FilmeContextModelSnapshot.cs:
--------------------------------------------------------------------------------
1 | //
2 | using System;
3 | using FilmesApi.Data;
4 | using Microsoft.EntityFrameworkCore;
5 | using Microsoft.EntityFrameworkCore.Infrastructure;
6 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
7 |
8 | namespace FilmesApi.Migrations;
9 |
10 | [DbContext(typeof(FilmeContext))]
11 | partial class FilmeContextModelSnapshot : ModelSnapshot
12 | {
13 | protected override void BuildModel(ModelBuilder modelBuilder)
14 | {
15 | #pragma warning disable 612, 618
16 | modelBuilder
17 | .HasAnnotation("Relational:MaxIdentifierLength", 64)
18 | .HasAnnotation("ProductVersion", "5.0.5");
19 |
20 | modelBuilder.Entity("FilmesAPI.Models.Filme", b =>
21 | {
22 | b.Property("Id")
23 | .ValueGeneratedOnAdd()
24 | .HasColumnType("int");
25 |
26 | b.Property("Diretor")
27 | .HasMaxLength(100)
28 | .HasColumnType("varchar(100)");
29 |
30 | b.Property("Duracao")
31 | .HasColumnType("int");
32 |
33 | b.Property("Faturamento")
34 | .HasColumnType("double");
35 |
36 | b.Property("Genero")
37 | .HasColumnType("text");
38 |
39 | b.Property("Lancamento")
40 | .HasColumnType("datetime");
41 |
42 | b.Property("Titulo")
43 | .IsRequired()
44 | .HasColumnType("text");
45 |
46 | b.HasKey("Id");
47 |
48 | b.ToTable("Filmes");
49 | });
50 | #pragma warning restore 612, 618
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/FilmesApi/Models/Filme.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel.DataAnnotations;
3 |
4 | namespace FilmesAPI.Models;
5 |
6 | public class Filme
7 | {
8 | [Key]
9 | [Required]
10 | public int Id { get; set; }
11 | [Required(ErrorMessage = "O título do filme é obrigatório")]
12 | [MaxLength(50, ErrorMessage = "O título do filme não pode exceder 50 caracteres")]
13 | public string Titulo { get; set; }
14 | [Required(ErrorMessage = "O campo de duração é obrigatório")]
15 | [Range(1, 360, ErrorMessage = "A duração deve ter no mínimo 1 minuto e no máximo 360")]
16 | public int Duracao { get; set; }
17 | public string Diretor { get; set; }
18 | public string Genero { get; set; }
19 | }
20 |
--------------------------------------------------------------------------------
/FilmesApi/Profiles/FilmeProfile.cs:
--------------------------------------------------------------------------------
1 | using AutoMapper;
2 | using FilmesAPI.Data.Dtos;
3 | using FilmesAPI.Models;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Linq;
7 | using System.Threading.Tasks;
8 |
9 | namespace FilmesAPI.Profiles;
10 |
11 | public class FilmeProfile : Profile
12 | {
13 | public FilmeProfile()
14 | {
15 | CreateMap();
16 | CreateMap();
17 | CreateMap();
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/FilmesApi/Program.cs:
--------------------------------------------------------------------------------
1 | using FilmesApi.Data;
2 | using Microsoft.AspNetCore.Builder;
3 | using Microsoft.EntityFrameworkCore;
4 | using Microsoft.Extensions.Configuration;
5 | using Microsoft.Extensions.DependencyInjection;
6 | using Microsoft.OpenApi.Models;
7 | using System;
8 | using System.IO;
9 | using System.Reflection;
10 |
11 | var builder = WebApplication.CreateBuilder(args);
12 |
13 | builder.Services.AddDbContext(opts => opts.UseMySQL(builder.Configuration.GetConnectionString("FilmeConnection")));
14 | builder.Services.AddControllers();
15 | builder.Services.AddSwaggerGen(c =>
16 | {
17 | c.SwaggerDoc("v1", new OpenApiInfo { Title = "FilmesAPI", Version = "v1" });
18 | var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
19 | var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
20 | c.IncludeXmlComments(xmlPath);
21 | });
22 | builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
23 |
24 | var app = builder.Build();
25 |
26 | app.UseSwagger();
27 | app.UseSwaggerUI();
28 |
29 | app.UseHttpsRedirection();
30 |
31 | app.UseRouting();
32 |
33 | app.UseAuthorization();
34 |
35 | app.MapControllers();
36 |
37 | using (var serviceScope = app.Services.GetService().CreateScope())
38 | {
39 | var context = serviceScope.ServiceProvider.GetRequiredService();
40 | context.Database.EnsureCreated();
41 | }
42 |
43 | app.Run();
--------------------------------------------------------------------------------
/FilmesApi/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "http://json.schemastore.org/launchsettings.json",
3 | "iisSettings": {
4 | "windowsAuthentication": false,
5 | "anonymousAuthentication": true,
6 | "iisExpress": {
7 | "applicationUrl": "http://localhost:53343",
8 | "sslPort": 44380
9 | }
10 | },
11 | "profiles": {
12 | "IIS Express": {
13 | "commandName": "IISExpress",
14 | "environmentVariables": {
15 | "ASPNETCORE_ENVIRONMENT": "Development"
16 | }
17 | },
18 | "FilmesApi": {
19 | "commandName": "Project",
20 | "applicationUrl": "https://localhost:5001;http://localhost:5000",
21 | "environmentVariables": {
22 | "ASPNETCORE_ENVIRONMENT": "Development"
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/FilmesApi/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "LogLevel": {
4 | "Default": "Information",
5 | "Microsoft": "Warning",
6 | "Microsoft.Hosting.Lifetime": "Information"
7 | }
8 | },
9 | "AllowedHosts": "*",
10 | "ConnectionStrings": {
11 | "FilmeConnection": "server=localhost;database=filmeDb;user=root;password=root"
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # dotnet-api
2 |
--------------------------------------------------------------------------------