Skip to content

Commit 67f4e51

Browse files
authored
[YS-306] fix: 공고 수정 시 nullable 필드 및 이미지 생성 버그 수정 (#96)
* fix: fix for update logics for changing TSID id strategy and nullable fields * fix: define request dto in presentation layer * fix: add idGenerator to newly added updateImages * fix: change nullable to non-nullable for busniess rules
1 parent 650ada1 commit 67f4e51

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

src/main/kotlin/com/dobby/backend/application/usecase/experiment/UpdateExperimentPostUseCase.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.dobby.backend.application.usecase.experiment
22

33
import com.dobby.backend.application.usecase.UseCase
4+
import com.dobby.backend.domain.IdGenerator
45
import com.dobby.backend.domain.exception.*
56
import com.dobby.backend.domain.gateway.experiment.ExperimentPostGateway
67
import com.dobby.backend.domain.model.experiment.ExperimentPost
@@ -12,7 +13,8 @@ import com.dobby.backend.infrastructure.database.entity.enums.areaInfo.Region
1213
import java.time.LocalDate
1314

1415
class UpdateExperimentPostUseCase (
15-
private val experimentPostGateway: ExperimentPostGateway
16+
private val experimentPostGateway: ExperimentPostGateway,
17+
private val idGenerator: IdGenerator
1618
) : UseCase<UpdateExperimentPostUseCase.Input, UpdateExperimentPostUseCase.Output> {
1719
data class Input(
1820
val experimentPostId: String,
@@ -104,7 +106,8 @@ class UpdateExperimentPostUseCase (
104106
univName = input.univName,
105107
region = input.region,
106108
area = input.area,
107-
imageListInfo = input.imageListInfo?.images
109+
imageListInfo = input.imageListInfo?.images,
110+
idGenerator = idGenerator
108111
)
109112
val updatedPost = experimentPostGateway.save(experimentPost)
110113

src/main/kotlin/com/dobby/backend/domain/model/experiment/ExperimentPost.kt

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.dobby.backend.domain.model.experiment
22

3+
import com.dobby.backend.domain.IdGenerator
34
import com.dobby.backend.domain.exception.ExperimentPostImageSizeException
45
import com.dobby.backend.domain.exception.ExperimentPostInvalidOnlineRequestException
56
import com.dobby.backend.domain.model.member.Member
@@ -69,12 +70,18 @@ data class ExperimentPost(
6970
univName: String?,
7071
region: Region?,
7172
area: Area?,
72-
imageListInfo: List<String>?
73+
imageListInfo: List<String>?,
74+
idGenerator: IdGenerator
7375
): ExperimentPost {
74-
val updatedImages = imageListInfo?.map { imageUrl ->
75-
val existingImage = this.images.find { it.imageUrl == imageUrl }
76-
existingImage ?: ExperimentImage(id = "0", experimentPost = this, imageUrl = imageUrl)
77-
} ?: this.images
76+
val existingImageUrls = this.images.map { it.imageUrl }.toSet()
77+
val newImages = imageListInfo?.filter { it !in existingImageUrls }?.map { imageUrl ->
78+
ExperimentImage(
79+
id = idGenerator.generateId(),
80+
experimentPost = this,
81+
imageUrl = imageUrl
82+
)
83+
} ?: emptyList()
84+
val updatedImages = this.images.toMutableList().apply { addAll(newImages) }
7885

7986
return this.copy(
8087
targetGroup = targetGroup ?: this.targetGroup,
@@ -88,9 +95,9 @@ data class ExperimentPost(
8895
leadResearcher = leadResearcher ?: this.leadResearcher,
8996
detailedAddress = detailedAddress ?: this.detailedAddress,
9097
matchType = matchType ?: this.matchType,
91-
univName = univName ?: this.univName,
92-
region = region ?: this.region,
93-
area = area ?: this.area,
98+
univName = univName,
99+
region = region,
100+
area = area,
94101
images = updatedImages.toMutableList(),
95102
updatedAt = LocalDateTime.now()
96103
).apply { validate() }

src/main/kotlin/com/dobby/backend/presentation/api/dto/request/experiment/UpdateExperimentPostRequest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ data class UpdateExperimentPostRequest (
1717
val count: Int, // N 회 참여
1818
val timeRequired: TimeSlot?,
1919

20-
val leadResearcher: String, // 연구 책임 정보 -> 기본값: 연구자 정보에서 끌어와야 함, 추후에 자유롭게 수정 가능
20+
val leadResearcher: String?, // 연구 책임 정보 -> 기본값: 연구자 정보에서 끌어와야 함, 추후에 자유롭게 수정 가능
2121

22-
val univName: String, // 대학교 이름 -> 기본값: 연구자 정보에서 끌어와야 함, 추후에 자유롭게 수정 가능
23-
val region: Region,
24-
val area: Area,
22+
val univName: String?, // 대학교 이름 -> 기본값: 연구자 정보에서 끌어와야 함, 추후에 자유롭게 수정 가능
23+
val region: Region?,
24+
val area: Area?,
2525
val detailedAddress: String?,
2626

2727
val reward: String,

0 commit comments

Comments
 (0)