package name change

This commit is contained in:
Jari 2025-03-12 13:21:12 +01:00
parent 1910f30289
commit e2cd042e59
81 changed files with 536 additions and 347 deletions

View File

@ -8,7 +8,7 @@ plugins {
} }
group = "org.js" group = "org.octopus"
version = "0.0.1-SNAPSHOT" version = "0.0.1-SNAPSHOT"

View File

@ -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
)

View File

@ -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
)

View File

@ -1,5 +0,0 @@
package org.js.lorca_core.common.enums
enum class EWorkerCategory {
FISIO
}

View File

@ -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>

View File

@ -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>

View File

@ -1,7 +0,0 @@
package org.js.lorca_core.common.models
data class Client(
var id: Long?,
var name: String,
var surname: String
)

View File

@ -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
)

View File

@ -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?
)

View File

@ -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>

View File

@ -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>

View File

@ -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>
}

View File

@ -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
)

View File

@ -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
}

View File

@ -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>
}

View File

@ -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>
}

View File

@ -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)
}
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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>
}

View File

@ -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))
}
}

View File

@ -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()
}
}

View File

@ -1,9 +1,9 @@
package org.js.lorca_core package org.octopus.lorca_core
import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication import org.springframework.boot.runApplication
@SpringBootApplication(scanBasePackages = ["org.js.lorca_core"]) @SpringBootApplication(scanBasePackages = ["org.octopus.lorca_core"])
class LorcaCoreApplication class LorcaCoreApplication
fun main(args: Array<String>) { fun main(args: Array<String>) {

View File

@ -1,6 +1,7 @@
package org.js.lorca_core.common.enums package org.octopus.lorca_core.common.enums
enum class EBusinessException(val msg: String) { 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_ALREADY_EXISTS("Username: '%s' already exists"),
USER_NOT_FOUND("Username: '%s' not found"), USER_NOT_FOUND("Username: '%s' not found"),
ENTITY_WITH_ID_NOT_FOUND("%s with id %s not found"), ENTITY_WITH_ID_NOT_FOUND("%s with id %s not found"),

View File

@ -1,8 +1,9 @@
package org.js.lorca_core.common.enums package org.octopus.lorca_core.common.enums
enum class EUserRoles(val role: String) { enum class EUserRoles(val role: String) {
FISIO("FISIO"), FISIO("FISIO"),
PSICO("PSICO"), PSICO("PSICO"),
ALL("ALL"), ALL("ALL"),
ADMIN("ADMIN") ADMIN("ADMIN"),
BASE("BASE")
} }

View File

@ -0,0 +1,5 @@
package org.octopus.lorca_core.common.enums
enum class EWorkerCategory {
FISIO
}

View File

@ -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() { class LorcaException(val ex: EBusinessException, override val message: String) : Exception() {

View File

@ -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>

View File

@ -1,4 +1,4 @@
package org.js.lorca_core.common.mappers package org.octopus.lorca_core.common.mappers
interface GenericMapper<M, E> { interface GenericMapper<M, E> {

View File

@ -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>

View File

@ -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.Mapper
import org.mapstruct.Mapping import org.mapstruct.Mapping
import org.octopus.lorca_core.common.models.Worker
import org.octopus.lorca_core.db.entities.WorkerEntity
@Mapper(componentModel = "spring") @Mapper(componentModel = "spring")
interface WorkerMapper : GenericMapper<Worker, WorkerEntity> { interface WorkerMapper : GenericMapper<Worker, WorkerEntity> {

View File

@ -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
)

View File

@ -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()
)

View File

@ -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( data class Worker(
var id: Long, var id: Long,

View File

@ -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.Bean
import org.springframework.context.annotation.Configuration import org.springframework.context.annotation.Configuration
import org.springframework.security.authentication.AuthenticationManager import org.springframework.security.authentication.AuthenticationManager

View File

@ -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.FilterChain
import jakarta.servlet.ServletException import jakarta.servlet.ServletException
import jakarta.servlet.http.HttpServletRequest import jakarta.servlet.http.HttpServletRequest
import jakarta.servlet.http.HttpServletResponse 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.lang.NonNull
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken import org.springframework.security.authentication.UsernamePasswordAuthenticationToken
import org.springframework.security.core.Authentication 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.context.SecurityContextHolder
import org.springframework.security.core.userdetails.UserDetailsService import org.springframework.security.core.userdetails.UserDetailsService
import org.springframework.security.web.authentication.WebAuthenticationDetailsSource import org.springframework.security.web.authentication.WebAuthenticationDetailsSource
@ -44,11 +46,13 @@ class JwtAuthenticationFilter(
if (authentication == null) { if (authentication == null) {
val userDetails = userDetailsService.loadUserByUsername(userEmail) 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( val authToken = UsernamePasswordAuthenticationToken(
userDetails, userDetails,
null, null,
userDetails.authorities roles.map { SimpleGrantedAuthority("ROLE_$it") }
) )
authToken.details = WebAuthenticationDetailsSource().buildDetails(request) authToken.details = WebAuthenticationDetailsSource().buildDetails(request)

View File

@ -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.Bean
import org.springframework.context.annotation.Configuration import org.springframework.context.annotation.Configuration
import org.springframework.security.authentication.AuthenticationProvider 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.builders.HttpSecurity
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
import org.springframework.security.config.http.SessionCreationPolicy import org.springframework.security.config.http.SessionCreationPolicy
@ -13,6 +13,7 @@ import org.springframework.security.web.authentication.UsernamePasswordAuthentic
@Configuration @Configuration
@EnableWebSecurity @EnableWebSecurity
@EnableMethodSecurity(securedEnabled = true)
class SecurityConfig( class SecurityConfig(
val authenticationProvider: AuthenticationProvider, val authenticationProvider: AuthenticationProvider,
val jwtAuthenticationFilter: JwtAuthenticationFilter val jwtAuthenticationFilter: JwtAuthenticationFilter

View File

@ -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>
}

View File

@ -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>

View File

@ -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 org.springframework.data.jpa.repository.JpaRepository
import java.util.* import java.util.*

View File

@ -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>
}

View File

@ -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.Entity
import jakarta.persistence.GeneratedValue import jakarta.persistence.GeneratedValue
@ -10,5 +10,6 @@ data class ClientEntity(
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Id @GeneratedValue(strategy = GenerationType.IDENTITY)
var id: Long = 0L, var id: Long = 0L,
var name: String, var name: String,
var surname: String var surname: String,
val deactivated: Boolean
) )

View File

@ -1,4 +1,4 @@
package org.js.lorca_core.db.entities package org.octopus.lorca_core.db.entities
import jakarta.persistence.* import jakarta.persistence.*
import java.util.* import java.util.*
@ -13,5 +13,5 @@ data class ReportEntity(
val filedBy: WorkerEntity, val filedBy: WorkerEntity,
@OneToMany(fetch = FetchType.LAZY, cascade = [CascadeType.DETACH]) @OneToMany(fetch = FetchType.LAZY, cascade = [CascadeType.DETACH])
val clientEntities: MutableList<ClientEntity> = mutableListOf() val clients: MutableList<ClientEntity> = mutableListOf()
) )

View File

@ -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.GrantedAuthority
import org.springframework.security.core.userdetails.UserDetails import org.springframework.security.core.userdetails.UserDetails
@ -9,11 +13,25 @@ class UserAuthEntity(usr: String, pwd: String) : UserDetails {
@Id @Id
@GeneratedValue @GeneratedValue
var id: Long? = null var id: Long? = null
@Column(nullable = false, unique = true)
var usr: String? = usr var usr: String? = usr
@Column(nullable = false, unique = true)
var pwd: String? = pwd var pwd: String? = pwd
@ManyToMany(cascade = [CascadeType.DETACH]) @Column(length = 255)
var claims: MutableList<UserAuthClaimEntity> = mutableListOf() 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> { override fun getAuthorities(): Collection<GrantedAuthority> {
return listOf() return listOf()

View File

@ -1,7 +1,7 @@
package org.js.lorca_core.db.entities package org.octopus.lorca_core.db.entities
import jakarta.persistence.* import jakarta.persistence.*
import org.js.lorca_core.common.enums.EWorkerCategory import org.octopus.lorca_core.common.enums.EWorkerCategory
@Entity(name = "workers") @Entity(name = "workers")
data class WorkerEntity( data class WorkerEntity(

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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>
}

View File

@ -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.octopus.lorca_core.common.enums.EBusinessException
import org.js.lorca_core.common.exceptions.LorcaException import org.octopus.lorca_core.common.exceptions.LorcaException
import org.js.lorca_core.common.mappers.ClientMapper import org.octopus.lorca_core.common.mappers.ClientMapper
import org.js.lorca_core.common.models.Client import org.octopus.lorca_core.common.models.Client
import org.js.lorca_core.db.ClientJpa import org.octopus.lorca_core.db.ClientJpa
import org.js.lorca_core.repositories.ClientRepository import org.octopus.lorca_core.repositories.ClientRepository
import org.springframework.stereotype.Component import org.springframework.stereotype.Component
@Component @Component
@ -18,8 +18,14 @@ class ClientRepositoryImpl(
} }
override fun getAll(): MutableList<Client> { override fun getAll(includeNotActive: Boolean): MutableList<Client> {
return mapper.toModels(jpa.findAll()) return mapper.toModels(
if (includeNotActive) {
jpa.findAll()
} else {
jpa.findAllByDeactivatedIsFalse()
}
)
} }
override fun getById(id: Long): Client { override fun getById(id: Long): Client {

View File

@ -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()
)
)
)
)
}
}

View File

@ -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)
}
}

View File

@ -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.octopus.lorca_core.common.enums.EUserRoles
import org.js.lorca_core.common.models.Worker import org.octopus.lorca_core.common.enums.EWorkerCategory
import org.js.lorca_core.db.WorkerJpa import org.octopus.lorca_core.common.mappers.WorkerMapper
import org.js.lorca_core.db.entities.UserAuthEntity import org.octopus.lorca_core.common.models.Worker
import org.js.lorca_core.repositories.WorkerRepository 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 org.springframework.stereotype.Component
import kotlin.jvm.optionals.getOrNull import kotlin.jvm.optionals.getOrNull
@ -21,6 +23,7 @@ class WorkerRepositoryImpl(
override fun createForUser(worker: Worker, userAuth: UserAuthEntity): Worker { override fun createForUser(worker: Worker, userAuth: UserAuthEntity): Worker {
val w = mapper.toEntity(worker) val w = mapper.toEntity(worker)
w.authUser = userAuth w.authUser = userAuth
userAuth.setClaimsList(listOf(EUserRoles.FISIO, EUserRoles.ADMIN))
val ent = jpa.save(w) val ent = jpa.save(w)
return mapper.toModel(ent) return mapper.toModel(ent)
} }
@ -29,4 +32,8 @@ class WorkerRepositoryImpl(
return mapper.toModels(jpa.findAll()) return mapper.toModels(jpa.findAll())
} }
override fun getAllByCategory(category: EWorkerCategory): MutableList<Worker> {
return mapper.toModels(jpa.findAllByCategory(category))
}
} }

View File

@ -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>)
}

View File

@ -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
}

View File

@ -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
}

View File

@ -1,6 +1,7 @@
package org.js.lorca_core.services package org.octopus.lorca_core.services
import io.jsonwebtoken.Claims import io.jsonwebtoken.Claims
import org.octopus.lorca_core.common.enums.EUserRoles
import org.springframework.security.core.userdetails.UserDetails import org.springframework.security.core.userdetails.UserDetails
import java.util.function.Function import java.util.function.Function
@ -17,4 +18,6 @@ interface JwtService {
fun getExpirationTime(): Long fun getExpirationTime(): Long
fun isTokenValid(token: String, userDetails: UserDetails): Boolean fun isTokenValid(token: String, userDetails: UserDetails): Boolean
fun getRoles(token: String): List<EUserRoles>
} }

View File

@ -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>
}

View File

@ -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)
}
}
}

View File

@ -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.octopus.lorca_core.common.enums.EBusinessException
import org.js.lorca_core.common.enums.EBusinessException import org.octopus.lorca_core.common.exceptions.LorcaException
import org.js.lorca_core.common.exceptions.LorcaException import org.octopus.lorca_core.db.entities.UserAuthEntity
import org.js.lorca_core.common.responses.LoginResponse import org.octopus.lorca_core.repositories.UserAuthRepository
import org.js.lorca_core.db.entities.UserAuthEntity import org.octopus.lorca_core.repositories.WorkerRepository
import org.js.lorca_core.repositories.UserAuthRepository import org.octopus.lorca_core.services.AuthenticationService
import org.js.lorca_core.repositories.WorkerRepository import org.octopus.lorca_core.services.JwtService
import org.js.lorca_core.services.AuthenticationService import org.octopus.lorca_core.web.utils.dtos.UserAuthDto
import org.js.lorca_core.services.JwtService import org.octopus.lorca_core.web.utils.responses.LoginResponse
import org.springframework.security.authentication.AuthenticationManager import org.springframework.security.authentication.AuthenticationManager
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken import org.springframework.security.authentication.UsernamePasswordAuthenticationToken
import org.springframework.security.crypto.password.PasswordEncoder import org.springframework.security.crypto.password.PasswordEncoder
@ -26,7 +26,7 @@ class AuthenticationServiceImpl(
override fun register(dto: UserAuthDto): Boolean { override fun register(dto: UserAuthDto): Boolean {
if (userAuthRepository.existsByUsername(dto.username)) { 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))) userAuthRepository.save(UserAuthEntity(dto.username, passwordEncoder.encode(dto.password)))

View File

@ -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))
}
}

View File

@ -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.Claims
import io.jsonwebtoken.Jwts import io.jsonwebtoken.Jwts
import io.jsonwebtoken.io.Decoders import io.jsonwebtoken.io.Decoders
import io.jsonwebtoken.security.Keys import io.jsonwebtoken.security.Keys
import org.js.lorca_core.common.enums.EUserRoles import org.octopus.lorca_core.common.enums.EUserRoles
import org.js.lorca_core.db.entities.UserAuthEntity import org.octopus.lorca_core.repositories.UserAuthRepository
import org.js.lorca_core.repositories.UserAuthRepository import org.octopus.lorca_core.services.JwtService
import org.js.lorca_core.services.JwtService
import org.springframework.beans.factory.annotation.Value import org.springframework.beans.factory.annotation.Value
import org.springframework.security.core.userdetails.UserDetails import org.springframework.security.core.userdetails.UserDetails
import org.springframework.stereotype.Service import org.springframework.stereotype.Service
@ -37,7 +36,7 @@ class JwtServiceImpl(
override fun generateToken(userDetails: UserDetails): String { override fun generateToken(userDetails: UserDetails): String {
val extraClaims: MutableMap<String, Any> = mutableMapOf() val extraClaims: MutableMap<String, Any> = mutableMapOf()
getClaimsForUser(userAuthRepository.getByUsername(userDetails.username)).let { claims -> userAuthRepository.getByUsername(userDetails.username).getClaimsList().let { claims ->
if (claims.isNotEmpty()) { if (claims.isNotEmpty()) {
extraClaims["roles"] = claims extraClaims["roles"] = claims
} }
@ -75,6 +74,10 @@ class JwtServiceImpl(
return (username == userDetails.username) && !isTokenExpired(token) 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 { private fun isTokenExpired(token: String): Boolean {
return extractExpiration(token).before(Date()) return extractExpiration(token).before(Date())
} }
@ -95,8 +98,4 @@ class JwtServiceImpl(
val keyBytes = Decoders.BASE64.decode(secretKey) val keyBytes = Decoders.BASE64.decode(secretKey)
return Keys.hmacShaKeyFor(keyBytes) return Keys.hmacShaKeyFor(keyBytes)
} }
private fun getClaimsForUser(user: UserAuthEntity): List<EUserRoles> {
return userAuthRepository.getClaimsForUser(user)
}
} }

View File

@ -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.octopus.lorca_core.common.enums.EWorkerCategory
import org.js.lorca_core.common.models.Worker import org.octopus.lorca_core.common.models.Worker
import org.js.lorca_core.repositories.UserAuthRepository import org.octopus.lorca_core.repositories.UserAuthRepository
import org.js.lorca_core.repositories.WorkerRepository import org.octopus.lorca_core.repositories.WorkerRepository
import org.js.lorca_core.services.WorkerService import org.octopus.lorca_core.services.WorkerService
import org.springframework.stereotype.Service import org.springframework.stereotype.Service
@Service @Service
@ -22,4 +22,8 @@ class WorkerServiceImpl(val repo: WorkerRepository, val authRepository: UserAuth
override fun getAllWorkers(): List<Worker> { override fun getAllWorkers(): List<Worker> {
return repo.getAll().toList() return repo.getAll().toList()
} }
override fun getAllWorkersForCategory(workCategory: EWorkerCategory): List<Worker> {
return repo.getAllByCategory(workCategory)
}
} }

View File

@ -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()
}
}

View File

@ -1,11 +1,11 @@
package org.js.lorca_core.web.controllers package org.octopus.lorca_core.web.controllers
import jakarta.validation.Valid import jakarta.validation.Valid
import lombok.AllArgsConstructor import lombok.AllArgsConstructor
import org.js.lorca_core.common.dtos.UserAuthDto import org.octopus.lorca_core.services.AuthenticationService
import org.js.lorca_core.common.responses.LoginResponse import org.octopus.lorca_core.web.utils.dtos.UserAuthDto
import org.js.lorca_core.services.AuthenticationService import org.octopus.lorca_core.web.utils.responses.LoginResponse
import org.js.lorca_core.web.advices.WebResponse import org.octopus.lorca_core.web.utils.responses.WebResponse
import org.springframework.web.bind.annotation.PostMapping import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RequestMapping

View File

@ -1,11 +1,11 @@
package org.js.lorca_core.web.controllers package org.octopus.lorca_core.web.controllers
import jakarta.validation.Valid import jakarta.validation.Valid
import lombok.AllArgsConstructor import lombok.AllArgsConstructor
import org.js.lorca_core.common.dtos.ClientDto import org.octopus.lorca_core.common.models.Client
import org.js.lorca_core.common.models.Client import org.octopus.lorca_core.services.ClientService
import org.js.lorca_core.services.ClientService import org.octopus.lorca_core.web.utils.dtos.ClientDto
import org.js.lorca_core.web.advices.WebResponse import org.octopus.lorca_core.web.utils.responses.WebResponse
import org.springframework.web.bind.annotation.* import org.springframework.web.bind.annotation.*
@RestController @RestController
@ -17,10 +17,12 @@ class ClientController(
@GetMapping @GetMapping
fun getAllClients( fun getAllClients(
@RequestParam("name", required = false, defaultValue = "") name: String, @RequestParam(
@RequestParam("surname", required = false, defaultValue = "") surname: String "includeDeactivated",
required = false
) includeDeactivated: Boolean = false
): WebResponse<List<Client>> { ): WebResponse<List<Client>> {
return WebResponse.ok(clientService.getAllClients(name, surname)) return WebResponse.ok(clientService.getAllClients(includeDeactivated))
} }
@PostMapping @PostMapping

View File

@ -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

View File

@ -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()
}
}

View File

@ -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.octopus.lorca_core.common.enums.EBusinessException
import org.js.lorca_core.common.exceptions.LorcaException 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.HttpStatus
import org.springframework.http.converter.HttpMessageNotReadableException import org.springframework.http.converter.HttpMessageNotReadableException
import org.springframework.security.authorization.AuthorizationDeniedException
import org.springframework.web.HttpRequestMethodNotSupportedException import org.springframework.web.HttpRequestMethodNotSupportedException
import org.springframework.web.bind.MethodArgumentNotValidException import org.springframework.web.bind.MethodArgumentNotValidException
import org.springframework.web.bind.annotation.ExceptionHandler import org.springframework.web.bind.annotation.ExceptionHandler
@ -28,6 +30,7 @@ class BaseAdvice {
private fun deductStatus(ex: EBusinessException): HttpStatus { private fun deductStatus(ex: EBusinessException): HttpStatus {
return when (ex) { return when (ex) {
EBusinessException.IMPOSSIBLE_ADD_ROLES -> HttpStatus.EXPECTATION_FAILED
EBusinessException.USER_ALREADY_EXISTS -> HttpStatus.UNPROCESSABLE_ENTITY EBusinessException.USER_ALREADY_EXISTS -> HttpStatus.UNPROCESSABLE_ENTITY
EBusinessException.USER_NOT_FOUND -> HttpStatus.NOT_FOUND EBusinessException.USER_NOT_FOUND -> HttpStatus.NOT_FOUND
EBusinessException.ENTITY_WITH_ID_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) @ExceptionHandler(Exception::class)
fun handleException( fun handleException(

View File

@ -1,10 +1,10 @@
package org.js.lorca_core.web.advices package org.octopus.lorca_core.web.utils
//@Aspect //@Aspect
//@Component //@Component
class LoggingAspect { class LoggingAspect {
// @Around("execution(* org.js.lorca_core.web.controllers.*.*(..))") // @Around("execution(* org.octopus.lorca_core.web.controllers.*.*(..))")
// @Throws(Throwable::class) // @Throws(Throwable::class)
// fun logMethodDetails(proceedingJoinPoint: ProceedingJoinPoint): Any? { // fun logMethodDetails(proceedingJoinPoint: ProceedingJoinPoint): Any? {
// val methodName = proceedingJoinPoint.signature.toShortString() // val methodName = proceedingJoinPoint.signature.toShortString()

View File

@ -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>
)

View File

@ -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
)

View File

@ -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
)

View File

@ -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.Constraint
import jakarta.validation.ConstraintValidator import jakarta.validation.ConstraintValidator

View File

@ -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.Constraint
import jakarta.validation.ConstraintValidator import jakarta.validation.ConstraintValidator

View File

@ -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.Constraint
import jakarta.validation.ConstraintValidator import jakarta.validation.ConstraintValidator

View File

@ -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?
)

View File

@ -1,4 +1,4 @@
package org.js.lorca_core.web.advices package org.octopus.lorca_core.web.utils.responses
import org.springframework.http.HttpStatus import org.springframework.http.HttpStatus

View File

@ -20,3 +20,6 @@ security.jwt.secret-key=93d5326c5ae622c9332f291c6a9868d237e6b41fc47c5f2581448d4d
security.jwt.expiration-time=3600000 security.jwt.expiration-time=3600000
# #
# #
# WHATSAPP API: https://developers.facebook.com/docs/whatsapp/cloud-api/overview
# MAIL SERVICE: https://sendgrid.com/en-us/pricing
#

View File

@ -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 import org.springframework.boot.test.context.SpringBootTest
@SpringBootTest @SpringBootTest

View File

@ -2,8 +2,9 @@ TOKEN=$(curl -s -X POST http://localhost:8080/api/auth/login \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d '{"username":"test","password":"cGFzc3dvcmQ="}' | sed -n 's/.*"token":"\([^"]*\)".*/\1/p') -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" -X POST http://localhost:8080/api/workers/test
curl -H "Authorization: Bearer $TOKEN" -XGET http://localhost:8080/api/workers #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"