diff --git a/build.gradle.kts b/build.gradle.kts index 5678e4c..957e6d2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ plugins { } -group = "org.js" +group = "org.octopus" version = "0.0.1-SNAPSHOT" diff --git a/src/main/kotlin/org/js/lorca_core/common/dtos/ClientDto.kt b/src/main/kotlin/org/js/lorca_core/common/dtos/ClientDto.kt deleted file mode 100644 index ac70e2b..0000000 --- a/src/main/kotlin/org/js/lorca_core/common/dtos/ClientDto.kt +++ /dev/null @@ -1,10 +0,0 @@ -package org.js.lorca_core.common.dtos - -import org.js.lorca_core.common.dtos.validators.NameValidator - -data class ClientDto( - @field:NameValidator.Validate - val name: String, - @field:NameValidator.Validate - val surname: String -) \ No newline at end of file diff --git a/src/main/kotlin/org/js/lorca_core/common/dtos/UserAuthDto.kt b/src/main/kotlin/org/js/lorca_core/common/dtos/UserAuthDto.kt deleted file mode 100644 index 0d651e8..0000000 --- a/src/main/kotlin/org/js/lorca_core/common/dtos/UserAuthDto.kt +++ /dev/null @@ -1,11 +0,0 @@ -package org.js.lorca_core.common.dtos - -import org.js.lorca_core.common.dtos.validators.B64Validator -import org.js.lorca_core.common.dtos.validators.UsernameValidator - -data class UserAuthDto( - @field:UsernameValidator.Validate - val username: String, - @field:B64Validator.Validate - val password: String -) \ No newline at end of file diff --git a/src/main/kotlin/org/js/lorca_core/common/enums/EWorkerCategory.kt b/src/main/kotlin/org/js/lorca_core/common/enums/EWorkerCategory.kt deleted file mode 100644 index 9ffd36c..0000000 --- a/src/main/kotlin/org/js/lorca_core/common/enums/EWorkerCategory.kt +++ /dev/null @@ -1,5 +0,0 @@ -package org.js.lorca_core.common.enums - -enum class EWorkerCategory { - FISIO -} \ No newline at end of file diff --git a/src/main/kotlin/org/js/lorca_core/common/mappers/ClientMapper.kt b/src/main/kotlin/org/js/lorca_core/common/mappers/ClientMapper.kt deleted file mode 100644 index 7b8ec89..0000000 --- a/src/main/kotlin/org/js/lorca_core/common/mappers/ClientMapper.kt +++ /dev/null @@ -1,8 +0,0 @@ -package org.js.lorca_core.common.mappers - -import org.js.lorca_core.common.models.Client -import org.js.lorca_core.db.entities.ClientEntity -import org.mapstruct.Mapper - -@Mapper(componentModel = "spring") -interface ClientMapper : GenericMapper \ No newline at end of file diff --git a/src/main/kotlin/org/js/lorca_core/common/mappers/UserAuthClaimMapper.kt b/src/main/kotlin/org/js/lorca_core/common/mappers/UserAuthClaimMapper.kt deleted file mode 100644 index 3318638..0000000 --- a/src/main/kotlin/org/js/lorca_core/common/mappers/UserAuthClaimMapper.kt +++ /dev/null @@ -1,8 +0,0 @@ -package org.js.lorca_core.common.mappers - -import org.js.lorca_core.common.models.UserAuthClaim -import org.js.lorca_core.db.entities.UserAuthClaimEntity -import org.mapstruct.Mapper - -@Mapper(componentModel = "spring") -interface UserAuthClaimMapper : GenericMapper \ No newline at end of file diff --git a/src/main/kotlin/org/js/lorca_core/common/models/Client.kt b/src/main/kotlin/org/js/lorca_core/common/models/Client.kt deleted file mode 100644 index cb2f85d..0000000 --- a/src/main/kotlin/org/js/lorca_core/common/models/Client.kt +++ /dev/null @@ -1,7 +0,0 @@ -package org.js.lorca_core.common.models - -data class Client( - var id: Long?, - var name: String, - var surname: String -) \ No newline at end of file diff --git a/src/main/kotlin/org/js/lorca_core/common/models/UserAuthClaim.kt b/src/main/kotlin/org/js/lorca_core/common/models/UserAuthClaim.kt deleted file mode 100644 index e97100c..0000000 --- a/src/main/kotlin/org/js/lorca_core/common/models/UserAuthClaim.kt +++ /dev/null @@ -1,8 +0,0 @@ -package org.js.lorca_core.common.models - -import org.js.lorca_core.common.enums.EUserRoles - -data class UserAuthClaim( - var id: Long, - var name: EUserRoles -) \ No newline at end of file diff --git a/src/main/kotlin/org/js/lorca_core/common/responses/LoginResponse.kt b/src/main/kotlin/org/js/lorca_core/common/responses/LoginResponse.kt deleted file mode 100644 index ad683d2..0000000 --- a/src/main/kotlin/org/js/lorca_core/common/responses/LoginResponse.kt +++ /dev/null @@ -1,8 +0,0 @@ -package org.js.lorca_core.common.responses - -import org.js.lorca_core.common.models.Worker - -data class LoginResponse( - val token: String, - val userInfo: Worker? -) \ No newline at end of file diff --git a/src/main/kotlin/org/js/lorca_core/db/ClientJpa.kt b/src/main/kotlin/org/js/lorca_core/db/ClientJpa.kt deleted file mode 100644 index 525d81f..0000000 --- a/src/main/kotlin/org/js/lorca_core/db/ClientJpa.kt +++ /dev/null @@ -1,6 +0,0 @@ -package org.js.lorca_core.db - -import org.js.lorca_core.db.entities.ClientEntity -import org.springframework.data.jpa.repository.JpaRepository - -interface ClientJpa : JpaRepository \ No newline at end of file diff --git a/src/main/kotlin/org/js/lorca_core/db/WorkerCategoryJpa.kt b/src/main/kotlin/org/js/lorca_core/db/WorkerCategoryJpa.kt deleted file mode 100644 index 1f2a44e..0000000 --- a/src/main/kotlin/org/js/lorca_core/db/WorkerCategoryJpa.kt +++ /dev/null @@ -1,6 +0,0 @@ -package org.js.lorca_core.db - -import org.js.lorca_core.db.entities.ClientEntity -import org.springframework.data.jpa.repository.JpaRepository - -interface WorkerCategoryJpa : JpaRepository \ No newline at end of file diff --git a/src/main/kotlin/org/js/lorca_core/db/WorkerJpa.kt b/src/main/kotlin/org/js/lorca_core/db/WorkerJpa.kt deleted file mode 100644 index 34b1b50..0000000 --- a/src/main/kotlin/org/js/lorca_core/db/WorkerJpa.kt +++ /dev/null @@ -1,9 +0,0 @@ -package org.js.lorca_core.db - -import org.js.lorca_core.db.entities.WorkerEntity -import org.springframework.data.jpa.repository.JpaRepository -import java.util.* - -interface WorkerJpa : JpaRepository { - fun findByAuthUserUsr(username: String): Optional -} \ No newline at end of file diff --git a/src/main/kotlin/org/js/lorca_core/db/entities/UserAuthClaimEntity.kt b/src/main/kotlin/org/js/lorca_core/db/entities/UserAuthClaimEntity.kt deleted file mode 100644 index d9fc7be..0000000 --- a/src/main/kotlin/org/js/lorca_core/db/entities/UserAuthClaimEntity.kt +++ /dev/null @@ -1,14 +0,0 @@ -package org.js.lorca_core.db.entities - -import jakarta.persistence.Entity -import jakarta.persistence.GeneratedValue -import jakarta.persistence.GenerationType -import jakarta.persistence.Id -import org.js.lorca_core.common.enums.EUserRoles - -@Entity(name = "user_auth_claims") -data class UserAuthClaimEntity( - @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - var id: Long = 0L, - var name: EUserRoles -) \ No newline at end of file diff --git a/src/main/kotlin/org/js/lorca_core/repositories/ClientRepository.kt b/src/main/kotlin/org/js/lorca_core/repositories/ClientRepository.kt deleted file mode 100644 index f395d82..0000000 --- a/src/main/kotlin/org/js/lorca_core/repositories/ClientRepository.kt +++ /dev/null @@ -1,10 +0,0 @@ -package org.js.lorca_core.repositories - -import org.js.lorca_core.common.models.Client - -interface ClientRepository { - fun createClient(client: Client): Client - fun getAll(): MutableList - fun getById(id: Long): Client - -} diff --git a/src/main/kotlin/org/js/lorca_core/repositories/UserAuthRepository.kt b/src/main/kotlin/org/js/lorca_core/repositories/UserAuthRepository.kt deleted file mode 100644 index f964272..0000000 --- a/src/main/kotlin/org/js/lorca_core/repositories/UserAuthRepository.kt +++ /dev/null @@ -1,11 +0,0 @@ -package org.js.lorca_core.repositories - -import org.js.lorca_core.common.enums.EUserRoles -import org.js.lorca_core.db.entities.UserAuthEntity - -interface UserAuthRepository { - fun existsByUsername(username: String): Boolean - fun getByUsername(username: String): UserAuthEntity - fun save(userAuth: UserAuthEntity): UserAuthEntity - fun getClaimsForUser(user: UserAuthEntity): List -} \ No newline at end of file diff --git a/src/main/kotlin/org/js/lorca_core/repositories/WorkerRepository.kt b/src/main/kotlin/org/js/lorca_core/repositories/WorkerRepository.kt deleted file mode 100644 index 36bdde6..0000000 --- a/src/main/kotlin/org/js/lorca_core/repositories/WorkerRepository.kt +++ /dev/null @@ -1,10 +0,0 @@ -package org.js.lorca_core.repositories - -import org.js.lorca_core.common.models.Worker -import org.js.lorca_core.db.entities.UserAuthEntity - -interface WorkerRepository { - fun getByUsername(username: String): Worker? - fun createForUser(worker: Worker, userAuth: UserAuthEntity): Worker - fun getAll(): MutableList -} diff --git a/src/main/kotlin/org/js/lorca_core/repositories/impl/UserAuthRepositoryImpl.kt b/src/main/kotlin/org/js/lorca_core/repositories/impl/UserAuthRepositoryImpl.kt deleted file mode 100644 index 8745c5d..0000000 --- a/src/main/kotlin/org/js/lorca_core/repositories/impl/UserAuthRepositoryImpl.kt +++ /dev/null @@ -1,34 +0,0 @@ -package org.js.lorca_core.repositories.impl - -import org.js.lorca_core.common.enums.EBusinessException -import org.js.lorca_core.common.enums.EUserRoles -import org.js.lorca_core.common.exceptions.LorcaException -import org.js.lorca_core.common.mappers.UserAuthClaimMapper -import org.js.lorca_core.db.UserAuthJpa -import org.js.lorca_core.db.entities.UserAuthEntity -import org.js.lorca_core.repositories.UserAuthRepository -import org.springframework.stereotype.Component - -@Component -class UserAuthRepositoryImpl( - protected val jpa: UserAuthJpa, - protected val claimMapper: UserAuthClaimMapper -) : UserAuthRepository { - override fun getByUsername(username: String): UserAuthEntity { - return jpa.findByUsr(username) - .orElseThrow { LorcaException.create(EBusinessException.USER_NOT_FOUND, username) } - } - - override fun save(userAuth: UserAuthEntity): UserAuthEntity { - return jpa.save(userAuth) - } - - override fun getClaimsForUser(user: UserAuthEntity): List { - return claimMapper.toModels(user.claims).map { it.name }.toList() - } - - override fun existsByUsername(username: String): Boolean { - return jpa.existsByUsr(username) - } - -} \ No newline at end of file diff --git a/src/main/kotlin/org/js/lorca_core/services/AuthenticationService.kt b/src/main/kotlin/org/js/lorca_core/services/AuthenticationService.kt deleted file mode 100644 index 481991a..0000000 --- a/src/main/kotlin/org/js/lorca_core/services/AuthenticationService.kt +++ /dev/null @@ -1,10 +0,0 @@ -package org.js.lorca_core.services - -import org.js.lorca_core.common.dtos.UserAuthDto -import org.js.lorca_core.common.responses.LoginResponse - -interface AuthenticationService { - fun register(dto: UserAuthDto): Boolean - - fun login(dto: UserAuthDto): LoginResponse -} \ No newline at end of file diff --git a/src/main/kotlin/org/js/lorca_core/services/ClientService.kt b/src/main/kotlin/org/js/lorca_core/services/ClientService.kt deleted file mode 100644 index 7b22f30..0000000 --- a/src/main/kotlin/org/js/lorca_core/services/ClientService.kt +++ /dev/null @@ -1,10 +0,0 @@ -package org.js.lorca_core.services - -import org.js.lorca_core.common.dtos.ClientDto -import org.js.lorca_core.common.models.Client - -interface ClientService { - fun getAllClients(name: String?, surname: String?): MutableList - fun getClientById(id: Long): Client - fun createClient(clientDto: ClientDto): Client -} \ No newline at end of file diff --git a/src/main/kotlin/org/js/lorca_core/services/WorkerService.kt b/src/main/kotlin/org/js/lorca_core/services/WorkerService.kt deleted file mode 100644 index 96f8511..0000000 --- a/src/main/kotlin/org/js/lorca_core/services/WorkerService.kt +++ /dev/null @@ -1,8 +0,0 @@ -package org.js.lorca_core.services - -import org.js.lorca_core.common.models.Worker - -interface WorkerService { - fun createTestData() - fun getAllWorkers(): List -} \ No newline at end of file diff --git a/src/main/kotlin/org/js/lorca_core/services/impl/ClientServiceImpl.kt b/src/main/kotlin/org/js/lorca_core/services/impl/ClientServiceImpl.kt deleted file mode 100644 index ad5cf1f..0000000 --- a/src/main/kotlin/org/js/lorca_core/services/impl/ClientServiceImpl.kt +++ /dev/null @@ -1,22 +0,0 @@ -package org.js.lorca_core.services.impl - -import org.js.lorca_core.common.dtos.ClientDto -import org.js.lorca_core.common.models.Client -import org.js.lorca_core.repositories.ClientRepository -import org.js.lorca_core.services.ClientService -import org.springframework.stereotype.Service - -@Service -class ClientServiceImpl(val repo: ClientRepository) : ClientService { - override fun getAllClients(name: String?, surname: String?): MutableList { - return repo.getAll() - } - - override fun getClientById(id: Long): Client { - return repo.getById(id) - } - - override fun createClient(clientDto: ClientDto): Client { - return repo.createClient(Client(null, clientDto.name, clientDto.surname)) - } -} \ No newline at end of file diff --git a/src/main/kotlin/org/js/lorca_core/web/controllers/WorkerController.kt b/src/main/kotlin/org/js/lorca_core/web/controllers/WorkerController.kt deleted file mode 100644 index f29e5b4..0000000 --- a/src/main/kotlin/org/js/lorca_core/web/controllers/WorkerController.kt +++ /dev/null @@ -1,28 +0,0 @@ -package org.js.lorca_core.web.controllers - -import lombok.AllArgsConstructor -import org.js.lorca_core.common.models.Worker -import org.js.lorca_core.services.WorkerService -import org.js.lorca_core.web.advices.WebResponse -import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.PostMapping -import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.RestController - -@RestController -@RequestMapping("/workers") -@AllArgsConstructor -class WorkerController( - val workerService: WorkerService -) { - @GetMapping - fun getAllWorkers(): WebResponse> { - return WebResponse.ok(workerService.getAllWorkers()) - } - - @PostMapping - fun createTestData(): WebResponse { - workerService.createTestData() - return WebResponse.ok() - } -} \ No newline at end of file diff --git a/src/main/kotlin/org/js/lorca_core/LorcaCoreApplication.kt b/src/main/kotlin/org/octopus/lorca_core/LorcaCoreApplication.kt similarity index 69% rename from src/main/kotlin/org/js/lorca_core/LorcaCoreApplication.kt rename to src/main/kotlin/org/octopus/lorca_core/LorcaCoreApplication.kt index fde5ec1..993e8da 100644 --- a/src/main/kotlin/org/js/lorca_core/LorcaCoreApplication.kt +++ b/src/main/kotlin/org/octopus/lorca_core/LorcaCoreApplication.kt @@ -1,9 +1,9 @@ -package org.js.lorca_core +package org.octopus.lorca_core import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.runApplication -@SpringBootApplication(scanBasePackages = ["org.js.lorca_core"]) +@SpringBootApplication(scanBasePackages = ["org.octopus.lorca_core"]) class LorcaCoreApplication fun main(args: Array) { diff --git a/src/main/kotlin/org/js/lorca_core/common/enums/EBusinessException.kt b/src/main/kotlin/org/octopus/lorca_core/common/enums/EBusinessException.kt similarity index 67% rename from src/main/kotlin/org/js/lorca_core/common/enums/EBusinessException.kt rename to src/main/kotlin/org/octopus/lorca_core/common/enums/EBusinessException.kt index 70b8826..134ebd2 100644 --- a/src/main/kotlin/org/js/lorca_core/common/enums/EBusinessException.kt +++ b/src/main/kotlin/org/octopus/lorca_core/common/enums/EBusinessException.kt @@ -1,6 +1,7 @@ -package org.js.lorca_core.common.enums +package org.octopus.lorca_core.common.enums enum class EBusinessException(val msg: String) { + IMPOSSIBLE_ADD_ROLES("Impossible to add roles for username: '%s'. Check logs."), USER_ALREADY_EXISTS("Username: '%s' already exists"), USER_NOT_FOUND("Username: '%s' not found"), ENTITY_WITH_ID_NOT_FOUND("%s with id %s not found"), diff --git a/src/main/kotlin/org/js/lorca_core/common/enums/EUserRoles.kt b/src/main/kotlin/org/octopus/lorca_core/common/enums/EUserRoles.kt similarity index 54% rename from src/main/kotlin/org/js/lorca_core/common/enums/EUserRoles.kt rename to src/main/kotlin/org/octopus/lorca_core/common/enums/EUserRoles.kt index ad9cc00..7edd0e4 100644 --- a/src/main/kotlin/org/js/lorca_core/common/enums/EUserRoles.kt +++ b/src/main/kotlin/org/octopus/lorca_core/common/enums/EUserRoles.kt @@ -1,8 +1,9 @@ -package org.js.lorca_core.common.enums +package org.octopus.lorca_core.common.enums enum class EUserRoles(val role: String) { FISIO("FISIO"), PSICO("PSICO"), ALL("ALL"), - ADMIN("ADMIN") + ADMIN("ADMIN"), + BASE("BASE") } \ No newline at end of file diff --git a/src/main/kotlin/org/octopus/lorca_core/common/enums/EWorkerCategory.kt b/src/main/kotlin/org/octopus/lorca_core/common/enums/EWorkerCategory.kt new file mode 100644 index 0000000..292820c --- /dev/null +++ b/src/main/kotlin/org/octopus/lorca_core/common/enums/EWorkerCategory.kt @@ -0,0 +1,5 @@ +package org.octopus.lorca_core.common.enums + +enum class EWorkerCategory { + FISIO +} \ No newline at end of file diff --git a/src/main/kotlin/org/js/lorca_core/common/exceptions/LorcaException.kt b/src/main/kotlin/org/octopus/lorca_core/common/exceptions/LorcaException.kt similarity index 71% rename from src/main/kotlin/org/js/lorca_core/common/exceptions/LorcaException.kt rename to src/main/kotlin/org/octopus/lorca_core/common/exceptions/LorcaException.kt index ccdf920..6643ad5 100644 --- a/src/main/kotlin/org/js/lorca_core/common/exceptions/LorcaException.kt +++ b/src/main/kotlin/org/octopus/lorca_core/common/exceptions/LorcaException.kt @@ -1,6 +1,6 @@ -package org.js.lorca_core.common.exceptions +package org.octopus.lorca_core.common.exceptions -import org.js.lorca_core.common.enums.EBusinessException +import org.octopus.lorca_core.common.enums.EBusinessException class LorcaException(val ex: EBusinessException, override val message: String) : Exception() { diff --git a/src/main/kotlin/org/octopus/lorca_core/common/mappers/ClientMapper.kt b/src/main/kotlin/org/octopus/lorca_core/common/mappers/ClientMapper.kt new file mode 100644 index 0000000..be8a572 --- /dev/null +++ b/src/main/kotlin/org/octopus/lorca_core/common/mappers/ClientMapper.kt @@ -0,0 +1,8 @@ +package org.octopus.lorca_core.common.mappers + +import org.mapstruct.Mapper +import org.octopus.lorca_core.common.models.Client +import org.octopus.lorca_core.db.entities.ClientEntity + +@Mapper(componentModel = "spring") +interface ClientMapper : GenericMapper \ No newline at end of file diff --git a/src/main/kotlin/org/js/lorca_core/common/mappers/GenericMapper.kt b/src/main/kotlin/org/octopus/lorca_core/common/mappers/GenericMapper.kt similarity index 87% rename from src/main/kotlin/org/js/lorca_core/common/mappers/GenericMapper.kt rename to src/main/kotlin/org/octopus/lorca_core/common/mappers/GenericMapper.kt index 6ba717f..b8135ce 100644 --- a/src/main/kotlin/org/js/lorca_core/common/mappers/GenericMapper.kt +++ b/src/main/kotlin/org/octopus/lorca_core/common/mappers/GenericMapper.kt @@ -1,4 +1,4 @@ -package org.js.lorca_core.common.mappers +package org.octopus.lorca_core.common.mappers interface GenericMapper { diff --git a/src/main/kotlin/org/octopus/lorca_core/common/mappers/ReportMapper.kt b/src/main/kotlin/org/octopus/lorca_core/common/mappers/ReportMapper.kt new file mode 100644 index 0000000..f7f61dd --- /dev/null +++ b/src/main/kotlin/org/octopus/lorca_core/common/mappers/ReportMapper.kt @@ -0,0 +1,8 @@ +package org.octopus.lorca_core.common.mappers + +import org.mapstruct.Mapper +import org.octopus.lorca_core.common.models.Report +import org.octopus.lorca_core.db.entities.ReportEntity + +@Mapper(componentModel = "spring") +interface ReportMapper : GenericMapper \ No newline at end of file diff --git a/src/main/kotlin/org/js/lorca_core/common/mappers/WorkerMapper.kt b/src/main/kotlin/org/octopus/lorca_core/common/mappers/WorkerMapper.kt similarity index 63% rename from src/main/kotlin/org/js/lorca_core/common/mappers/WorkerMapper.kt rename to src/main/kotlin/org/octopus/lorca_core/common/mappers/WorkerMapper.kt index b498c9a..60d1119 100644 --- a/src/main/kotlin/org/js/lorca_core/common/mappers/WorkerMapper.kt +++ b/src/main/kotlin/org/octopus/lorca_core/common/mappers/WorkerMapper.kt @@ -1,9 +1,9 @@ -package org.js.lorca_core.common.mappers +package org.octopus.lorca_core.common.mappers -import org.js.lorca_core.common.models.Worker -import org.js.lorca_core.db.entities.WorkerEntity import org.mapstruct.Mapper import org.mapstruct.Mapping +import org.octopus.lorca_core.common.models.Worker +import org.octopus.lorca_core.db.entities.WorkerEntity @Mapper(componentModel = "spring") interface WorkerMapper : GenericMapper { diff --git a/src/main/kotlin/org/octopus/lorca_core/common/models/Client.kt b/src/main/kotlin/org/octopus/lorca_core/common/models/Client.kt new file mode 100644 index 0000000..c0b7f8d --- /dev/null +++ b/src/main/kotlin/org/octopus/lorca_core/common/models/Client.kt @@ -0,0 +1,8 @@ +package org.octopus.lorca_core.common.models + +data class Client( + var id: Long?, + var name: String, + var surname: String, + val deactivated: Boolean +) \ No newline at end of file diff --git a/src/main/kotlin/org/octopus/lorca_core/common/models/Report.kt b/src/main/kotlin/org/octopus/lorca_core/common/models/Report.kt new file mode 100644 index 0000000..cbaaa01 --- /dev/null +++ b/src/main/kotlin/org/octopus/lorca_core/common/models/Report.kt @@ -0,0 +1,10 @@ +package org.octopus.lorca_core.common.models + +import java.util.* + +data class Report( + var id: Long = 0L, + var reportDate: Date, + val filedBy: Worker, + val clients: MutableList = mutableListOf() +) \ No newline at end of file diff --git a/src/main/kotlin/org/js/lorca_core/common/models/Worker.kt b/src/main/kotlin/org/octopus/lorca_core/common/models/Worker.kt similarity index 53% rename from src/main/kotlin/org/js/lorca_core/common/models/Worker.kt rename to src/main/kotlin/org/octopus/lorca_core/common/models/Worker.kt index 0425a5d..03306e5 100644 --- a/src/main/kotlin/org/js/lorca_core/common/models/Worker.kt +++ b/src/main/kotlin/org/octopus/lorca_core/common/models/Worker.kt @@ -1,6 +1,6 @@ -package org.js.lorca_core.common.models +package org.octopus.lorca_core.common.models -import org.js.lorca_core.common.enums.EWorkerCategory +import org.octopus.lorca_core.common.enums.EWorkerCategory data class Worker( var id: Long, diff --git a/src/main/kotlin/org/js/lorca_core/config/auth/JwtAuthConfiguration.kt b/src/main/kotlin/org/octopus/lorca_core/config/security/JwtAuthConfiguration.kt similarity index 93% rename from src/main/kotlin/org/js/lorca_core/config/auth/JwtAuthConfiguration.kt rename to src/main/kotlin/org/octopus/lorca_core/config/security/JwtAuthConfiguration.kt index c28188b..d293bd9 100644 --- a/src/main/kotlin/org/js/lorca_core/config/auth/JwtAuthConfiguration.kt +++ b/src/main/kotlin/org/octopus/lorca_core/config/security/JwtAuthConfiguration.kt @@ -1,6 +1,6 @@ -package org.js.lorca_core.config.auth +package org.octopus.lorca_core.config.security -import org.js.lorca_core.repositories.UserAuthRepository +import org.octopus.lorca_core.repositories.UserAuthRepository import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration import org.springframework.security.authentication.AuthenticationManager diff --git a/src/main/kotlin/org/js/lorca_core/config/auth/JwtAuthenticationFilter.kt b/src/main/kotlin/org/octopus/lorca_core/config/security/JwtAuthenticationFilter.kt similarity index 84% rename from src/main/kotlin/org/js/lorca_core/config/auth/JwtAuthenticationFilter.kt rename to src/main/kotlin/org/octopus/lorca_core/config/security/JwtAuthenticationFilter.kt index 93662ba..95d679b 100644 --- a/src/main/kotlin/org/js/lorca_core/config/auth/JwtAuthenticationFilter.kt +++ b/src/main/kotlin/org/octopus/lorca_core/config/security/JwtAuthenticationFilter.kt @@ -1,13 +1,15 @@ -package org.js.lorca_core.config.auth +package org.octopus.lorca_core.config.security import jakarta.servlet.FilterChain import jakarta.servlet.ServletException import jakarta.servlet.http.HttpServletRequest import jakarta.servlet.http.HttpServletResponse -import org.js.lorca_core.services.JwtService +import org.octopus.lorca_core.common.enums.EUserRoles +import org.octopus.lorca_core.services.JwtService import org.springframework.lang.NonNull import org.springframework.security.authentication.UsernamePasswordAuthenticationToken import org.springframework.security.core.Authentication +import org.springframework.security.core.authority.SimpleGrantedAuthority import org.springframework.security.core.context.SecurityContextHolder import org.springframework.security.core.userdetails.UserDetailsService import org.springframework.security.web.authentication.WebAuthenticationDetailsSource @@ -44,11 +46,13 @@ class JwtAuthenticationFilter( if (authentication == null) { val userDetails = userDetailsService.loadUserByUsername(userEmail) - if (jwtService.isTokenValid(jwt, userDetails)) { + val roles = jwtService.getRoles(jwt) + + if (jwtService.isTokenValid(jwt, userDetails) && roles.contains(EUserRoles.BASE)) { val authToken = UsernamePasswordAuthenticationToken( userDetails, null, - userDetails.authorities + roles.map { SimpleGrantedAuthority("ROLE_$it") } ) authToken.details = WebAuthenticationDetailsSource().buildDetails(request) diff --git a/src/main/kotlin/org/js/lorca_core/config/SecurityConfig.kt b/src/main/kotlin/org/octopus/lorca_core/config/security/SecurityConfig.kt similarity index 88% rename from src/main/kotlin/org/js/lorca_core/config/SecurityConfig.kt rename to src/main/kotlin/org/octopus/lorca_core/config/security/SecurityConfig.kt index ccab33f..80349f8 100644 --- a/src/main/kotlin/org/js/lorca_core/config/SecurityConfig.kt +++ b/src/main/kotlin/org/octopus/lorca_core/config/security/SecurityConfig.kt @@ -1,9 +1,9 @@ -package org.js.lorca_core.config +package org.octopus.lorca_core.config.security -import org.js.lorca_core.config.auth.JwtAuthenticationFilter import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration import org.springframework.security.authentication.AuthenticationProvider +import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity import org.springframework.security.config.annotation.web.builders.HttpSecurity import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity import org.springframework.security.config.http.SessionCreationPolicy @@ -13,6 +13,7 @@ import org.springframework.security.web.authentication.UsernamePasswordAuthentic @Configuration @EnableWebSecurity +@EnableMethodSecurity(securedEnabled = true) class SecurityConfig( val authenticationProvider: AuthenticationProvider, val jwtAuthenticationFilter: JwtAuthenticationFilter diff --git a/src/main/kotlin/org/octopus/lorca_core/db/ClientJpa.kt b/src/main/kotlin/org/octopus/lorca_core/db/ClientJpa.kt new file mode 100644 index 0000000..83bdb86 --- /dev/null +++ b/src/main/kotlin/org/octopus/lorca_core/db/ClientJpa.kt @@ -0,0 +1,8 @@ +package org.octopus.lorca_core.db + +import org.octopus.lorca_core.db.entities.ClientEntity +import org.springframework.data.jpa.repository.JpaRepository + +interface ClientJpa : JpaRepository { + fun findAllByDeactivatedIsFalse(): MutableList +} \ No newline at end of file diff --git a/src/main/kotlin/org/octopus/lorca_core/db/ReportJpa.kt b/src/main/kotlin/org/octopus/lorca_core/db/ReportJpa.kt new file mode 100644 index 0000000..ff6730e --- /dev/null +++ b/src/main/kotlin/org/octopus/lorca_core/db/ReportJpa.kt @@ -0,0 +1,6 @@ +package org.octopus.lorca_core.db + +import org.octopus.lorca_core.db.entities.ReportEntity +import org.springframework.data.jpa.repository.JpaRepository + +interface ReportJpa : JpaRepository \ No newline at end of file diff --git a/src/main/kotlin/org/js/lorca_core/db/UserAuthJpa.kt b/src/main/kotlin/org/octopus/lorca_core/db/UserAuthJpa.kt similarity index 73% rename from src/main/kotlin/org/js/lorca_core/db/UserAuthJpa.kt rename to src/main/kotlin/org/octopus/lorca_core/db/UserAuthJpa.kt index 353db51..157aed2 100644 --- a/src/main/kotlin/org/js/lorca_core/db/UserAuthJpa.kt +++ b/src/main/kotlin/org/octopus/lorca_core/db/UserAuthJpa.kt @@ -1,6 +1,6 @@ -package org.js.lorca_core.db +package org.octopus.lorca_core.db -import org.js.lorca_core.db.entities.UserAuthEntity +import org.octopus.lorca_core.db.entities.UserAuthEntity import org.springframework.data.jpa.repository.JpaRepository import java.util.* diff --git a/src/main/kotlin/org/octopus/lorca_core/db/WorkerJpa.kt b/src/main/kotlin/org/octopus/lorca_core/db/WorkerJpa.kt new file mode 100644 index 0000000..b583826 --- /dev/null +++ b/src/main/kotlin/org/octopus/lorca_core/db/WorkerJpa.kt @@ -0,0 +1,11 @@ +package org.octopus.lorca_core.db + +import org.octopus.lorca_core.common.enums.EWorkerCategory +import org.octopus.lorca_core.db.entities.WorkerEntity +import org.springframework.data.jpa.repository.JpaRepository +import java.util.* + +interface WorkerJpa : JpaRepository { + fun findByAuthUserUsr(username: String): Optional + fun findAllByCategory(category: EWorkerCategory): MutableList +} \ No newline at end of file diff --git a/src/main/kotlin/org/js/lorca_core/db/entities/ClientEntity.kt b/src/main/kotlin/org/octopus/lorca_core/db/entities/ClientEntity.kt similarity index 75% rename from src/main/kotlin/org/js/lorca_core/db/entities/ClientEntity.kt rename to src/main/kotlin/org/octopus/lorca_core/db/entities/ClientEntity.kt index 2154de6..04f2271 100644 --- a/src/main/kotlin/org/js/lorca_core/db/entities/ClientEntity.kt +++ b/src/main/kotlin/org/octopus/lorca_core/db/entities/ClientEntity.kt @@ -1,4 +1,4 @@ -package org.js.lorca_core.db.entities +package org.octopus.lorca_core.db.entities import jakarta.persistence.Entity import jakarta.persistence.GeneratedValue @@ -10,5 +10,6 @@ data class ClientEntity( @Id @GeneratedValue(strategy = GenerationType.IDENTITY) var id: Long = 0L, var name: String, - var surname: String + var surname: String, + val deactivated: Boolean ) \ No newline at end of file diff --git a/src/main/kotlin/org/js/lorca_core/db/entities/ReportEntity.kt b/src/main/kotlin/org/octopus/lorca_core/db/entities/ReportEntity.kt similarity index 78% rename from src/main/kotlin/org/js/lorca_core/db/entities/ReportEntity.kt rename to src/main/kotlin/org/octopus/lorca_core/db/entities/ReportEntity.kt index e6ff5ad..f1d14b6 100644 --- a/src/main/kotlin/org/js/lorca_core/db/entities/ReportEntity.kt +++ b/src/main/kotlin/org/octopus/lorca_core/db/entities/ReportEntity.kt @@ -1,4 +1,4 @@ -package org.js.lorca_core.db.entities +package org.octopus.lorca_core.db.entities import jakarta.persistence.* import java.util.* @@ -13,5 +13,5 @@ data class ReportEntity( val filedBy: WorkerEntity, @OneToMany(fetch = FetchType.LAZY, cascade = [CascadeType.DETACH]) - val clientEntities: MutableList = mutableListOf() + val clients: MutableList = mutableListOf() ) \ No newline at end of file diff --git a/src/main/kotlin/org/js/lorca_core/db/entities/UserAuthEntity.kt b/src/main/kotlin/org/octopus/lorca_core/db/entities/UserAuthEntity.kt similarity index 59% rename from src/main/kotlin/org/js/lorca_core/db/entities/UserAuthEntity.kt rename to src/main/kotlin/org/octopus/lorca_core/db/entities/UserAuthEntity.kt index 04213a5..2b942e9 100644 --- a/src/main/kotlin/org/js/lorca_core/db/entities/UserAuthEntity.kt +++ b/src/main/kotlin/org/octopus/lorca_core/db/entities/UserAuthEntity.kt @@ -1,6 +1,10 @@ -package org.js.lorca_core.db.entities +package org.octopus.lorca_core.db.entities -import jakarta.persistence.* +import jakarta.persistence.Column +import jakarta.persistence.Entity +import jakarta.persistence.GeneratedValue +import jakarta.persistence.Id +import org.octopus.lorca_core.common.enums.EUserRoles import org.springframework.security.core.GrantedAuthority import org.springframework.security.core.userdetails.UserDetails @@ -9,11 +13,25 @@ class UserAuthEntity(usr: String, pwd: String) : UserDetails { @Id @GeneratedValue var id: Long? = null + + @Column(nullable = false, unique = true) var usr: String? = usr + + @Column(nullable = false, unique = true) var pwd: String? = pwd - @ManyToMany(cascade = [CascadeType.DETACH]) - var claims: MutableList = mutableListOf() + @Column(length = 255) + var claims: String = "" + + fun getClaimsList(): List { + return claims.split(",").mapNotNull { + runCatching { EUserRoles.valueOf(it) }.getOrNull() + } + } + + fun setClaimsList(roles: List) { + claims = roles.joinToString(",") { it.name } + } override fun getAuthorities(): Collection { return listOf() diff --git a/src/main/kotlin/org/js/lorca_core/db/entities/WorkerEntity.kt b/src/main/kotlin/org/octopus/lorca_core/db/entities/WorkerEntity.kt similarity index 74% rename from src/main/kotlin/org/js/lorca_core/db/entities/WorkerEntity.kt rename to src/main/kotlin/org/octopus/lorca_core/db/entities/WorkerEntity.kt index 6f323ab..b883fcf 100644 --- a/src/main/kotlin/org/js/lorca_core/db/entities/WorkerEntity.kt +++ b/src/main/kotlin/org/octopus/lorca_core/db/entities/WorkerEntity.kt @@ -1,7 +1,7 @@ -package org.js.lorca_core.db.entities +package org.octopus.lorca_core.db.entities import jakarta.persistence.* -import org.js.lorca_core.common.enums.EWorkerCategory +import org.octopus.lorca_core.common.enums.EWorkerCategory @Entity(name = "workers") data class WorkerEntity( diff --git a/src/main/kotlin/org/octopus/lorca_core/repositories/ClientRepository.kt b/src/main/kotlin/org/octopus/lorca_core/repositories/ClientRepository.kt new file mode 100644 index 0000000..bbcd299 --- /dev/null +++ b/src/main/kotlin/org/octopus/lorca_core/repositories/ClientRepository.kt @@ -0,0 +1,10 @@ +package org.octopus.lorca_core.repositories + +import org.octopus.lorca_core.common.models.Client + +interface ClientRepository { + fun createClient(client: Client): Client + fun getAll(includeNotActive: Boolean): MutableList + fun getById(id: Long): Client + +} diff --git a/src/main/kotlin/org/octopus/lorca_core/repositories/ReportRepository.kt b/src/main/kotlin/org/octopus/lorca_core/repositories/ReportRepository.kt new file mode 100644 index 0000000..be27cf0 --- /dev/null +++ b/src/main/kotlin/org/octopus/lorca_core/repositories/ReportRepository.kt @@ -0,0 +1,10 @@ +package org.octopus.lorca_core.repositories + +import org.octopus.lorca_core.common.models.Client +import org.octopus.lorca_core.common.models.Report +import org.octopus.lorca_core.common.models.Worker +import java.util.* + +interface ReportRepository { + fun createReport(filedBy: Worker, clients: List, scheduledDate: Date?): Report +} diff --git a/src/main/kotlin/org/octopus/lorca_core/repositories/UserAuthRepository.kt b/src/main/kotlin/org/octopus/lorca_core/repositories/UserAuthRepository.kt new file mode 100644 index 0000000..7920821 --- /dev/null +++ b/src/main/kotlin/org/octopus/lorca_core/repositories/UserAuthRepository.kt @@ -0,0 +1,11 @@ +package org.octopus.lorca_core.repositories + +import org.octopus.lorca_core.common.enums.EUserRoles +import org.octopus.lorca_core.db.entities.UserAuthEntity + +interface UserAuthRepository { + fun existsByUsername(username: String): Boolean + fun getByUsername(username: String): UserAuthEntity + fun save(userAuth: UserAuthEntity): UserAuthEntity + fun modifyClaims(username: String, claims: List): Boolean +} \ No newline at end of file diff --git a/src/main/kotlin/org/octopus/lorca_core/repositories/WorkerRepository.kt b/src/main/kotlin/org/octopus/lorca_core/repositories/WorkerRepository.kt new file mode 100644 index 0000000..74c2f87 --- /dev/null +++ b/src/main/kotlin/org/octopus/lorca_core/repositories/WorkerRepository.kt @@ -0,0 +1,12 @@ +package org.octopus.lorca_core.repositories + +import org.octopus.lorca_core.common.enums.EWorkerCategory +import org.octopus.lorca_core.common.models.Worker +import org.octopus.lorca_core.db.entities.UserAuthEntity + +interface WorkerRepository { + fun getByUsername(username: String): Worker? + fun createForUser(worker: Worker, userAuth: UserAuthEntity): Worker + fun getAll(): MutableList + fun getAllByCategory(category: EWorkerCategory): MutableList +} diff --git a/src/main/kotlin/org/js/lorca_core/repositories/impl/ClientRepositoryImpl.kt b/src/main/kotlin/org/octopus/lorca_core/repositories/impl/ClientRepositoryImpl.kt similarity index 50% rename from src/main/kotlin/org/js/lorca_core/repositories/impl/ClientRepositoryImpl.kt rename to src/main/kotlin/org/octopus/lorca_core/repositories/impl/ClientRepositoryImpl.kt index 7c66b1c..c7b0132 100644 --- a/src/main/kotlin/org/js/lorca_core/repositories/impl/ClientRepositoryImpl.kt +++ b/src/main/kotlin/org/octopus/lorca_core/repositories/impl/ClientRepositoryImpl.kt @@ -1,11 +1,11 @@ -package org.js.lorca_core.repositories.impl +package org.octopus.lorca_core.repositories.impl -import org.js.lorca_core.common.enums.EBusinessException -import org.js.lorca_core.common.exceptions.LorcaException -import org.js.lorca_core.common.mappers.ClientMapper -import org.js.lorca_core.common.models.Client -import org.js.lorca_core.db.ClientJpa -import org.js.lorca_core.repositories.ClientRepository +import org.octopus.lorca_core.common.enums.EBusinessException +import org.octopus.lorca_core.common.exceptions.LorcaException +import org.octopus.lorca_core.common.mappers.ClientMapper +import org.octopus.lorca_core.common.models.Client +import org.octopus.lorca_core.db.ClientJpa +import org.octopus.lorca_core.repositories.ClientRepository import org.springframework.stereotype.Component @Component @@ -18,8 +18,14 @@ class ClientRepositoryImpl( } - override fun getAll(): MutableList { - return mapper.toModels(jpa.findAll()) + override fun getAll(includeNotActive: Boolean): MutableList { + return mapper.toModels( + if (includeNotActive) { + jpa.findAll() + } else { + jpa.findAllByDeactivatedIsFalse() + } + ) } override fun getById(id: Long): Client { diff --git a/src/main/kotlin/org/octopus/lorca_core/repositories/impl/ReportRepositoryImpl.kt b/src/main/kotlin/org/octopus/lorca_core/repositories/impl/ReportRepositoryImpl.kt new file mode 100644 index 0000000..eaf104f --- /dev/null +++ b/src/main/kotlin/org/octopus/lorca_core/repositories/impl/ReportRepositoryImpl.kt @@ -0,0 +1,31 @@ +package org.octopus.lorca_core.repositories.impl + +import org.octopus.lorca_core.common.mappers.ReportMapper +import org.octopus.lorca_core.common.models.Client +import org.octopus.lorca_core.common.models.Report +import org.octopus.lorca_core.common.models.Worker +import org.octopus.lorca_core.db.ReportJpa +import org.octopus.lorca_core.repositories.ReportRepository +import org.springframework.stereotype.Component +import java.util.* + +@Component +class ReportRepositoryImpl( + protected val jpa: ReportJpa, + protected val mapper: ReportMapper +) : ReportRepository { + override fun createReport(filedBy: Worker, clients: List, scheduledDate: Date?): Report { + return mapper.toModel( + jpa.save( + mapper.toEntity( + Report( + id = 0, + reportDate = scheduledDate ?: Date(), + filedBy = filedBy, + clients = clients.toMutableList() + ) + ) + ) + ) + } +} \ No newline at end of file diff --git a/src/main/kotlin/org/octopus/lorca_core/repositories/impl/UserAuthRepositoryImpl.kt b/src/main/kotlin/org/octopus/lorca_core/repositories/impl/UserAuthRepositoryImpl.kt new file mode 100644 index 0000000..632d36a --- /dev/null +++ b/src/main/kotlin/org/octopus/lorca_core/repositories/impl/UserAuthRepositoryImpl.kt @@ -0,0 +1,38 @@ +package org.octopus.lorca_core.repositories.impl + +import org.octopus.lorca_core.common.enums.EBusinessException +import org.octopus.lorca_core.common.enums.EUserRoles +import org.octopus.lorca_core.common.exceptions.LorcaException +import org.octopus.lorca_core.db.UserAuthJpa +import org.octopus.lorca_core.db.entities.UserAuthEntity +import org.octopus.lorca_core.repositories.UserAuthRepository +import org.springframework.stereotype.Component + +@Component +class UserAuthRepositoryImpl( + protected val jpa: UserAuthJpa +) : UserAuthRepository { + override fun getByUsername(username: String): UserAuthEntity { + return jpa.findByUsr(username) + .orElseThrow { LorcaException.create(EBusinessException.USER_NOT_FOUND, username) } + } + + override fun save(userAuth: UserAuthEntity): UserAuthEntity { + return jpa.save(userAuth) + } + + override fun modifyClaims(username: String, claims: List): Boolean { + if (!existsByUsername(username)) { + return false + } + val uae = getByUsername(username) + uae.setClaimsList(roles = claims) + save(uae) + return true + } + + override fun existsByUsername(username: String): Boolean { + return jpa.existsByUsr(username) + } + +} \ No newline at end of file diff --git a/src/main/kotlin/org/js/lorca_core/repositories/impl/WorkerRepositoryImpl.kt b/src/main/kotlin/org/octopus/lorca_core/repositories/impl/WorkerRepositoryImpl.kt similarity index 52% rename from src/main/kotlin/org/js/lorca_core/repositories/impl/WorkerRepositoryImpl.kt rename to src/main/kotlin/org/octopus/lorca_core/repositories/impl/WorkerRepositoryImpl.kt index 6a38d61..e135a7c 100644 --- a/src/main/kotlin/org/js/lorca_core/repositories/impl/WorkerRepositoryImpl.kt +++ b/src/main/kotlin/org/octopus/lorca_core/repositories/impl/WorkerRepositoryImpl.kt @@ -1,10 +1,12 @@ -package org.js.lorca_core.repositories.impl +package org.octopus.lorca_core.repositories.impl -import org.js.lorca_core.common.mappers.WorkerMapper -import org.js.lorca_core.common.models.Worker -import org.js.lorca_core.db.WorkerJpa -import org.js.lorca_core.db.entities.UserAuthEntity -import org.js.lorca_core.repositories.WorkerRepository +import org.octopus.lorca_core.common.enums.EUserRoles +import org.octopus.lorca_core.common.enums.EWorkerCategory +import org.octopus.lorca_core.common.mappers.WorkerMapper +import org.octopus.lorca_core.common.models.Worker +import org.octopus.lorca_core.db.WorkerJpa +import org.octopus.lorca_core.db.entities.UserAuthEntity +import org.octopus.lorca_core.repositories.WorkerRepository import org.springframework.stereotype.Component import kotlin.jvm.optionals.getOrNull @@ -21,6 +23,7 @@ class WorkerRepositoryImpl( override fun createForUser(worker: Worker, userAuth: UserAuthEntity): Worker { val w = mapper.toEntity(worker) w.authUser = userAuth + userAuth.setClaimsList(listOf(EUserRoles.FISIO, EUserRoles.ADMIN)) val ent = jpa.save(w) return mapper.toModel(ent) } @@ -29,4 +32,8 @@ class WorkerRepositoryImpl( return mapper.toModels(jpa.findAll()) } + override fun getAllByCategory(category: EWorkerCategory): MutableList { + return mapper.toModels(jpa.findAllByCategory(category)) + } + } \ No newline at end of file diff --git a/src/main/kotlin/org/octopus/lorca_core/services/AdminService.kt b/src/main/kotlin/org/octopus/lorca_core/services/AdminService.kt new file mode 100644 index 0000000..80b7e42 --- /dev/null +++ b/src/main/kotlin/org/octopus/lorca_core/services/AdminService.kt @@ -0,0 +1,7 @@ +package org.octopus.lorca_core.services + +import org.octopus.lorca_core.common.enums.EUserRoles + +interface AdminService { + fun modifyRoles(username: String, claims: List) +} \ No newline at end of file diff --git a/src/main/kotlin/org/octopus/lorca_core/services/AuthenticationService.kt b/src/main/kotlin/org/octopus/lorca_core/services/AuthenticationService.kt new file mode 100644 index 0000000..3a1188e --- /dev/null +++ b/src/main/kotlin/org/octopus/lorca_core/services/AuthenticationService.kt @@ -0,0 +1,10 @@ +package org.octopus.lorca_core.services + +import org.octopus.lorca_core.web.utils.dtos.UserAuthDto +import org.octopus.lorca_core.web.utils.responses.LoginResponse + +interface AuthenticationService { + fun register(dto: UserAuthDto): Boolean + + fun login(dto: UserAuthDto): LoginResponse +} \ No newline at end of file diff --git a/src/main/kotlin/org/octopus/lorca_core/services/ClientService.kt b/src/main/kotlin/org/octopus/lorca_core/services/ClientService.kt new file mode 100644 index 0000000..80812a9 --- /dev/null +++ b/src/main/kotlin/org/octopus/lorca_core/services/ClientService.kt @@ -0,0 +1,10 @@ +package org.octopus.lorca_core.services + +import org.octopus.lorca_core.common.models.Client +import org.octopus.lorca_core.web.utils.dtos.ClientDto + +interface ClientService { + fun getAllClients(includeDeactivated: Boolean): MutableList + fun getClientById(id: Long): Client + fun createClient(clientDto: ClientDto): Client +} \ No newline at end of file diff --git a/src/main/kotlin/org/js/lorca_core/services/JwtService.kt b/src/main/kotlin/org/octopus/lorca_core/services/JwtService.kt similarity index 78% rename from src/main/kotlin/org/js/lorca_core/services/JwtService.kt rename to src/main/kotlin/org/octopus/lorca_core/services/JwtService.kt index 978d2f0..9a948d1 100644 --- a/src/main/kotlin/org/js/lorca_core/services/JwtService.kt +++ b/src/main/kotlin/org/octopus/lorca_core/services/JwtService.kt @@ -1,6 +1,7 @@ -package org.js.lorca_core.services +package org.octopus.lorca_core.services import io.jsonwebtoken.Claims +import org.octopus.lorca_core.common.enums.EUserRoles import org.springframework.security.core.userdetails.UserDetails import java.util.function.Function @@ -17,4 +18,6 @@ interface JwtService { fun getExpirationTime(): Long fun isTokenValid(token: String, userDetails: UserDetails): Boolean + + fun getRoles(token: String): List } diff --git a/src/main/kotlin/org/octopus/lorca_core/services/WorkerService.kt b/src/main/kotlin/org/octopus/lorca_core/services/WorkerService.kt new file mode 100644 index 0000000..d0e2c42 --- /dev/null +++ b/src/main/kotlin/org/octopus/lorca_core/services/WorkerService.kt @@ -0,0 +1,10 @@ +package org.octopus.lorca_core.services + +import org.octopus.lorca_core.common.enums.EWorkerCategory +import org.octopus.lorca_core.common.models.Worker + +interface WorkerService { + fun createTestData() + fun getAllWorkers(): List + fun getAllWorkersForCategory(workCategory: EWorkerCategory): List +} \ No newline at end of file diff --git a/src/main/kotlin/org/octopus/lorca_core/services/impl/AdminServiceImpl.kt b/src/main/kotlin/org/octopus/lorca_core/services/impl/AdminServiceImpl.kt new file mode 100644 index 0000000..fbec0fe --- /dev/null +++ b/src/main/kotlin/org/octopus/lorca_core/services/impl/AdminServiceImpl.kt @@ -0,0 +1,19 @@ +package org.octopus.lorca_core.services.impl + +import org.octopus.lorca_core.common.enums.EBusinessException +import org.octopus.lorca_core.common.enums.EUserRoles +import org.octopus.lorca_core.common.exceptions.LorcaException +import org.octopus.lorca_core.repositories.UserAuthRepository +import org.octopus.lorca_core.services.AdminService +import org.springframework.stereotype.Service + +@Service +class AdminServiceImpl( + val userAuthRepository: UserAuthRepository +) : AdminService { + override fun modifyRoles(username: String, claims: List) { + if (!userAuthRepository.modifyClaims(username, claims)) { + throw LorcaException.create(EBusinessException.IMPOSSIBLE_ADD_ROLES, username) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/org/js/lorca_core/services/impl/AuthenticationServiceImpl.kt b/src/main/kotlin/org/octopus/lorca_core/services/impl/AuthenticationServiceImpl.kt similarity index 66% rename from src/main/kotlin/org/js/lorca_core/services/impl/AuthenticationServiceImpl.kt rename to src/main/kotlin/org/octopus/lorca_core/services/impl/AuthenticationServiceImpl.kt index 0e006d3..f9a7abc 100644 --- a/src/main/kotlin/org/js/lorca_core/services/impl/AuthenticationServiceImpl.kt +++ b/src/main/kotlin/org/octopus/lorca_core/services/impl/AuthenticationServiceImpl.kt @@ -1,14 +1,14 @@ -package org.js.lorca_core.services.impl +package org.octopus.lorca_core.services.impl -import org.js.lorca_core.common.dtos.UserAuthDto -import org.js.lorca_core.common.enums.EBusinessException -import org.js.lorca_core.common.exceptions.LorcaException -import org.js.lorca_core.common.responses.LoginResponse -import org.js.lorca_core.db.entities.UserAuthEntity -import org.js.lorca_core.repositories.UserAuthRepository -import org.js.lorca_core.repositories.WorkerRepository -import org.js.lorca_core.services.AuthenticationService -import org.js.lorca_core.services.JwtService +import org.octopus.lorca_core.common.enums.EBusinessException +import org.octopus.lorca_core.common.exceptions.LorcaException +import org.octopus.lorca_core.db.entities.UserAuthEntity +import org.octopus.lorca_core.repositories.UserAuthRepository +import org.octopus.lorca_core.repositories.WorkerRepository +import org.octopus.lorca_core.services.AuthenticationService +import org.octopus.lorca_core.services.JwtService +import org.octopus.lorca_core.web.utils.dtos.UserAuthDto +import org.octopus.lorca_core.web.utils.responses.LoginResponse import org.springframework.security.authentication.AuthenticationManager import org.springframework.security.authentication.UsernamePasswordAuthenticationToken import org.springframework.security.crypto.password.PasswordEncoder @@ -26,7 +26,7 @@ class AuthenticationServiceImpl( override fun register(dto: UserAuthDto): Boolean { if (userAuthRepository.existsByUsername(dto.username)) { - throw LorcaException(EBusinessException.USER_ALREADY_EXISTS, dto.username) + throw LorcaException.create(EBusinessException.USER_ALREADY_EXISTS, dto.username) } userAuthRepository.save(UserAuthEntity(dto.username, passwordEncoder.encode(dto.password))) diff --git a/src/main/kotlin/org/octopus/lorca_core/services/impl/ClientServiceImpl.kt b/src/main/kotlin/org/octopus/lorca_core/services/impl/ClientServiceImpl.kt new file mode 100644 index 0000000..b0c5c5f --- /dev/null +++ b/src/main/kotlin/org/octopus/lorca_core/services/impl/ClientServiceImpl.kt @@ -0,0 +1,22 @@ +package org.octopus.lorca_core.services.impl + +import org.octopus.lorca_core.common.models.Client +import org.octopus.lorca_core.repositories.ClientRepository +import org.octopus.lorca_core.services.ClientService +import org.octopus.lorca_core.web.utils.dtos.ClientDto +import org.springframework.stereotype.Service + +@Service +class ClientServiceImpl(val repo: ClientRepository) : ClientService { + override fun getAllClients(includeDeactivated: Boolean): MutableList { + return repo.getAll(includeDeactivated) + } + + override fun getClientById(id: Long): Client { + return repo.getById(id) + } + + override fun createClient(clientDto: ClientDto): Client { + return repo.createClient(Client(null, clientDto.name, clientDto.surname, clientDto.deactivated)) + } +} \ No newline at end of file diff --git a/src/main/kotlin/org/js/lorca_core/services/impl/JwtServiceImpl.kt b/src/main/kotlin/org/octopus/lorca_core/services/impl/JwtServiceImpl.kt similarity index 85% rename from src/main/kotlin/org/js/lorca_core/services/impl/JwtServiceImpl.kt rename to src/main/kotlin/org/octopus/lorca_core/services/impl/JwtServiceImpl.kt index 77636c6..1c65471 100644 --- a/src/main/kotlin/org/js/lorca_core/services/impl/JwtServiceImpl.kt +++ b/src/main/kotlin/org/octopus/lorca_core/services/impl/JwtServiceImpl.kt @@ -1,13 +1,12 @@ -package org.js.lorca_core.services.impl +package org.octopus.lorca_core.services.impl import io.jsonwebtoken.Claims import io.jsonwebtoken.Jwts import io.jsonwebtoken.io.Decoders import io.jsonwebtoken.security.Keys -import org.js.lorca_core.common.enums.EUserRoles -import org.js.lorca_core.db.entities.UserAuthEntity -import org.js.lorca_core.repositories.UserAuthRepository -import org.js.lorca_core.services.JwtService +import org.octopus.lorca_core.common.enums.EUserRoles +import org.octopus.lorca_core.repositories.UserAuthRepository +import org.octopus.lorca_core.services.JwtService import org.springframework.beans.factory.annotation.Value import org.springframework.security.core.userdetails.UserDetails import org.springframework.stereotype.Service @@ -37,7 +36,7 @@ class JwtServiceImpl( override fun generateToken(userDetails: UserDetails): String { val extraClaims: MutableMap = mutableMapOf() - getClaimsForUser(userAuthRepository.getByUsername(userDetails.username)).let { claims -> + userAuthRepository.getByUsername(userDetails.username).getClaimsList().let { claims -> if (claims.isNotEmpty()) { extraClaims["roles"] = claims } @@ -75,6 +74,10 @@ class JwtServiceImpl( return (username == userDetails.username) && !isTokenExpired(token) } + override fun getRoles(token: String): List { + return (extractAllClaims(token).get("roles") as List).map { EUserRoles.valueOf(it) } + } + private fun isTokenExpired(token: String): Boolean { return extractExpiration(token).before(Date()) } @@ -95,8 +98,4 @@ class JwtServiceImpl( val keyBytes = Decoders.BASE64.decode(secretKey) return Keys.hmacShaKeyFor(keyBytes) } - - private fun getClaimsForUser(user: UserAuthEntity): List { - return userAuthRepository.getClaimsForUser(user) - } } diff --git a/src/main/kotlin/org/js/lorca_core/services/impl/WorkerServiceImpl.kt b/src/main/kotlin/org/octopus/lorca_core/services/impl/WorkerServiceImpl.kt similarity index 53% rename from src/main/kotlin/org/js/lorca_core/services/impl/WorkerServiceImpl.kt rename to src/main/kotlin/org/octopus/lorca_core/services/impl/WorkerServiceImpl.kt index 598cbd6..7315522 100644 --- a/src/main/kotlin/org/js/lorca_core/services/impl/WorkerServiceImpl.kt +++ b/src/main/kotlin/org/octopus/lorca_core/services/impl/WorkerServiceImpl.kt @@ -1,10 +1,10 @@ -package org.js.lorca_core.services.impl +package org.octopus.lorca_core.services.impl -import org.js.lorca_core.common.enums.EWorkerCategory -import org.js.lorca_core.common.models.Worker -import org.js.lorca_core.repositories.UserAuthRepository -import org.js.lorca_core.repositories.WorkerRepository -import org.js.lorca_core.services.WorkerService +import org.octopus.lorca_core.common.enums.EWorkerCategory +import org.octopus.lorca_core.common.models.Worker +import org.octopus.lorca_core.repositories.UserAuthRepository +import org.octopus.lorca_core.repositories.WorkerRepository +import org.octopus.lorca_core.services.WorkerService import org.springframework.stereotype.Service @Service @@ -22,4 +22,8 @@ class WorkerServiceImpl(val repo: WorkerRepository, val authRepository: UserAuth override fun getAllWorkers(): List { return repo.getAll().toList() } + + override fun getAllWorkersForCategory(workCategory: EWorkerCategory): List { + return repo.getAllByCategory(workCategory) + } } \ No newline at end of file diff --git a/src/main/kotlin/org/octopus/lorca_core/web/controllers/AdminController.kt b/src/main/kotlin/org/octopus/lorca_core/web/controllers/AdminController.kt new file mode 100644 index 0000000..e026704 --- /dev/null +++ b/src/main/kotlin/org/octopus/lorca_core/web/controllers/AdminController.kt @@ -0,0 +1,24 @@ +package org.octopus.lorca_core.web.controllers + +import jakarta.validation.Valid +import lombok.AllArgsConstructor +import org.octopus.lorca_core.services.AdminService +import org.octopus.lorca_core.web.utils.dtos.AddRoleDto +import org.octopus.lorca_core.web.utils.responses.WebResponse +import org.springframework.web.bind.annotation.PutMapping +import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController + +@RestController +@RequestMapping("/admin") +@AllArgsConstructor +class AdminController(val adminService: AdminService) { + + @PutMapping("/modifyRoles") + fun addRoles(@Valid @RequestBody addRoleDto: AddRoleDto): WebResponse { + adminService.modifyRoles(addRoleDto.username, addRoleDto.roles) + return WebResponse.ok() + } + +} \ No newline at end of file diff --git a/src/main/kotlin/org/js/lorca_core/web/controllers/AuthController.kt b/src/main/kotlin/org/octopus/lorca_core/web/controllers/AuthController.kt similarity index 75% rename from src/main/kotlin/org/js/lorca_core/web/controllers/AuthController.kt rename to src/main/kotlin/org/octopus/lorca_core/web/controllers/AuthController.kt index e7fcb32..c8693e0 100644 --- a/src/main/kotlin/org/js/lorca_core/web/controllers/AuthController.kt +++ b/src/main/kotlin/org/octopus/lorca_core/web/controllers/AuthController.kt @@ -1,11 +1,11 @@ -package org.js.lorca_core.web.controllers +package org.octopus.lorca_core.web.controllers import jakarta.validation.Valid import lombok.AllArgsConstructor -import org.js.lorca_core.common.dtos.UserAuthDto -import org.js.lorca_core.common.responses.LoginResponse -import org.js.lorca_core.services.AuthenticationService -import org.js.lorca_core.web.advices.WebResponse +import org.octopus.lorca_core.services.AuthenticationService +import org.octopus.lorca_core.web.utils.dtos.UserAuthDto +import org.octopus.lorca_core.web.utils.responses.LoginResponse +import org.octopus.lorca_core.web.utils.responses.WebResponse import org.springframework.web.bind.annotation.PostMapping import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RequestMapping diff --git a/src/main/kotlin/org/js/lorca_core/web/controllers/ClientController.kt b/src/main/kotlin/org/octopus/lorca_core/web/controllers/ClientController.kt similarity index 58% rename from src/main/kotlin/org/js/lorca_core/web/controllers/ClientController.kt rename to src/main/kotlin/org/octopus/lorca_core/web/controllers/ClientController.kt index 069e84b..609ecf7 100644 --- a/src/main/kotlin/org/js/lorca_core/web/controllers/ClientController.kt +++ b/src/main/kotlin/org/octopus/lorca_core/web/controllers/ClientController.kt @@ -1,11 +1,11 @@ -package org.js.lorca_core.web.controllers +package org.octopus.lorca_core.web.controllers import jakarta.validation.Valid import lombok.AllArgsConstructor -import org.js.lorca_core.common.dtos.ClientDto -import org.js.lorca_core.common.models.Client -import org.js.lorca_core.services.ClientService -import org.js.lorca_core.web.advices.WebResponse +import org.octopus.lorca_core.common.models.Client +import org.octopus.lorca_core.services.ClientService +import org.octopus.lorca_core.web.utils.dtos.ClientDto +import org.octopus.lorca_core.web.utils.responses.WebResponse import org.springframework.web.bind.annotation.* @RestController @@ -17,10 +17,12 @@ class ClientController( @GetMapping fun getAllClients( - @RequestParam("name", required = false, defaultValue = "") name: String, - @RequestParam("surname", required = false, defaultValue = "") surname: String + @RequestParam( + "includeDeactivated", + required = false + ) includeDeactivated: Boolean = false ): WebResponse> { - return WebResponse.ok(clientService.getAllClients(name, surname)) + return WebResponse.ok(clientService.getAllClients(includeDeactivated)) } @PostMapping diff --git a/src/main/kotlin/org/octopus/lorca_core/web/controllers/ReportController.kt b/src/main/kotlin/org/octopus/lorca_core/web/controllers/ReportController.kt new file mode 100644 index 0000000..2c04345 --- /dev/null +++ b/src/main/kotlin/org/octopus/lorca_core/web/controllers/ReportController.kt @@ -0,0 +1,10 @@ +package org.octopus.lorca_core.web.controllers + +import lombok.AllArgsConstructor +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController + +@RestController +@RequestMapping("/reports") +@AllArgsConstructor +class ReportController \ No newline at end of file diff --git a/src/main/kotlin/org/octopus/lorca_core/web/controllers/WorkerController.kt b/src/main/kotlin/org/octopus/lorca_core/web/controllers/WorkerController.kt new file mode 100644 index 0000000..d3b3b4b --- /dev/null +++ b/src/main/kotlin/org/octopus/lorca_core/web/controllers/WorkerController.kt @@ -0,0 +1,38 @@ +package org.octopus.lorca_core.web.controllers + +import lombok.AllArgsConstructor +import org.octopus.lorca_core.common.enums.EWorkerCategory +import org.octopus.lorca_core.common.models.Worker +import org.octopus.lorca_core.services.WorkerService +import org.octopus.lorca_core.web.utils.responses.WebResponse +import org.springframework.web.bind.annotation.* + +@RestController +@RequestMapping("/workers") +@AllArgsConstructor +class WorkerController( + val workerService: WorkerService +) { + + @GetMapping + fun getAllWorkers( + @RequestParam( + "category", + required = false + ) category: EWorkerCategory? + ): WebResponse> { + return WebResponse.ok( + if (category != null) { + workerService.getAllWorkersForCategory(category) + } else { + workerService.getAllWorkers() + } + ) + } + + @PostMapping("/test") + fun createTestData(): WebResponse { +// workerService.createTestData() + return WebResponse.ok() + } +} \ No newline at end of file diff --git a/src/main/kotlin/org/js/lorca_core/web/advices/BaseAdvice.kt b/src/main/kotlin/org/octopus/lorca_core/web/utils/BaseAdvice.kt similarity index 82% rename from src/main/kotlin/org/js/lorca_core/web/advices/BaseAdvice.kt rename to src/main/kotlin/org/octopus/lorca_core/web/utils/BaseAdvice.kt index 50988e7..ad03070 100644 --- a/src/main/kotlin/org/js/lorca_core/web/advices/BaseAdvice.kt +++ b/src/main/kotlin/org/octopus/lorca_core/web/utils/BaseAdvice.kt @@ -1,9 +1,11 @@ -package org.js.lorca_core.web.advices +package org.octopus.lorca_core.web.utils -import org.js.lorca_core.common.enums.EBusinessException -import org.js.lorca_core.common.exceptions.LorcaException +import org.octopus.lorca_core.common.enums.EBusinessException +import org.octopus.lorca_core.common.exceptions.LorcaException +import org.octopus.lorca_core.web.utils.responses.WebResponse import org.springframework.http.HttpStatus import org.springframework.http.converter.HttpMessageNotReadableException +import org.springframework.security.authorization.AuthorizationDeniedException import org.springframework.web.HttpRequestMethodNotSupportedException import org.springframework.web.bind.MethodArgumentNotValidException import org.springframework.web.bind.annotation.ExceptionHandler @@ -28,6 +30,7 @@ class BaseAdvice { private fun deductStatus(ex: EBusinessException): HttpStatus { return when (ex) { + EBusinessException.IMPOSSIBLE_ADD_ROLES -> HttpStatus.EXPECTATION_FAILED EBusinessException.USER_ALREADY_EXISTS -> HttpStatus.UNPROCESSABLE_ENTITY EBusinessException.USER_NOT_FOUND -> HttpStatus.NOT_FOUND EBusinessException.ENTITY_WITH_ID_NOT_FOUND -> HttpStatus.NOT_FOUND @@ -100,6 +103,18 @@ class BaseAdvice { ) } + @ExceptionHandler(AuthorizationDeniedException::class) + fun handleAuthorizationDeniedException( + ex: AuthorizationDeniedException, + request: WebRequest + ): WebResponse { + return WebResponse.ko( + HttpStatus.FORBIDDEN, + "${HttpStatus.FORBIDDEN.reasonPhrase}: ${ex.message}" + + ) + } + @ExceptionHandler(Exception::class) fun handleException( diff --git a/src/main/kotlin/org/js/lorca_core/web/advices/LoggingAspect.kt b/src/main/kotlin/org/octopus/lorca_core/web/utils/LoggingAspect.kt similarity index 91% rename from src/main/kotlin/org/js/lorca_core/web/advices/LoggingAspect.kt rename to src/main/kotlin/org/octopus/lorca_core/web/utils/LoggingAspect.kt index 666892d..e118249 100644 --- a/src/main/kotlin/org/js/lorca_core/web/advices/LoggingAspect.kt +++ b/src/main/kotlin/org/octopus/lorca_core/web/utils/LoggingAspect.kt @@ -1,10 +1,10 @@ -package org.js.lorca_core.web.advices +package org.octopus.lorca_core.web.utils //@Aspect //@Component class LoggingAspect { -// @Around("execution(* org.js.lorca_core.web.controllers.*.*(..))") +// @Around("execution(* org.octopus.lorca_core.web.controllers.*.*(..))") // @Throws(Throwable::class) // fun logMethodDetails(proceedingJoinPoint: ProceedingJoinPoint): Any? { // val methodName = proceedingJoinPoint.signature.toShortString() diff --git a/src/main/kotlin/org/octopus/lorca_core/web/utils/dtos/AddRoleDto.kt b/src/main/kotlin/org/octopus/lorca_core/web/utils/dtos/AddRoleDto.kt new file mode 100644 index 0000000..04426bf --- /dev/null +++ b/src/main/kotlin/org/octopus/lorca_core/web/utils/dtos/AddRoleDto.kt @@ -0,0 +1,10 @@ +package org.octopus.lorca_core.web.utils.dtos + +import org.octopus.lorca_core.common.enums.EUserRoles +import org.octopus.lorca_core.web.utils.dtos.validators.UsernameValidator + +data class AddRoleDto( + @field:UsernameValidator.Validate + val username: String, + val roles: List +) \ No newline at end of file diff --git a/src/main/kotlin/org/octopus/lorca_core/web/utils/dtos/ClientDto.kt b/src/main/kotlin/org/octopus/lorca_core/web/utils/dtos/ClientDto.kt new file mode 100644 index 0000000..159c3e1 --- /dev/null +++ b/src/main/kotlin/org/octopus/lorca_core/web/utils/dtos/ClientDto.kt @@ -0,0 +1,11 @@ +package org.octopus.lorca_core.web.utils.dtos + +import org.octopus.lorca_core.web.utils.dtos.validators.NameValidator + +data class ClientDto( + @field:NameValidator.Validate + val name: String, + @field:NameValidator.Validate + val surname: String, + val deactivated: Boolean +) \ No newline at end of file diff --git a/src/main/kotlin/org/octopus/lorca_core/web/utils/dtos/UserAuthDto.kt b/src/main/kotlin/org/octopus/lorca_core/web/utils/dtos/UserAuthDto.kt new file mode 100644 index 0000000..11422e6 --- /dev/null +++ b/src/main/kotlin/org/octopus/lorca_core/web/utils/dtos/UserAuthDto.kt @@ -0,0 +1,11 @@ +package org.octopus.lorca_core.web.utils.dtos + +import org.octopus.lorca_core.web.utils.dtos.validators.B64Validator +import org.octopus.lorca_core.web.utils.dtos.validators.UsernameValidator + +data class UserAuthDto( + @field:UsernameValidator.Validate + val username: String, + @field:B64Validator.Validate + val password: String +) \ No newline at end of file diff --git a/src/main/kotlin/org/js/lorca_core/common/dtos/validators/B64Validator.kt b/src/main/kotlin/org/octopus/lorca_core/web/utils/dtos/validators/B64Validator.kt similarity index 95% rename from src/main/kotlin/org/js/lorca_core/common/dtos/validators/B64Validator.kt rename to src/main/kotlin/org/octopus/lorca_core/web/utils/dtos/validators/B64Validator.kt index 5d5af44..8b9a54f 100644 --- a/src/main/kotlin/org/js/lorca_core/common/dtos/validators/B64Validator.kt +++ b/src/main/kotlin/org/octopus/lorca_core/web/utils/dtos/validators/B64Validator.kt @@ -1,4 +1,4 @@ -package org.js.lorca_core.common.dtos.validators +package org.octopus.lorca_core.web.utils.dtos.validators import jakarta.validation.Constraint import jakarta.validation.ConstraintValidator diff --git a/src/main/kotlin/org/js/lorca_core/common/dtos/validators/NameValidator.kt b/src/main/kotlin/org/octopus/lorca_core/web/utils/dtos/validators/NameValidator.kt similarity index 95% rename from src/main/kotlin/org/js/lorca_core/common/dtos/validators/NameValidator.kt rename to src/main/kotlin/org/octopus/lorca_core/web/utils/dtos/validators/NameValidator.kt index dbd973c..5980440 100644 --- a/src/main/kotlin/org/js/lorca_core/common/dtos/validators/NameValidator.kt +++ b/src/main/kotlin/org/octopus/lorca_core/web/utils/dtos/validators/NameValidator.kt @@ -1,4 +1,4 @@ -package org.js.lorca_core.common.dtos.validators +package org.octopus.lorca_core.web.utils.dtos.validators import jakarta.validation.Constraint import jakarta.validation.ConstraintValidator diff --git a/src/main/kotlin/org/js/lorca_core/common/dtos/validators/UsernameValidator.kt b/src/main/kotlin/org/octopus/lorca_core/web/utils/dtos/validators/UsernameValidator.kt similarity index 95% rename from src/main/kotlin/org/js/lorca_core/common/dtos/validators/UsernameValidator.kt rename to src/main/kotlin/org/octopus/lorca_core/web/utils/dtos/validators/UsernameValidator.kt index 9d5da84..9d39d69 100644 --- a/src/main/kotlin/org/js/lorca_core/common/dtos/validators/UsernameValidator.kt +++ b/src/main/kotlin/org/octopus/lorca_core/web/utils/dtos/validators/UsernameValidator.kt @@ -1,4 +1,4 @@ -package org.js.lorca_core.common.dtos.validators +package org.octopus.lorca_core.web.utils.dtos.validators import jakarta.validation.Constraint import jakarta.validation.ConstraintValidator diff --git a/src/main/kotlin/org/octopus/lorca_core/web/utils/responses/LoginResponse.kt b/src/main/kotlin/org/octopus/lorca_core/web/utils/responses/LoginResponse.kt new file mode 100644 index 0000000..8254302 --- /dev/null +++ b/src/main/kotlin/org/octopus/lorca_core/web/utils/responses/LoginResponse.kt @@ -0,0 +1,8 @@ +package org.octopus.lorca_core.web.utils.responses + +import org.octopus.lorca_core.common.models.Worker + +data class LoginResponse( + val token: String, + val userInfo: Worker? +) \ No newline at end of file diff --git a/src/main/kotlin/org/js/lorca_core/web/advices/WebResponse.kt b/src/main/kotlin/org/octopus/lorca_core/web/utils/responses/WebResponse.kt similarity index 93% rename from src/main/kotlin/org/js/lorca_core/web/advices/WebResponse.kt rename to src/main/kotlin/org/octopus/lorca_core/web/utils/responses/WebResponse.kt index 73377ec..4cae6b8 100644 --- a/src/main/kotlin/org/js/lorca_core/web/advices/WebResponse.kt +++ b/src/main/kotlin/org/octopus/lorca_core/web/utils/responses/WebResponse.kt @@ -1,4 +1,4 @@ -package org.js.lorca_core.web.advices +package org.octopus.lorca_core.web.utils.responses import org.springframework.http.HttpStatus diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 33a8d27..8d8494e 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -20,3 +20,6 @@ security.jwt.secret-key=93d5326c5ae622c9332f291c6a9868d237e6b41fc47c5f2581448d4d security.jwt.expiration-time=3600000 # # +# WHATSAPP API: https://developers.facebook.com/docs/whatsapp/cloud-api/overview +# MAIL SERVICE: https://sendgrid.com/en-us/pricing +# diff --git a/src/test/kotlin/org/js/lorca_core/LorcaCoreApplicationTests.kt b/src/test/kotlin/org/octopus/lorca_core/LorcaCoreApplicationTests.kt similarity index 65% rename from src/test/kotlin/org/js/lorca_core/LorcaCoreApplicationTests.kt rename to src/test/kotlin/org/octopus/lorca_core/LorcaCoreApplicationTests.kt index 1d704bc..dad98e3 100644 --- a/src/test/kotlin/org/js/lorca_core/LorcaCoreApplicationTests.kt +++ b/src/test/kotlin/org/octopus/lorca_core/LorcaCoreApplicationTests.kt @@ -1,6 +1,6 @@ -package org.js.lorca_core +package org.octopus.lorca_core -import org.js.lorca_core.db.entities.WorkerEntity +import org.octopus.lorca_core.db.entities.WorkerEntity import org.springframework.boot.test.context.SpringBootTest @SpringBootTest diff --git a/testSuite/login_and_clients.sh b/testSuite/login_and_clients.sh index e11465f..073bb52 100644 --- a/testSuite/login_and_clients.sh +++ b/testSuite/login_and_clients.sh @@ -2,8 +2,9 @@ TOKEN=$(curl -s -X POST http://localhost:8080/api/auth/login \ -H "Content-Type: application/json" \ -d '{"username":"test","password":"cGFzc3dvcmQ="}' | sed -n 's/.*"token":"\([^"]*\)".*/\1/p') -#curl -H "Authorization: Bearer $TOKEN" -X POST http://localhost:8080/api/workers -curl -H "Authorization: Bearer $TOKEN" -XGET http://localhost:8080/api/workers +#curl -H "Authorization: Bearer $TOKEN" -X POST http://localhost:8080/api/workers/test +#curl -H "Authorization: Bearer $TOKEN" -XGET http://localhost:8080/api/workers +curl -G -H "Authorization: Bearer $TOKEN" --data-urlencode "category=FISIO" "http://localhost:8080/api/workers" -echo $TOKEN +#echo "$TOKEN"