From 92a21b61c1f9170a4950bdbad23b5e1f0a17d6a9 Mon Sep 17 00:00:00 2001 From: kgc9007 Date: Tue, 16 Jul 2024 17:48:27 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20Registration=20Registration=20Entity,?= =?UTF-8?q?=20Repository,=20Service,=20Controller=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edufocus/lecture/entity/Lecture.java | 2 + .../controller/RegistrationController.java | 42 +++++++++++++++++ .../registration/entity/Registration.java | 28 +++++++++++ .../entity/RegistrationStatus.java | 5 ++ .../repository/RegistrationRepository.java | 11 +++++ .../service/RegistrationService.java | 17 +++++++ .../service/RegistrationServiceImpl.java | 46 +++++++++++++++++++ 7 files changed, 151 insertions(+) create mode 100644 backend/src/main/java/com/edufocus/edufocus/registration/controller/RegistrationController.java create mode 100644 backend/src/main/java/com/edufocus/edufocus/registration/entity/Registration.java create mode 100644 backend/src/main/java/com/edufocus/edufocus/registration/entity/RegistrationStatus.java create mode 100644 backend/src/main/java/com/edufocus/edufocus/registration/repository/RegistrationRepository.java create mode 100644 backend/src/main/java/com/edufocus/edufocus/registration/service/RegistrationService.java create mode 100644 backend/src/main/java/com/edufocus/edufocus/registration/service/RegistrationServiceImpl.java diff --git a/backend/src/main/java/com/edufocus/edufocus/lecture/entity/Lecture.java b/backend/src/main/java/com/edufocus/edufocus/lecture/entity/Lecture.java index c006240..5ae3972 100644 --- a/backend/src/main/java/com/edufocus/edufocus/lecture/entity/Lecture.java +++ b/backend/src/main/java/com/edufocus/edufocus/lecture/entity/Lecture.java @@ -35,6 +35,8 @@ public class Lecture { @Lob private String plan; + @Column + private boolean online; } diff --git a/backend/src/main/java/com/edufocus/edufocus/registration/controller/RegistrationController.java b/backend/src/main/java/com/edufocus/edufocus/registration/controller/RegistrationController.java new file mode 100644 index 0000000..fc6e67d --- /dev/null +++ b/backend/src/main/java/com/edufocus/edufocus/registration/controller/RegistrationController.java @@ -0,0 +1,42 @@ +package com.edufocus.edufocus.registration.controller; + +import com.edufocus.edufocus.registration.entity.Registration; +import com.edufocus.edufocus.registration.service.RegistrationService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequestMapping("/registration") +@Slf4j +public class RegistrationController { + + private final RegistrationService registrationServiceImpl; + + public RegistrationController(RegistrationService registrationServiceImpl) { + this.registrationServiceImpl = registrationServiceImpl; + } + + @PostMapping + public ResponseEntity register(@RequestBody Registration registration) { + registrationServiceImpl.createRegistration(registration); + + return new ResponseEntity<>(HttpStatus.OK); + } + + @PatchMapping("/registrationId/{registrationId}") + public ResponseEntity acceptRigistration(@PathVariable long registrationId) { + registrationServiceImpl.acceptRegistration(registrationId); + + return new ResponseEntity<>(HttpStatus.OK); + } + + @DeleteMapping("/registrationId/{registrationId}") + public ResponseEntity deleteRigistration(@PathVariable long registrationId) { + registrationServiceImpl.deleteRegistration(registrationId); + + return new ResponseEntity<>(HttpStatus.OK); + } + +} diff --git a/backend/src/main/java/com/edufocus/edufocus/registration/entity/Registration.java b/backend/src/main/java/com/edufocus/edufocus/registration/entity/Registration.java new file mode 100644 index 0000000..7e1cce6 --- /dev/null +++ b/backend/src/main/java/com/edufocus/edufocus/registration/entity/Registration.java @@ -0,0 +1,28 @@ +package com.edufocus.edufocus.registration.entity; + +import com.edufocus.edufocus.lecture.entity.Lecture; +import com.edufocus.edufocus.user.model.entity.User; +import jakarta.persistence.*; +import lombok.Getter; +import lombok.Setter; + +@Entity +@Getter +@Setter +public class Registration { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private long id; + + @ManyToOne + @JoinColumn(name = "user_id") + private User user; + + @ManyToOne + @JoinColumn(name = "lecture_id") + private Lecture lecture; + + @Enumerated(EnumType.STRING) + private RegistrationStatus status ; +} diff --git a/backend/src/main/java/com/edufocus/edufocus/registration/entity/RegistrationStatus.java b/backend/src/main/java/com/edufocus/edufocus/registration/entity/RegistrationStatus.java new file mode 100644 index 0000000..5540eed --- /dev/null +++ b/backend/src/main/java/com/edufocus/edufocus/registration/entity/RegistrationStatus.java @@ -0,0 +1,5 @@ +package com.edufocus.edufocus.registration.entity; + +public enum RegistrationStatus { + WAITING, ACCEPTED +} diff --git a/backend/src/main/java/com/edufocus/edufocus/registration/repository/RegistrationRepository.java b/backend/src/main/java/com/edufocus/edufocus/registration/repository/RegistrationRepository.java new file mode 100644 index 0000000..f8dc7db --- /dev/null +++ b/backend/src/main/java/com/edufocus/edufocus/registration/repository/RegistrationRepository.java @@ -0,0 +1,11 @@ +package com.edufocus.edufocus.registration.repository; + +import com.edufocus.edufocus.registration.entity.Registration; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.repository.query.Param; +import org.springframework.stereotype.Repository; + +@Repository +public interface RegistrationRepository extends JpaRepository { + +} diff --git a/backend/src/main/java/com/edufocus/edufocus/registration/service/RegistrationService.java b/backend/src/main/java/com/edufocus/edufocus/registration/service/RegistrationService.java new file mode 100644 index 0000000..fcaac94 --- /dev/null +++ b/backend/src/main/java/com/edufocus/edufocus/registration/service/RegistrationService.java @@ -0,0 +1,17 @@ +package com.edufocus.edufocus.registration.service; + +import com.edufocus.edufocus.registration.entity.Registration; +import org.springframework.stereotype.Service; + +@Service +public interface RegistrationService { + + void createRegistration(Registration registration); + + void acceptRegistration(long RegistrationId); + + void deleteRegistration(long registrationId); + + boolean isAcceptedRegistration(long registrationId); + +} diff --git a/backend/src/main/java/com/edufocus/edufocus/registration/service/RegistrationServiceImpl.java b/backend/src/main/java/com/edufocus/edufocus/registration/service/RegistrationServiceImpl.java new file mode 100644 index 0000000..6eadce6 --- /dev/null +++ b/backend/src/main/java/com/edufocus/edufocus/registration/service/RegistrationServiceImpl.java @@ -0,0 +1,46 @@ +package com.edufocus.edufocus.registration.service; + +import com.edufocus.edufocus.registration.entity.Registration; +import com.edufocus.edufocus.registration.entity.RegistrationStatus; +import com.edufocus.edufocus.registration.repository.RegistrationRepository; +import jakarta.transaction.Transactional; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.Optional; + +@Service +@Transactional +@RequiredArgsConstructor +public class RegistrationServiceImpl implements RegistrationService { + + private final RegistrationRepository registrationRepository; + + @Override + public void createRegistration(Registration registration) { + registrationRepository.save(registration); + } + + @Override + public void acceptRegistration(long registrationId) { + Optional registration = registrationRepository.findById(registrationId); + + if (registration.isPresent()) { + Registration reg = registration.get(); + reg.setStatus(RegistrationStatus.valueOf("ACCEPTED")); + registrationRepository.save(reg); + } + } + + @Override + public void deleteRegistration(long registrationId) { + registrationRepository.deleteById(registrationId); + } + + @Override + public boolean isAcceptedRegistration(long registrationId) { + Optional registration = registrationRepository.findById(registrationId); + + return registration.isPresent() && registration.get().getStatus().equals("ACCEPTED"); + } +}