添加关卡结算接口
This commit is contained in:
parent
baef746aff
commit
312f9c4ad8
|
@ -68,7 +68,7 @@ public class LevelController {
|
|||
|
||||
@ApiOperation(value = "关卡结算(游戏结束时提交,一定要鉴别token)")
|
||||
@PostMapping("/settle")
|
||||
public R settle(@RequestBody ScoreInfo scoreInfo) {
|
||||
return null;
|
||||
public R<ScoreInfo> settle(@RequestBody ScoreInfo scoreInfo, @RequestHeader("token")String token) {
|
||||
return levelService.settle(scoreInfo, token);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.example.catchTheLetters.service;
|
||||
|
||||
import com.example.catchTheLetters.entity.Level;
|
||||
import com.example.catchTheLetters.entity.ScoreInfo;
|
||||
import com.example.catchTheLetters.utils.R;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -16,4 +17,6 @@ public interface LevelService {
|
|||
R<Level> levelDetail(Long id);
|
||||
|
||||
R<List<Level>> list();
|
||||
|
||||
R<ScoreInfo> settle(ScoreInfo scoreInfo, String token);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package com.example.catchTheLetters.service.impl;
|
||||
|
||||
import com.example.catchTheLetters.entity.Level;
|
||||
import com.example.catchTheLetters.entity.ScoreInfo;
|
||||
import com.example.catchTheLetters.service.LevelService;
|
||||
import com.example.catchTheLetters.utils.JwtUtil;
|
||||
import com.example.catchTheLetters.utils.R;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.data.annotation.QueryAnnotation;
|
||||
|
@ -40,4 +42,21 @@ public class LevelServiceImpl implements LevelService {
|
|||
List<Level> levels = mongoTemplate.find(query, Level.class);
|
||||
return R.ok(levels);
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<ScoreInfo> settle(ScoreInfo scoreInfo, String token) {
|
||||
var map = JwtUtil.getPayload(token);
|
||||
String id = null;
|
||||
if (map != null) {
|
||||
id = map.get("id").asString().replaceAll("\"", "");
|
||||
}
|
||||
if (id == null){
|
||||
return R.fail("token解析失败");
|
||||
}
|
||||
if (id.equals(scoreInfo.getUserId().toString())){
|
||||
ScoreInfo insert = mongoTemplate.insert(scoreInfo);
|
||||
return R.ok(insert);
|
||||
}
|
||||
return R.fail("添加失败,请重试");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue