feat: a lot
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
package com.andr3h3nriqu3s.applications
|
||||
|
||||
import java.sql.ResultSet
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
import java.util.UUID
|
||||
import kotlin.collections.emptyList
|
||||
import kotlin.collections.setOf
|
||||
@@ -23,27 +21,35 @@ import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
import org.springframework.web.server.ResponseStatusException
|
||||
|
||||
data class ApplicationUrl(
|
||||
var application_id: String,
|
||||
var url: String,
|
||||
) {
|
||||
companion object : RowMapper<ApplicationUrl> {
|
||||
override public fun mapRow(rs: ResultSet, rowNum: Int): ApplicationUrl {
|
||||
return ApplicationUrl(
|
||||
rs.getString("application_id"),
|
||||
rs.getString("url"),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data class Application(
|
||||
var id: String,
|
||||
var url: String,
|
||||
var original_url: String?,
|
||||
var unique_url: String?,
|
||||
var title: String,
|
||||
var user_id: String,
|
||||
var extra_data: String,
|
||||
var payrange: String,
|
||||
var status: Int,
|
||||
var status_id: String?,
|
||||
var company: String,
|
||||
var recruiter: String,
|
||||
var agency: Boolean,
|
||||
var message: String,
|
||||
var linked_application: String,
|
||||
var status_history: String,
|
||||
var application_time: String,
|
||||
var create_time: String,
|
||||
var simple_url: String,
|
||||
var flairs: List<Flair>,
|
||||
var views: List<View>,
|
||||
var events: List<Event>,
|
||||
) {
|
||||
companion object : RowMapper<Application> {
|
||||
@@ -51,23 +57,17 @@ data class Application(
|
||||
return Application(
|
||||
rs.getString("id"),
|
||||
rs.getString("url"),
|
||||
rs.getString("original_url"),
|
||||
rs.getString("unique_url"),
|
||||
rs.getString("title"),
|
||||
rs.getString("user_id"),
|
||||
rs.getString("extra_data"),
|
||||
rs.getString("payrange"),
|
||||
rs.getInt("status"),
|
||||
rs.getString("status_id"),
|
||||
rs.getString("company"),
|
||||
rs.getString("recruiter"),
|
||||
rs.getBoolean("agency"),
|
||||
rs.getString("message"),
|
||||
rs.getString("linked_application"),
|
||||
rs.getString("status_history"),
|
||||
rs.getString("application_time"),
|
||||
rs.getString("create_time"),
|
||||
emptyList(),
|
||||
rs.getString("simple_url"),
|
||||
emptyList(),
|
||||
emptyList(),
|
||||
)
|
||||
@@ -77,9 +77,7 @@ data class Application(
|
||||
|
||||
data class SubmitRequest(val text: String)
|
||||
|
||||
data class ListRequest(val status: Int? = null, val views: Boolean? = null)
|
||||
|
||||
data class StatusRequest(val id: String, val status: Int)
|
||||
data class StatusRequest(val id: String, val status_id: String?)
|
||||
|
||||
data class FlairRequest(val id: String, val text: String)
|
||||
|
||||
@@ -100,7 +98,6 @@ class ApplicationsController(
|
||||
val sessionService: SessionService,
|
||||
val applicationService: ApplicationService,
|
||||
val flairService: FlairService,
|
||||
val viewService: ViewService,
|
||||
val eventService: EventService,
|
||||
) {
|
||||
|
||||
@@ -118,7 +115,13 @@ class ApplicationsController(
|
||||
|
||||
val flairs = application.flairs.map { it.toFlairSimple() }
|
||||
|
||||
return CVData(application.company, application.recruiter, application.message, application.agency, flairs)
|
||||
return CVData(
|
||||
application.company,
|
||||
application.recruiter,
|
||||
application.message,
|
||||
application.agency,
|
||||
flairs
|
||||
)
|
||||
}
|
||||
|
||||
/** Create a new application from the link */
|
||||
@@ -133,13 +136,10 @@ class ApplicationsController(
|
||||
Application(
|
||||
UUID.randomUUID().toString(),
|
||||
submit.text,
|
||||
submit.text,
|
||||
submit.text,
|
||||
"New Application",
|
||||
user.id,
|
||||
"",
|
||||
"",
|
||||
0,
|
||||
null,
|
||||
"",
|
||||
"",
|
||||
@@ -147,9 +147,6 @@ class ApplicationsController(
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
emptyList(),
|
||||
emptyList(),
|
||||
emptyList(),
|
||||
)
|
||||
@@ -199,7 +196,7 @@ class ApplicationsController(
|
||||
public fun submitText(
|
||||
@RequestBody submit: SubmitRequest,
|
||||
@RequestHeader("token") token: String
|
||||
): Int {
|
||||
): List<Application> {
|
||||
val user = sessionService.verifyTokenThrow(token)
|
||||
|
||||
var text = submit.text.replace("=\n", "")
|
||||
@@ -263,23 +260,17 @@ class ApplicationsController(
|
||||
Application(
|
||||
UUID.randomUUID().toString(),
|
||||
if (elm.contains("linkedin")) elm.split("?")[0] else elm,
|
||||
if (elm.contains("linkedin")) elm.split("?")[0] else null,
|
||||
if (elm.contains("linkedin")) elm.split("?")[0] else null,
|
||||
"New Application",
|
||||
user.id,
|
||||
"",
|
||||
"",
|
||||
0,
|
||||
null,
|
||||
"",
|
||||
"",
|
||||
false,
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
emptyList(),
|
||||
if (elm.contains("linkedin")) elm.split("?")[0] else "",
|
||||
emptyList(),
|
||||
emptyList(),
|
||||
)
|
||||
@@ -292,26 +283,46 @@ class ApplicationsController(
|
||||
print(applications.size)
|
||||
print(" links\n")
|
||||
|
||||
return applications.size
|
||||
return applications
|
||||
}
|
||||
|
||||
@PostMapping(path = ["/list"], produces = [MediaType.APPLICATION_JSON_VALUE])
|
||||
public fun list(
|
||||
@RequestBody info: ListRequest,
|
||||
@RequestHeader("token") token: String
|
||||
): List<Application> {
|
||||
@GetMapping(path = ["/list"], produces = [MediaType.APPLICATION_JSON_VALUE])
|
||||
public fun list(@RequestHeader("token") token: String): List<Application> {
|
||||
val user = sessionService.verifyTokenThrow(token)
|
||||
return applicationService.findAll(user, info)
|
||||
return applicationService.findAll(user)
|
||||
}
|
||||
|
||||
@GetMapping(path = ["/active"], produces = [MediaType.APPLICATION_JSON_VALUE])
|
||||
public fun active(@RequestHeader("token") token: String): Application? {
|
||||
@GetMapping(path = ["/{id}"], produces = [MediaType.APPLICATION_JSON_VALUE])
|
||||
public fun get(@PathVariable id: String, @RequestHeader("token") token: String): Application? {
|
||||
val user = sessionService.verifyTokenThrow(token)
|
||||
val possibleApplications = applicationService.findAll(user, ListRequest(1))
|
||||
if (possibleApplications.size == 0) {
|
||||
return null
|
||||
val app = applicationService.findApplicationById(user, id)
|
||||
if (app == null) {
|
||||
throw ResponseStatusException(HttpStatus.NOT_FOUND, "Application not found", null)
|
||||
}
|
||||
return applicationService.findApplicationById(user, possibleApplications[0].id)
|
||||
return app
|
||||
}
|
||||
|
||||
@PostMapping(
|
||||
path = ["/link/application/{toLink}/{surviving}"],
|
||||
produces = [MediaType.APPLICATION_JSON_VALUE]
|
||||
)
|
||||
public fun get(
|
||||
@PathVariable toLink: String,
|
||||
@PathVariable surviving: String,
|
||||
@RequestHeader("token") token: String
|
||||
): Application {
|
||||
val user = sessionService.verifyTokenThrow(token)
|
||||
val toLinkApp = applicationService.findApplicationById(user, toLink)
|
||||
val app = applicationService.findApplicationById(user, surviving)
|
||||
|
||||
if (app == null || toLinkApp == null) {
|
||||
throw ResponseStatusException(HttpStatus.NOT_FOUND, "Application not found", null)
|
||||
}
|
||||
|
||||
applicationService.linkApplications(toLinkApp, app)
|
||||
applicationService.delete(toLinkApp)
|
||||
|
||||
return app
|
||||
}
|
||||
|
||||
@PutMapping(path = ["/status"], produces = [MediaType.APPLICATION_JSON_VALUE])
|
||||
@@ -325,11 +336,11 @@ class ApplicationsController(
|
||||
throw NotFound()
|
||||
}
|
||||
|
||||
if (application.status == info.status) {
|
||||
return application;
|
||||
if (application.status_id == info.status_id) {
|
||||
return application
|
||||
}
|
||||
|
||||
application.status = info.status
|
||||
application.status_id = info.status_id
|
||||
|
||||
applicationService.updateStatus(application)
|
||||
|
||||
@@ -362,68 +373,28 @@ class ApplicationsController(
|
||||
throw ResponseStatusException(HttpStatus.NOT_FOUND, "Application not found", null)
|
||||
}
|
||||
|
||||
if (application.unique_url != null) {
|
||||
throw ResponseStatusException(
|
||||
HttpStatus.BAD_REQUEST,
|
||||
"Application already has unique_url",
|
||||
null
|
||||
)
|
||||
}
|
||||
|
||||
application.original_url = application.url
|
||||
application.url = info.url
|
||||
application.unique_url = info.url.split("?")[0]
|
||||
application.simple_url = info.url.split("?")[0]
|
||||
|
||||
var maybe_exists =
|
||||
applicationService.findApplicationByUrl(
|
||||
user,
|
||||
application.url,
|
||||
application.unique_url
|
||||
)
|
||||
if (maybe_exists != null) {
|
||||
applicationService.findApplicationByUrl(user, application.url)
|
||||
?: applicationService.findApplicationByUrl(user, application.simple_url)
|
||||
|
||||
if (maybe_exists != null && maybe_exists.id != application.id) {
|
||||
applicationService.delete(application)
|
||||
|
||||
if (maybe_exists.status == 0 && application.status == 1) {
|
||||
maybe_exists.status = 1
|
||||
applicationService.update(maybe_exists)
|
||||
}
|
||||
|
||||
maybe_exists.flairs = flairService.listFromLinkApplicationId(maybe_exists.id)
|
||||
maybe_exists.events = eventService.listFromApplicationId(maybe_exists.id).toList()
|
||||
|
||||
return maybe_exists
|
||||
}
|
||||
|
||||
applicationService.addUrl(application.id, info.url)
|
||||
applicationService.addUrl(application.id, info.url.split("?")[0])
|
||||
applicationService.update(application)
|
||||
|
||||
application.flairs = flairService.listFromLinkApplicationId(application.id)
|
||||
application.views = viewService.listFromApplicationId(application.id)
|
||||
|
||||
return application
|
||||
}
|
||||
|
||||
@PostMapping(path = ["/reset/url/{id}"], produces = [MediaType.APPLICATION_JSON_VALUE])
|
||||
public fun updateUrl(
|
||||
@PathVariable id: String,
|
||||
@RequestHeader("token") token: String
|
||||
): Application {
|
||||
val user = sessionService.verifyTokenThrow(token)
|
||||
var application = applicationService.findApplicationById(user, id)
|
||||
|
||||
if (application == null) {
|
||||
throw NotFound()
|
||||
}
|
||||
|
||||
if (application.unique_url == null) {
|
||||
throw BadRequest()
|
||||
}
|
||||
|
||||
application.url = application.original_url!!
|
||||
application.original_url = null
|
||||
application.unique_url = null
|
||||
|
||||
applicationService.update(application)
|
||||
|
||||
application.flairs = flairService.listFromLinkApplicationId(application.id)
|
||||
application.events = eventService.listFromApplicationId(application.id).toList()
|
||||
|
||||
return application
|
||||
}
|
||||
@@ -466,28 +437,13 @@ class ApplicationsController(
|
||||
class ApplicationService(
|
||||
val db: JdbcTemplate,
|
||||
val flairService: FlairService,
|
||||
val viewService: ViewService,
|
||||
val eventService: EventService,
|
||||
) {
|
||||
|
||||
public fun findApplicationByUrl(user: UserDb, url: String, unique_url: String?): Application? {
|
||||
if (unique_url != null) {
|
||||
val unique: List<Application> =
|
||||
db.query(
|
||||
"select * from applications where unique_url=? and user_id=?",
|
||||
arrayOf(unique_url, user.id),
|
||||
Application
|
||||
)
|
||||
.toList()
|
||||
|
||||
if (unique.size != 0) {
|
||||
return unique[0]
|
||||
}
|
||||
}
|
||||
|
||||
val applications: List<Application> =
|
||||
public fun findApplicationByUrl(user: UserDb, url: String): Application? {
|
||||
val applications =
|
||||
db.query(
|
||||
"select * from applications where url=? and user_id=?",
|
||||
"select * from applications as app inner join applications_urls as app_url on app_url.application_id=app.id where app_url.url=? and user_id=?",
|
||||
arrayOf(url, user.id),
|
||||
Application
|
||||
)
|
||||
@@ -516,7 +472,6 @@ class ApplicationService(
|
||||
var application = applications[0]
|
||||
|
||||
application.flairs = flairService.listFromLinkApplicationId(application.id)
|
||||
application.views = viewService.listFromApplicationId(application.id)
|
||||
application.events = eventService.listFromApplicationId(application.id).toList()
|
||||
|
||||
return application
|
||||
@@ -538,106 +493,80 @@ class ApplicationService(
|
||||
return application
|
||||
}
|
||||
|
||||
public fun addUrl(id: String, url: String) {
|
||||
val applications =
|
||||
db.query(
|
||||
"select * from applications_urls as app_url where app_url.url=? and app_url.application_id=?",
|
||||
arrayOf(url, id),
|
||||
ApplicationUrl
|
||||
)
|
||||
.toList()
|
||||
|
||||
if (applications.size > 0) {
|
||||
return
|
||||
}
|
||||
|
||||
db.update("insert into applications_urls (application_id, url) values (?, ?);", id, url)
|
||||
}
|
||||
|
||||
public fun createApplication(user: UserDb, application: Application): Boolean {
|
||||
if (this.findApplicationByUrl(user, application.url, application.unique_url) != null) {
|
||||
if (this.findApplicationByUrl(user, application.url) != null) {
|
||||
return false
|
||||
}
|
||||
|
||||
// Create time is auto created by the database
|
||||
// The default status is null
|
||||
db.update(
|
||||
"insert into applications (id, url, original_url, unique_url, title, user_id, extra_data, payrange, status, company, recruiter, message, linked_application, status_history, application_time, agency) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);",
|
||||
"insert into applications (id, url, title, user_id, extra_data, payrange, status_id, company, recruiter, message, agency, simple_url) values (?,?,?,?,?,?,?,?,?,?,?,?);",
|
||||
application.id,
|
||||
application.url,
|
||||
application.original_url,
|
||||
application.unique_url,
|
||||
application.title,
|
||||
application.user_id,
|
||||
application.extra_data,
|
||||
application.payrange,
|
||||
application.status,
|
||||
application.status_id,
|
||||
application.company,
|
||||
application.recruiter,
|
||||
application.message,
|
||||
application.linked_application,
|
||||
application.status_history,
|
||||
application.application_time,
|
||||
application.agency,
|
||||
application.simple_url,
|
||||
)
|
||||
|
||||
eventService.create(application.id, EventType.Creation)
|
||||
addUrl(application.id, application.url)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
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
|
||||
)
|
||||
}
|
||||
|
||||
// If it's to apply also remove the linked_application to only show the main
|
||||
if (info.status == 0) {
|
||||
return db.query(
|
||||
"select * from applications where user_id=? and linked_application='' and status=0 order by title asc;",
|
||||
arrayOf(user.id),
|
||||
Application
|
||||
)
|
||||
}
|
||||
|
||||
private fun internalFindAll(user: UserDb): Iterable<Application> {
|
||||
return db.query(
|
||||
"select * from applications where user_id=? and status=? order by title asc;",
|
||||
arrayOf(user.id, info.status),
|
||||
Application,
|
||||
)
|
||||
"select * from applications where user_id=? order by title asc;",
|
||||
arrayOf(user.id),
|
||||
Application
|
||||
)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
public fun findAll(user: UserDb): List<Application> {
|
||||
var iter = internalFindAll(user)
|
||||
return iter.toList()
|
||||
}
|
||||
|
||||
public fun findAllByUserStatusId(statusId: String, user: UserDb): List<Application> {
|
||||
return db.query(
|
||||
"select * from applications where status_id=? and user_id=? order by title asc;",
|
||||
arrayOf(statusId, user.id),
|
||||
Application
|
||||
)
|
||||
return db.query(
|
||||
"select * from applications where status_id=? and user_id=? order by title asc;",
|
||||
arrayOf(statusId, user.id),
|
||||
Application
|
||||
)
|
||||
}
|
||||
|
||||
// Update the stauts on the application object before giving it to this function
|
||||
// TODO how status history works
|
||||
public fun updateStatus(application: Application): Application {
|
||||
|
||||
val status_string = "${application.status}"
|
||||
var status_history = application.status_history.split(",").filter { it.length >= 1 }
|
||||
if (status_history.indexOf(status_string) == -1) {
|
||||
status_history = status_history.plus(status_string)
|
||||
}
|
||||
|
||||
application.status_history = status_history.joinToString(",") { it }
|
||||
|
||||
if (application.status == 4) {
|
||||
val sdf = SimpleDateFormat("dd/MM/yyyy hh:mm:ss")
|
||||
application.application_time = sdf.format(Date())
|
||||
}
|
||||
|
||||
eventService.create(application.id, EventType.StatusUpdate, application.status)
|
||||
eventService.create(application.id, EventType.StatusUpdate, application.status_id)
|
||||
|
||||
db.update(
|
||||
"update applications set status=?, status_history=?, application_time=? where id=?",
|
||||
application.status,
|
||||
application.status_history,
|
||||
application.application_time,
|
||||
"update applications set status_id=? where id=?",
|
||||
application.status_id,
|
||||
application.id,
|
||||
)
|
||||
return application
|
||||
@@ -647,10 +576,8 @@ class ApplicationService(
|
||||
public fun update(application: Application): Application {
|
||||
// I don't want ot update create_time
|
||||
db.update(
|
||||
"update applications set url=?, original_url=?, unique_url=?, title=?, user_id=?, extra_data=?, payrange=?, company=?, recruiter=?, message=?, linked_application=?, agency=? where id=?",
|
||||
"update applications set url=?, title=?, user_id=?, extra_data=?, payrange=?, company=?, recruiter=?, message=?, agency=?, simple_url=? where id=?",
|
||||
application.url,
|
||||
application.original_url,
|
||||
application.unique_url,
|
||||
application.title,
|
||||
application.user_id,
|
||||
application.extra_data,
|
||||
@@ -658,17 +585,29 @@ class ApplicationService(
|
||||
application.company,
|
||||
application.recruiter,
|
||||
application.message,
|
||||
application.linked_application,
|
||||
application.agency,
|
||||
application.simple_url,
|
||||
application.id,
|
||||
)
|
||||
return application
|
||||
}
|
||||
|
||||
public fun linkApplications(toLink: Application, surviving: Application) {
|
||||
db.update(
|
||||
"update applications_urls set application_id=? where application_id=?;",
|
||||
surviving.id,
|
||||
toLink.id,
|
||||
)
|
||||
}
|
||||
|
||||
public fun delete(application: Application) {
|
||||
db.update(
|
||||
"delete from applications where id=?",
|
||||
application.id,
|
||||
)
|
||||
db.update(
|
||||
"delete from applications_urls where application_id=?",
|
||||
application.id,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ data class Event(
|
||||
var id: String,
|
||||
var application_id: String,
|
||||
var event_type: Int,
|
||||
var new_status: Int?,
|
||||
var new_status_id: String?,
|
||||
var time: Timestamp
|
||||
) {
|
||||
companion object : RowMapper<Event> {
|
||||
@@ -34,7 +34,7 @@ data class Event(
|
||||
rs.getString("id"),
|
||||
rs.getString("application_id"),
|
||||
rs.getInt("event_type"),
|
||||
rs.getInt("new_status"),
|
||||
rs.getString("new_status_id"),
|
||||
rs.getTimestamp("time"),
|
||||
)
|
||||
}
|
||||
@@ -93,23 +93,19 @@ public class EventService(val db: JdbcTemplate) {
|
||||
public fun create(
|
||||
application_id: String,
|
||||
event_type: EventType,
|
||||
new_status: Int? = null
|
||||
new_status_id: String? = null
|
||||
): Event {
|
||||
val id = UUID.randomUUID().toString()
|
||||
|
||||
if (event_type == EventType.StatusUpdate && new_status == null) {
|
||||
throw Exception("When event_type == StatusUpdate new_status must be set")
|
||||
}
|
||||
|
||||
var new_event =
|
||||
Event(id, application_id, event_type.value, new_status, Timestamp(Date().getTime()))
|
||||
Event(id, application_id, event_type.value, new_status_id, Timestamp(Date().getTime()))
|
||||
|
||||
db.update(
|
||||
"insert into events (id, application_id, event_type, new_status) values (?, ?, ? ,?)",
|
||||
"insert into events (id, application_id, event_type, new_status_id) values (?, ?, ? ,?)",
|
||||
new_event.id,
|
||||
new_event.application_id,
|
||||
new_event.event_type,
|
||||
new_event.new_status,
|
||||
new_event.new_status_id,
|
||||
)
|
||||
|
||||
return new_event
|
||||
|
||||
@@ -2,8 +2,8 @@ package com.andr3h3nriqu3s.applications
|
||||
|
||||
import java.sql.ResultSet
|
||||
import java.util.UUID
|
||||
import org.springframework.http.MediaType
|
||||
import org.springframework.http.HttpStatus
|
||||
import org.springframework.http.MediaType
|
||||
import org.springframework.jdbc.core.JdbcTemplate
|
||||
import org.springframework.jdbc.core.RowMapper
|
||||
import org.springframework.stereotype.Service
|
||||
@@ -52,10 +52,6 @@ class FlairController(
|
||||
throw NotFound()
|
||||
}
|
||||
|
||||
if (old_flair.user_id != user.id) {
|
||||
throw NotAuth()
|
||||
}
|
||||
|
||||
flair.user_id = old_flair.user_id
|
||||
|
||||
return flairService.updateFlair(flair)
|
||||
@@ -88,6 +84,8 @@ data class SimpleFlair(
|
||||
val name: String,
|
||||
val description: String,
|
||||
val color: String,
|
||||
val sort: Int,
|
||||
val showFullDescription: Int,
|
||||
)
|
||||
|
||||
data class Flair(
|
||||
@@ -97,6 +95,8 @@ data class Flair(
|
||||
var name: String,
|
||||
var expr: String,
|
||||
var description: String,
|
||||
var sort: Int,
|
||||
var showFullDescription: Int,
|
||||
) {
|
||||
companion object : RowMapper<Flair> {
|
||||
override public fun mapRow(rs: ResultSet, rowNum: Int): Flair {
|
||||
@@ -107,12 +107,20 @@ data class Flair(
|
||||
rs.getString("name"),
|
||||
rs.getString("expr"),
|
||||
rs.getString("description"),
|
||||
rs.getInt("sort"),
|
||||
rs.getInt("showFullDescription"),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun toFlairSimple(): SimpleFlair {
|
||||
return SimpleFlair(this.name, this.description, this.color)
|
||||
return SimpleFlair(
|
||||
this.name,
|
||||
this.description,
|
||||
this.color,
|
||||
this.sort,
|
||||
this.showFullDescription
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,7 +168,7 @@ 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=? order by name asc;",
|
||||
"select f.id, f.user_id, f.color, f.name, f.expr, f.description, f.sort, f.showFullDescription 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
|
||||
)
|
||||
@@ -210,12 +218,14 @@ public class FlairService(val db: JdbcTemplate) {
|
||||
|
||||
public fun updateFlair(flair: Flair): Flair {
|
||||
db.update(
|
||||
"update flair set user_id=?, color=?, name=?, expr=?, description=? where id=?;",
|
||||
"update flair set user_id=?, color=?, name=?, expr=?, description=?, sort=?, showFullDescription=? where id=?;",
|
||||
flair.user_id,
|
||||
flair.color,
|
||||
flair.name,
|
||||
flair.expr,
|
||||
flair.description,
|
||||
flair.sort,
|
||||
flair.showFullDescription,
|
||||
flair.id,
|
||||
)
|
||||
|
||||
@@ -231,16 +241,18 @@ public class FlairService(val db: JdbcTemplate) {
|
||||
description = flair.description!!
|
||||
}
|
||||
|
||||
var new_flair = Flair(id, user.id, flair.color, flair.name, flair.expr, description)
|
||||
var new_flair = Flair(id, user.id, flair.color, flair.name, flair.expr, description, 0, 1)
|
||||
|
||||
db.update(
|
||||
"insert into flair (id, user_id, color, name, expr, description) values (?, ?, ?, ?, ?, ?)",
|
||||
"insert into flair (id, user_id, color, name, expr, description, sort, showFullDescription) values (?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
new_flair.id,
|
||||
new_flair.user_id,
|
||||
new_flair.color,
|
||||
new_flair.name,
|
||||
new_flair.expr,
|
||||
new_flair.description
|
||||
new_flair.description,
|
||||
new_flair.showFullDescription,
|
||||
new_flair.sort,
|
||||
)
|
||||
|
||||
return new_flair
|
||||
|
||||
@@ -28,7 +28,9 @@ data class UserStatusNode(
|
||||
var y: Int,
|
||||
var width: Int,
|
||||
var height: Int,
|
||||
var permission: Int
|
||||
var permission: Int,
|
||||
var visible: Boolean,
|
||||
var endable: Boolean,
|
||||
) {
|
||||
companion object : RowMapper<UserStatusNode> {
|
||||
override public fun mapRow(rs: ResultSet, rowNum: Int): UserStatusNode {
|
||||
@@ -42,6 +44,8 @@ data class UserStatusNode(
|
||||
rs.getInt("width"),
|
||||
rs.getInt("height"),
|
||||
rs.getInt("permission"),
|
||||
rs.getBoolean("visible"),
|
||||
rs.getBoolean("endable"),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -211,7 +215,7 @@ public class UserStatusNodeService(val db: JdbcTemplate) {
|
||||
|
||||
public fun update(node: UserStatusNode): UserStatusNode {
|
||||
db.update(
|
||||
"update user_status_node set name=?, icon=?, x=?, y=?, width=?, height=?, permission=? where id=?;",
|
||||
"update user_status_node set name=?, icon=?, x=?, y=?, width=?, height=?, permission=?, visible=?, endable=? where id=?;",
|
||||
node.name,
|
||||
node.icon,
|
||||
node.x,
|
||||
@@ -219,6 +223,8 @@ public class UserStatusNodeService(val db: JdbcTemplate) {
|
||||
node.width,
|
||||
node.height,
|
||||
node.permission,
|
||||
node.visible,
|
||||
node.endable,
|
||||
node.id,
|
||||
)
|
||||
|
||||
@@ -230,7 +236,7 @@ public class UserStatusNodeService(val db: JdbcTemplate) {
|
||||
node.id = id
|
||||
|
||||
db.update(
|
||||
"insert into user_status_node (id, user_id, name, icon, x, y, width, height, permission) values (?, ?, ?, ?, ?, ?, ?, ?, ?);",
|
||||
"insert into user_status_node (id, user_id, name, icon, x, y, width, height, permission, visible, endable) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);",
|
||||
node.id,
|
||||
node.user_id,
|
||||
node.name,
|
||||
@@ -239,7 +245,9 @@ public class UserStatusNodeService(val db: JdbcTemplate) {
|
||||
node.y,
|
||||
node.width,
|
||||
node.height,
|
||||
node.permission
|
||||
node.permission,
|
||||
node.visible,
|
||||
node.endable,
|
||||
)
|
||||
|
||||
return node
|
||||
|
||||
@@ -1,103 +0,0 @@
|
||||
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: Timestamp) {
|
||||
companion object : RowMapper<View> {
|
||||
override public fun mapRow(rs: ResultSet, rowNum: Int): View {
|
||||
return View(
|
||||
rs.getString("id"),
|
||||
rs.getString("application_id"),
|
||||
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) {
|
||||
|
||||
public fun listFromApplicationId(id: String): List<View> =
|
||||
db.query("select * from views where application_id=?;", arrayOf(id), View).toList()
|
||||
|
||||
public fun getById(id: String): View? {
|
||||
val items = db.query("select * from views where id=?;", arrayOf(id), View).toList()
|
||||
if (items.size == 0) {
|
||||
return null
|
||||
}
|
||||
return items[0]
|
||||
}
|
||||
|
||||
public fun deleteById(id: String): View {
|
||||
val view = this.getById(id)
|
||||
if (view == null) {
|
||||
throw NotFound()
|
||||
}
|
||||
|
||||
db.update("delete from views where id=?", id)
|
||||
|
||||
return view
|
||||
}
|
||||
|
||||
public fun update(view: View): View {
|
||||
db.update(
|
||||
"update views set application_id=?, time=? where id=?;",
|
||||
view.application_id,
|
||||
view.time,
|
||||
view.id,
|
||||
)
|
||||
|
||||
return view
|
||||
}
|
||||
|
||||
public fun create(application_id: String): View {
|
||||
val id = UUID.randomUUID().toString()
|
||||
|
||||
var new_view = View(id, application_id, Timestamp(Date().getTime()))
|
||||
|
||||
db.update(
|
||||
"insert into views (id, application_id) values (?, ?)",
|
||||
new_view.id,
|
||||
new_view.application_id
|
||||
)
|
||||
|
||||
return new_view
|
||||
}
|
||||
}
|
||||
@@ -1,61 +1,53 @@
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id VARCHAR PRIMARY KEY,
|
||||
username VARCHAR NOT NULL,
|
||||
email VARCHAR NOT NULL,
|
||||
passwd VARCHAR NOT NULL,
|
||||
level INT NOT NULL
|
||||
id VARCHAR PRIMARY KEY,
|
||||
username VARCHAR NOT NULL,
|
||||
email VARCHAR NOT NULL,
|
||||
passwd VARCHAR NOT NULL,
|
||||
level INT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS tokens (
|
||||
token VARCHAR PRIMARY KEY,
|
||||
user_id VARCHAR
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS tokens (token VARCHAR PRIMARY KEY, user_id VARCHAR);
|
||||
|
||||
create table if not exists applications (
|
||||
id text primary key,
|
||||
url text not null,
|
||||
original_url text,
|
||||
unique_url text,
|
||||
company text,
|
||||
recruiter text,
|
||||
title text,
|
||||
mesasge text default '',
|
||||
status_history text default '',
|
||||
user_id text,
|
||||
extra_data text,
|
||||
-- this status will be deprecated in favor of the node style status
|
||||
status integer,
|
||||
status_id text default null,
|
||||
linked_application text default '',
|
||||
application_time text default '',
|
||||
agency boolean default false,
|
||||
create_time timestamp default now()
|
||||
id text primary key,
|
||||
url text not null,
|
||||
simple_url text not null,
|
||||
company text,
|
||||
recruiter text,
|
||||
title text,
|
||||
mesasge text default '',
|
||||
user_id text,
|
||||
extra_data text,
|
||||
status_id text default null,
|
||||
agency boolean default false,
|
||||
create_time timestamp default now ()
|
||||
);
|
||||
|
||||
-- Views are deprecated will be removed in the future
|
||||
create table if not exists views (
|
||||
id text primary key,
|
||||
application_id text not null,
|
||||
time timestamp default now()
|
||||
create table if not exists applications_urls (
|
||||
application_id text,
|
||||
url text not null,
|
||||
primary key (application_id, url)
|
||||
);
|
||||
|
||||
create table if not exists flair (
|
||||
id text primary key,
|
||||
user_id text not null,
|
||||
color text default '#ff0000',
|
||||
name text default 'New Flair',
|
||||
expr text default 'flair',
|
||||
description text default ''
|
||||
id text primary key,
|
||||
user_id text not null,
|
||||
color text default '#ff0000',
|
||||
name text default 'New Flair',
|
||||
expr text default 'flair',
|
||||
description text default '',
|
||||
showFullDescription integer default 1,
|
||||
sort integer default 0
|
||||
);
|
||||
|
||||
create table if not exists flair_link (
|
||||
id text primary key,
|
||||
application_id text not null,
|
||||
flair_id text not null
|
||||
id text primary key,
|
||||
application_id text not null,
|
||||
flair_id text not null
|
||||
);
|
||||
|
||||
create table if not exists events (
|
||||
id text primary key,
|
||||
id text primary key,
|
||||
application_id text not null,
|
||||
--
|
||||
-- Event Types
|
||||
@@ -64,46 +56,41 @@ create table if not exists events (
|
||||
-- Creation(0),
|
||||
-- StatusUpdate(1),
|
||||
-- Page(2)
|
||||
event_type integer not null,
|
||||
|
||||
event_type integer not null,
|
||||
-- This only matters when event_type == 1
|
||||
new_status integer,
|
||||
|
||||
time timestamp default now()
|
||||
new_status_id text,
|
||||
time timestamp default now ()
|
||||
);
|
||||
|
||||
--
|
||||
-- User Controlled Status
|
||||
--
|
||||
|
||||
create table if not exists user_status_node (
|
||||
id text primary key,
|
||||
user_id text not null,
|
||||
name text not null,
|
||||
icon text not null,
|
||||
x integer default 0,
|
||||
y integer default 0,
|
||||
width integer default 0,
|
||||
height integer default 0,
|
||||
permission integer default 0
|
||||
id text primary key,
|
||||
user_id text not null,
|
||||
name text not null,
|
||||
icon text not null,
|
||||
x integer default 0,
|
||||
y integer default 0,
|
||||
width integer default 0,
|
||||
height integer default 0,
|
||||
permission integer default 0,
|
||||
visible boolean default true,
|
||||
endable boolean default false
|
||||
);
|
||||
|
||||
create table if not exists user_status_link (
|
||||
id text primary key,
|
||||
id text primary key,
|
||||
-- You technically can get this by loking a the source and target nodes but that seams more complicated
|
||||
user_id text not null,
|
||||
|
||||
user_id text not null,
|
||||
-- This can be null because null means creation
|
||||
source_node text,
|
||||
-- This can be null because null means creation
|
||||
target_node text,
|
||||
|
||||
source_x integer default 0,
|
||||
source_y integer default 0,
|
||||
|
||||
target_x integer default 0,
|
||||
target_y integer default 0,
|
||||
|
||||
source_x integer default 0,
|
||||
source_y integer default 0,
|
||||
target_x integer default 0,
|
||||
target_y integer default 0,
|
||||
-- If this link is bidiretoral
|
||||
bi boolean
|
||||
bi boolean
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user