Skip to content

Commit

Permalink
feat: 空教室初步接入新后端
Browse files Browse the repository at this point in the history
  • Loading branch information
klxiaoniu committed Sep 30, 2024
1 parent fa01e0e commit 1002643
Show file tree
Hide file tree
Showing 11 changed files with 189 additions and 229 deletions.
8 changes: 6 additions & 2 deletions shared/src/commonMain/kotlin/config/BaseUrlConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@ package config
object BaseUrlConfig {
// 设置是否为debug状态,这会影响日志输出
const val isDebug = true

// val BaseUrl = "http://47.116.24.13:9077"
// if( isDebug )"http://10.0.2.2:9077" else
// const val BaseUrl = "http://47.116.24.13:9077"
const val BaseUrl = "http://10.0.2.2:9077"

// const val BaseUrl = "http://192.168.1.233:9077"
const val UserAvatar = "${BaseUrl}/static/userAvatar"
const val CommentImage = "${BaseUrl}/static/comment"
const val PostImage = "${BaseUrl}/static/post"
const val RibbonImage = "${BaseUrl}/static/ribbon"
const val OpenImage = "${BaseUrl}/openImage"
const val FuTalkFeedbackQuestionUrl = "https://api.github.com/repos/Futalker/FuTalk_Question"

const val NEW_SERVER_URL = "https://fzuhelper.west2.online"
// const val NEW_SERVER_URL = "http://121.199.41.144"
}

// BASE_URL配置
Expand Down Expand Up @@ -45,12 +50,11 @@ const val USERINFO_URL = "https://avatar.fzuhelper.w2fzu.com/"
const val SCHOOL_MAP_URL = "https://map.fzu.edu.cn/#/home"
const val SCREEN_BASE_URL = "https://launch.w2fzu.com/"
const val WELCOME_URL = "https://welcome.fzuhelper.w2fzu.com"

// 推送设置
const val PUSH_PLATFORM = "android_umeng"

const val BUGLY_APP_ID = "27422503a8"

const val UMENG_APP_KEY = "5dce696b570df3081900033f"
const val UMENG_MESSAGE_SECRET = "2931a731b52ca1457b387bcc22cdff32"

const val NEW_SERVER_URL = "https://fzuhelper.west2.online"
20 changes: 20 additions & 0 deletions shared/src/commonMain/kotlin/data/base/BaseResponseData.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package data.base

import kotlinx.serialization.Serializable
import util.network.NetworkResult
import util.network.networkErrorWithLog


@Serializable
data class BaseResponseData<T>(
val code: Int,
val message: String,
val data: T
) {
fun toNetworkResult(): NetworkResult<T> {
return when (code) {
10000 -> NetworkResult.Success(data)
else -> networkErrorWithLog(code, "获取失败")
}
}
}
5 changes: 0 additions & 5 deletions shared/src/commonMain/kotlin/data/emptyRoom/Data.kt

This file was deleted.

15 changes: 0 additions & 15 deletions shared/src/commonMain/kotlin/data/emptyRoom/EmptyData.kt

This file was deleted.

5 changes: 0 additions & 5 deletions shared/src/commonMain/kotlin/data/emptyRoom/EmptyItemData.kt

This file was deleted.

11 changes: 11 additions & 0 deletions shared/src/commonMain/kotlin/data/emptyRoom/EmptyRoom.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package data.emptyRoom

import kotlinx.serialization.Serializable

@Serializable
data class EmptyRoom(
val build: String,
val location: String,
val capacity: String,
val type: String
)
20 changes: 20 additions & 0 deletions shared/src/commonMain/kotlin/di/koinAction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,25 @@ class LoginClient(
.encodeAction()
)

/**
* 用于访问福uu后端的client
*
* @property client HttpClient
* @constructor
*/
class FzuHelperClient(
val client: HttpClient =
HttpClient {
install(ContentNegotiation) { json() }
install(DefaultRequest) { url(BaseUrlConfig.NEW_SERVER_URL) }
install(Logging)
install(HttpCookies) {}
install(HttpRedirect) { checkHttpMethod = false }
configure()
}
.encodeAction()
)

class SchoolClient(
val client: HttpClient =
HttpClient {
Expand Down Expand Up @@ -407,6 +426,7 @@ fun appModule(rootAction: RootAction, systemAction: SystemAction, navigator: Nav
viewModel()
single { initStore() }
single { LoginClient() }
single { FzuHelperClient() }
single { ShareClient() }
single { WebClient() }
single { Toast(globalScope) }
Expand Down
54 changes: 21 additions & 33 deletions shared/src/commonMain/kotlin/repository/EmptyRoomRepository.kt
Original file line number Diff line number Diff line change
@@ -1,56 +1,44 @@
package repository

import data.emptyRoom.EmptyData
import io.ktor.client.HttpClient
import data.base.BaseResponseData
import data.emptyRoom.EmptyRoom
import di.FzuHelperClient
import io.ktor.client.call.body
import io.ktor.client.request.forms.submitForm
import io.ktor.http.parameters
import io.ktor.client.request.get
import io.ktor.client.request.parameter
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow

/**
* 空教室的相关仓库层 -- 需要重写
* 空教室的相关仓库层
*
* @property client HttpClient
* @property client FzuHelperClient
* @constructor
*/
class EmptyRoomRepository(val client: HttpClient) {
class EmptyRoomRepository(val client: FzuHelperClient) {
/**
* 刷新课程
*
* @param campus String
* @param date String
* @param roomType String
* @param start String
* @param end String
* @param build String
* @return Flow<EmptyRoomData>
* @param startTime String
* @param endTime String
* @return Flow<List<EmptyRoom>>
*/
fun getEmptyRoom(
fun getEmptyRoomList(
campus: String,
date: String,
roomType: String,
start: String,
end: String,
build: List<String>,
): Flow<EmptyData> {
startTime: String,
endTime: String
): Flow<BaseResponseData<List<EmptyRoom>>> {
return flow {
val response =
client
.apply {}
.submitForm(
url = "/emptyRoom/class",
formParameters =
parameters {
append("Campus", campus)
build.forEach { append("Build", it) }
append("RoomType", roomType)
append("Date", date)
append("Start", start)
append("End", end)
},
)
.body<EmptyData>()
client.client.get("/api/v1/common/classroom/empty") {
parameter("date", date)
parameter("campus", campus)
parameter("startTime", startTime)
parameter("endTime", endTime)
}.body<BaseResponseData<List<EmptyRoom>>>()
emit(response)
}
}
Expand Down
Loading

0 comments on commit 1002643

Please sign in to comment.