Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
vridge-docs
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
JIRA
JIRA
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Gyeongho Park
vridge-docs
Commits
914fc6ad
Commit
914fc6ad
authored
Feb 25, 2023
by
shj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[ADD] 인덱스 추가,수정,삭제 시 형제 인덱스들 order 자동 업데이트 구현
parent
73b6c854
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
4 deletions
+60
-4
GuideIndexRepository.java
...om/vazil/vridge/docs/repository/GuideIndexRepository.java
+1
-0
GuideIndexService.java
...java/com/vazil/vridge/docs/service/GuideIndexService.java
+59
-4
No files found.
docs-back/src/main/java/com/vazil/vridge/docs/repository/GuideIndexRepository.java
View file @
914fc6ad
...
...
@@ -11,6 +11,7 @@ import java.util.List;
public
interface
GuideIndexRepository
extends
CrudRepository
<
GuideIndex
,
String
>
{
List
<
GuideIndex
>
findAll
();
List
<
GuideIndex
>
findAllByOrderByOrder
();
List
<
GuideIndex
>
findAllByDepthOrderByOrder
(
Integer
depth
);
List
<
GuideIndex
>
findAllByPathContainingAndDepth
(
String
path
,
Integer
depth
);
List
<
GuideIndex
>
findAllByPathContainingAndDepthOrderByOrderDesc
(
String
path
,
Integer
depth
);
GuideIndex
findByPath
(
String
path
);
...
...
docs-back/src/main/java/com/vazil/vridge/docs/service/GuideIndexService.java
View file @
914fc6ad
...
...
@@ -16,7 +16,6 @@ import java.util.NoSuchElementException;
@Log4j2
public
class
GuideIndexService
{
GuideIndexRepository
repository
;
GuideTestRepository
testRepository
;
@Transactional
public
GuideIndex
getById
(
String
id
)
throws
Exception
{
...
...
@@ -100,7 +99,7 @@ public class GuideIndexService {
@Transactional
public
GuideIndex
create
(
GuideIndex
index
)
throws
Exception
{
// todo : 기존 인덱스와 위치가 중복될 경우, 기존 인덱스들 order + 1
autoUpdateOrder
(
index
,
1
);
index
.
setLike
(
0
);
index
.
setView
(
0
);
...
...
@@ -112,8 +111,8 @@ public class GuideIndexService {
public
GuideIndex
update
(
GuideIndex
index
)
throws
Exception
{
GuideIndex
db
=
repository
.
findById
(
index
.
getId
()).
orElseThrow
(
NoSuchElementException:
:
new
);
// todo : 기존 인덱스와 위치가 중복될 경우, 기존 인덱스들 order + 1
autoUpdateOrder
(
db
,
-
1
);
autoUpdateOrder
(
index
,
1
);
db
.
setLocale
(
index
.
getLocale
());
db
.
setTitle
(
index
.
getTitle
());
...
...
@@ -127,7 +126,63 @@ public class GuideIndexService {
@Transactional
public
String
delete
(
String
id
)
throws
Exception
{
GuideIndex
db
=
repository
.
findById
(
id
).
orElseThrow
(
NoSuchElementException:
:
new
);
autoUpdateOrder
(
db
,
-
1
);
repository
.
delete
(
db
);
return
db
.
getId
();
}
// targetIndex의 형제들 order 업데이트
@Transactional
public
void
autoUpdateOrder
(
GuideIndex
targetIndex
,
Integer
type
)
throws
Exception
{
String
path
=
targetIndex
.
getPath
();
String
parentPath
=
path
.
substring
(
0
,
path
.
lastIndexOf
(
"/"
,
path
.
length
()
-
2
)
+
1
);
// 인덱스 증가해야 할 경우 (type == 1)
if
(
type
==
1
){
if
(
targetIndex
.
getDepth
()
==
1
){
List
<
GuideIndex
>
siblings
=
repository
.
findAllByDepthOrderByOrder
(
1
);
siblings
.
forEach
(
el
->
{
if
(
el
.
getOrder
()
>=
targetIndex
.
getOrder
()){
el
.
setOrder
(
el
.
getOrder
()
+
1
);
repository
.
save
(
el
);
}
});
}
else
{
List
<
GuideIndex
>
siblings
=
repository
.
findAllByPathContainingAndDepth
(
parentPath
,
targetIndex
.
getDepth
());
siblings
.
forEach
(
el
->
{
if
(
el
.
getOrder
()
>=
targetIndex
.
getOrder
()){
el
.
setOrder
(
el
.
getOrder
()
+
1
);
repository
.
save
(
el
);
}
});
}
return
;
}
// 인덱스 감소해야 할 경우 (type == -1)
if
(
type
==
-
1
){
if
(
targetIndex
.
getDepth
()
==
1
){
List
<
GuideIndex
>
siblings
=
repository
.
findAllByDepthOrderByOrder
(
1
);
siblings
.
forEach
(
el
->
{
if
(
el
.
getOrder
()
>
targetIndex
.
getOrder
()){
el
.
setOrder
(
el
.
getOrder
()
-
1
);
repository
.
save
(
el
);
}
});
}
else
{
List
<
GuideIndex
>
siblings
=
repository
.
findAllByPathContainingAndDepth
(
parentPath
,
targetIndex
.
getDepth
());
siblings
.
forEach
(
el
->
{
if
(
el
.
getOrder
()
>
targetIndex
.
getOrder
()){
el
.
setOrder
(
el
.
getOrder
()
-
1
);
repository
.
save
(
el
);
}
});
}
return
;
}
log
.
info
(
"type 파라미터가 부적절합니다."
);
}
}
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