aboutsummaryrefslogtreecommitdiff
path: root/Backend/Api
diff options
context:
space:
mode:
authorTAMARA JERINIC <tamara.jerinic@gmail.com>2022-12-09 21:58:37 +0100
committerTAMARA JERINIC <tamara.jerinic@gmail.com>2022-12-09 21:58:37 +0100
commit2be5fb31bdf9400d7419159c1d37bf25306b0741 (patch)
treee38e1f03a708fbd366b3b0c3a6f3b312233e55a1 /Backend/Api
parentd776acefb2316f875b93dbe956253e160c003a58 (diff)
parent8da0efaf10d33e919aab0ae53e5117cc2dd02429 (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/Controllers/AuthController.cs10
-rw-r--r--Backend/Api/Api/Controllers/PostController.cs2
-rw-r--r--Backend/Api/Api/Controllers/UserController.cs4
-rw-r--r--Backend/Api/Api/Models/User.cs10
-rw-r--r--Backend/Api/Api/Services/PostService.cs5
-rw-r--r--Backend/Api/Api/Services/UserService.cs22
6 files changed, 40 insertions, 13 deletions
diff --git a/Backend/Api/Api/Controllers/AuthController.cs b/Backend/Api/Api/Controllers/AuthController.cs
index abb7adc..b63665b 100644
--- a/Backend/Api/Api/Controllers/AuthController.cs
+++ b/Backend/Api/Api/Controllers/AuthController.cs
@@ -120,5 +120,15 @@ namespace Api.Controllers
return base.Content(html, "text/html");
}
}
+ [HttpGet("jwttoid")]
+ [Authorize(Roles = "User")]
+ public async Task<ActionResult<string>> JwtToUserId()
+ {
+ var userid = await _userService.UserIdFromJwt();
+ if (userid != null)
+ return Ok(userid);
+ return BadRequest();
+ }
+
}
}
diff --git a/Backend/Api/Api/Controllers/PostController.cs b/Backend/Api/Api/Controllers/PostController.cs
index 61a4f48..33c240c 100644
--- a/Backend/Api/Api/Controllers/PostController.cs
+++ b/Backend/Api/Api/Controllers/PostController.cs
@@ -56,7 +56,7 @@ namespace Api.Controllers
}
return BadRequest();
}
- [HttpGet("posts/delete/{id}")]
+ [HttpDelete("posts/delete/{id}")]
[Authorize(Roles = "User")]
public async Task<ActionResult<string>> deletePost(string id)
{
diff --git a/Backend/Api/Api/Controllers/UserController.cs b/Backend/Api/Api/Controllers/UserController.cs
index 30beac4..abdf685 100644
--- a/Backend/Api/Api/Controllers/UserController.cs
+++ b/Backend/Api/Api/Controllers/UserController.cs
@@ -164,9 +164,9 @@ namespace Api.Controllers
[HttpPost("changePass")]
[Authorize(Roles = "User")]
- public async Task<ActionResult<int>> ChangePass(string currentPass, string newPass)
+ public async Task<ActionResult<int>> ChangePass([FromBody] ChangePass cp)
{
- return Ok(await _userService.ChangePass(currentPass,newPass));
+ return Ok(await _userService.ChangePass(cp.currentPass,cp.newPass));
}
diff --git a/Backend/Api/Api/Models/User.cs b/Backend/Api/Api/Models/User.cs
index 52d0f24..f789ffe 100644
--- a/Backend/Api/Api/Models/User.cs
+++ b/Backend/Api/Api/Models/User.cs
@@ -65,7 +65,7 @@ namespace Api.Models
public File? pfp { get; set; }
public int postcount { get; set; }
- public List<String> followers{ get; set; }
+ public List<String> followers { get; set; }
public List<String> following { get; set; }
public int followersCount { get; set; }
@@ -80,8 +80,9 @@ namespace Api.Models
public int totalViews { get; set; }
public int numberOfPosts { get; set; }
public int numberOfRatingsOnPosts { get; set; }
- public double averagePostRatingOnPosts {get; set; }
+ public double averagePostRatingOnPosts { get; set; }
public List<MonthlyViews> monthlyViews { get; set; }
+ public int numberOfFavouritePosts { get; set; }
}
public class MonthlyViews
@@ -89,4 +90,9 @@ namespace Api.Models
public int month { get; set; }
public int views { get; set; }
}
+ public class ChangePass
+ {
+ public string currentPass { get; set; }
+ public string newPass { get; set; }
+ }
}
diff --git a/Backend/Api/Api/Services/PostService.cs b/Backend/Api/Api/Services/PostService.cs
index 0799f10..07e225e 100644
--- a/Backend/Api/Api/Services/PostService.cs
+++ b/Backend/Api/Api/Services/PostService.cs
@@ -115,7 +115,7 @@ namespace Api.Services
foreach (var image in p.images)
System.IO.File.Delete(image.path);
- await _posts.DeleteOneAsync(postid);
+ await _posts.FindOneAndDeleteAsync(x => x._id==postid);
return true;
}
@@ -672,6 +672,7 @@ namespace Api.Services
stats.numberOfPosts = 0;
stats.totalViews = 0;
stats.monthlyViews = new List<MonthlyViews>();
+ stats.numberOfFavouritePosts = 0;
if(posts != null)
@@ -691,6 +692,8 @@ namespace Api.Services
stats.totalViews += post.views;
stats.numberOfRatingsOnPosts += post.ratingscount;
stats.numberOfPosts++;
+ if(post.favourites!=null)
+ stats.numberOfFavouritePosts+=post.favourites.Count;
ratingsum += post.ratings * post.ratingscount;
}
if(stats.numberOfRatingsOnPosts > 0) //don't forget to check div by 0 jesus
diff --git a/Backend/Api/Api/Services/UserService.cs b/Backend/Api/Api/Services/UserService.cs
index 74c0894..d8ec4a2 100644
--- a/Backend/Api/Api/Services/UserService.cs
+++ b/Backend/Api/Api/Services/UserService.cs
@@ -416,7 +416,9 @@ namespace Api.Services
}
User f = await _users.Find(user => user._id == followerId).FirstOrDefaultAsync();
User u = await _users.Find(user => user._id == id).FirstOrDefaultAsync();
-
+ if(await CheckIfAlreadyFollow(followerId))
+ return false;
+
if (id != null && followerId!=null)
{
if (f.followers == null)
@@ -617,27 +619,33 @@ namespace Api.Services
User u = await _users.Find(user => user._id == myId).FirstOrDefaultAsync();
User f = await _users.Find(user => user._id == id).FirstOrDefaultAsync();
-
+ if(await CheckIfAlreadyFollow(id))
if (u != null)
{
- if (u.following != null && f.followers!=null)
- {
u.following.Remove(f._id);
+ if (u.following == null)
+ u.following = new List<string>();
u.followingCount=u.following.Count();
+ if (u.followers == null)
+ u.followers = new List<string>();
u.followersCount = u.followers.Count();
f.followers.Remove(u._id);
+ if (f.followers == null)
+ f.followers = new List<string>();
f.followersCount =f.followers.Count();
+ if (f.following == null)
+ f.following = new List<string>();
f.followingCount =f.following.Count();
- _users.ReplaceOne(user => user._id == myId, u);
- _users.ReplaceOne(user => user._id == id, f);
+ await _users.ReplaceOneAsync(user => user._id == myId, u);
+ await _users.ReplaceOneAsync(user => user._id == id, f);
//updateUserFollowerFollowingCount(u.followers, u.following, u._id);
//updateUserFollowerFollowingCount(f.followers, f.following, f._id);
return true;
- }
+
}
return false;