forked from delta/codecharacter-server-2022
-
Notifications
You must be signed in to change notification settings - Fork 1
feat(dc): Add seeders for daily challenge and add get route for daily challenges #6
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
3167853
feat: daily challenges (incomplete)
ZaBarudo c6e8a74
feat: made /dc/get route working
ZaBarudo 470dec4
fix: Fixed import issues
ZaBarudo 7ba1426
fix: formatted
ZaBarudo 9c1e9ef
fix: completed todos
ZaBarudo 430c33f
fix: PR Requests (3/4 done)
ZaBarudo 308f8ae
Merge branch 'main' into daily_challenges
ZaBarudo 6136bb6
fix: Finished PR Requests
ZaBarudo faea3ff
fix: changed start_date format, added exception handling for getDC, r…
ZaBarudo df4637d
fix: secured /dc/get route
ZaBarudo c55209e
fix: added id to dcEntity, made dcObject
ZaBarudo 7c47afe
fix: fixed formatting for dcEntity, dcObject
ZaBarudo e1d284f
fix: added jsonproperty to dcObject, fixed typo
ZaBarudo 03a86dc
fix: Added a check if already seeded DCs
ZaBarudo c009cb8
fix: Fixed log message in DC_Seeder
ZaBarudo 20ac9d9
fix: Formatted
ZaBarudo 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
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 |
|---|---|---|
|
|
@@ -44,6 +44,7 @@ services: | |
| networks: | ||
| - common | ||
|
|
||
|
|
||
| networks: | ||
| common: | ||
| name: codecharacter_common | ||
|
|
||
11 changes: 9 additions & 2 deletions
11
...rd/DailyChallengeLeaderboardController.kt → ...ily_challenge/DailyChallengeController.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
16 changes: 16 additions & 0 deletions
16
server/src/main/kotlin/delta/codecharacter/server/daily_challenge/DailyChallengeEntity.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,16 @@ | ||
| package delta.codecharacter.server.daily_challenge | ||
|
|
||
| import delta.codecharacter.dtos.ChallengeTypeDto | ||
| import org.springframework.data.annotation.Id | ||
| import org.springframework.data.mongodb.core.mapping.Document | ||
| import java.util.UUID | ||
|
|
||
| @Document(collection = "daily_challenges") | ||
| data class DailyChallengeEntity( | ||
|
Ram-20062003 marked this conversation as resolved.
|
||
| @Id val id: UUID, | ||
| val day: Int, | ||
| val challName: String, | ||
| val challType: ChallengeTypeDto, | ||
| val chall: String, | ||
| val description: String?, | ||
| ) | ||
11 changes: 11 additions & 0 deletions
11
...er/src/main/kotlin/delta/codecharacter/server/daily_challenge/DailyChallengeRepository.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,11 @@ | ||
| package delta.codecharacter.server.daily_challenge | ||
|
|
||
| import org.springframework.data.mongodb.repository.MongoRepository | ||
| import org.springframework.stereotype.Repository | ||
| import java.util.Optional | ||
| import java.util.UUID | ||
|
|
||
| @Repository | ||
| interface DailyChallengeRepository : MongoRepository<DailyChallengeEntity, UUID> { | ||
| fun findByDay(day: Int): Optional<DailyChallengeEntity> | ||
| } |
40 changes: 40 additions & 0 deletions
40
server/src/main/kotlin/delta/codecharacter/server/daily_challenge/DailyChallengeService.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,40 @@ | ||
| package delta.codecharacter.server.daily_challenge | ||
|
|
||
| import delta.codecharacter.dtos.DailyChallengeGetRequestDto | ||
| import delta.codecharacter.server.exception.CustomException | ||
| import org.apache.http.HttpStatus | ||
| import org.springframework.beans.factory.annotation.Autowired | ||
| import org.springframework.beans.factory.annotation.Value | ||
| import org.springframework.stereotype.Service | ||
| import java.time.Duration | ||
| import java.time.Instant | ||
|
|
||
| @Service | ||
| class DailyChallengeService( | ||
| @Autowired private val dailyChallengeRepository: DailyChallengeRepository | ||
| ) { | ||
|
|
||
| @Value("\${environment.event-start-date}") val tempDate: String = "" | ||
|
|
||
| fun findNumberOfDays(): Int { | ||
| val givenDateTime = Instant.parse(tempDate) | ||
| val nowDateTime = Instant.now() | ||
| val period: Duration = Duration.between(givenDateTime, nowDateTime) | ||
| return period.toDays().toInt() | ||
| } | ||
|
|
||
| fun getDailyChallengeByDate(): DailyChallengeGetRequestDto { | ||
|
|
||
| val dc = | ||
| dailyChallengeRepository.findByDay(findNumberOfDays()).orElseThrow { | ||
| throw CustomException(org.springframework.http.HttpStatus.BAD_REQUEST, "Invalid Request") | ||
| } | ||
| return DailyChallengeGetRequestDto( | ||
|
Ram-20062003 marked this conversation as resolved.
|
||
| challName = dc.challName, | ||
| chall = dc.chall, | ||
| challType = dc.challType, | ||
| description = dc.description, | ||
| completionStatus = true | ||
| ) | ||
| } | ||
| } | ||
12 changes: 12 additions & 0 deletions
12
server/src/main/kotlin/delta/codecharacter/server/seeders/DailyChallengeObject.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,12 @@ | ||
| package delta.codecharacter.server.seeders | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty | ||
| import delta.codecharacter.dtos.ChallengeTypeDto | ||
|
|
||
| data class DailyChallengeObject( | ||
| @field:JsonProperty("day") val day: Int, | ||
| @field:JsonProperty("challName") val challName: String, | ||
| @field:JsonProperty("challType") val challType: ChallengeTypeDto, | ||
| @field:JsonProperty("chall") val chall: String, | ||
| @field:JsonProperty("description") val description: String?, | ||
| ) |
54 changes: 54 additions & 0 deletions
54
server/src/main/kotlin/delta/codecharacter/server/seeders/DailyChallengeSeeder.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,54 @@ | ||
| package delta.codecharacter.server.seeders | ||
|
|
||
| import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper | ||
| import com.fasterxml.jackson.module.kotlin.readValue | ||
| import delta.codecharacter.server.daily_challenge.DailyChallengeEntity | ||
| import delta.codecharacter.server.daily_challenge.DailyChallengeRepository | ||
| import org.slf4j.Logger | ||
| import org.slf4j.LoggerFactory | ||
| import org.springframework.beans.factory.annotation.Autowired | ||
| import org.springframework.boot.context.event.ApplicationReadyEvent | ||
| import org.springframework.context.event.EventListener | ||
| import org.springframework.stereotype.Component | ||
| import java.util.UUID | ||
|
|
||
| @Component | ||
| class DailyChallengeSeeder { | ||
|
|
||
| @Autowired private lateinit var dailyChallengeRepository: DailyChallengeRepository | ||
|
|
||
| private val logger: Logger = LoggerFactory.getLogger(DailyChallengeSeeder::class.java) | ||
| @EventListener(ApplicationReadyEvent::class) | ||
| fun doSomethingAfterStartup() { | ||
|
|
||
| if (dailyChallengeRepository.findAll().isEmpty()) { | ||
| logger.info("Seeding daily_challenges") | ||
|
|
||
| val jsonString = this::class.java.classLoader.getResource("dcConstants.json")?.readText() | ||
| if (!jsonString.isNullOrEmpty()) { | ||
| val objectMapper = jacksonObjectMapper() | ||
| val dcs: List<DailyChallengeObject> = objectMapper.readValue(jsonString) | ||
| var dcEntities: List<DailyChallengeEntity> = listOf() | ||
| dcs.forEach { | ||
| val id = UUID.randomUUID() | ||
| dcEntities = | ||
| dcEntities.plus( | ||
| DailyChallengeEntity( | ||
| id = id, | ||
| day = it.day, | ||
| chall = it.chall, | ||
| challName = it.challName, | ||
| challType = it.challType, | ||
| description = it.description | ||
| ) | ||
| ) | ||
| } | ||
| dailyChallengeRepository.saveAll(dcEntities) | ||
| } else { | ||
| logger.error("dcConstants.json is empty or doesn't exist") | ||
| } | ||
| } else { | ||
| logger.info("Daily Challenges seeded already") | ||
| } | ||
| } | ||
| } |
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
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,72 @@ | ||
| [ | ||
| { | ||
| "day": 0, | ||
| "challName": "Nisi sunt ea culpa est cillum cupidatat officia est.", | ||
| "challType": "CODE", | ||
| "chall": "Commodo duis sunt est ad duis ea anim nisi pariatur ut.", | ||
| "description": "Sunt ut est ea et dolor minim veniam quis id occaecat adipisicing quis." | ||
| }, | ||
| { | ||
| "day": 1, | ||
| "challName": "Exercitation esse ullamco irure quis dolor ut.", | ||
| "challType": "CODE", | ||
| "chall": "Aute nulla dolor consequat tempor commodo et aute occaecat est nulla esse reprehenderit anim tempor.", | ||
| "description": "Labore adipisicing culpa eiusmod labore mollit nisi ex fugiat nulla et voluptate laborum." | ||
| }, | ||
| { | ||
| "day": 2, | ||
| "challName": "Ex incididunt laboris ex pariatur irure aute qui occaecat ullamco consequat eu mollit fugiat culpa.", | ||
| "challType": "CODE", | ||
| "chall": "Id aliqua sit fugiat exercitation Lorem elit sint nisi commodo magna do.", | ||
| "description": "Laborum labore in excepteur do." | ||
| }, | ||
| { | ||
| "day": 3, | ||
| "challName": "Sint ut proident ipsum est nostrud nostrud pariatur anim id laboris velit officia est.", | ||
| "challType": "MAP", | ||
| "chall": "Incididunt id aute ad velit commodo aute cupidatat voluptate qui mollit.", | ||
| "description": "Esse do sint non enim dolore." | ||
| }, | ||
| { | ||
| "day": 4, | ||
| "challName": "Mollit qui in culpa nostrud veniam commodo fugiat tempor sit dolor duis id non.", | ||
| "challType": "MAP", | ||
| "chall": "Aliqua mollit sint sunt id elit mollit ipsum incididunt sint qui officia quis elit cillum.", | ||
| "description": "Et et labore ad ad ex elit et laboris deserunt eiusmod eiusmod reprehenderit eu." | ||
| }, | ||
| { | ||
| "day": 5, | ||
| "challName": "Est qui aliquip esse mollit.", | ||
| "challType": "MAP", | ||
| "chall": "Voluptate quis commodo mollit id deserunt.", | ||
| "description": "Aute voluptate amet aliquip irure." | ||
| }, | ||
| { | ||
| "day": 6, | ||
| "challName": "Duis anim tempor velit do fugiat tempor aute aliqua velit ut reprehenderit.", | ||
| "challType": "MAP", | ||
| "chall": "Laborum sunt anim duis nulla reprehenderit aliqua sunt veniam elit.", | ||
| "description": "Duis do est Lorem ex veniam." | ||
| }, | ||
| { | ||
| "day": 7, | ||
| "challName": "Labore velit consequat quis irure officia ad qui sint deserunt ea dolore nostrud consequat aute.", | ||
| "challType": "CODE", | ||
| "chall": "Occaecat id magna ut incididunt consectetur sunt magna labore.", | ||
| "description": "Irure qui minim aliqua sunt esse consequat commodo nostrud consectetur." | ||
| }, | ||
| { | ||
| "day": 8, | ||
| "challName": "Ullamco magna Lorem Lorem sit sunt.", | ||
| "challType": "MAP", | ||
| "chall": "Eiusmod voluptate aliqua duis duis sunt pariatur quis sint eiusmod adipisicing duis quis anim aute.", | ||
| "description": "Aliquip ad sunt do eu duis nulla deserunt." | ||
| }, | ||
| { | ||
| "day": 9, | ||
| "challName": "Est aliquip in ut ex velit.", | ||
| "challType": "CODE", | ||
| "chall": "Labore magna occaecat consectetur reprehenderit nostrud aliqua nostrud occaecat occaecat aliquip cillum anim ullamco.", | ||
| "description": "Commodo ex adipisicing dolore aliqua adipisicing laboris duis ad irure mollit." | ||
| } | ||
| ] |
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.