✨ Can now get all movies from API
Co-authored-by: haraldnilsen <harald_998@hotmail.com>
This commit is contained in:
		
							parent
							
								
									c0c22c1317
								
							
						
					
					
						commit
						9364b5cfc4
					
				
					 1 changed files with 7 additions and 3 deletions
				
			
		| 
						 | 
					@ -1,3 +1,4 @@
 | 
				
			||||||
 | 
					using System.Collections;
 | 
				
			||||||
using Microsoft.AspNetCore.Mvc;
 | 
					using Microsoft.AspNetCore.Mvc;
 | 
				
			||||||
using Microsoft.OpenApi.Writers;
 | 
					using Microsoft.OpenApi.Writers;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -23,7 +24,7 @@ public class MovieController: ControllerBase
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [HttpGet(Name = "GetMovies")]
 | 
					    [HttpGet(Name = "GetMovies")]
 | 
				
			||||||
    public ActionResult<IEnumerable<MovieDB>> Get(
 | 
					    public ActionResult<IEnumerable<MovieDB>> Get(
 | 
				
			||||||
        [FromQuery] string s,
 | 
					        [FromQuery] string? s,
 | 
				
			||||||
        [FromQuery] string? type,
 | 
					        [FromQuery] string? type,
 | 
				
			||||||
        [FromQuery] string? y,
 | 
					        [FromQuery] string? y,
 | 
				
			||||||
        [FromQuery] string? sort,
 | 
					        [FromQuery] string? sort,
 | 
				
			||||||
| 
						 | 
					@ -32,8 +33,11 @@ public class MovieController: ControllerBase
 | 
				
			||||||
    ) {
 | 
					    ) {
 | 
				
			||||||
    try
 | 
					    try
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 | 
					            var movies = _context.Movies.AsQueryable();
 | 
				
			||||||
 | 
					            if (s != null) {
 | 
				
			||||||
                if (!IsValidS(s)) return StatusCode(400, "Bad Request: Invalid title");
 | 
					                if (!IsValidS(s)) return StatusCode(400, "Bad Request: Invalid title");
 | 
				
			||||||
            var movies = _context.Movies.Where(m => m.Title.ToLower().Contains(s.ToLower()));
 | 
					                movies = _context.Movies.Where(m => m.Title.ToLower().Contains(s.ToLower()));
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (type != null) {
 | 
					            if (type != null) {
 | 
				
			||||||
                if (!IsValidType(type)) return StatusCode(400, "Bad Request: Invalid type");
 | 
					                if (!IsValidType(type)) return StatusCode(400, "Bad Request: Invalid type");
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Reference in a new issue