Добавил логику работы с ИИ-агентом и работу с расписанием
This commit is contained in:
@@ -10,6 +10,10 @@ data class Task(
|
||||
val completed: Boolean = false,
|
||||
val scheduledTime: LocalDateTime?,
|
||||
val duration: Int? = null, // in minutes
|
||||
val scheduleId: String
|
||||
val scheduleId: String,
|
||||
val order: Int = 0,
|
||||
val category: String? = null,
|
||||
val createdAt: LocalDateTime? = null,
|
||||
val updatedAt: LocalDateTime? = null
|
||||
)
|
||||
|
||||
|
||||
@@ -4,8 +4,24 @@ import com.novayaplaneta.domain.model.ChatMessage
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
interface AIRepository {
|
||||
suspend fun sendMessage(userId: String, message: String): Result<String>
|
||||
suspend fun sendMessage(userId: String, message: String, conversationId: String?): Result<ChatResponse>
|
||||
fun getChatHistory(userId: String): Flow<List<ChatMessage>>
|
||||
suspend fun generateSchedule(userId: String, preferences: String): Result<String>
|
||||
suspend fun generateSchedule(
|
||||
childAge: Int,
|
||||
preferences: List<String>,
|
||||
date: String,
|
||||
description: String
|
||||
): Result<GenerateScheduleResult>
|
||||
}
|
||||
|
||||
data class ChatResponse(
|
||||
val response: String,
|
||||
val conversationId: String
|
||||
)
|
||||
|
||||
data class GenerateScheduleResult(
|
||||
val scheduleId: String,
|
||||
val title: String,
|
||||
val tasks: List<Map<String, Any>>
|
||||
)
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.novayaplaneta.domain.repository
|
||||
|
||||
import com.novayaplaneta.domain.model.Schedule
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import java.time.LocalDateTime
|
||||
|
||||
interface ScheduleRepository {
|
||||
fun getSchedules(userId: String): Flow<List<Schedule>>
|
||||
@@ -11,5 +10,6 @@ interface ScheduleRepository {
|
||||
suspend fun updateSchedule(schedule: Schedule)
|
||||
suspend fun deleteSchedule(id: String)
|
||||
suspend fun syncSchedules(userId: String)
|
||||
suspend fun loadSchedules(scheduleDate: String? = null)
|
||||
}
|
||||
|
||||
|
||||
@@ -4,11 +4,12 @@ import com.novayaplaneta.domain.model.Task
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
interface TaskRepository {
|
||||
suspend fun loadTasks(scheduleId: String): Result<Unit>
|
||||
fun getTasks(scheduleId: String): Flow<List<Task>>
|
||||
suspend fun getTaskById(id: String): Task?
|
||||
suspend fun createTask(task: Task)
|
||||
suspend fun getTaskById(id: String): Result<Task>
|
||||
suspend fun createTask(task: Task): Result<Task>
|
||||
suspend fun updateTask(task: Task)
|
||||
suspend fun deleteTask(id: String)
|
||||
suspend fun completeTask(id: String)
|
||||
suspend fun deleteTask(id: String): Result<Unit>
|
||||
suspend fun completeTask(id: String, completed: Boolean): Result<Task>
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package com.novayaplaneta.domain.usecase
|
||||
|
||||
import com.novayaplaneta.domain.model.Task
|
||||
import com.novayaplaneta.domain.repository.TaskRepository
|
||||
import javax.inject.Inject
|
||||
|
||||
class CompleteTaskUseCase @Inject constructor(
|
||||
private val repository: TaskRepository
|
||||
) {
|
||||
suspend operator fun invoke(taskId: String) {
|
||||
repository.completeTask(taskId)
|
||||
suspend operator fun invoke(id: String, completed: Boolean): Result<Task> {
|
||||
return repository.completeTask(id, completed)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,8 +7,17 @@ import javax.inject.Inject
|
||||
class CreateScheduleUseCase @Inject constructor(
|
||||
private val repository: ScheduleRepository
|
||||
) {
|
||||
suspend operator fun invoke(schedule: Schedule) {
|
||||
repository.createSchedule(schedule)
|
||||
suspend operator fun invoke(schedule: Schedule): Result<Schedule> {
|
||||
return try {
|
||||
repository.createSchedule(schedule)
|
||||
// После создания перезагружаем список, чтобы получить актуальные данные
|
||||
repository.loadSchedules()
|
||||
// Возвращаем успешный результат
|
||||
// Созданное расписание уже добавлено в кэш через createSchedule
|
||||
Result.success(schedule)
|
||||
} catch (e: Exception) {
|
||||
Result.failure(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.novayaplaneta.domain.usecase
|
||||
|
||||
import com.novayaplaneta.domain.model.Task
|
||||
import com.novayaplaneta.domain.repository.TaskRepository
|
||||
import javax.inject.Inject
|
||||
|
||||
class CreateTaskUseCase @Inject constructor(
|
||||
private val repository: TaskRepository
|
||||
) {
|
||||
suspend operator fun invoke(task: Task): Result<Task> {
|
||||
return repository.createTask(task)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.novayaplaneta.domain.usecase
|
||||
|
||||
import com.novayaplaneta.domain.repository.ScheduleRepository
|
||||
import javax.inject.Inject
|
||||
|
||||
class DeleteScheduleUseCase @Inject constructor(
|
||||
private val repository: ScheduleRepository
|
||||
) {
|
||||
suspend operator fun invoke(id: String): Result<Unit> {
|
||||
return try {
|
||||
repository.deleteSchedule(id)
|
||||
Result.success(Unit)
|
||||
} catch (e: Exception) {
|
||||
Result.failure(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.novayaplaneta.domain.usecase
|
||||
|
||||
import com.novayaplaneta.domain.repository.TaskRepository
|
||||
import javax.inject.Inject
|
||||
|
||||
class DeleteTaskUseCase @Inject constructor(
|
||||
private val repository: TaskRepository
|
||||
) {
|
||||
suspend operator fun invoke(id: String): Result<Unit> {
|
||||
return repository.deleteTask(id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.novayaplaneta.domain.usecase
|
||||
|
||||
import com.novayaplaneta.domain.repository.AIRepository
|
||||
import com.novayaplaneta.domain.repository.GenerateScheduleResult
|
||||
import javax.inject.Inject
|
||||
|
||||
class GenerateScheduleUseCase @Inject constructor(
|
||||
private val aiRepository: AIRepository
|
||||
) {
|
||||
suspend operator fun invoke(
|
||||
childAge: Int,
|
||||
preferences: List<String>,
|
||||
date: String,
|
||||
description: String
|
||||
): Result<GenerateScheduleResult> {
|
||||
return aiRepository.generateSchedule(childAge, preferences, date, description)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.novayaplaneta.domain.usecase
|
||||
|
||||
import com.novayaplaneta.domain.model.Schedule
|
||||
import com.novayaplaneta.domain.repository.ScheduleRepository
|
||||
import javax.inject.Inject
|
||||
|
||||
class GetScheduleByIdUseCase @Inject constructor(
|
||||
private val repository: ScheduleRepository
|
||||
) {
|
||||
suspend operator fun invoke(id: String): Result<Schedule> {
|
||||
return try {
|
||||
val schedule = repository.getScheduleById(id)
|
||||
if (schedule != null) {
|
||||
Result.success(schedule)
|
||||
} else {
|
||||
Result.failure(Exception("Schedule not found"))
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Result.failure(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,5 +11,14 @@ class GetSchedulesUseCase @Inject constructor(
|
||||
operator fun invoke(userId: String): Flow<List<Schedule>> {
|
||||
return repository.getSchedules(userId)
|
||||
}
|
||||
|
||||
suspend fun loadSchedules(scheduleDate: String? = null): Result<Unit> {
|
||||
return try {
|
||||
repository.loadSchedules(scheduleDate)
|
||||
Result.success(Unit)
|
||||
} catch (e: Exception) {
|
||||
Result.failure(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.novayaplaneta.domain.usecase
|
||||
|
||||
import com.novayaplaneta.domain.model.Task
|
||||
import com.novayaplaneta.domain.repository.TaskRepository
|
||||
import javax.inject.Inject
|
||||
|
||||
class GetTaskByIdUseCase @Inject constructor(
|
||||
private val repository: TaskRepository
|
||||
) {
|
||||
suspend operator fun invoke(id: String): Result<Task> {
|
||||
return repository.getTaskById(id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.novayaplaneta.domain.usecase
|
||||
|
||||
import com.novayaplaneta.domain.model.Task
|
||||
import com.novayaplaneta.domain.repository.TaskRepository
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import javax.inject.Inject
|
||||
|
||||
class GetTasksUseCase @Inject constructor(
|
||||
private val repository: TaskRepository
|
||||
) {
|
||||
operator fun invoke(scheduleId: String): Flow<List<Task>> {
|
||||
return repository.getTasks(scheduleId)
|
||||
}
|
||||
|
||||
suspend fun loadTasks(scheduleId: String): Result<Unit> {
|
||||
return try {
|
||||
repository.loadTasks(scheduleId)
|
||||
} catch (e: Exception) {
|
||||
Result.failure(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package com.novayaplaneta.domain.usecase
|
||||
|
||||
import com.novayaplaneta.domain.repository.AIRepository
|
||||
import com.novayaplaneta.domain.repository.ChatResponse
|
||||
import javax.inject.Inject
|
||||
|
||||
class SendAIMessageUseCase @Inject constructor(
|
||||
private val repository: AIRepository
|
||||
) {
|
||||
suspend operator fun invoke(userId: String, message: String): Result<String> {
|
||||
return repository.sendMessage(userId, message)
|
||||
suspend operator fun invoke(userId: String, message: String, conversationId: String? = null): Result<ChatResponse> {
|
||||
return repository.sendMessage(userId, message, conversationId)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user