-
-
Notifications
You must be signed in to change notification settings - Fork 202
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
135 changed files
with
3,025 additions
and
955 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
backend/api/src/main/kotlin/io/tolgee/api/v2/controllers/QuickStartController.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,42 @@ | ||
package io.tolgee.api.v2.controllers | ||
|
||
import io.tolgee.hateoas.quickStart.QuickStartModel | ||
import io.tolgee.hateoas.quickStart.QuickStartModelAssembler | ||
import io.tolgee.security.authentication.AuthenticationFacade | ||
import io.tolgee.service.QuickStartService | ||
import org.springframework.data.crossstore.ChangeSetPersister.NotFoundException | ||
import org.springframework.web.bind.annotation.PathVariable | ||
import org.springframework.web.bind.annotation.PutMapping | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@RestController | ||
@RequestMapping("/v2/quick-start") | ||
class QuickStartController( | ||
private val quickStartService: QuickStartService, | ||
private val quickStartModelAssembler: QuickStartModelAssembler, | ||
private val authenticationFacade: AuthenticationFacade | ||
) { | ||
@PutMapping("/steps/{step}/complete") | ||
fun completeGuideStep(@PathVariable("step") step: String): QuickStartModel { | ||
val entity = quickStartService.completeStep(authenticationFacade.authenticatedUser, step) | ||
?: throw NotFoundException() | ||
return quickStartModelAssembler.toModel(entity) | ||
} | ||
|
||
@PutMapping("/set-finished/{finished}") | ||
fun setFinishedState( | ||
@PathVariable finished: Boolean | ||
): QuickStartModel { | ||
val entity = quickStartService.setFinishState(authenticationFacade.authenticatedUser, finished) | ||
return quickStartModelAssembler.toModel(entity) | ||
} | ||
|
||
@PutMapping("/set-open/{open}") | ||
fun setOpenState( | ||
@PathVariable open: Boolean | ||
): QuickStartModel { | ||
val entity = quickStartService.setOpenState(authenticationFacade.authenticatedUser, open) | ||
return quickStartModelAssembler.toModel(entity) | ||
} | ||
} |
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
21 changes: 12 additions & 9 deletions
21
...d/api/src/main/kotlin/io/tolgee/hateoas/organization/PrivateOrganizationModelAssembler.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 |
---|---|---|
@@ -1,22 +1,25 @@ | ||
package io.tolgee.hateoas.organization | ||
|
||
import io.tolgee.api.v2.controllers.organization.OrganizationController | ||
import io.tolgee.constants.Feature | ||
import io.tolgee.hateoas.quickStart.QuickStartModelAssembler | ||
import io.tolgee.model.QuickStart | ||
import io.tolgee.model.views.OrganizationView | ||
import org.springframework.hateoas.server.mvc.RepresentationModelAssemblerSupport | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class PrivateOrganizationModelAssembler( | ||
private val organizationModelAssembler: OrganizationModelAssembler | ||
) : RepresentationModelAssemblerSupport<Pair<OrganizationView, Array<Feature>>, PrivateOrganizationModel>( | ||
OrganizationController::class.java, PrivateOrganizationModel::class.java | ||
private val organizationModelAssembler: OrganizationModelAssembler, | ||
private val quickStartModelAssembler: QuickStartModelAssembler | ||
) { | ||
override fun toModel(data: Pair<OrganizationView, Array<Feature>>): PrivateOrganizationModel { | ||
val (view, features) = data | ||
fun toModel( | ||
organization: OrganizationView, | ||
features: Array<Feature>, | ||
quickStart: QuickStart? | ||
): PrivateOrganizationModel { | ||
return PrivateOrganizationModel( | ||
organizationModel = organizationModelAssembler.toModel(view), | ||
enabledFeatures = features | ||
organizationModel = organizationModelAssembler.toModel(organization), | ||
enabledFeatures = features, | ||
quickStart = quickStart?.let { quickStartModelAssembler.toModel(it) } | ||
) | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
backend/api/src/main/kotlin/io/tolgee/hateoas/quickStart/QuickStartModel.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 io.tolgee.hateoas.quickStart | ||
|
||
import org.springframework.hateoas.RepresentationModel | ||
|
||
data class QuickStartModel( | ||
val finished: Boolean, | ||
val completedSteps: MutableList<String>, | ||
val open: Boolean | ||
) : RepresentationModel<QuickStartModel>() |
18 changes: 18 additions & 0 deletions
18
backend/api/src/main/kotlin/io/tolgee/hateoas/quickStart/QuickStartModelAssembler.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 io.tolgee.hateoas.quickStart | ||
|
||
import io.tolgee.model.QuickStart | ||
import org.springframework.hateoas.server.mvc.RepresentationModelAssemblerSupport | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class QuickStartModelAssembler() : RepresentationModelAssemblerSupport<QuickStart, QuickStartModel>( | ||
QuickStart::class.java, QuickStartModel::class.java | ||
) { | ||
override fun toModel(entity: QuickStart): QuickStartModel { | ||
return QuickStartModel( | ||
finished = entity.finished, | ||
completedSteps = entity.completedSteps, | ||
open = entity.open | ||
) | ||
} | ||
} |
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
50 changes: 50 additions & 0 deletions
50
backend/app/src/test/kotlin/io/tolgee/controllers/DemoProjectTest.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,50 @@ | ||
package io.tolgee.controllers | ||
|
||
import io.tolgee.component.demoProject.DemoProjectData | ||
import io.tolgee.dtos.request.auth.SignUpDto | ||
import io.tolgee.fixtures.andIsOk | ||
import io.tolgee.fixtures.waitForNotThrowing | ||
import io.tolgee.testing.AbstractControllerTest | ||
import io.tolgee.testing.assert | ||
import io.tolgee.testing.assertions.Assertions.assertThat | ||
import org.junit.jupiter.api.Test | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc | ||
|
||
@AutoConfigureMockMvc | ||
class DemoProjectTest : | ||
AbstractControllerTest() { | ||
|
||
@Test | ||
fun `creates demo project`() { | ||
val demoOrganization = "Oh my organization" | ||
val dto = SignUpDto( | ||
name = "Pavel Novak", | ||
password = "aaaaaaaaa", | ||
email = "aaaa@aaaa.com", | ||
organizationName = demoOrganization | ||
) | ||
performPost("/api/public/sign_up", dto).andIsOk | ||
val project = executeInNewTransaction { | ||
val organization = organizationRepository.findAllByName(demoOrganization).single() | ||
val project = organization.projects.single() | ||
assertThat(project.name).isEqualTo("Demo project") | ||
val keyCount = DemoProjectData.translations["en"]!!.size | ||
project.keys.assert.hasSize(keyCount) | ||
val key = project.keys.find { it.name == "add-item-add-button" }!! | ||
key.keyScreenshotReferences.assert.hasSize(1) | ||
val screenshot = key.keyScreenshotReferences.single().screenshot | ||
screenshot.keyScreenshotReferences.assert.hasSize(keyCount) | ||
key.translations.assert.hasSize(3) | ||
project | ||
} | ||
|
||
waitForNotThrowing { | ||
executeInNewTransaction { | ||
val stats = languageStatsService.getLanguageStats(project.id) | ||
stats.forEach { | ||
it.reviewedWords.assert.isGreaterThan(0) | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.