Skip to content

Commit

Permalink
feat: upload images before add place usecase service logic
Browse files Browse the repository at this point in the history
  • Loading branch information
KimDoubleB committed Aug 22, 2024
1 parent ce89da7 commit ac4c5ab
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package com.piikii.application.domain.place

import com.piikii.application.domain.generic.LongTypeId
import com.piikii.application.domain.generic.UuidTypeId
import com.piikii.application.domain.image.ImageFolderType
import com.piikii.application.port.input.PlaceUseCase
import com.piikii.application.port.input.dto.request.AddPlaceRequest
import com.piikii.application.port.input.dto.request.ModifyPlaceRequest
import com.piikii.application.port.input.dto.response.PlaceResponse
import com.piikii.application.port.input.dto.response.ScheduleTypeGroupResponse
import com.piikii.application.port.output.objectstorage.BucketFolderType
import com.piikii.application.port.output.objectstorage.ObjectStoragePort
import com.piikii.application.port.output.persistence.PlaceCommandPort
import com.piikii.application.port.output.persistence.PlaceQueryPort
Expand All @@ -32,25 +32,16 @@ class PlaceService(
override fun addPlace(
targetRoomUid: UuidTypeId,
addPlaceRequest: AddPlaceRequest,
placeImages: List<MultipartFile>?,
placeImageUrls: List<String>,
): List<PlaceResponse> {
val imageUrls =
placeImages?.let {
objectStoragePort.uploadAll(
bucketFolderType = BUCKET_TYPE,
multipartFiles = it,
).get()
} ?: listOf()

val room = roomQueryPort.findById(targetRoomUid)
val schedules = scheduleQueryPort.findAllByIds(addPlaceRequest.scheduleIds.map(::LongTypeId))

val places =
schedules.map { schedule ->
addPlaceRequest.toDomain(
roomUid = room.roomUid,
scheduleId = schedule.id,
imageUrls = imageUrls,
imageUrls = placeImageUrls,
)
}

Expand Down Expand Up @@ -83,7 +74,7 @@ class PlaceService(
val updatedUrls =
newPlaceImages?.let {
objectStoragePort.updateAllByUrls(
bucketFolderType = BUCKET_TYPE,
imageFolderType = BUCKET_TYPE,
deleteTargetUrls = modifyPlaceRequest.deleteTargetUrls,
newMultipartFiles = it,
).get()
Expand All @@ -107,7 +98,7 @@ class PlaceService(
@Transactional
override fun delete(targetPlaceId: LongTypeId) {
objectStoragePort.deleteAllByUrls(
bucketFolderType = BUCKET_TYPE,
imageFolderType = BUCKET_TYPE,
deleteTargetUrls = isPlaceNullOrGet(targetPlaceId).thumbnailLinks.convertToList,
)
placeCommandPort.delete(targetPlaceId)
Expand All @@ -128,6 +119,6 @@ class PlaceService(
}

companion object {
private val BUCKET_TYPE = BucketFolderType.PLACE
private val BUCKET_TYPE = ImageFolderType.PLACE
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface PlaceUseCase {
fun addPlace(
targetRoomUid: UuidTypeId,
addPlaceRequest: AddPlaceRequest,
placeImages: List<MultipartFile>?,
placeImageUrls: List<String>,
): List<PlaceResponse>

fun findAllByRoomUidGroupByPlaceType(roomUid: UuidTypeId): List<ScheduleTypeGroupResponse>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.piikii.input.http.controller

import com.piikii.application.domain.generic.LongTypeId
import com.piikii.application.domain.generic.UuidTypeId
import com.piikii.application.domain.image.ImageFolderType
import com.piikii.application.port.input.ImageUploadUseCase
import com.piikii.application.port.input.PlaceUseCase
import com.piikii.application.port.input.dto.request.AddPlaceRequest
import com.piikii.application.port.input.dto.request.ModifyPlaceRequest
Expand Down Expand Up @@ -31,6 +33,7 @@ import java.util.UUID
@RequestMapping("/v1/rooms/{roomUid}/places")
class PlaceApi(
private val placeUseCase: PlaceUseCase,
private val imageUploadUseCase: ImageUploadUseCase,
) : PlaceDocs {
@ResponseStatus(HttpStatus.CREATED)
@PostMapping(consumes = [MediaType.MULTIPART_FORM_DATA_VALUE])
Expand All @@ -39,7 +42,8 @@ class PlaceApi(
@Valid @NotNull @RequestPart addPlaceRequest: AddPlaceRequest,
@RequestPart(required = false) placeImages: List<MultipartFile>?,
): ResponseForm<List<PlaceResponse>> {
return ResponseForm(placeUseCase.addPlace(UuidTypeId(roomUid), addPlaceRequest, placeImages))
val placeImageUrls = imageUploadUseCase.upload(placeImages, ImageFolderType.PLACE)
return ResponseForm(placeUseCase.addPlace(UuidTypeId(roomUid), addPlaceRequest, placeImageUrls))
}

@GetMapping
Expand Down

0 comments on commit ac4c5ab

Please sign in to comment.