fix: lecture 조회 결과 반환값 수정

This commit is contained in:
kgc9007 2024-07-29 10:55:07 +09:00
parent c99d3cc7ec
commit 2d88ceed34
2 changed files with 10 additions and 18 deletions

View File

@ -35,14 +35,12 @@ public class LectureController {
Lecture lecture = lectureService.findLectureByTitle(lectureCreateRequest.getTitle()); Lecture lecture = lectureService.findLectureByTitle(lectureCreateRequest.getTitle());
if (lecture != null) { if (lecture != null) {
String msg = new String("Duplicated Lecture"); return new ResponseEntity<>(HttpStatus.CONFLICT);
return new ResponseEntity<>(msg, HttpStatus.CONFLICT);
} }
lectureService.createLecture(userId, lectureCreateRequest, image); lectureService.createLecture(userId, lectureCreateRequest, image);
String msg = new String("Lecture registered successfully"); return new ResponseEntity<>(HttpStatus.CREATED);
return new ResponseEntity<>(msg, HttpStatus.CREATED);
} }
@PutMapping("/{lectureId}") @PutMapping("/{lectureId}")
@ -50,11 +48,9 @@ public class LectureController {
Long userId = Long.parseLong(jwtUtil.getUserId(accessToken)); Long userId = Long.parseLong(jwtUtil.getUserId(accessToken));
if (!lectureService.updateLecture(userId, lectureId, lectureCreateRequest)) { if (!lectureService.updateLecture(userId, lectureId, lectureCreateRequest)) {
String msg = new String("Can't update Lecture"); return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
return new ResponseEntity<>(msg, HttpStatus.UNAUTHORIZED);
} }
String msg = new String("Lecture updated successfully"); return new ResponseEntity<>(HttpStatus.OK);
return new ResponseEntity<>(msg, HttpStatus.OK);
} }
@ -63,8 +59,7 @@ public class LectureController {
Long userId = Long.parseLong(jwtUtil.getUserId(accessToken)); Long userId = Long.parseLong(jwtUtil.getUserId(accessToken));
if (!lectureService.deleteLecture(userId, lectureId)) { if (!lectureService.deleteLecture(userId, lectureId)) {
String msg = new String("Can't delete Lecture"); return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
return new ResponseEntity<>(msg, HttpStatus.UNAUTHORIZED);
} }
return new ResponseEntity<>(HttpStatus.NO_CONTENT); return new ResponseEntity<>(HttpStatus.NO_CONTENT);
@ -75,8 +70,7 @@ public class LectureController {
List<LectureSearchResponse> lectures = lectureService.findAllLecture(); List<LectureSearchResponse> lectures = lectureService.findAllLecture();
if (lectures.isEmpty()) { if (lectures.isEmpty()) {
String msg = new String("No lectures found"); return new ResponseEntity<>(HttpStatus.NO_CONTENT);
return new ResponseEntity<>(msg, HttpStatus.OK);
} }
return new ResponseEntity<>(lectures, HttpStatus.OK); return new ResponseEntity<>(lectures, HttpStatus.OK);
@ -93,8 +87,7 @@ public class LectureController {
LectureDetailResponse lectureDetailResponse = lectureService.findLectureById(userId, lectureId); LectureDetailResponse lectureDetailResponse = lectureService.findLectureById(userId, lectureId);
if (lectureDetailResponse == null) { if (lectureDetailResponse == null) {
String msg = new String("Can't find Lecture"); return new ResponseEntity<>(HttpStatus.OK);
return new ResponseEntity<>(msg, HttpStatus.OK);
} }
@ -104,8 +97,7 @@ public class LectureController {
@GetMapping("/mylecture") @GetMapping("/mylecture")
public ResponseEntity<?> findMyLecture(@RequestHeader(value = "Authorization", required = false) String accessToken) { public ResponseEntity<?> findMyLecture(@RequestHeader(value = "Authorization", required = false) String accessToken) {
if (accessToken == null) { if (accessToken == null) {
String msg = new String("Not logged in"); return new ResponseEntity<>(HttpStatus.NO_CONTENT);
return new ResponseEntity<>(msg, HttpStatus.OK);
} }
Long userId = Long.parseLong(jwtUtil.getUserId(accessToken)); Long userId = Long.parseLong(jwtUtil.getUserId(accessToken));
@ -113,8 +105,7 @@ public class LectureController {
List<LectureSearchResponse> myLectures = lectureService.findMyLecture(userId); List<LectureSearchResponse> myLectures = lectureService.findMyLecture(userId);
if (myLectures.isEmpty()) { if (myLectures.isEmpty()) {
String msg = new String("No lectures found"); return new ResponseEntity<>(HttpStatus.NO_CONTENT);
return new ResponseEntity<>(msg, HttpStatus.OK);
} }
return new ResponseEntity<>(myLectures, HttpStatus.OK); return new ResponseEntity<>(myLectures, HttpStatus.OK);

View File

@ -119,6 +119,7 @@ public class LectureServiceImpl implements LectureService {
@Override @Override
public List<LectureSearchResponse> findAllLecture() { public List<LectureSearchResponse> findAllLecture() {
List<Lecture> lectureList = lectureRepository.findAll(); List<Lecture> lectureList = lectureRepository.findAll();
System.out.println(lectureList.size());
List<LectureSearchResponse> lectureSearchResponseList = new ArrayList<>(); List<LectureSearchResponse> lectureSearchResponseList = new ArrayList<>();
for (Lecture lecture : lectureList) { for (Lecture lecture : lectureList) {