-
Notifications
You must be signed in to change notification settings - Fork 0
CRUD 완성 #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DongHyukki
wants to merge
19
commits into
review/kotlin
Choose a base branch
from
mark
base: review/kotlin
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
CRUD 완성 #5
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
0e4a4db
CRUD 완성
markkang-kakaoent 66b2bf3
JPA로 전환중
markkang-kakaoent 1d084ca
JPA적용
markkang-kakaoent 5b3b4b4
HIT COUNT 개발중
markkang-kakaoent 96c155d
AssertJ 적용
markkang-kakaoent 16aa5d6
TestCode 수정
markkang-kakaoent 37e1c3d
Event Listener
markkang-kakaoent 19d786a
Entity Listener
markkang-kakaoent edd5c5e
deploy
markkang-kakaoent 3466e73
deploy
markkang-kakaoent b771d92
deploy
markkang-kakaoent fc5c2ed
deploy
markkang-kakaoent 4a2f321
deploy
markkang-kakaoent 27c34d5
deploy
markkang-kakaoent bccf0de
deploy
markkang-kakaoent 40ea599
deploy
markkang-kakaoent b7af788
deploy
markkang-kakaoent 464b465
deploy
markkang-kakaoent 02a3ef6
123
markkang-kakaoent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| FROM adoptopenjdk/openjdk11:latest | ||
|
|
||
| ARG HEAP_SIZE | ||
| ENV HEAP_SIZE=${HEAP_SIZE:-512M} | ||
| ARG NEW_SIZE | ||
| ENV NEW_SIZE=${NEW_SIZE:-256M} | ||
|
|
||
| ADD . . | ||
|
|
||
| RUN ["./gradlew", "clean", "build", "-x","test"] | ||
|
|
||
| ENTRYPOINT java -server -Xms${HEAP_SIZE} -Xmx${HEAP_SIZE} -XX:NewSize=${NEW_SIZE} -XX:MaxNewSize=${NEW_SIZE} -Djava.net.preferIPv4Stack=true -Djava.security.egd=file:/dev/./urandom -jar /build/libs/springwebproject-0.0.1-SNAPSHOT.jar |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| apiVersion: apps/v1 | ||
| kind: Deployment | ||
| metadata: | ||
| name: mark-app | ||
| namespace: mark-space | ||
| labels: | ||
| app: mark-app | ||
| spec: | ||
| selector: | ||
| matchLabels: | ||
| app: mark-app | ||
| replicas: 1 | ||
| template: | ||
| metadata: | ||
| labels: | ||
| app: mark-app | ||
| spec: | ||
| containers: | ||
| - name: mark-app | ||
| image: idock.daumkakao.io/mark-d2hub/mark-repository:latest | ||
| imagePullPolicy: Always | ||
| resources: | ||
| limits: | ||
| cpu: 1 | ||
| memory: 300Mi | ||
| requests: | ||
| cpu: 1 | ||
| memory: 1Gi | ||
| ports: | ||
| - containerPort: 8080 | ||
| env: | ||
| - name: application_name | ||
| value: mark-app | ||
| - name: instance_name | ||
| value: "8080" | ||
| readinessProbe: | ||
| httpGet: | ||
| path: /health_check.html | ||
| port: 8080 | ||
| initialDelaySeconds: 10 | ||
| periodSeconds: 5 | ||
| lifecycle: | ||
| preStop: | ||
| exec: | ||
| command: ["/bin/sleep","2"] | ||
| terminationGracePeriodSeconds: 60 |
Binary file not shown.
32 changes: 32 additions & 0 deletions
32
src/main/kotlin/com/example/kotlinweb/board/controller/PostController.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package com.example.kotlinweb.board.controller | ||
| import com.example.kotlinweb.board.model.Post | ||
| import com.example.kotlinweb.board.service.BoardService | ||
| import org.springframework.http.HttpStatus | ||
| import org.springframework.http.ResponseEntity | ||
| import org.springframework.web.bind.annotation.* | ||
|
|
||
| @RestController | ||
| class BoardController(private val boardService: BoardService) { | ||
|
|
||
| @GetMapping(value = ["/board"]) | ||
| fun findAllPosts(): ResponseEntity<Any> { | ||
| return ResponseEntity(boardService.findPosts(), HttpStatus.OK); | ||
| } | ||
|
|
||
| @PostMapping(value = ["/board"]) | ||
| fun savePost(@RequestBody post: Post): ResponseEntity<Any> { | ||
| println("hello") | ||
| return ResponseEntity(boardService.savePost(post), HttpStatus.CREATED); | ||
| } | ||
|
|
||
| @PutMapping(value = ["/board/{id}"]) | ||
| fun updatePost(@RequestBody post: Post, @PathVariable id: String): ResponseEntity<Any> { | ||
| return ResponseEntity(boardService.updatePost(post), HttpStatus.OK); | ||
| } | ||
|
|
||
| @DeleteMapping(value = ["/board"]) | ||
| fun deletePost(@RequestBody post: Post): ResponseEntity<Any> { | ||
| return ResponseEntity(boardService.deletePost(post), HttpStatus.OK); | ||
| } | ||
|
|
||
| } | ||
43 changes: 43 additions & 0 deletions
43
src/main/kotlin/com/example/kotlinweb/board/event/PostEntityListener.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package com.example.kotlinweb.board.event | ||
|
|
||
| import com.example.kotlinweb.board.model.Post | ||
| import javax.persistence.* | ||
|
|
||
|
|
||
| class PostEntityListener { | ||
|
|
||
| @PostLoad | ||
| fun postLoad(post: Post?) { | ||
| println("post load: $post") | ||
| } | ||
|
|
||
| @PrePersist | ||
| fun prePersist(post: Post?) { | ||
| println("pre persist: $post") | ||
| } | ||
|
|
||
| @PostPersist | ||
| fun postPersist(post: Post?) { | ||
| println("post persist: $post") | ||
| } | ||
|
|
||
| @PreUpdate | ||
| fun preUpdate(post: Post?) { | ||
| println("pre update: $post") | ||
| } | ||
|
|
||
| @PostUpdate | ||
| fun postUpdate(post: Post?) { | ||
| println("post update: $post") | ||
| } | ||
|
|
||
| @PreRemove | ||
| fun preRemove(post: Post?) { | ||
| println("pre remove: $post") | ||
| } | ||
|
|
||
| @PostRemove | ||
| fun postRemove(post: Post?) { | ||
| println("post remove: $post") | ||
| } | ||
| } |
14 changes: 14 additions & 0 deletions
14
src/main/kotlin/com/example/kotlinweb/board/event/PostSaveEvent.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package com.example.kotlinweb.board.event | ||
|
|
||
| data class PostSaveEvent( | ||
| private val postId: Long, | ||
| private val message: String | ||
| ) { | ||
| fun getPostId(): Long { | ||
| return postId | ||
| } | ||
|
|
||
| fun getMessage(): String { | ||
| return message | ||
| } | ||
| } |
22 changes: 22 additions & 0 deletions
22
src/main/kotlin/com/example/kotlinweb/board/event/PostSaveEventHandler.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package com.example.kotlinweb.board.event | ||
|
|
||
| import com.example.kotlinweb.board.model.Notify | ||
| import com.example.kotlinweb.board.service.NotifyDTO | ||
| import com.example.kotlinweb.board.service.NotifyService | ||
| import org.springframework.context.event.EventListener | ||
| import org.springframework.stereotype.Component | ||
| import org.springframework.transaction.event.TransactionPhase | ||
| import org.springframework.transaction.event.TransactionalEventListener | ||
|
|
||
| @Component | ||
| class PostSaveEventHandler( | ||
| private val notifyService: NotifyService | ||
| ) { | ||
| // @EventListener | ||
| @TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) | ||
| fun postSaveEventListener(event: PostSaveEvent) { | ||
| println("Event Listen") | ||
| notifyService.saveNotify(Notify.of(event.getPostId().toString(), event.getMessage())) | ||
| notifyService.sendNotify(NotifyDTO(event.getMessage(), "0")) | ||
| } | ||
| } |
37 changes: 37 additions & 0 deletions
37
src/main/kotlin/com/example/kotlinweb/board/model/Notify.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package com.example.kotlinweb.board.model | ||
|
|
||
| import org.hibernate.annotations.CreationTimestamp | ||
| import org.hibernate.annotations.UpdateTimestamp | ||
| import java.time.LocalDateTime | ||
| import javax.persistence.* | ||
|
|
||
|
|
||
| @Entity | ||
| class Notify( | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.AUTO) | ||
| val id: Long?, | ||
|
|
||
| @Column | ||
| var postId: String, | ||
|
|
||
| @Column | ||
| val message: String | ||
|
|
||
| ) { | ||
| companion object { | ||
| fun of(postId: String, message: String): Notify { | ||
| return Notify(null, postId, message) | ||
| } | ||
| } | ||
|
|
||
| @Column | ||
| @CreationTimestamp | ||
| lateinit var createDate: LocalDateTime | ||
|
|
||
| @Column | ||
| @UpdateTimestamp | ||
| lateinit var updateDate: LocalDateTime | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package com.example.kotlinweb.board.model | ||
|
|
||
| import com.example.kotlinweb.board.event.PostEntityListener | ||
| import org.hibernate.annotations.CreationTimestamp | ||
| import org.hibernate.annotations.UpdateTimestamp | ||
| import java.time.LocalDateTime | ||
| import javax.persistence.* | ||
|
|
||
| @Entity | ||
| @EntityListeners(PostEntityListener::class) | ||
| class Post( | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.AUTO) | ||
| val id: Long, | ||
| @Column | ||
| var title: String, | ||
| @Column | ||
| val writer: String, | ||
| @Column | ||
| var text: String | ||
|
|
||
| ) { | ||
| @Column | ||
| var hitCount: Int = 0 | ||
|
|
||
| @Column | ||
| @CreationTimestamp | ||
| lateinit var createDate: LocalDateTime | ||
|
|
||
| @Column | ||
| @UpdateTimestamp | ||
| lateinit var updateDate: LocalDateTime | ||
|
|
||
| fun increaseHitCount() = hitCount++ | ||
| } |
10 changes: 10 additions & 0 deletions
10
src/main/kotlin/com/example/kotlinweb/board/repository/NotifyRepository.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package com.example.kotlinweb.board.repository | ||
|
|
||
| import com.example.kotlinweb.board.model.Notify | ||
| import org.springframework.data.jpa.repository.JpaRepository | ||
| import org.springframework.stereotype.Repository | ||
|
|
||
| @Repository | ||
| interface NotifyRepository : JpaRepository<Notify, Long> { | ||
|
|
||
| } |
10 changes: 10 additions & 0 deletions
10
src/main/kotlin/com/example/kotlinweb/board/repository/PostRepository.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package com.example.kotlinweb.board.repository | ||
|
|
||
| import com.example.kotlinweb.board.model.Post | ||
| import org.springframework.data.jpa.repository.JpaRepository | ||
| import org.springframework.stereotype.Repository | ||
|
|
||
| @Repository | ||
| interface PostRepository : JpaRepository<Post, Long> { | ||
|
|
||
| } |
49 changes: 49 additions & 0 deletions
49
src/main/kotlin/com/example/kotlinweb/board/service/BoardService.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package com.example.kotlinweb.board.service | ||
|
|
||
| import com.example.kotlinweb.board.event.PostSaveEvent | ||
| import com.example.kotlinweb.board.model.Post | ||
| import com.example.kotlinweb.board.repository.PostRepository | ||
| import org.springframework.context.ApplicationEventPublisher | ||
| import org.springframework.data.repository.findByIdOrNull | ||
| import org.springframework.stereotype.Service | ||
| import org.springframework.transaction.annotation.Transactional | ||
|
|
||
|
|
||
| @Service | ||
| class BoardService( | ||
| private val postRepository: PostRepository, | ||
| private val applicationEventPublisher: ApplicationEventPublisher | ||
| ) { | ||
|
|
||
| @Transactional | ||
| fun savePost(post: Post) { | ||
| postRepository.save(post) | ||
| applicationEventPublisher.publishEvent(PostSaveEvent(post.id, "게시글 작성이 완료 되었습니다.")) | ||
| } | ||
|
|
||
| @Transactional(readOnly = true) | ||
| fun findPostById(id: Long): Post? { | ||
| return postRepository.findByIdOrNull(id) | ||
| } | ||
|
|
||
| @Transactional(readOnly = true) | ||
| fun findPosts(): MutableList<Post> { | ||
| return postRepository.findAll() | ||
| } | ||
|
|
||
| @Transactional | ||
| fun updatePost(post: Post) { | ||
| print(post.toString()) | ||
| var foundPost: Post = postRepository.findByIdOrNull(post.id) as Post | ||
| foundPost.text = post.text | ||
| foundPost.title = post.title | ||
| } | ||
|
|
||
| @Transactional | ||
| fun deletePost(post: Post) { | ||
| var foundPost: Post = postRepository.findById(post.id) as Post | ||
| foundPost?.let { | ||
| postRepository.delete(post) | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
근데 delete는 body지원 안하지 않나요? (잘 모름..)