package name change
This commit is contained in:
parent
1910f30289
commit
e2cd042e59
|
|
@ -8,7 +8,7 @@ plugins {
|
|||
|
||||
}
|
||||
|
||||
group = "org.js"
|
||||
group = "org.octopus"
|
||||
version = "0.0.1-SNAPSHOT"
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
)
|
||||
|
|
@ -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
|
||||
)
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
package org.js.lorca_core.common.enums
|
||||
|
||||
enum class EWorkerCategory {
|
||||
FISIO
|
||||
}
|
||||
|
|
@ -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<Client, ClientEntity>
|
||||
|
|
@ -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<UserAuthClaim, UserAuthClaimEntity>
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
package org.js.lorca_core.common.models
|
||||
|
||||
data class Client(
|
||||
var id: Long?,
|
||||
var name: String,
|
||||
var surname: String
|
||||
)
|
||||
|
|
@ -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
|
||||
)
|
||||
|
|
@ -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?
|
||||
)
|
||||
|
|
@ -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<ClientEntity, Long>
|
||||
|
|
@ -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<ClientEntity, Long>
|
||||
|
|
@ -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<WorkerEntity, Long> {
|
||||
fun findByAuthUserUsr(username: String): Optional<WorkerEntity>
|
||||
}
|
||||
|
|
@ -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
|
||||
)
|
||||
|
|
@ -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<Client>
|
||||
fun getById(id: Long): Client
|
||||
|
||||
}
|
||||
|
|
@ -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<EUserRoles>
|
||||
}
|
||||
|
|
@ -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<Worker>
|
||||
}
|
||||
|
|
@ -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<EUserRoles> {
|
||||
return claimMapper.toModels(user.claims).map { it.name }.toList()
|
||||
}
|
||||
|
||||
override fun existsByUsername(username: String): Boolean {
|
||||
return jpa.existsByUsr(username)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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<Client>
|
||||
fun getClientById(id: Long): Client
|
||||
fun createClient(clientDto: ClientDto): Client
|
||||
}
|
||||
|
|
@ -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<Worker>
|
||||
}
|
||||
|
|
@ -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<Client> {
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
|
@ -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<List<Worker>> {
|
||||
return WebResponse.ok(workerService.getAllWorkers())
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
fun createTestData(): WebResponse<Nothing> {
|
||||
workerService.createTestData()
|
||||
return WebResponse.ok()
|
||||
}
|
||||
}
|
||||
|
|
@ -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<String>) {
|
||||
|
|
@ -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"),
|
||||
|
|
@ -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")
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package org.octopus.lorca_core.common.enums
|
||||
|
||||
enum class EWorkerCategory {
|
||||
FISIO
|
||||
}
|
||||
|
|
@ -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() {
|
||||
|
||||
|
|
@ -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<Client, ClientEntity>
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.js.lorca_core.common.mappers
|
||||
package org.octopus.lorca_core.common.mappers
|
||||
|
||||
interface GenericMapper<M, E> {
|
||||
|
||||
|
|
@ -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<Report, ReportEntity>
|
||||
|
|
@ -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<Worker, WorkerEntity> {
|
||||
|
|
@ -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
|
||||
)
|
||||
|
|
@ -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<Client> = mutableListOf()
|
||||
)
|
||||
|
|
@ -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,
|
||||
|
|
@ -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
|
||||
|
|
@ -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)
|
||||
|
|
@ -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
|
||||
|
|
@ -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<ClientEntity, Long> {
|
||||
fun findAllByDeactivatedIsFalse(): MutableList<ClientEntity>
|
||||
}
|
||||
|
|
@ -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<ReportEntity, Long>
|
||||
|
|
@ -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.*
|
||||
|
||||
|
|
@ -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<WorkerEntity, Long> {
|
||||
fun findByAuthUserUsr(username: String): Optional<WorkerEntity>
|
||||
fun findAllByCategory(category: EWorkerCategory): MutableList<WorkerEntity>
|
||||
}
|
||||
|
|
@ -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
|
||||
)
|
||||
|
|
@ -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<ClientEntity> = mutableListOf()
|
||||
val clients: MutableList<ClientEntity> = mutableListOf()
|
||||
)
|
||||
|
|
@ -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<UserAuthClaimEntity> = mutableListOf()
|
||||
@Column(length = 255)
|
||||
var claims: String = ""
|
||||
|
||||
fun getClaimsList(): List<EUserRoles> {
|
||||
return claims.split(",").mapNotNull {
|
||||
runCatching { EUserRoles.valueOf(it) }.getOrNull()
|
||||
}
|
||||
}
|
||||
|
||||
fun setClaimsList(roles: List<EUserRoles>) {
|
||||
claims = roles.joinToString(",") { it.name }
|
||||
}
|
||||
|
||||
override fun getAuthorities(): Collection<GrantedAuthority> {
|
||||
return listOf()
|
||||
|
|
@ -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(
|
||||
|
|
@ -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<Client>
|
||||
fun getById(id: Long): Client
|
||||
|
||||
}
|
||||
|
|
@ -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<Client>, scheduledDate: Date?): Report
|
||||
}
|
||||
|
|
@ -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<EUserRoles>): Boolean
|
||||
}
|
||||
|
|
@ -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<Worker>
|
||||
fun getAllByCategory(category: EWorkerCategory): MutableList<Worker>
|
||||
}
|
||||
|
|
@ -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<Client> {
|
||||
return mapper.toModels(jpa.findAll())
|
||||
override fun getAll(includeNotActive: Boolean): MutableList<Client> {
|
||||
return mapper.toModels(
|
||||
if (includeNotActive) {
|
||||
jpa.findAll()
|
||||
} else {
|
||||
jpa.findAllByDeactivatedIsFalse()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
override fun getById(id: Long): Client {
|
||||
|
|
@ -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<Client>, scheduledDate: Date?): Report {
|
||||
return mapper.toModel(
|
||||
jpa.save(
|
||||
mapper.toEntity(
|
||||
Report(
|
||||
id = 0,
|
||||
reportDate = scheduledDate ?: Date(),
|
||||
filedBy = filedBy,
|
||||
clients = clients.toMutableList()
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -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<EUserRoles>): 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)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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<Worker> {
|
||||
return mapper.toModels(jpa.findAllByCategory(category))
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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<EUserRoles>)
|
||||
}
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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<Client>
|
||||
fun getClientById(id: Long): Client
|
||||
fun createClient(clientDto: ClientDto): Client
|
||||
}
|
||||
|
|
@ -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<EUserRoles>
|
||||
}
|
||||
|
|
@ -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<Worker>
|
||||
fun getAllWorkersForCategory(workCategory: EWorkerCategory): List<Worker>
|
||||
}
|
||||
|
|
@ -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<EUserRoles>) {
|
||||
if (!userAuthRepository.modifyClaims(username, claims)) {
|
||||
throw LorcaException.create(EBusinessException.IMPOSSIBLE_ADD_ROLES, username)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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)))
|
||||
|
|
@ -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<Client> {
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
|
@ -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<String, Any> = 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<EUserRoles> {
|
||||
return (extractAllClaims(token).get("roles") as List<String>).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<EUserRoles> {
|
||||
return userAuthRepository.getClaimsForUser(user)
|
||||
}
|
||||
}
|
||||
|
|
@ -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<Worker> {
|
||||
return repo.getAll().toList()
|
||||
}
|
||||
|
||||
override fun getAllWorkersForCategory(workCategory: EWorkerCategory): List<Worker> {
|
||||
return repo.getAllByCategory(workCategory)
|
||||
}
|
||||
}
|
||||
|
|
@ -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<Nothing> {
|
||||
adminService.modifyRoles(addRoleDto.username, addRoleDto.roles)
|
||||
return WebResponse.ok()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
@ -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<List<Client>> {
|
||||
return WebResponse.ok(clientService.getAllClients(name, surname))
|
||||
return WebResponse.ok(clientService.getAllClients(includeDeactivated))
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
|
|
@ -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
|
||||
|
|
@ -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<List<Worker>> {
|
||||
return WebResponse.ok(
|
||||
if (category != null) {
|
||||
workerService.getAllWorkersForCategory(category)
|
||||
} else {
|
||||
workerService.getAllWorkers()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@PostMapping("/test")
|
||||
fun createTestData(): WebResponse<Nothing> {
|
||||
// workerService.createTestData()
|
||||
return WebResponse.ok()
|
||||
}
|
||||
}
|
||||
|
|
@ -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<Nothing> {
|
||||
return WebResponse.ko(
|
||||
HttpStatus.FORBIDDEN,
|
||||
"${HttpStatus.FORBIDDEN.reasonPhrase}: ${ex.message}"
|
||||
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@ExceptionHandler(Exception::class)
|
||||
fun handleException(
|
||||
|
|
@ -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()
|
||||
|
|
@ -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<EUserRoles>
|
||||
)
|
||||
|
|
@ -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
|
||||
)
|
||||
|
|
@ -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
|
||||
)
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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?
|
||||
)
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.js.lorca_core.web.advices
|
||||
package org.octopus.lorca_core.web.utils.responses
|
||||
|
||||
import org.springframework.http.HttpStatus
|
||||
|
||||
|
|
@ -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
|
||||
#
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Reference in New Issue