Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/main/kotlin/ui/main/FormatDateTime.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package ui.main
import kotlinx.datetime.LocalDateTime

fun LocalDateTime.format(): String {
val monthString = monthNumber.toString().padStart(2, '0')
val dayString = dayOfMonth.toString().padStart(2, '0')
val hourString = hour.toString().padStart(2, '0')
val minuteString = minute.toString().padStart(2, '0')
val month = monthNumber.toString().padStart(2, '0')
val day = dayOfMonth.toString().padStart(2, '0')
val hour = hour.toString().padStart(2, '0')
val minute = minute.toString().padStart(2, '0')

return "$year-$monthString-$dayString,$hourString:$minuteString"
return "$year-$month-$day,$hour:$minute"
}
53 changes: 21 additions & 32 deletions src/main/kotlin/ui/screens/TaskManagementScreen.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package ui.screens

import data.remote.mongoDataSource.dto.TaskDto
import data.repository.mapper.toTaskDto
import data.repository.mapper.toTaskEntity
import ui.main.format
import kotlinx.datetime.Clock
import kotlinx.datetime.LocalDateTime
Expand Down Expand Up @@ -96,26 +93,19 @@ class TaskManagementScreen(
consoleIO.showWithLine("⚠️ No tasks available.")
}
tasks.forEach { task ->
val taskDTO = task.toTaskDto()
val createdAt = try {
LocalDateTime.parse(taskDTO.createdAt).format()
} catch (_: Exception) {
taskDTO.createdAt
}
val updatedAt = try {
LocalDateTime.parse(taskDTO.updatedAt).format()
} catch (_: Exception) {
taskDTO.updatedAt
}
val createdAt = LocalDateTime.parse(task.createdAt.toString()).format()

val updatedAt = LocalDateTime.parse(task.updatedAt.toString()).format()

consoleIO.showWithLine("")
consoleIO.showWithLine(
"""
╭────────────────────────────────────────╮
│ ID: ${taskDTO.id}
│ Title: ${taskDTO.title}
│ Description: ${taskDTO.description}
│ State ID: ${taskDTO.stateId}
│ Created By: ${taskDTO.createdBy}
│ ID: ${task.id}
│ Title: ${task.title}
│ Description: ${task.description}
│ State ID: ${task.stateId}
│ Created By: ${task.createdBy}
│ Created At: $createdAt
│ Updated At: $updatedAt
╰────────────────────────────────────────╯
Expand All @@ -140,18 +130,18 @@ class TaskManagementScreen(

showAnimation("Finding task...") {
try {
val taskDTO = getTaskByIdUseCase.getTaskById(id)
val task = getTaskByIdUseCase.getTaskById(id)
consoleIO.showWithLine("")
consoleIO.showWithLine(
"""
╭─────────────────────────────────────────╮
│ ID: ${taskDTO.id}
│ Title: ${taskDTO.title}
│ Description: ${taskDTO.description}
│ State ID: ${taskDTO.stateId}
│ Created By: ${taskDTO.createdBy}
│ Created At: ${taskDTO.createdAt.format()}
│ Updated At: ${taskDTO.updatedAt.format()}
│ ID: ${task.id}
│ Title: ${task.title}
│ Description: ${task.description}
│ State ID: ${task.stateId}
│ Created By: ${task.createdBy}
│ Created At: ${task.createdAt.format()}
│ Updated At: ${task.updatedAt.format()}
╰─────────────────────────────────────────╯
""".trimIndent()
)
Expand Down Expand Up @@ -191,20 +181,19 @@ class TaskManagementScreen(

val now = Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault())

val taskDTO = TaskDto(
id = Uuid.random().toString(),
val task = Task(
id = Uuid.random(),
projectId = projectId,
title = title,
description = description ?: "",
createdBy = currentUser.userName,
stateId = stateId,
createdAt = now.toString(),
updatedAt = now.toString()
createdAt = now,
updatedAt = now
)

showAnimation("Adding task...") {
try {
val task = taskDTO.toTaskEntity()
addTaskUseCase.addTask(task)
consoleIO.showWithLine("✅ Task added successfully.")

Expand Down
Loading