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.

141 lines
2.5 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
Logo("/uploadLogo"),
//提交注册资料
Register("/register"),
//受理注册资料
Accept("/accept"),
//模糊查询社团
List("/list"),
//审核注册资料
Check("/check"),
//社团注册资料列表
Audit("/audit"),
//审核进度
Read("/read"),
//id精确查询社团
Load("/load"),
//加载社团成员
LoadMember("${Load.path}/members");
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 = "出现未知异常,请联系管理员"