-
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
Showing
27 changed files
with
1,058 additions
and
63 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ name: db_backup | |
|
||
on: | ||
schedule: | ||
- cron: '0 3 * * *' | ||
- cron: '0 20 * * *' | ||
|
||
jobs: | ||
cron: | ||
|
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
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
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
33 changes: 33 additions & 0 deletions
33
src/main/kotlin/backend/itracker/tracker/product/controller/HomeController.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,33 @@ | ||
package backend.itracker.tracker.product.controller | ||
|
||
import backend.itracker.crawl.common.ProductCategory | ||
import backend.itracker.tracker.common.response.Pages | ||
import backend.itracker.tracker.product.handler.ProductHandlerImpl | ||
import backend.itracker.tracker.product.response.product.CommonProductModel | ||
import backend.itracker.tracker.product.vo.Limit | ||
import org.springframework.http.ResponseEntity | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.RequestParam | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@RestController | ||
class HomeController( | ||
private val productHandler: ProductHandlerImpl, | ||
) { | ||
|
||
@GetMapping("/api/v1/products") | ||
fun getAllProductsByFilter( | ||
@RequestParam(defaultValue = "10") limit: Int | ||
): ResponseEntity<Pages<CommonProductModel>> { | ||
val macbookAirs = | ||
productHandler.findTopDiscountPercentageProducts(ProductCategory.MACBOOK_AIR, Limit(limit)) | ||
val macbookPros = | ||
productHandler.findTopDiscountPercentageProducts(ProductCategory.MACBOOK_PRO, Limit(limit)) | ||
val airPods = | ||
productHandler.findTopDiscountPercentageProducts(ProductCategory.AIRPODS, Limit(limit)) | ||
|
||
val allProducts = macbookAirs + macbookPros + airPods | ||
return ResponseEntity.ok(Pages.withPagination(allProducts.sortedBy { it.discountPercentage() } | ||
.take(limit))) | ||
} | ||
} |
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
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
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 |
---|---|---|
|
@@ -43,4 +43,8 @@ data class AirPodsResponse( | |
) | ||
} | ||
} | ||
|
||
override fun discountPercentage(): Int { | ||
return discountPercentage | ||
} | ||
} |
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
38 changes: 38 additions & 0 deletions
38
src/test/kotlin/backend/itracker/config/AssuredTestConfig.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,38 @@ | ||
package backend.itracker.config | ||
|
||
import backend.itracker.tracker.common.PathParams | ||
import backend.itracker.tracker.common.QueryParams | ||
import io.restassured.RestAssured | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.springframework.boot.test.web.server.LocalServerPort | ||
import org.springframework.http.MediaType | ||
|
||
|
||
class AssuredTestConfig : ServiceTestConfig() { | ||
|
||
@BeforeEach | ||
fun assuredTestSetUp(@LocalServerPort port: Int) { | ||
RestAssured.port = port | ||
} | ||
|
||
fun get(url: String) = given() | ||
.`when`().get(url) | ||
.then().log().ifError() | ||
.extract() | ||
|
||
fun get(url: String, pathParams: PathParams) = given() | ||
.pathParams(pathParams.values) | ||
.`when`().get(url) | ||
.then().log().ifError() | ||
.extract() | ||
|
||
fun get(url: String, pathParams: PathParams, queryParams: QueryParams) = given() | ||
.pathParams(pathParams.values) | ||
.queryParams(queryParams.values) | ||
.`when`().get(url) | ||
.then().log().ifError() | ||
.extract() | ||
|
||
private fun given() = RestAssured.given().log().ifValidationFails() | ||
.contentType(MediaType.APPLICATION_JSON_VALUE) | ||
} |
36 changes: 36 additions & 0 deletions
36
src/test/kotlin/backend/itracker/config/DatabaseTruncater.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,36 @@ | ||
package backend.itracker.config | ||
|
||
import org.springframework.jdbc.core.JdbcTemplate | ||
import org.springframework.test.context.TestContext | ||
import org.springframework.test.context.support.AbstractTestExecutionListener | ||
|
||
class DatabaseTruncater : AbstractTestExecutionListener() { | ||
|
||
override fun afterTestMethod(testContext: TestContext) { | ||
val jdbcTemplate = getJdbcTemplate(testContext) | ||
val truncateQueries = getTruncateQueries(jdbcTemplate) | ||
truncateTables(jdbcTemplate, truncateQueries) | ||
} | ||
|
||
private fun getTruncateQueries(jdbcTemplate: JdbcTemplate): List<String> { | ||
return jdbcTemplate.queryForList( | ||
""" | ||
SELECT Concat('TRUNCATE TABLE ', TABLE_NAME, ';') AS q | ||
FROM INFORMATION_SCHEMA.TABLES | ||
WHERE TABLE_SCHEMA = 'PUBLIC' | ||
""", String::class.java | ||
) | ||
} | ||
|
||
private fun getJdbcTemplate(testContext: TestContext): JdbcTemplate { | ||
return testContext.applicationContext.getBean(JdbcTemplate::class.java) | ||
} | ||
|
||
private fun truncateTables(jdbcTemplate: JdbcTemplate, truncateQueries: List<String>) { | ||
execute(jdbcTemplate, "SET REFERENTIAL_INTEGRITY FALSE") | ||
truncateQueries.forEach { execute(jdbcTemplate, it) } | ||
execute(jdbcTemplate, "SET REFERENTIAL_INTEGRITY TRUE") | ||
} | ||
|
||
private fun execute(jdbcTemplate: JdbcTemplate, query: String) = jdbcTemplate.execute(query) | ||
} |
10 changes: 10 additions & 0 deletions
10
src/test/kotlin/backend/itracker/config/RepositoryTestConfig.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,10 @@ | ||
package backend.itracker.config | ||
|
||
import backend.itracker.crawl.macbook.domain.repository.MacbookRepository | ||
import org.springframework.beans.factory.annotation.Autowired | ||
|
||
abstract class RepositoryTestConfig { | ||
|
||
@Autowired | ||
lateinit var macbookRepository: MacbookRepository | ||
} |
20 changes: 20 additions & 0 deletions
20
src/test/kotlin/backend/itracker/config/ServiceTestConfig.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,20 @@ | ||
package backend.itracker.config | ||
|
||
import backend.itracker.crawl.macbook.domain.Macbook | ||
import backend.itracker.crawl.macbook.service.MacbookService | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.test.context.SpringBootTest | ||
import org.springframework.test.context.TestExecutionListeners | ||
|
||
@TestExecutionListeners(value = [DatabaseTruncater::class], mergeMode = TestExecutionListeners.MergeMode.MERGE_WITH_DEFAULTS) | ||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
abstract class ServiceTestConfig : RepositoryTestConfig() { | ||
|
||
@Autowired | ||
lateinit var macbookService: MacbookService | ||
|
||
fun saveMacbook(macbook: Macbook) : Macbook { | ||
macbookRepository.save(macbook) | ||
return macbook | ||
} | ||
} |
Oops, something went wrong.