Merge pull request #91 from TeamBNBN/be/Registration
feat: Registration 수강신청 승인/거절 관리자 확인 추가
This commit is contained in:
commit
6f907e4ec5
@ -1,6 +1,5 @@
|
|||||||
package com.edufocus.edufocus.registration.controller;
|
package com.edufocus.edufocus.registration.controller;
|
||||||
|
|
||||||
import com.edufocus.edufocus.registration.entity.Registration;
|
|
||||||
import com.edufocus.edufocus.registration.service.RegistrationService;
|
import com.edufocus.edufocus.registration.service.RegistrationService;
|
||||||
import com.edufocus.edufocus.user.util.JWTUtil;
|
import com.edufocus.edufocus.user.util.JWTUtil;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@ -9,6 +8,8 @@ import org.springframework.http.HttpStatus;
|
|||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/registration")
|
@RequestMapping("/registration")
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@ -20,26 +21,42 @@ public class RegistrationController {
|
|||||||
private final JWTUtil jwtUtil;
|
private final JWTUtil jwtUtil;
|
||||||
|
|
||||||
@PostMapping
|
@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 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}")
|
@PutMapping("/{registrationId}")
|
||||||
public ResponseEntity<?> acceptRigistration(@PathVariable long registrationId) {
|
public ResponseEntity<?> acceptRigistration(@RequestHeader("Authorization") String accessToken, @PathVariable long registrationId) {
|
||||||
registrationServiceImpl.acceptRegistration(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);
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/{registrationId}")
|
@DeleteMapping("/{registrationId}")
|
||||||
public ResponseEntity<?> deleteRigistration(@PathVariable long registrationId) {
|
public ResponseEntity<?> deleteRigistration(@RequestHeader("Authorization") String accessToken, @PathVariable long registrationId) {
|
||||||
registrationServiceImpl.deleteRegistration(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
|
@Service
|
||||||
public interface RegistrationService {
|
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 deleteRegistration(long userId, long registrationId);
|
||||||
|
|
||||||
boolean isAcceptedRegistration(long registrationId);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,11 @@ public class RegistrationServiceImpl implements RegistrationService {
|
|||||||
private final LectureRepository lectureRepository;
|
private final LectureRepository lectureRepository;
|
||||||
|
|
||||||
@Override
|
@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()
|
Registration registration = new Registration().builder()
|
||||||
.user(userRepository.getReferenceById(userId))
|
.user(userRepository.getReferenceById(userId))
|
||||||
.lecture(lectureRepository.getReferenceById(lectureId))
|
.lecture(lectureRepository.getReferenceById(lectureId))
|
||||||
@ -29,25 +33,33 @@ public class RegistrationServiceImpl implements RegistrationService {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
registrationRepository.save(registration);
|
registrationRepository.save(registration);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void acceptRegistration(long registrationId) {
|
public boolean acceptRegistration(long userId, long registrationId) {
|
||||||
Registration registration = registrationRepository.findById(registrationId).get();
|
Registration registration = registrationRepository.findById(registrationId).get();
|
||||||
|
|
||||||
|
if (registration.getLecture().getUser().getId() != userId) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
registration.setStatus(RegistrationStatus.valueOf("ACCEPTED"));
|
registration.setStatus(RegistrationStatus.valueOf("ACCEPTED"));
|
||||||
registrationRepository.save(registration);
|
registrationRepository.save(registration);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteRegistration(long registrationId) {
|
public boolean deleteRegistration(long userId, long registrationId) {
|
||||||
registrationRepository.deleteById(registrationId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAcceptedRegistration(long registrationId) {
|
|
||||||
Registration registration = registrationRepository.findById(registrationId).get();
|
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