添加关卡列表、关卡详情接口
This commit is contained in:
parent
6e61ffd198
commit
38a35aefed
|
@ -3,13 +3,17 @@ package com.example.catchTheLetters.controller;
|
||||||
import com.example.catchTheLetters.entity.Level;
|
import com.example.catchTheLetters.entity.Level;
|
||||||
import com.example.catchTheLetters.model.vo.RankVo;
|
import com.example.catchTheLetters.model.vo.RankVo;
|
||||||
import com.example.catchTheLetters.entity.ScoreInfo;
|
import com.example.catchTheLetters.entity.ScoreInfo;
|
||||||
|
import com.example.catchTheLetters.service.LevelService;
|
||||||
import com.example.catchTheLetters.utils.R;
|
import com.example.catchTheLetters.utils.R;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import io.swagger.annotations.ApiParam;
|
import io.swagger.annotations.ApiParam;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 关卡控制器
|
* 关卡控制器
|
||||||
*
|
*
|
||||||
|
@ -20,17 +24,21 @@ import org.springframework.web.bind.annotation.*;
|
||||||
@Api(tags = "关卡API")
|
@Api(tags = "关卡API")
|
||||||
@RequestMapping("/level")
|
@RequestMapping("/level")
|
||||||
public class LevelController {
|
public class LevelController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private LevelService levelService;
|
||||||
|
|
||||||
@ApiOperation(value = "关卡列表(只返回ID、名称和类型)")
|
@ApiOperation(value = "关卡列表(只返回ID、名称和类型)")
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
public R<Level> list() {
|
public R<List<Level>> list() {
|
||||||
return null;
|
return levelService.list();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "关卡详情")
|
@ApiOperation(value = "关卡详情")
|
||||||
@GetMapping("/detail")
|
@GetMapping("/detail")
|
||||||
@ApiParam(name = "id", value = "关卡ID")
|
@ApiParam(name = "id", value = "关卡ID")
|
||||||
public R<Level> detail(Long id) {
|
public R<Level> detail(Long id) {
|
||||||
return null;
|
return levelService.levelDetail(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "关卡创建(web前端管理员提交)")
|
@ApiOperation(value = "关卡创建(web前端管理员提交)")
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
package com.example.catchTheLetters.service;
|
package com.example.catchTheLetters.service;
|
||||||
|
|
||||||
|
import com.example.catchTheLetters.entity.Level;
|
||||||
|
import com.example.catchTheLetters.utils.R;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author 慕华
|
* @author 慕华
|
||||||
* @date 2024/4/10
|
* @date 2024/4/10
|
||||||
|
@ -7,4 +12,8 @@ package com.example.catchTheLetters.service;
|
||||||
* @description
|
* @description
|
||||||
*/
|
*/
|
||||||
public interface LevelService {
|
public interface LevelService {
|
||||||
|
|
||||||
|
R<Level> levelDetail(Long id);
|
||||||
|
|
||||||
|
R<List<Level>> list();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,17 @@
|
||||||
package com.example.catchTheLetters.service.impl;
|
package com.example.catchTheLetters.service.impl;
|
||||||
|
|
||||||
|
import com.example.catchTheLetters.entity.Level;
|
||||||
|
import com.example.catchTheLetters.service.LevelService;
|
||||||
|
import com.example.catchTheLetters.utils.R;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.data.annotation.QueryAnnotation;
|
||||||
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||||
|
import org.springframework.data.mongodb.core.query.Criteria;
|
||||||
|
import org.springframework.data.mongodb.core.query.Query;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author 慕华
|
* @author 慕华
|
||||||
* @date 2024/4/10
|
* @date 2024/4/10
|
||||||
|
@ -9,5 +19,25 @@ import org.springframework.stereotype.Service;
|
||||||
* @description
|
* @description
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class LevelServiceImpl {
|
public class LevelServiceImpl implements LevelService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private MongoTemplate mongoTemplate;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public R<Level> levelDetail(Long id) {
|
||||||
|
Level level = mongoTemplate.findOne(new Query(Criteria.where("id").is(id)), Level.class);
|
||||||
|
if (level == null){
|
||||||
|
return R.fail("查询失败,请重试");
|
||||||
|
}
|
||||||
|
return R.ok(level);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public R<List<Level>> list() {
|
||||||
|
Query query = new Query();
|
||||||
|
query.fields().include("id").include("name").include("type");
|
||||||
|
List<Level> levels = mongoTemplate.find(query, Level.class);
|
||||||
|
return R.ok(levels);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue