router.go 7.43 KB
Newer Older
hujiebin's avatar
hujiebin committed
1 2 3
package route

import (
hujiebin's avatar
hujiebin committed
4 5
	"git.hilo.cn/hilo-common/domain"
	"git.hilo.cn/hilo-common/mylogrus"
hujiebin's avatar
hujiebin committed
6 7 8
	"github.com/gin-gonic/gin"
	ginSwagger "github.com/swaggo/gin-swagger"
	"github.com/swaggo/gin-swagger/swaggerFiles"
hujiebin's avatar
hujiebin committed
9
	"hilo-group/_const/enum/mgr_e"
hujiebin's avatar
hujiebin committed
10
	_ "hilo-group/docs"
hujiebin's avatar
hujiebin committed
11
	"hilo-group/domain/model/mgr_m"
chenweijian's avatar
chenweijian committed
12
	"hilo-group/route/charge_r"
hujiebin's avatar
hujiebin committed
13
	"hilo-group/route/group_power_r"
hujiebin's avatar
hujiebin committed
14
	"hilo-group/route/group_r"
hujiebin's avatar
hujiebin committed
15 16 17 18 19 20 21 22 23 24
)

func InitRouter() *gin.Engine {
	var r = gin.Default()

	r.GET("/group-swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))

	needLogin := r.Group("")
	needLogin.Use(ExceptionHandle, LoggerHandle, JWTApiHandle)
	v1 := needLogin.Group("/v1")
hujiebin's avatar
hujiebin committed
25 26 27 28 29 30 31 32 33
	imGroup := v1.Group("/imGroup")
	{
		imGroup.GET("/popular", wrapper(group_r.GetPopularGroups))
		imGroup.GET("/latest", wrapper(group_r.GetLatestGroups))
		imGroup.GET("/recommended", wrapper(group_r.GetRecommendGroup))
		//
		imGroup.POST("/group", wrapper(group_r.CreateGroup))
		imGroup.DELETE("/group/:groupId", wrapper(group_r.DestroyGroup))
		imGroup.GET("/group/:code", wrapper(group_r.GetGroupInfo))
hujiebin's avatar
hujiebin committed
34
		imGroup.GET("/detail/:groupId", wrapper(group_r.GetGroupDetail))
hujiebin's avatar
hujiebin committed
35
		imGroup.PUT("/group/:groupId", wrapper(group_r.ModifyGroupInfo))
36 37 38 39 40 41 42
		imGroup.GET("/search/:code", wrapper(group_r.SearchGroup))
		imGroup.DELETE("/member/:groupId", wrapper(group_r.LeaveGroup))
		imGroup.PUT("/permanent/:groupId", wrapper(group_r.AddPermanentMember))
		imGroup.DELETE("/permanent/:groupId", wrapper(group_r.RemovePermanentMember))
		imGroup.GET("/permanent/:groupId", wrapper(group_r.GetPermanentMember))
		imGroup.GET("/myRecent", wrapper(group_r.GetRecentGroup))
		imGroup.GET("/myPermanent", wrapper(group_r.GetMyGroup))
hujiebin's avatar
hujiebin committed
43
		//
44 45
		imGroup.GET("/visitors/:groupId", wrapper(group_r.GetGroupVisitors))
		imGroup.GET("/ownPublicGroup/:userExternalId", wrapper(group_r.GetOwnPublicGroup))
hujiebin's avatar
hujiebin committed
46
		//// 2.19的新接口
47 48 49 50
		imGroup.GET("/ownGroup", wrapper(group_r.GetOwnGroup))
		imGroup.GET("/theirGroup/:userExternalId", wrapper(group_r.GetTheirGroups))
		imGroup.PUT("/pluginReady/:groupId", wrapper(group_r.PluginReady))
		imGroup.GET("/roomInfo/:groupId", wrapper(group_r.GetRoomInfo))
hujiebin's avatar
hujiebin committed
51
		//
52 53 54 55 56
		imGroup.GET("/password/:groupId", wrapper(group_r.GetGroupPassword))
		imGroup.GET("/role/:groupId", wrapper(group_r.GetGroupRole))
		imGroup.PUT("/role/:groupId", wrapper(group_r.SetGroupRole))
		imGroup.POST("/role/accept", wrapper(group_r.AcceptMemberInvite))
		imGroup.GET("/admin/:groupId", wrapper(group_r.GetGroupAdmin))
hujiebin's avatar
hujiebin committed
57
		//
58 59 60 61
		imGroup.PUT("/blacklist/:groupId", wrapper(group_r.AddGroupBlacklist))
		imGroup.DELETE("/blacklist/:groupId", wrapper(group_r.RemoveGroupBlacklist))
		imGroup.GET("/blacklist/:groupId", wrapper(group_r.GetGroupBlacklist))
		imGroup.PUT("/kick/:groupId", wrapper(group_r.KickGroupMembers))
hujiebin's avatar
hujiebin committed
62
		//
63
		imGroup.PUT("/allGroupMsg", wrapper(group_r.SendTextMsg))
hujiebin's avatar
hujiebin committed
64
		//
65 66 67 68 69
		imGroup.PUT("/welcomeText/:groupId", wrapper(group_r.SetWelcomeText))
		imGroup.GET("/support/page/:groupId", wrapper(group_r.GetSupportPage))
		imGroup.GET("/support/detail", wrapper(group_r.GetSupportDetail))
		imGroup.GET("/support/award/:groupId", wrapper(group_r.TryAddSupporter))
		imGroup.POST("/support/award/:groupId", wrapper(group_r.TakeSupportAward))
hujiebin's avatar
hujiebin committed
70 71
		//
		//// 操作类,普通用户不用
hujiebin's avatar
hujiebin committed
72 73 74 75
		imGroup.PUT("/memberLimit", wrapper(group_r.SetGroupMemberLimit))
		imGroup.PUT("/info/reset", wrapper(group_r.ResetGroupInfo), OperationLog)
		imGroup.PUT("/upgrade", wrapper(group_r.UpgradeGroup))
		imGroup.PUT("/downgrade", wrapper(group_r.DowngradeGroup))
hujiebin's avatar
hujiebin committed
76
		//
hujiebin's avatar
hujiebin committed
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
		imGroup.GET("/mic/all", wrapper(group_r.GroupMicAllInfoFive))
		imGroup.GET("/mic/all/type", wrapper(group_r.GroupMicAllInfoTen))
		imGroup.GET("/mic/all/type/new", wrapper(group_r.GroupMicAllInfoType))
		imGroup.PUT("/mic/num", wrapper(group_r.GroupMicNumChange))
		imGroup.GET("/mic/num", wrapper(group_r.GroupMicNum))
		imGroup.POST("/mic/emoji/msg", wrapper(group_r.GroupSendMicSystemMsg))
		imGroup.POST("/mic/in/invite/dialog", wrapper(group_r.GroupMicInInviteDialog))
		imGroup.POST("/mic/task/invite/dialog", wrapper(group_r.GroupMicTaskInviteDialog))
		imGroup.POST("/mic/in", wrapper(group_r.GroupMicIn))
		imGroup.POST("/mic/invite", wrapper(group_r.GroupMicInvite))
		imGroup.POST("/mic/leave", wrapper(group_r.GroupMicLeave))
		imGroup.POST("/mic/lock", wrapper(group_r.GroupMicLock))
		imGroup.POST("/mic/unlock", wrapper(group_r.GroupMicUnLock))
		imGroup.POST("/mic/speech/open", wrapper(group_r.GroupMicSpeechOpen))
		imGroup.POST("/mic/speech/close", wrapper(group_r.GroupMicSpeechClose))
		imGroup.POST("/mic/mute", wrapper(group_r.GroupMicMute))
		imGroup.POST("/mic/unmute", wrapper(group_r.GroupMicUnmute))
		imGroup.PUT("/in", wrapper(group_r.GroupIn))
		imGroup.POST("/leave", wrapper(group_r.GroupLeave))
		imGroup.POST("/kick", wrapper(group_r.GroupKick))
		imGroup.PUT("/user/msg/status", wrapper(group_r.GroupUserMsg))
		imGroup.POST("/report", wrapper(group_r.GroupReport))
		imGroup.GET("/banner/list", wrapper(group_r.GroupBannerList))
		imGroup.GET("/roomBanners", wrapper(group_r.RoomBannerList))
		imGroup.PUT("/roomBanners", wrapper(group_r.NotifyRoomBannerListChange))
		//imGroup.POST("/mic/gift", wrapper(GroupMicGift)) // todo 先留在biz,内容有点多
		imGroup.POST("/mic/mass", wrapper(group_r.GroupMicMass))
		imGroup.POST("/mgr/mass", wrapper(group_r.GroupMgrMass))
		imGroup.POST("/mgr/clearScreen", wrapper(group_r.GroupMgrClearScreen))
		imGroup.GET("/online/users", wrapper(group_r.GroupInUsers))
		imGroup.GET("/online/users/new", wrapper(group_r.GroupInUserNew))
		imGroup.GET("/country", wrapper(group_r.GetGroupByCountry))
		imGroup.GET("/country/prior", wrapper(group_r.GroupountryPrior))
hujiebin's avatar
hujiebin committed
110
		//
hujiebin's avatar
hujiebin committed
111 112 113 114
		imGroup.POST("/theme/custom", wrapper(group_r.GroupThemeAdd))
		imGroup.GET("/theme/custom/config", wrapper(group_r.GroupThemeConfig))
		imGroup.PUT("/theme/custom/using", wrapper(group_r.GroupThemeUsing))
		imGroup.GET("/theme/custom/all", wrapper(group_r.GroupThemeValidAll))
hujiebin's avatar
hujiebin committed
115
		//
hujiebin's avatar
hujiebin committed
116 117
		imGroup.GET("/medal/all", wrapper(group_r.GroupMedalAll))
		imGroup.GET("/medal/room", wrapper(group_r.GetRoomMedal))
hujiebin's avatar
hujiebin committed
118
	}
hujiebin's avatar
hujiebin committed
119 120 121 122 123 124 125 126 127 128

	groupPower := v1.Group("/groupPower")
	{
		groupPower.POST("/user", wrapper(group_power_r.GroupPowerJoin))
		groupPower.DELETE("/user/:groupPowerId", wrapper(group_power_r.GroupPowerLeave))
		groupPower.GET("/title/:groupPowerId", wrapper(group_power_r.GetGroupPowerTitle))
		groupPower.GET("/group/:groupPowerId", wrapper(group_power_r.GetGroupPowerGroups))
		groupPower.GET("/team", wrapper(group_power_r.GroupPowerTeam))
		groupPower.GET("/billboard/week", wrapper(group_power_r.GroupPowerBillboardWeek))
		groupPower.GET("/billboard/owner/week", wrapper(group_power_r.GroupPowerBillboardOwnerWeek))
chenweijian's avatar
chenweijian committed
129
		groupPower.GET("/info", wrapper(group_power_r.GroupPowerInfo))
chenweijian's avatar
chenweijian committed
130
		groupPower.GET("/rooms", wrapper(group_power_r.GroupPowerRooms))
chenweijian's avatar
chenweijian committed
131
		groupPower.GET("/members", wrapper(group_power_r.GroupPowerMembers))
hujiebin's avatar
hujiebin committed
132
	}
chenweijian's avatar
chenweijian committed
133 134 135 136 137

	charge := v1.Group("/charge")
	{
		charge.GET("/share", wrapper(charge_r.CanShareChargeLink))
	}
hujiebin's avatar
hujiebin committed
138 139
	return r
}
hujiebin's avatar
hujiebin committed
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160

// 操作日志
func OperationLog(c *gin.Context) {
	mylogrus.MyLog.Infof("%v-%v", c.Request.Method, c.FullPath())
	// 处理请求
	c.Next()
	model := domain.CreateModelNil()
	operConfig := mgr_m.GetOperationModuleUrl(model, c.Request.Method, c.FullPath())
	if operConfig.ID > 0 {
		// 需要记录操作日志
		if data, ok := c.Get(mgr_e.OperationLogKey); ok {
			if log, ok := data.(mgr_m.MgrOperationLog); ok {
				log.ModuleId = operConfig.ModuleId
				log.ModuleUrlId = operConfig.ID
				if err := mgr_m.SaveOperationLog(model, log); err != nil {
					model.Log.Error("SaveOperationLog fail:%v", err.Error())
				}
			}
		}
	}
}