Skip to content

Commit

Permalink
merge: 내가 작성한 글 구현 (#887)
Browse files Browse the repository at this point in the history
Related to: #886
  • Loading branch information
chws0508 authored Feb 7, 2024
1 parent d1d3dcc commit 3f53d2b
Show file tree
Hide file tree
Showing 36 changed files with 662 additions and 319 deletions.
5 changes: 4 additions & 1 deletion android/2023-emmsale/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
android:theme="@style/Theme.Emmsale"
android:usesCleartextTraffic="true"
tools:targetApi="33">
<activity
android:name=".presentation.ui.myPostListPage.MyPostsActivity"
android:exported="false" />
<activity android:name=".presentation.ui.eventSearch.EventSearchActivity" />
<activity android:name=".presentation.ui.feedDetail.FeedDetailActivity" />
<activity
Expand All @@ -35,10 +38,10 @@
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".presentation.ui.myRecruitmentList.MyRecruitmentActivity" />
<activity android:name=".presentation.ui.notificationTagConfig.NotificationTagConfigActivity" />
<activity android:name=".presentation.ui.notificationList.NotificationsActivity" />
<activity android:name=".presentation.ui.myCommentList.MyCommentsActivity" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ data class FeedResponse(
val id: Long,
@SerialName("eventId")
val eventId: Long,
@SerialName("eventName")
val eventName: String = "",
@SerialName("title")
val title: String,
@SerialName("content")
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ data class RecruitmentResponse(
val member: MemberResponse,
@SerialName("eventId")
val eventId: Long,
@SerialName("eventName")
val eventName: String = "",
)

@Serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ package com.emmsale.data.mapper

import com.emmsale.BuildConfig
import com.emmsale.data.apiModel.response.FeedResponse
import com.emmsale.data.model.Event
import com.emmsale.data.model.Feed

fun List<FeedResponse>.toData(): List<Feed> = map { it.toData() }

fun FeedResponse.toData(): Feed = Feed(
id = id,
eventId = eventId,
event = Event(
id = eventId,
name = eventName,
),
title = title,
content = content,
writer = writer.toData(),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ fun RecruitmentResponse.toData(): Recruitment = Recruitment(
content = content,
updatedDate = updatedAt,
writer = member.toData(),
event = Event(id = eventId),
event = Event(
id = eventId,
name = eventName,
),
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import java.time.LocalDateTime

data class Feed(
val id: Long = -1,
val eventId: Long = -1,
val event: Event = Event(),
val title: String = "",
val content: String = "",
val writer: Member = Member(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ class DefaultFeedRepository @Inject constructor(
.map(FeedResponse::toData)
}

override suspend fun getMyFeeds(): ApiResponse<List<Feed>> = withContext(dispatcher) {
feedService
.getMyFeeds()
.map { it.toData() }
}

override suspend fun deleteFeed(
feedId: Long,
): ApiResponse<Unit> = withContext(dispatcher) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ interface FeedRepository {

suspend fun getFeed(feedId: Long): ApiResponse<Feed>

suspend fun getMyFeeds(): ApiResponse<List<Feed>>

suspend fun deleteFeed(feedId: Long): ApiResponse<Unit>

suspend fun uploadFeed(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ interface FeedService {
@Query("event-id") eventId: Long,
): ApiResponse<List<FeedResponse>>

@GET("/feeds/my")
suspend fun getMyFeeds(): ApiResponse<List<FeedResponse>>

@GET("/feeds/{feedId}")
suspend fun getFeed(
@Path("feedId") feedId: Long,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.emmsale.data.service
import com.emmsale.data.apiModel.request.RecruitmentCreateRequest
import com.emmsale.data.apiModel.request.RecruitmentDeleteRequest
import com.emmsale.data.apiModel.request.RecruitmentReportCreateRequest
import com.emmsale.data.apiModel.response.MyPostResponse
import com.emmsale.data.apiModel.response.RecruitmentReportResponse
import com.emmsale.data.apiModel.response.RecruitmentResponse
import com.emmsale.data.common.retrofit.callAdapter.ApiResponse
Expand Down Expand Up @@ -31,7 +30,7 @@ interface RecruitmentService {
@GET("/events/recruitment-posts")
suspend fun getMemberRecruitments(
@Query("member-id") memberId: Long,
): ApiResponse<List<MyPostResponse>>
): ApiResponse<List<RecruitmentResponse>>

@POST("/events/{eventId}/recruitment-posts")
suspend fun postRecruitment(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import com.emmsale.data.service.FeedService
import com.emmsale.data.service.LoginService
import com.emmsale.data.service.MemberService
import com.emmsale.data.service.MessageRoomService
import com.emmsale.data.service.MyPostService
import com.emmsale.data.service.NotificationService
import com.emmsale.data.service.RecruitmentService
import dagger.Module
Expand Down Expand Up @@ -88,12 +87,6 @@ class ServiceModule {
serviceFactory: ServiceFactory,
): BlockedMemberService = serviceFactory.create(BlockedMemberService::class.java)

@Provides
@Singleton
fun provideMyPostService(
serviceFactory: ServiceFactory,
): MyPostService = serviceFactory.create(MyPostService::class.java)

@Provides
@Singleton
fun provideMessageRoomService(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.emmsale.presentation.ui.myFeedList

import android.os.Bundle
import android.view.View
import androidx.fragment.app.viewModels
import com.emmsale.R
import com.emmsale.databinding.FragmentMyFeedsBinding
import com.emmsale.presentation.base.NetworkFragment
import com.emmsale.presentation.common.recyclerView.DividerItemDecoration
import com.emmsale.presentation.ui.feedDetail.FeedDetailActivity
import com.emmsale.presentation.ui.myFeedList.recyclerView.MyFeedAdapter
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class MyFeedsFragment : NetworkFragment<FragmentMyFeedsBinding>(R.layout.fragment_my_feeds) {

override val viewModel: MyFeedsViewModel by viewModels()

private val myFeedAdapter: MyFeedAdapter by lazy {
MyFeedAdapter(onItemClick = ::navigateToDetail)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setupDataBinding()
setupRecyclerView()

observeMyFeeds()
}

private fun setupDataBinding() {
binding.vm = viewModel
}

private fun setupRecyclerView() {
binding.rvMyFeeds.apply {
adapter = myFeedAdapter
itemAnimator = null
addItemDecoration(DividerItemDecoration(context = context))
}
}

private fun observeMyFeeds() {
viewModel.myFeeds.observe(viewLifecycleOwner) { myFeeds ->
myFeedAdapter.submitList(myFeeds)
}
}

private fun navigateToDetail(feedId: Long) {
FeedDetailActivity.startActivity(
requireContext(),
feedId = feedId,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.emmsale.presentation.ui.myFeedList

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.emmsale.data.model.Feed
import com.emmsale.data.repository.interfaces.FeedRepository
import com.emmsale.presentation.base.RefreshableViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Job
import javax.inject.Inject

@HiltViewModel
class MyFeedsViewModel @Inject constructor(
private val feedRepository: FeedRepository,
) : RefreshableViewModel() {

private val _myFeeds: MutableLiveData<List<Feed>> = MutableLiveData(emptyList())
val myFeeds: LiveData<List<Feed>> = _myFeeds

init {
fetchMyFeeds()
}

private fun fetchMyFeeds(): Job = fetchData(
fetchData = { feedRepository.getMyFeeds() },
onSuccess = {
_myFeeds.value = it.sortedByDescending { feed -> feed.createdAt }
},
)

override fun refresh(): Job = refreshData(
refresh = { feedRepository.getMyFeeds() },
onSuccess = {
_myFeeds.value = it.sortedByDescending { feed -> feed.createdAt }
},
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.emmsale.presentation.ui.myFeedList.recyclerView

import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import com.emmsale.data.model.Feed

class MyFeedAdapter(
private val onItemClick: (recruitmentId: Long) -> Unit,
) : ListAdapter<Feed, MyFeedViewHolder>(
object : DiffUtil.ItemCallback<Feed>() {
override fun areItemsTheSame(
oldItem: Feed,
newItem: Feed,
): Boolean = oldItem == newItem

override fun areContentsTheSame(
oldItem: Feed,
newItem: Feed,
): Boolean = oldItem.id == newItem.id
},
) {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyFeedViewHolder {
return MyFeedViewHolder.create(parent, onItemClick)
}

override fun onBindViewHolder(holder: MyFeedViewHolder, position: Int) {
holder.bind(getItem(position))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.emmsale.presentation.ui.myFeedList.recyclerView

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.emmsale.data.model.Feed
import com.emmsale.databinding.ItemMyFeedBinding

class MyFeedViewHolder(
private val binding: ItemMyFeedBinding,
navigateToDetail: (feedId: Long) -> Unit,
) : RecyclerView.ViewHolder(binding.root) {

init {
itemView.setOnClickListener { navigateToDetail(binding.feed!!.id) }
}

fun bind(feed: Feed) {
binding.feed = feed
}

companion object {
fun create(
parent: ViewGroup,
onItemClick: (feedId: Long) -> Unit,
): MyFeedViewHolder {
val binding =
ItemMyFeedBinding.inflate(LayoutInflater.from(parent.context), parent, false)
return MyFeedViewHolder(binding, onItemClick)
}
}
}
Loading

0 comments on commit 3f53d2b

Please sign in to comment.