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

refactor: 서술형 문제 수정/생성에서 gradingStandard 제거 #176

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
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
@@ -1,14 +1,10 @@
package io.csbroker.apiserver.dto.problem.longproblem

import io.csbroker.apiserver.dto.user.GradingStandardResponseDto

data class LongProblemResponseDto(
val id: Long,
val title: String,
val description: String,
val standardAnswers: List<String>,
val tags: List<String>,
val gradingStandards: List<GradingStandardResponseDto>,
val isActive: Boolean,
val isGradable: Boolean,
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.csbroker.apiserver.dto.problem.longproblem

import io.csbroker.apiserver.common.enums.GradingStandardType
import io.csbroker.apiserver.model.GradingStandard
import io.csbroker.apiserver.model.LongProblem
import io.csbroker.apiserver.model.User

Expand All @@ -10,33 +8,14 @@ data class LongProblemUpsertRequestDto(
val description: String,
val standardAnswers: List<String>,
val tags: List<String>,
val gradingStandards: List<GradingStandardData>,
val isGradable: Boolean = false,
val isActive: Boolean = true,
) {

data class GradingStandardData(
val content: String,
val score: Double,
val type: GradingStandardType,
)

fun toLongProblem(creator: User): LongProblem {
return LongProblem(
title = title,
description = description,
creator = creator,
)
}

fun getGradingStandardList(longProblem: LongProblem): List<GradingStandard> {
return gradingStandards.map {
GradingStandard(
content = it.content,
score = it.score,
type = it.type,
problem = longProblem,
)
}
}
}

This file was deleted.

4 changes: 0 additions & 4 deletions src/main/kotlin/io/csbroker/apiserver/model/LongProblem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import io.csbroker.apiserver.dto.problem.longproblem.LongProblemDetailResponseDt
import io.csbroker.apiserver.dto.problem.longproblem.LongProblemResponseDto
import io.csbroker.apiserver.dto.problem.longproblem.LongProblemSearchResponseDto.LongProblemDataDto
import io.csbroker.apiserver.dto.problem.longproblem.LongProblemUpsertRequestDto
import io.csbroker.apiserver.dto.user.GradingStandardResponseDto
import jakarta.persistence.CascadeType
import jakarta.persistence.DiscriminatorValue
import jakarta.persistence.Entity
Expand Down Expand Up @@ -43,7 +42,6 @@ class LongProblem(
fun updateFromDto(upsertRequestDto: LongProblemUpsertRequestDto) {
title = upsertRequestDto.title
description = upsertRequestDto.description
isGradable = upsertRequestDto.isGradable
isActive = upsertRequestDto.isActive
updateStandardAnswers(upsertRequestDto.standardAnswers)
}
Expand All @@ -55,9 +53,7 @@ class LongProblem(
description,
standardAnswers.map { it.content },
problemTags.map { it.tag.name },
gradingStandards.map { GradingStandardResponseDto.fromGradingStandard(it) },
isActive,
isGradable,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ import io.csbroker.apiserver.dto.problem.longproblem.LongProblemSearchResponseDt
import io.csbroker.apiserver.dto.problem.longproblem.LongProblemUpsertRequestDto
import io.csbroker.apiserver.model.StandardAnswer
import io.csbroker.apiserver.model.User
import io.csbroker.apiserver.repository.problem.GradingStandardRepository
import io.csbroker.apiserver.repository.problem.LongProblemRepository
import io.csbroker.apiserver.repository.problem.ProblemRepository
import io.csbroker.apiserver.repository.problem.StandardAnswerRepository
import io.csbroker.apiserver.repository.user.UserRepository
import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
Expand All @@ -21,8 +19,6 @@ import org.springframework.transaction.annotation.Transactional
class AdminLongProblemServiceImpl(
private val longProblemRepository: LongProblemRepository,
private val problemRepository: ProblemRepository,
private val userRepository: UserRepository,
private val gradingStandardRepository: GradingStandardRepository,
private val tagUpserter: TagUpserter,
private val standardAnswerRepository: StandardAnswerRepository,
) : AdminLongProblemService {
Expand All @@ -47,8 +43,6 @@ class AdminLongProblemServiceImpl(
@Transactional
override fun createProblem(createRequestDto: LongProblemUpsertRequestDto, user: User): Long {
val longProblem = createRequestDto.toLongProblem(user)
val gradingStandardList = createRequestDto.getGradingStandardList(longProblem)
longProblem.addGradingStandards(gradingStandardList)

val savedProblem = problemRepository.save(longProblem)
tagUpserter.setTags(savedProblem, createRequestDto.tags)
Expand All @@ -69,12 +63,6 @@ class AdminLongProblemServiceImpl(
override fun updateProblem(id: Long, updateRequestDto: LongProblemUpsertRequestDto): Long {
val longProblem = longProblemRepository.findByIdOrNull(id)
?: throw EntityNotFoundException("${id}번 문제는 존재하지 않는 서술형 문제입니다.")
val gradingStandardList = updateRequestDto.getGradingStandardList(longProblem)

if (longProblem.gradingStandards.map { it.content }.toSet() != gradingStandardList.map { it.content }.toSet()) {
gradingStandardRepository.deleteAllById(longProblem.gradingStandards.map { it.id })
longProblem.addGradingStandards(gradingStandardList)
}

longProblem.updateFromDto(updateRequestDto)
tagUpserter.updateTags(longProblem, updateRequestDto.tags.toMutableList())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class AdminLongProblemControllerIntegrationTest : IntegrationTest() {
description = "This is a test problem",
tags = mutableListOf(),
standardAnswers = listOf("업데이트될 모범 답안"),
gradingStandards = mutableListOf(),
)

// when
Expand Down Expand Up @@ -61,7 +60,6 @@ class AdminLongProblemControllerIntegrationTest : IntegrationTest() {
description = longProblem.description,
tags = mutableListOf(newTag1.name, newTag2.name),
standardAnswers = emptyList(),
gradingStandards = mutableListOf(),
)

// when
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package io.csbroker.apiserver.controller.v1.admin.problem

import io.csbroker.apiserver.common.enums.GradingStandardType
import io.csbroker.apiserver.controller.RestDocsTest
import io.csbroker.apiserver.dto.problem.longproblem.LongProblemResponseDto
import io.csbroker.apiserver.dto.problem.longproblem.LongProblemSearchResponseDto
import io.csbroker.apiserver.dto.problem.longproblem.LongProblemUpsertRequestDto
import io.csbroker.apiserver.dto.user.GradingStandardResponseDto
import io.csbroker.apiserver.service.problem.admin.AdminLongProblemService
import io.mockk.every
import io.mockk.mockk
Expand Down Expand Up @@ -62,16 +60,6 @@ class AdminLongProblemControllerTest : RestDocsTest() {
.description("모범 답안"),
fieldWithPath("tags").type(JsonFieldType.ARRAY)
.description("태그"),
fieldWithPath("gradingStandards").type(JsonFieldType.ARRAY)
.description("채점기준"),
fieldWithPath("gradingStandards.[].content")
.type(JsonFieldType.STRING).description("채점기준 내용"),
fieldWithPath("gradingStandards.[].score")
.type(JsonFieldType.NUMBER).description("채점기준 점수"),
fieldWithPath("gradingStandards.[].type")
.type(JsonFieldType.STRING).description("채점기준 타입 ( 'KEYWORD' or 'CONTENT' )"),
fieldWithPath("isGradable")
.type(JsonFieldType.BOOLEAN).description("채점 가능 여부 ( 필수 x, 기본 값 false )"),
fieldWithPath("isActive")
.type(JsonFieldType.BOOLEAN).description("활성화 여부 ( 필수 x, 기본 값 true )"),
),
Expand Down Expand Up @@ -114,16 +102,6 @@ class AdminLongProblemControllerTest : RestDocsTest() {
.description("모범 답안"),
fieldWithPath("tags").type(JsonFieldType.ARRAY)
.description("태그"),
fieldWithPath("gradingStandards").type(JsonFieldType.ARRAY)
.description("채점기준"),
fieldWithPath("gradingStandards.[].content")
.type(JsonFieldType.STRING).description("채점기준 내용"),
fieldWithPath("gradingStandards.[].score")
.type(JsonFieldType.NUMBER).description("채점기준 점수"),
fieldWithPath("gradingStandards.[].type")
.type(JsonFieldType.STRING).description("채점기준 타입 ( 'KEYWORD' or 'CONTENT' )"),
fieldWithPath("isGradable")
.type(JsonFieldType.BOOLEAN).description("채점 가능 여부"),
fieldWithPath("isActive")
.type(JsonFieldType.BOOLEAN).description("활성화 여부"),
),
Expand All @@ -146,16 +124,7 @@ class AdminLongProblemControllerTest : RestDocsTest() {
standardAnswers = listOf("answer"),
description = "description",
tags = listOf("tag1", "tag2"),
gradingStandards = listOf(
GradingStandardResponseDto(
id = 1L,
content = "content",
score = 1.0,
type = GradingStandardType.KEYWORD,
),
),
isActive = true,
isGradable = true,
)

// when
Expand Down Expand Up @@ -184,18 +153,6 @@ class AdminLongProblemControllerTest : RestDocsTest() {
.description("모범 답안"),
fieldWithPath("data.tags").type(JsonFieldType.ARRAY)
.description("태그"),
fieldWithPath("data.gradingStandards").type(JsonFieldType.ARRAY)
.description("채점기준"),
fieldWithPath("data.gradingStandards.[].id")
.type(JsonFieldType.NUMBER).description("채점기준 ID"),
fieldWithPath("data.gradingStandards.[].content")
.type(JsonFieldType.STRING).description("채점기준 내용"),
fieldWithPath("data.gradingStandards.[].score")
.type(JsonFieldType.NUMBER).description("채점기준 점수"),
fieldWithPath("data.gradingStandards.[].type")
.type(JsonFieldType.STRING).description("채점기준 타입 ( 'KEYWORD' or 'CONTENT' )"),
fieldWithPath("data.isGradable")
.type(JsonFieldType.BOOLEAN).description("채점 가능 여부"),
fieldWithPath("data.isActive")
.type(JsonFieldType.BOOLEAN).description("활성화 여부"),
),
Expand Down Expand Up @@ -289,12 +246,5 @@ class AdminLongProblemControllerTest : RestDocsTest() {
"test",
listOf("test"),
listOf("db", "network"),
listOf(
LongProblemUpsertRequestDto.GradingStandardData(
"keyword-1",
1.0,
GradingStandardType.KEYWORD,
),
),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.jayway.jsonpath.JsonPath
import io.csbroker.apiserver.controller.IntegrationTest
import io.csbroker.apiserver.controller.v2.problem.response.SubmitLongProblemResponseDto
import io.csbroker.apiserver.dto.problem.longproblem.LongProblemAnswerDto
import io.csbroker.apiserver.model.GradingHistory
import io.csbroker.apiserver.model.LongProblem
import io.csbroker.apiserver.model.StandardAnswer
import io.kotest.matchers.collections.shouldContain
Expand Down Expand Up @@ -44,17 +43,6 @@ class LongProblemIntegrationTest : IntegrationTest() {
fun `서술형 문제 제출`() {
val problem = getProblem()

// given & when
val preSubmissionCount = findAll<GradingHistory>(
"SELECT gh From GradingHistory gh where gh.problem.id = :id",
mapOf("id" to problem.id),
).size

val preUserSubmissionCount = findAll<GradingHistory>(
"SELECT gh From GradingHistory gh where gh.problem.id = :problemId AND gh.user.id = :userId",
mapOf("problemId" to problem.id, "userId" to defaultUser.id!!),
).size

val standardAnswers = findAll<StandardAnswer>(
"SELECT sa From StandardAnswer sa where sa.longProblem.id = :id",
mapOf("id" to problem.id),
Expand All @@ -77,8 +65,6 @@ class LongProblemIntegrationTest : IntegrationTest() {
val responseDto = objectMapper.readValue<SubmitLongProblemResponseDto>(dataAsString)
responseDto.title shouldBe problem.title
responseDto.description shouldBe problem.description
responseDto.totalSubmission shouldBe preSubmissionCount + 1 // 제출 수가 증가하는지 확인
responseDto.userSubmission shouldBe preUserSubmissionCount + 1 // 제출 수가 증가하는지 확인
responseDto.userAnswer shouldBe userAnswer
standardAnswers.map { sa -> sa.content } shouldContain responseDto.standardAnswer // 모법답안중 하나가 반환되는지 확인
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ class AdminLongProblemServiceTest {
adminLongProblemService = AdminLongProblemServiceImpl(
longProblemRepository,
problemRepository,
userRepository,
gradingStandardRepository,
tagUpserter,
standardAnswerRepository,
)
Expand Down Expand Up @@ -105,7 +103,6 @@ class AdminLongProblemServiceTest {
description = "This is a test problem",
tags = listOf("tag 1", "tag 2"),
standardAnswers = emptyList(),
gradingStandards = emptyList(),
)
}
}