Commit 785624a5 authored by Ghitha Dinan's avatar Ghitha Dinan

delete add check data application

parent 1856ab60
......@@ -11,3 +11,7 @@ const val VALIDATOR_MSG_NOT_FOUND = "tidak di temukan"
const val VALIDATOR_MSG_DUPLICATE = "Data sudah ada di database"
const val VALIDATOR_MSG_NOT_HAVE_ACCESS = "tidak mempunyai hak akses"
const val VALIDATOR_MSG_DELETE_RELATION = "Data tidak dapat di hapus."
const val VALIDATOR_MSG_REQUEST_FAILED = "Gagal melakukan request data"
......@@ -45,7 +45,7 @@ class ApplicationCategoryController {
}
@DeleteMapping(value = [""], produces = ["application/json"])
fun deleteData(@Valid @RequestBody request: DeleteDataRequest): ResponseEntity<*>? {
return service.deleteData(request)
fun deleteData(@Valid @RequestBody request: DeleteDataRequest, httpServletRequest: HttpServletRequest): ResponseEntity<*>? {
return service.deleteData(request, httpServletRequest)
}
}
......@@ -8,6 +8,7 @@ import id.co.sangkuriang.inovasi.daerah.master.service.ProvinceService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*
import javax.servlet.http.HttpServletRequest
import javax.validation.Valid
@RestController
......@@ -43,7 +44,7 @@ class ProvinceController {
}
@DeleteMapping(value = [""], produces = ["application/json"])
fun deleteData(@Valid @RequestBody request: DeleteDataRequest): ResponseEntity<*>? {
return service.deleteData(request)
fun deleteData(@Valid @RequestBody request: DeleteDataRequest, httpServletRequest: HttpServletRequest): ResponseEntity<*>? {
return service.deleteData(request, httpServletRequest)
}
}
......@@ -7,6 +7,7 @@ import id.co.sangkuriang.inovasi.daerah.master.service.RegencyService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*
import javax.servlet.http.HttpServletRequest
import javax.validation.Valid
@RestController
......@@ -37,7 +38,7 @@ class RegencyController {
}
@DeleteMapping(value = [""], produces = ["application/json"])
fun deleteData(@Valid @RequestBody request: DeleteDataRequest): ResponseEntity<*>? {
return service.deleteData(request)
fun deleteData(@Valid @RequestBody request: DeleteDataRequest, httpServletRequest: HttpServletRequest): ResponseEntity<*>? {
return service.deleteData(request, httpServletRequest)
}
}
......@@ -20,7 +20,7 @@ interface ApplicationCategoryService {
httpServletRequest: HttpServletRequest
): ResponseEntity<*>?
fun deleteData(request: DeleteDataRequest): ResponseEntity<*>?
fun deleteData(request: DeleteDataRequest, httpServletRequest: HttpServletRequest): ResponseEntity<*>?
fun count(): ResponseEntity<*>?
}
......@@ -5,6 +5,7 @@ import id.co.sangkuriang.inovasi.daerah.master.model.request.Pagination2Request
import id.co.sangkuriang.inovasi.daerah.master.model.request.PaginationRequest
import id.co.sangkuriang.inovasi.daerah.master.pojo.Province
import org.springframework.http.ResponseEntity
import javax.servlet.http.HttpServletRequest
interface ProvinceService {
......@@ -16,7 +17,7 @@ interface ProvinceService {
fun updateData(id: String, request: Province): ResponseEntity<*>?
fun deleteData(request: DeleteDataRequest): ResponseEntity<*>?
fun deleteData(request: DeleteDataRequest, httpServletRequest: HttpServletRequest): ResponseEntity<*>?
fun datatable(req: Pagination2Request): ResponseEntity<*>?
......
......@@ -4,6 +4,7 @@ import id.co.sangkuriang.inovasi.daerah.master.model.request.DeleteDataRequest
import id.co.sangkuriang.inovasi.daerah.master.model.request.PaginationRequest
import id.co.sangkuriang.inovasi.daerah.master.pojo.Regency
import org.springframework.http.ResponseEntity
import javax.servlet.http.HttpServletRequest
interface RegencyService {
......@@ -15,5 +16,5 @@ interface RegencyService {
fun updateData(id: String, request: Regency): ResponseEntity<*>?
fun deleteData(request: DeleteDataRequest): ResponseEntity<*>?
fun deleteData(request: DeleteDataRequest, httpServletRequest: HttpServletRequest): ResponseEntity<*>?
}
package id.co.sangkuriang.inovasi.daerah.master.service.impl
import id.co.sangkuriang.inovasi.daerah.master.constant.UPLOAD_ICON_APPLICATION_CATEGORY_DIR
import id.co.sangkuriang.inovasi.daerah.master.constant.UPLOAD_IMAGE_APPLICATION_CATEGORY_DIR
import id.co.sangkuriang.inovasi.daerah.master.constant.VALIDATOR_MSG_HAS_USED
import id.co.sangkuriang.inovasi.daerah.master.constant.*
import id.co.sangkuriang.inovasi.daerah.master.exception.BadRequestException
import id.co.sangkuriang.inovasi.daerah.master.helpers.responseCreated
import id.co.sangkuriang.inovasi.daerah.master.helpers.responseNotFound
import id.co.sangkuriang.inovasi.daerah.master.helpers.responseSuccess
import id.co.sangkuriang.inovasi.daerah.master.helpers.*
import id.co.sangkuriang.inovasi.daerah.master.model.request.ApplicationCategoryRequest
import id.co.sangkuriang.inovasi.daerah.master.model.request.DeleteDataRequest
import id.co.sangkuriang.inovasi.daerah.master.model.request.PaginationRequest
import id.co.sangkuriang.inovasi.daerah.master.model.response.ReturnData
import id.co.sangkuriang.inovasi.daerah.master.pojo.ApplicationCategory
import id.co.sangkuriang.inovasi.daerah.master.repository.ApplicationCategoryRepository
import id.co.sangkuriang.inovasi.daerah.master.service.ApplicationCategoryService
......@@ -29,6 +26,8 @@ import javax.servlet.http.HttpServletRequest
@Service
class ApplicationCategoryServiceImpl : ApplicationCategoryService {
private val title = "Kategori Aplikasi"
@Autowired
private lateinit var repo: ApplicationCategoryRepository
......@@ -122,10 +121,27 @@ class ApplicationCategoryServiceImpl : ApplicationCategoryService {
}
}
override fun deleteData(request: DeleteDataRequest): ResponseEntity<*>? {
override fun deleteData(request: DeleteDataRequest, httpServletRequest: HttpServletRequest): ResponseEntity<*>? {
try {
val data = repo.findByIdAndActive(request.id)
if (data.isPresent) {
val checkApplication: ReturnData =
RequestHelpers.applicationCountByParam(
httpServletRequest.getHeader(HEADER_STRING),
"applicationCategoryId",
data.get().id
) as ReturnData
if (checkApplication.success == true) {
if (checkApplication.data != null) {
val countUserApplication: Long = (checkApplication.data as Int).toLong()
if (countUserApplication > 0) {
return responseBadRequest("$VALIDATOR_MSG_DELETE_RELATION $title ${data.get().name} mempunyai $countUserApplication data aplikasi")
}
}
} else {
return responseBadRequest("$VALIDATOR_MSG_REQUEST_FAILED Aplikasi")
}
val update = data.get()
update.updatedAt = Date()
update.active = false
......@@ -141,7 +157,7 @@ class ApplicationCategoryServiceImpl : ApplicationCategoryService {
override fun count(): ResponseEntity<*>? {
return try {
responseSuccess(data = repo.getCount())
} catch (e : Exception) {
} catch (e: Exception) {
throw e
}
}
......
package id.co.sangkuriang.inovasi.daerah.master.service.impl
import id.co.sangkuriang.inovasi.daerah.master.constant.HEADER_STRING
import id.co.sangkuriang.inovasi.daerah.master.constant.VALIDATOR_MSG_DELETE_RELATION
import id.co.sangkuriang.inovasi.daerah.master.constant.VALIDATOR_MSG_HAS_USED
import id.co.sangkuriang.inovasi.daerah.master.constant.VALIDATOR_MSG_REQUEST_FAILED
import id.co.sangkuriang.inovasi.daerah.master.exception.BadRequestException
import id.co.sangkuriang.inovasi.daerah.master.helpers.responseCreated
import id.co.sangkuriang.inovasi.daerah.master.helpers.responseNotFound
import id.co.sangkuriang.inovasi.daerah.master.helpers.responseSuccess
import id.co.sangkuriang.inovasi.daerah.master.helpers.*
import id.co.sangkuriang.inovasi.daerah.master.model.request.DeleteDataRequest
import id.co.sangkuriang.inovasi.daerah.master.model.request.Pagination2Request
import id.co.sangkuriang.inovasi.daerah.master.model.request.PaginationRequest
import id.co.sangkuriang.inovasi.daerah.master.model.response.ReturnData
import id.co.sangkuriang.inovasi.daerah.master.pojo.Province
import id.co.sangkuriang.inovasi.daerah.master.repository.ProvinceRepository
import id.co.sangkuriang.inovasi.daerah.master.repository.native.ProvinceRepositoryNative
......@@ -20,11 +22,14 @@ import org.springframework.data.domain.Sort
import org.springframework.http.ResponseEntity
import org.springframework.stereotype.Service
import java.util.*
import javax.servlet.http.HttpServletRequest
@Suppress("NAME_SHADOWING")
@Service
class ProvinceServiceImpl : ProvinceService {
private val title = "Provinsi"
@Autowired
private lateinit var repo: ProvinceRepository
......@@ -77,7 +82,7 @@ class ProvinceServiceImpl : ProvinceService {
override fun count(): ResponseEntity<*>? {
return try {
responseSuccess(data = repo.getCount())
} catch (e : Exception) {
} catch (e: Exception) {
throw e
}
}
......@@ -123,10 +128,27 @@ class ProvinceServiceImpl : ProvinceService {
}
}
override fun deleteData(request: DeleteDataRequest): ResponseEntity<*>? {
override fun deleteData(request: DeleteDataRequest, httpServletRequest: HttpServletRequest): ResponseEntity<*>? {
try {
val data = repo.findByIdAndActive(request.id)
if (data.isPresent) {
val checkApplication: ReturnData =
RequestHelpers.applicationCountByParam(
httpServletRequest.getHeader(HEADER_STRING),
"provinceId",
data.get().id
) as ReturnData
if (checkApplication.success == true) {
if (checkApplication.data != null) {
val countUserApplication: Long = (checkApplication.data as Int).toLong()
if (countUserApplication > 0) {
return responseBadRequest("$VALIDATOR_MSG_DELETE_RELATION $title ${data.get().name} mempunyai $countUserApplication data aplikasi")
}
}
} else {
return responseBadRequest("$VALIDATOR_MSG_REQUEST_FAILED Aplikasi")
}
val update = data.get()
update.active = false
update.updatedAt = Date()
......
package id.co.sangkuriang.inovasi.daerah.master.service.impl
import id.co.sangkuriang.inovasi.daerah.master.constant.HEADER_STRING
import id.co.sangkuriang.inovasi.daerah.master.constant.VALIDATOR_MSG_DELETE_RELATION
import id.co.sangkuriang.inovasi.daerah.master.constant.VALIDATOR_MSG_HAS_USED
import id.co.sangkuriang.inovasi.daerah.master.constant.VALIDATOR_MSG_REQUEST_FAILED
import id.co.sangkuriang.inovasi.daerah.master.exception.BadRequestException
import id.co.sangkuriang.inovasi.daerah.master.helpers.responseCreated
import id.co.sangkuriang.inovasi.daerah.master.helpers.responseNotFound
import id.co.sangkuriang.inovasi.daerah.master.helpers.responseSuccess
import id.co.sangkuriang.inovasi.daerah.master.helpers.*
import id.co.sangkuriang.inovasi.daerah.master.model.request.DeleteDataRequest
import id.co.sangkuriang.inovasi.daerah.master.model.request.PaginationRequest
import id.co.sangkuriang.inovasi.daerah.master.model.response.ReturnData
import id.co.sangkuriang.inovasi.daerah.master.pojo.Regency
import id.co.sangkuriang.inovasi.daerah.master.repository.RegencyRepository
import id.co.sangkuriang.inovasi.daerah.master.service.RegencyService
......@@ -18,11 +20,14 @@ import org.springframework.data.domain.Sort
import org.springframework.http.ResponseEntity
import org.springframework.stereotype.Service
import java.util.*
import javax.servlet.http.HttpServletRequest
@Suppress("NAME_SHADOWING")
@Service
class RegencyServiceImpl : RegencyService {
private val title = "Kabupaten/Kota"
@Autowired
private lateinit var repo: RegencyRepository
......@@ -91,10 +96,27 @@ class RegencyServiceImpl : RegencyService {
}
}
override fun deleteData(request: DeleteDataRequest): ResponseEntity<*>? {
override fun deleteData(request: DeleteDataRequest, httpServletRequest: HttpServletRequest): ResponseEntity<*>? {
try {
val data = repo.findByIdAndActive(request.id)
if (data.isPresent) {
val checkApplication: ReturnData =
RequestHelpers.applicationCountByParam(
httpServletRequest.getHeader(HEADER_STRING),
"regencyId",
data.get().id
) as ReturnData
if (checkApplication.success == true) {
if (checkApplication.data != null) {
val countUserApplication: Long = (checkApplication.data as Int).toLong()
if (countUserApplication > 0) {
return responseBadRequest("$VALIDATOR_MSG_DELETE_RELATION $title ${data.get().name} mempunyai $countUserApplication data aplikasi")
}
}
} else {
return responseBadRequest("$VALIDATOR_MSG_REQUEST_FAILED Aplikasi")
}
val update = data.get()
update.active = false
update.updatedAt = Date()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment