Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@

import com.example.bilda_server.auth.CustomUserDetails;
import com.example.bilda_server.request.EvaluationRequestDTO;
import com.example.bilda_server.response.BaseResponse;
import com.example.bilda_server.response.ResponseDto;
import com.example.bilda_server.response.TeamMemberEvaluationDTO;
import com.example.bilda_server.service.EvaluationService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.persistence.EntityNotFoundException;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
Expand All @@ -28,19 +31,39 @@ public ResponseDto<Void> createEvaluation(
@RequestBody EvaluationRequestDTO evaluationDTO,
@AuthenticationPrincipal CustomUserDetails userDetails
) {
evaluationService.createAndReflectEvaluation(evaluationDTO, userDetails.getId());
return ResponseDto.success("평가 반영 완료");
try{
evaluationService.createAndReflectEvaluation(evaluationDTO, userDetails.getId());
return ResponseDto.success("평가 반영 완료");
}catch (EntityNotFoundException ex) {
// EntityNotFoundException 발생 시
return ResponseDto.fail(HttpStatus.NOT_FOUND, ex.getMessage());
} catch (RuntimeException ex) {
return ResponseDto.fail(HttpStatus.BAD_REQUEST, ex.getMessage());
} catch (Exception ex) {
// 그 외 일반 예외 발생 시
return ResponseDto.fail(HttpStatus.INTERNAL_SERVER_ERROR, "서버 내부 오류");
}

}

@Operation(summary = "팀원 평가 여부 조회하기", description = "requestParam으로 조회하는 유저의 id를 가져오고 teamId를 pathVariable로 넘기면 팀원들의 평가 여부를 확인할 수 있습니다. ", tags = {
"EvaluationController"})
@GetMapping("/status/{teamId}")
public ResponseEntity<List<TeamMemberEvaluationDTO>> getEvaluationStatus(
public ResponseEntity<?> getEvaluationStatus(
@PathVariable Long teamId,
@AuthenticationPrincipal CustomUserDetails userDetails
) {
List<TeamMemberEvaluationDTO> evaluationStatus = evaluationService.getEvaluationStatusOfTeamMembers(userDetails.getId(), teamId);
return ResponseEntity.ok(evaluationStatus);
try{
List<TeamMemberEvaluationDTO> evaluationStatus = evaluationService.getEvaluationStatusOfTeamMembers(userDetails.getId(), teamId);
return ResponseEntity.ok(evaluationStatus);
}catch (EntityNotFoundException ex) {
// EntityNotFoundException 발생 시
return new ResponseEntity<>(new BaseResponse<>(HttpStatus.NOT_FOUND.value(), ex.getMessage(), null), HttpStatus.NOT_FOUND);
}catch (Exception ex) {
// 그 외 일반 예외 발생 시
return new ResponseEntity<>(new BaseResponse<>(HttpStatus.INTERNAL_SERVER_ERROR.value(), "서버 내부 오류", null), HttpStatus.INTERNAL_SERVER_ERROR);
}

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

import com.example.bilda_server.auth.CustomUserDetails;
import com.example.bilda_server.response.PageAverageDTO;
import com.example.bilda_server.response.ResponseDto;
import com.example.bilda_server.response.TeamMemberEvaluationDTO;
import com.example.bilda_server.service.PageService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
Expand All @@ -23,15 +25,26 @@ public class PageController {
@Operation(summary = "마이페이지 조회", description = "마이페이지의 정보들을 조회할 수 있습니다. ", tags = {
"PageController"})
@GetMapping("")
public PageAverageDTO getPageByUserId(@AuthenticationPrincipal CustomUserDetails userDetails) {
return pageService.getAverageScores(userDetails.getId());
public ResponseDto<PageAverageDTO> getPageByUserId(@AuthenticationPrincipal CustomUserDetails userDetails) {
try{
PageAverageDTO pageAverage = pageService.getAverageScores(userDetails.getId());
return ResponseDto.success("마이 페이지 조회", pageAverage);
}catch (Exception ex) {
return ResponseDto.fail(HttpStatus.INTERNAL_SERVER_ERROR, "서버 내부 오류");
}

}

@Operation(summary = "팀원의 마이페이지 조회", description = "조회하고자하는 user의 id를 pathVariable로 넘기면 마이페이지의 정보들을 조회할 수 있습니다. ", tags = {
"PageController"})
@GetMapping("/{userId}")
public PageAverageDTO getPageByUserId(@PathVariable Long userId) {
return pageService.getAverageScores(userId);
public ResponseDto<PageAverageDTO> getPageByUserId(@PathVariable Long userId) {
try{
PageAverageDTO pageAverage = pageService.getAverageScores(userId);
return ResponseDto.success("마이 페이지 조회", pageAverage);
}catch (Exception ex) {
return ResponseDto.fail(HttpStatus.INTERNAL_SERVER_ERROR, "서버 내부 오류");
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import jakarta.persistence.EntityNotFoundException;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.stereotype.Controller;
Expand Down Expand Up @@ -43,8 +45,14 @@ public class SubjectController {
public ResponseDto<List<Subject>> getSubjectsByDepartment(
@AuthenticationPrincipal CustomUserDetails userDetails
) {
List<Subject> subjects = subjectService.findSubjectsByUserDepartment(userDetails.getId());
return ResponseDto.success("과목 정보 조회 완료", subjects);

try{
List<Subject> subjects = subjectService.findSubjectsByUserDepartment(userDetails.getId());
return ResponseDto.success("과목 정보 조회 완료", subjects);
}catch (EntityNotFoundException ex) {
return ResponseDto.fail(HttpStatus.NOT_FOUND, ex.getMessage());
}

}

@Operation(summary = "유저가 속해있는 과목정보 가져오기", description = "유저가 듣고있는 과목정보를 가져올 수 있습니다. ", tags = {"SubjectController"})
Expand All @@ -58,8 +66,14 @@ public ResponseDto<List<Subject>> getSubjectsByDepartment(
@GetMapping("")
@ResponseBody
public ResponseDto<List<SubjectWithTeamStatusDTO>> getSubjects(@AuthenticationPrincipal CustomUserDetails userDetails) {
List<SubjectWithTeamStatusDTO> subjects = subjectService.findSubjectsByUserId(userDetails.getId());
return ResponseDto.success("유저가 속해 있는 과목 정보 조회 완료", subjects);

try{
List<SubjectWithTeamStatusDTO> subjects = subjectService.findSubjectsByUserId(userDetails.getId());
return ResponseDto.success("유저가 속해 있는 과목 정보 조회 완료", subjects);
}catch (EntityNotFoundException ex) {
return ResponseDto.fail(HttpStatus.NOT_FOUND, ex.getMessage());
}

}

@Operation(summary = "유저가 듣고 있는 과목 추가하기", description = "SubjectId를 pathVariable로 넘기면 유저가 듣고 있는 과목을 추가할 수 있습니다. ", tags = {"SubjectController"})
Expand All @@ -74,8 +88,19 @@ public ResponseDto<List<SubjectWithTeamStatusDTO>> getSubjects(@AuthenticationPr
public ResponseEntity<BaseResponse<UserSubjectDTO>> addSubjectToUser(
@PathVariable Long subjectCode,
@AuthenticationPrincipal CustomUserDetails userDetails) {
UserSubjectDTO userSubjectDTO = subjectService.addUserToSubject(subjectCode, userDetails.getId());
return ResponseEntity.ok(new BaseResponse<>(200, "유저의 과목 추가 성공", userSubjectDTO));
try{
UserSubjectDTO userSubjectDTO = subjectService.addUserToSubject(subjectCode, userDetails.getId());
return ResponseEntity.ok(new BaseResponse<>(200, "유저의 과목 추가 성공", userSubjectDTO));
}catch (EntityNotFoundException ex) {
return new ResponseEntity<>(new BaseResponse<>(HttpStatus.NOT_FOUND.value(), ex.getMessage(), null), HttpStatus.NOT_FOUND);
}catch (IllegalStateException ex) {
// IllegalStateException 발생 시
return new ResponseEntity<>(new BaseResponse<>(HttpStatus.BAD_REQUEST.value(), ex.getMessage(), null), HttpStatus.BAD_REQUEST);
} catch (Exception ex) {
// 그 외 일반 예외 발생 시
return new ResponseEntity<>(new BaseResponse<>(HttpStatus.INTERNAL_SERVER_ERROR.value(), "서버 내부 오류", null), HttpStatus.INTERNAL_SERVER_ERROR);
}


}
}
Loading