router.go 8.98 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"
hujiebin's avatar
hujiebin 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
	"hilo-group/route/mic_r"
hujiebin's avatar
hujiebin committed
16 17 18 19 20 21 22 23 24 25
)

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
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))
hujiebin's avatar
hujiebin committed
34 35
		imGroup.GET("/group/:code", EncryptHandle, wrapper(group_r.GetGroupInfo))
		imGroup.GET("/detail/:groupId", EncryptHandle, wrapper(group_r.GetGroupDetail))
hujiebin's avatar
hujiebin committed
36
		imGroup.PUT("/group/:groupId", wrapper(group_r.ModifyGroupInfo))
37 38 39 40 41 42 43
		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
44
		//
45 46
		imGroup.GET("/visitors/:groupId", wrapper(group_r.GetGroupVisitors))
		imGroup.GET("/ownPublicGroup/:userExternalId", wrapper(group_r.GetOwnPublicGroup))
hujiebin's avatar
hujiebin committed
47
		//// 2.19的新接口
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))
chenweijian's avatar
chenweijian committed
51
		imGroup.GET("/roomInfo/:groupId", EncryptHandle, wrapper(group_r.GetRoomInfo)) // 进房
hujiebin's avatar
hujiebin committed
52
		//
53 54 55 56 57
		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
58
		//
59 60 61 62
		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
63
		//
64
		imGroup.PUT("/allGroupMsg", wrapper(group_r.SendTextMsg))
hujiebin's avatar
hujiebin committed
65
		//
66 67 68 69 70
		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
71 72
		//
		//// 操作类,普通用户不用
hujiebin's avatar
hujiebin committed
73 74 75 76
		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
77
		//
hujiebin's avatar
hujiebin committed
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
		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))
chenweijian's avatar
chenweijian committed
95
		imGroup.PUT("/in", wrapper(group_r.GroupIn)) // 进房
hujiebin's avatar
hujiebin committed
96 97 98 99 100 101 102 103 104 105 106 107 108
		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))
chenweijian's avatar
chenweijian committed
109
		imGroup.GET("/country", wrapper(group_r.GetGroupByCountryV2))
hujiebin's avatar
hujiebin committed
110
		imGroup.GET("/country/prior", wrapper(group_r.GroupountryPrior))
hujiebin's avatar
hujiebin committed
111
		//
hujiebin's avatar
hujiebin committed
112 113 114 115
		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
116
		//
hujiebin's avatar
hujiebin committed
117 118
		imGroup.GET("/medal/all", wrapper(group_r.GroupMedalAll))
		imGroup.GET("/medal/room", wrapper(group_r.GetRoomMedal))
hujiebin's avatar
hujiebin committed
119
	}
hujiebin's avatar
hujiebin committed
120 121 122 123 124 125 126 127 128 129

	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))
hujiebin's avatar
hujiebin committed
130 131 132 133 134 135
		groupPower.GET("/info", wrapper(group_power_r.GroupPowerInfo))
		groupPower.GET("/rooms", wrapper(group_power_r.GroupPowerRooms))
		groupPower.GET("/members", wrapper(group_power_r.GroupPowerMembers))
		groupPower.POST("/apply", wrapper(group_power_r.GroupPowerApplyJoin))
		groupPower.POST("/apply/pass", wrapper(group_power_r.GroupPowerApplyPass))
		groupPower.GET("/apply/list", wrapper(group_power_r.GroupPowerApplyList))
hujiebin's avatar
hujiebin committed
136
		groupPower.GET("/apply/count", wrapper(group_power_r.GroupPowerApplyCount))
hujiebin's avatar
hujiebin committed
137 138 139 140
		groupPower.POST("/quit", wrapper(group_power_r.GroupPowerQuit))
		groupPower.GET("/quit/list", wrapper(group_power_r.GroupPowerQuitList))
		groupPower.POST("/admin", wrapper(group_power_r.GroupPowerSetAdmin))
		groupPower.GET("/rank/:period", wrapper(group_power_r.GroupPowerRank))
141
		groupPower.GET("/rankTop", wrapper(group_power_r.GroupPowerRankTop))
hujiebin's avatar
hujiebin committed
142
		groupPower.GET("/star", wrapper(group_power_r.GroupPowerStar))
143
		groupPower.GET("/star/:period", wrapper(group_power_r.GroupPowerStarPeriod))
hujiebin's avatar
hujiebin committed
144
		groupPower.POST("/info/set", wrapper(group_power_r.GroupPowerSetInfo))
hujiebin's avatar
hujiebin committed
145
	}
hujiebin's avatar
hujiebin committed
146 147 148
	h5GroupPower := v1.Group("/h5/groupPower")
	{
		h5GroupPower.GET("/grade/detail", wrapper(group_power_r.GroupPowerGradeDetail))
chenweijian's avatar
chenweijian committed
149
		h5GroupPower.GET("/rank/month", wrapper(group_power_r.GroupPowerMonthRankAct))
hujiebin's avatar
hujiebin committed
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
	}

	charge := v1.Group("/charge")
	{
		charge.GET("/share", wrapper(charge_r.CanShareChargeLink))
	}

	// 内部接口
	inner := r.Group("/inner")
	innerGroupPower := inner.Group("/groupPower")
	{
		innerGroupPower.GET("/infos", wrapper(group_power_r.MGetGroupPowers))
	}
	innerMic := inner.Group("/mic")
	{
		innerMic.GET("/onMicSeconds", wrapper(mic_r.MGetUserOnMicSeconds))
hujiebin's avatar
hujiebin committed
166
		innerMic.GET("/onMicSeconds/range", wrapper(mic_r.MGetUserOnMicSecondsRange))
hujiebin's avatar
hujiebin committed
167 168
	}
	r.GET("/test", wrapper(group_power_r.Test))
hujiebin's avatar
hujiebin committed
169 170
	return r
}
hujiebin's avatar
hujiebin committed
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191

// 操作日志
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())
				}
			}
		}
	}
}