Hi Channel! I don’t know if this is the right place as my question is related to AWS dynamodb with ...
a

asavio

over 2 years ago
Hi Channel! I don’t know if this is the right place as my question is related to AWS dynamodb with the V2 enhanced client (of course in Spring Boot + Kotlin). I’m following this blog post. I keep getting this exception from the dynamodb SDK when I try to write to dynamo -
java.lang.IllegalArgumentException: Attempt to execute an operation that requires a primary index without defining any primary key attributes in the table metadata.
. I define partition key in the data class. But it keeps complaining that I don’t have it!. Here’s the entire code:
package com.redacted.backend.monolith.app.controllers

import com.redacted.backend.monolith.config.dynamodb.createDynamoDbClient
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.graphql.data.method.annotation.Argument
import org.springframework.graphql.data.method.annotation.MutationMapping
import org.springframework.stereotype.Controller
import org.springframework.stereotype.Repository
import software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient
import software.amazon.awssdk.enhanced.dynamodb.TableSchema
import software.amazon.awssdk.enhanced.dynamodb.mapper.annotations.DynamoDbBean
import software.amazon.awssdk.enhanced.dynamodb.mapper.annotations.DynamoDbPartitionKey
import software.amazon.awssdk.enhanced.dynamodb.mapper.annotations.DynamoDbSortKey

@Controller
class DogController(private val repo: DogRepository) {

    @MutationMapping
    fun createDog(@Argument dog: Dog): String {
        return repo.create(dog)
    }

}

@DynamoDbBean
data class Dog(
    @get:DynamoDbPartitionKey
    val dogId: String? = null,
    @get:DynamoDbSortKey
    val rating: Int = 0,
    val name: String? = null
)

@Configuration
class DynamoClient(
    @Value("aws.dynamodb.access-key") private val dynamoDbAccessKey: String,
    @Value("aws.dynamodb.secret-key") private val dynamoDbSecretKey: String,
    @Value("aws.dynamodb.region") private val dynamoDbRegion: String
) {

    @Bean
    fun dynamoDbClient(): DynamoDbEnhancedClient = createDynamoDbClient(
        accessKey = dynamoDbAccessKey,
        secretKey = dynamoDbSecretKey,
        region = dynamoDbRegion
    )

}

@Repository
class DogRepository(private var client: DynamoDbEnhancedClient) {

    private val table = client.table("dog_table", TableSchema.fromBean(Dog::class.java))
    fun create(dog: Dog): String {
        table.putItem(dog)
        println("Written the dog to db successfully!")
        return "Written"
    }
}
Here’s the whole error: Any help would be very much appreciated! Error message is in the 🧵
So i am trying to make auto resizable Text in compose and I found a solution online. Code is given b...
a

Abdul Hafeez Sajid

over 2 years ago
So i am trying to make auto resizable Text in compose and I found a solution online. Code is given below:
@Composable
fun AutoResizeText(
    text: String,
    fontSizeRange: FontSizeRange,
    modifier: Modifier = Modifier,
    color: Color = Color.Unspecified,
    fontStyle: FontStyle? = null,
    fontWeight: FontWeight? = null,
    fontFamily: FontFamily? = null,
    letterSpacing: TextUnit = TextUnit.Unspecified,
    textDecoration: TextDecoration? = null,
    textAlign: TextAlign? = null,
    lineHeight: TextUnit = TextUnit.Unspecified,
    overflow: TextOverflow = TextOverflow.Clip,
    softWrap: Boolean = true,
    maxLines: Int = Int.MAX_VALUE,
    style: TextStyle = LocalTextStyle.current,
) {
    var fontSizeValue by remember { mutableStateOf(fontSizeRange.max.value) }
    var readyToDraw by remember { mutableStateOf(false) }

    Text(
        text = text,
        color = color,
        maxLines = maxLines,
        fontStyle = fontStyle,
        fontWeight = fontWeight,
        fontFamily = fontFamily,
        letterSpacing = letterSpacing,
        textDecoration = textDecoration,
        textAlign = textAlign,
        lineHeight = lineHeight,
        overflow = overflow,
        softWrap = softWrap,
        style = style,
        fontSize = fontSizeValue.sp,
        onTextLayout = {
            Timber.d("onTextLayout")
            if (it.didOverflowHeight && !readyToDraw) {
                Timber.d("Did Overflow height, calculate next font size value")
                val nextFontSizeValue = fontSizeValue - fontSizeRange.step.value
                if (nextFontSizeValue <= fontSizeRange.min.value) {
                    // Reached minimum, set minimum font size and it's readToDraw
                    fontSizeValue = fontSizeRange.min.value
                    readyToDraw = true
                } else {
                    // Text doesn't fit yet and haven't reached minimum text range, keep decreasing
                    fontSizeValue = nextFontSizeValue
                }
            } else {
                // Text fits before reaching the minimum, it's readyToDraw
                readyToDraw = true
            }
        },
        modifier = modifier.drawWithContent { if (readyToDraw) drawContent() }
    )
}

data class FontSizeRange(
    val min: TextUnit,
    val max: TextUnit,
    val step: TextUnit = DEFAULT_TEXT_STEP,
) {
    init {
        require(min < max) { "min should be less than max, $this" }
        require(step.value > 0) { "step should be greater than 0, $this" }
    }

    companion object {
        private val DEFAULT_TEXT_STEP = 1.sp
    }
}
Problem is above solution works only when I apply either border or maxLines property to modifier. Even though specific size is set. If I remove both border and maxlines then text does not auto resize. any help!
🧵 3