Compare commits
4 Commits
6c2cb2b197
...
289fe1c009
Author | SHA1 | Date |
---|---|---|
石皮幼鸟 | 289fe1c009 | |
石皮幼鸟 | baa889f73b | |
石皮幼鸟 | 4af5dae371 | |
Ch3nGO | a7442babbe |
|
@ -24,7 +24,6 @@ import java.util.List;
|
|||
@Api(tags = "关卡API")
|
||||
@RequestMapping("/level")
|
||||
public class LevelController {
|
||||
|
||||
@Resource
|
||||
private LevelService levelService;
|
||||
|
||||
|
@ -49,14 +48,15 @@ public class LevelController {
|
|||
|
||||
@ApiOperation(value = "关卡修改(web前端管理员提交)")
|
||||
@PostMapping("/update")
|
||||
public R update(@RequestBody Level level) {
|
||||
return null;
|
||||
public R update(@RequestBody Level level)
|
||||
{
|
||||
return levelService.update(level) ? R.ok() : R.fail();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "关卡删除(web前端管理员提交)")
|
||||
@PostMapping("/delete")
|
||||
public R delete(String id) {
|
||||
return null;
|
||||
return levelService.delete(id) ? R.ok() : R.fail();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取某个关卡排行榜数据")
|
||||
|
|
|
@ -55,4 +55,19 @@ public interface LevelService {
|
|||
*/
|
||||
boolean levelCreate(Level level);
|
||||
|
||||
|
||||
/**
|
||||
* 删除关卡
|
||||
* @param id 关卡id
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean delete(String id);
|
||||
|
||||
/**
|
||||
* 更新关卡
|
||||
* @param level 关卡
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean update(Level level);
|
||||
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import jakarta.annotation.Resource;
|
|||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import org.springframework.data.mongodb.core.query.Criteria;
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
import com.mongodb.client.result.DeleteResult;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -29,7 +30,7 @@ public class LevelServiceImpl implements LevelService {
|
|||
@Override
|
||||
public R<Level> levelDetail(String id) {
|
||||
Level level = mongoTemplate.findOne(new Query(Criteria.where("id").is(id)), Level.class);
|
||||
if (level == null){
|
||||
if (level == null) {
|
||||
return R.fail("查询失败,请重试");
|
||||
}
|
||||
return R.ok(level);
|
||||
|
@ -50,10 +51,10 @@ public class LevelServiceImpl implements LevelService {
|
|||
if (map != null) {
|
||||
id = map.get("id").asString().replaceAll("\"", "");
|
||||
}
|
||||
if (id == null){
|
||||
if (id == null) {
|
||||
return R.fail("token解析失败");
|
||||
}
|
||||
if (id.equals(scoreInfo.getUserId().toString())){
|
||||
if (id.equals(scoreInfo.getUserId())) {
|
||||
ScoreInfo insert = mongoTemplate.insert(scoreInfo);
|
||||
return R.ok(insert);
|
||||
}
|
||||
|
@ -90,4 +91,18 @@ public class LevelServiceImpl implements LevelService {
|
|||
var insert = mongoTemplate.insert(level);
|
||||
return insert.getId() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(String id) {
|
||||
Level level = new Level();
|
||||
level.setId(id);
|
||||
DeleteResult deleteRequest = mongoTemplate.remove(level);
|
||||
return deleteRequest.getDeletedCount() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(Level level) {
|
||||
var save = mongoTemplate.save(level);
|
||||
return save.getId() != null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue