-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0c9d4fc
commit 924f57c
Showing
4 changed files
with
168 additions
and
5 deletions.
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
...src/main/kotlin/com/aamdigital/aambackendservice/skill/controller/SkillAdminController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package com.aamdigital.aambackendservice.skill.controller | ||
|
||
import com.aamdigital.aambackendservice.error.HttpErrorDto | ||
import com.aamdigital.aambackendservice.skill.core.FetchUserProfileUpdatesRequest | ||
import com.aamdigital.aambackendservice.skill.core.FetchUserProfileUpdatesUseCase | ||
import com.aamdigital.aambackendservice.skill.repository.SkillLabUserProfileSyncRepository | ||
import org.slf4j.LoggerFactory | ||
import org.springframework.http.ResponseEntity | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.PathVariable | ||
import org.springframework.web.bind.annotation.PostMapping | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
import java.time.Instant | ||
import java.time.ZoneOffset | ||
import kotlin.jvm.optionals.getOrElse | ||
|
||
data class SkillDto( | ||
val projectId: String, | ||
val latestSync: String, | ||
) | ||
|
||
enum class SyncModeDto { | ||
DELTA, | ||
FULL, | ||
} | ||
|
||
@RestController | ||
@RequestMapping("/v1/skill") | ||
class SkillAdminController( | ||
private val skillLabFetchUserProfileUpdatesUseCase: FetchUserProfileUpdatesUseCase, | ||
private val skillLabUserProfileSyncRepository: SkillLabUserProfileSyncRepository, | ||
) { | ||
|
||
private val logger = LoggerFactory.getLogger(javaClass) | ||
|
||
|
||
@GetMapping("/sync") | ||
fun fetchSyncStatus(): ResponseEntity<List<SkillDto>> { | ||
val result = skillLabUserProfileSyncRepository.findAll().mapNotNull { | ||
SkillDto( | ||
projectId = it.projectId, | ||
latestSync = it.latestSync.toString() | ||
) | ||
} | ||
|
||
return ResponseEntity.ok().body(result) | ||
} | ||
|
||
@PostMapping("/sync/{projectId}") | ||
fun triggerSync( | ||
@PathVariable projectId: String, | ||
syncMode: SyncModeDto = SyncModeDto.DELTA, | ||
updatedFrom: String? = null, | ||
): ResponseEntity<Any> { | ||
|
||
val result = skillLabUserProfileSyncRepository.findByProjectId(projectId).getOrElse { | ||
return ResponseEntity.notFound().build() | ||
} | ||
|
||
when (syncMode) { | ||
SyncModeDto.DELTA -> if (!updatedFrom.isNullOrBlank()) { | ||
result.latestSync = Instant.parse(updatedFrom).atOffset(ZoneOffset.UTC) | ||
skillLabUserProfileSyncRepository.save(result) | ||
} | ||
|
||
SyncModeDto.FULL -> skillLabUserProfileSyncRepository.delete(result) | ||
} | ||
|
||
try { | ||
skillLabFetchUserProfileUpdatesUseCase.run( | ||
request = FetchUserProfileUpdatesRequest( | ||
projectId = projectId | ||
) | ||
) | ||
} catch (ex: Exception) { | ||
logger.error( | ||
"[${this.javaClass.name}] An error occurred: {}", | ||
ex.localizedMessage, | ||
ex | ||
) | ||
return ResponseEntity.internalServerError().body( | ||
HttpErrorDto( | ||
errorCode = "INTERNAL_SERVER_ERROR", | ||
errorMessage = ex.localizedMessage, | ||
) | ||
) | ||
} | ||
|
||
|
||
return ResponseEntity.noContent().build() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,7 @@ logging: | |
logback: | ||
rollingpolicy: | ||
max-file-size: 100MB | ||
|
||
--- | ||
|
||
spring: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters