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
48aae8f1
Commit
48aae8f1
authored
Feb 24, 2023
by
shj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[REFACTOR] GuideIndex 모델 개편(코드,파일 정리), 클래스 이름 전반적으로 개선
parent
7f1a4c26
Changes
15
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
213 additions
and
506 deletions
+213
-506
GuideController.java
...ava/com/vazil/vridge/docs/controller/GuideController.java
+0
-72
GuideIndexController.java
...om/vazil/vridge/docs/controller/GuideIndexController.java
+51
-0
GuideTestController.java
...com/vazil/vridge/docs/controller/GuideTestController.java
+0
-75
Guide.java
...back/src/main/java/com/vazil/vridge/docs/model/Guide.java
+0
-49
GuideContent.java
...c/main/java/com/vazil/vridge/docs/model/GuideContent.java
+0
-39
GuideIndex.java
...src/main/java/com/vazil/vridge/docs/model/GuideIndex.java
+4
-4
GuideSub.java
...k/src/main/java/com/vazil/vridge/docs/model/GuideSub.java
+0
-31
GuideContentRepository.java
.../vazil/vridge/docs/repository/GuideContentRepository.java
+0
-13
GuideIndexRepository.java
...om/vazil/vridge/docs/repository/GuideIndexRepository.java
+18
-0
GuideRepository.java
...ava/com/vazil/vridge/docs/repository/GuideRepository.java
+0
-17
GuideTestRepository.java
...com/vazil/vridge/docs/repository/GuideTestRepository.java
+0
-19
GuideIndexService.java
...java/com/vazil/vridge/docs/service/GuideIndexService.java
+133
-0
GuideService.java
...main/java/com/vazil/vridge/docs/service/GuideService.java
+0
-180
default.vue
docs-front/layouts/default.vue
+5
-5
index.vue
docs-front/pages/_guide/index.vue
+2
-2
No files found.
docs-back/src/main/java/com/vazil/vridge/docs/controller/GuideController.java
deleted
100644 → 0
View file @
7f1a4c26
package
com
.
vazil
.
vridge
.
docs
.
controller
;
import
com.vazil.vridge.docs.model.Guide
;
import
com.vazil.vridge.docs.model.GuideContent
;
import
com.vazil.vridge.docs.service.GuideService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.log4j.Log4j2
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.*
;
@RestController
@AllArgsConstructor
@Log4j2
@RequestMapping
(
"/api"
)
@CrossOrigin
@Api
(
"가이드 API V1"
)
public
class
GuideController
{
GuideService
guideService
;
@ApiOperation
(
value
=
"모든 가이드 목차 조회"
)
@GetMapping
(
"/index"
)
public
ResponseEntity
<?>
findIndex
()
throws
Exception
{
return
new
ResponseEntity
<>(
guideService
.
findGuideIndex
(),
HttpStatus
.
OK
);
}
@ApiOperation
(
value
=
"모든 가이드 목차 검색"
)
@GetMapping
(
"/search"
)
public
ResponseEntity
<?>
search
(
@RequestParam
(
value
=
"keyword"
,
required
=
false
)
String
keyword
)
throws
Exception
{
return
new
ResponseEntity
<>(
guideService
.
search
(
keyword
),
HttpStatus
.
OK
);
}
@ApiOperation
(
value
=
"가이드 타이틀 추가"
)
@PostMapping
(
"/index"
)
public
ResponseEntity
<?>
createGuideIndex
(
@RequestBody
Guide
guide
)
throws
Exception
{
return
new
ResponseEntity
<>(
guideService
.
createGuide
(
guide
),
HttpStatus
.
CREATED
);
}
@PutMapping
(
"/index"
)
public
ResponseEntity
<?>
updateGuideIndex
(
@RequestBody
Guide
guide
)
throws
Exception
{
return
new
ResponseEntity
<>(
guideService
.
updateGuide
(
guide
),
HttpStatus
.
OK
);
}
@PutMapping
(
"/keyword"
)
public
ResponseEntity
<?>
updateGuideKeyword
(
@RequestBody
Guide
guide
)
throws
Exception
{
return
new
ResponseEntity
<>(
guideService
.
updateGuideKeyword
(
guide
),
HttpStatus
.
OK
);
}
@GetMapping
public
ResponseEntity
<?>
getGuide
(
@RequestParam
(
value
=
"guideId"
)
String
guideId
)
throws
Exception
{
return
new
ResponseEntity
<>(
guideService
.
findGuideById
(
guideId
),
HttpStatus
.
OK
);
}
@DeleteMapping
public
ResponseEntity
<?>
deleteGuideIndex
(
@RequestParam
(
value
=
"guideId"
)
String
guideId
,
@RequestParam
(
value
=
"cascade"
,
required
=
false
)
boolean
cascade
)
throws
Exception
{
return
new
ResponseEntity
<>(
guideService
.
deleteGuide
(
guideId
,
cascade
),
HttpStatus
.
OK
);
}
@PutMapping
public
ResponseEntity
<?>
updateGuideContent
(
@RequestBody
GuideContent
guideContent
)
throws
Exception
{
return
new
ResponseEntity
<>(
guideService
.
updateGuideContent
(
guideContent
),
HttpStatus
.
OK
);
}
}
docs-back/src/main/java/com/vazil/vridge/docs/controller/GuideIndexController.java
0 → 100644
View file @
48aae8f1
package
com
.
vazil
.
vridge
.
docs
.
controller
;
import
com.vazil.vridge.docs.model.GuideIndex
;
import
com.vazil.vridge.docs.service.GuideIndexService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.log4j.Log4j2
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.*
;
@RestController
@AllArgsConstructor
@Log4j2
@RequestMapping
(
"/guide-index"
)
@CrossOrigin
@Api
(
"가이드 API V1"
)
public
class
GuideIndexController
{
GuideIndexService
service
;
@ApiOperation
(
value
=
"가이드 인덱스 조회"
)
@GetMapping
public
ResponseEntity
<?>
getById
(
@RequestParam
(
value
=
"id"
)
String
id
)
throws
Exception
{
return
new
ResponseEntity
<>(
service
.
getById
(
id
),
HttpStatus
.
OK
);
}
@ApiOperation
(
value
=
"가이드 인덱스 전체 조회"
)
@GetMapping
(
"/all"
)
public
ResponseEntity
<?>
getAll
()
throws
Exception
{
return
new
ResponseEntity
<>(
service
.
getAll
(),
HttpStatus
.
OK
);
}
@ApiOperation
(
value
=
"가이드 인덱스 추가"
)
@PostMapping
public
ResponseEntity
<?>
create
(
@RequestBody
GuideIndex
index
)
throws
Exception
{
return
new
ResponseEntity
<>(
service
.
create
(
index
),
HttpStatus
.
CREATED
);
}
@PutMapping
public
ResponseEntity
<?>
update
(
@RequestBody
GuideIndex
index
)
throws
Exception
{
return
new
ResponseEntity
<>(
service
.
update
(
index
),
HttpStatus
.
OK
);
}
@DeleteMapping
public
ResponseEntity
<?>
delete
(
@RequestParam
(
value
=
"id"
)
String
id
)
throws
Exception
{
return
new
ResponseEntity
<>(
service
.
delete
(
id
),
HttpStatus
.
OK
);
}
}
docs-back/src/main/java/com/vazil/vridge/docs/controller/GuideTestController.java
deleted
100644 → 0
View file @
7f1a4c26
package
com
.
vazil
.
vridge
.
docs
.
controller
;
import
com.vazil.vridge.docs.model.Guide
;
import
com.vazil.vridge.docs.model.GuideContent
;
import
com.vazil.vridge.docs.model.GuideTest
;
import
com.vazil.vridge.docs.service.GuideService
;
import
com.vazil.vridge.docs.service.GuideTestService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.log4j.Log4j2
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.*
;
@RestController
@AllArgsConstructor
@Log4j2
@RequestMapping
(
"/test"
)
@CrossOrigin
@Api
(
"가이드 API V1"
)
public
class
GuideTestController
{
GuideService
guideService
;
GuideTestService
guideTestService
;
@GetMapping
public
ResponseEntity
<?>
getGuide
(
@RequestParam
(
value
=
"guideId"
)
String
guideId
)
throws
Exception
{
return
new
ResponseEntity
<>(
guideTestService
.
findGuideById
(
guideId
),
HttpStatus
.
OK
);
}
@ApiOperation
(
value
=
"모든 가이드 목차 조회"
)
@GetMapping
(
"/index"
)
public
ResponseEntity
<?>
findIndex
()
throws
Exception
{
return
new
ResponseEntity
<>(
guideTestService
.
findGuideIndex
(),
HttpStatus
.
OK
);
}
@ApiOperation
(
value
=
"모든 가이드 목차 검색"
)
@GetMapping
(
"/search"
)
public
ResponseEntity
<?>
search
(
@RequestParam
(
value
=
"keyword"
,
required
=
false
)
String
keyword
)
throws
Exception
{
return
new
ResponseEntity
<>(
guideService
.
search
(
keyword
),
HttpStatus
.
OK
);
}
@ApiOperation
(
value
=
"가이드 타이틀 추가"
)
@PostMapping
public
ResponseEntity
<?>
createGuideIndex
(
@RequestBody
GuideTest
guide
)
throws
Exception
{
return
new
ResponseEntity
<>(
guideTestService
.
createGuide
(
guide
),
HttpStatus
.
CREATED
);
}
@PutMapping
(
"/index"
)
public
ResponseEntity
<?>
updateGuideIndex
(
@RequestBody
GuideTest
guide
)
throws
Exception
{
return
new
ResponseEntity
<>(
guideTestService
.
updateGuide
(
guide
),
HttpStatus
.
OK
);
}
@PutMapping
(
"/keyword"
)
public
ResponseEntity
<?>
updateGuideKeyword
(
@RequestBody
Guide
guide
)
throws
Exception
{
return
new
ResponseEntity
<>(
guideService
.
updateGuideKeyword
(
guide
),
HttpStatus
.
OK
);
}
@DeleteMapping
public
ResponseEntity
<?>
deleteGuideIndex
(
@RequestParam
(
value
=
"guideId"
)
String
guideId
)
throws
Exception
{
return
new
ResponseEntity
<>(
guideTestService
.
deleteGuide
(
guideId
),
HttpStatus
.
OK
);
}
@PutMapping
public
ResponseEntity
<?>
updateGuideContent
(
@RequestBody
GuideContent
guideContent
)
throws
Exception
{
return
new
ResponseEntity
<>(
guideService
.
updateGuideContent
(
guideContent
),
HttpStatus
.
OK
);
}
}
docs-back/src/main/java/com/vazil/vridge/docs/model/Guide.java
deleted
100644 → 0
View file @
7f1a4c26
package
com
.
vazil
.
vridge
.
docs
.
model
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
nonapi.io.github.classgraph.json.Id
;
import
org.springframework.data.annotation.CreatedDate
;
import
org.springframework.data.annotation.LastModifiedDate
;
import
org.springframework.data.annotation.Transient
;
import
org.springframework.data.mongodb.core.mapping.Document
;
import
java.io.Serializable
;
import
java.time.LocalDateTime
;
import
java.util.List
;
import
java.util.Set
;
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Document
(
value
=
"guide"
)
@Data
public
class
Guide
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1928367242L
;
@Id
private
String
id
;
private
String
parentId
;
private
String
title
;
private
Integer
order
;
private
Integer
like
;
private
Integer
view
;
private
String
contentKey
;
private
Set
<
String
>
keywordSet
;
@CreatedDate
private
LocalDateTime
createDate
;
@LastModifiedDate
private
LocalDateTime
updateDate
;
private
LocalDateTime
deleteDate
;
@Transient
List
<
Guide
>
children
;
@Transient
private
Guide
prevContent
;
@Transient
private
Guide
nextContent
;
}
docs-back/src/main/java/com/vazil/vridge/docs/model/GuideContent.java
deleted
100644 → 0
View file @
7f1a4c26
package
com
.
vazil
.
vridge
.
docs
.
model
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
org.springframework.data.annotation.CreatedDate
;
import
org.springframework.data.annotation.Id
;
import
org.springframework.data.annotation.LastModifiedDate
;
import
org.springframework.data.annotation.Transient
;
import
org.springframework.data.mongodb.core.mapping.Document
;
import
java.time.LocalDateTime
;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Document
(
value
=
"guideContent"
)
public
class
GuideContent
{
@Id
private
String
id
;
private
String
guideId
;
private
String
title
;
private
String
content
;
private
Integer
like
;
private
Integer
view
;
@Transient
private
Guide
prevContent
;
@Transient
private
Guide
nextContent
;
@CreatedDate
private
LocalDateTime
createDate
;
@LastModifiedDate
private
LocalDateTime
updateDate
;
private
LocalDateTime
deleteDate
;
}
docs-back/src/main/java/com/vazil/vridge/docs/model/Guide
Test
.java
→
docs-back/src/main/java/com/vazil/vridge/docs/model/Guide
Index
.java
View file @
48aae8f1
...
@@ -15,9 +15,9 @@ import java.time.LocalDateTime;
...
@@ -15,9 +15,9 @@ import java.time.LocalDateTime;
@Builder
@Builder
@AllArgsConstructor
@AllArgsConstructor
@NoArgsConstructor
@NoArgsConstructor
@Document
(
value
=
"guide-
test
"
)
@Document
(
value
=
"guide-
index
"
)
@Data
@Data
public
class
Guide
Test
implements
Serializable
{
public
class
Guide
Index
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1928367242L
;
private
static
final
long
serialVersionUID
=
1928367242L
;
@Id
@Id
private
String
id
;
private
String
id
;
...
@@ -30,9 +30,9 @@ public class GuideTest implements Serializable {
...
@@ -30,9 +30,9 @@ public class GuideTest implements Serializable {
private
Integer
like
;
private
Integer
like
;
@Transient
@Transient
private
Guide
Test
prevGuide
;
private
Guide
Index
prevIndex
;
@Transient
@Transient
private
Guide
Test
nextGuide
;
private
Guide
Index
nextIndex
;
private
LocalDateTime
createDate
;
private
LocalDateTime
createDate
;
@LastModifiedDate
@LastModifiedDate
...
...
docs-back/src/main/java/com/vazil/vridge/docs/model/GuideSub.java
deleted
100644 → 0
View file @
7f1a4c26
package
com
.
vazil
.
vridge
.
docs
.
model
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
org.springframework.data.annotation.CreatedDate
;
import
org.springframework.data.annotation.Id
;
import
org.springframework.data.annotation.LastModifiedDate
;
import
java.time.LocalDateTime
;
@Data
@AllArgsConstructor
@NoArgsConstructor
public
class
GuideSub
{
@Id
private
String
id
;
private
String
title
;
private
String
contents
;
private
String
router
;
@CreatedDate
private
LocalDateTime
createDate
;
@LastModifiedDate
private
LocalDateTime
updateDate
;
private
LocalDateTime
deleteDate
;
}
docs-back/src/main/java/com/vazil/vridge/docs/repository/GuideContentRepository.java
deleted
100644 → 0
View file @
7f1a4c26
package
com
.
vazil
.
vridge
.
docs
.
repository
;
import
com.vazil.vridge.docs.model.GuideContent
;
import
org.springframework.data.repository.CrudRepository
;
import
org.springframework.stereotype.Repository
;
import
java.util.Optional
;
@Repository
public
interface
GuideContentRepository
extends
CrudRepository
<
GuideContent
,
String
>
{
Optional
<
GuideContent
>
findByGuideId
(
String
guideId
);
void
deleteByGuideId
(
String
guideId
);
}
docs-back/src/main/java/com/vazil/vridge/docs/repository/GuideIndexRepository.java
0 → 100644
View file @
48aae8f1
package
com
.
vazil
.
vridge
.
docs
.
repository
;
import
com.vazil.vridge.docs.model.GuideIndex
;
import
org.springframework.data.repository.CrudRepository
;
import
org.springframework.stereotype.Repository
;
import
java.util.List
;
@Repository
public
interface
GuideIndexRepository
extends
CrudRepository
<
GuideIndex
,
String
>
{
List
<
GuideIndex
>
findAll
();
List
<
GuideIndex
>
findAllByOrderByOrder
();
List
<
GuideIndex
>
findAllByPathContainingAndDepth
(
String
path
,
Integer
depth
);
List
<
GuideIndex
>
findAllByPathContainingAndDepthOrderByOrderDesc
(
String
path
,
Integer
depth
);
GuideIndex
findByPath
(
String
path
);
GuideIndex
findByPathContainingAndDepthAndOrder
(
String
path
,
Integer
depth
,
Integer
order
);
}
docs-back/src/main/java/com/vazil/vridge/docs/repository/GuideRepository.java
deleted
100644 → 0
View file @
7f1a4c26
package
com
.
vazil
.
vridge
.
docs
.
repository
;
import
com.vazil.vridge.docs.model.Guide
;
import
org.springframework.data.repository.CrudRepository
;
import
org.springframework.stereotype.Repository
;
import
java.util.List
;
@Repository
public
interface
GuideRepository
extends
CrudRepository
<
Guide
,
String
>
{
List
<
Guide
>
findAllByParentIdOrderByOrderAsc
(
String
parentId
);
List
<
Guide
>
findAllByKeywordSetContaining
(
String
keyword
);
int
countAllBy
();
int
countAllByParentId
(
String
parentId
);
}
docs-back/src/main/java/com/vazil/vridge/docs/repository/GuideTestRepository.java
deleted
100644 → 0
View file @
7f1a4c26
package
com
.
vazil
.
vridge
.
docs
.
repository
;
import
com.vazil.vridge.docs.model.Guide
;
import
com.vazil.vridge.docs.model.GuideTest
;
import
org.springframework.data.repository.CrudRepository
;
import
org.springframework.stereotype.Repository
;
import
java.util.List
;
@Repository
public
interface
GuideTestRepository
extends
CrudRepository
<
GuideTest
,
String
>
{
List
<
GuideTest
>
findAll
();
List
<
GuideTest
>
findAllByOrderByOrder
();
List
<
GuideTest
>
findAllByPathContainingAndDepth
(
String
path
,
Integer
depth
);
List
<
GuideTest
>
findAllByPathContainingAndDepthOrderByOrderDesc
(
String
path
,
Integer
depth
);
GuideTest
findByPath
(
String
path
);
GuideTest
findByPathContainingAndDepthAndOrder
(
String
path
,
Integer
depth
,
Integer
order
);
}
docs-back/src/main/java/com/vazil/vridge/docs/service/Guide
Test
Service.java
→
docs-back/src/main/java/com/vazil/vridge/docs/service/Guide
Index
Service.java
View file @
48aae8f1
package
com
.
vazil
.
vridge
.
docs
.
service
;
package
com
.
vazil
.
vridge
.
docs
.
service
;
import
com.vazil.vridge.docs.model.Guide
;
import
com.vazil.vridge.docs.model.GuideIndex
;
import
com.vazil.vridge.docs.model.GuideTest
;
import
com.vazil.vridge.docs.repository.GuideIndexRepository
;
import
com.vazil.vridge.docs.repository.GuideTestRepository
;
import
com.vazil.vridge.docs.utils.TimeManager
;
import
com.vazil.vridge.docs.utils.TimeManager
;
import
lombok.AllArgsConstructor
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.log4j.Log4j2
;
import
lombok.extern.log4j.Log4j2
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.*
;
import
java.util.List
;
import
java.util.NoSuchElementException
;
@Service
@Service
@AllArgsConstructor
@AllArgsConstructor
@Log4j2
@Log4j2
public
class
GuideTestService
{
public
class
GuideIndexService
{
GuideTestRepository
repository
;
GuideIndexRepository
repository
;
GuideTestRepository
testRepository
;
public
List
<
GuideTest
>
findGuideIndex
()
throws
Exception
{
List
<
GuideTest
>
guideList
=
repository
.
findAllByOrderByOrder
();
return
guideList
;
}
@Transactional
@Transactional
public
Guide
Test
findGuideById
(
String
guideI
d
)
throws
Exception
{
public
Guide
Index
getById
(
String
i
d
)
throws
Exception
{
Guide
Test
targetGuide
=
repository
.
findById
(
guideI
d
).
orElseThrow
(
NoSuchElementException:
:
new
);
Guide
Index
db
=
repository
.
findById
(
i
d
).
orElseThrow
(
NoSuchElementException:
:
new
);
int
viewCount
=
targetGuide
.
getView
()
!=
null
?
targetGuide
.
getView
()
:
0
;
int
viewCount
=
db
.
getView
()
!=
null
?
db
.
getView
()
:
0
;
targetGuide
.
setView
(
viewCount
+
1
);
db
.
setView
(
viewCount
+
1
);
repository
.
save
(
targetGuide
);
repository
.
save
(
db
);
targetGuide
.
setNextGuide
(
getNextGuide
(
targetGuide
,
false
));
db
.
setNextIndex
(
getNextIndex
(
db
,
false
));
targetGuide
.
setPrevGuide
(
getPrevGuide
(
targetGuide
));
db
.
setPrevIndex
(
getPrevIndex
(
db
));
return
targetGuide
;
return
db
;
}
}
public
Guide
Test
getPrevGuide
(
GuideTest
targetGuide
)
throws
Exception
{
public
Guide
Index
getPrevIndex
(
GuideIndex
targetIndex
)
throws
Exception
{
String
path
=
target
Guide
.
getPath
();
String
path
=
target
Index
.
getPath
();
String
parentPath
=
path
.
substring
(
0
,
path
.
lastIndexOf
(
"/"
,
path
.
length
()
-
2
)
+
1
);
String
parentPath
=
path
.
substring
(
0
,
path
.
lastIndexOf
(
"/"
,
path
.
length
()
-
2
)
+
1
);
// depth == 1, order == 0 인 경우 이전
guide
없음
// depth == 1, order == 0 인 경우 이전
인덱스
없음
if
(
target
Guide
.
getDepth
()
==
1
&&
targetGuide
.
getOrder
()
==
0
)
if
(
target
Index
.
getDepth
()
==
1
&&
targetIndex
.
getOrder
()
==
0
)
return
null
;
return
null
;
// order == 0 인 경우 부모
guide
반환
// order == 0 인 경우 부모
인덱스
반환
if
(
target
Guide
.
getOrder
()
==
0
){
if
(
target
Index
.
getOrder
()
==
0
){
return
repository
.
findByPath
(
parentPath
);
return
repository
.
findByPath
(
parentPath
);
}
}
// 이전 형제의 자식이 없을 경우 해당 형제 반환
// 이전 형제의 자식이 없을 경우 해당 형제 반환
Guide
Test
prevSibling
=
repository
.
findByPathContainingAndDepthAndOrder
(
parentPath
,
targetGuide
.
getDepth
(),
targetGuide
.
getOrder
()
-
1
);
Guide
Index
prevSibling
=
repository
.
findByPathContainingAndDepthAndOrder
(
parentPath
,
targetIndex
.
getDepth
(),
targetIndex
.
getOrder
()
-
1
);
if
(
repository
.
findAllByPathContainingAndDepth
(
prevSibling
.
getPath
(),
prevSibling
.
getDepth
()
+
1
).
size
()
==
0
){
if
(
repository
.
findAllByPathContainingAndDepth
(
prevSibling
.
getPath
(),
prevSibling
.
getDepth
()
+
1
).
size
()
==
0
){
return
prevSibling
;
return
prevSibling
;
}
else
{
// 이전 형제의 자식이 있을 경우 가장 마지막 자식 반환
}
else
{
// 이전 형제의 자식이 있을 경우 가장 마지막 자식 반환
return
getLastChild
Guide
(
prevSibling
);
return
getLastChild
Index
(
prevSibling
);
}
}
}
}
public
Guide
Test
getLastChildGuide
(
GuideTest
targetGuide
)
throws
Exception
{
public
Guide
Index
getLastChildIndex
(
GuideIndex
targetIndex
)
throws
Exception
{
Guide
Test
lastChild
=
repository
.
findAllByPathContainingAndDepthOrderByOrderDesc
(
targetGuide
.
getPath
(),
targetGuide
.
getDepth
()
+
1
).
get
(
0
);
Guide
Index
lastChild
=
repository
.
findAllByPathContainingAndDepthOrderByOrderDesc
(
targetIndex
.
getPath
(),
targetIndex
.
getDepth
()
+
1
).
get
(
0
);
if
(
repository
.
findAllByPathContainingAndDepth
(
lastChild
.
getPath
(),
lastChild
.
getDepth
()
+
1
).
size
()
==
0
){
if
(
repository
.
findAllByPathContainingAndDepth
(
lastChild
.
getPath
(),
lastChild
.
getDepth
()
+
1
).
size
()
==
0
){
return
lastChild
;
return
lastChild
;
}
else
{
}
else
{
return
getLastChild
Guide
(
lastChild
);
return
getLastChild
Index
(
lastChild
);
}
}
}
}
/**
/**
* @param target
Guide
* @param target
Index
* @param onlySibling true일 경우, 자식 guide는 무시하고 다음 형제 guide를 찾음
* @param onlySibling true일 경우, 자식 guide는 무시하고 다음 형제 guide를 찾음
*/
*/
public
Guide
Test
getNextGuide
(
GuideTest
targetGuide
,
Boolean
onlySibling
)
throws
Exception
{
public
Guide
Index
getNextIndex
(
GuideIndex
targetIndex
,
Boolean
onlySibling
)
throws
Exception
{
String
path
=
target
Guide
.
getPath
();
String
path
=
target
Index
.
getPath
();
String
parentPath
=
target
Guide
.
getDepth
()
==
1
?
String
parentPath
=
target
Index
.
getDepth
()
==
1
?
"/"
:
path
.
substring
(
0
,
path
.
lastIndexOf
(
"/"
,
path
.
length
()
-
2
)
+
1
);
"/"
:
path
.
substring
(
0
,
path
.
lastIndexOf
(
"/"
,
path
.
length
()
-
2
)
+
1
);
Guide
Test
nextGuide
=
null
;
Guide
Index
nextIndex
=
null
;
// child가 있으면 order == 0 인 자식 반환 (onlySibling == true 일 경우 패스하여 형제 반환으로 넘어감)
// child가 있으면 order == 0 인 자식 반환 (onlySibling == true 일 경우 패스하여 형제 반환으로 넘어감)
if
(!
onlySibling
){
if
(!
onlySibling
){
next
Guide
=
repository
.
findByPathContainingAndDepthAndOrder
(
path
,
targetGuide
.
getDepth
()
+
1
,
0
);
next
Index
=
repository
.
findByPathContainingAndDepthAndOrder
(
path
,
targetIndex
.
getDepth
()
+
1
,
0
);
}
}
// child가 없으면 다음 형제 반환
// child가 없으면 다음 형제 반환
if
(
next
Guide
==
null
){
if
(
next
Index
==
null
){
next
Guide
=
repository
.
findByPathContainingAndDepthAndOrder
(
parentPath
,
targetGuide
.
getDepth
(),
targetGuide
.
getOrder
()
+
1
);
next
Index
=
repository
.
findByPathContainingAndDepthAndOrder
(
parentPath
,
targetIndex
.
getDepth
(),
targetIndex
.
getOrder
()
+
1
);
}
}
// child가 없고, 다음 형제 없는 경우, 부모 guide의 next
Guide
탐색
// child가 없고, 다음 형제 없는 경우, 부모 guide의 next
Index
탐색
if
(
next
Guide
==
null
&&
targetGuide
.
getDepth
()
!=
1
)
{
if
(
next
Index
==
null
&&
targetIndex
.
getDepth
()
!=
1
)
{
Guide
Test
parentGuide
=
repository
.
findByPath
(
parentPath
);
Guide
Index
parentIndex
=
repository
.
findByPath
(
parentPath
);
next
Guide
=
getNextGuide
(
parentGuide
,
true
);
next
Index
=
getNextIndex
(
parentIndex
,
true
);
}
}
return
next
Guide
;
return
next
Index
;
}
}
@Transactional
public
List
<
GuideIndex
>
getAll
()
throws
Exception
{
public
GuideTest
createGuide
(
GuideTest
guide
)
throws
Exception
{
return
repository
.
findAllByOrderByOrder
();
// guide.setOrder(guide.getOrder() == null ? getLastOrder(guide.getParentId()) : 0);
}
@Transactional
public
GuideIndex
create
(
GuideIndex
index
)
throws
Exception
{
// todo : 기존 인덱스와 위치가 중복될 경우, 기존 인덱스들 order + 1
// todo : 기존 인덱스와 위치가 중복될 경우, 기존 인덱스들 order + 1
index
.
setLike
(
0
);
guide
.
setLike
(
0
);
index
.
setView
(
0
);
guide
.
setView
(
0
);
index
.
setCreateDate
(
TimeManager
.
now
());
guide
.
setCreateDate
(
TimeManager
.
now
());
return
repository
.
save
(
index
);
return
repository
.
save
(
guide
);
}
}
@Transactional
@Transactional
public
Guide
Test
updateGuide
(
GuideTest
guide
)
throws
Exception
{
public
Guide
Index
update
(
GuideIndex
index
)
throws
Exception
{
Guide
Test
db
=
repository
.
findById
(
guide
.
getId
()).
orElseThrow
(
NoSuchElementException:
:
new
);
Guide
Index
db
=
repository
.
findById
(
index
.
getId
()).
orElseThrow
(
NoSuchElementException:
:
new
);
// todo : 기존 인덱스와 위치가 중복될 경우, 기존 인덱스들 order + 1
// todo : 기존 인덱스와 위치가 중복될 경우, 기존 인덱스들 order + 1
db
.
setLocale
(
guide
.
getLocale
());
db
.
setLocale
(
index
.
getLocale
());
db
.
setTitle
(
guide
.
getTitle
());
db
.
setTitle
(
index
.
getTitle
());
db
.
setOrder
(
guide
.
getOrder
());
db
.
setOrder
(
index
.
getOrder
());
db
.
setPath
(
guide
.
getPath
());
db
.
setPath
(
index
.
getPath
());
db
.
setDepth
(
guide
.
getDepth
());
db
.
setDepth
(
index
.
getDepth
());
return
repository
.
save
(
db
);
return
repository
.
save
(
db
);
}
}
@Transactional
@Transactional
public
String
delete
Guide
(
String
guideI
d
)
throws
Exception
{
public
String
delete
(
String
i
d
)
throws
Exception
{
Guide
Test
db
=
repository
.
findById
(
guideI
d
).
orElseThrow
(
NoSuchElementException:
:
new
);
Guide
Index
db
=
repository
.
findById
(
i
d
).
orElseThrow
(
NoSuchElementException:
:
new
);
repository
.
delete
(
db
);
repository
.
delete
(
db
);
return
db
.
getId
();
return
db
.
getId
();
}
}
...
...
docs-back/src/main/java/com/vazil/vridge/docs/service/GuideService.java
deleted
100644 → 0
View file @
7f1a4c26
package
com
.
vazil
.
vridge
.
docs
.
service
;
import
com.vazil.vridge.docs.model.Guide
;
import
com.vazil.vridge.docs.model.GuideContent
;
import
com.vazil.vridge.docs.repository.GuideContentRepository
;
import
com.vazil.vridge.docs.repository.GuideRepository
;
import
com.vazil.vridge.docs.utils.TimeManager
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.log4j.Log4j2
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.NoSuchElementException
;
@Service
@AllArgsConstructor
@Log4j2
public
class
GuideService
{
GuideRepository
guideRepository
;
GuideContentRepository
guideContentRepository
;
public
List
<
Guide
>
findGuideIndex
()
throws
Exception
{
List
<
Guide
>
guides
=
new
ArrayList
<>();
List
<
Guide
>
sortedGuideList
=
guideRepository
.
findAllByParentIdOrderByOrderAsc
(
""
);
for
(
Guide
guide
:
sortedGuideList
)
{
guide
.
setChildren
(
getGuideTreeByParentId
(
guide
.
getId
()));
guides
.
add
(
guide
);
}
return
guides
;
}
@Transactional
public
Guide
findGuideById
(
String
guideId
)
throws
Exception
{
Guide
targetGuide
=
guideRepository
.
findById
(
guideId
).
orElseThrow
(
NoSuchElementException:
:
new
);
List
<
Guide
>
sortedGuideList
=
new
ArrayList
<>();
for
(
Guide
guide
:
guideRepository
.
findAllByParentIdOrderByOrderAsc
(
""
))
{
sortedGuideList
.
add
(
guide
);
sortedGuideList
.
addAll
(
getGuideListByParentId
(
guide
.
getId
()));
}
for
(
int
i
=
0
;
i
<
sortedGuideList
.
size
();
i
++)
{
if
(
sortedGuideList
.
get
(
i
).
getId
().
equals
(
guideId
))
{
if
(
i
>
0
)
{
targetGuide
.
setPrevContent
(
sortedGuideList
.
get
(
i
-
1
));
}
if
(
i
<
sortedGuideList
.
size
()
-
1
)
{
targetGuide
.
setNextContent
(
sortedGuideList
.
get
(
i
+
1
));
}
break
;
}
}
return
targetGuide
;
}
public
List
<
Guide
>
search
(
String
keyword
)
throws
Exception
{
return
guideRepository
.
findAllByKeywordSetContaining
(
keyword
);
}
@Transactional
public
Guide
createGuide
(
Guide
guide
)
throws
Exception
{
guide
.
setCreateDate
(
TimeManager
.
now
());
guide
.
setUpdateDate
(
TimeManager
.
now
());
guide
.
setOrder
(
guide
.
getOrder
()
==
null
?
getLastOrder
(
guide
.
getParentId
())
:
0
);
guide
.
setParentId
(
StringUtils
.
isEmpty
(
guide
.
getParentId
())
?
""
:
guide
.
getParentId
());
guide
.
setLike
(
0
);
guide
.
setView
(
0
);
return
guideRepository
.
save
(
guide
);
}
@Transactional
public
Guide
updateGuide
(
Guide
guide
)
throws
Exception
{
Guide
savedGuide
=
guideRepository
.
findById
(
guide
.
getId
()).
orElseThrow
(
NoSuchElementException:
:
new
);
savedGuide
.
setParentId
(
guide
.
getParentId
());
savedGuide
.
setOrder
(
guide
.
getOrder
());
savedGuide
.
setUpdateDate
(
TimeManager
.
now
());
savedGuide
.
setContentKey
(
guide
.
getContentKey
());
return
guideRepository
.
save
(
savedGuide
);
}
@Transactional
public
Guide
updateGuideKeyword
(
Guide
guide
)
throws
Exception
{
Guide
savedGuide
=
guideRepository
.
findById
(
guide
.
getId
()).
orElseThrow
(
NoSuchElementException:
:
new
);
savedGuide
.
setKeywordSet
(
guide
.
getKeywordSet
());
return
guideRepository
.
save
(
savedGuide
);
}
@Transactional
public
Guide
deleteGuide
(
String
guideId
,
boolean
cascade
)
throws
Exception
{
Guide
guide
=
guideRepository
.
findById
(
guideId
).
orElseThrow
(
NoSuchElementException:
:
new
);
String
targetId
=
guide
.
getId
();
String
parentId
=
guide
.
getParentId
();
List
<
Guide
>
children
=
getGuideListByParentId
(
targetId
);
if
(
cascade
)
{
for
(
Guide
g
:
children
)
{
guideRepository
.
delete
(
g
);
//guideContentRepository.deleteByGuideId(g.getId());
}
}
else
{
for
(
Guide
g
:
guideRepository
.
findAllByParentIdOrderByOrderAsc
(
targetId
))
{
g
.
setParentId
(
parentId
);
g
.
setOrder
(
getLastOrder
(
parentId
));
guideRepository
.
save
(
g
);
}
}
guideRepository
.
delete
(
guide
);
//guideContentRepository.deleteByGuideId(guide.getId());
return
guide
;
}
///////////////////////////////////////////////////////
// Guide Content CRUD
@Transactional
public
GuideContent
findContentById
(
String
guideId
)
throws
Exception
{
GuideContent
targetContent
=
guideContentRepository
.
findByGuideId
(
guideId
).
orElseThrow
(
NoSuchElementException:
:
new
);
List
<
Guide
>
sortedGuideList
=
new
ArrayList
<>();
for
(
Guide
guide
:
guideRepository
.
findAllByParentIdOrderByOrderAsc
(
""
))
{
sortedGuideList
.
add
(
guide
);
sortedGuideList
.
addAll
(
getGuideListByParentId
(
guide
.
getId
()));
}
for
(
int
i
=
0
;
i
<
sortedGuideList
.
size
();
i
++)
{
if
(
sortedGuideList
.
get
(
i
).
getId
().
equals
(
guideId
))
{
if
(
i
>
0
)
{
targetContent
.
setPrevContent
(
sortedGuideList
.
get
(
i
-
1
));
}
if
(
i
<
sortedGuideList
.
size
()
-
1
)
{
targetContent
.
setNextContent
(
sortedGuideList
.
get
(
i
+
1
));
}
}
}
return
targetContent
;
}
@Transactional
public
GuideContent
updateGuideContent
(
GuideContent
guideContent
)
throws
Exception
{
GuideContent
savedGuideContent
=
guideContentRepository
.
findById
(
guideContent
.
getId
()).
orElseThrow
(
NoSuchElementException:
:
new
);
savedGuideContent
.
setContent
(
guideContent
.
getContent
());
savedGuideContent
.
setUpdateDate
(
TimeManager
.
now
());
return
guideContentRepository
.
save
(
savedGuideContent
);
}
/////////////////////////////////////////////////
// Common
// 트리 구조로 자식 guide를 가져옴
private
List
<
Guide
>
getGuideTreeByParentId
(
String
parentId
)
{
List
<
Guide
>
children
=
new
ArrayList
<>();
for
(
Guide
childGuide
:
guideRepository
.
findAllByParentIdOrderByOrderAsc
(
parentId
))
{
childGuide
.
setChildren
(
guideRepository
.
findAllByParentIdOrderByOrderAsc
(
childGuide
.
getId
()));
children
.
add
(
childGuide
);
}
return
children
;
}
//트리 구조의 guide를 1차원 리스트로 가져옴
private
List
<
Guide
>
getGuideListByParentId
(
String
parentId
)
{
List
<
Guide
>
children
=
new
ArrayList
<>();
for
(
Guide
childGuide
:
guideRepository
.
findAllByParentIdOrderByOrderAsc
(
parentId
))
{
children
.
add
(
childGuide
);
children
.
addAll
(
guideRepository
.
findAllByParentIdOrderByOrderAsc
(
childGuide
.
getId
()));
}
return
children
;
}
//현재 뎁스의 마지막 순번을 가져옴
private
Integer
getLastOrder
(
String
parentId
)
{
return
guideRepository
.
countAllByParentId
(
parentId
);
}
}
docs-front/layouts/default.vue
View file @
48aae8f1
...
@@ -320,7 +320,7 @@ export default{
...
@@ -320,7 +320,7 @@ export default{
async
getGuideIndex
(){
async
getGuideIndex
(){
this
.
loadingPageList
=
true
this
.
loadingPageList
=
true
await
this
.
$axios
.
get
(
'/
test/index
'
)
await
this
.
$axios
.
get
(
'/
guide-index/all
'
)
.
then
(
res
=>
{
.
then
(
res
=>
{
this
.
rawIndexList
=
res
.
data
;
this
.
rawIndexList
=
res
.
data
;
this
.
getIndexTree
(
JSON
.
parse
(
JSON
.
stringify
(
res
.
data
)));
this
.
getIndexTree
(
JSON
.
parse
(
JSON
.
stringify
(
res
.
data
)));
...
@@ -422,7 +422,7 @@ export default{
...
@@ -422,7 +422,7 @@ export default{
return
return
}
}
this
.
$axios
.
post
(
'/
test
'
,
this
.
formData
)
this
.
$axios
.
post
(
'/
guide-index
'
,
this
.
formData
)
.
then
(
res
=>
{
.
then
(
res
=>
{
this
.
getGuideIndex
()
this
.
getGuideIndex
()
})
})
...
@@ -438,7 +438,7 @@ export default{
...
@@ -438,7 +438,7 @@ export default{
return
return
}
}
this
.
$axios
.
put
(
'/
test/
index'
,
this
.
formData
)
this
.
$axios
.
put
(
'/
guide-
index'
,
this
.
formData
)
.
then
(
res
=>
{
.
then
(
res
=>
{
this
.
getGuideIndex
()
this
.
getGuideIndex
()
})
})
...
@@ -447,9 +447,9 @@ export default{
...
@@ -447,9 +447,9 @@ export default{
})
})
},
},
removeIndex
(){
removeIndex
(){
this
.
$axios
.
delete
(
"/
test
"
,
{
this
.
$axios
.
delete
(
"/
guide-index
"
,
{
params
:{
params
:{
guideI
d
:
this
.
formData
.
id
,
i
d
:
this
.
formData
.
id
,
}
}
})
})
.
then
(
res
=>
{
.
then
(
res
=>
{
...
...
docs-front/pages/_guide/index.vue
View file @
48aae8f1
...
@@ -143,9 +143,9 @@ export default {
...
@@ -143,9 +143,9 @@ export default {
methods
:{
methods
:{
async
getGuide
(
id
){
async
getGuide
(
id
){
this
.
loading
=
true
this
.
loading
=
true
await
this
.
$axios
.
get
(
'/
test
'
,{
await
this
.
$axios
.
get
(
'/
guide-index
'
,{
params
:{
params
:{
guideId
:
id
id
}
}
})
})
.
then
(
res
=>
{
.
then
(
res
=>
{
...
...
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