Skip to content

Commit

Permalink
Add initiator name and event description to GCal event
Browse files Browse the repository at this point in the history
  • Loading branch information
balysv committed Jul 10, 2021
1 parent c51d3ff commit bef09a1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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 <a href=$samaUri>Sama app</a>",
command.recipientEmail,
1,
null
)
blockRepository.save(userId, block)
}
}
1 change: 1 addition & 0 deletions app/src/main/java/com/sama/calendar/domain/Block.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit bef09a1

Please sign in to comment.