Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.example.smarthr_app.data.model

import com.google.gson.annotations.SerializedName

// Meeting Request Models
data class MeetingCreateRequestDto(
val title: String,
val description: String,
val startTime: String, // ISO format: "2025-07-22T10:00:00"
val endTime: String, // ISO format: "2025-07-22T11:00:00"
val meetingLink: String? = null,
val participants: List<String> // List of participant IDs
)

data class MeetingUpdateRequestDto(
val title: String,
val description: String,
val startTime: String,
val endTime: String,
val meetingLink: String? = null,
val participants: List<String>
)

// Meeting Response Models
data class MeetingResponseDto(
val id: String,
val title: String,
val description: String,
val organizer: String, // HR ID
val companyCode: String,
val meetingLink: String?,
val startTime: String,
val endTime: String,
val participants: List<UserInfo>,
val responses: List<MeetingResponseInfo>,
val status: String // "SCHEDULED", "CANCELLED", etc.
)

data class MeetingResponseInfo(
val participant: UserInfo,
val status: String // "ACCEPTED", "DECLINED", "PENDING"
)

// Enums
enum class MeetingStatus {
SCHEDULED, CANCELLED, COMPLETED
}

enum class ParticipantResponseStatus {
PENDING, ACCEPTED, DECLINED
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,42 @@ interface ApiService {
@Query("date") date: String? = null // Optional date parameter, defaults to today
): Response<List<AttendanceResponseDto>>

// Meeting endpoints
@POST("meetings/create")
suspend fun createMeeting(
@Header("Authorization") token: String,
@Body request: MeetingCreateRequestDto
): Response<MeetingResponseDto>

@GET("meetings/myMeetings")
suspend fun getMyMeetings(
@Header("Authorization") token: String
): Response<List<MeetingResponseDto>>

@GET("meetings/{id}")
suspend fun getMeetingById(
@Header("Authorization") token: String,
@Path("id") meetingId: String
): Response<MeetingResponseDto>

@POST("meetings/{id}")
suspend fun updateMeeting(
@Header("Authorization") token: String,
@Path("id") meetingId: String,
@Body request: MeetingUpdateRequestDto
): Response<MeetingResponseDto>

@POST("meetings/cancel/{id}")
suspend fun cancelMeeting(
@Header("Authorization") token: String,
@Path("id") meetingId: String
): Response<SuccessApiResponseMessage>

@POST("meetings/respond/{id}")
suspend fun respondToMeeting(
@Header("Authorization") token: String,
@Path("id") meetingId: String,
@Query("status") status: String // "ACCEPTED" or "DECLINED"
): Response<SuccessApiResponseMessage>

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import java.util.concurrent.TimeUnit

object RetrofitInstance {

// const val BASE_URL = "https://smarthr-backend-jx0v.onrender.com/"
const val BASE_URL = "https://3e1dce4d1855.ngrok-free.app/"
const val BASE_URL = "https://smarthr-backend-jx0v.onrender.com/"
// const val BASE_URL = "https://3e1dce4d1855.ngrok-free.app/"

private val loggingInterceptor = HttpLoggingInterceptor().apply {
level = HttpLoggingInterceptor.Level.BODY
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
package com.example.smarthr_app.data.repository

import com.example.smarthr_app.data.local.DataStoreManager
import com.example.smarthr_app.data.model.*
import com.example.smarthr_app.data.remote.RetrofitInstance
import com.example.smarthr_app.utils.Resource
import kotlinx.coroutines.flow.first

class MeetingRepository(private val dataStoreManager: DataStoreManager) {

suspend fun createMeeting(
title: String,
description: String,
startTime: String,
endTime: String,
meetingLink: String?,
participants: List<String>
): Resource<MeetingResponseDto> {
return try {
val token = dataStoreManager.token.first()
if (token != null) {
val request = MeetingCreateRequestDto(
title = title,
description = description,
startTime = startTime,
endTime = endTime,
meetingLink = meetingLink,
participants = participants
)
val response = RetrofitInstance.api.createMeeting("Bearer $token", request)
if (response.isSuccessful) {
response.body()?.let {
Resource.Success(it)
} ?: Resource.Error("Meeting created but no data received")
} else {
Resource.Error("Failed to create meeting: ${response.message()}")
}
} else {
Resource.Error("No authentication token found")
}
} catch (e: Exception) {
Resource.Error("Network error: ${e.message}")
}
}

suspend fun getMyMeetings(): Resource<List<MeetingResponseDto>> {
return try {
val token = dataStoreManager.token.first()
if (token != null) {
val response = RetrofitInstance.api.getMyMeetings("Bearer $token")
if (response.isSuccessful) {
response.body()?.let {
Resource.Success(it)
} ?: Resource.Error("No meetings data received")
} else {
Resource.Error("Failed to load meetings: ${response.message()}")
}
} else {
Resource.Error("No authentication token found")
}
} catch (e: Exception) {
Resource.Error("Network error: ${e.message}")
}
}

suspend fun getMeetingById(meetingId: String): Resource<MeetingResponseDto> {
return try {
val token = dataStoreManager.token.first()
if (token != null) {
val response = RetrofitInstance.api.getMeetingById("Bearer $token", meetingId)
if (response.isSuccessful) {
response.body()?.let {
Resource.Success(it)
} ?: Resource.Error("No meeting data received")
} else {
Resource.Error("Failed to load meeting: ${response.message()}")
}
} else {
Resource.Error("No authentication token found")
}
} catch (e: Exception) {
Resource.Error("Network error: ${e.message}")
}
}

suspend fun updateMeeting(
meetingId: String,
title: String,
description: String,
startTime: String,
endTime: String,
meetingLink: String?,
participants: List<String>
): Resource<MeetingResponseDto> {
return try {
val token = dataStoreManager.token.first()
if (token != null) {
val request = MeetingUpdateRequestDto(
title = title,
description = description,
startTime = startTime,
endTime = endTime,
meetingLink = meetingLink,
participants = participants
)
val response = RetrofitInstance.api.updateMeeting("Bearer $token", meetingId, request)
if (response.isSuccessful) {
response.body()?.let {
Resource.Success(it)
} ?: Resource.Error("Meeting updated but no data received")
} else {
Resource.Error("Failed to update meeting: ${response.message()}")
}
} else {
Resource.Error("No authentication token found")
}
} catch (e: Exception) {
Resource.Error("Network error: ${e.message}")
}
}

suspend fun cancelMeeting(meetingId: String): Resource<SuccessApiResponseMessage> {
return try {
val token = dataStoreManager.token.first()
if (token != null) {
val response = RetrofitInstance.api.cancelMeeting("Bearer $token", meetingId)
if (response.isSuccessful) {
response.body()?.let {
Resource.Success(it)
} ?: Resource.Error("Meeting cancelled but no confirmation received")
} else {
Resource.Error("Failed to cancel meeting: ${response.message()}")
}
} else {
Resource.Error("No authentication token found")
}
} catch (e: Exception) {
Resource.Error("Network error: ${e.message}")
}
}

suspend fun respondToMeeting(meetingId: String, status: String): Resource<SuccessApiResponseMessage> {
return try {
val token = dataStoreManager.token.first()
if (token != null) {
val response = RetrofitInstance.api.respondToMeeting("Bearer $token", meetingId, status)
if (response.isSuccessful) {
response.body()?.let {
Resource.Success(it)
} ?: Resource.Error("Response sent but no confirmation received")
} else {
Resource.Error("Failed to respond to meeting: ${response.message()}")
}
} else {
Resource.Error("No authentication token found")
}
} catch (e: Exception) {
Resource.Error("Network error: ${e.message}")
}
}
}
Loading