Skip to content

Commit

Permalink
feat: 데이터 일괄 삭제
Browse files Browse the repository at this point in the history
  • Loading branch information
DongGeon0908 committed Aug 30, 2024
1 parent e0264b8 commit 03f02c7
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package com.hero.alignlab.domain.dev.application
import com.hero.alignlab.common.extension.executes
import com.hero.alignlab.config.database.TransactionTemplates
import com.hero.alignlab.domain.dev.model.request.DevPoseSnapshotRequest
import com.hero.alignlab.domain.pose.application.PoseSnapshotService
import com.hero.alignlab.domain.group.application.GroupUserScoreService
import com.hero.alignlab.domain.pose.application.*
import com.hero.alignlab.domain.pose.domain.PoseSnapshot
import com.hero.alignlab.domain.pose.domain.vo.PoseType
import com.hero.alignlab.domain.pose.model.PoseSnapshotModel
Expand All @@ -15,8 +16,13 @@ import java.math.BigDecimal
import java.time.temporal.ChronoUnit

@Service
class DevPoseSnapshotService(
class DevPoseService(
private val poseSnapshotService: PoseSnapshotService,
private val groupUserScoreService: GroupUserScoreService,
private val poseCountService: PoseCountService,
private val poseKeyPointSnapshotService: PoseKeyPointSnapshotService,
private val poseLayoutService: PoseLayoutService,
private val poseLayoutPointService: PoseLayoutPointService,
private val txTemplates: TransactionTemplates,
private val publisher: ApplicationEventPublisher,
) {
Expand Down Expand Up @@ -159,4 +165,13 @@ class DevPoseSnapshotService(
imageUrl = null
)
}

suspend fun deleteAllPoseData() {
groupUserScoreService.deleteAll()
poseCountService.deleteAll()
poseKeyPointSnapshotService.deleteAll()
poseLayoutService.deleteAll()
poseLayoutPointService.deleteAll()
poseSnapshotService.deleteAll()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.hero.alignlab.domain.dev.resource
import com.hero.alignlab.common.extension.wrapVoid
import com.hero.alignlab.config.dev.DevResourceCheckConfig.Companion.devResource
import com.hero.alignlab.config.swagger.SwaggerTag.DEV_TAG
import com.hero.alignlab.domain.dev.application.DevPoseSnapshotService
import com.hero.alignlab.domain.dev.application.DevPoseService
import com.hero.alignlab.domain.dev.model.request.DevPoseSnapshotRequest
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
Expand All @@ -13,15 +13,23 @@ import org.springframework.web.bind.annotation.*
@Tag(name = DEV_TAG)
@RestController
@RequestMapping(produces = [MediaType.APPLICATION_JSON_VALUE])
class DevPoseSnapshotResource(
private val devPoseSnapshotService: DevPoseSnapshotService,
class DevPoseResource(
private val devPoseService: DevPoseService,
) {
@Operation(summary = "[DEV] 포즈 스냅샷 생성")
@PostMapping("/api/dev/v1/pose-snapshots")
suspend fun createPoseSnapshots(
@RequestHeader("X-HERO-DEV-TOKEN") token: String,
@RequestBody request: DevPoseSnapshotRequest,
) = devResource(token) {
devPoseSnapshotService.create(request).wrapVoid()
devPoseService.create(request).wrapVoid()
}

@Operation(summary = "[DEV] 포즈 데이터 삭제")
@DeleteMapping("/api/dev/v1/pose-snapshots/{id}")
suspend fun deletePoseSnapshots(
@RequestHeader("X-HERO-DEV-TOKEN") token: String,
) = devResource(token) {
devPoseService.deleteAllPoseData()
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.hero.alignlab.domain.group.application

import com.hero.alignlab.common.extension.coExecuteOrNull
import com.hero.alignlab.config.database.TransactionTemplates
import com.hero.alignlab.domain.group.domain.GroupUserScore
import com.hero.alignlab.domain.group.infrastructure.GroupUserScoreRepository
import kotlinx.coroutines.Dispatchers
Expand All @@ -10,6 +12,7 @@ import org.springframework.transaction.annotation.Transactional
@Service
class GroupUserScoreService(
private val groupUserScoreRepository: GroupUserScoreRepository,
private val txTemplates: TransactionTemplates,
) {
suspend fun findAllByGroupId(groupId: Long): List<GroupUserScore> {
return withContext(Dispatchers.IO) {
Expand Down Expand Up @@ -48,4 +51,10 @@ class GroupUserScoreService(
fun findAllByGroupIdAndUidsSync(groupId: Long, uids: List<Long>): List<GroupUserScore> {
return groupUserScoreRepository.findAllByGroupIdAndUidIn(groupId, uids)
}

suspend fun deleteAll() {
txTemplates.writer.coExecuteOrNull {
groupUserScoreRepository.deleteAllInBatch()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.hero.alignlab.domain.pose.application

import com.hero.alignlab.common.extension.coExecuteOrNull
import com.hero.alignlab.common.model.HeroPageRequest
import com.hero.alignlab.config.database.TransactionTemplates
import com.hero.alignlab.domain.auth.model.AuthUser
import com.hero.alignlab.domain.pose.domain.PoseCount
import com.hero.alignlab.domain.pose.infrastructure.PoseCountRepository
Expand All @@ -18,6 +20,7 @@ import java.time.LocalDate
@Service
class PoseCountService(
private val poseCountRepository: PoseCountRepository,
private val txTemplates: TransactionTemplates,
) {
@Transactional
fun saveSync(poseCount: PoseCount): PoseCount {
Expand Down Expand Up @@ -82,4 +85,10 @@ class PoseCountService(
poseCountRepository.findAllByUidIn(uids)
}
}

suspend fun deleteAll() {
txTemplates.writer.coExecuteOrNull {
poseCountRepository.deleteAllInBatch()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.hero.alignlab.domain.pose.application

import com.hero.alignlab.common.extension.coExecuteOrNull
import com.hero.alignlab.config.database.TransactionTemplates
import com.hero.alignlab.domain.pose.domain.PoseKeyPointSnapshot
import com.hero.alignlab.domain.pose.infrastructure.PoseKeyPointSnapshotRepository
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
Expand All @@ -11,6 +13,7 @@ import org.springframework.transaction.annotation.Transactional
class PoseKeyPointSnapshotService(
private val heroNamedParameterJdbcTemplate: NamedParameterJdbcTemplate,
private val poseKeyPointSnapshotRepository: PoseKeyPointSnapshotRepository,
private val txTemplates: TransactionTemplates,
) {
@Transactional
fun bulkSave(poseKeyPointSnapshots: List<PoseKeyPointSnapshot>) {
Expand All @@ -28,4 +31,10 @@ class PoseKeyPointSnapshotService(
fun saveAllSync(poseKeyPointSnapshots: List<PoseKeyPointSnapshot>): List<PoseKeyPointSnapshot> {
return poseKeyPointSnapshotRepository.saveAll(poseKeyPointSnapshots)
}

suspend fun deleteAll() {
txTemplates.writer.coExecuteOrNull {
poseKeyPointSnapshotRepository.deleteAllInBatch()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.hero.alignlab.domain.pose.application

import com.hero.alignlab.common.extension.coExecuteOrNull
import com.hero.alignlab.config.database.TransactionTemplates
import com.hero.alignlab.domain.pose.domain.PoseLayoutPoint
import com.hero.alignlab.domain.pose.infrastructure.PoseLayoutPointRepository
import kotlinx.coroutines.Dispatchers
Expand All @@ -10,6 +12,7 @@ import org.springframework.transaction.annotation.Transactional
@Service
class PoseLayoutPointService(
private val poseLayoutPointRepository: PoseLayoutPointRepository,
private val txTemplates: TransactionTemplates,
) {
suspend fun findAllByPoseLayoutId(poseLayoutPointId: Long): List<PoseLayoutPoint> {
return withContext(Dispatchers.IO) {
Expand All @@ -21,4 +24,10 @@ class PoseLayoutPointService(
fun saveAllSync(poseLayoutPoints: List<PoseLayoutPoint>): List<PoseLayoutPoint> {
return poseLayoutPointRepository.saveAll(poseLayoutPoints)
}

suspend fun deleteAll() {
txTemplates.writer.coExecuteOrNull {
poseLayoutPointRepository.deleteAllInBatch()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.hero.alignlab.domain.pose.application

import com.hero.alignlab.common.extension.coExecuteOrNull
import com.hero.alignlab.config.database.TransactionTemplates
import com.hero.alignlab.domain.pose.domain.PoseLayout
import com.hero.alignlab.domain.pose.infrastructure.PoseLayoutRepository
import com.hero.alignlab.exception.ErrorCode
Expand All @@ -11,7 +13,8 @@ import org.springframework.transaction.annotation.Transactional

@Service
class PoseLayoutService(
private val poseLayoutRepository: PoseLayoutRepository
private val poseLayoutRepository: PoseLayoutRepository,
private val txTemplates: TransactionTemplates,
) {
suspend fun findTop1ByUidOrderByIdDesc(uid: Long): PoseLayout? {
return withContext(Dispatchers.IO) {
Expand All @@ -33,4 +36,10 @@ class PoseLayoutService(
fun saveSync(poseLayout: PoseLayout): PoseLayout {
return poseLayoutRepository.save(poseLayout)
}

suspend fun deleteAll() {
txTemplates.writer.coExecuteOrNull {
poseLayoutRepository.deleteAllInBatch()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.hero.alignlab.domain.pose.application

import com.hero.alignlab.common.extension.coExecuteOrNull
import com.hero.alignlab.config.database.TransactionTemplates
import com.hero.alignlab.domain.pose.domain.PoseSnapshot
import com.hero.alignlab.domain.pose.infrastructure.PoseSnapshotRepository
import com.hero.alignlab.domain.pose.infrastructure.model.PoseTypeCountModel
Expand All @@ -12,6 +14,7 @@ import java.time.LocalDate
@Service
class PoseSnapshotService(
private val poseSnapshotRepository: PoseSnapshotRepository,
private val txTemplates: TransactionTemplates,
) {
@Transactional
fun saveSync(poseSnapshot: PoseSnapshot): PoseSnapshot {
Expand All @@ -23,4 +26,10 @@ class PoseSnapshotService(
poseSnapshotRepository.countByUidsAndDate(uids, date)
}
}

suspend fun deleteAll() {
txTemplates.writer.coExecuteOrNull {
poseSnapshotRepository.deleteAllInBatch()
}
}
}

0 comments on commit 03f02c7

Please sign in to comment.