Skip to content

Commit

Permalink
WIP: feat: started adding search endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
y9san9 committed Oct 25, 2023
1 parent bbaf74c commit f08f485
Show file tree
Hide file tree
Showing 52 changed files with 415 additions and 808 deletions.
1 change: 1 addition & 0 deletions api/api-ktor/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dependencies {
commonMainImplementation(libs.rsocketKtorClient)

commonMainApi(projects.api)
commonMainImplementation(projects.types.serializable)

jvmTestImplementation(libs.ktorClientCio)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package app.meetacy.sdk.engine.ktor

import app.meetacy.sdk.types.auth.Token
import app.meetacy.sdk.version.ApiVersion
import io.ktor.client.request.*
import io.ktor.http.*

public fun HttpRequestBuilder.apiVersion(apiVersion: ApiVersion) {
header("Api-Version", apiVersion.int)
}

public fun HttpRequestBuilder.token(token: Token) {
header(HttpHeaders.Authorization, token.string)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import app.meetacy.sdk.engine.ktor.requests.friends.FriendsEngine
import app.meetacy.sdk.engine.ktor.requests.invitations.InvitationsEngine
import app.meetacy.sdk.engine.ktor.requests.meetings.MeetingsEngine
import app.meetacy.sdk.engine.ktor.requests.notifications.NotificationsEngine
import app.meetacy.sdk.engine.ktor.requests.search.SearchEngine
import app.meetacy.sdk.engine.ktor.requests.updates.UpdatesEngine
import app.meetacy.sdk.engine.ktor.requests.users.UsersEngine
import app.meetacy.sdk.engine.ktor.response.ServerResponse
Expand Down Expand Up @@ -51,6 +52,7 @@ public class KtorMeetacyEngine(
private val files = FilesEngine(baseUrl, this.httpClient)
private val invitations = InvitationsEngine(baseUrl, this.httpClient, this.json)
private val notifications = NotificationsEngine(baseUrl, this.httpClient, this.json)
private val search = SearchEngine(baseUrl, this.httpClient)
private val updates = UpdatesEngine(baseUrl, this.httpClient, this.json)

override fun getFileUrl(
Expand Down Expand Up @@ -93,12 +95,13 @@ public class KtorMeetacyEngine(
// notifications
is ReadNotificationRequest -> notifications.read(request) as T
is ListNotificationsRequest -> notifications.list(request) as T
// search
is SearchRequest -> search.search(request) as T
// updates
is EmitUpdatesRequest -> updates.stream(request) as T
// not yet supported
is LinkEmailRequest -> notSupported()
is ConfirmEmailRequest -> notSupported()
is TokenProviderEmpty -> notSupported()
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,33 @@

package app.meetacy.sdk.engine.ktor.requests.auth

import app.meetacy.sdk.engine.ktor.requests.extencion.postWithoutToken
import app.meetacy.sdk.engine.ktor.response.models.GenerateIdentityResponse
import app.meetacy.sdk.engine.ktor.apiVersion
import app.meetacy.sdk.engine.ktor.response.bodyAsSuccess
import app.meetacy.sdk.engine.requests.GenerateAuthRequest
import app.meetacy.sdk.types.annotation.UnsafeConstructor
import app.meetacy.sdk.types.auth.Token
import app.meetacy.sdk.types.url.Url
import io.ktor.client.*
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.buildJsonObject
import kotlinx.serialization.json.put
import io.ktor.client.request.*
import kotlinx.serialization.Serializable

internal class AuthEngine(
private val baseUrl: Url,
private val httpClient: HttpClient,
private val json: Json
private val httpClient: HttpClient
) {
@Serializable
private data class GenerateAuthBody(val nickname: String)

suspend fun generate(request: GenerateAuthRequest): GenerateAuthRequest.Response {
val url = baseUrl / "auth" / "generate"

val jsonObject = buildJsonObject {
put("nickname", request.nickname)
}

val string = postWithoutToken(url.string, jsonObject, httpClient, request)

val token = json.decodeFromString<GenerateIdentityResponse>(string).result

return GenerateAuthRequest.Response(token = Token(token))
val body = GenerateAuthBody(request.nickname)
val response = httpClient
.post(url.string) {
apiVersion(request.apiVersion)
setBody(body)
}
.bodyAsSuccess<String>()
val result = Token(response)
return GenerateAuthRequest.Response(result)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import app.meetacy.sdk.engine.ktor.mapToLocation
import app.meetacy.sdk.engine.ktor.mapToRegularUser
import app.meetacy.sdk.engine.ktor.mapToUser
import app.meetacy.sdk.engine.ktor.requests.extencion.post
import app.meetacy.sdk.engine.ktor.response.models.ListFriendsResponse
import app.meetacy.sdk.engine.ktor.response.models.Location as ModelLocation
import app.meetacy.sdk.engine.ktor.response.models.StatusTrueResponse
import app.meetacy.sdk.engine.ktor.response.models.User as ModelUser
import app.meetacy.sdk.engine.ktor.models.ListFriendsResponse
import app.meetacy.sdk.engine.ktor.models.Location as ModelLocation
import app.meetacy.sdk.engine.ktor.models.StatusTrueResponse
import app.meetacy.sdk.engine.ktor.models.User as ModelUser
import app.meetacy.sdk.engine.requests.AddFriendRequest
import app.meetacy.sdk.engine.requests.DeleteFriendRequest
import app.meetacy.sdk.engine.requests.EmitFriendsLocationRequest
Expand Down Expand Up @@ -43,7 +43,7 @@ internal class FriendsEngine(
) {
private val baseUrl = baseUrl / "friends"

suspend fun add(request: AddFriendRequest): StatusTrueResponse {
suspend fun add(request: AddFriendRequest): app.meetacy.sdk.engine.ktor.models.StatusTrueResponse {
val url = baseUrl / "add"

val jsonObject = buildJsonObject {
Expand All @@ -52,10 +52,10 @@ internal class FriendsEngine(

val string = post(url.string, jsonObject, httpClient, request)

return json.decodeFromString<StatusTrueResponse>(string)
return json.decodeFromString<app.meetacy.sdk.engine.ktor.models.StatusTrueResponse>(string)
}

suspend fun delete(request: DeleteFriendRequest): StatusTrueResponse {
suspend fun delete(request: DeleteFriendRequest): app.meetacy.sdk.engine.ktor.models.StatusTrueResponse {
val url = baseUrl / "delete"

val jsonObject = buildJsonObject {
Expand All @@ -64,20 +64,20 @@ internal class FriendsEngine(

val string = post(url.string, jsonObject, httpClient, request)

return json.decodeFromString<StatusTrueResponse>(string)
return json.decodeFromString<app.meetacy.sdk.engine.ktor.models.StatusTrueResponse>(string)
}

suspend fun list(request: ListFriendsRequest): ListFriendsRequest.Response {
val url = baseUrl / "list"

val jsonObject = buildJsonObject {
put("amount", request.amount.int.toString())
put("amount", request.amount.int)
put("pagingId", request.pagingId?.string)
}

val string = post(url.string, jsonObject, httpClient, request)

val response = Json.decodeFromString<ListFriendsResponse>(string).result
val response = Json.decodeFromString<app.meetacy.sdk.engine.ktor.models.ListFriendsResponse>(string).result

val paging = PagingResponse(
nextPagingId = response.nextPagingId?.let(::PagingId),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package app.meetacy.sdk.engine.ktor.requests.invitations

import app.meetacy.sdk.engine.ktor.requests.extencion.post
import app.meetacy.sdk.engine.ktor.response.models.CreateInvitationResponse
import app.meetacy.sdk.engine.ktor.response.models.StatusTrueResponse
import app.meetacy.sdk.engine.ktor.models.CreateInvitationResponse
import app.meetacy.sdk.engine.ktor.models.StatusTrueResponse
import app.meetacy.sdk.engine.ktor.toInvitation
import app.meetacy.sdk.engine.requests.AcceptInvitationRequest
import app.meetacy.sdk.engine.requests.CancelInvitationRequest
Expand Down Expand Up @@ -32,14 +32,14 @@ internal class InvitationsEngine(

val string = post(url.string, jsonObject, httpClient, request)

val response = json.decodeFromString<CreateInvitationResponse>(string).result
val response = json.decodeFromString<app.meetacy.sdk.engine.ktor.models.CreateInvitationResponse>(string).result

return CreateInvitationRequest.Response(response.toInvitation())
}

suspend fun accept(
request: AcceptInvitationRequest
): StatusTrueResponse {
): app.meetacy.sdk.engine.ktor.models.StatusTrueResponse {
val url = baseUrl / "accept"

val jsonObject = buildJsonObject {
Expand All @@ -48,12 +48,12 @@ internal class InvitationsEngine(

val string = post(url.string, jsonObject, httpClient, request)

return json.decodeFromString<StatusTrueResponse>(string)
return json.decodeFromString<app.meetacy.sdk.engine.ktor.models.StatusTrueResponse>(string)
}

suspend fun deny(
request: DenyInvitationRequest
): StatusTrueResponse {
): app.meetacy.sdk.engine.ktor.models.StatusTrueResponse {
val url = baseUrl / "deny"

val jsonObject = buildJsonObject {
Expand All @@ -62,12 +62,12 @@ internal class InvitationsEngine(

val string = post(url.string, jsonObject, httpClient, request)

return json.decodeFromString<StatusTrueResponse>(string)
return json.decodeFromString<app.meetacy.sdk.engine.ktor.models.StatusTrueResponse>(string)
}

suspend fun cancel(
request: CancelInvitationRequest
): StatusTrueResponse {
): app.meetacy.sdk.engine.ktor.models.StatusTrueResponse {
val url = baseUrl / "cancel"

val jsonObject = buildJsonObject {
Expand All @@ -76,7 +76,7 @@ internal class InvitationsEngine(

val string = post(url.string, jsonObject, httpClient, request)

return json.decodeFromString<StatusTrueResponse>(string)
return json.decodeFromString<app.meetacy.sdk.engine.ktor.models.StatusTrueResponse>(string)
}

}
Loading

0 comments on commit f08f485

Please sign in to comment.