Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
beyond-clouds
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
4
Issues
4
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
段启岩
beyond-clouds
Commits
db2d6b8e
Commit
db2d6b8e
authored
Feb 04, 2020
by
段启岩
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复重复关注的问题
parent
d741e04b
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
71 additions
and
15 deletions
+71
-15
src/main/java/cn/meteor/beyondclouds/core/constant/RegexPatterns.java
+12
-0
src/main/java/cn/meteor/beyondclouds/modules/blog/service/impl/BlogServiceImpl.java
+1
-1
src/main/java/cn/meteor/beyondclouds/modules/sms/api/SmsApi.java
+5
-2
src/main/java/cn/meteor/beyondclouds/modules/sms/enums/SmsErrorCode.java
+2
-1
src/main/java/cn/meteor/beyondclouds/modules/user/api/AuthenticationApi.java
+6
-3
src/main/java/cn/meteor/beyondclouds/modules/user/api/UserApi.java
+7
-3
src/main/java/cn/meteor/beyondclouds/modules/user/enums/UserErrorCode.java
+5
-1
src/main/java/cn/meteor/beyondclouds/modules/user/form/SmsAuthFrom.java
+9
-0
src/main/java/cn/meteor/beyondclouds/modules/user/service/IUserFollowService.java
+2
-1
src/main/java/cn/meteor/beyondclouds/modules/user/service/impl/UserFollowServiceImpl.java
+22
-3
No files found.
src/main/java/cn/meteor/beyondclouds/core/constant/RegexPatterns.java
0 → 100644
View file @
db2d6b8e
package
cn
.
meteor
.
beyondclouds
.
core
.
constant
;
/**
* 正则表达式
* @author meteor
*/
public
class
RegexPatterns
{
/**
* 手机号
*/
public
static
final
String
MOBILE
=
"^[1](([3|5|8][\\d])|([4][4,5,6,7,8,9])|([6][2,5,6,7])|([7][^9])|([9][1,8,9]))[\\d]{8}$"
;
}
src/main/java/cn/meteor/beyondclouds/modules/blog/service/impl/BlogServiceImpl.java
View file @
db2d6b8e
...
...
@@ -244,7 +244,7 @@ public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements IB
if
(!
CollectionUtils
.
isEmpty
(
topicIds
))
{
blog
.
setTopics
(
topicService
.
listByIds
(
topicIds
));
}
else
{
blog
.
setT
ag
s
(
List
.
of
());
blog
.
setT
opic
s
(
List
.
of
());
}
//装配并返回查询到的数据
...
...
src/main/java/cn/meteor/beyondclouds/modules/sms/api/SmsApi.java
View file @
db2d6b8e
package
cn
.
meteor
.
beyondclouds
.
modules
.
sms
.
api
;
import
cn.meteor.beyondclouds.common.exception.SmsException
;
import
cn.meteor.beyondclouds.core.annotation.Anonymous
;
import
cn.meteor.beyondclouds.core.api.Response
;
import
cn.meteor.beyondclouds.core.exception.ServiceException
;
import
cn.meteor.beyondclouds.core.constant.RegexPatterns
;
import
cn.meteor.beyondclouds.modules.sms.enums.SmsErrorCode
;
import
cn.meteor.beyondclouds.modules.sms.exception.SmsServiceException
;
import
cn.meteor.beyondclouds.modules.sms.service.ISmsService
;
import
cn.meteor.beyondclouds.util.VerifyCodeUtils
;
...
...
@@ -36,6 +36,9 @@ public class SmsApi {
@ApiOperation
(
"发送验证码"
)
@GetMapping
(
"/verifyCode"
)
public
Response
sendVerify
(
@RequestParam
(
"mobile"
)
String
mobile
)
{
if
(!
mobile
.
matches
(
RegexPatterns
.
MOBILE
))
{
return
Response
.
error
(
SmsErrorCode
.
INVALID_MOBILE
);
}
try
{
smsService
.
sendVerifyCode
(
mobile
,
VerifyCodeUtils
.
randomVerifyCode
());
return
Response
.
success
();
...
...
src/main/java/cn/meteor/beyondclouds/modules/sms/enums/SmsErrorCode.java
View file @
db2d6b8e
...
...
@@ -9,7 +9,8 @@ import cn.meteor.beyondclouds.core.IErrorCode;
public
enum
SmsErrorCode
implements
IErrorCode
{
SERVER_ERROR
(
2001
,
"发送短信时阿里的服务器出现了异常"
),
CLIENT_ERROR
(
2002
,
"发送短信时自己的服务器出现了异常"
),
SEND_FAILURE
(
2003
,
"短信发送失败"
);
SEND_FAILURE
(
2004
,
"短信发送失败"
),
INVALID_MOBILE
(
2005
,
"手机号格式错误"
);
private
long
code
;
private
String
msg
;
...
...
src/main/java/cn/meteor/beyondclouds/modules/user/api/AuthenticationApi.java
View file @
db2d6b8e
package
cn
.
meteor
.
beyondclouds
.
modules
.
user
.
api
;
import
cn.meteor.beyondclouds.core.annotation.Anonymous
;
import
cn.meteor.beyondclouds.core.annotation.CurrentSubject
;
import
cn.meteor.beyondclouds.core.api.Response
;
import
cn.meteor.beyondclouds.core.bean.Subject
;
import
cn.meteor.beyondclouds.modules.user.bean.AuthenticationResult
;
import
cn.meteor.beyondclouds.modules.user.exception.AuthenticationServiceException
;
import
cn.meteor.beyondclouds.modules.user.exception.UserServiceException
;
...
...
@@ -14,6 +12,7 @@ import io.swagger.annotations.Api;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiParam
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.validation.BindingResult
;
import
org.springframework.web.bind.annotation.*
;
import
javax.validation.Valid
;
...
...
@@ -50,7 +49,11 @@ public class AuthenticationApi {
@Anonymous
@ApiOperation
(
value
=
"短信验证登陆"
)
@PostMapping
(
"/sms"
)
public
Response
<
AuthenticationResult
>
smsAuth
(
@RequestBody
@Valid
@ApiParam
(
"短信认证表单"
)
SmsAuthFrom
smsAuthFrom
)
throws
UserServiceException
{
public
Response
smsAuth
(
@RequestBody
@Valid
@ApiParam
(
"短信认证表单"
)
SmsAuthFrom
smsAuthFrom
,
BindingResult
bindingResult
)
throws
UserServiceException
{
if
(
bindingResult
.
hasErrors
())
{
return
Response
.
fieldError
(
bindingResult
.
getFieldError
());
}
AuthenticationResult
authenticationResult
=
null
;
try
{
authenticationResult
=
authenticationService
.
smsAuthentication
(
smsAuthFrom
.
getMobile
(),
smsAuthFrom
.
getVerifyCode
());
...
...
src/main/java/cn/meteor/beyondclouds/modules/user/api/UserApi.java
View file @
db2d6b8e
...
...
@@ -148,9 +148,13 @@ public class UserApi {
@PostMapping
(
"/user/{userId}/follower"
)
public
Response
follower
(
@PathVariable
(
name
=
"userId"
)
String
userId
,
@CurrentSubject
Subject
subject
){
userFollowService
.
follow
(
userId
,
(
String
)
subject
.
getId
());
return
Response
.
success
();
try
{
userFollowService
.
follow
(
userId
,
(
String
)
subject
.
getId
());
return
Response
.
success
();
}
catch
(
UserServiceException
e
)
{
e
.
printStackTrace
();
return
Response
.
error
(
e
);
}
}
@ApiOperation
((
"取消关注"
))
...
...
src/main/java/cn/meteor/beyondclouds/modules/user/enums/UserErrorCode.java
View file @
db2d6b8e
...
...
@@ -12,7 +12,11 @@ public enum UserErrorCode implements IErrorCode {
* 手机号已经被注册//
*/
MOBILE_REGISTERED
(
1001
,
"该手机号已被注册"
),
REG_VERIFY_CODE_ERROR
(
1002
,
"验证码错误"
);
REG_VERIFY_CODE_ERROR
(
1002
,
"验证码错误"
),
CAN_NOT_FOLLOW_SELF
(
1003
,
"不能关注自己"
),
FOLLOWED_USER_NOT_EXISTS
(
1004
,
"被关注用户不存在"
),
FOLLOWER_USER_NOT_EXISTS
(
1005
,
"关注者不存在"
),
ALREADY_FOLLOWED
(
1006
,
"已关注过该用户"
);
UserErrorCode
(
long
code
,
String
msg
)
{
this
.
code
=
code
;
...
...
src/main/java/cn/meteor/beyondclouds/modules/user/form/SmsAuthFrom.java
View file @
db2d6b8e
package
cn
.
meteor
.
beyondclouds
.
modules
.
user
.
form
;
import
cn.meteor.beyondclouds.core.constant.RegexPatterns
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
javax.validation.constraints.NotBlank
;
import
javax.validation.constraints.NotNull
;
import
javax.validation.constraints.Pattern
;
/**
* @program: beyond-clouds
...
...
@@ -17,9 +22,13 @@ import lombok.Data;
public
class
SmsAuthFrom
{
@ApiModelProperty
(
"手机号"
)
@NotNull
(
message
=
"手机号不能为空"
)
@Pattern
(
regexp
=
RegexPatterns
.
MOBILE
,
message
=
"手机号格式不正确"
)
private
String
mobile
;
@ApiModelProperty
(
"验证码"
)
@NotBlank
(
message
=
"验证码不能为空"
)
@NotBlank
private
String
verifyCode
;
}
src/main/java/cn/meteor/beyondclouds/modules/user/service/IUserFollowService.java
View file @
db2d6b8e
package
cn
.
meteor
.
beyondclouds
.
modules
.
user
.
service
;
import
cn.meteor.beyondclouds.modules.user.entity.UserFollow
;
import
cn.meteor.beyondclouds.modules.user.exception.UserServiceException
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.service.IService
;
...
...
@@ -17,7 +18,7 @@ public interface IUserFollowService extends IService<UserFollow> {
* @param followedId 关注者的ID
* @param followerId 被关注者的ID
*/
void
follow
(
String
followedId
,
String
followerId
);
void
follow
(
String
followedId
,
String
followerId
)
throws
UserServiceException
;
/**
...
...
src/main/java/cn/meteor/beyondclouds/modules/user/service/impl/UserFollowServiceImpl.java
View file @
db2d6b8e
...
...
@@ -2,6 +2,8 @@ package cn.meteor.beyondclouds.modules.user.service.impl;
import
cn.meteor.beyondclouds.modules.user.entity.User
;
import
cn.meteor.beyondclouds.modules.user.entity.UserFollow
;
import
cn.meteor.beyondclouds.modules.user.enums.UserErrorCode
;
import
cn.meteor.beyondclouds.modules.user.exception.UserServiceException
;
import
cn.meteor.beyondclouds.modules.user.mapper.IUserFollowMapper
;
import
cn.meteor.beyondclouds.modules.user.service.IUserFollowService
;
import
cn.meteor.beyondclouds.modules.user.service.IUserService
;
...
...
@@ -34,19 +36,36 @@ public class UserFollowServiceImpl extends ServiceImpl<IUserFollowMapper, UserFo
* @param followerId 关注者的userId
*/
@Override
public
void
follow
(
String
followedId
,
String
followerId
)
{
public
void
follow
(
String
followedId
,
String
followerId
)
throws
UserServiceException
{
// 自己不能关注自己
if
(
followedId
.
equals
(
followerId
))
{
throw
new
UserServiceException
(
UserErrorCode
.
CAN_NOT_FOLLOW_SELF
);
}
UserFollow
userFollow
=
new
UserFollow
();
userFollow
.
setFollowedId
(
followedId
);
userFollow
.
setFollowerId
(
followerId
);
QueryWrapper
<
UserFollow
>
userFollowQueryWrapper
=
new
QueryWrapper
<>(
userFollow
);
if
(
null
!=
getOne
(
userFollowQueryWrapper
))
{
throw
new
UserServiceException
(
UserErrorCode
.
ALREADY_FOLLOWED
);
}
//1.查询被关注用户的基本信息
User
followedUser
=
userService
.
getById
(
followedId
);
userFollow
.
setFollowedId
(
followedId
);
if
(
null
==
followedUser
)
{
throw
new
UserServiceException
(
UserErrorCode
.
FOLLOWED_USER_NOT_EXISTS
);
}
userFollow
.
setFollowedNick
(
followedUser
.
getNickName
());
userFollow
.
setFollowedAvatar
(
followedUser
.
getUserAvatar
());
//2.查询我的基本信息
User
followerUser
=
userService
.
getById
(
followerId
);
userFollow
.
setFollowerId
(
followerId
);
if
(
null
==
followedUser
)
{
throw
new
UserServiceException
(
UserErrorCode
.
FOLLOWER_USER_NOT_EXISTS
);
}
userFollow
.
setFollowerNick
(
followerUser
.
getNickName
());
userFollow
.
setFollowerAvatar
(
followerUser
.
getUserAvatar
());
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment