Skip to content

Commit

Permalink
fix: 일관된 empty content 처리
Browse files Browse the repository at this point in the history
  • Loading branch information
SHEOMM committed Mar 7, 2024
1 parent 637a019 commit a8c4ccc
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.waruru.areyouhere.attendee.advice;

import static com.waruru.areyouhere.common.utils.HttpStatusResponseEntity.RESPONSE_NOT_FOUND;
import static com.waruru.areyouhere.common.utils.HttpStatusResponseEntity.RESPONSE_NO_CONTENT;

import com.waruru.areyouhere.attendee.exception.ClassAttendeesEmptyException;
import com.waruru.areyouhere.attendee.exception.SessionAttendeesEmptyException;
import com.waruru.areyouhere.session.exception.CourseIdNotFoundException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice("com.waruru.areyouhere.attendee")
public class AttendeeExceptionAdvice {
@ExceptionHandler(CourseIdNotFoundException.class)
public ResponseEntity<HttpStatus> courseIdNotFoundFoundHandler() {
return RESPONSE_NOT_FOUND;
}

@ExceptionHandler(SessionAttendeesEmptyException.class)
public ResponseEntity<HttpStatus> sessionAttendeesEmptyHandler() {
return RESPONSE_NO_CONTENT;
}

@ExceptionHandler(ClassAttendeesEmptyException.class)
public ResponseEntity<HttpStatus> classAttendeesEmptyHandler() {
return RESPONSE_NO_CONTENT;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ public class AttendeeController {
@GetMapping("/{courseId}")
public ResponseEntity<ClassAttendeesDto> getClassAttendees(@PathVariable("courseId") Long courseId){
List<ClassAttendees> classAttendees = attendeeService.getClassAttendeesIfExistsOrEmpty(courseId);
if(classAttendees.isEmpty()){
return ResponseEntity.noContent().build();
}

return ResponseEntity.ok(ClassAttendeesDto.builder()
.classAttendees(classAttendees)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.waruru.areyouhere.attendee.exception;

public class ClassAttendeesEmptyException extends RuntimeException{
public ClassAttendeesEmptyException() {
}

public ClassAttendeesEmptyException(String message) {
super(message);
}

public ClassAttendeesEmptyException(String message, Throwable cause) {
super(message, cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.waruru.areyouhere.attendee.exception;

public class SessionAttendeesEmptyException extends RuntimeException{
public SessionAttendeesEmptyException() {
}

public SessionAttendeesEmptyException(String message) {
super(message);
}

public SessionAttendeesEmptyException(String message, Throwable cause) {
super(message, cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.waruru.areyouhere.attendee.domain.repository.AttendeeRepository;
import com.waruru.areyouhere.attendee.domain.repository.dto.ClassAttendeeInfo;
import com.waruru.areyouhere.attendee.domain.repository.dto.SessionAttendeeInfo;
import com.waruru.areyouhere.attendee.exception.ClassAttendeesEmptyException;
import com.waruru.areyouhere.attendee.exception.SessionAttendeesEmptyException;
import com.waruru.areyouhere.attendee.service.dto.ClassAttendees;
import com.waruru.areyouhere.attendee.service.dto.SessionAttendees;
import com.waruru.areyouhere.course.domain.entity.Course;
Expand Down Expand Up @@ -54,9 +56,11 @@ public void deleteAttendees(List<Long> deleteAttendees){
@Transactional(readOnly = true)
public List<SessionAttendees> getSessionAttendeesIfExistsOrEmpty(Long sessionId){
List<SessionAttendeeInfo> sessionAttendees = attendeeRepository.findSessionAttendees(sessionId);
return sessionAttendees == null || sessionAttendees.isEmpty() ?
Collections.emptyList()
: sessionAttendees.stream().map(sessionAttendee -> SessionAttendees.builder()

if(sessionAttendees == null || sessionAttendees.isEmpty())
throw new SessionAttendeesEmptyException();

return sessionAttendees.stream().map(sessionAttendee -> SessionAttendees.builder()
.attendanceId(sessionAttendee.getAttendanceId())
.attendeeName(sessionAttendee.getAttendeeName())
.attendanceStatus(sessionAttendee.getAttendanceStatus())
Expand All @@ -67,9 +71,11 @@ public List<SessionAttendees> getSessionAttendeesIfExistsOrEmpty(Long sessionId)
@Transactional(readOnly = true)
public List<SessionAttendees> getSessionAbsenteesIfExistsOrEmpty(Long sessionId){
List<SessionAttendeeInfo> sessionAttendees = attendeeRepository.findSessionOnlyAbsentee(sessionId);
return sessionAttendees == null || sessionAttendees.isEmpty() ?
Collections.emptyList()
: sessionAttendees.stream().map(sessionAttendee -> SessionAttendees.builder()

if(sessionAttendees == null || sessionAttendees.isEmpty())
throw new SessionAttendeesEmptyException();

return sessionAttendees.stream().map(sessionAttendee -> SessionAttendees.builder()
.attendanceId(sessionAttendee.getAttendanceId())
.attendeeName(sessionAttendee.getAttendeeName())
.attendanceStatus(sessionAttendee.getAttendanceStatus())
Expand All @@ -82,9 +88,10 @@ public List<SessionAttendees> getSessionAbsenteesIfExistsOrEmpty(Long sessionId)
public List<ClassAttendees> getClassAttendeesIfExistsOrEmpty(Long courseId){
List<ClassAttendeeInfo> classAttendancesInfos = attendeeRepository.getClassAttendancesInfo(courseId);

return classAttendancesInfos == null || classAttendancesInfos.isEmpty() ?
Collections.emptyList()
: classAttendancesInfos.stream().map( classAttendancesInfo -> ClassAttendees.builder()
if(classAttendancesInfos == null || classAttendancesInfos.isEmpty())
throw new ClassAttendeesEmptyException();

return classAttendancesInfos.stream().map( classAttendancesInfo -> ClassAttendees.builder()
.id(classAttendancesInfo.getattendeeId())
.name(classAttendancesInfo.getName())
.attendance(classAttendancesInfo.getAttendance())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ public ResponseEntity<SessionAttendanceInfo> getSessionBasicInfo(@PathVariable("
public ResponseEntity<SessionAttendeesDto> getSessionAllAttendees(@PathVariable("sessionId") Long sessionId){
List<SessionAttendees> sessionAttendees = attendeeService.getSessionAttendeesIfExistsOrEmpty(
sessionId);
if(sessionAttendees.isEmpty()){
return ResponseEntity.noContent().build();
}

return ResponseEntity.ok(SessionAttendeesDto.builder()
.sessionAttendees(sessionAttendees)
.build());
Expand All @@ -78,22 +76,10 @@ public ResponseEntity<SessionAttendeesDto> getSessionAllAttendees(@PathVariable(
public ResponseEntity<SessionAttendeesDto> getSessionAbsenteeOnly(@PathVariable("sessionId") Long sessionId){
List<SessionAttendees> sessionAttendees = attendeeService.getSessionAbsenteesIfExistsOrEmpty(
sessionId);
if(sessionAttendees.isEmpty()){
return ResponseEntity.noContent().build();
}

return ResponseEntity.ok(SessionAttendeesDto.builder()
.sessionAttendees(sessionAttendees)
.build());
}

// @PostMapping()









}

0 comments on commit a8c4ccc

Please sign in to comment.