feat: Registration

Registration Entity, Repository, Service, Controller 추가
This commit is contained in:
kgc9007 2024-07-16 17:48:27 +09:00
parent ef75e672f1
commit 92a21b61c1
7 changed files with 151 additions and 0 deletions

View File

@ -35,6 +35,8 @@ public class Lecture {
@Lob @Lob
private String plan; private String plan;
@Column
private boolean online;
} }

View File

@ -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);
}
}

View File

@ -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 ;
}

View File

@ -0,0 +1,5 @@
package com.edufocus.edufocus.registration.entity;
public enum RegistrationStatus {
WAITING, ACCEPTED
}

View File

@ -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<Registration, Long> {
}

View File

@ -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);
}

View File

@ -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> 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> registration = registrationRepository.findById(registrationId);
return registration.isPresent() && registration.get().getStatus().equals("ACCEPTED");
}
}