diff --git a/app/src/main/java/com/sama/calendar/application/BlockApplicationService.kt b/app/src/main/java/com/sama/calendar/application/BlockApplicationService.kt index d01c346c..62dc102d 100644 --- a/app/src/main/java/com/sama/calendar/application/BlockApplicationService.kt +++ b/app/src/main/java/com/sama/calendar/application/BlockApplicationService.kt @@ -3,14 +3,23 @@ package com.sama.calendar.application import com.sama.calendar.domain.Block import com.sama.calendar.domain.BlockRepository import com.sama.common.ApplicationService +import com.sama.common.findByIdOrThrow import com.sama.users.domain.UserId +import com.sama.users.domain.UserRepository +import org.springframework.beans.factory.annotation.Value import org.springframework.stereotype.Service +import org.springframework.web.util.UriComponentsBuilder import java.time.LocalDate import java.time.ZoneId @ApplicationService @Service -class BlockApplicationService(private val blockRepository: BlockRepository) { +class BlockApplicationService( + private val blockRepository: BlockRepository, + private val userRepository: UserRepository, + @Value("\${sama.meeting.url.scheme}") private val samaScheme: String, + @Value("\${sama.meeting.url.host}") private val samaHost: String +) { fun fetchBlocks(userId: UserId, startDate: LocalDate, endDate: LocalDate, timezone: ZoneId) = blockRepository.findAll( @@ -23,7 +32,23 @@ class BlockApplicationService(private val blockRepository: BlockRepository) { fun createBlock(userId: UserId, command: CreateBlockCommand) { - val block = Block(command.startDateTime, command.endDateTime, false, null, command.recipientEmail, 1,null) + val initiatorName = userRepository.findByIdOrThrow(userId).fullName + val samaUri = UriComponentsBuilder.newInstance() + .scheme(samaScheme) + .host(samaHost) + .build().toUriString() + + val block = Block( + command.startDateTime, + command.endDateTime, + false, + // TODO: use Moustache templates + initiatorName?.let { "Meeting with $it" }, + "Time for this meeting was created via Sama app", + command.recipientEmail, + 1, + null + ) blockRepository.save(userId, block) } } diff --git a/app/src/main/java/com/sama/calendar/domain/Block.kt b/app/src/main/java/com/sama/calendar/domain/Block.kt index fd0f87fe..34b29bd3 100644 --- a/app/src/main/java/com/sama/calendar/domain/Block.kt +++ b/app/src/main/java/com/sama/calendar/domain/Block.kt @@ -10,6 +10,7 @@ data class Block( val endDateTime: ZonedDateTime, val allDay: Boolean, val title: String?, + val description: String?, val recipientEmail: String?, val recurrenceCount: Int, val recurrenceRule: RecurrenceRule? diff --git a/app/src/main/java/com/sama/integration/google/GoogleCalendarBlockRepository.kt b/app/src/main/java/com/sama/integration/google/GoogleCalendarBlockRepository.kt index edfaf9fa..d44d49ae 100644 --- a/app/src/main/java/com/sama/integration/google/GoogleCalendarBlockRepository.kt +++ b/app/src/main/java/com/sama/integration/google/GoogleCalendarBlockRepository.kt @@ -79,9 +79,13 @@ class GoogleCalendarBlockRepository( end = EventDateTime() .setDateTime(block.endDateTime.toGoogleCalendarDateTime()) .setTimeZone(timeZone.id) - attendees = listOf(EventAttendee().apply { - email = block.recipientEmail - }) + attendees = listOf( + EventAttendee().apply { + email = block.recipientEmail + }, + ) + summary = block.title + description = block.description } val inserted = calendarService.events() @@ -142,7 +146,7 @@ class GoogleCalendarBlockRepository( this.end.toZonedDateTime(calendarTimeZone), this.isAllDay(), this.summary, - + this.description, if (this.attendees != null) { this.attendees.firstOrNull()?.email } else {