chore: more work on cv and on main page
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
spring.datasource.driver-class-name=org.postgresql.Driver
|
||||
spring.datasource.url=jdbc:postgresql://localhost:5432/applications
|
||||
spring.datasource.url=jdbc:postgresql://kronos:5432/applications
|
||||
spring.datasource.username=applications
|
||||
spring.datasource.password=applications
|
||||
|
||||
|
||||
@@ -30,7 +30,9 @@ data class Application(
|
||||
var extra_data: String,
|
||||
var payrange: String,
|
||||
var status: Int,
|
||||
var flairs: List<Flair>
|
||||
var company: String,
|
||||
var recruiter: String,
|
||||
var flairs: List<Flair>,
|
||||
) {
|
||||
companion object : RowMapper<Application> {
|
||||
override public fun mapRow(rs: ResultSet, rowNum: Int): Application {
|
||||
@@ -44,6 +46,8 @@ data class Application(
|
||||
rs.getString("extra_data"),
|
||||
rs.getString("payrange"),
|
||||
rs.getInt("status"),
|
||||
rs.getString("company"),
|
||||
rs.getString("recruiter"),
|
||||
emptyList()
|
||||
)
|
||||
}
|
||||
@@ -60,6 +64,8 @@ data class FlairRequest(val id: String, val text: String)
|
||||
|
||||
data class UpdateUrl(val id: String, val url: String)
|
||||
|
||||
data class CVData(val company: String, val recruiter: String, val flairs: List<SimpleFlair>)
|
||||
|
||||
@RestController
|
||||
@ControllerAdvice
|
||||
@RequestMapping("/api/application")
|
||||
@@ -69,6 +75,23 @@ class ApplicationsController(
|
||||
val flairService: FlairService
|
||||
) {
|
||||
|
||||
@GetMapping(path = ["/cv/{id}"], produces = [MediaType.APPLICATION_JSON_VALUE])
|
||||
public fun getCV(
|
||||
@PathVariable id: String,
|
||||
@RequestHeader("token") token: String
|
||||
): CVData? {
|
||||
print("here!");
|
||||
val user = sessionService.verifyToken(token);
|
||||
|
||||
val application = applicationService.findApplicationByIdNoUser(id);
|
||||
|
||||
if (application == null) return null;
|
||||
|
||||
val flairs = application.flairs.map {it.toFlairSimple()};
|
||||
|
||||
return CVData(application.company, application.recruiter, flairs);
|
||||
}
|
||||
|
||||
@PostMapping(path = ["/text"], produces = [MediaType.APPLICATION_JSON_VALUE])
|
||||
public fun submitText(
|
||||
@RequestBody submit: SubmitRequest,
|
||||
@@ -179,6 +202,8 @@ class ApplicationsController(
|
||||
"",
|
||||
"",
|
||||
0,
|
||||
"",
|
||||
"",
|
||||
emptyList()
|
||||
)
|
||||
}
|
||||
@@ -435,13 +460,27 @@ class ApplicationService(val db: JdbcTemplate, val flairService: FlairService) {
|
||||
return application
|
||||
}
|
||||
|
||||
public fun findApplicationByIdNoUser(id: String): Application? {
|
||||
var applications = db.query("select * from applications where id=?", arrayOf(id), Application).toList()
|
||||
|
||||
if (applications.size == 0) {
|
||||
return null
|
||||
}
|
||||
|
||||
var application = applications[0]
|
||||
|
||||
application.flairs = flairService.listFromLinkApplicationId(application.id)
|
||||
|
||||
return application
|
||||
}
|
||||
|
||||
public fun createApplication(user: UserDb, application: Application): Boolean {
|
||||
if (this.findApplicationByUrl(user, application.url, application.unique_url) != null) {
|
||||
return false
|
||||
}
|
||||
|
||||
db.update(
|
||||
"insert into applications (id, url, original_url, unique_url, title, user_id, extra_data, payrange, status) values (?, ?, ?, ?, ?, ?, ?, ?, ?);",
|
||||
"insert into applications (id, url, original_url, unique_url, title, user_id, extra_data, payrange, status, company, recruiter) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);",
|
||||
application.id,
|
||||
application.url,
|
||||
application.original_url,
|
||||
@@ -451,6 +490,8 @@ class ApplicationService(val db: JdbcTemplate, val flairService: FlairService) {
|
||||
application.extra_data,
|
||||
application.payrange,
|
||||
application.status,
|
||||
application.company,
|
||||
application.recruiter
|
||||
)
|
||||
|
||||
return true
|
||||
@@ -476,7 +517,7 @@ class ApplicationService(val db: JdbcTemplate, val flairService: FlairService) {
|
||||
|
||||
public fun update(application: Application): Application {
|
||||
db.update(
|
||||
"update applications set url=?, original_url=?, unique_url=?, title=?, user_id=?, extra_data=?, payrange=?, status=? where id=?",
|
||||
"update applications set url=?, original_url=?, unique_url=?, title=?, user_id=?, extra_data=?, payrange=?, status=?, company=?, recruiter=? where id=?",
|
||||
application.url,
|
||||
application.original_url,
|
||||
application.unique_url,
|
||||
@@ -485,6 +526,8 @@ class ApplicationService(val db: JdbcTemplate, val flairService: FlairService) {
|
||||
application.extra_data,
|
||||
application.payrange,
|
||||
application.status,
|
||||
application.company,
|
||||
application.recruiter,
|
||||
application.id,
|
||||
)
|
||||
return application
|
||||
|
||||
@@ -68,6 +68,12 @@ class FlairController(val sessionService: SessionService, val flairService: Flai
|
||||
}
|
||||
}
|
||||
|
||||
data class SimpleFlair(
|
||||
val name: String,
|
||||
val description: String,
|
||||
val color: String,
|
||||
)
|
||||
|
||||
data class Flair(
|
||||
var id: String,
|
||||
var user_id: String,
|
||||
@@ -88,6 +94,10 @@ data class Flair(
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun toFlairSimple(): SimpleFlair {
|
||||
return SimpleFlair(this.name, this.description, this.color);
|
||||
}
|
||||
}
|
||||
|
||||
data class FlairLink(var id: String, var application_id: String, var flair_id: String)
|
||||
@@ -134,14 +144,14 @@ public class FlairService(val db: JdbcTemplate) {
|
||||
|
||||
public fun listFromLinkApplicationId(id: String): List<Flair> =
|
||||
db.query(
|
||||
"select f.id, f.user_id, f.color, f.name, f.expr, f.description from flair_link as fl inner join flair as f on f.id = fl.flair_id where application_id=?;",
|
||||
"select f.id, f.user_id, f.color, f.name, f.expr, f.description from flair_link as fl inner join flair as f on f.id = fl.flair_id where application_id=? order by name asc;",
|
||||
arrayOf(id),
|
||||
Flair
|
||||
)
|
||||
.toList()
|
||||
|
||||
public fun listUser(user: UserDb): List<Flair> =
|
||||
db.query("select * from flair where user_id=?;", arrayOf(user.id), Flair).toList()
|
||||
db.query("select * from flair where user_id=? order by name asc;", arrayOf(user.id), Flair).toList()
|
||||
|
||||
public fun getById(user: UserDb, id: String): Flair? {
|
||||
val items =
|
||||
|
||||
@@ -16,6 +16,8 @@ create table if not exists applications (
|
||||
url text not null,
|
||||
original_url text,
|
||||
unique_url text,
|
||||
company text,
|
||||
recruiter text,
|
||||
title text,
|
||||
user_id text,
|
||||
extra_data text,
|
||||
|
||||
Reference in New Issue
Block a user