chore: things done a very nice and usable git commit
This commit is contained in:
@@ -71,7 +71,7 @@ data class Application(
|
||||
|
||||
data class SubmitRequest(val text: String)
|
||||
|
||||
data class ListRequest(val status: Int?)
|
||||
data class ListRequest(val status: Int? = null, val views: Boolean? = null)
|
||||
|
||||
data class StatusRequest(val id: String, val status: Int)
|
||||
|
||||
@@ -357,7 +357,11 @@ class ApplicationsController(
|
||||
}
|
||||
|
||||
if (application.unique_url != null) {
|
||||
throw ResponseStatusException(HttpStatus.BAD_REQUEST, "Application already has unique_url", null)
|
||||
throw ResponseStatusException(
|
||||
HttpStatus.BAD_REQUEST,
|
||||
"Application already has unique_url",
|
||||
null
|
||||
)
|
||||
}
|
||||
|
||||
application.original_url = application.url
|
||||
@@ -554,14 +558,13 @@ class ApplicationService(
|
||||
return true
|
||||
}
|
||||
|
||||
public fun findAll(user: UserDb, info: ListRequest): List<Application> {
|
||||
private fun internalFindAll(user: UserDb, info: ListRequest): Iterable<Application> {
|
||||
if (info.status == null) {
|
||||
return db.query(
|
||||
"select * from applications where user_id=? order by title asc;",
|
||||
arrayOf(user.id),
|
||||
Application
|
||||
)
|
||||
.toList()
|
||||
"select * from applications where user_id=? order by title asc;",
|
||||
arrayOf(user.id),
|
||||
Application
|
||||
)
|
||||
}
|
||||
|
||||
// If it's to apply also remove the linked_application to only show the main
|
||||
@@ -571,7 +574,6 @@ class ApplicationService(
|
||||
arrayOf(user.id),
|
||||
Application
|
||||
)
|
||||
.toList()
|
||||
}
|
||||
|
||||
return db.query(
|
||||
@@ -579,7 +581,17 @@ class ApplicationService(
|
||||
arrayOf(user.id, info.status),
|
||||
Application,
|
||||
)
|
||||
.toList()
|
||||
}
|
||||
|
||||
public fun findAll(user: UserDb, info: ListRequest): List<Application> {
|
||||
var iter = internalFindAll(user, info);
|
||||
if (info.views == true) {
|
||||
iter = iter.map {
|
||||
it.views = viewService.listFromApplicationId(it.id)
|
||||
it
|
||||
}
|
||||
}
|
||||
return iter.toList()
|
||||
}
|
||||
|
||||
public fun update(application: Application): Application {
|
||||
|
||||
@@ -1,24 +1,56 @@
|
||||
package com.andr3h3nriqu3s.applications
|
||||
|
||||
import java.sql.ResultSet
|
||||
import java.sql.Timestamp
|
||||
import java.util.Date
|
||||
import java.util.UUID
|
||||
import org.springframework.http.MediaType
|
||||
import org.springframework.jdbc.core.JdbcTemplate
|
||||
import org.springframework.jdbc.core.RowMapper
|
||||
import org.springframework.stereotype.Service
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.PathVariable
|
||||
import org.springframework.web.bind.annotation.RequestHeader
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
|
||||
data class View(var id: String, var application_id: String, var time: Date) {
|
||||
data class View(var id: String, var application_id: String, var time: Timestamp) {
|
||||
companion object : RowMapper<View> {
|
||||
override public fun mapRow(rs: ResultSet, rowNum: Int): View {
|
||||
return View(
|
||||
rs.getString("id"),
|
||||
rs.getString("application_id"),
|
||||
rs.getDate("time"),
|
||||
rs.getTimestamp("time"),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@RestController
|
||||
@ControllerAdvice
|
||||
@RequestMapping("/api/view")
|
||||
class ViewController(
|
||||
val sessionService: SessionService,
|
||||
val applicationService: ApplicationService,
|
||||
val flairService: FlairService,
|
||||
val viewService: ViewService,
|
||||
) {
|
||||
|
||||
@GetMapping(path = ["/{id}"], produces = [MediaType.APPLICATION_JSON_VALUE])
|
||||
public fun getCV(@PathVariable id: String, @RequestHeader("token") token: String): List<View> {
|
||||
val user = sessionService.verifyTokenThrow(token)
|
||||
|
||||
val application = applicationService.findApplicationById(user, id)
|
||||
|
||||
if (application == null) {
|
||||
throw NotFound()
|
||||
}
|
||||
|
||||
return application.views
|
||||
}
|
||||
}
|
||||
|
||||
@Service
|
||||
public class ViewService(val db: JdbcTemplate) {
|
||||
|
||||
@@ -58,7 +90,7 @@ public class ViewService(val db: JdbcTemplate) {
|
||||
public fun create(application_id: String): View {
|
||||
val id = UUID.randomUUID().toString()
|
||||
|
||||
var new_view = View(id, application_id, Date())
|
||||
var new_view = View(id, application_id, Timestamp(Date().getTime()))
|
||||
|
||||
db.update(
|
||||
"insert into views (id, application_id) values (?, ?)",
|
||||
|
||||
Reference in New Issue
Block a user