add EntryDTO
This commit is contained in:
parent
80292af22a
commit
52033fe77f
|
|
@ -1,7 +1,9 @@
|
||||||
package org.octopus.internal.services
|
package org.octopus.internal.services
|
||||||
|
|
||||||
import org.octopus.internal.common.models.Entry
|
import org.octopus.internal.common.models.Entry
|
||||||
|
import org.octopus.internal.web.utils.dtos.EntryDto
|
||||||
|
|
||||||
interface EntryService {
|
interface EntryService {
|
||||||
|
fun createEntry(entry: EntryDto)
|
||||||
fun getAllEntries(): MutableList<Entry>
|
fun getAllEntries(): MutableList<Entry>
|
||||||
}
|
}
|
||||||
|
|
@ -4,12 +4,17 @@ import org.octopus.internal.common.enums.EEntryType
|
||||||
import org.octopus.internal.common.models.Entry
|
import org.octopus.internal.common.models.Entry
|
||||||
import org.octopus.internal.repositories.EntryRepository
|
import org.octopus.internal.repositories.EntryRepository
|
||||||
import org.octopus.internal.services.EntryService
|
import org.octopus.internal.services.EntryService
|
||||||
|
import org.octopus.internal.web.utils.dtos.EntryDto
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
class EntryServiceImpl(val repo: EntryRepository) : EntryService {
|
class EntryServiceImpl(val repo: EntryRepository) : EntryService {
|
||||||
|
override fun createEntry(entry: EntryDto) {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
override fun getAllEntries(): MutableList<Entry> {
|
override fun getAllEntries(): MutableList<Entry> {
|
||||||
return repo.getA
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
package org.octopus.internal.web.utils.dtos
|
|
||||||
|
|
||||||
import org.octopus.internal.web.utils.dtos.validators.UsernameValidator
|
|
||||||
|
|
||||||
data class AddRoleDto(
|
|
||||||
@field:UsernameValidator.Validate
|
|
||||||
val username: String
|
|
||||||
)
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
package org.octopus.internal.web.utils.dtos
|
|
||||||
|
|
||||||
import org.octopus.internal.web.utils.dtos.validators.DniValidator
|
|
||||||
import org.octopus.internal.web.utils.dtos.validators.ExpValidator
|
|
||||||
import org.octopus.internal.web.utils.dtos.validators.NameValidator
|
|
||||||
import org.octopus.internal.web.utils.dtos.validators.PhoneValidator
|
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
data class ClientDto(
|
|
||||||
@field:NameValidator.Validate
|
|
||||||
val name: String,
|
|
||||||
@field:NameValidator.Validate
|
|
||||||
val surname: String,
|
|
||||||
@field:DniValidator.Validate
|
|
||||||
val dni: String,
|
|
||||||
@field:PhoneValidator.Validate
|
|
||||||
val phone: String,
|
|
||||||
@field:ExpValidator.Validate
|
|
||||||
val numExp: String,
|
|
||||||
@field:ExpValidator.Validate
|
|
||||||
val numUser: String,
|
|
||||||
val dateOfBirth: Date,
|
|
||||||
val deactivated: Boolean? = false
|
|
||||||
)
|
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
package org.octopus.internal.web.utils.dtos
|
||||||
|
|
||||||
|
import org.octopus.internal.web.utils.dtos.validators.EntryMonthValidator
|
||||||
|
import org.octopus.internal.web.utils.dtos.validators.EntryTypeValidator
|
||||||
|
import java.util.Date
|
||||||
|
|
||||||
|
data class EntryDto(
|
||||||
|
@field:EntryTypeValidator.Validate
|
||||||
|
val type: String,
|
||||||
|
val amount: Double,
|
||||||
|
val fixedDate: Date?,
|
||||||
|
val recurrent: Boolean?,
|
||||||
|
@field:EntryMonthValidator.Validate
|
||||||
|
val recurrentMonths: List<Int>?,
|
||||||
|
val endDate: Date?
|
||||||
|
|
||||||
|
)
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
package org.octopus.internal.web.utils.dtos
|
|
||||||
|
|
||||||
import org.octopus.internal.web.utils.dtos.validators.B64Validator
|
|
||||||
import org.octopus.internal.web.utils.dtos.validators.UsernameValidator
|
|
||||||
|
|
||||||
data class UserAuthDto(
|
|
||||||
@field:UsernameValidator.Validate
|
|
||||||
val username: String,
|
|
||||||
@field:B64Validator.Validate
|
|
||||||
val password: String
|
|
||||||
)
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
package org.octopus.internal.web.utils.dtos
|
|
||||||
|
|
||||||
import org.octopus.internal.web.utils.dtos.validators.DniValidator
|
|
||||||
import org.octopus.internal.web.utils.dtos.validators.EmailValidator
|
|
||||||
import org.octopus.internal.web.utils.dtos.validators.NameValidator
|
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
data class WorkerDto(
|
|
||||||
@field:NameValidator.Validate
|
|
||||||
val name: String,
|
|
||||||
@field:NameValidator.Validate
|
|
||||||
val surname: String,
|
|
||||||
@field:DniValidator.Validate
|
|
||||||
val dni: String,
|
|
||||||
val dateOfBirth: Date,
|
|
||||||
@field:EmailValidator.Validate
|
|
||||||
val email: String
|
|
||||||
)
|
|
||||||
|
|
@ -1,33 +0,0 @@
|
||||||
package org.octopus.internal.web.utils.dtos.validators
|
|
||||||
|
|
||||||
import jakarta.validation.Constraint
|
|
||||||
import jakarta.validation.ConstraintValidator
|
|
||||||
import jakarta.validation.ConstraintValidatorContext
|
|
||||||
import jakarta.validation.Payload
|
|
||||||
import kotlin.reflect.KClass
|
|
||||||
|
|
||||||
|
|
||||||
class B64Validator : ConstraintValidator<B64Validator.Validate, String> {
|
|
||||||
override fun isValid(value: String?, context: ConstraintValidatorContext): Boolean {
|
|
||||||
val pattern = Regex("^[-A-Za-z0-9+/]*={0,3}\$")
|
|
||||||
if (value == null || value.matches(pattern)) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
context.disableDefaultConstraintViolation()
|
|
||||||
context.buildConstraintViolationWithTemplate("Invalid value '$value' : this is not b64")
|
|
||||||
.addConstraintViolation()
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
@Target(AnnotationTarget.FIELD, AnnotationTarget.PROPERTY, AnnotationTarget.VALUE_PARAMETER)
|
|
||||||
@Retention(AnnotationRetention.RUNTIME)
|
|
||||||
@MustBeDocumented
|
|
||||||
@Constraint(validatedBy = [B64Validator::class])
|
|
||||||
annotation class Validate(
|
|
||||||
val message: String = "",
|
|
||||||
val groups: Array<KClass<*>> = [],
|
|
||||||
val payload: Array<KClass<out Payload>> = []
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
package org.octopus.internal.web.utils.dtos.validators
|
|
||||||
|
|
||||||
import jakarta.validation.Constraint
|
|
||||||
import jakarta.validation.ConstraintValidator
|
|
||||||
import jakarta.validation.ConstraintValidatorContext
|
|
||||||
import jakarta.validation.Payload
|
|
||||||
import kotlin.reflect.KClass
|
|
||||||
|
|
||||||
|
|
||||||
class DniValidator : ConstraintValidator<DniValidator.Validate, String> {
|
|
||||||
override fun isValid(value: String?, context: ConstraintValidatorContext): Boolean {
|
|
||||||
val pattern = Regex("^\\d{8}[A-Z]$")
|
|
||||||
|
|
||||||
if (value == null || value.matches(pattern)) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
context.disableDefaultConstraintViolation()
|
|
||||||
context.buildConstraintViolationWithTemplate("Invalid value '$value' : 8 numbers and a letter are expected.")
|
|
||||||
.addConstraintViolation()
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
@Target(AnnotationTarget.FIELD, AnnotationTarget.PROPERTY, AnnotationTarget.VALUE_PARAMETER)
|
|
||||||
@Retention(AnnotationRetention.RUNTIME)
|
|
||||||
@MustBeDocumented
|
|
||||||
@Constraint(validatedBy = [DniValidator::class])
|
|
||||||
annotation class Validate(
|
|
||||||
val message: String = "",
|
|
||||||
val groups: Array<KClass<*>> = [],
|
|
||||||
val payload: Array<KClass<out Payload>> = []
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
@ -1,33 +0,0 @@
|
||||||
package org.octopus.internal.web.utils.dtos.validators
|
|
||||||
|
|
||||||
import jakarta.validation.Constraint
|
|
||||||
import jakarta.validation.ConstraintValidator
|
|
||||||
import jakarta.validation.ConstraintValidatorContext
|
|
||||||
import jakarta.validation.Payload
|
|
||||||
import kotlin.reflect.KClass
|
|
||||||
|
|
||||||
|
|
||||||
class EmailValidator : ConstraintValidator<EmailValidator.Validate, String> {
|
|
||||||
override fun isValid(value: String?, context: ConstraintValidatorContext): Boolean {
|
|
||||||
val pattern = Regex("^(?=.{1,64}@.{1,255}$)([a-zA-Z0-9._%+-]{1,64})@([a-zA-Z0-9.-]+\\.[a-zA-Z]{2,})$")
|
|
||||||
if (value == null || value.matches(pattern)) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
context.disableDefaultConstraintViolation()
|
|
||||||
context.buildConstraintViolationWithTemplate("Invalid value '$value' : Email pattern is wrong.")
|
|
||||||
.addConstraintViolation()
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
@Target(AnnotationTarget.FIELD, AnnotationTarget.PROPERTY, AnnotationTarget.VALUE_PARAMETER)
|
|
||||||
@Retention(AnnotationRetention.RUNTIME)
|
|
||||||
@MustBeDocumented
|
|
||||||
@Constraint(validatedBy = [EmailValidator::class])
|
|
||||||
annotation class Validate(
|
|
||||||
val message: String = "",
|
|
||||||
val groups: Array<KClass<*>> = [],
|
|
||||||
val payload: Array<KClass<out Payload>> = []
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,39 @@
|
||||||
|
package org.octopus.internal.web.utils.dtos.validators
|
||||||
|
|
||||||
|
import jakarta.validation.Constraint
|
||||||
|
import jakarta.validation.ConstraintValidator
|
||||||
|
import jakarta.validation.ConstraintValidatorContext
|
||||||
|
import jakarta.validation.Payload
|
||||||
|
import org.octopus.internal.common.enums.EEntryType
|
||||||
|
import java.time.Month
|
||||||
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
|
|
||||||
|
class EntryMonthValidator : ConstraintValidator<EntryMonthValidator.Validate, List<Int>?> {
|
||||||
|
override fun isValid(value: List<Int>?, context: ConstraintValidatorContext): Boolean {
|
||||||
|
val monthInt = Month.entries.map { m -> m.value }
|
||||||
|
if (value == null) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
val allMatched = value.all { v -> monthInt.contains(v) }
|
||||||
|
|
||||||
|
if (!allMatched) {
|
||||||
|
context.disableDefaultConstraintViolation()
|
||||||
|
context.buildConstraintViolationWithTemplate("Invalid. '$value' contains at least a value outside [1,12] range.")
|
||||||
|
.addConstraintViolation()
|
||||||
|
}
|
||||||
|
|
||||||
|
return allMatched
|
||||||
|
}
|
||||||
|
|
||||||
|
@Target(AnnotationTarget.FIELD, AnnotationTarget.PROPERTY, AnnotationTarget.VALUE_PARAMETER)
|
||||||
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
|
@MustBeDocumented
|
||||||
|
@Constraint(validatedBy = [EntryMonthValidator::class])
|
||||||
|
annotation class Validate(
|
||||||
|
val message: String = "",
|
||||||
|
val groups: Array<KClass<*>> = [],
|
||||||
|
val payload: Array<KClass<out Payload>> = []
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
package org.octopus.internal.web.utils.dtos.validators
|
||||||
|
|
||||||
|
import jakarta.validation.Constraint
|
||||||
|
import jakarta.validation.ConstraintValidator
|
||||||
|
import jakarta.validation.ConstraintValidatorContext
|
||||||
|
import jakarta.validation.Payload
|
||||||
|
import org.octopus.internal.common.enums.EEntryType
|
||||||
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
|
|
||||||
|
class EntryTypeValidator : ConstraintValidator<EntryTypeValidator.Validate, String> {
|
||||||
|
override fun isValid(value: String, context: ConstraintValidatorContext): Boolean {
|
||||||
|
val typeNames = EEntryType.entries.map {e -> e.name}
|
||||||
|
val matchedType = typeNames.any { e -> e == value }
|
||||||
|
|
||||||
|
if (!matchedType) {
|
||||||
|
context.disableDefaultConstraintViolation()
|
||||||
|
context.buildConstraintViolationWithTemplate("Invalid. '$value' is not in accepted values: $typeNames")
|
||||||
|
.addConstraintViolation()
|
||||||
|
}
|
||||||
|
|
||||||
|
return matchedType
|
||||||
|
}
|
||||||
|
|
||||||
|
@Target(AnnotationTarget.FIELD, AnnotationTarget.PROPERTY, AnnotationTarget.VALUE_PARAMETER)
|
||||||
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
|
@MustBeDocumented
|
||||||
|
@Constraint(validatedBy = [EntryTypeValidator::class])
|
||||||
|
annotation class Validate(
|
||||||
|
val message: String = "",
|
||||||
|
val groups: Array<KClass<*>> = [],
|
||||||
|
val payload: Array<KClass<out Payload>> = []
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
package org.octopus.internal.web.utils.dtos.validators
|
|
||||||
|
|
||||||
import jakarta.validation.Constraint
|
|
||||||
import jakarta.validation.ConstraintValidator
|
|
||||||
import jakarta.validation.ConstraintValidatorContext
|
|
||||||
import jakarta.validation.Payload
|
|
||||||
import kotlin.reflect.KClass
|
|
||||||
|
|
||||||
|
|
||||||
class ExpValidator : ConstraintValidator<ExpValidator.Validate, String> {
|
|
||||||
override fun isValid(value: String?, context: ConstraintValidatorContext): Boolean {
|
|
||||||
val pattern = Regex("\\d+/[0-9]{4}")
|
|
||||||
|
|
||||||
if (value == null || value.matches(pattern)) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
context.disableDefaultConstraintViolation()
|
|
||||||
context.buildConstraintViolationWithTemplate("Invalid value '$value' : digits/full_year is expected")
|
|
||||||
.addConstraintViolation()
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
@Target(AnnotationTarget.FIELD, AnnotationTarget.PROPERTY, AnnotationTarget.VALUE_PARAMETER)
|
|
||||||
@Retention(AnnotationRetention.RUNTIME)
|
|
||||||
@MustBeDocumented
|
|
||||||
@Constraint(validatedBy = [ExpValidator::class])
|
|
||||||
annotation class Validate(
|
|
||||||
val message: String = "",
|
|
||||||
val groups: Array<KClass<*>> = [],
|
|
||||||
val payload: Array<KClass<out Payload>> = []
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
package org.octopus.internal.web.utils.dtos.validators
|
|
||||||
|
|
||||||
import jakarta.validation.Constraint
|
|
||||||
import jakarta.validation.ConstraintValidator
|
|
||||||
import jakarta.validation.ConstraintValidatorContext
|
|
||||||
import jakarta.validation.Payload
|
|
||||||
import kotlin.reflect.KClass
|
|
||||||
|
|
||||||
|
|
||||||
class NameValidator : ConstraintValidator<NameValidator.Validate, String> {
|
|
||||||
override fun isValid(value: String?, context: ConstraintValidatorContext): Boolean {
|
|
||||||
val pattern = Regex("^[A-Za-zÁÉÍÓÚÜÑáéíóúüñ]+(?:[-' ][A-Za-zÁÉÍÓÚÜÑáéíóúüñ]+)*$")
|
|
||||||
|
|
||||||
if (value == null || value.matches(pattern)) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
context.disableDefaultConstraintViolation()
|
|
||||||
context.buildConstraintViolationWithTemplate("Invalid value '$value' : Only letters, spaces, and dashes are allowed.")
|
|
||||||
.addConstraintViolation()
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
@Target(AnnotationTarget.FIELD, AnnotationTarget.PROPERTY, AnnotationTarget.VALUE_PARAMETER)
|
|
||||||
@Retention(AnnotationRetention.RUNTIME)
|
|
||||||
@MustBeDocumented
|
|
||||||
@Constraint(validatedBy = [NameValidator::class])
|
|
||||||
annotation class Validate(
|
|
||||||
val message: String = "",
|
|
||||||
val groups: Array<KClass<*>> = [],
|
|
||||||
val payload: Array<KClass<out Payload>> = []
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
package org.octopus.internal.web.utils.dtos.validators
|
|
||||||
|
|
||||||
import jakarta.validation.Constraint
|
|
||||||
import jakarta.validation.ConstraintValidator
|
|
||||||
import jakarta.validation.ConstraintValidatorContext
|
|
||||||
import jakarta.validation.Payload
|
|
||||||
import kotlin.reflect.KClass
|
|
||||||
|
|
||||||
|
|
||||||
class PhoneValidator : ConstraintValidator<PhoneValidator.Validate, String> {
|
|
||||||
override fun isValid(value: String?, context: ConstraintValidatorContext): Boolean {
|
|
||||||
val pattern = Regex("^[6789]\\d{8}$")
|
|
||||||
|
|
||||||
if (value == null || value.matches(pattern)) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
context.disableDefaultConstraintViolation()
|
|
||||||
context.buildConstraintViolationWithTemplate("Invalid value '$value' : Phone must start with [6,7,8,9] and 8 more numbers are expected.")
|
|
||||||
.addConstraintViolation()
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
@Target(AnnotationTarget.FIELD, AnnotationTarget.PROPERTY, AnnotationTarget.VALUE_PARAMETER)
|
|
||||||
@Retention(AnnotationRetention.RUNTIME)
|
|
||||||
@MustBeDocumented
|
|
||||||
@Constraint(validatedBy = [PhoneValidator::class])
|
|
||||||
annotation class Validate(
|
|
||||||
val message: String = "",
|
|
||||||
val groups: Array<KClass<*>> = [],
|
|
||||||
val payload: Array<KClass<out Payload>> = []
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
@ -1,33 +0,0 @@
|
||||||
package org.octopus.internal.web.utils.dtos.validators
|
|
||||||
|
|
||||||
import jakarta.validation.Constraint
|
|
||||||
import jakarta.validation.ConstraintValidator
|
|
||||||
import jakarta.validation.ConstraintValidatorContext
|
|
||||||
import jakarta.validation.Payload
|
|
||||||
import kotlin.reflect.KClass
|
|
||||||
|
|
||||||
|
|
||||||
class UsernameValidator : ConstraintValidator<UsernameValidator.Validate, String> {
|
|
||||||
override fun isValid(value: String?, context: ConstraintValidatorContext): Boolean {
|
|
||||||
val pattern = Regex("[a-z]{4,16}")
|
|
||||||
if (value == null || value.matches(pattern)) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
context.disableDefaultConstraintViolation()
|
|
||||||
context.buildConstraintViolationWithTemplate("Invalid value '$value' : Only 4 to 16 lowercase letters are allowed")
|
|
||||||
.addConstraintViolation()
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
@Target(AnnotationTarget.FIELD, AnnotationTarget.PROPERTY, AnnotationTarget.VALUE_PARAMETER)
|
|
||||||
@Retention(AnnotationRetention.RUNTIME)
|
|
||||||
@MustBeDocumented
|
|
||||||
@Constraint(validatedBy = [UsernameValidator::class])
|
|
||||||
annotation class Validate(
|
|
||||||
val message: String = "",
|
|
||||||
val groups: Array<KClass<*>> = [],
|
|
||||||
val payload: Array<KClass<out Payload>> = []
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue