Skip to content

Commit

Permalink
removed comment csv (#566)
Browse files Browse the repository at this point in the history
  • Loading branch information
starheim98 authored Dec 19, 2024
1 parent 94e2672 commit 270fc05
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions backend/src/main/kotlin/no/bekk/routes/UploadCSVRouting.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ fun getLatestAnswersAndComments(): List<AnswersCSVDump> {
" a.answer_type, \n" +
" a.answer_unit, \n" +
" a.updated as answer_updated,\n" +
" c.comment, \n" +
" c.updated as comment_updated,\n" +
" a.actor as answer_actor,\n" +
" c.actor as comment_actor,\n" +
" a.context_id,\n" +
" ctx.name as context_name,\n" +
" ctx.table_id as table_id,\n" +
Expand All @@ -60,11 +57,6 @@ fun getLatestAnswersAndComments(): List<AnswersCSVDump> {
"JOIN \n" +
" (SELECT question_id, record_id, MAX(updated) as latest FROM answers GROUP BY question_id, record_id) as latest_answers\n" +
" ON a.question_id = latest_answers.question_id AND a.record_id = latest_answers.record_id AND a.updated = latest_answers.latest\n" +
"LEFT JOIN \n" +
" comments c ON a.question_id = c.question_id AND a.record_id = c.record_id\n" +
"LEFT JOIN \n" +
" (SELECT question_id, record_id, MAX(updated) as latest FROM comments GROUP BY question_id, record_id) as latest_comments\n" +
" ON c.question_id = latest_comments.question_id AND c.record_id = latest_comments.record_id AND c.updated = latest_comments.latest\n" +
"JOIN \n" +
" contexts ctx ON a.context_id = ctx.id;\n"

Expand All @@ -86,9 +78,9 @@ fun getLatestAnswersAndComments(): List<AnswersCSVDump> {

fun List<AnswersCSVDump>.toCsv(): String {
val stringWriter = StringWriter()
stringWriter.append("questionId,answer,answer_type,answer_unit,answer_updated,answer_actor,comment,comment_updated,comment_actor,context_id,context_name,table_id,team_id\n")
stringWriter.append("questionId,answer,answer_type,answer_unit,answer_updated,answer_actor,context_id,context_name,table_id,team_id\n")
this.forEach {
stringWriter.append("\"${it.questionId}\",\"${it.answer}\",\"${it.answerType}\",\"${it.answerUnit}\",\"${it.answerUpdated}\",\"${it.answerActor}\",\"${it.comment}\",\"${it.commentUpdated}\",\"${it.commentActor}\",\"${it.contextId}\",\"${it.contextName}\",\"${it.tableName}\",\"${it.teamId}\"\n")
stringWriter.append("\"${it.questionId}\",\"${it.answer}\",\"${it.answerType}\",\"${it.answerUnit}\",\"${it.answerUpdated}\",\"${it.answerActor}\",\"${it.contextId}\",\"${it.contextName}\",\"${it.tableName}\",\"${it.teamId}\"\n")
}

return stringWriter.toString()
Expand All @@ -102,9 +94,6 @@ fun mapRowToAnswersCSVDump(rs: ResultSet): AnswersCSVDump {
answerUnit = rs.getString("answer_unit"),
answerUpdated = rs.getDate("answer_updated"),
answerActor = rs.getString("answer_actor"),
comment = rs.getString("comment"),
commentUpdated = rs.getDate("comment_updated"),
commentActor = rs.getString("comment_actor"),
contextId = rs.getString("context_id"),
tableName = rs.getString("table_id"),
teamId = rs.getString("team_id"),
Expand All @@ -119,9 +108,6 @@ data class AnswersCSVDump(
val answerUnit: String?,
val answerUpdated: Date,
val answerActor: String,
val comment: String?,
val commentUpdated: Date?,
val commentActor: String?,
val contextId: String,
val tableName: String,
val teamId: String,
Expand Down

0 comments on commit 270fc05

Please sign in to comment.