|
@@ -17,7 +17,7 @@ public class FamilyChallengeController {
|
|
|
private FamilyChallengeService familyChallengeService;
|
|
private FamilyChallengeService familyChallengeService;
|
|
|
|
|
|
|
|
@PostMapping("/list")
|
|
@PostMapping("/list")
|
|
|
- public Result<List<FamilyChallenge>> getList(@RequestAttribute("familyId") Long familyId) {
|
|
|
|
|
|
|
+ public Result<List<FamilyChallenge>> getList(@RequestAttribute(value = "familyId", required = false) Long familyId) {
|
|
|
if (familyId == null) {
|
|
if (familyId == null) {
|
|
|
return Result.noFamily("请先创建或加入家庭");
|
|
return Result.noFamily("请先创建或加入家庭");
|
|
|
}
|
|
}
|
|
@@ -25,7 +25,7 @@ public class FamilyChallengeController {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@PostMapping("/history")
|
|
@PostMapping("/history")
|
|
|
- public Result<List<FamilyChallenge>> getHistory(@RequestAttribute("familyId") Long familyId) {
|
|
|
|
|
|
|
+ public Result<List<FamilyChallenge>> getHistory(@RequestAttribute(value = "familyId", required = false) Long familyId) {
|
|
|
if (familyId == null) {
|
|
if (familyId == null) {
|
|
|
return Result.noFamily("请先创建或加入家庭");
|
|
return Result.noFamily("请先创建或加入家庭");
|
|
|
}
|
|
}
|
|
@@ -34,14 +34,19 @@ public class FamilyChallengeController {
|
|
|
|
|
|
|
|
@PostMapping("/progress")
|
|
@PostMapping("/progress")
|
|
|
public Result<Void> updateProgress(@RequestBody Map<String, Object> params,
|
|
public Result<Void> updateProgress(@RequestBody Map<String, Object> params,
|
|
|
|
|
+ @RequestAttribute(value = "role", required = false) String role,
|
|
|
@RequestAttribute(value = "currentMemberId", required = false) Long currentMemberId) {
|
|
@RequestAttribute(value = "currentMemberId", required = false) Long currentMemberId) {
|
|
|
|
|
+ if (!"child".equals(role)) {
|
|
|
|
|
+ return Result.error("仅孩子可打卡");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (currentMemberId == null) {
|
|
|
|
|
+ return Result.error("未识别当前成员");
|
|
|
|
|
+ }
|
|
|
Long challengeId = params.get("challengeId") != null
|
|
Long challengeId = params.get("challengeId") != null
|
|
|
? Long.valueOf(params.get("challengeId").toString()) : null;
|
|
? Long.valueOf(params.get("challengeId").toString()) : null;
|
|
|
- Long memberId = params.get("memberId") != null
|
|
|
|
|
- ? Long.valueOf(params.get("memberId").toString()) : currentMemberId;
|
|
|
|
|
int delta = params.get("delta") != null
|
|
int delta = params.get("delta") != null
|
|
|
? Integer.parseInt(params.get("delta").toString()) : 0;
|
|
? Integer.parseInt(params.get("delta").toString()) : 0;
|
|
|
- return familyChallengeService.updateProgress(challengeId, memberId, delta);
|
|
|
|
|
|
|
+ return familyChallengeService.updateProgress(challengeId, currentMemberId, delta);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@PostMapping("/templates")
|
|
@PostMapping("/templates")
|
|
@@ -51,23 +56,35 @@ public class FamilyChallengeController {
|
|
|
|
|
|
|
|
@PostMapping("/create")
|
|
@PostMapping("/create")
|
|
|
public Result<Long> createChallenge(@RequestBody Map<String, Object> params,
|
|
public Result<Long> createChallenge(@RequestBody Map<String, Object> params,
|
|
|
- @RequestAttribute("familyId") Long familyId,
|
|
|
|
|
|
|
+ @RequestAttribute(value = "role", required = false) String role,
|
|
|
|
|
+ @RequestAttribute(value = "familyId", required = false) Long familyId,
|
|
|
@RequestAttribute("userId") Long userId) {
|
|
@RequestAttribute("userId") Long userId) {
|
|
|
|
|
+ if (!"parent".equals(role)) {
|
|
|
|
|
+ return Result.error("仅家长可创建挑战");
|
|
|
|
|
+ }
|
|
|
return familyChallengeService.createChallenge(familyId, userId, params);
|
|
return familyChallengeService.createChallenge(familyId, userId, params);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@PostMapping("/update/{id}")
|
|
@PostMapping("/update/{id}")
|
|
|
public Result<Void> updateChallenge(@PathVariable("id") Long challengeId,
|
|
public Result<Void> updateChallenge(@PathVariable("id") Long challengeId,
|
|
|
@RequestBody Map<String, Object> params,
|
|
@RequestBody Map<String, Object> params,
|
|
|
- @RequestAttribute("familyId") Long familyId,
|
|
|
|
|
|
|
+ @RequestAttribute(value = "role", required = false) String role,
|
|
|
|
|
+ @RequestAttribute(value = "familyId", required = false) Long familyId,
|
|
|
@RequestAttribute("userId") Long userId) {
|
|
@RequestAttribute("userId") Long userId) {
|
|
|
|
|
+ if (!"parent".equals(role)) {
|
|
|
|
|
+ return Result.error("仅家长可修改挑战");
|
|
|
|
|
+ }
|
|
|
return familyChallengeService.updateChallenge(challengeId, userId, familyId, params);
|
|
return familyChallengeService.updateChallenge(challengeId, userId, familyId, params);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@PostMapping("/delete/{id}")
|
|
@PostMapping("/delete/{id}")
|
|
|
public Result<Void> deleteChallenge(@PathVariable("id") Long challengeId,
|
|
public Result<Void> deleteChallenge(@PathVariable("id") Long challengeId,
|
|
|
- @RequestAttribute("familyId") Long familyId,
|
|
|
|
|
|
|
+ @RequestAttribute(value = "role", required = false) String role,
|
|
|
|
|
+ @RequestAttribute(value = "familyId", required = false) Long familyId,
|
|
|
@RequestAttribute("userId") Long userId) {
|
|
@RequestAttribute("userId") Long userId) {
|
|
|
|
|
+ if (!"parent".equals(role)) {
|
|
|
|
|
+ return Result.error("仅家长可删除挑战");
|
|
|
|
|
+ }
|
|
|
return familyChallengeService.deleteChallenge(challengeId, userId, familyId);
|
|
return familyChallengeService.deleteChallenge(challengeId, userId, familyId);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|