Skip to content

Commit bbf6a58

Browse files
feat: add check-in activity, but need to fix
1 parent 2526952 commit bbf6a58

File tree

5 files changed

+59
-2
lines changed

5 files changed

+59
-2
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.example.activity.controller;
2+
3+
import com.example.activity.service.UserService;
4+
import com.example.common.core.response.ResponseResult;
5+
import lombok.RequiredArgsConstructor;
6+
import org.springframework.web.bind.annotation.PostMapping;
7+
import org.springframework.web.bind.annotation.RequestMapping;
8+
import org.springframework.web.bind.annotation.RestController;
9+
10+
@RestController
11+
@RequiredArgsConstructor
12+
@RequestMapping("/user")
13+
public class UserController {
14+
15+
private final UserService userService;
16+
17+
@PostMapping("/signIn")
18+
public ResponseResult<?> signIn(){
19+
return userService.signIn();
20+
}
21+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.example.activity.service;
2+
3+
import com.example.common.core.response.ResponseResult;
4+
5+
public interface UserService {
6+
ResponseResult<?> signIn();
7+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.example.activity.service.impl;
2+
3+
import com.example.activity.service.UserService;
4+
import com.example.common.core.constant.RedisKeyConstant;
5+
import com.example.common.core.response.ResponseResult;
6+
import lombok.RequiredArgsConstructor;
7+
import org.springframework.data.redis.core.StringRedisTemplate;
8+
import org.springframework.stereotype.Service;
9+
10+
import java.time.LocalDateTime;
11+
import java.time.format.DateTimeFormatter;
12+
13+
@Service
14+
@RequiredArgsConstructor
15+
public class UserServiceImpl implements UserService {
16+
private final StringRedisTemplate stringRedisTemplate;
17+
@Override
18+
public ResponseResult signIn() {
19+
LocalDateTime now = LocalDateTime.now();
20+
String keySuffix = now.format(DateTimeFormatter.ofPattern("yyyyMM:"));
21+
String key = RedisKeyConstant.user.USER_SIGN_IN + keySuffix + "Username:";
22+
int dayOfMonth = now.getDayOfMonth();
23+
stringRedisTemplate.opsForValue().setBit(key, dayOfMonth -1, true);
24+
return ResponseResult.success();
25+
}
26+
}

common/common-core/src/main/java/com/example/common/core/constant/RedisKeyConstant.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package com.example.common.core.constant;
22

33
public interface RedisKeyConstant {
4+
interface user {
5+
String USER_SIGN_IN = "user:sign_in:";
6+
}
47

58
interface captcha {
69
String CAPTCHA_UUID = "captcha:uuid:";

common/common-core/src/main/java/com/example/common/core/handler/GlobalExceptionHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
@RestControllerAdvice
1616
public class GlobalExceptionHandler {
1717

18-
// @ResponseStatus(HttpStatus.BAD_REQUEST)
18+
@ResponseStatus(HttpStatus.BAD_REQUEST)
1919
@ExceptionHandler(value = CustomException.class)
2020
public ResponseResult<?> handle(CustomException e) {
2121
if (e.getErrorCode() != null) {
@@ -26,7 +26,7 @@ public ResponseResult<?> handle(CustomException e) {
2626
return ResponseResult.failed(e.getMessage());
2727
}
2828

29-
// @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
29+
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
3030
@ExceptionHandler(value = Throwable.class)
3131
public ResponseResult<?> unknownException(Throwable e){
3232
log.error(ThrowableUtil.getStackTrace(e));

0 commit comments

Comments
 (0)