From 0354b7c0989711ff664438d6f5805176ceaf2d6f Mon Sep 17 00:00:00 2001
From: haraldnilsen <harald_998@hotmail.com>
Date: Tue, 19 Sep 2023 13:53:05 +0200
Subject: [PATCH] :construction: working on sorting in api

Co-authored-by: Sindre Kjelsrud <kjelsrudsindre@gmail.com>
---
 backend/Controllers/MovieController.cs | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/backend/Controllers/MovieController.cs b/backend/Controllers/MovieController.cs
index b87ac19..980265e 100644
--- a/backend/Controllers/MovieController.cs
+++ b/backend/Controllers/MovieController.cs
@@ -47,8 +47,12 @@ public class MovieController: ControllerBase
 
             if (sort != null) {
                 if (!IsValidSort(sort)) return StatusCode(400, "Bad Request: Invalid sort-type");
-                
-            }
+                if (sort == "titleasc") movies = movies.OrderBy(m => m.Title);
+                if (sort == "titledesc") movies = movies.OrderByDescending(m => m.Title);
+                if (sort == "yearasc") movies = movies.OrderBy(m => m.Year);
+                if (sort == "yeardesc") movies = movies.OrderByDescending(m => m.Year);
+            }   
+
 
             if (!IsValidPageNumber(pageNumber) || !IsValidPageSize(pageSize)) 
                 return StatusCode(400, "Bad Request: Invalid page-size or page-number");