Skip to content

Commit

Permalink
Merge pull request #89 from meetacy/#177-search-without-location
Browse files Browse the repository at this point in the history
feat(#177-search-without-location): added support search without loca…
  • Loading branch information
y9san9 authored Feb 28, 2024
2 parents 2ffd9e5 + f8b4165 commit 16b47c2
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ internal class FriendsEngine(
suspend fun delete(request: DeleteFriendRequest) {
val url = baseUrl / "delete"
val body = request.toBody()
httpClient.post(url.string) {
httpClient.delete(url.string) {
apiVersion(request.apiVersion)
token(request.token)
setBody(body)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ import app.meetacy.sdk.types.serializable.user.type
import app.meetacy.sdk.types.url.Url
import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.request.get
import io.ktor.client.request.post
import io.ktor.client.request.setBody
import io.ktor.client.request.*
import kotlinx.serialization.Serializable

internal class MeetingsEngine(
Expand Down Expand Up @@ -76,43 +74,31 @@ internal class MeetingsEngine(
return ListMeetingsHistoryRequest.Response(response)
}

private fun ListActiveMeetingsRequest.toBody() = ListMeetingsPagingBody(
amount.serializable(),
pagingId?.serializable()
)

suspend fun listActiveMeetings(
request: ListActiveMeetingsRequest
): ListActiveMeetingsRequest.Response {
val url = baseUrl / "history" / "active"
val body = request.toBody()

val response = httpClient.get(url.string) {
apiVersion(request.apiVersion)
token(request.token)
setBody(body)
parameter("amount", request.amount.int)
parameter("pagingId", request.pagingId?.string)
}.bodyAsSuccess<PagingResponseSerializable<MeetingSerializable>>()
.type()
.mapItems { meeting -> meeting.type() }

return ListActiveMeetingsRequest.Response(response)
}

private fun ListPastMeetingsRequest.toBody() = ListMeetingsPagingBody(
amount.serializable(),
pagingId?.serializable()
)

suspend fun listPastMeetings(
request: ListPastMeetingsRequest
): ListPastMeetingsRequest.Response {
val url = baseUrl / "history" / "past"
val body = request.toBody()

val response = httpClient.post(url.string) {
val response = httpClient.get(url.string) {
apiVersion(request.apiVersion)
token(request.token)
setBody(body)
parameter("amount", request.amount.int)
parameter("pagingId", request.pagingId?.string)
}.bodyAsSuccess<PagingResponseSerializable<MeetingSerializable>>()
.type()
.mapItems { meeting -> meeting.type() }
Expand Down Expand Up @@ -164,7 +150,7 @@ internal class MeetingsEngine(

suspend fun createMeeting(
request: CreateMeetingRequest
): CreateMeetingRequest.Response = with(request) {
): CreateMeetingRequest.Response {
val url = baseUrl / "create"
val body = request.toBody()
val response = httpClient.post(url.string) {
Expand Down Expand Up @@ -199,7 +185,7 @@ internal class MeetingsEngine(
suspend fun editMeeting(request: EditMeetingRequest): EditMeetingRequest.Response = with(request) {
val url = baseUrl / "edit"
val body = request.toBody()
val response = httpClient.post(url.string) {
val response = httpClient.put(url.string) {
apiVersion(request.apiVersion)
token(request.token)
setBody(body)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ internal class SearchEngine(
val response = httpClient.get(baseUrl.string) {
apiVersion(request.apiVersion)
token(request.token)
parameter("latitude", request.location.latitude)
parameter("longitude", request.location.longitude)
parameter("latitude", request.location?.latitude)
parameter("longitude", request.location?.longitude)
parameter("prompt", request.prompt)
}.bodyAsSuccess<List<SearchItemSerializable>>()
return SearchRequest.Response(response.map { it.type() })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ internal class UsersEngine(
suspend fun editUser(request: EditUserRequest): EditUserRequest.Response {
val url = baseUrl / "edit"
val body = request.toBody()
val response = httpClient.post(url.string) {
val response = httpClient.put(url.string) {
apiVersion(request.apiVersion)
token(request.token)
setBody(body)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class AuthorizedMeetacyApi @UnsafeConstructor constructor(
data = base.getMe(token),
api = this
)
public suspend fun search(location: Location, prompt: String): List<AuthorizedSearchItemRepository> =
public suspend fun search(location: Location?, prompt: String): List<AuthorizedSearchItemRepository> =
base.search(token, location, prompt).map { AuthorizedSearchItemRepository.of(it.data, api = this) }

}
2 changes: 1 addition & 1 deletion api/src/commonMain/kotlin/app/meetacy/sdk/MeetacyApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class MeetacyApi(

public suspend fun search(
token: Token,
location: Location,
location: Location?,
prompt: String
): List<SearchItemRepository> {
return engine.execute(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import app.meetacy.sdk.types.search.SearchItem

public data class SearchRequest(
val token: Token,
val location: Location,
val location: Location?,
val prompt: String
) : MeetacyRequest<SearchRequest.Response> {
public data class Response(val items: List<SearchItem>)
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

kotlin = "1.9.0"
ktor = "2.3.6"
meetacySdk = "0.0.61"
meetacySdk = "0.0.62"

# kotlinx
kotlinxCoroutines = "1.6.4"
Expand Down

0 comments on commit 16b47c2

Please sign in to comment.