aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJelena Petrovic <jelenapetrovic.7119@gmail.com>2022-11-06 23:45:09 +0100
committerJelena Petrovic <jelenapetrovic.7119@gmail.com>2022-11-06 23:45:09 +0100
commitf12280f2396d424ca43893a32939b1b016158b7b (patch)
treef57d0e7e24fe2c86bba7346cc7d3a4c91dd277c0
parent37f735cc805d63128263d417f8150e77b4b6272a (diff)
parentf5b8977e911adf5caba238d624c2668f2a57ba92 (diff)
Merge branch 'develop' of http://gitlab.pmf.kg.ac.rs/BrzoDoLokacije2022/odyssey/brzodolokacije into develop
-rw-r--r--Backend/Api/Api/Controllers/PostController.cs19
-rw-r--r--Backend/Api/Api/Interfaces/IPostService.cs2
-rw-r--r--Backend/Api/Api/Services/PostService.cs21
-rw-r--r--Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Fragments/FragmentLogin.kt1
-rw-r--r--Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/MainActivity.kt2
5 files changed, 36 insertions, 9 deletions
diff --git a/Backend/Api/Api/Controllers/PostController.cs b/Backend/Api/Api/Controllers/PostController.cs
index 31dbeef..a61ee2e 100644
--- a/Backend/Api/Api/Controllers/PostController.cs
+++ b/Backend/Api/Api/Controllers/PostController.cs
@@ -13,9 +13,11 @@ namespace Api.Controllers
public class PostController : ControllerBase
{
private readonly IPostService _postService;
- public PostController(IPostService postService)
+ private readonly IFileService _fileService;
+ public PostController(IPostService postService, IFileService fileService)
{
_postService = postService;
+ _fileService = fileService;
}
[HttpPost("add")]
@@ -40,7 +42,7 @@ namespace Api.Controllers
}
return BadRequest();
}
- [HttpGet("posts /{id}")]
+ [HttpGet("posts/{id}")]
[Authorize(Roles = "User")]
public async Task<ActionResult<PostSend>> getPostByid(string id)
{
@@ -52,5 +54,18 @@ namespace Api.Controllers
return BadRequest();
}
+ [HttpGet("image/{id}")]
+ [Authorize(Roles = "User")]
+ public async Task<ActionResult> getImage(string id)
+ {
+ Models.File f =await _fileService.getById(id);
+ if (f == null || !System.IO.File.Exists(f.path))
+ return BadRequest("Slika ne postoji");
+ return File(System.IO.File.ReadAllBytes(f.path), "image/*", Path.GetFileName(f.path));
+
+
+ }
+
+
}
}
diff --git a/Backend/Api/Api/Interfaces/IPostService.cs b/Backend/Api/Api/Interfaces/IPostService.cs
index 31e80cd..29a824a 100644
--- a/Backend/Api/Api/Interfaces/IPostService.cs
+++ b/Backend/Api/Api/Interfaces/IPostService.cs
@@ -7,6 +7,6 @@ namespace Api.Interfaces
Task<PostSend> addPost(PostReceive post);
Task<List<PostSend>> getAllPosts();
Task<PostSend> getPostById(string id);
- PostSend postToPostSend(Post post);
+ Task<PostSend> postToPostSend(Post post);
}
} \ No newline at end of file
diff --git a/Backend/Api/Api/Services/PostService.cs b/Backend/Api/Api/Services/PostService.cs
index 0a12f39..e9a56d2 100644
--- a/Backend/Api/Api/Services/PostService.cs
+++ b/Backend/Api/Api/Services/PostService.cs
@@ -11,12 +11,14 @@ namespace Api.Services
private readonly IMongoCollection<Post> _posts;
private readonly IHttpContextAccessor _httpContext;
private readonly IFileService _fileService;
- public PostService(IDatabaseConnection settings, IMongoClient mongoClient, IHttpContextAccessor httpContext, IFileService fileService)
+ private readonly ILocationService _locationService;
+ public PostService(IDatabaseConnection settings, IMongoClient mongoClient, IHttpContextAccessor httpContext, IFileService fileService,ILocationService locationService)
{
var database = mongoClient.GetDatabase(settings.DatabaseName);
_posts = database.GetCollection<Post>(settings.PostCollectionName);
_httpContext = httpContext;
_fileService = fileService;
+ _locationService = locationService;
}
public async Task<PostSend> addPost(PostReceive post)
@@ -63,14 +65,23 @@ namespace Api.Services
}
await _posts.InsertOneAsync(p);
- return postToPostSend(p);
+ return await postToPostSend(p);
}
- public PostSend postToPostSend(Post post)
+ public async Task<PostSend> postToPostSend(Post post)
{
PostSend p = new PostSend();
//Convert post to post send (TODO)
p._id = post._id;
+ p.ownerId = post.ownerId;
+ p.description = post.description;
+ p.location = await _locationService.getById(post.locationId);
+ p.images = post.images;
+ p.views = 1;//Default values todo
+ p.ratings = 1;
+ p.comments = null;
+
+
return p;
}
@@ -80,7 +91,7 @@ namespace Api.Services
List<PostSend> temp = new List<PostSend>();
foreach (var post in posts)
{
- temp.Add(postToPostSend(post));
+ temp.Add(await postToPostSend(post));
}
return temp;
}
@@ -88,7 +99,7 @@ namespace Api.Services
public async Task<PostSend> getPostById(string id)
{
Post p = await _posts.Find(post => post._id == id).FirstOrDefaultAsync();
- return postToPostSend(p);
+ return await postToPostSend(p);
}
//(TODO) ADD Delete and update
diff --git a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Fragments/FragmentLogin.kt b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Fragments/FragmentLogin.kt
index 9092700..01b3f1d 100644
--- a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Fragments/FragmentLogin.kt
+++ b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Fragments/FragmentLogin.kt
@@ -95,6 +95,7 @@ class FragmentLogin : Fragment() {
SharedPreferencesHelper.addValue("jwt",token,activity!!)
val intent= Intent(activity!!, NavigationActivity::class.java)
startActivity(intent)
+ activity!!.finish()
}else{
if(response.errorBody()!=null)
Toast.makeText(activity, response.errorBody()!!.string(), Toast.LENGTH_LONG).show();
diff --git a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/MainActivity.kt b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/MainActivity.kt
index e55da11..0245e9b 100644
--- a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/MainActivity.kt
+++ b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/MainActivity.kt
@@ -30,6 +30,7 @@ class MainActivity : AppCompatActivity() {
startActivity(intent)
+ finish()
}
fun checkLoggedIn():Boolean{
@@ -48,7 +49,6 @@ class MainActivity : AppCompatActivity() {
}
fun refreshJwt(token:String){
- Log.d("Main","RIPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP")
if(token==null)
return
var refreshJwt= RetrofitHelper.getInstance().refreshJwt("Bearer "+token)