Skip to content

heejeong 3주차 과제#16

Open
Hxxjeong wants to merge 1 commit into
mainfrom
heejeong
Open

heejeong 3주차 과제#16
Hxxjeong wants to merge 1 commit into
mainfrom
heejeong

Conversation

@Hxxjeong

@Hxxjeong Hxxjeong commented Oct 5, 2023

Copy link
Copy Markdown
Contributor

학생의 벌점 점수 합산
controller의 메소드를 수정하여 작성하였으나, Workbench에서 확인한 결과 student 테이블에 벌점 적용이 되지 않아 문제 사항을 발견하였으며,
DB에 적용이 되어야 하기 때문에 Transactional 어노테이션을 사용하는 Service 클래스에 로직을 구현하였습니다.

  • 초기 코드
    public RspTemplate<Void> handleUpdateStudentInLecture(@PathVariable Long studentInLectureId, @RequestBody PenaltyReqDto penaltyReqDto) {

//      StudentInLecture에서 학생과 강의 정보 받아오기
        StudentInLecture stuInLec = studentInLectureService.getById(studentInLectureId);
        Student student = stuInLec.getStudent();

//      벌점을 의미하는 요청값 받아오기
         Penalty penalty = penaltyReqDto.getPenalty();

//      현재 학생의 강의 벌점
         int currentTotalPenalty = student.getTotalPenalty();

//      벌점이 있는 경우 수정, 없는 경우 추가하여 합산
         int diff = penalty.getValue() - stuInLec.getPenalty();
         student.setTotalPenalty(currentTotalPenalty + diff);

//      StudentInLecture 객체 update
        long updatedStuInLecId = studentInLectureService.updatePenalty(studentInLectureId, penalty);

        return new RspTemplate<>(HttpStatus.OK, updatedStuInLecId + "번 수강신청의 벌점이 수정되었습니다.");
    }

@Hxxjeong Hxxjeong changed the title heejong 3주차 과제 heejeong 3주차 과제 Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant