Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into feat/#462
Browse files Browse the repository at this point in the history
# Conflicts:
#	backend/src/main/java/com/festago/presentation/AuthController.java
  • Loading branch information
xxeol2 committed Oct 5, 2023
2 parents d4a0c7b + 59da4a1 commit c9de21b
Show file tree
Hide file tree
Showing 82 changed files with 604 additions and 303 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import kotlinx.serialization.Serializable

@Serializable
data class SendVerificationRequest(
val userName: String,
val schoolId: Int,
val username: String,
val schoolId: Long,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.festago.festago.data.dto

import com.festago.festago.model.StudentVerificationCode
import kotlinx.serialization.Serializable

@Serializable
data class VerificationRequest(
val code: String,
) {
companion object {
fun from(code: StudentVerificationCode) = VerificationRequest(code.value)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.festago.festago.data.repository

import com.festago.festago.data.dto.SendVerificationRequest
import com.festago.festago.data.dto.VerificationRequest
import com.festago.festago.data.service.StudentVerificationRetrofitService
import com.festago.festago.data.util.runCatchingWithErrorHandler
import com.festago.festago.model.StudentVerificationCode
import com.festago.festago.repository.StudentVerificationRepository
import javax.inject.Inject
Expand All @@ -10,12 +13,18 @@ class StudentVerificationDefaultRepository @Inject constructor(
) : StudentVerificationRepository {

override suspend fun sendVerificationCode(userName: String, schoolId: Long): Result<Unit> {
// TODO: API 연동 작업 필요
return Result.success(Unit)
studentVerificationRetrofitService.sendVerificationCode(
SendVerificationRequest(userName, schoolId),
).runCatchingWithErrorHandler()
.getOrElse { error -> return Result.failure(error) }
.let { return Result.success(Unit) }
}

override suspend fun requestVerificationCodeConfirm(code: StudentVerificationCode): Result<Unit> {
// TODO: API 연동 작업 필요
return Result.success(Unit)
studentVerificationRetrofitService.requestVerification(
VerificationRequest.from(code),
).runCatchingWithErrorHandler()
.getOrElse { error -> return Result.failure(error) }
.let { return Result.success(Unit) }
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.festago.festago.data.service

import com.festago.festago.data.dto.SendVerificationRequest
import com.festago.festago.data.dto.VerificationRequest
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.POST
Expand All @@ -10,4 +11,9 @@ interface StudentVerificationRetrofitService {
suspend fun sendVerificationCode(
@Body sendVerificationRequest: SendVerificationRequest,
): Response<Unit>

@POST("/students/verification")
suspend fun requestVerification(
@Body verificationRequest: VerificationRequest,
): Response<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ class SelectSchoolActivity : AppCompatActivity() {
}

private fun initObserve() {
repeatOnStarted {
repeatOnStarted(this) {
vm.uiState.collect { uiState ->
handleUiState(uiState)
}
}
repeatOnStarted {
repeatOnStarted(this) {
vm.event.collect { event ->
handleEvent(event)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ class SelectSchoolViewModel @Inject constructor(
viewModelScope.launch {
schoolRepository.loadSchools()
.onSuccess { schools ->
if (uiState.value is SelectSchoolUiState.Success) {
val successState = (uiState.value as SelectSchoolUiState.Success)
_uiState.value = successState.copy(schools = schools)
val state = uiState.value
if (state is SelectSchoolUiState.Success) {
_uiState.value = state.copy(schools = schools)
} else {
_uiState.value = SelectSchoolUiState.Success(schools)
}
Expand All @@ -46,20 +46,18 @@ class SelectSchoolViewModel @Inject constructor(
}

fun selectSchool(schoolId: Long) {
if (uiState.value is SelectSchoolUiState.Success) {
_uiState.value =
(uiState.value as SelectSchoolUiState.Success).copy(selectedSchoolId = schoolId)
val state = uiState.value
if (state is SelectSchoolUiState.Success) {
_uiState.value = state.copy(selectedSchoolId = schoolId)
}
}

fun showStudentVerification() {
viewModelScope.launch {
if (uiState.value is SelectSchoolUiState.Success) {
val success = uiState.value as SelectSchoolUiState.Success
success.selectedSchoolId?.let { schoolId ->
_event.emit(
SelectSchoolEvent.ShowStudentVerification(schoolId)
)
val state = uiState.value
if (state is SelectSchoolUiState.Success) {
state.selectedSchoolId?.let { schoolId ->
_event.emit(SelectSchoolEvent.ShowStudentVerification(schoolId))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import com.festago.festago.R
import com.festago.festago.databinding.ActivityStudentVerificationBinding
import com.festago.festago.presentation.ui.customview.OkDialogFragment
import com.festago.festago.presentation.ui.home.HomeActivity
import com.festago.festago.presentation.util.repeatOnStarted
import dagger.hilt.android.AndroidEntryPoint
import java.time.LocalTime
Expand Down Expand Up @@ -42,17 +44,17 @@ class StudentVerificationActivity : AppCompatActivity() {

private fun initRequestVerificationCodeBtn(schoolId: Long) {
binding.btnRequestVerificationCode.setOnClickListener {
vm.sendVerificationCode(binding.tieVerificationCode.text.toString(), schoolId)
vm.sendVerificationCode(binding.tieUserName.text.toString(), schoolId)
}
}

private fun initObserve() {
repeatOnStarted {
repeatOnStarted(this) {
vm.uiState.collect { uiState ->
handleUiState(uiState)
}
}
repeatOnStarted {
repeatOnStarted(this) {
vm.event.collect { event ->
handleEvent(event)
}
Expand All @@ -62,8 +64,9 @@ class StudentVerificationActivity : AppCompatActivity() {
private fun handleUiState(uiState: StudentVerificationUiState) {
binding.uiState = uiState
when (uiState) {
is StudentVerificationUiState.Loading -> Unit
is StudentVerificationUiState.Success -> handleSuccess(uiState)
is StudentVerificationUiState.Loading, StudentVerificationUiState.Error -> Unit
is StudentVerificationUiState.Error -> Unit
}
}

Expand All @@ -81,15 +84,31 @@ class StudentVerificationActivity : AppCompatActivity() {

private fun handleEvent(event: StudentVerificationEvent) {
when (event) {
is StudentVerificationEvent.VerificationSuccess -> Unit
is StudentVerificationEvent.VerificationFailure -> Unit
is StudentVerificationEvent.CodeTimeOut -> Unit
is StudentVerificationEvent.VerificationSuccess -> handleVerificationSuccess()
is StudentVerificationEvent.VerificationFailure -> showDialog(FAILURE_VERIFICATION)
is StudentVerificationEvent.VerificationTimeOut -> showDialog(TIME_OUT_VERIFICATION)
is StudentVerificationEvent.SendingEmailFailure -> showDialog(FAILURE_SENDING_EMAIL)
}
}

companion object {
private fun handleVerificationSuccess() {
val intent = HomeActivity.getIntent(this).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_SINGLE_TOP)
}
finishAffinity()
startActivity(intent)
}

private fun showDialog(message: String) {
val dialog = OkDialogFragment.newInstance(message)
dialog.show(supportFragmentManager, OkDialogFragment::class.java.name)
}

companion object {
private const val KEY_SCHOOL_ID = "KEY_SCHOOL_ID"
private const val FAILURE_VERIFICATION = "인증에 실패하였습니다"
private const val TIME_OUT_VERIFICATION = "인증 시간이 만료되었습니다"
private const val FAILURE_SENDING_EMAIL = "이메일 입력을 확인해주세요"

fun getIntent(context: Context, schoolId: Long): Intent {
return Intent(context, StudentVerificationActivity::class.java).apply {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.festago.festago.presentation.ui.studentverification

sealed interface StudentVerificationEvent {
object CodeTimeOut : StudentVerificationEvent
object VerificationTimeOut : StudentVerificationEvent
object VerificationFailure : StudentVerificationEvent
object VerificationSuccess : StudentVerificationEvent
object SendingEmailFailure : StudentVerificationEvent
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class StudentVerificationViewModel @Inject constructor(
setTimer()
}
.onFailure {
_event.emit(StudentVerificationEvent.SendingEmailFailure)
analyticsHelper.logNetworkFailure(
KEY_SEND_VERIFICATION_CODE_LOG,
it.message.toString(),
Expand Down Expand Up @@ -129,7 +130,7 @@ class StudentVerificationViewModel @Inject constructor(
val state = uiState.value as? StudentVerificationUiState.Success ?: return@launch

if (state.remainTime == MIN_REMAIN_TIME) {
_event.emit(StudentVerificationEvent.CodeTimeOut)
_event.emit(StudentVerificationEvent.VerificationTimeOut)
return@launch
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import kotlinx.coroutines.launch

fun LifecycleOwner.repeatOnStarted(action: suspend () -> Unit) {
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
fun repeatOnStarted(lifecycleOwner: LifecycleOwner, action: suspend () -> Unit) {
lifecycleOwner.lifecycleScope.launch {
lifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
action()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/student_verification_btn_student_verification"
android:textSize="12sp"
android:textStyle="bold"
app:layout_constraintEnd_toStartOf="@+id/glEnd"
app:layout_constraintTop_toBottomOf="@+id/tilEmail" />

Expand Down Expand Up @@ -110,13 +112,13 @@
android:id="@+id/tvTimerVerificationCode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:layout_marginEnd="12dp"
android:textColor="@color/md_theme_light_primary"
android:textSize="20sp"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="@id/glEnd"
app:layout_constraintTop_toBottomOf="@id/tilVerificationCode"
app:layout_constraintBottom_toBottomOf="@+id/btnRequestVerificationCode"
app:layout_constraintEnd_toStartOf="@+id/btnRequestVerificationCode"
app:layout_constraintTop_toTopOf="@+id/btnRequestVerificationCode"
tools:text="00:24" />

<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ class StudentVerificationViewModelTest {
`인증 코드를 확인하면`()

// then
assertThat(awaitItem()).isEqualTo(StudentVerificationEvent.CodeTimeOut)
assertThat(awaitItem()).isEqualTo(StudentVerificationEvent.VerificationTimeOut)
cancelAndIgnoreRemainingEvents()
}
}
Expand Down
12 changes: 12 additions & 0 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,24 @@ dependencies {
// Mockito
testImplementation 'org.mockito:mockito-inline'

// Cucumber
testImplementation 'io.cucumber:cucumber-java:7.13.0'
testImplementation 'io.cucumber:cucumber-spring:7.13.0'
testImplementation 'io.cucumber:cucumber-junit-platform-engine:7.13.0'
testImplementation 'org.junit.platform:junit-platform-suite:1.8.2'

// Flyway
implementation 'org.flywaydb:flyway-core'
implementation 'org.flywaydb:flyway-mysql'

// Firebase
implementation 'com.google.firebase:firebase-admin:8.1.0'

// Lombok
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testCompileOnly 'org.projectlombok:lombok'
testAnnotationProcessor 'org.projectlombok:lombok'
}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,20 @@
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Transactional
@Service
@RequiredArgsConstructor
public class AdminService {

private final FestivalRepository festivalRepository;
private final StageRepository stageRepository;
private final TicketRepository ticketRepository;
private final SchoolRepository schoolRepository;

public AdminService(FestivalRepository festivalRepository, StageRepository stageRepository,
TicketRepository ticketRepository,
SchoolRepository schoolRepository) {
this.festivalRepository = festivalRepository;
this.stageRepository = stageRepository;
this.ticketRepository = ticketRepository;
this.schoolRepository = schoolRepository;
}

@Transactional(readOnly = true)
public AdminResponse getAdminResponse() {
List<School> allSchool = schoolRepository.findAll();
Expand Down
6 changes: 3 additions & 3 deletions backend/src/main/java/com/festago/admin/domain/Admin.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

@Entity
@Table(
Expand All @@ -17,6 +19,7 @@
)
}
)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Admin extends BaseTimeEntity {

@Id
Expand All @@ -27,9 +30,6 @@ public class Admin extends BaseTimeEntity {

private String password;

protected Admin() {
}

public Admin(String username, String password) {
this(null, username, password);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,20 @@
import com.festago.common.exception.ForbiddenException;
import com.festago.common.exception.UnauthorizedException;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
@RequiredArgsConstructor
public class AdminAuthService {

private static final String ROOT_ADMIN = "admin";

private final AuthProvider authProvider;
private final AdminRepository adminRepository;

public AdminAuthService(AuthProvider authProvider, AdminRepository adminRepository) {
this.authProvider = authProvider;
this.adminRepository = adminRepository;
}

@Transactional(readOnly = true)
public String login(AdminLoginRequest request) {
Admin admin = findAdmin(request);
Expand Down
Loading

0 comments on commit c9de21b

Please sign in to comment.