Skip to content

Commit

Permalink
#118 feat: 투표 생성 서버 세팅 완료
Browse files Browse the repository at this point in the history
  • Loading branch information
stopkite committed Mar 3, 2024
1 parent 0c593b1 commit 8df3a05
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
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 {

@GET("/group/{groupId}/vote")
suspend fun getVoteStatus(@Path("groupId") groupId: Int): Response<ResponseVoteStatus>

@POST("/group/{groupId}/vote")
suspend fun createVote(@Path("groupId") groupId: Int, @Body requestCreateVote: RequestCreateVote): Response<ResponseCreateVote>

}
Original file line number Diff line number Diff line change
@@ -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<ResponseVoteStatus>

suspend fun createVote(groupId: Int, requestCreateVote: RequestCreateVote): Result<ResponseCreateVote>
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ 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

class GroupVoteRemoteDataSourceImpl @Inject constructor(private val groupVoteService: GroupVoteService) : GroupVoteRemoteDataSource {
override suspend fun getVoteStatus(groupId: Int): Result<ResponseVoteStatus> {
return groupVoteService.getVoteStatus(groupId).getResultFromResponse()
}

override suspend fun createVote(groupId: Int, requestCreateVote: RequestCreateVote): Result<ResponseCreateVote> {
return groupVoteService.createVote(groupId, requestCreateVote).getResultFromResponse()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.moidot.moidot.data.remote.request

data class RequestCreateVote(
val isAnonymous: Boolean,
val isEnabledMultipleChoice: Boolean,
val endAt: String,
)
Original file line number Diff line number Diff line change
@@ -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
)
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -9,4 +11,8 @@ class GroupVoteRepositoryImpl @Inject constructor(private val groupVoteRemoteDat
override suspend fun getVoteStatus(groupId: Int): Result<ResponseVoteStatus> {
return groupVoteRemoteDataSource.getVoteStatus(groupId)
}

override suspend fun createVote(groupId: Int, requestCreateVote: RequestCreateVote): Result<ResponseCreateVote> {
return groupVoteRemoteDataSource.createVote(groupId, requestCreateVote)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,15 @@ class LeaderVoteBeforeFragment : BaseFragment<FragmentLeaderVoteBeforeBinding>(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 {
Expand Down Expand Up @@ -90,7 +94,6 @@ class LeaderVoteBeforeFragment : BaseFragment<FragmentLeaderVoteBeforeBinding>(R
}
}

// TODO 왜 데이터 바인딩 onclick 이 안 먹는 건지 이해 x
fun onClickVoteCreate() {
Intent(requireContext(), CreateVoteActivity::class.java).apply {
putExtra(VOTE_RECREATE_STATE, voteRecreateState)
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ResponseVoteStatus>

suspend fun createVote(groupId: Int, requestCreateVote: RequestCreateVote): Result<ResponseCreateVote>
}

0 comments on commit 8df3a05

Please sign in to comment.