Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix/inflate issue #58

Merged
merged 9 commits into from
Jul 19, 2023
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.puzzling.puzzlingaos.data.model.request

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class RequestInvitationCode(
@SerialName("projectId")
val projectId: Int,
@SerialName("memberProjectNickname")
val memberProjectNickname: String,
@SerialName("memberProjectRole")
val memberProjectRole: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.puzzling.puzzlingaos.data.model.response

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class ResponseProjectRetroWeekDto(
@SerialName("status")
val status: Int,
@SerialName("success")
val success: Boolean,
@SerialName("data")
val data: ProjectCycle?,
) {
@Serializable
data class ProjectCycle(
@SerialName("projectName")
val projectName: String,
@SerialName("projectReviewCycle")
val projectReviewCycle: String,
)
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.puzzling.puzzlingaos.data.repository

import android.util.Log
import com.puzzling.puzzlingaos.data.model.request.RequestInvitationCode
import com.puzzling.puzzlingaos.data.model.request.RequestProjectRegisterDto
import com.puzzling.puzzlingaos.data.model.response.ResponseInvitationCodeDto
import com.puzzling.puzzlingaos.data.model.response.ResponseProjectRegisterDto
import com.puzzling.puzzlingaos.data.model.response.ResponseProjectRetroWeekDto
import com.puzzling.puzzlingaos.data.source.remote.ProjectDataSource
import com.puzzling.puzzlingaos.domain.repository.ProjectRepository
import javax.inject.Inject
Expand All @@ -21,4 +24,19 @@ class ProjectRepositoryImpl @Inject constructor(
}.onFailure {
Log.d("register: ", "등록 실패")
}

override suspend fun joinProject(
memberId: Int,
request: RequestInvitationCode
): ResponseInvitationCodeDto {
return projectDataSource.joinProject(memberId, request)
}

override suspend fun isValidInvitationCode(invitationCode: String): ResponseInvitationCodeDto {
return projectDataSource.isValidInvitationCode(invitationCode)
}

override suspend fun getProjectWeekCycle(projectId: Int): ResponseProjectRetroWeekDto {
return projectDataSource.getProjectWeekCycle(projectId)
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package com.puzzling.puzzlingaos.data.service

import com.puzzling.puzzlingaos.data.model.request.RequestInvitationCode
import com.puzzling.puzzlingaos.data.model.request.RequestProjectRegisterDto
import com.puzzling.puzzlingaos.data.model.response.ResponseInvitationCodeDto
import com.puzzling.puzzlingaos.data.model.response.ResponseProjectRegisterDto
import com.puzzling.puzzlingaos.data.model.response.ResponseProjectRetroWeekDto
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Path
import retrofit2.http.Query

interface ProjectService {

Expand All @@ -13,4 +18,20 @@ interface ProjectService {
@Path("memberId") memberId: Int,
@Body request: RequestProjectRegisterDto,
): ResponseProjectRegisterDto

@POST("api/v1/member/{memberId}/project/join")
suspend fun joinProject(
@Path("memberId") memberId: Int,
@Body request: RequestInvitationCode,
): ResponseInvitationCodeDto

@GET("api/v1/project/verify?")
suspend fun isValidInvitationCode(
@Query("invitationCode") invitationCode: String,
): ResponseInvitationCodeDto

@GET("api/v1/project/{projectId}/cycle")
suspend fun getProjectWeekCycle(
@Path("projectId") projectId: Int,
): ResponseProjectRetroWeekDto
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
package com.puzzling.puzzlingaos.data.source.remote

import com.puzzling.puzzlingaos.data.model.request.RequestInvitationCode
import com.puzzling.puzzlingaos.data.model.request.RequestProjectRegisterDto
import com.puzzling.puzzlingaos.data.model.response.ResponseInvitationCodeDto
import com.puzzling.puzzlingaos.data.model.response.ResponseProjectRegisterDto
import com.puzzling.puzzlingaos.data.model.response.ResponseProjectRetroWeekDto

interface ProjectDataSource {
suspend fun projectRegister(
memberId: Int,
request: RequestProjectRegisterDto,
): ResponseProjectRegisterDto

suspend fun joinProject(
memberId: Int,
request: RequestInvitationCode,
): ResponseInvitationCodeDto

suspend fun isValidInvitationCode(
invitationCode: String,
): ResponseInvitationCodeDto

suspend fun getProjectWeekCycle(
projectId: Int,
): ResponseProjectRetroWeekDto
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.puzzling.puzzlingaos.data.source.remote.impl

import com.puzzling.puzzlingaos.data.model.request.RequestInvitationCode
import com.puzzling.puzzlingaos.data.model.request.RequestProjectRegisterDto
import com.puzzling.puzzlingaos.data.model.response.ResponseInvitationCodeDto
import com.puzzling.puzzlingaos.data.model.response.ResponseProjectRegisterDto
import com.puzzling.puzzlingaos.data.model.response.ResponseProjectRetroWeekDto
import com.puzzling.puzzlingaos.data.service.ProjectService
import com.puzzling.puzzlingaos.data.source.remote.ProjectDataSource
import javax.inject.Inject
Expand All @@ -15,4 +18,15 @@ class ProjectDataSourceImpl @Inject constructor(
request: RequestProjectRegisterDto,
): ResponseProjectRegisterDto =
apiService.projectRegister2(memberId, request)

override suspend fun joinProject(
memberId: Int,
request: RequestInvitationCode,
): ResponseInvitationCodeDto = apiService.joinProject(memberId, request)

override suspend fun isValidInvitationCode(invitationCode: String): ResponseInvitationCodeDto =
apiService.isValidInvitationCode(invitationCode)

override suspend fun getProjectWeekCycle(projectId: Int): ResponseProjectRetroWeekDto =
apiService.getProjectWeekCycle(projectId)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.puzzling.puzzlingaos.domain.repository

import com.puzzling.puzzlingaos.data.model.request.RequestInvitationCode
import com.puzzling.puzzlingaos.data.model.request.RequestProjectRegisterDto
import com.puzzling.puzzlingaos.data.model.response.ResponseInvitationCodeDto
import com.puzzling.puzzlingaos.data.model.response.ResponseProjectRegisterDto
import com.puzzling.puzzlingaos.data.model.response.ResponseProjectRetroWeekDto

interface ProjectRepository {

Expand All @@ -11,4 +14,17 @@ interface ProjectRepository {
memberId: Int,
request: RequestProjectRegisterDto,
): Result<ResponseProjectRegisterDto>

suspend fun joinProject(
memberId: Int,
request: RequestInvitationCode,
): ResponseInvitationCodeDto

suspend fun isValidInvitationCode(
invitationCode: String,
): ResponseInvitationCodeDto

suspend fun getProjectWeekCycle(
projectId: Int,
): ResponseProjectRetroWeekDto
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.lifecycle.viewModelScope
import com.puzzling.puzzlingaos.data.model.response.ResponseMyPageProjectDto
import com.puzzling.puzzlingaos.domain.entity.Project
import com.puzzling.puzzlingaos.domain.repository.MyBoardRepository
import com.puzzling.puzzlingaos.domain.repository.ProjectRepository
import com.puzzling.puzzlingaos.util.UserInfo
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
Expand All @@ -16,6 +17,7 @@ import javax.inject.Inject
@HiltViewModel
class HomeViewModel @Inject constructor(
private val repository: MyBoardRepository,
private val projectRepository: ProjectRepository
) : ViewModel() {

private var _projectList: MutableLiveData<List<Project>> = MutableLiveData()
Expand Down Expand Up @@ -48,6 +50,9 @@ class HomeViewModel @Inject constructor(
val selectedProjectName: LiveData<String>
get() = _selectedProjectName

private val _retroWeek = MutableLiveData<String>()
val retroWeek: LiveData<String> get() = _retroWeek

init {
_reviewCycleList.value = listOf("월", "수", "금")
_reviewCycleText.value = _reviewCycleList.value?.joinToString(separator = ",")
Expand All @@ -68,4 +73,15 @@ class HomeViewModel @Inject constructor(
Log.d("home", "_selectedProjectName.value :: ${_selectedProjectName.value}")
_isProjectNameSelected.value = true
}

fun getProjectWeekCycle() = viewModelScope.launch {
kotlin.runCatching {
projectRepository.getProjectWeekCycle(UserInfo.PROJECT_ID)
}.onSuccess { response ->
_retroWeek.value = response.data?.projectReviewCycle
Log.d("회고 주기", "$response")
}.onFailure {
Log.d("회고 주기", "$it")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import com.puzzling.puzzlingaos.R
import com.puzzling.puzzlingaos.base.BaseFragment
import com.puzzling.puzzlingaos.databinding.FragmentInputCodeBinding
import com.puzzling.puzzlingaos.util.ViewModelFactory
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch

@AndroidEntryPoint
class InputCodeFragment : BaseFragment<FragmentInputCodeBinding>(R.layout.fragment_input_code) {

lateinit var viewModel: InvitationCodeViewModel
Expand All @@ -20,7 +21,6 @@ class InputCodeFragment : BaseFragment<FragmentInputCodeBinding>(R.layout.fragme

viewModel = ViewModelProvider(
requireActivity(),
ViewModelFactory(requireContext()),
)[InvitationCodeViewModel::class.java]

binding.vm = viewModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import androidx.lifecycle.ViewModelProvider
import com.puzzling.puzzlingaos.R
import com.puzzling.puzzlingaos.base.BaseFragment
import com.puzzling.puzzlingaos.databinding.FragmentInputProfileBinding
import com.puzzling.puzzlingaos.presentation.team.currentSituation.TeamCurrentSituationViewModel
import com.puzzling.puzzlingaos.util.ViewModelFactory
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class InputProfileFragment :
BaseFragment<FragmentInputProfileBinding>(R.layout.fragment_input_profile) {

Expand All @@ -17,7 +20,6 @@ class InputProfileFragment :
super.onViewCreated(view, savedInstanceState)
viewModel = ViewModelProvider(
requireActivity(),
ViewModelFactory(requireContext()),
)[InvitationCodeViewModel::class.java]

binding.lifecycleOwner = viewLifecycleOwner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import com.puzzling.puzzlingaos.R
import com.puzzling.puzzlingaos.base.BaseActivity
import com.puzzling.puzzlingaos.databinding.ActivityInvitationCodeBinding
import com.puzzling.puzzlingaos.util.ViewModelFactory
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class InvitationCodeActivity :
BaseActivity<ActivityInvitationCodeBinding>(R.layout.activity_invitation_code) {

private val viewModel: InvitationCodeViewModel by viewModels { ViewModelFactory(this) }
private val viewModel by viewModels<InvitationCodeViewModel>()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package com.puzzling.puzzlingaos.presentation.invitationCode

import android.content.Context
import android.util.Log
import androidx.lifecycle.*
import com.puzzling.puzzlingaos.data.model.request.RequestInvitationCode
import com.puzzling.puzzlingaos.data.model.response.ResponseInvitationCodeDto
import com.puzzling.puzzlingaos.domain.repository.ProjectRepository
import com.puzzling.puzzlingaos.util.UserInfo.MEMBER_ID
import com.puzzling.puzzlingaos.util.UserInfo.PROJECT_ID
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
import javax.inject.Inject

class InvitationCodeViewModel(context: Context) : ViewModel() {
@HiltViewModel
class InvitationCodeViewModel @Inject constructor(private val repository: ProjectRepository) :
ViewModel() {

// inputCode 관련
val inputCode = MutableStateFlow("")
Expand Down Expand Up @@ -102,15 +109,31 @@ class InvitationCodeViewModel(context: Context) : ViewModel() {
}.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), true)

fun isCodeValid() = viewModelScope.launch {
// 서버 통신 추가 예정
_codeResponse.value = ResponseInvitationCodeDto.InvitationCodeData(4, "pickle")
_isCodeSucces.value = true
kotlin.runCatching {
repository.isValidInvitationCode(inputCode.value)
}.onSuccess { response ->
_isCodeSucces.value = true
_codeResponse.value = response.data
Log.d("초대코드", "$response")
}.onFailure {
_isCodeSucces.value = true
Log.d("초대코드", "$it")
}
}

fun joinProject() = viewModelScope.launch {
// 서버 통신 추가 예정
_isProfileSucces.value = true
Log.d("프로젝트 참여하기", "프로젝트 참여하기 ${_codeResponse.value?.projectName}")
kotlin.runCatching {
repository.joinProject(
MEMBER_ID,
RequestInvitationCode(PROJECT_ID, inputNickName.value, inputRole.value),
)
}.onSuccess { response ->
_isProfileSucces.value = true
Log.d("프로젝트 참여하기", "프로젝트 참여하기 $response")
}.onFailure {
_isProfileSucces.value = true
Log.d("프로젝트 참여하기", "$it")
}
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class MyPageFragment : BaseFragment<FragmentMyPageBinding>(R.layout.fragment_my_
super.onViewCreated(view, savedInstanceState)
viewModel = ViewModelProvider(requireActivity())[MyRetrospectViewModel::class.java]
viewModel.getMyProjectList()
viewModel.getProjectWeekCycle()
initAdapter()
showPopupMessage()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import com.puzzling.puzzlingaos.data.model.response.ResponseMyRetroListDto
import com.puzzling.puzzlingaos.domain.entity.Project
import com.puzzling.puzzlingaos.domain.repository.MyBoardRepository
import com.puzzling.puzzlingaos.domain.repository.MyPageRepository
import com.puzzling.puzzlingaos.domain.repository.ProjectRepository
import com.puzzling.puzzlingaos.util.UserInfo.PROJECT_ID
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject
Expand All @@ -17,6 +19,7 @@ import javax.inject.Inject
class MyRetrospectViewModel @Inject constructor(
private val myPageRepository: MyPageRepository,
private val myBoardRepository: MyBoardRepository,
private val projectRepository: ProjectRepository,
) :
ViewModel() {

Expand All @@ -30,6 +33,9 @@ class MyRetrospectViewModel @Inject constructor(
private val _currentProject = MutableLiveData<String>("프로젝트 이름")
val currentProject: LiveData<String> get() = _currentProject

private val _retroWeek = MutableLiveData<String>()
val retroWeek: LiveData<String> get() = _retroWeek

init {
getMyProjectReview()
}
Expand Down Expand Up @@ -59,4 +65,15 @@ class MyRetrospectViewModel @Inject constructor(
}
}
}

fun getProjectWeekCycle() = viewModelScope.launch {
kotlin.runCatching {
projectRepository.getProjectWeekCycle(PROJECT_ID)
}.onSuccess { response ->
_retroWeek.value = response.data?.projectReviewCycle
Log.d("회고 주기", "$response")
}.onFailure {
Log.d("회고 주기", "$it")
}
}
}
Loading
Loading