+ google drive
This commit is contained in:
@@ -13,6 +13,8 @@ import space.luminic.finance.dtos.UserDTO.RegisterUserDTO
|
||||
import space.luminic.finance.mappers.UserMapper.toDto
|
||||
import space.luminic.finance.mappers.UserMapper.toTelegramMap
|
||||
import space.luminic.finance.services.AuthService
|
||||
import space.luminic.finance.services.GoogleDriveService
|
||||
import space.luminic.finance.services.UserService
|
||||
import java.net.URLDecoder
|
||||
import java.security.MessageDigest
|
||||
import java.time.Instant
|
||||
@@ -23,6 +25,8 @@ import javax.crypto.spec.SecretKeySpec
|
||||
@RequestMapping("/auth")
|
||||
class AuthController(
|
||||
private val authService: AuthService,
|
||||
private val googleDriveService: GoogleDriveService,
|
||||
private val userService: UserService,
|
||||
@Value("\${telegram.bot.token}") private val botToken: String
|
||||
) {
|
||||
|
||||
@@ -183,4 +187,18 @@ class AuthController(
|
||||
|
||||
return authService.getSecurityUser().toDto()
|
||||
}
|
||||
|
||||
@PostMapping("/me/google-drive")
|
||||
fun linkGoogleDrive(@RequestBody request: UserDTO.GoogleAuthDTO): Map<String, String> {
|
||||
val user = authService.getSecurityUser()
|
||||
val refreshToken = googleDriveService.exchangeCodeForRefreshToken(request.code)
|
||||
|
||||
if (refreshToken.isNotEmpty()) {
|
||||
user.googleRefreshToken = refreshToken
|
||||
userService.update(user)
|
||||
return mapOf("status" to "success", "message" to "Google Drive linked successfully")
|
||||
} else {
|
||||
throw IllegalArgumentException("Failed to exchange code for refresh token")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package space.luminic.finance.api
|
||||
|
||||
import org.springframework.http.HttpHeaders
|
||||
import org.springframework.http.MediaType
|
||||
import org.springframework.http.ResponseEntity
|
||||
import io.swagger.v3.oas.annotations.enums.SecuritySchemeType
|
||||
import io.swagger.v3.oas.annotations.security.SecurityScheme
|
||||
import org.springframework.web.bind.annotation.*
|
||||
@@ -26,6 +29,18 @@ class TransactionController (
|
||||
return transactionService.getTransactions(spaceId, filter).map { it.toDto() }
|
||||
}
|
||||
|
||||
@PostMapping("/_export")
|
||||
fun exportExcel(@PathVariable spaceId: Int, @RequestBody filter: TransactionService.TransactionsFilter): ResponseEntity<ByteArray> {
|
||||
val excelBytes = transactionService.generateExcel(spaceId, filter)
|
||||
val headers = HttpHeaders()
|
||||
headers.contentType = MediaType.APPLICATION_OCTET_STREAM
|
||||
headers.setContentDispositionFormData("attachment", "transactions.xlsx")
|
||||
|
||||
return ResponseEntity.ok()
|
||||
.headers(headers)
|
||||
.body(excelBytes)
|
||||
}
|
||||
|
||||
@GetMapping("/{transactionId}")
|
||||
fun getTransaction(@PathVariable spaceId: Int, @PathVariable transactionId: Int): TransactionDTO {
|
||||
return transactionService.getTransaction(spaceId, transactionId).toDto()
|
||||
|
||||
Reference in New Issue
Block a user