Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
I
Inovasi Daerah Master
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ghitha Dinan
Inovasi Daerah Master
Commits
aadfdaad
Commit
aadfdaad
authored
Nov 18, 2021
by
Ghitha Dinan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
delete add check data application
parent
785624a5
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
74 additions
and
15 deletions
+74
-15
TagController.kt
...kuriang/inovasi/daerah/master/controller/TagController.kt
+6
-2
RequestHelpers.kt
...ngkuriang/inovasi/daerah/master/helpers/RequestHelpers.kt
+20
-0
RegencyRepository.kt
...ang/inovasi/daerah/master/repository/RegencyRepository.kt
+3
-0
TagService.kt
...o/sangkuriang/inovasi/daerah/master/service/TagService.kt
+2
-1
ProvinceServiceImpl.kt
...inovasi/daerah/master/service/impl/ProvinceServiceImpl.kt
+13
-4
RegencyServiceImpl.kt
.../inovasi/daerah/master/service/impl/RegencyServiceImpl.kt
+3
-3
TagServiceImpl.kt
...iang/inovasi/daerah/master/service/impl/TagServiceImpl.kt
+27
-5
No files found.
src/main/kotlin/id/co/sangkuriang/inovasi/daerah/master/controller/TagController.kt
View file @
aadfdaad
...
...
@@ -7,6 +7,7 @@ import id.co.sangkuriang.inovasi.daerah.master.service.TagService
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,10 @@ class TagController {
}
@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
)
}
}
src/main/kotlin/id/co/sangkuriang/inovasi/daerah/master/helpers/RequestHelpers.kt
View file @
aadfdaad
...
...
@@ -72,5 +72,25 @@ class RequestHelpers {
null
}
}
fun
applicationTagCountByParam
(
bearer
:
String
?,
param
:
String
?,
paramId
:
String
?):
ReturnData
?
{
return
try
{
configHttpClient
()
val
objectMapper
=
ObjectMapper
()
objectMapper
.
configure
(
DeserializationFeature
.
FAIL_ON_UNKNOWN_PROPERTIES
,
false
)
val
reqUrl
=
"$APPLICATION_URL/application-tag/count-by-param?param=$param¶mId=$paramId"
val
response
=
Unirest
.
get
(
reqUrl
)
.
header
(
"Content-Type"
,
"application/json"
)
.
header
(
HEADER_STRING
,
bearer
)
.
asString
()
objectMapper
.
readValue
(
response
.
body
,
ReturnData
::
class
.
java
)
}
catch
(
e
:
Exception
)
{
e
.
printStackTrace
()
null
}
}
}
}
src/main/kotlin/id/co/sangkuriang/inovasi/daerah/master/repository/RegencyRepository.kt
View file @
aadfdaad
...
...
@@ -21,4 +21,7 @@ interface RegencyRepository : JpaRepository<Regency, String> {
@Query
(
"FROM Regency WHERE LOWER(name) = LOWER(:name) AND provinceId = :provinceId AND active = true"
)
fun
findByNameProvinceId
(
name
:
String
?,
provinceId
:
String
?):
Optional
<
Regency
>
@Query
(
"SELECT COUNT(u) FROM Regency u WHERE u.active = true AND u.provinceId = :provinceId"
)
fun
countByProvinceId
(
provinceId
:
String
?):
Long
?
}
src/main/kotlin/id/co/sangkuriang/inovasi/daerah/master/service/TagService.kt
View file @
aadfdaad
...
...
@@ -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.Tag
import
org.springframework.http.ResponseEntity
import
javax.servlet.http.HttpServletRequest
interface
TagService
{
...
...
@@ -15,5 +16,5 @@ interface TagService {
fun
updateData
(
id
:
String
,
request
:
Tag
):
ResponseEntity
<*>?
fun
deleteData
(
request
:
DeleteDataRequest
):
ResponseEntity
<*>?
fun
deleteData
(
request
:
DeleteDataRequest
,
httpServletRequest
:
HttpServletRequest
):
ResponseEntity
<*>?
}
src/main/kotlin/id/co/sangkuriang/inovasi/daerah/master/service/impl/ProvinceServiceImpl.kt
View file @
aadfdaad
...
...
@@ -12,6 +12,7 @@ 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.RegencyRepository
import
id.co.sangkuriang.inovasi.daerah.master.repository.native.ProvinceRepositoryNative
import
id.co.sangkuriang.inovasi.daerah.master.service.ProvinceService
import
org.springframework.beans.factory.annotation.Autowired
...
...
@@ -33,6 +34,9 @@ class ProvinceServiceImpl : ProvinceService {
@Autowired
private
lateinit
var
repo
:
ProvinceRepository
@Autowired
private
lateinit
var
repoRegency
:
RegencyRepository
@Autowired
private
lateinit
var
repoNative
:
ProvinceRepositoryNative
...
...
@@ -140,19 +144,24 @@ class ProvinceServiceImpl : ProvinceService {
)
as
ReturnData
if
(
checkApplication
.
success
==
true
)
{
if
(
checkApplication
.
data
!=
null
)
{
val
count
User
Application
:
Long
=
(
checkApplication
.
data
as
Int
).
toLong
()
if
(
count
User
Application
>
0
)
{
return
responseBadRequest
(
"$VALIDATOR_MSG_DELETE_RELATION $title ${data.get().name} mempunyai $count
UserApplication data a
plikasi"
)
val
countApplication
:
Long
=
(
checkApplication
.
data
as
Int
).
toLong
()
if
(
countApplication
>
0
)
{
return
responseBadRequest
(
"$VALIDATOR_MSG_DELETE_RELATION $title ${data.get().name} mempunyai $count
Application data A
plikasi"
)
}
}
}
else
{
return
responseBadRequest
(
"$VALIDATOR_MSG_REQUEST_FAILED Aplikasi"
)
}
val
countRegency
=
repoRegency
.
countByProvinceId
(
data
.
get
().
id
)
?:
0
if
(
countRegency
>
0
)
{
return
responseBadRequest
(
"$VALIDATOR_MSG_DELETE_RELATION $title ${data.get().name} mempunyai $countRegency data Kabupaten / Kota"
)
}
val
update
=
data
.
get
()
update
.
active
=
false
update
.
updatedAt
=
Date
()
repo
.
save
(
update
)
//
repo.save(update)
return
responseSuccess
()
}
return
responseNotFound
()
...
...
src/main/kotlin/id/co/sangkuriang/inovasi/daerah/master/service/impl/RegencyServiceImpl.kt
View file @
aadfdaad
...
...
@@ -108,9 +108,9 @@ class RegencyServiceImpl : RegencyService {
)
as
ReturnData
if
(
checkApplication
.
success
==
true
)
{
if
(
checkApplication
.
data
!=
null
)
{
val
count
User
Application
:
Long
=
(
checkApplication
.
data
as
Int
).
toLong
()
if
(
count
User
Application
>
0
)
{
return
responseBadRequest
(
"$VALIDATOR_MSG_DELETE_RELATION $title ${data.get().name} mempunyai $count
UserApplication data a
plikasi"
)
val
countApplication
:
Long
=
(
checkApplication
.
data
as
Int
).
toLong
()
if
(
countApplication
>
0
)
{
return
responseBadRequest
(
"$VALIDATOR_MSG_DELETE_RELATION $title ${data.get().name} mempunyai $count
Application data A
plikasi"
)
}
}
}
else
{
...
...
src/main/kotlin/id/co/sangkuriang/inovasi/daerah/master/
repository/nativ
e/impl/TagServiceImpl.kt
→
src/main/kotlin/id/co/sangkuriang/inovasi/daerah/master/
servic
e/impl/TagServiceImpl.kt
View file @
aadfdaad
package
id.co.sangkuriang.inovasi.daerah.master.
repository.nativ
e.impl
package
id.co.sangkuriang.inovasi.daerah.master.
servic
e.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.Tag
import
id.co.sangkuriang.inovasi.daerah.master.repository.TagRepository
import
id.co.sangkuriang.inovasi.daerah.master.service.TagService
...
...
@@ -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
TagServiceImpl
:
TagService
{
private
val
title
=
"Tag"
@Autowired
private
lateinit
var
repo
:
TagRepository
...
...
@@ -90,10 +95,27 @@ class TagServiceImpl : TagService {
}
}
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
checkApplicationTag
:
ReturnData
=
RequestHelpers
.
applicationTagCountByParam
(
httpServletRequest
.
getHeader
(
HEADER_STRING
),
"tagId"
,
data
.
get
().
id
)
as
ReturnData
if
(
checkApplicationTag
.
success
==
true
)
{
if
(
checkApplicationTag
.
data
!=
null
)
{
val
countUserApplicationTag
:
Long
=
(
checkApplicationTag
.
data
as
Int
).
toLong
()
if
(
countUserApplicationTag
>
0
)
{
return
responseBadRequest
(
"$VALIDATOR_MSG_DELETE_RELATION $title ${data.get().name} mempunyai $countUserApplicationTag data Tag Aplikasi"
)
}
}
}
else
{
return
responseBadRequest
(
"$VALIDATOR_MSG_REQUEST_FAILED Tag Aplikasi"
)
}
val
update
=
data
.
get
()
update
.
active
=
false
update
.
updatedAt
=
Date
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment