aboutsummaryrefslogtreecommitdiff
path: root/Backend/Api
diff options
context:
space:
mode:
authorTAMARA JERINIC <tamara.jerinic@gmail.com>2022-11-28 01:46:34 +0100
committerTAMARA JERINIC <tamara.jerinic@gmail.com>2022-11-28 01:46:34 +0100
commit37b2dff40d7e1395e3dc77bd7bb353e0181a37a6 (patch)
tree0fd75d98956a14eba18c4fed399140555899524f /Backend/Api
parent6e7afb7ae49eff07f9403e006dbe102e402a0441 (diff)
Dodato sortiranje objava na back-u i prikaz sortiranih objava na front-u. Izmenjen prikaz objave.
Diffstat (limited to 'Backend/Api')
-rw-r--r--Backend/Api/Api/Controllers/PostController.cs22
-rw-r--r--Backend/Api/Api/Interfaces/IPostService.cs6
-rw-r--r--Backend/Api/Api/Services/PostService.cs36
3 files changed, 64 insertions, 0 deletions
diff --git a/Backend/Api/Api/Controllers/PostController.cs b/Backend/Api/Api/Controllers/PostController.cs
index 3fe1b3f..4c6fbac 100644
--- a/Backend/Api/Api/Controllers/PostController.cs
+++ b/Backend/Api/Api/Controllers/PostController.cs
@@ -137,5 +137,27 @@ namespace Api.Controllers
}
return BadRequest();
}
+
+ [HttpGet("posts/get10MostViewed")]
+ [Authorize(Roles = "User")]
+ public async Task<ActionResult<List<PostSend>>> Get10MostViewed()
+ {
+ return Ok(await _postService.Get10MostViewed());
+ }
+
+ [HttpGet("posts/get10Newest")]
+ [Authorize(Roles = "User")]
+ public async Task<ActionResult<List<PostSend>>> Get10Newest()
+ {
+ return Ok(await _postService.Get10Newest());
+ }
+
+ [HttpGet("posts/get10Best")]
+ [Authorize(Roles = "User")]
+ public async Task<ActionResult<List<PostSend>>> Get10Best()
+ {
+ return Ok(await _postService.Get10Best());
+ }
+
}
}
diff --git a/Backend/Api/Api/Interfaces/IPostService.cs b/Backend/Api/Api/Interfaces/IPostService.cs
index 12a5fe8..5b04dc3 100644
--- a/Backend/Api/Api/Interfaces/IPostService.cs
+++ b/Backend/Api/Api/Interfaces/IPostService.cs
@@ -19,5 +19,11 @@ namespace Api.Interfaces
int DateEnumToDays(int filterdate);
Task<List<PostSend>> GetUsersPosts(string id);
Task<List<PostSend>> UserHistory(string userid);
+
+ Task<List<PostSend>> Get10Best();
+
+ Task<List<PostSend>> Get10MostViewed();
+
+ Task<List<PostSend>> Get10Newest();
}
} \ No newline at end of file
diff --git a/Backend/Api/Api/Services/PostService.cs b/Backend/Api/Api/Services/PostService.cs
index bdf150b..b75656e 100644
--- a/Backend/Api/Api/Services/PostService.cs
+++ b/Backend/Api/Api/Services/PostService.cs
@@ -368,5 +368,41 @@ namespace Api.Services
}
return tosend;
}
+
+ public async Task<List<PostSend>> Get10Best()
+ {
+ List<Post> posts = await _posts.Find(_ => true).ToListAsync();
+ List<PostSend> temp = new List<PostSend>();
+ foreach (var post in posts)
+ {
+ temp.Add(await postToPostSend(post));
+ }
+ List<PostSend> best = temp.OrderByDescending(o => o.ratings).Take(10).ToList();
+ return best;
+ }
+
+ public async Task<List<PostSend>> Get10MostViewed()
+ {
+ List<Post> posts = await _posts.Find(_ => true).ToListAsync();
+ List<PostSend> temp = new List<PostSend>();
+ foreach (var post in posts)
+ {
+ temp.Add(await postToPostSend(post));
+ }
+ List<PostSend> mostViewed = temp.OrderByDescending(o => o.views).Take(10).ToList();
+ return mostViewed;
+ }
+
+ public async Task<List<PostSend>> Get10Newest()
+ {
+ List<Post> posts = await _posts.Find(_ => true).ToListAsync();
+ List<PostSend> temp = new List<PostSend>();
+ foreach (var post in posts)
+ {
+ temp.Add(await postToPostSend(post));
+ }
+ List<PostSend> newest = temp.OrderByDescending(o => o.createdAt).Take(10).ToList();
+ return newest;
+ }
}
}