aboutsummaryrefslogtreecommitdiff
path: root/Backend/Api
diff options
context:
space:
mode:
authorTAMARA JERINIC <tamara.jerinic@gmail.com>2022-11-28 16:34:59 +0100
committerTAMARA JERINIC <tamara.jerinic@gmail.com>2022-11-28 16:34:59 +0100
commit93a81646dab2369978dde4a9ca11f9f79061e369 (patch)
tree85d3c85152600e54836e2878f71edbe9517d3a38 /Backend/Api
parent74936fc8083a6d0ff242d5328786822471dfc58f (diff)
parente4b8c1498f3320b4f7aa0283241c7a06b77b349c (diff)
Merge branch 'develop' of http://gitlab.pmf.kg.ac.rs/BrzoDoLokacije2022/odyssey/brzodolokacije into develop
Diffstat (limited to 'Backend/Api')
-rw-r--r--Backend/Api/Api/Models/Post.cs2
-rw-r--r--Backend/Api/Api/Services/PostService.cs29
2 files changed, 22 insertions, 9 deletions
diff --git a/Backend/Api/Api/Models/Post.cs b/Backend/Api/Api/Models/Post.cs
index 1a4129f..0dc8158 100644
--- a/Backend/Api/Api/Models/Post.cs
+++ b/Backend/Api/Api/Models/Post.cs
@@ -38,9 +38,11 @@ namespace Api.Models
public DateTime createdAt { get; set; }
public int views { get; set; }
public double ratings { get; set; }
+ public int ratingscount { get; set; }
public List<CommentSend> comments { get; set; }
public List<File> images { get; set; }
public List<string>? tags { get; set; }
+ public DateTime? lastViewed { get; set; }
}
public class Rating
{
diff --git a/Backend/Api/Api/Services/PostService.cs b/Backend/Api/Api/Services/PostService.cs
index e2e4e40..0676d74 100644
--- a/Backend/Api/Api/Services/PostService.cs
+++ b/Backend/Api/Api/Services/PostService.cs
@@ -39,11 +39,11 @@ namespace Api.Services
p.comments = new List<Comment>();
p.images = new List<Models.File>();
p.createdAt = DateTime.Now.ToUniversalTime();
- if (post.tags != null)
- {
- var tags = post.tags.Split("|").ToList();
- p.tags = tags;
- }
+ List<String> tags;
+ if (post.tags != "none")
+ tags = post.tags.Remove(post.tags.Length-1,1).Split("|").ToList();
+ else tags = null;
+ p.tags = tags;
var folderPath = Path.Combine(Directory.GetCurrentDirectory(), "Files", p.ownerId);
if (!Directory.Exists(folderPath))
{
@@ -88,6 +88,7 @@ namespace Api.Services
p.views = post.views.Count();
p.createdAt = post.createdAt;
p.tags = post.tags;
+ p.ratingscount = post.ratings.Count();
if (post.ratings.Count() > 0)
{
List<int> ratings = new List<int>();
@@ -119,9 +120,16 @@ namespace Api.Services
Post p = await _posts.Find(post => post._id == id).FirstOrDefaultAsync();
if (p != null)
{
- if (!p.views.Any(x => x == userid))
+ if (!p.views.Any(x => x.Split("|")[0] == userid))
+ {
+ p.views.Add(userid + "|" + DateTime.Now.ToUniversalTime().ToString());
+ await _posts.ReplaceOneAsync(x => x._id == id, p);
+ }
+ else
{
- p.views.Add(userid);
+ var v = p.views.Find(x => x.Split("|")[0] == userid);
+ p.views.Remove(v);
+ p.views.Add(userid + "|" + DateTime.Now.ToUniversalTime().ToString());
await _posts.ReplaceOneAsync(x => x._id == id, p);
}
}
@@ -311,7 +319,7 @@ namespace Api.Services
xd = ls.OrderByDescending(x => x.createdAt).ToList();
break;
default:
-
+ xd = ls.OrderByDescending(x => x.views).ToList();
break;
}
if(xd != null)
@@ -363,12 +371,15 @@ namespace Api.Services
var tosend = new List<PostSend>();
foreach (var post in posts)
{
- if (post.views.Any(x => x.Equals(userid)))
+ if (post.views.Any(x => x.Split("|")[0] == userid))
{
+ var t = post.views.Find(x => x.Split("|")[0] == userid);
var x = await postToPostSend(post);
+ x.lastViewed = DateTime.Parse(t.Split("|")[1]).ToUniversalTime();
tosend.Add(x);
}
}
+ tosend = tosend.OrderByDescending(x => x.lastViewed).ToList();
return tosend;
}