feat: Registration 수강신청 승인/거절 관리자 확인 추가
This commit is contained in:
parent
1b4b4d9274
commit
792a32711c
@ -1,6 +1,5 @@
|
||||
package com.edufocus.edufocus.registration.controller;
|
||||
|
||||
import com.edufocus.edufocus.registration.entity.Registration;
|
||||
import com.edufocus.edufocus.registration.service.RegistrationService;
|
||||
import com.edufocus.edufocus.user.util.JWTUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -9,6 +8,8 @@ import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/registration")
|
||||
@Slf4j
|
||||
@ -20,26 +21,42 @@ public class RegistrationController {
|
||||
private final JWTUtil jwtUtil;
|
||||
|
||||
@PostMapping
|
||||
public ResponseEntity<?> register(@RequestHeader("Authorization") String accessToken, @RequestBody long lectureId) {
|
||||
public ResponseEntity<?> register(@RequestHeader("Authorization") String accessToken, @RequestBody Map<String, Long> map) {
|
||||
Long userId = Long.parseLong(jwtUtil.getUserId(accessToken));
|
||||
Long lectureId = map.get("lectureId");
|
||||
|
||||
registrationServiceImpl.createRegistration(userId, lectureId);
|
||||
if (!registrationServiceImpl.createRegistration(userId, lectureId)) {
|
||||
String msg = new String("Duplicated Registration");
|
||||
return new ResponseEntity<>(msg, HttpStatus.CONFLICT);
|
||||
}
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
String msg = new String("registration successful");
|
||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@PutMapping("/{registrationId}")
|
||||
public ResponseEntity<?> acceptRigistration(@PathVariable long registrationId) {
|
||||
registrationServiceImpl.acceptRegistration(registrationId);
|
||||
public ResponseEntity<?> acceptRigistration(@RequestHeader("Authorization") String accessToken, @PathVariable long registrationId) {
|
||||
Long userId = Long.parseLong(jwtUtil.getUserId(accessToken));
|
||||
|
||||
if (!registrationServiceImpl.acceptRegistration(userId, registrationId)) {
|
||||
String msg = new String("Not Acceptable");
|
||||
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
String msg = new String("registration accepted");
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{registrationId}")
|
||||
public ResponseEntity<?> deleteRigistration(@PathVariable long registrationId) {
|
||||
registrationServiceImpl.deleteRegistration(registrationId);
|
||||
public ResponseEntity<?> deleteRigistration(@RequestHeader("Authorization") String accessToken, @PathVariable long registrationId) {
|
||||
Long userId = Long.parseLong(jwtUtil.getUserId(accessToken));
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
if (!registrationServiceImpl.deleteRegistration(userId, registrationId)) {
|
||||
String msg = new String("Not Acceptable");
|
||||
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,12 +6,10 @@ import org.springframework.stereotype.Service;
|
||||
@Service
|
||||
public interface RegistrationService {
|
||||
|
||||
void createRegistration(long userId, long registrationId);
|
||||
boolean createRegistration(long userId, long registrationId);
|
||||
|
||||
void acceptRegistration(long RegistrationId);
|
||||
boolean acceptRegistration(long userId, long RegistrationId);
|
||||
|
||||
void deleteRegistration(long registrationId);
|
||||
|
||||
boolean isAcceptedRegistration(long registrationId);
|
||||
boolean deleteRegistration(long userId, long registrationId);
|
||||
|
||||
}
|
||||
|
@ -21,7 +21,11 @@ public class RegistrationServiceImpl implements RegistrationService {
|
||||
private final LectureRepository lectureRepository;
|
||||
|
||||
@Override
|
||||
public void createRegistration(long userId, long lectureId) {
|
||||
public boolean createRegistration(long userId, long lectureId) {
|
||||
if (registrationRepository.findByUserIdAndLectureId(userId, lectureId) != null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Registration registration = new Registration().builder()
|
||||
.user(userRepository.getReferenceById(userId))
|
||||
.lecture(lectureRepository.getReferenceById(lectureId))
|
||||
@ -29,25 +33,33 @@ public class RegistrationServiceImpl implements RegistrationService {
|
||||
.build();
|
||||
|
||||
registrationRepository.save(registration);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void acceptRegistration(long registrationId) {
|
||||
public boolean acceptRegistration(long userId, long registrationId) {
|
||||
Registration registration = registrationRepository.findById(registrationId).get();
|
||||
|
||||
if (registration.getLecture().getUser().getId() != userId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
registration.setStatus(RegistrationStatus.valueOf("ACCEPTED"));
|
||||
registrationRepository.save(registration);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteRegistration(long registrationId) {
|
||||
registrationRepository.deleteById(registrationId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAcceptedRegistration(long registrationId) {
|
||||
public boolean deleteRegistration(long userId, long registrationId) {
|
||||
Registration registration = registrationRepository.findById(registrationId).get();
|
||||
|
||||
return registration.getStatus().equals("ACCEPTED");
|
||||
if (registration.getLecture().getUser().getId() != userId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
registrationRepository.deleteById(registrationId);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user