Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,17 @@ sealed interface ResumeRoute : Route {
@Serializable
data object AddWorkExperience : ResumeRoute

@Serializable
data class EditWorkExperience(val activityId: Long) : ResumeRoute

@Serializable
data object Activities : ResumeRoute

@Serializable
data object AddActivities : ResumeRoute

@Serializable
data class EditActivities(val activityId: Long) : ResumeRoute
}

sealed interface CertRecommendRoute : Route {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import org.sopt.certi.data.remote.dto.response.UserInfoResponseDto
import org.sopt.certi.domain.model.user.UserInfoData

fun UserInfoResponseDto.toDomain() = UserInfoData(
nickname = nickname,
name = name,
university = university,
major = major
major = major,
profileImageUrl = profileImage,
birthday = birthDate
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ interface ActivityRemoteDataSource {
): NullableApiResponse<Unit>
suspend fun getActivityList(): ApiResponse<GetActivityListResponseDto>
suspend fun deleteActivity(activityId: Long): NullableApiResponse<Unit>
suspend fun editActivity(activityId: Long, startAt: String, endAt: String, place: String, name: String, description: String): NullableApiResponse<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ interface CareerRemoteDataSource {
): NullableApiResponse<Unit>
suspend fun getCareerList(): ApiResponse<GetCareersResponseDto>
suspend fun deleteCareer(careerId: Long): NullableApiResponse<Unit>
suspend fun editCareer(careerId: Long, startAt: String, endAt: String, place: String, name: String, description: String): NullableApiResponse<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package org.sopt.certi.data.remote.datasourceimpl
import org.sopt.certi.data.remote.datasource.ActivityRemoteDataSource
import org.sopt.certi.data.remote.dto.base.ApiResponse
import org.sopt.certi.data.remote.dto.base.NullableApiResponse
import org.sopt.certi.data.remote.dto.request.AddActivityCareerRequestDto
import org.sopt.certi.data.remote.dto.request.ActivityCareerRequestDto
import org.sopt.certi.data.remote.dto.response.GetActivityListResponseDto
import org.sopt.certi.data.remote.service.ActivityService
import javax.inject.Inject
Expand All @@ -12,11 +12,14 @@ class ActivityRemoteDataSourceImpl @Inject constructor(
private val activityService: ActivityService
) : ActivityRemoteDataSource {
override suspend fun addActivity(startAt: String, endAt: String, place: String, name: String, description: String): NullableApiResponse<Unit> =
activityService.addActivity(addActivityRequest = AddActivityCareerRequestDto(startAt, endAt, place, name, description))
activityService.addActivity(addActivityRequest = ActivityCareerRequestDto(startAt, endAt, place, name, description))

override suspend fun getActivityList(): ApiResponse<GetActivityListResponseDto> =
activityService.getActivityList()

override suspend fun deleteActivity(activityId: Long): NullableApiResponse<Unit> =
activityService.deleteActivity(activityId)

override suspend fun editActivity(activityId: Long, startAt: String, endAt: String, place: String, name: String, description: String): NullableApiResponse<Unit> =
activityService.editActivity(activityId, ActivityCareerRequestDto(startAt, endAt, place, name, description))
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package org.sopt.certi.data.remote.datasourceimpl
import org.sopt.certi.data.remote.datasource.CareerRemoteDataSource
import org.sopt.certi.data.remote.dto.base.ApiResponse
import org.sopt.certi.data.remote.dto.base.NullableApiResponse
import org.sopt.certi.data.remote.dto.request.AddActivityCareerRequestDto
import org.sopt.certi.data.remote.dto.request.ActivityCareerRequestDto
import org.sopt.certi.data.remote.dto.response.GetCareersResponseDto
import org.sopt.certi.data.remote.service.CareerService
import javax.inject.Inject
Expand All @@ -12,7 +12,9 @@ class CareerRemoteDataSourceImpl @Inject constructor(
private val careerService: CareerService
) : CareerRemoteDataSource {
override suspend fun addCareer(startAt: String, endAt: String, place: String, name: String, description: String): NullableApiResponse<Unit> =
careerService.addCareers(addCareerRequest = AddActivityCareerRequestDto(startAt, endAt, place, name, description))
careerService.addCareers(addCareerRequest = ActivityCareerRequestDto(startAt, endAt, place, name, description))
override suspend fun getCareerList(): ApiResponse<GetCareersResponseDto> = careerService.getCareerList()
override suspend fun deleteCareer(careerId: Long): NullableApiResponse<Unit> = careerService.deleteCareer(careerId)
override suspend fun editCareer(careerId: Long, startAt: String, endAt: String, place: String, name: String, description: String): NullableApiResponse<Unit> =
careerService.editCareer(careerId, ActivityCareerRequestDto(startAt, endAt, place, name, description))
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class AddActivityCareerRequestDto(
data class ActivityCareerRequestDto(
@SerialName("startAt")
val startAt: String,
@SerialName("endAt")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ import kotlinx.serialization.Serializable
@Serializable
data class UserInfoResponseDto(
@SerialName("nickname")
val nickname: String,
@SerialName("name")
val name: String,
@SerialName("university")
val university: String,
@SerialName("major")
val major: String
val major: String,
@SerialName("profileImage")
val profileImage: String?,
@SerialName("birthDate")
val birthDate: String?
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ package org.sopt.certi.data.remote.service

import org.sopt.certi.data.remote.dto.base.ApiResponse
import org.sopt.certi.data.remote.dto.base.NullableApiResponse
import org.sopt.certi.data.remote.dto.request.AddActivityCareerRequestDto
import org.sopt.certi.data.remote.dto.request.ActivityCareerRequestDto
import retrofit2.http.Body
import retrofit2.http.POST
import org.sopt.certi.data.remote.dto.response.GetActivityListResponseDto
import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.PUT
import retrofit2.http.Path

interface ActivityService {
@POST("/api/v1/activity")
suspend fun addActivity(
@Body addActivityRequest: AddActivityCareerRequestDto
@Body addActivityRequest: ActivityCareerRequestDto
): NullableApiResponse<Unit>

@GET("/api/v1/activity")
Expand All @@ -23,4 +24,10 @@ interface ActivityService {
suspend fun deleteActivity(
@Path("activity-id") activityId: Long
): NullableApiResponse<Unit>

@PUT("/api/v1/activity/{activity-id}")
suspend fun editActivity(
@Path("activity-id") activityId: Long,
@Body editActivityRequest: ActivityCareerRequestDto
): NullableApiResponse<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ package org.sopt.certi.data.remote.service

import org.sopt.certi.data.remote.dto.base.ApiResponse
import org.sopt.certi.data.remote.dto.base.NullableApiResponse
import org.sopt.certi.data.remote.dto.request.AddActivityCareerRequestDto
import org.sopt.certi.data.remote.dto.request.ActivityCareerRequestDto
import retrofit2.http.Body
import retrofit2.http.POST
import org.sopt.certi.data.remote.dto.response.GetCareersResponseDto
import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.PUT
import retrofit2.http.Path

interface CareerService {
@POST("/api/v1/careers")
suspend fun addCareers(
@Body addCareerRequest: AddActivityCareerRequestDto
@Body addCareerRequest: ActivityCareerRequestDto
): NullableApiResponse<Unit>

@GET("/api/v1/careers")
Expand All @@ -23,4 +24,10 @@ interface CareerService {
suspend fun deleteCareer(
@Path("career-id") careerId: Long
): NullableApiResponse<Unit>

@PUT("/api/v1/careers/{career-id}")
suspend fun editCareer(
@Path("career-id") careerId: Long,
@Body editCareerRequest: ActivityCareerRequestDto
): NullableApiResponse<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,10 @@ class ActivityRepositoryImpl @Inject constructor(
.handleNullableApiResponse()
.getOrThrow()
}

override suspend fun editActivity(activityId: Long, startAt: String, endAt: String, place: String, name: String, description: String): Result<Unit> = safeApiCall {
activityRemoteDataSource.editActivity(activityId, startAt, endAt, place, name, description)
.handleNullableApiResponse()
.getOrThrow()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,10 @@ class CareerRepositoryImpl @Inject constructor(
.handleNullableApiResponse()
.getOrThrow()
}

override suspend fun editCareer(careerId: Long, startAt: String, endAt: String, place: String, name: String, description: String): Result<Unit> = safeApiCall {
careerRemoteDataSource.editCareer(careerId, startAt, endAt, place, name, description)
.handleNullableApiResponse()
.getOrThrow()
}
}
14 changes: 14 additions & 0 deletions app/src/main/java/org/sopt/certi/di/UseCaseModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ import org.sopt.certi.domain.usecase.acquisition.AcquiredCertUseCase
import org.sopt.certi.domain.usecase.acquisition.DeleteAcquisitionUseCase
import org.sopt.certi.domain.usecase.acquisition.GetAcquisitionDetailUseCase
import org.sopt.certi.domain.usecase.activity.DeleteActivityUseCase
import org.sopt.certi.domain.usecase.activity.EditActivityUseCase
import org.sopt.certi.domain.usecase.career.DeleteCareerUseCase
import org.sopt.certi.domain.usecase.career.EditCareerUseCase
import org.sopt.certi.domain.usecase.certification.GetJobCertListUseCase
import org.sopt.certi.domain.usecase.certification.GetCertInfoUseCase
import org.sopt.certi.domain.usecase.certification.GetRecommendCertListUseCase
Expand Down Expand Up @@ -164,6 +166,12 @@ object UseCaseModule {
careerRepository: CareerRepository
): AddCareerUseCase = AddCareerUseCase(careerRepository)

@Provides
@Singleton
fun provideEditCareerUseCase(
careerRepository: CareerRepository
): EditCareerUseCase = EditCareerUseCase(careerRepository)

@Provides
@Singleton
fun provideGetAcquisitionListUseCase(
Expand Down Expand Up @@ -200,6 +208,12 @@ object UseCaseModule {
activityRepository: ActivityRepository
): AddActivityUseCase = AddActivityUseCase(activityRepository)

@Provides
@Singleton
fun provideEditActivityUseCase(
activityRepository: ActivityRepository
): EditActivityUseCase = EditActivityUseCase(activityRepository)

@Provides
@Singleton
fun providePreCertEditUseCase(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ data class UserInfoData(
val major: String = "",
val category: List<String> = emptyList<String>(),
val track: String = "",
val birthday: String = "",
val birthday: String? = null,
val profileImageUrl: String? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ interface ActivityRepository {
): Result<Unit>
suspend fun getActivityList(): Result<List<ActivityData>>
suspend fun deleteActivity(activityId: Long): Result<Unit>
suspend fun editActivity(activityId: Long, startAt: String, endAt: String, place: String, name: String, description: String): Result<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ interface CareerRepository {
): Result<Unit>
suspend fun getCareerList(): Result<List<ActivityData>>
suspend fun deleteCareer(careerId: Long): Result<Unit>
suspend fun editCareer(careerId: Long, startAt: String, endAt: String, place: String, name: String, description: String): Result<Unit>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.sopt.certi.domain.usecase.activity

import org.sopt.certi.domain.repository.ActivityRepository

class EditActivityUseCase(
private val activityRepository: ActivityRepository
) {
suspend operator fun invoke(
activityId: Long,
startAt: String,
endAt: String,
place: String,
name: String,
description: String
): Result<Unit> = activityRepository.editActivity(activityId, startAt, endAt, place, name, description)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.sopt.certi.domain.usecase.career

import org.sopt.certi.domain.repository.CareerRepository

class EditCareerUseCase(
private val careerRepository: CareerRepository
) {
suspend operator fun invoke(
careerId: Long,
startAt: String,
endAt: String,
place: String,
name: String,
description: String
): Result<Unit> = careerRepository.editCareer(careerId, startAt, endAt, place, name, description)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package org.sopt.certi.presentation.ui.activity

import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import org.sopt.certi.domain.usecase.activity.EditActivityUseCase
import org.sopt.certi.domain.usecase.activity.GetActivityListUseCase
import org.sopt.certi.presentation.ui.activity.state.AddActivityUiState
import javax.inject.Inject

@HiltViewModel
class EditActivitiesViewModel @Inject constructor(
private val getActivityListUseCase: GetActivityListUseCase,
private val editActivityUseCase: EditActivityUseCase,
savedStateHandle: SavedStateHandle
) : ViewModel() {

private val activityId: Long = checkNotNull(savedStateHandle["activityId"])

private val _startDate = MutableStateFlow("")
private val _endDate = MutableStateFlow("")
private val _organizationValue = MutableStateFlow("")
private val _activityValue = MutableStateFlow("")
private val _descriptionValue = MutableStateFlow("")

private val _editActivitySuccess = MutableStateFlow(false)
val editActivitySuccess: StateFlow<Boolean> = _editActivitySuccess

val addActivityUiState: StateFlow<AddActivityUiState> =
combine(
_startDate,
_endDate,
_organizationValue,
_activityValue,
_descriptionValue
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[3] 이거 combine 최대 5개 아닌가여 더 늘어나면 어케여

) { startDate, endDate, organization, activity, description ->
AddActivityUiState(
startDate = startDate,
endDate = endDate,
organizationValue = organization,
activityValue = activity,
descriptionValue = description,
addButtonEnabled = listOf(startDate, endDate, organization, activity, description).all { it.isNotBlank() }
)
}.stateIn(
scope = viewModelScope,
started = SharingStarted.WhileSubscribed(5_000),
initialValue = AddActivityUiState("", "", "", "", "", false)
)

init {
loadInitial()
}

private fun loadInitial() {
viewModelScope.launch {
getActivityListUseCase.invoke().fold(
onSuccess = { list ->
val item = list.find { it.activityId == activityId }
if (item != null) {
_startDate.value = item.startAt
_endDate.value = item.endAt
_organizationValue.value = item.organization
_activityValue.value = item.role /* 또는 name/activityValue 필드에 맞게 */
_descriptionValue.value = item.description
}
},
onFailure = { }
)
}
}

fun onStartDateChanged(value: String) { _startDate.value = value }
fun onEndDateChanged(value: String) { _endDate.value = value }
fun onOrganizationChanged(value: String) { _organizationValue.value = value }
fun onActivityChanged(value: String) { _activityValue.value = value }
fun onDescriptionChanged(value: String) { _descriptionValue.value = value }

fun editActivity() {
viewModelScope.launch {
editActivityUseCase(
activityId = activityId,
startAt = _startDate.value,
endAt = _endDate.value,
place = _organizationValue.value,
name = _activityValue.value,
description = _descriptionValue.value
).fold(
onSuccess = { _editActivitySuccess.value = true },
onFailure = { _editActivitySuccess.value = false }
)
}
}

fun resetEditActivitySuccess() {
_editActivitySuccess.value = false
}
}
Loading