diff --git a/src/main/java/UMC/campusNote/common/code/status/SuccessStatus.java b/src/main/java/UMC/campusNote/common/code/status/SuccessStatus.java index 94ae1a4..5490793 100644 --- a/src/main/java/UMC/campusNote/common/code/status/SuccessStatus.java +++ b/src/main/java/UMC/campusNote/common/code/status/SuccessStatus.java @@ -51,7 +51,10 @@ public enum SuccessStatus implements BaseCode { IMAGE_GET_ONE(HttpStatus.OK, "IMAGE200", "노트의 특정 이미지 조회 성공"), IMAGE_GET_ALL(HttpStatus.OK, "IMAGE200", "노트의 모든 이미지 조회 성공"), IMAGE_DELETE_ONE(HttpStatus.OK, "IMAGE202", "노트의 특정 이미지 삭제 성공"), - IMAGE_DELETE_ALL(HttpStatus.OK, "IMAGE202", "노트의 모든 이미지 삭제 성공"), + IMAGE_DELETE_ALL(HttpStatus.OK, "IMAGE203", "노트의 모든 이미지 삭제 성공"), + + // 수강 학기 + ATTENDED_SEMESTER_UPDATE(HttpStatus.OK, "ATTENDED_SEMESTER200", "수강 학기 업데이트 성공"), ; private final HttpStatus httpStatus; diff --git a/src/main/java/UMC/campusNote/image/controller/ImageController.java b/src/main/java/UMC/campusNote/image/controller/ImageController.java index e00da6b..4c85718 100644 --- a/src/main/java/UMC/campusNote/image/controller/ImageController.java +++ b/src/main/java/UMC/campusNote/image/controller/ImageController.java @@ -81,7 +81,7 @@ public ApiResponse getImageOne(@PathVariable @DeleteMapping("/{noteId}") @Operation(summary = "특정 노트의 모든 이미지를 삭제하는 API", description = "특정 노트의 모든 이미지를 삭제하는 API") @ApiResponses({ - @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "IMAGE202",description = "노트의 모든 이미지 삭제 성공"), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "IMAGE203",description = "노트의 모든 이미지 삭제 성공"), @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "NOTE4001", description = "존재하지 않는 노트.",content = @Content(schema = @Schema(implementation = ApiResponse.class))), @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "IMAGE4001", description = "존재하지 않는 이미지.",content = @Content(schema = @Schema(implementation = ApiResponse.class))) }) diff --git a/src/main/java/UMC/campusNote/mapping/repository/UserLessonRepository.java b/src/main/java/UMC/campusNote/mapping/repository/UserLessonRepository.java index 19318c8..2818be1 100644 --- a/src/main/java/UMC/campusNote/mapping/repository/UserLessonRepository.java +++ b/src/main/java/UMC/campusNote/mapping/repository/UserLessonRepository.java @@ -4,6 +4,9 @@ import UMC.campusNote.mapping.UserLesson; import UMC.campusNote.user.entity.User; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import java.util.List; import java.util.Optional; @@ -16,4 +19,9 @@ public interface UserLessonRepository extends JpaRepository { Optional findByUserAndAttendedSemesterAndLesson(User user, String attendedSemester, Lesson lesson); Optional findByUserAndLesson(User user, Lesson lesson); + + @Modifying + @Query("UPDATE UserLesson u SET u.attendedSemester = :attendedSemester WHERE u.user.id = :userId") + int updateAttendedSemester(@Param("userId") Long userId, @Param("attendedSemester") String attendedSemester); + } diff --git a/src/main/java/UMC/campusNote/user/controller/UserController.java b/src/main/java/UMC/campusNote/user/controller/UserController.java index 5471988..b7b6d22 100644 --- a/src/main/java/UMC/campusNote/user/controller/UserController.java +++ b/src/main/java/UMC/campusNote/user/controller/UserController.java @@ -1,11 +1,18 @@ package UMC.campusNote.user.controller; import UMC.campusNote.common.ApiResponse; +import UMC.campusNote.user.dto.UserRequestDTO; +import UMC.campusNote.user.dto.UserResponseDTO; +import UMC.campusNote.user.entity.User; import UMC.campusNote.user.service.UserService; -import lombok.Getter; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.responses.ApiResponses; import lombok.RequiredArgsConstructor; +import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; +import static UMC.campusNote.common.code.status.SuccessStatus.ATTENDED_SEMESTER_UPDATE; + @RestController @RequiredArgsConstructor @@ -19,4 +26,14 @@ public ApiResponse get() { return ApiResponse.onSuccess("GET:: user controller"); } + + @PatchMapping("/attended-semester") + @Operation(summary = "유저의 수강 학기 수정 API",description = "유저의 수강 학기 수정 API입니다.") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "ATTENDED_SEMESTER200",description = "수강 학기 업데이트 성공"), + }) + public ApiResponse updateAttendedSemester(@AuthenticationPrincipal User user, @RequestBody UserRequestDTO.AttendedSemesterUpdateDTO request) { + return ApiResponse.of(ATTENDED_SEMESTER_UPDATE ,userService.updateAttendedSemester(user.getId(), request)); + } + } diff --git a/src/main/java/UMC/campusNote/user/converter/UserConverter.java b/src/main/java/UMC/campusNote/user/converter/UserConverter.java new file mode 100644 index 0000000..43bf904 --- /dev/null +++ b/src/main/java/UMC/campusNote/user/converter/UserConverter.java @@ -0,0 +1,17 @@ +package UMC.campusNote.user.converter; + +import UMC.campusNote.user.dto.UserResponseDTO; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class UserConverter { + + public static UserResponseDTO.AttendedSemesterUpdateDTO toAttendedSemesterUpdateDTO(String attendedSemester, int count) { + return UserResponseDTO.AttendedSemesterUpdateDTO.builder() + .count(count) + .attendedSemester(attendedSemester) + .build(); + } +} diff --git a/src/main/java/UMC/campusNote/user/dto/UserRequestDTO.java b/src/main/java/UMC/campusNote/user/dto/UserRequestDTO.java new file mode 100644 index 0000000..e633068 --- /dev/null +++ b/src/main/java/UMC/campusNote/user/dto/UserRequestDTO.java @@ -0,0 +1,22 @@ +package UMC.campusNote.user.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +public class UserRequestDTO { + + @AllArgsConstructor + @NoArgsConstructor + @Getter + @Builder + public static class AttendedSemesterUpdateDTO{ + + @Schema(description = "수정할 수강 학기", example = "4-2") + @NotNull + String attendedSemester; + } +} diff --git a/src/main/java/UMC/campusNote/user/dto/UserResponseDTO.java b/src/main/java/UMC/campusNote/user/dto/UserResponseDTO.java new file mode 100644 index 0000000..2f9fc07 --- /dev/null +++ b/src/main/java/UMC/campusNote/user/dto/UserResponseDTO.java @@ -0,0 +1,18 @@ +package UMC.campusNote.user.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +public class UserResponseDTO { + + @Builder + @Getter + @NoArgsConstructor + @AllArgsConstructor + public static class AttendedSemesterUpdateDTO { + int count; + String attendedSemester; + } +} diff --git a/src/main/java/UMC/campusNote/user/service/UserService.java b/src/main/java/UMC/campusNote/user/service/UserService.java index 130fb6b..4f56599 100644 --- a/src/main/java/UMC/campusNote/user/service/UserService.java +++ b/src/main/java/UMC/campusNote/user/service/UserService.java @@ -1,13 +1,12 @@ package UMC.campusNote.user.service; +import UMC.campusNote.user.dto.UserRequestDTO; +import UMC.campusNote.user.dto.UserResponseDTO; import UMC.campusNote.user.repository.UserRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; -@Service -@RequiredArgsConstructor -public class UserService { - - private final UserRepository userRepository; +public interface UserService { + UserResponseDTO.AttendedSemesterUpdateDTO updateAttendedSemester(Long userId, UserRequestDTO.AttendedSemesterUpdateDTO request); } diff --git a/src/main/java/UMC/campusNote/user/service/UserServiceImpl.java b/src/main/java/UMC/campusNote/user/service/UserServiceImpl.java new file mode 100644 index 0000000..ecaaf51 --- /dev/null +++ b/src/main/java/UMC/campusNote/user/service/UserServiceImpl.java @@ -0,0 +1,26 @@ +package UMC.campusNote.user.service; + + +import UMC.campusNote.mapping.repository.UserLessonRepository; +import UMC.campusNote.user.converter.UserConverter; +import UMC.campusNote.user.dto.UserRequestDTO; +import UMC.campusNote.user.dto.UserResponseDTO; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + + +@Service +@RequiredArgsConstructor +@Transactional(readOnly = true) +public class UserServiceImpl implements UserService{ + + private final UserLessonRepository userLessonRepository; + + @Override + @Transactional + public UserResponseDTO.AttendedSemesterUpdateDTO updateAttendedSemester(Long userId, UserRequestDTO.AttendedSemesterUpdateDTO request) { + int count = userLessonRepository.updateAttendedSemester(userId, request.getAttendedSemester()); + return UserConverter.toAttendedSemesterUpdateDTO(request.getAttendedSemester(), count); + } +}