added the views funcionality and other things
This commit is contained in:
@@ -33,7 +33,10 @@ dependencies {
|
||||
implementation("org.bouncycastle:bcprov-jdk18on:1.76")
|
||||
}
|
||||
|
||||
//kotlin { compilerOptions { freeCompilerArgs.addAll("-Xjsr305=strict") } compiler { jvm { target = JavaLanguageVersion.of(17) } } }
|
||||
springBoot {
|
||||
mainClass.set("com.andr3h3nriqu3s.applications.ApplicationsApplicationKt")
|
||||
}
|
||||
|
||||
kotlin {
|
||||
compilerOptions {
|
||||
freeCompilerArgs.addAll("-Xjsr305=strict")
|
||||
|
||||
@@ -7,5 +7,6 @@ import org.springframework.boot.runApplication
|
||||
class ApplicationsApplication
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
runApplication<ApplicationsApplication>(*args)
|
||||
runApplication<ApplicationsApplication>(*args)
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.andr3h3nriqu3s.applications
|
||||
import java.sql.ResultSet
|
||||
import java.util.UUID
|
||||
import kotlin.collections.setOf
|
||||
import kotlin.collections.emptyList
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import org.springframework.http.MediaType
|
||||
@@ -32,7 +33,9 @@ data class Application(
|
||||
var status: Int,
|
||||
var company: String,
|
||||
var recruiter: String,
|
||||
var message: String,
|
||||
var flairs: List<Flair>,
|
||||
var views: List<View>,
|
||||
) {
|
||||
companion object : RowMapper<Application> {
|
||||
override public fun mapRow(rs: ResultSet, rowNum: Int): Application {
|
||||
@@ -48,7 +51,9 @@ data class Application(
|
||||
rs.getInt("status"),
|
||||
rs.getString("company"),
|
||||
rs.getString("recruiter"),
|
||||
emptyList()
|
||||
rs.getString("message"),
|
||||
emptyList(),
|
||||
emptyList(),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -64,7 +69,7 @@ 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>)
|
||||
data class CVData(val company: String, val recruiter: String, val message: String, val flairs: List<SimpleFlair>)
|
||||
|
||||
@RestController
|
||||
@ControllerAdvice
|
||||
@@ -72,24 +77,28 @@ data class CVData(val company: String, val recruiter: String, val flairs: List<
|
||||
class ApplicationsController(
|
||||
val sessionService: SessionService,
|
||||
val applicationService: ApplicationService,
|
||||
val flairService: FlairService
|
||||
val flairService: FlairService,
|
||||
val viewService: ViewService,
|
||||
) {
|
||||
|
||||
@GetMapping(path = ["/cv/{id}"], produces = [MediaType.APPLICATION_JSON_VALUE])
|
||||
public fun getCV(
|
||||
@PathVariable id: String,
|
||||
@RequestHeader("token") token: String
|
||||
@RequestHeader("token") token: String?
|
||||
): CVData? {
|
||||
print("here!");
|
||||
val user = sessionService.verifyToken(token);
|
||||
|
||||
val application = applicationService.findApplicationByIdNoUser(id);
|
||||
|
||||
if (application == null) return null;
|
||||
|
||||
if (user == null) {
|
||||
viewService.create(application.id)
|
||||
}
|
||||
|
||||
val flairs = application.flairs.map {it.toFlairSimple()};
|
||||
|
||||
return CVData(application.company, application.recruiter, flairs);
|
||||
return CVData(application.company, application.recruiter, application.message, flairs);
|
||||
}
|
||||
|
||||
@PostMapping(path = ["/text"], produces = [MediaType.APPLICATION_JSON_VALUE])
|
||||
@@ -204,7 +213,9 @@ class ApplicationsController(
|
||||
0,
|
||||
"",
|
||||
"",
|
||||
emptyList()
|
||||
"",
|
||||
emptyList(),
|
||||
emptyList(),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -408,7 +419,7 @@ class ApplicationsController(
|
||||
}
|
||||
|
||||
@Service
|
||||
class ApplicationService(val db: JdbcTemplate, val flairService: FlairService) {
|
||||
class ApplicationService(val db: JdbcTemplate, val flairService: FlairService, val viewService: ViewService) {
|
||||
|
||||
public fun findApplicationByUrl(user: UserDb, url: String, unique_url: String?): Application? {
|
||||
if (unique_url != null) {
|
||||
@@ -456,6 +467,7 @@ class ApplicationService(val db: JdbcTemplate, val flairService: FlairService) {
|
||||
var application = applications[0]
|
||||
|
||||
application.flairs = flairService.listFromLinkApplicationId(application.id)
|
||||
application.views = viewService.listFromApplicationId(application.id)
|
||||
|
||||
return application
|
||||
}
|
||||
@@ -469,6 +481,7 @@ class ApplicationService(val db: JdbcTemplate, val flairService: FlairService) {
|
||||
|
||||
var application = applications[0]
|
||||
|
||||
// Views are not needed for this request
|
||||
application.flairs = flairService.listFromLinkApplicationId(application.id)
|
||||
|
||||
return application
|
||||
@@ -480,7 +493,7 @@ class ApplicationService(val db: JdbcTemplate, val flairService: FlairService) {
|
||||
}
|
||||
|
||||
db.update(
|
||||
"insert into applications (id, url, original_url, unique_url, title, user_id, extra_data, payrange, status, company, recruiter) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);",
|
||||
"insert into applications (id, url, original_url, unique_url, title, user_id, extra_data, payrange, status, company, recruiter, message) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);",
|
||||
application.id,
|
||||
application.url,
|
||||
application.original_url,
|
||||
@@ -491,7 +504,8 @@ class ApplicationService(val db: JdbcTemplate, val flairService: FlairService) {
|
||||
application.payrange,
|
||||
application.status,
|
||||
application.company,
|
||||
application.recruiter
|
||||
application.recruiter,
|
||||
application.message,
|
||||
)
|
||||
|
||||
return true
|
||||
@@ -517,7 +531,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=?, company=?, recruiter=? where id=?",
|
||||
"update applications set url=?, original_url=?, unique_url=?, title=?, user_id=?, extra_data=?, payrange=?, status=?, company=?, recruiter=?, message=? where id=?",
|
||||
application.url,
|
||||
application.original_url,
|
||||
application.unique_url,
|
||||
@@ -528,6 +542,7 @@ class ApplicationService(val db: JdbcTemplate, val flairService: FlairService) {
|
||||
application.status,
|
||||
application.company,
|
||||
application.recruiter,
|
||||
application.message,
|
||||
application.id,
|
||||
)
|
||||
return application
|
||||
|
||||
@@ -3,19 +3,16 @@ package com.andr3h3nriqu3s.applications
|
||||
import java.util.UUID
|
||||
import kotlin.io.encoding.Base64
|
||||
import kotlin.random.Random
|
||||
import org.springframework.http.HttpStatus
|
||||
import org.springframework.http.MediaType
|
||||
import org.springframework.jdbc.core.JdbcTemplate
|
||||
import org.springframework.security.crypto.argon2.Argon2PasswordEncoder
|
||||
import org.springframework.stereotype.Service
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.PostMapping
|
||||
import org.springframework.web.bind.annotation.RequestBody
|
||||
import org.springframework.web.bind.annotation.RequestHeader
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.ResponseStatus
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
|
||||
enum class UserLevel(val level: Int) {
|
||||
@@ -167,7 +164,10 @@ data class Session(val token: String, val user_id: String)
|
||||
@Service
|
||||
class SessionService(val db: JdbcTemplate) {
|
||||
|
||||
fun verifyToken(token: String): UserDb? {
|
||||
fun verifyToken(token: String?): UserDb? {
|
||||
if (token == null) {
|
||||
return null;
|
||||
}
|
||||
var users =
|
||||
db
|
||||
.query(
|
||||
|
||||
71
api/src/main/kotlin/com/andr3h3nriqu3s/applications/View.kt
Normal file
71
api/src/main/kotlin/com/andr3h3nriqu3s/applications/View.kt
Normal file
@@ -0,0 +1,71 @@
|
||||
package com.andr3h3nriqu3s.applications
|
||||
|
||||
import java.sql.ResultSet
|
||||
import java.util.Date
|
||||
import java.util.UUID
|
||||
import org.springframework.jdbc.core.JdbcTemplate
|
||||
import org.springframework.jdbc.core.RowMapper
|
||||
import org.springframework.stereotype.Service
|
||||
|
||||
data class View(var id: String, var application_id: String, var time: Date) {
|
||||
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"),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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, Date())
|
||||
|
||||
db.update(
|
||||
"insert into views (id, application_id) values (?, ?)",
|
||||
new_view.id,
|
||||
new_view.application_id
|
||||
)
|
||||
|
||||
return new_view
|
||||
}
|
||||
}
|
||||
@@ -19,18 +19,25 @@ create table if not exists applications (
|
||||
company text,
|
||||
recruiter text,
|
||||
title text,
|
||||
mesasge text default '',
|
||||
user_id text,
|
||||
extra_data text,
|
||||
status integer
|
||||
);
|
||||
|
||||
create table if not exists views (
|
||||
id text primary key,
|
||||
application_id text not null,
|
||||
time timestamp default current_timestamp
|
||||
);
|
||||
|
||||
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 '',
|
||||
expr text default 'flair',
|
||||
description text default ''
|
||||
);
|
||||
|
||||
create table if not exists flair_link (
|
||||
|
||||
Reference in New Issue
Block a user