diff --git a/.gitignore b/.gitignore index d0038b5..62d874f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /.idea/ /.vscode/ +/.postman/ diff --git a/backend/Dockerfile b/Dockerfile similarity index 100% rename from backend/Dockerfile rename to Dockerfile diff --git a/backend/build.gradle.kts b/backend/build.gradle.kts index 64c3d68..8a51c2b 100644 --- a/backend/build.gradle.kts +++ b/backend/build.gradle.kts @@ -33,7 +33,7 @@ dependencies { implementation("org.jetbrains.kotlin:kotlin-reflect") implementation("com.fasterxml.jackson.module:jackson-module-kotlin") - implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:3.0.3") + implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.13") developmentOnly("org.springframework.boot:spring-boot-devtools") developmentOnly("org.springframework.boot:spring-boot-docker-compose") diff --git a/backend/src/main/kotlin/io/github/devcavin/backend/domain/repository/UserRepository.kt b/backend/src/main/kotlin/io/github/devcavin/backend/domain/repository/UserRepository.kt index e7f545c..2bc04c5 100644 --- a/backend/src/main/kotlin/io/github/devcavin/backend/domain/repository/UserRepository.kt +++ b/backend/src/main/kotlin/io/github/devcavin/backend/domain/repository/UserRepository.kt @@ -13,6 +13,18 @@ interface UserRepository : JpaRepository{ fun findAllBySiteId(siteId: UUID): List fun findAllBySiteIdAndIsActiveTrue(siteId: UUID): List - @Query("SELECT u FROM User u JOIN FETCH u.role WHERE u.email = :email") + @Query("SELECT DISTINCT u FROM User u JOIN FETCH u.role WHERE u.id = :id") + fun findByIdWithRole(id: UUID): User? + + @Query("SELECT DISTINCT u FROM User u JOIN FETCH u.role WHERE u.email = :email") fun findByEmailWithRole(email: String): User? + + @Query("SELECT DISTINCT u FROM User u JOIN FETCH u.role") + fun findAllWithRole(): List + + @Query("SELECT DISTINCT u FROM User u JOIN FETCH u.role WHERE u.site.id = :siteId") + fun findAllBySiteIdWithRole(siteId: UUID): List + + @Query("SELECT u FROM User u JOIN FETCH u.role JOIN FETCH u.site WHERE u.id = :id") + fun findByIdWithRoleAndSite(id: UUID): User? } \ No newline at end of file diff --git a/backend/src/main/kotlin/io/github/devcavin/backend/security/JwtAuthenticationFilter.kt b/backend/src/main/kotlin/io/github/devcavin/backend/security/JwtAuthenticationFilter.kt index 6f94933..399546e 100644 --- a/backend/src/main/kotlin/io/github/devcavin/backend/security/JwtAuthenticationFilter.kt +++ b/backend/src/main/kotlin/io/github/devcavin/backend/security/JwtAuthenticationFilter.kt @@ -26,7 +26,7 @@ class JwtAuthenticationFilter( val userId = jwtTokenProvider.getUserIdFromToken(token) val role = jwtTokenProvider.getRoleFromToken(token) - val user = userRepository.findById(userId).orElse(null) + val user = userRepository.findByIdWithRoleAndSite(userId) if (user != null && user.isActive) { val authorities = listOf(SimpleGrantedAuthority("ROLE_$role")) diff --git a/backend/src/main/kotlin/io/github/devcavin/backend/service/UserService.kt b/backend/src/main/kotlin/io/github/devcavin/backend/service/UserService.kt index 0f3a3d1..bf14208 100644 --- a/backend/src/main/kotlin/io/github/devcavin/backend/service/UserService.kt +++ b/backend/src/main/kotlin/io/github/devcavin/backend/service/UserService.kt @@ -50,10 +50,13 @@ class UserService( @Transactional(readOnly = true) fun getAll(requestedBy: User): List { - return when (requestedBy.role.name) { - "SUPER_ADMIN" -> userRepository.findAll().map { it.toResponse() } + val roleName = requestedBy.role.name + val siteId = requestedBy.site.id!! + + return when (roleName) { + "SUPER_ADMIN" -> userRepository.findAllWithRole().map { it.toResponse() } else -> userRepository - .findAllBySiteId(requestedBy.site.id!!) + .findAllBySiteIdWithRole(siteId) .map { it.toResponse() } } } diff --git a/backend/src/main/kotlin/io/github/devcavin/backend/web/dto/user/UserDTOs.kt b/backend/src/main/kotlin/io/github/devcavin/backend/web/dto/user/UserDTOs.kt index 0afa570..509c1ad 100644 --- a/backend/src/main/kotlin/io/github/devcavin/backend/web/dto/user/UserDTOs.kt +++ b/backend/src/main/kotlin/io/github/devcavin/backend/web/dto/user/UserDTOs.kt @@ -21,7 +21,6 @@ data class CreateUserRequest( @field:NotBlank val roleName: String, - @field:NotBlank val siteId: UUID ) diff --git a/backend/src/main/kotlin/io/github/devcavin/backend/web/dto/zone/ZoneDTOs.kt b/backend/src/main/kotlin/io/github/devcavin/backend/web/dto/zone/ZoneDTOs.kt index e742e1c..afc6d2a 100644 --- a/backend/src/main/kotlin/io/github/devcavin/backend/web/dto/zone/ZoneDTOs.kt +++ b/backend/src/main/kotlin/io/github/devcavin/backend/web/dto/zone/ZoneDTOs.kt @@ -3,8 +3,7 @@ package io.github.devcavin.backend.web.dto.zone import io.github.devcavin.backend.domain.model.Zone import jakarta.validation.constraints.NotBlank import jakarta.validation.constraints.Size -import org.springframework.data.jpa.domain.AbstractPersistable_.id -import java.util.UUID +import java.util.* data class ZoneRequest( @field:NotBlank diff --git a/backend/src/main/resources/application.yaml b/backend/src/main/resources/application.yaml index 3a503ee..fca2e7f 100644 --- a/backend/src/main/resources/application.yaml +++ b/backend/src/main/resources/application.yaml @@ -18,7 +18,6 @@ spring: properties: hibernate: format_sql: true - dialect: org.hibernate.dialect.PostgreSQLDialect jdbc: batch_size: 50 open-in-view: false @@ -27,10 +26,6 @@ spring: enabled: true locations: classpath:db/migration baseline-on-migrate: false - web: - error: - include-binding-errors: always - include-message: always server: port: 8080 diff --git a/backend/src/main/resources/db/migration/V8__create_visitor_profiles.sql b/backend/src/main/resources/db/migration/V8__create_visitor_profiles.sql index e7acb2e..cd16e2c 100644 --- a/backend/src/main/resources/db/migration/V8__create_visitor_profiles.sql +++ b/backend/src/main/resources/db/migration/V8__create_visitor_profiles.sql @@ -8,9 +8,9 @@ CREATE TABLE visitor_profiles( CONSTRAINT uq_visitor_profiles_phone_site UNIQUE(phone_number, site_id) ); -CREATE INDEX idx_visitor_profiles_phone ON visitor_profiles(phone_number) -CREATE INDEX idx_visitor_profiles_site_id ON visitor_profiles(site_id) +CREATE INDEX idx_visitor_profiles_phone ON visitor_profiles(phone_number); +CREATE INDEX idx_visitor_profiles_site_id ON visitor_profiles(site_id); ALTER TABLE visitors ADD column visitor_profile_id UUID REFERENCES visitor_profiles(id); -CREATE INDEX idx_visitors_profile_id ON visitors(visitor_profile_id) \ No newline at end of file +CREATE INDEX idx_visitors_profile_id ON visitors(visitor_profile_id); \ No newline at end of file diff --git a/backend/compose.yaml b/compose.yaml similarity index 100% rename from backend/compose.yaml rename to compose.yaml