diff --git a/app/src/main/java/com/moidot/moidot/data/api/GroupVoteService.kt b/app/src/main/java/com/moidot/moidot/data/api/GroupVoteService.kt index 25a260ec..b10b6a5e 100644 --- a/app/src/main/java/com/moidot/moidot/data/api/GroupVoteService.kt +++ b/app/src/main/java/com/moidot/moidot/data/api/GroupVoteService.kt @@ -1,8 +1,12 @@ package com.moidot.moidot.data.api +import com.moidot.moidot.data.remote.request.RequestCreateVote +import com.moidot.moidot.data.remote.response.ResponseCreateVote import com.moidot.moidot.data.remote.response.ResponseVoteStatus import retrofit2.Response +import retrofit2.http.Body import retrofit2.http.GET +import retrofit2.http.POST import retrofit2.http.Path interface GroupVoteService { @@ -10,4 +14,7 @@ interface GroupVoteService { @GET("/group/{groupId}/vote") suspend fun getVoteStatus(@Path("groupId") groupId: Int): Response + @POST("/group/{groupId}/vote") + suspend fun createVote(@Path("groupId") groupId: Int, @Body requestCreateVote: RequestCreateVote): Response + } \ No newline at end of file diff --git a/app/src/main/java/com/moidot/moidot/data/remote/datasource/group/GroupVoteRemoteDataSource.kt b/app/src/main/java/com/moidot/moidot/data/remote/datasource/group/GroupVoteRemoteDataSource.kt index aa94e843..875c5173 100644 --- a/app/src/main/java/com/moidot/moidot/data/remote/datasource/group/GroupVoteRemoteDataSource.kt +++ b/app/src/main/java/com/moidot/moidot/data/remote/datasource/group/GroupVoteRemoteDataSource.kt @@ -1,7 +1,11 @@ package com.moidot.moidot.data.remote.datasource.group +import com.moidot.moidot.data.remote.request.RequestCreateVote +import com.moidot.moidot.data.remote.response.ResponseCreateVote import com.moidot.moidot.data.remote.response.ResponseVoteStatus interface GroupVoteRemoteDataSource { suspend fun getVoteStatus(groupId:Int): Result + + suspend fun createVote(groupId: Int, requestCreateVote: RequestCreateVote): Result } \ No newline at end of file diff --git a/app/src/main/java/com/moidot/moidot/data/remote/datasource/group/GroupVoteRemoteDataSourceImpl.kt b/app/src/main/java/com/moidot/moidot/data/remote/datasource/group/GroupVoteRemoteDataSourceImpl.kt index 7a06ca4e..93c5f6be 100644 --- a/app/src/main/java/com/moidot/moidot/data/remote/datasource/group/GroupVoteRemoteDataSourceImpl.kt +++ b/app/src/main/java/com/moidot/moidot/data/remote/datasource/group/GroupVoteRemoteDataSourceImpl.kt @@ -2,6 +2,8 @@ package com.moidot.moidot.data.remote.datasource.group import com.moidot.moidot.data.api.GroupVoteService import com.moidot.moidot.data.remote.datasource.getResultFromResponse +import com.moidot.moidot.data.remote.request.RequestCreateVote +import com.moidot.moidot.data.remote.response.ResponseCreateVote import com.moidot.moidot.data.remote.response.ResponseVoteStatus import javax.inject.Inject @@ -9,4 +11,8 @@ class GroupVoteRemoteDataSourceImpl @Inject constructor(private val groupVoteSer override suspend fun getVoteStatus(groupId: Int): Result { return groupVoteService.getVoteStatus(groupId).getResultFromResponse() } + + override suspend fun createVote(groupId: Int, requestCreateVote: RequestCreateVote): Result { + return groupVoteService.createVote(groupId, requestCreateVote).getResultFromResponse() + } } \ No newline at end of file diff --git a/app/src/main/java/com/moidot/moidot/data/remote/request/RequestCreateVote.kt b/app/src/main/java/com/moidot/moidot/data/remote/request/RequestCreateVote.kt new file mode 100644 index 00000000..9083419c --- /dev/null +++ b/app/src/main/java/com/moidot/moidot/data/remote/request/RequestCreateVote.kt @@ -0,0 +1,7 @@ +package com.moidot.moidot.data.remote.request + +data class RequestCreateVote( + val isAnonymous: Boolean, + val isEnabledMultipleChoice: Boolean, + val endAt: String, +) \ No newline at end of file diff --git a/app/src/main/java/com/moidot/moidot/data/remote/response/ResponseCreateVote.kt b/app/src/main/java/com/moidot/moidot/data/remote/response/ResponseCreateVote.kt new file mode 100644 index 00000000..e1f7e318 --- /dev/null +++ b/app/src/main/java/com/moidot/moidot/data/remote/response/ResponseCreateVote.kt @@ -0,0 +1,14 @@ +package com.moidot.moidot.data.remote.response + +data class ResponseCreateVote( + val `data`: Data, +) : BaseResponse() { + data class Data( + val endAt: String, + val groupId: Int, + val isAnonymous: Boolean, + val isClosed: Boolean, + val isEnabledMultipleChoice: Boolean, + val voteId: Int + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/moidot/moidot/data/repository/GroupVoteRepositoryImpl.kt b/app/src/main/java/com/moidot/moidot/data/repository/GroupVoteRepositoryImpl.kt index d7ea715c..f2b8e96d 100644 --- a/app/src/main/java/com/moidot/moidot/data/repository/GroupVoteRepositoryImpl.kt +++ b/app/src/main/java/com/moidot/moidot/data/repository/GroupVoteRepositoryImpl.kt @@ -1,6 +1,8 @@ package com.moidot.moidot.data.repository import com.moidot.moidot.data.remote.datasource.group.GroupVoteRemoteDataSource +import com.moidot.moidot.data.remote.request.RequestCreateVote +import com.moidot.moidot.data.remote.response.ResponseCreateVote import com.moidot.moidot.data.remote.response.ResponseVoteStatus import com.moidot.moidot.repository.GroupVoteRepository import javax.inject.Inject @@ -9,4 +11,8 @@ class GroupVoteRepositoryImpl @Inject constructor(private val groupVoteRemoteDat override suspend fun getVoteStatus(groupId: Int): Result { return groupVoteRemoteDataSource.getVoteStatus(groupId) } + + override suspend fun createVote(groupId: Int, requestCreateVote: RequestCreateVote): Result { + return groupVoteRemoteDataSource.createVote(groupId, requestCreateVote) + } } \ No newline at end of file diff --git a/app/src/main/java/com/moidot/moidot/presentation/main/group/space/leader/vote/before/LeaderVoteBeforeFragment.kt b/app/src/main/java/com/moidot/moidot/presentation/main/group/space/leader/vote/before/LeaderVoteBeforeFragment.kt index 48692e9f..ff2cc3ad 100644 --- a/app/src/main/java/com/moidot/moidot/presentation/main/group/space/leader/vote/before/LeaderVoteBeforeFragment.kt +++ b/app/src/main/java/com/moidot/moidot/presentation/main/group/space/leader/vote/before/LeaderVoteBeforeFragment.kt @@ -42,11 +42,15 @@ class LeaderVoteBeforeFragment : BaseFragment(R override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - binding.fragment = this viewModel.loadBestRegions(groupId) + initBinding() setupObserver() } + private fun initBinding() { + binding.fragment = this + } + private fun setupObserver() { viewModel.bestRegions.observe(viewLifecycleOwner) { lifecycleScope.launch { @@ -90,7 +94,6 @@ class LeaderVoteBeforeFragment : BaseFragment(R } } - // TODO 왜 데이터 바인딩 onclick 이 안 먹는 건지 이해 x fun onClickVoteCreate() { Intent(requireContext(), CreateVoteActivity::class.java).apply { putExtra(VOTE_RECREATE_STATE, voteRecreateState) diff --git a/app/src/main/java/com/moidot/moidot/repository/GroupVoteRepository.kt b/app/src/main/java/com/moidot/moidot/repository/GroupVoteRepository.kt index 9cf560dc..b4fa9c80 100644 --- a/app/src/main/java/com/moidot/moidot/repository/GroupVoteRepository.kt +++ b/app/src/main/java/com/moidot/moidot/repository/GroupVoteRepository.kt @@ -1,7 +1,11 @@ package com.moidot.moidot.repository +import com.moidot.moidot.data.remote.request.RequestCreateVote +import com.moidot.moidot.data.remote.response.ResponseCreateVote import com.moidot.moidot.data.remote.response.ResponseVoteStatus interface GroupVoteRepository { suspend fun getVoteStatus(groupId: Int): Result + + suspend fun createVote(groupId: Int, requestCreateVote: RequestCreateVote): Result } \ No newline at end of file