Add logic for qrs extracting and add database change log for oauth2 clients
This commit is contained in:
parent
913c895cab
commit
81f7e5ebde
@ -0,0 +1,12 @@
|
|||||||
|
package ru.vyatsu.qr_access_api.controller
|
||||||
|
|
||||||
|
import org.springframework.http.ResponseEntity
|
||||||
|
import ru.vyatsu.apis.QrApi
|
||||||
|
import ru.vyatsu.models.QrCodesResponse
|
||||||
|
import ru.vyatsu.qr_access_api.service.QrSyncService
|
||||||
|
|
||||||
|
class QrSyncController(val syncService: QrSyncService) : QrApi {
|
||||||
|
|
||||||
|
override fun getQrCodes(): ResponseEntity<QrCodesResponse> =
|
||||||
|
ResponseEntity.ok(QrCodesResponse(syncService.getQrCodes()))
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package ru.vyatsu.qr_access_api.controller
|
||||||
|
|
||||||
|
import org.springframework.http.HttpStatusCode
|
||||||
|
import org.springframework.http.ResponseEntity
|
||||||
|
import org.springframework.web.client.HttpServerErrorException
|
||||||
|
import ru.vyatsu.apis.QrUsedApi
|
||||||
|
|
||||||
|
class QrUsedController : QrUsedApi {
|
||||||
|
override fun markQrCodeAsUsed(qrId: String): ResponseEntity<Unit> {
|
||||||
|
throw HttpServerErrorException(HttpStatusCode.valueOf(501))
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
package ru.vyatsu.qr_access_api.repository
|
||||||
|
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate
|
||||||
|
import org.springframework.stereotype.Repository
|
||||||
|
import ru.vyatsu.models.QrCode
|
||||||
|
import java.time.ZoneOffset
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
private const val GET_QRS_BY_DOOR_IDS =
|
||||||
|
"SELECT key_code, door_id, start_date_time, end_date_time FROM qrs WHERE door_id IN (?)"
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
class QrRepository(private val template: JdbcTemplate) {
|
||||||
|
|
||||||
|
fun getActualQrCodesByDoorIds(doorIds: Array<String>): List<QrCode> {
|
||||||
|
return when {
|
||||||
|
doorIds.isNotEmpty() -> template.query({ conn ->
|
||||||
|
val doorIdsDbArray = conn.createArrayOf("TEXT", doorIds)
|
||||||
|
val stmt = conn.prepareStatement(GET_QRS_BY_DOOR_IDS)
|
||||||
|
stmt.setArray(1, doorIdsDbArray)
|
||||||
|
stmt
|
||||||
|
}, { rs, _ ->
|
||||||
|
QrCode(
|
||||||
|
rs.getTimestamp("start_date_time").toLocalDateTime().atOffset(ZoneOffset.UTC),
|
||||||
|
rs.getTimestamp("end_date_time").toLocalDateTime().atOffset(ZoneOffset.UTC),
|
||||||
|
UUID.fromString(rs.getString("door_id")),
|
||||||
|
UUID.fromString(rs.getString("key_code"))
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
else -> listOf()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package ru.vyatsu.qr_access_api.service
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service
|
||||||
|
import ru.vyatsu.models.QrCode
|
||||||
|
import ru.vyatsu.qr_access_api.repository.QrRepository
|
||||||
|
|
||||||
|
@Service
|
||||||
|
class QrSyncService(val qrRepository: QrRepository) {
|
||||||
|
fun getQrCodes(): List<QrCode> {
|
||||||
|
// TODO: Тут логика с извлечением клайма из jwt в котором идентификатор клиента лежит
|
||||||
|
val extractedDoorIds = arrayOf("945c8621-9adc-4a49-bc56-10253d27c581", "4dbf27d7-df77-493d-b970-67f8a5178eb9")
|
||||||
|
// TODO: Переделать на передачу unitId и извлечь из бд unit и двери, которые ему принадлежат
|
||||||
|
return qrRepository.getActualQrCodesByDoorIds(extractedDoorIds)
|
||||||
|
}
|
||||||
|
}
|
@ -1 +1,4 @@
|
|||||||
spring.application.name=qr-access-api
|
spring.application.name=qr-access-api
|
||||||
|
spring.datasource.url=jdbc:postgresql://localhost:5432/qr_access
|
||||||
|
spring.datasource.username=qr_access_user
|
||||||
|
spring.datasource.password=123
|
63
src/main/resources/db/changelog/1.0.0/changelog.yml
Normal file
63
src/main/resources/db/changelog/1.0.0/changelog.yml
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
databaseChangeLog:
|
||||||
|
- changeSet:
|
||||||
|
id: create-oauth2-registered-clients
|
||||||
|
author: d.krupin
|
||||||
|
changes:
|
||||||
|
- createTable:
|
||||||
|
tableName: oauth2_authorized_client
|
||||||
|
columns:
|
||||||
|
- column:
|
||||||
|
constraints:
|
||||||
|
nullable: false
|
||||||
|
primaryKey: true
|
||||||
|
primaryKeyName: PK_oauth2_client
|
||||||
|
name: client_registration_id
|
||||||
|
type: VARCHAR(100)
|
||||||
|
- column:
|
||||||
|
constraints:
|
||||||
|
nullable: false
|
||||||
|
primaryKey: true
|
||||||
|
primaryKeyName: PK_oauth2_client
|
||||||
|
name: principal_name
|
||||||
|
type: VARCHAR(200)
|
||||||
|
- column:
|
||||||
|
name: access_token_type
|
||||||
|
type: VARCHAR(100)
|
||||||
|
constraints:
|
||||||
|
nullable: false
|
||||||
|
- column:
|
||||||
|
name: access_token_value
|
||||||
|
type: TEXT
|
||||||
|
constraints:
|
||||||
|
nullable: false
|
||||||
|
- column:
|
||||||
|
name: access_token_issued_at
|
||||||
|
type: TIMESTAMP
|
||||||
|
constraints:
|
||||||
|
nullable: false
|
||||||
|
- column:
|
||||||
|
name: access_token_expires_at
|
||||||
|
type: TIMESTAMP
|
||||||
|
constraints:
|
||||||
|
nullable: false
|
||||||
|
- column:
|
||||||
|
name: access_token_scopes
|
||||||
|
type: TEXT
|
||||||
|
constraints:
|
||||||
|
nullable: true
|
||||||
|
- column:
|
||||||
|
name: refresh_token_value
|
||||||
|
type: TEXT
|
||||||
|
constraints:
|
||||||
|
nullable: true
|
||||||
|
- column:
|
||||||
|
name: refresh_token_issued_at
|
||||||
|
type: TIMESTAMP
|
||||||
|
constraints:
|
||||||
|
nullable: true
|
||||||
|
- column:
|
||||||
|
name: created_at
|
||||||
|
type: TIMESTAMP
|
||||||
|
constraints:
|
||||||
|
nullable: false
|
||||||
|
defaultValueComputed: CURRENT_TIMESTAMP
|
3
src/main/resources/db/changelog/db.changelog-master.yaml
Normal file
3
src/main/resources/db/changelog/db.changelog-master.yaml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
databaseChangeLog:
|
||||||
|
- include:
|
||||||
|
file: db/changelog/1.0.0/changelog.yml
|
Loading…
Reference in New Issue
Block a user