feat: finished creating services from controllers, continued implementing entrepreneurServiceApi with some validation
This commit is contained in:
@ -3,6 +3,8 @@ package enseirb.myinpulse.service.database;
|
||||
import enseirb.myinpulse.model.Annotation;
|
||||
import enseirb.myinpulse.repository.AnnotationRepository;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -13,6 +15,8 @@ import java.util.Optional;
|
||||
@Service
|
||||
public class AnnotationService {
|
||||
|
||||
protected static final Logger logger = LogManager.getLogger();
|
||||
|
||||
private final AnnotationRepository annotationRepository;
|
||||
|
||||
@Autowired
|
||||
@ -27,6 +31,7 @@ public class AnnotationService {
|
||||
public Annotation getAnnotationById(Long id) {
|
||||
Optional<Annotation> annotation = annotationRepository.findById(id);
|
||||
if (annotation.isEmpty()) {
|
||||
logger.error("getAnnotationById : No annotation found with id {}", id);
|
||||
throw new ResponseStatusException(
|
||||
HttpStatus.NOT_FOUND, "Cette annotation n'existe pas");
|
||||
}
|
||||
@ -44,7 +49,9 @@ public class AnnotationService {
|
||||
public Annotation updateAnnotation(Long id, String comment) {
|
||||
Optional<Annotation> annotation = annotationRepository.findById(id);
|
||||
if (annotation.isEmpty()) {
|
||||
return null;
|
||||
logger.error("updateAnnotation : No annotation found with id {}", id);
|
||||
throw new ResponseStatusException(
|
||||
HttpStatus.NOT_FOUND, "Cette annotation n'existe pas");
|
||||
}
|
||||
if (comment != null) {
|
||||
annotation.get().setComment(comment);
|
||||
|
Reference in New Issue
Block a user