作者 yangfu

服务分层

... ... @@ -8,7 +8,7 @@ import (
"encoding/hex"
"gitlab.fjmaimaimai.com/mmm-go/ability/protocol"
"gitlab.fjmaimaimai.com/mmm-go/ability/services/auth"
s_auth "gitlab.fjmaimaimai.com/mmm-go/ability/services/auth"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego"
... ... @@ -18,6 +18,10 @@ import (
"github.com/astaxie/beego/validation"
)
var(
auth s_auth.IAuthService = &s_auth.AuthService{}
)
type BaseController struct {
mybeego.BaseController
}
... ...
... ... @@ -4,11 +4,15 @@ import (
"encoding/json"
"gitlab.fjmaimaimai.com/mmm-go/ability/controllers"
"gitlab.fjmaimaimai.com/mmm-go/ability/protocol"
"gitlab.fjmaimaimai.com/mmm-go/ability/services/auth"
s_auth "gitlab.fjmaimaimai.com/mmm-go/ability/services/auth"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego"
)
var(
auth s_auth.IAuthService = &s_auth.AuthService{}
)
type AuthController struct {
controllers.BaseController
}
... ...
package repository
import "gitlab.fjmaimaimai.com/mmm-go/ability/models"
type IUserRepository interface {
GetUsersByMobile(mobile string)(v *models.Users, err error)
GetUserInfoByMobile(mobile string)(v *models.UserInfo, err error)
}
func assertImplement(){
var _ IUserRepository = (*UserRepository)(nil)
}
type UserRepository struct {}
func (r *UserRepository)GetUsersByMobile(mobile string)(v *models.Users, err error) {
return models.GetUsersByMobile(mobile)
}
func (r *UserRepository)GetUserInfoByMobile(mobile string)(v *models.UserInfo, err error) {
return models.GetUserInfoByMobile(mobile)
}
\ No newline at end of file
... ...
... ... @@ -2,19 +2,45 @@ package auth
import (
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/ability/internal/repository"
"gitlab.fjmaimaimai.com/mmm-go/ability/models"
"gitlab.fjmaimaimai.com/mmm-go/ability/protocol"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"strings"
)
type IAuthService interface {
Login(request *protocol.LoginRequest)(rsp *protocol.LoginResponse,err error)
AccessToken(request *protocol.AccessTokenRequest)(rsp *protocol.AccessTokenResponse,err error)
RefreshToken(request *protocol.RefreshTokenRequest)(rsp *protocol.RefreshTokenResponse,err error)
UpdateDevice(request *protocol.UpdateDeviceRequest)(rsp *protocol.UpdateDeviceResponse,err error)
CheckToken(request *protocol.CheckTokenRequest)(rsp *protocol.CheckTokenResponse,err error)
CheckUuid(request *protocol.CheckUuidRequest)(rsp *protocol.CheckUuidResponse,err error)
SmsCode(request *protocol.SmsCodeRequest)(rsp *protocol.SmsCodeResponse,err error)
}
type AuthService struct {}
func assertImplement(){
var _ IAuthService = (*AuthService)(nil)
}
var(
//服务
//sms s_sms.ISmsService = &s_sms.SmsService{}
//仓储
UserRepository repository.IUserRepository =&repository.UserRepository{}
)
//登录
func Login(request *protocol.LoginRequest)(rsp *protocol.LoginResponse,err error){
func (s *AuthService)Login(request *protocol.LoginRequest)(rsp *protocol.LoginResponse,err error){
var (
user *models.Users
userInfo *models.UserInfo
)
user,err =models.GetUsersByMobile(request.Phone)
user,err =UserRepository.GetUsersByMobile(request.Phone)
if err!=nil{
log.Error(err)
err =common.NewError(2020,err)//账号不存在
... ... @@ -37,7 +63,7 @@ func Login(request *protocol.LoginRequest)(rsp *protocol.LoginResponse,err error
}
Success:
{
userInfo,err =models.GetUserInfoByMobile(request.Phone)
userInfo,err =UserRepository.GetUserInfoByMobile(request.Phone)
if err!=nil{
log.Error(err)
return
... ... @@ -47,17 +73,12 @@ func Login(request *protocol.LoginRequest)(rsp *protocol.LoginResponse,err error
}
return
}
//短信验证码
func SmsCode(request *protocol.SmsCodeRequest)(rsp *protocol.SmsCodeResponse,err error){
return nil,nil
}
//更新设备信息
func UpdateDevice(request *protocol.UpdateDeviceRequest)(rsp *protocol.UpdateDeviceResponse,err error){
func (s *AuthService)UpdateDevice(request *protocol.UpdateDeviceRequest)(rsp *protocol.UpdateDeviceResponse,err error){
return nil,nil
}
//获取accessToken
func AccessToken(request *protocol.AccessTokenRequest)(rsp *protocol.AccessTokenResponse,err error){
func (s *AuthService)AccessToken(request *protocol.AccessTokenRequest)(rsp *protocol.AccessTokenResponse,err error){
var (
userInfo *models.UserInfo
)
... ... @@ -78,7 +99,7 @@ func AccessToken(request *protocol.AccessTokenRequest)(rsp *protocol.AccessToken
return
}
//刷新token
func RefreshToken(request *protocol.RefreshTokenRequest)(rsp *protocol.RefreshTokenResponse,err error){
func (s *AuthService)RefreshToken(request *protocol.RefreshTokenRequest)(rsp *protocol.RefreshTokenResponse,err error){
var (
userInfo *models.UserInfo
newAccess *protocol.Access
... ... @@ -110,7 +131,7 @@ func refreshToken(request *protocol.RefreshTokenRequest)(rsp *protocol.Access,er
return nil,nil
}
//检查token有效性
func CheckToken(request *protocol.CheckTokenRequest)(rsp *protocol.CheckTokenResponse,err error){
func (s *AuthService)CheckToken(request *protocol.CheckTokenRequest)(rsp *protocol.CheckTokenResponse,err error){
var (
userInfo *models.UserInfo
)
... ... @@ -130,7 +151,7 @@ func CheckToken(request *protocol.CheckTokenRequest)(rsp *protocol.CheckTokenRes
return
}
//检查uuid 是否重复
func CheckUuid(request *protocol.CheckUuidRequest)(rsp *protocol.CheckUuidResponse,err error){
func (s *AuthService)CheckUuid(request *protocol.CheckUuidRequest)(rsp *protocol.CheckUuidResponse,err error){
var (
logUuid *models.LogUuid
)
... ... @@ -144,4 +165,8 @@ func CheckUuid(request *protocol.CheckUuidRequest)(rsp *protocol.CheckUuidRespon
models.AddLogUuid(&models.LogUuid{Uuid:request.Uuid})
rsp =&protocol.CheckUuidResponse{}
return
}
//短信验证码
func (s *AuthService)SmsCode(request *protocol.SmsCodeRequest)(rsp *protocol.SmsCodeResponse,err error){
return nil,nil
}
\ No newline at end of file
... ...
package sms
type ISmsService interface {
}
type SmsService struct {}
func assertImplement(){
var _ ISmsService = (*SmsService)(nil)
}
//发送
... ...