You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
2.2 KiB

package com.gyf.lib.util
import com.gyf.lib.BuildConfig
import java.util.*
interface UrlPath {
fun build(): String
}
enum class TestApi(val path: String) : UrlPath {
Test("test");
override fun build(): String = "/api/${this.path}"
}
/**
* 帐号接口
*
* @property path
*/
enum class AccountApi(val path: String) : UrlPath {
//注册
Register("/register"),
//学号检测
CheckId("/register/checkId"),
//前台登录
ForegroundLogin("/login/${ClientType.Foreground.name.toLowerCase(Locale.ROOT)}"),
//后台登陆
BackgroundLogin("/login/${ClientType.Background.name.toLowerCase(Locale.ROOT)}"),
//前台令牌校验
ForegroundToken("${ForegroundLogin.path}/token"),
//后台令牌校验
BackgroundToken("${BackgroundLogin.path}/token"),
//登出
Logout("/logout");
override fun build(): String {
return "/api/account${this.path}"
}
}
/**
* 主页接口
*
* @property path
*/
enum class MainApi(val path: String) : UrlPath {
//热门活动
HotActivity("/hotActivity"),
//留言区
LeaveMessage("/leaveMessage"),
GetMessage("/getMessage");
override fun build(): String {
return "/api/main${this.path}"
}
}
/**
* 社团接口
*
* @property path
*/
enum class AssociationApi(val path: String) : UrlPath {
Logo("/uploadLogo"),
Register("/register"),
Accept("/accept"),
List("/list"),
Check("/check"),
Audit("/audit"),
Read("/read"),
Load("/load");
override fun build(): String {
return "/api/association${this.path}"
}
}
enum class NotificationApi(val path: String) : UrlPath {
Count("/count"),
List("/list"),
Pull("/pull");
override fun build(): String {
return "/api/notification${this.path}"
}
}
/**
* 构建服务端请求接口地址
*
*/
object Api {
fun buildUrl(urlPath: UrlPath): String {
return "${BuildConfig.SERVER_ADDRESS}${urlPath.build()}"
}
fun buildUrl(path: String): String {
return "${BuildConfig.SERVER_ADDRESS}${if (path.startsWith("/")) "" else "/"}${path}"
}
}
const val NOT_IMPL_TIP = "功能尚未实现!"
const val UNKNOW_ERROR = "出现未知异常,请联系管理员"