mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-09 08:30:55 +08:00
feat: relocate remaining dtos
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
package com.openisle.controller;
|
||||
|
||||
import com.openisle.dto.MilkTeaInfoDto;
|
||||
import com.openisle.dto.MilkTeaRedeemRequest;
|
||||
import com.openisle.model.Activity;
|
||||
import com.openisle.model.ActivityType;
|
||||
import com.openisle.model.User;
|
||||
import com.openisle.service.ActivityService;
|
||||
import com.openisle.service.UserService;
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -25,20 +26,20 @@ public class ActivityController {
|
||||
}
|
||||
|
||||
@GetMapping("/milk-tea")
|
||||
public MilkTeaInfo milkTea() {
|
||||
public MilkTeaInfoDto milkTea() {
|
||||
Activity a = activityService.getByType(ActivityType.MILK_TEA);
|
||||
long count = activityService.countParticipants(a);
|
||||
if (!a.isEnded() && count >= 50) {
|
||||
activityService.end(a);
|
||||
}
|
||||
MilkTeaInfo info = new MilkTeaInfo();
|
||||
MilkTeaInfoDto info = new MilkTeaInfoDto();
|
||||
info.setRedeemCount(count);
|
||||
info.setEnded(a.isEnded());
|
||||
return info;
|
||||
}
|
||||
|
||||
@PostMapping("/milk-tea/redeem")
|
||||
public java.util.Map<String, String> redeemMilkTea(@RequestBody RedeemRequest req, Authentication auth) {
|
||||
public java.util.Map<String, String> redeemMilkTea(@RequestBody MilkTeaRedeemRequest req, Authentication auth) {
|
||||
User user = userService.findByIdentifier(auth.getName()).orElseThrow();
|
||||
Activity a = activityService.getByType(ActivityType.MILK_TEA);
|
||||
boolean first = activityService.redeem(a, user, req.getContact());
|
||||
@@ -47,15 +48,4 @@ public class ActivityController {
|
||||
}
|
||||
return java.util.Map.of("message", "updated");
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class MilkTeaInfo {
|
||||
private long redeemCount;
|
||||
private boolean ended;
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class RedeemRequest {
|
||||
private String contact;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user