-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
36ffad3
commit 4bddd12
Showing
11 changed files
with
1,233 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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 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 pl.writeonly.omnibus | ||
|
||
import org.springframework.boot.runApplication | ||
import java.io.File | ||
import java.sql.Timestamp | ||
import java.time.LocalDate | ||
import java.time.LocalDateTime | ||
|
||
class GenerateTestData | ||
|
||
fun main(args: Array<String>) { | ||
|
||
val dataSql = File("src/main/resources/data.sql") | ||
dataSql.writeText("") | ||
|
||
repeat(100) { i -> | ||
val timestamp = Timestamp.valueOf(LocalDateTime.now().minusDays(100 - i.toLong())) | ||
dataSql.appendText( | ||
"INSERT INTO post(id, title, content, created)" | ||
+ " VALUES(${i}, 'Test Post ${i}', 'Content ${i}', TIMESTAMP '${timestamp}');\n" | ||
) | ||
} | ||
|
||
repeat(1000) { i -> | ||
val post_id = i/10 | ||
val timestamp = Timestamp.valueOf(LocalDateTime.now().minusDays(100 - i.toLong())) | ||
dataSql.appendText( | ||
"INSERT INTO comment(id, post_id, content, created)" | ||
+ " VALUES(${i}, ${post_id}, 'Content ${i}', TIMESTAMP '${timestamp}');\n" | ||
) | ||
} | ||
} |
This file contains 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
18 changes: 18 additions & 0 deletions
18
src/main/kotlin/pl/writeonly/omnibus/controller/PostController.kt
This file contains 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,18 @@ | ||
package pl.writeonly.omnibus.controller | ||
|
||
import io.swagger.v3.oas.annotations.tags.Tag | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
import pl.writeonly.omnibus.model.Post | ||
import pl.writeonly.omnibus.service.PostService | ||
|
||
@Tag(name = "Post", description = "the Post Api") | ||
@RestController | ||
class PostController(val service: PostService) { | ||
|
||
@GetMapping("/posts") | ||
fun getPosts(): List<Post> = service.getPosts() | ||
|
||
@GetMapping("/posts/{id}") | ||
fun getPost(id: Long): Post = service.getPost(id) | ||
} |
This file contains 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 pl.writeonly.omnibus.model | ||
|
||
import jakarta.persistence.Entity | ||
import jakarta.persistence.Id | ||
import java.time.LocalDateTime | ||
|
||
@Entity | ||
open class Comment( | ||
@Id | ||
open var id: Long?, | ||
open var content: String?, | ||
open var created: LocalDateTime? | ||
|
||
) |
This file contains 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,20 @@ | ||
package pl.writeonly.omnibus.model | ||
|
||
import jakarta.persistence.Entity | ||
import jakarta.persistence.Id | ||
import jakarta.persistence.JoinColumn | ||
import jakarta.persistence.OneToMany | ||
import java.time.LocalDateTime | ||
|
||
@Entity | ||
open class Post( | ||
@Id | ||
open var id: Long?, | ||
open var title: String?, | ||
open var content: String?, | ||
open var created: LocalDateTime?, | ||
|
||
@OneToMany(targetEntity = Comment::class) | ||
@JoinColumn(name = "post_id") | ||
open var comments: List<Comment> | ||
) |
9 changes: 9 additions & 0 deletions
9
src/main/kotlin/pl/writeonly/omnibus/repository/PostRepository.kt
This file contains 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,9 @@ | ||
package pl.writeonly.omnibus.repository | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository | ||
import org.springframework.stereotype.Repository | ||
import pl.writeonly.omnibus.model.Post | ||
|
||
@Repository | ||
interface PostRepository : JpaRepository<Post, Long> { | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/kotlin/pl/writeonly/omnibus/service/PostService.kt
This file contains 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,13 @@ | ||
package pl.writeonly.omnibus.service | ||
|
||
import org.springframework.stereotype.Service | ||
import pl.writeonly.omnibus.model.Post | ||
import pl.writeonly.omnibus.repository.PostRepository | ||
|
||
@Service | ||
class PostService(val repository: PostRepository) { | ||
|
||
fun getPosts(): List<Post> = repository.findAll() | ||
|
||
fun getPost(id: Long): Post = repository.getById(id) | ||
} |
This file contains 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 |
---|---|---|
@@ -1 +1,6 @@ | ||
spring.application.name=omnibus | ||
spring.jpa.hibernate.ddl.auto=none | ||
spring.jpa.show-sql=true | ||
#springdoc.swagger-ui.path=/swagger | ||
#springdoc.api-docs.path=/api-docs | ||
|
Oops, something went wrong.