package com.gyf.lib.util import com.gyf.csams.module.ClientType 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"), //刷新用户信息 Refresh("/refresh"), //加载部门干事概况 Load("/load/manager"), UploadHeadimg("/upload/img"), //加载部门详情 LoadDetail("${Load.path}/detail"); 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"), //后台社团管理 ListAll("${List.path}/all"), Update("/update"), //审核注册资料 Check("/check"), //社团注册资料列表 Audit("/audit"), //审核进度 Read("/read"), //id精确查询社团 Load("/load"), //加载社团成员 LoadMember("${Load.path}/members"), //社团重命名 Rename("/rename"), //提交换名申请表 RenameRegister("${Rename.path}${Register.path}"), //换名申请表受理 RenameAccept("${Rename.path}${Accept.path}"), //换名申请表审核 RenameCheck("${Rename.path}${Check.path}"), //换名申请表审核记录 RenameAudit("${Rename.path}${Audit.path}"), //换名申请表审核进度 RenameRead("${Rename.path}${Read.path}"), //更新题库 UpdateExam("/update/exam"), //加载题库 LoadExam("/load/exam"), //申请入团 CheckApply("/check/apply"), //创建试卷 CreatePaper("/create/paper"), //提交答卷 ApplyAnswer("/apply/paper"), //检查入团申请 CheckJoin("/check/join"), //审核入团申请 AuditJoin("/audit/join"), //显示答案 ShowAnswers("/show/answer"); override fun build(): String { return "/api/association${this.path}" } } /** * 活动接口 * * @property path */ enum class ActivityApi(val path: String) : UrlPath { //前台提交活动申请书 Register("/register"), //后台查看活动申请书 Audit("/audit"), //后台受理活动申请书 Accept("/accept"), //后台审核活动申请书 Check("/check"), //审核进度 Read("/read"), //加载活动 Load("/load"), //加载活动详情 Show("/show"), //加载活动照片 Photo("/photo"), //上传照片 UploadPhoto("${Photo.path}/upload"), //查看评论 Comment("/comment"), //发送评论 SendComment("${Comment.path}/send"), //后台活动查看 ListAll("/list/all"), //修改活动倾向 Tendency("/tendency"), //检查活动倾向 CheckTendency("${Tendency.path}/check"), //查询活动倾向 FindTendency("${Tendency.path}/find") ; override fun build(): String { return "/api/activity${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 = "出现未知异常,请联系管理员"