Skip to content
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

feat: order professional translation #2621

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.tolgee.hateoas

import io.tolgee.dtos.Avatar
import org.springframework.hateoas.RepresentationModel

data class TranslationAgencySimpleModel(
var id: Long = 0L,
var name: String = "",
var url: String? = "",
val avatar: Avatar?,
): RepresentationModel<TranslationAgencySimpleModel>()

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.tolgee.hateoas.task

import io.tolgee.hateoas.TranslationAgencySimpleModel
import io.tolgee.hateoas.language.LanguageModel
import io.tolgee.hateoas.userAccount.SimpleUserAccountModel
import io.tolgee.model.enums.TaskState
Expand All @@ -24,4 +25,5 @@ class TaskModel(
var createdAt: Long? = 0,
var closedAt: Long? = null,
var state: TaskState = TaskState.IN_PROGRESS,
var agency: TranslationAgencySimpleModel? = null,
) : RepresentationModel<TaskModel>()
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.tolgee.hateoas.translationAgency

import io.tolgee.dtos.Avatar
import io.tolgee.hateoas.task.TaskModel
import org.springframework.hateoas.RepresentationModel
import org.springframework.hateoas.server.core.Relation

@Relation(collectionRelation = "translationAgencies", itemRelation = "translationAgency")
class TranslationAgencyModel(
var id: Long = 0L,
var name: String = "",
var description: String? = "",
var services: List<String> = listOf(),
var url: String? = "",
val avatar: Avatar?,
) : RepresentationModel<TaskModel>()
4 changes: 4 additions & 0 deletions backend/data/src/main/kotlin/io/tolgee/model/task/Task.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import io.tolgee.model.StandardAuditModel
import io.tolgee.model.UserAccount
import io.tolgee.model.enums.TaskState
import io.tolgee.model.enums.TaskType
import io.tolgee.model.translationAgency.TranslationAgency
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.EnumType
Expand Down Expand Up @@ -87,4 +88,7 @@ class Task : StandardAuditModel() {

@ActivityLoggedProp
var closedAt: Date? = null

@ManyToOne(fetch = FetchType.LAZY, optional = true)
var agency: TranslationAgency? = null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package io.tolgee.model.translationAgency

import io.hypersistence.utils.hibernate.type.json.JsonBinaryType
import io.tolgee.model.EntityWithId
import io.tolgee.model.ModelWithAvatar
import io.tolgee.model.StandardAuditModel
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.Table
import jakarta.validation.constraints.Size
import org.hibernate.annotations.Type

@Entity
@Table()
class TranslationAgency : StandardAuditModel(), ModelWithAvatar, EntityWithId {
@field:Size(max = 255)
@Column(length = 255)
var name: String = ""

@field:Size(max = 2000)
@Column(length = 2000)
var description: String? = null

@Type(JsonBinaryType::class)
@Column(columnDefinition = "jsonb")
var services: MutableList<String> = mutableListOf()

@field:Size(max = 255)
@Column(length = 255)
var url: String? = null

override var avatarHash: String? = null
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import io.tolgee.model.UserAccount
import io.tolgee.model.enums.TaskState
import io.tolgee.model.enums.TaskType
import io.tolgee.model.task.TaskKey
import io.tolgee.model.translationAgency.TranslationAgency
import java.util.*

data class TaskWithScopeView(
Expand All @@ -26,4 +27,5 @@ data class TaskWithScopeView(
val doneItems: Long,
val baseWordCount: Long,
val baseCharacterCount: Long,
val agency: TranslationAgency?,
)
12 changes: 9 additions & 3 deletions backend/data/src/main/kotlin/io/tolgee/service/AvatarService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,15 @@ class AvatarService(
fun storeAvatarFiles(
avatar: InputStream,
entity: ModelWithAvatar,
dimension: Dimension? = null,
thumbnailSize: Int? = null,
): String {
val dim = dimension ?: Dimension(200, 200)
val thumbSize = thumbnailSize ?: 50
val avatarBytes = avatar.readAllBytes()
val converter = ImageConverter(avatarBytes.inputStream())
val large = converter.getImage(-1f, Dimension(200, 200)).toByteArray()
val thumb = converter.getThumbnail(50).toByteArray()
val large = converter.getImage(-1f, dim).toByteArray()
val thumb = converter.getThumbnail(thumbSize).toByteArray()
val idByteArray = "${entity::class.simpleName}-${entity.id}---".toByteArray()
val bytesToHash = idByteArray + large
val hashBinary = MessageDigest.getInstance("SHA-256").digest(bytesToHash)
Expand All @@ -48,8 +52,10 @@ class AvatarService(
fun setAvatar(
entity: ModelWithAvatar,
avatar: InputStream,
dimension: Dimension? = null,
thumbnailSize: Int? = null,
) {
val hash = storeAvatarFiles(avatar, entity)
val hash = storeAvatarFiles(avatar, entity, dimension, thumbnailSize)
removeAvatar(entity)
entity.avatarHash = hash
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import org.springframework.data.domain.PageRequest
import org.springframework.data.domain.Pageable
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.awt.Dimension
import java.io.InputStream
import io.tolgee.dtos.cacheable.OrganizationDto as CachedOrganizationDto

Expand Down Expand Up @@ -301,7 +302,7 @@ class OrganizationService(
organization: Organization,
avatar: InputStream,
) {
avatarService.setAvatar(organization, avatar)
avatarService.setAvatar(organization, avatar, Dimension(300, 60))
}

/**
Expand Down
Loading
Loading