diff options
author | TAMARA JERINIC <tamara.jerinic@gmail.com> | 2022-11-28 01:46:34 +0100 |
---|---|---|
committer | TAMARA JERINIC <tamara.jerinic@gmail.com> | 2022-11-28 01:46:34 +0100 |
commit | 37b2dff40d7e1395e3dc77bd7bb353e0181a37a6 (patch) | |
tree | 0fd75d98956a14eba18c4fed399140555899524f | |
parent | 6e7afb7ae49eff07f9403e006dbe102e402a0441 (diff) |
Dodato sortiranje objava na back-u i prikaz sortiranih objava na front-u. Izmenjen prikaz objave.
11 files changed, 208 insertions, 50 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; + } } } diff --git a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Fragments/FragmentHomePageMainScroll.kt b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Fragments/FragmentHomePageMainScroll.kt index 3846d6c..46904d4 100644 --- a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Fragments/FragmentHomePageMainScroll.kt +++ b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Fragments/FragmentHomePageMainScroll.kt @@ -194,6 +194,9 @@ private lateinit var change:Button } private fun getAllPosts(){ + Toast.makeText( + activity," get all", Toast.LENGTH_LONG + ).show(); val api = Retrofit.Builder() .addConverterFactory(GsonConverterFactory.create()) .baseUrl(RetrofitHelper.baseUrl) @@ -219,9 +222,9 @@ private lateinit var change:Button // activity, "get all ", Toast.LENGTH_LONG // ).show(); posts = response.body()!!.toMutableList<PostPreview>() - getPopularPosts(posts) - getNewestPosts(posts) - getBestRatedPosts(posts) + getPopularPosts() + getNewestPosts() + getBestRatedPosts() } override fun onFailure(call: Call<MutableList<PostPreview>>, t: Throwable) { @@ -232,41 +235,101 @@ private lateinit var change:Button }) } - private fun getPopularPosts(allPosts:MutableList<PostPreview>){//most viewed + private fun getPopularPosts(){//most viewed // Toast.makeText( // activity, "get all mv ", Toast.LENGTH_LONG // ).show(); - mostViewedPosts=allPosts - mostViewedPosts.sortByDescending { it.views } - rvPopular.apply { - layoutManager= LinearLayoutManager(activity, LinearLayoutManager.HORIZONTAL,false) - adapter= ShowPostsHomePageAdapter(mostViewedPosts,requireActivity()) + Toast.makeText( + activity," get popular all", Toast.LENGTH_LONG + ).show(); + val api = RetrofitHelper.getInstance() + val token= SharedPreferencesHelper.getValue("jwt", requireActivity()) + val data=api.get10MostViewed("Bearer "+token) + + data.enqueue(object : Callback<MutableList<PostPreview>> { + override fun onResponse( + call: Call<MutableList<PostPreview>>, + response: Response<MutableList<PostPreview>> + ) { + if (response.body() == null) { + return + } + var mostpopular = response.body()!!.toMutableList<PostPreview>() + rvPopular.apply { + layoutManager= LinearLayoutManager(activity, LinearLayoutManager.HORIZONTAL,false) + adapter= ShowPostsHomePageAdapter(mostpopular,requireActivity()) + + } + } + override fun onFailure(call: Call<MutableList<PostPreview>>, t: Throwable) { + + } + }) - } } - private fun getNewestPosts(allPosts:MutableList<PostPreview>){ + private fun getNewestPosts(){ // Toast.makeText( // activity, "get all r ", Toast.LENGTH_LONG // ).show(); - newestPosts=allPosts/// izmeniti nakon dodavanja datuma u model!!!!!! - newestPosts.sortBy { it.ratings} - rvNewest.apply { - layoutManager= LinearLayoutManager(activity, LinearLayoutManager.HORIZONTAL,false) - adapter= ShowPostsHomePageAdapter(newestPosts,requireActivity()) - } + Toast.makeText( + activity," get all newest", Toast.LENGTH_LONG + ).show(); + val api = RetrofitHelper.getInstance() + val token= SharedPreferencesHelper.getValue("jwt", requireActivity()) + val data=api.get10Newest("Bearer "+token) + + data.enqueue(object : Callback<MutableList<PostPreview>> { + override fun onResponse( + call: Call<MutableList<PostPreview>>, + response: Response<MutableList<PostPreview>> + ) { + if (response.body() == null) { + return + } + var newestposts = response.body()!!.toMutableList<PostPreview>() + rvNewest.apply { + layoutManager= LinearLayoutManager(activity, LinearLayoutManager.HORIZONTAL,false) + adapter= ShowPostsHomePageAdapter(newestposts,requireActivity()) + } + } + override fun onFailure(call: Call<MutableList<PostPreview>>, t: Throwable) { + + } + }) + } - private fun getBestRatedPosts(allPosts:MutableList<PostPreview>){ + private fun getBestRatedPosts(){ // Toast.makeText( // activity, "get all br ", Toast.LENGTH_LONG // ).show(); - bestRatedPosts=allPosts - bestRatedPosts.sortByDescending { it.ratings } - rvBestRated.apply { - layoutManager= LinearLayoutManager(activity, LinearLayoutManager.HORIZONTAL,false) - adapter= ShowPostsHomePageAdapter(bestRatedPosts,requireActivity()) - } + Toast.makeText( + activity," get all best", Toast.LENGTH_LONG + ).show(); + val api = RetrofitHelper.getInstance() + val token= SharedPreferencesHelper.getValue("jwt", requireActivity()) + val data=api.get10Best("Bearer "+token) + + data.enqueue(object : Callback<MutableList<PostPreview>> { + override fun onResponse( + call: Call<MutableList<PostPreview>>, + response: Response<MutableList<PostPreview>> + ) { + if (response.body() == null) { + return + } + var bestposts = response.body()!!.toMutableList<PostPreview>() + rvBestRated.apply { + layoutManager= LinearLayoutManager(activity, LinearLayoutManager.HORIZONTAL,false) + adapter= ShowPostsHomePageAdapter(bestposts,requireActivity()) + } + } + override fun onFailure(call: Call<MutableList<PostPreview>>, t: Throwable) { + + } + }) + } diff --git a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Interfaces/IBackendApi.kt b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Interfaces/IBackendApi.kt index cb51627..e4bfbc8 100644 --- a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Interfaces/IBackendApi.kt +++ b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Interfaces/IBackendApi.kt @@ -83,4 +83,13 @@ interface IBackendApi { @GET("/api/user/{id}/id/profile") fun getProfileFromId(@Header("Authorization") authHeader:String,@Path("id") username:String):Call<UserReceive> + @GET("/api/Post/posts/get10MostViewed") + fun get10MostViewed(@Header("Authorization") authHeader:String):Call<MutableList<PostPreview>> + + @GET("/api/Post/posts/get10Best") + fun get10Best(@Header("Authorization") authHeader:String):Call<MutableList<PostPreview>> + + @GET("/api/Post/posts/get10Newest") + fun get10Newest(@Header("Authorization") authHeader:String):Call<MutableList<PostPreview>> + }
\ No newline at end of file diff --git a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Services/RetrofitHelper.kt b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Services/RetrofitHelper.kt index 88685e4..43c2109 100644 --- a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Services/RetrofitHelper.kt +++ b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Services/RetrofitHelper.kt @@ -7,8 +7,8 @@ import retrofit2.converter.gson.GsonConverterFactory object RetrofitHelper { - //val baseUrl="http://10.0.2.2:5279" - val baseUrl="http://147.91.204.115:10082" + val baseUrl="http://10.0.2.2:5279" + //val baseUrl="http://147.91.204.115:10082" private var retrofit_noauth: IBackendApi? = null private var retrofit_auth: IBackendApi? = null diff --git a/Client/BrzoDoLokacije/app/src/main/res/drawable/ic_baseline_circle_24.xml b/Client/BrzoDoLokacije/app/src/main/res/drawable/ic_baseline_circle_24.xml new file mode 100644 index 0000000..4d57238 --- /dev/null +++ b/Client/BrzoDoLokacije/app/src/main/res/drawable/ic_baseline_circle_24.xml @@ -0,0 +1,5 @@ +<vector android:height="15dp" android:tint="#F1DB24" + android:viewportHeight="15" android:viewportWidth="15" + android:width="15dp" xmlns:android="http://schemas.android.com/apk/res/android"> + <path android:fillColor="@android:color/white" android:pathData="M12,2C6.47,2 2,6.47 2,12s4.47,10 10,10 10,-4.47 10,-10S17.53,2 12,2z"/> +</vector> diff --git a/Client/BrzoDoLokacije/app/src/main/res/drawable/ic_baseline_circle_7.xml b/Client/BrzoDoLokacije/app/src/main/res/drawable/ic_baseline_circle_7.xml new file mode 100644 index 0000000..6d080ea --- /dev/null +++ b/Client/BrzoDoLokacije/app/src/main/res/drawable/ic_baseline_circle_7.xml @@ -0,0 +1,5 @@ +<vector android:height="7dp" android:tint="#F1DB24" + android:viewportHeight="24" android:viewportWidth="24" + android:width="7dp" xmlns:android="http://schemas.android.com/apk/res/android"> + <path android:fillColor="@android:color/white" android:pathData="M12,2C6.47,2 2,6.47 2,12s4.47,10 10,10 10,-4.47 10,-10S17.53,2 12,2z"/> +</vector> diff --git a/Client/BrzoDoLokacije/app/src/main/res/layout/fragment_home_page_main_scroll.xml b/Client/BrzoDoLokacije/app/src/main/res/layout/fragment_home_page_main_scroll.xml index 2883291..efae8d4 100644 --- a/Client/BrzoDoLokacije/app/src/main/res/layout/fragment_home_page_main_scroll.xml +++ b/Client/BrzoDoLokacije/app/src/main/res/layout/fragment_home_page_main_scroll.xml @@ -154,19 +154,34 @@ android:layout_marginTop="16dp" <androidx.cardview.widget.CardView android:backgroundTint="#f6f6f6" - android:layout_marginStart="25dp" + android:layout_marginStart="10dp" android:layout_marginEnd="16dp" + android:id="@+id/cvFragmentHomePageText2" android:layout_width="match_parent" android:layout_height="wrap_content" + android:stateListAnimator="@null" + android:elevation="0dp" android:layout_marginTop="16dp"> <TextView android:id="@+id/tvFragmentHomePageNewest" android:layout_width="wrap_content" - android:layout_height="wrap_content" + android:layout_height="match_parent" android:layout_gravity="left" + android:drawableBottom="@drawable/ic_baseline_circle_7" android:text="Najnovije" + android:clickable="true" + android:textStyle="bold" /> + <TextView + android:id="@+id/tvFragmentHomePageBestRated" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="left" + android:text="Najposećenije" + android:layout_marginStart="80dp" + android:drawableBottom="@drawable/ic_baseline_circle_7" + android:textStyle="bold" /> <TextView @@ -201,13 +216,7 @@ android:layout_marginTop="16dp" android:layout_height="wrap_content" android:layout_marginTop="16dp"> - <TextView - android:id="@+id/tvFragmentHomePageBestRated" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_gravity="left" - android:text="Najposećenije" - android:textStyle="bold" /> + <TextView android:id="@+id/tvFragmentHomePageBestRatedShowAll" diff --git a/Client/BrzoDoLokacije/app/src/main/res/layout/post_item_home_page.xml b/Client/BrzoDoLokacije/app/src/main/res/layout/post_item_home_page.xml index a2f20f3..d2c503f 100644 --- a/Client/BrzoDoLokacije/app/src/main/res/layout/post_item_home_page.xml +++ b/Client/BrzoDoLokacije/app/src/main/res/layout/post_item_home_page.xml @@ -9,34 +9,32 @@ android:id="@+id/imageView9" android:layout_width="170dp" android:layout_height="240dp" - android:layout_marginStart="4dp" - android:layout_marginBottom="10dp" - android:layout_marginEnd="4dp" + android:layout_marginStart="7dp" android:layout_marginTop="4dp" + android:layout_marginEnd="7dp" + android:layout_marginBottom="10dp" android:elevation="3dp" android:src="@color/white" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toTopOf="parent" app:shapeAppearanceOverlay="@style/Circular" /> <com.google.android.material.imageview.ShapeableImageView android:id="@+id/ivPIHPBackground" - android:layout_width="0dp" - android:layout_height="186dp" - android:layout_marginStart="8dp" - android:layout_marginEnd="4dp" + android:layout_width="172dp" + android:layout_height="185dp" + android:layout_marginStart="1dp" + android:layout_marginEnd="1dp" android:elevation="3dp" android:scaleType="fitXY" app:layout_constraintBottom_toBottomOf="@+id/imageView9" - app:layout_constraintEnd_toEndOf="@+id/imageView9" - app:layout_constraintHorizontal_bias="1.0" - app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toTopOf="parent" - app:layout_constraintVertical_bias="0.045" - app:shapeAppearanceOverlay="@style/Circular" + app:layout_constraintEnd_toEndOf="@id/imageView9" + app:layout_constraintStart_toStartOf="@id/imageView9" + app:layout_constraintTop_toTopOf="@id/imageView9" + app:layout_constraintVertical_bias="0.0" + app:shapeAppearanceOverlay="@style/roundedTop" app:srcCompat="@drawable/b1" /> <TextView @@ -95,7 +93,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="4dp" - android:layout_marginTop="2dp" + android:layout_marginTop="4dp" android:elevation="3dp" android:text="TextView" android:textSize="11dp" diff --git a/Client/BrzoDoLokacije/app/src/main/res/values/styles.xml b/Client/BrzoDoLokacije/app/src/main/res/values/styles.xml index dacd4b5..8fcd452 100644 --- a/Client/BrzoDoLokacije/app/src/main/res/values/styles.xml +++ b/Client/BrzoDoLokacije/app/src/main/res/values/styles.xml @@ -18,4 +18,9 @@ <item name="cornerSizeBottomLeft">20dp</item> <item name="cornerSizeBottomRight">20dp</item> </style> + + <style name="roundedTop"> + <item name="cornerSizeTopLeft">10dp</item> + <item name="cornerSizeTopRight">10dp</item> + </style> </resources>
\ No newline at end of file |