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" ...@@ -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_DUPLICATE = "Data sudah ada di database"
const val VALIDATOR_MSG_NOT_HAVE_ACCESS = "tidak mempunyai hak akses" 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 { ...@@ -45,7 +45,7 @@ class ApplicationCategoryController {
} }
@DeleteMapping(value = [""], produces = ["application/json"]) @DeleteMapping(value = [""], produces = ["application/json"])
fun deleteData(@Valid @RequestBody request: DeleteDataRequest): ResponseEntity<*>? { fun deleteData(@Valid @RequestBody request: DeleteDataRequest, httpServletRequest: HttpServletRequest): ResponseEntity<*>? {
return service.deleteData(request) return service.deleteData(request, httpServletRequest)
} }
} }
...@@ -8,6 +8,7 @@ import id.co.sangkuriang.inovasi.daerah.master.service.ProvinceService ...@@ -8,6 +8,7 @@ import id.co.sangkuriang.inovasi.daerah.master.service.ProvinceService
import org.springframework.beans.factory.annotation.Autowired import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.ResponseEntity import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.* import org.springframework.web.bind.annotation.*
import javax.servlet.http.HttpServletRequest
import javax.validation.Valid import javax.validation.Valid
@RestController @RestController
...@@ -43,7 +44,7 @@ class ProvinceController { ...@@ -43,7 +44,7 @@ class ProvinceController {
} }
@DeleteMapping(value = [""], produces = ["application/json"]) @DeleteMapping(value = [""], produces = ["application/json"])
fun deleteData(@Valid @RequestBody request: DeleteDataRequest): ResponseEntity<*>? { fun deleteData(@Valid @RequestBody request: DeleteDataRequest, httpServletRequest: HttpServletRequest): ResponseEntity<*>? {
return service.deleteData(request) return service.deleteData(request, httpServletRequest)
} }
} }
...@@ -7,6 +7,7 @@ import id.co.sangkuriang.inovasi.daerah.master.service.RegencyService ...@@ -7,6 +7,7 @@ import id.co.sangkuriang.inovasi.daerah.master.service.RegencyService
import org.springframework.beans.factory.annotation.Autowired import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.ResponseEntity import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.* import org.springframework.web.bind.annotation.*
import javax.servlet.http.HttpServletRequest
import javax.validation.Valid import javax.validation.Valid
@RestController @RestController
...@@ -37,7 +38,7 @@ class RegencyController { ...@@ -37,7 +38,7 @@ class RegencyController {
} }
@DeleteMapping(value = [""], produces = ["application/json"]) @DeleteMapping(value = [""], produces = ["application/json"])
fun deleteData(@Valid @RequestBody request: DeleteDataRequest): ResponseEntity<*>? { fun deleteData(@Valid @RequestBody request: DeleteDataRequest, httpServletRequest: HttpServletRequest): ResponseEntity<*>? {
return service.deleteData(request) return service.deleteData(request, httpServletRequest)
} }
} }
...@@ -20,7 +20,7 @@ interface ApplicationCategoryService { ...@@ -20,7 +20,7 @@ interface ApplicationCategoryService {
httpServletRequest: HttpServletRequest httpServletRequest: HttpServletRequest
): ResponseEntity<*>? ): ResponseEntity<*>?
fun deleteData(request: DeleteDataRequest): ResponseEntity<*>? fun deleteData(request: DeleteDataRequest, httpServletRequest: HttpServletRequest): ResponseEntity<*>?
fun count(): ResponseEntity<*>? fun count(): ResponseEntity<*>?
} }
...@@ -5,6 +5,7 @@ import id.co.sangkuriang.inovasi.daerah.master.model.request.Pagination2Request ...@@ -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.model.request.PaginationRequest
import id.co.sangkuriang.inovasi.daerah.master.pojo.Province import id.co.sangkuriang.inovasi.daerah.master.pojo.Province
import org.springframework.http.ResponseEntity import org.springframework.http.ResponseEntity
import javax.servlet.http.HttpServletRequest
interface ProvinceService { interface ProvinceService {
...@@ -16,7 +17,7 @@ interface ProvinceService { ...@@ -16,7 +17,7 @@ interface ProvinceService {
fun updateData(id: String, request: Province): ResponseEntity<*>? fun updateData(id: String, request: Province): ResponseEntity<*>?
fun deleteData(request: DeleteDataRequest): ResponseEntity<*>? fun deleteData(request: DeleteDataRequest, httpServletRequest: HttpServletRequest): ResponseEntity<*>?
fun datatable(req: Pagination2Request): ResponseEntity<*>? fun datatable(req: Pagination2Request): ResponseEntity<*>?
......
...@@ -4,6 +4,7 @@ import id.co.sangkuriang.inovasi.daerah.master.model.request.DeleteDataRequest ...@@ -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.model.request.PaginationRequest
import id.co.sangkuriang.inovasi.daerah.master.pojo.Regency import id.co.sangkuriang.inovasi.daerah.master.pojo.Regency
import org.springframework.http.ResponseEntity import org.springframework.http.ResponseEntity
import javax.servlet.http.HttpServletRequest
interface RegencyService { interface RegencyService {
...@@ -15,5 +16,5 @@ interface RegencyService { ...@@ -15,5 +16,5 @@ interface RegencyService {
fun updateData(id: String, request: Regency): ResponseEntity<*>? 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 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.*
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.exception.BadRequestException 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.*
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.model.request.ApplicationCategoryRequest 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.DeleteDataRequest
import id.co.sangkuriang.inovasi.daerah.master.model.request.PaginationRequest 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.pojo.ApplicationCategory
import id.co.sangkuriang.inovasi.daerah.master.repository.ApplicationCategoryRepository import id.co.sangkuriang.inovasi.daerah.master.repository.ApplicationCategoryRepository
import id.co.sangkuriang.inovasi.daerah.master.service.ApplicationCategoryService import id.co.sangkuriang.inovasi.daerah.master.service.ApplicationCategoryService
...@@ -29,6 +26,8 @@ import javax.servlet.http.HttpServletRequest ...@@ -29,6 +26,8 @@ import javax.servlet.http.HttpServletRequest
@Service @Service
class ApplicationCategoryServiceImpl : ApplicationCategoryService { class ApplicationCategoryServiceImpl : ApplicationCategoryService {
private val title = "Kategori Aplikasi"
@Autowired @Autowired
private lateinit var repo: ApplicationCategoryRepository private lateinit var repo: ApplicationCategoryRepository
...@@ -122,10 +121,27 @@ class ApplicationCategoryServiceImpl : ApplicationCategoryService { ...@@ -122,10 +121,27 @@ class ApplicationCategoryServiceImpl : ApplicationCategoryService {
} }
} }
override fun deleteData(request: DeleteDataRequest): ResponseEntity<*>? { override fun deleteData(request: DeleteDataRequest, httpServletRequest: HttpServletRequest): ResponseEntity<*>? {
try { try {
val data = repo.findByIdAndActive(request.id) val data = repo.findByIdAndActive(request.id)
if (data.isPresent) { 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() val update = data.get()
update.updatedAt = Date() update.updatedAt = Date()
update.active = false update.active = false
...@@ -141,7 +157,7 @@ class ApplicationCategoryServiceImpl : ApplicationCategoryService { ...@@ -141,7 +157,7 @@ class ApplicationCategoryServiceImpl : ApplicationCategoryService {
override fun count(): ResponseEntity<*>? { override fun count(): ResponseEntity<*>? {
return try { return try {
responseSuccess(data = repo.getCount()) responseSuccess(data = repo.getCount())
} catch (e : Exception) { } catch (e: Exception) {
throw e throw e
} }
} }
......
package id.co.sangkuriang.inovasi.daerah.master.service.impl 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_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.exception.BadRequestException
import id.co.sangkuriang.inovasi.daerah.master.helpers.responseCreated import id.co.sangkuriang.inovasi.daerah.master.helpers.*
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.model.request.DeleteDataRequest 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.Pagination2Request
import id.co.sangkuriang.inovasi.daerah.master.model.request.PaginationRequest 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.pojo.Province
import id.co.sangkuriang.inovasi.daerah.master.repository.ProvinceRepository import id.co.sangkuriang.inovasi.daerah.master.repository.ProvinceRepository
import id.co.sangkuriang.inovasi.daerah.master.repository.native.ProvinceRepositoryNative import id.co.sangkuriang.inovasi.daerah.master.repository.native.ProvinceRepositoryNative
...@@ -20,11 +22,14 @@ import org.springframework.data.domain.Sort ...@@ -20,11 +22,14 @@ import org.springframework.data.domain.Sort
import org.springframework.http.ResponseEntity import org.springframework.http.ResponseEntity
import org.springframework.stereotype.Service import org.springframework.stereotype.Service
import java.util.* import java.util.*
import javax.servlet.http.HttpServletRequest
@Suppress("NAME_SHADOWING") @Suppress("NAME_SHADOWING")
@Service @Service
class ProvinceServiceImpl : ProvinceService { class ProvinceServiceImpl : ProvinceService {
private val title = "Provinsi"
@Autowired @Autowired
private lateinit var repo: ProvinceRepository private lateinit var repo: ProvinceRepository
...@@ -77,7 +82,7 @@ class ProvinceServiceImpl : ProvinceService { ...@@ -77,7 +82,7 @@ class ProvinceServiceImpl : ProvinceService {
override fun count(): ResponseEntity<*>? { override fun count(): ResponseEntity<*>? {
return try { return try {
responseSuccess(data = repo.getCount()) responseSuccess(data = repo.getCount())
} catch (e : Exception) { } catch (e: Exception) {
throw e throw e
} }
} }
...@@ -123,10 +128,27 @@ class ProvinceServiceImpl : ProvinceService { ...@@ -123,10 +128,27 @@ class ProvinceServiceImpl : ProvinceService {
} }
} }
override fun deleteData(request: DeleteDataRequest): ResponseEntity<*>? { override fun deleteData(request: DeleteDataRequest, httpServletRequest: HttpServletRequest): ResponseEntity<*>? {
try { try {
val data = repo.findByIdAndActive(request.id) val data = repo.findByIdAndActive(request.id)
if (data.isPresent) { 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() val update = data.get()
update.active = false update.active = false
update.updatedAt = Date() update.updatedAt = Date()
......
package id.co.sangkuriang.inovasi.daerah.master.service.impl 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_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.exception.BadRequestException
import id.co.sangkuriang.inovasi.daerah.master.helpers.responseCreated import id.co.sangkuriang.inovasi.daerah.master.helpers.*
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.model.request.DeleteDataRequest 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.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.pojo.Regency
import id.co.sangkuriang.inovasi.daerah.master.repository.RegencyRepository import id.co.sangkuriang.inovasi.daerah.master.repository.RegencyRepository
import id.co.sangkuriang.inovasi.daerah.master.service.RegencyService import id.co.sangkuriang.inovasi.daerah.master.service.RegencyService
...@@ -18,11 +20,14 @@ import org.springframework.data.domain.Sort ...@@ -18,11 +20,14 @@ import org.springframework.data.domain.Sort
import org.springframework.http.ResponseEntity import org.springframework.http.ResponseEntity
import org.springframework.stereotype.Service import org.springframework.stereotype.Service
import java.util.* import java.util.*
import javax.servlet.http.HttpServletRequest
@Suppress("NAME_SHADOWING") @Suppress("NAME_SHADOWING")
@Service @Service
class RegencyServiceImpl : RegencyService { class RegencyServiceImpl : RegencyService {
private val title = "Kabupaten/Kota"
@Autowired @Autowired
private lateinit var repo: RegencyRepository private lateinit var repo: RegencyRepository
...@@ -91,10 +96,27 @@ class RegencyServiceImpl : RegencyService { ...@@ -91,10 +96,27 @@ class RegencyServiceImpl : RegencyService {
} }
} }
override fun deleteData(request: DeleteDataRequest): ResponseEntity<*>? { override fun deleteData(request: DeleteDataRequest, httpServletRequest: HttpServletRequest): ResponseEntity<*>? {
try { try {
val data = repo.findByIdAndActive(request.id) val data = repo.findByIdAndActive(request.id)
if (data.isPresent) { 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() val update = data.get()
update.active = false update.active = false
update.updatedAt = Date() 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