diff --git a/src/main/java/com/example/demo/config/errors/GlobalValidationHandler.java b/src/main/java/com/example/demo/config/errors/GlobalValidationHandler.java index 545123b0..12f0c9a5 100644 --- a/src/main/java/com/example/demo/config/errors/GlobalValidationHandler.java +++ b/src/main/java/com/example/demo/config/errors/GlobalValidationHandler.java @@ -6,10 +6,8 @@ import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Pointcut; import org.springframework.stereotype.Component; -import org.springframework.validation.BindingResult; import org.springframework.validation.Errors; import org.springframework.validation.FieldError; -import org.springframework.validation.ObjectError; import java.util.HashMap; import java.util.List; diff --git a/src/main/java/com/example/demo/config/errors/exception/Exception400.java b/src/main/java/com/example/demo/config/errors/exception/Exception400.java index fa170cc1..315eb295 100644 --- a/src/main/java/com/example/demo/config/errors/exception/Exception400.java +++ b/src/main/java/com/example/demo/config/errors/exception/Exception400.java @@ -3,6 +3,7 @@ import com.example.demo.config.utils.ApiResponseBuilder; import lombok.Getter; +import java.util.HashMap; import java.util.Map; @Getter @@ -11,12 +12,7 @@ public class Exception400 extends RuntimeException { public Exception400(Map errors, String message) { super(message); - this.errors = errors; - } - - public Exception400(String message) { - super(message); - errors = null; + this.errors = (errors != null) ? errors : null; } public ApiResponseBuilder.ApiResponse body(){ diff --git a/src/main/java/com/example/demo/interest/Interest.java b/src/main/java/com/example/demo/interest/Interest.java index 8e64541e..504be61f 100644 --- a/src/main/java/com/example/demo/interest/Interest.java +++ b/src/main/java/com/example/demo/interest/Interest.java @@ -12,7 +12,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity @Table(name = "interests") -public class Interest { +public class Interest extends BaseTime { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private int id; diff --git a/src/main/java/com/example/demo/mentoring/MentorPostResponse.java b/src/main/java/com/example/demo/mentoring/MentorPostResponse.java index 405a019b..0dfd3c5d 100644 --- a/src/main/java/com/example/demo/mentoring/MentorPostResponse.java +++ b/src/main/java/com/example/demo/mentoring/MentorPostResponse.java @@ -3,7 +3,6 @@ import com.example.demo.mentoring.contact.ContactStateEnum; import com.example.demo.mentoring.contact.NotConnectedRegisterUser; -import com.example.demo.user.Role; import com.example.demo.user.User; import com.example.demo.user.userInterest.UserInterest; import lombok.Getter; diff --git a/src/main/java/com/example/demo/mentoring/MentorPostRestController.java b/src/main/java/com/example/demo/mentoring/MentorPostRestController.java index fd19f3bb..17fd6dc2 100644 --- a/src/main/java/com/example/demo/mentoring/MentorPostRestController.java +++ b/src/main/java/com/example/demo/mentoring/MentorPostRestController.java @@ -33,7 +33,7 @@ public ResponseEntity getMentorPost( category = MentorPostCategoryEnum.NULL; List responseDTOs = mentorPostService.findAllMentorPost(category, keyword, page); - return ResponseEntity.ok(ApiUtils.success(responseDTOs)); + return ResponseEntity.ok(ApiResponseBuilder.success(responseDTOs)); } @GetMapping("/mentorings/post/{id}") @@ -45,19 +45,19 @@ public ResponseEntity getMentorPostId(@PathVariable int id) { @PutMapping(value = "/mentorings/post/{id}") public ResponseEntity updateMentorPost(@PathVariable int id, @RequestBody @Valid MentorPostRequest.CreateDTO requestDTO, Errors errors, @AuthenticationPrincipal CustomUserDetails userDetails) { mentorPostService.updateMentorPost(requestDTO, id, userDetails.getUser()); - return ResponseEntity.status(HttpStatus.OK).body(ApiUtils.successWithNoContent()); + return ResponseEntity.status(HttpStatus.OK).body(ApiResponseBuilder.successWithNoContent()); } @DeleteMapping(value = "/mentorings/post/{id}") public ResponseEntity deleteMentorPost(@PathVariable int id, @AuthenticationPrincipal CustomUserDetails userDetails) { mentorPostService.deleteMentorPost(id, userDetails.getUser()); - return ResponseEntity.status(HttpStatus.OK).body(ApiUtils.successWithNoContent()); + return ResponseEntity.status(HttpStatus.OK).body(ApiResponseBuilder.successWithNoContent()); } @PatchMapping(value = "/mentorings/post/{id}/done") public ResponseEntity changeMentorPostStatus(@PathVariable int id,@RequestBody @Valid MentorPostRequest.StateDTO requestDTO, Errors errors, @AuthenticationPrincipal CustomUserDetails userDetails) { mentorPostService.changeMentorPostStatus(requestDTO, id, userDetails.getUser()); - return ResponseEntity.status(HttpStatus.OK).body(ApiUtils.successWithNoContent()); + return ResponseEntity.status(HttpStatus.OK).body(ApiResponseBuilder.successWithNoContent()); } } diff --git a/src/main/java/com/example/demo/mentoring/MentorPostService.java b/src/main/java/com/example/demo/mentoring/MentorPostService.java index be3f9c45..ac075398 100644 --- a/src/main/java/com/example/demo/mentoring/MentorPostService.java +++ b/src/main/java/com/example/demo/mentoring/MentorPostService.java @@ -5,7 +5,6 @@ import com.example.demo.config.errors.exception.Exception404; import com.example.demo.mentoring.contact.ContactJPARepository; import com.example.demo.mentoring.contact.NotConnectedRegisterUser; -import com.example.demo.user.Role; import com.example.demo.user.User; import com.example.demo.user.userInterest.UserInterest; import com.example.demo.user.userInterest.UserInterestJPARepository; diff --git a/src/main/java/com/example/demo/mentoring/contact/ContactResponse.java b/src/main/java/com/example/demo/mentoring/contact/ContactResponse.java index ff83058c..62b8f150 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactResponse.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactResponse.java @@ -1,7 +1,6 @@ package com.example.demo.mentoring.contact; import com.example.demo.mentoring.MentorPost; -import com.example.demo.user.Role; import com.example.demo.user.User; import com.example.demo.user.userInterest.UserInterest; import lombok.Getter; diff --git a/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java b/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java index 2cfbc08c..abe0b21d 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java @@ -1,9 +1,7 @@ package com.example.demo.mentoring.contact; import com.example.demo.config.auth.CustomUserDetails; -import com.example.demo.config.utils.ApiUtils; -import com.example.demo.mentoring.done.DoneService; -import com.example.demo.user.Role; +import com.example.demo.config.utils.ApiResponseBuilder; import io.swagger.v3.oas.annotations.Operation; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; @@ -25,10 +23,10 @@ public class ContactRestController { public ResponseEntity findAllContacts(@AuthenticationPrincipal CustomUserDetails userDetails) { if ( userDetails.getUser().getRole() == Role.MENTEE ) { List responseDTO = contactService.findAllByMentee(userDetails.getUser()); - return ResponseEntity.ok(ApiUtils.success(responseDTO)); + return ResponseEntity.ok(ApiResponseBuilder.success(responseDTO)); } List responseDTO = contactService.findAllByMentor(userDetails.getUser()); - return ResponseEntity.ok(ApiUtils.success(responseDTO)); + return ResponseEntity.ok(ApiResponseBuilder.success(responseDTO)); } @@ -42,11 +40,11 @@ public ResponseEntity postCounts(@AuthenticationPrincipal CustomUserDetails u if ( role == Role.MENTEE ) { ContactResponse.PostCountDTO responseDTO = contactService.postCountsMyMentee(userDetails.getUser().getId()); - return ResponseEntity.ok(ApiUtils.success(responseDTO)); + return ResponseEntity.ok(ApiResponseBuilder.success(responseDTO)); } ContactResponse.PostCountDTO responseDTO = contactService.postCountsByMentor(userDetails.getUser().getId()); - return ResponseEntity.ok(ApiUtils.success(responseDTO)); + return ResponseEntity.ok(ApiResponseBuilder.success(responseDTO)); } @PostMapping(value = "/contacts/accept") @@ -54,7 +52,7 @@ public ResponseEntity postCounts(@AuthenticationPrincipal CustomUserDetails u public ResponseEntity acceptContact(@RequestBody @Valid ContactRequest.ContactAcceptDTO contactAcceptDTO, Error errors, @AuthenticationPrincipal CustomUserDetails userDetails) { // TO-DO : 멘토링 신청 수락 API 로직 만들기 contactService.acceptContact(contactAcceptDTO, userDetails.getUser()); - return ResponseEntity.status(HttpStatus.OK).body(ApiUtils.successWithNoContent()); + return ResponseEntity.status(HttpStatus.OK).body(ApiResponseBuilder.successWithNoContent()); } @PatchMapping(value = "/contacts/refuse") @@ -62,7 +60,7 @@ public ResponseEntity acceptContact(@RequestBody @Valid ContactRequest.Contac public ResponseEntity refuseContact(@RequestBody @Valid ContactRequest.ContactRefuseDTO contactRefuseDTO, Error errors, @AuthenticationPrincipal CustomUserDetails userDetails) { // TO-DO : 멘토링 신청 거절 API 로직 만들기 contactService.refuseContact(contactRefuseDTO, userDetails.getUser()); - return ResponseEntity.status(HttpStatus.OK).body(ApiUtils.successWithNoContent()); + return ResponseEntity.status(HttpStatus.OK).body(ApiResponseBuilder.successWithNoContent()); } @PostMapping(value = "/contacts") @@ -70,7 +68,7 @@ public ResponseEntity refuseContact(@RequestBody @Valid ContactRequest.Contac public ResponseEntity createContact(@RequestBody @Valid ContactRequest.ContactCreateDTO contactCreateDTO, Error errors, @AuthenticationPrincipal CustomUserDetails userDetails) { // TO-DO : 멘토링 신청 API 로직 만들기 contactService.createContact(contactCreateDTO, userDetails.getUser()); - return ResponseEntity.status(HttpStatus.OK).body(ApiUtils.successWithNoContent()); + return ResponseEntity.status(HttpStatus.OK).body(ApiResponseBuilder.successWithNoContent()); } @DeleteMapping(value = "/contacts") @@ -78,7 +76,7 @@ public ResponseEntity createContact(@RequestBody @Valid ContactRequest.Contac public ResponseEntity deleteContact(@RequestHeader("contactId") List contactId, Error errors, @AuthenticationPrincipal CustomUserDetails userDetails) { // TO-DO : 멘토링 신청 취소 API 로직 만들기 contactService.deleteContact(contactId, userDetails.getUser()); - return ResponseEntity.status(HttpStatus.OK).body(ApiUtils.successWithNoContent()); + return ResponseEntity.status(HttpStatus.OK).body(ApiResponseBuilder.successWithNoContent()); } } diff --git a/src/main/java/com/example/demo/mentoring/contact/ContactService.java b/src/main/java/com/example/demo/mentoring/contact/ContactService.java index f377e130..280ac6e8 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactService.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactService.java @@ -6,7 +6,6 @@ import com.example.demo.mentoring.MentorPostJPARepostiory; import com.example.demo.mentoring.done.ConnectedUser; import com.example.demo.mentoring.done.DoneJPARepository; -import com.example.demo.user.Role; import com.example.demo.user.User; import com.example.demo.user.userInterest.UserInterest; import com.example.demo.user.userInterest.UserInterestJPARepository; diff --git a/src/main/java/com/example/demo/mentoring/done/DoneResponse.java b/src/main/java/com/example/demo/mentoring/done/DoneResponse.java index 85dabc77..60f75141 100644 --- a/src/main/java/com/example/demo/mentoring/done/DoneResponse.java +++ b/src/main/java/com/example/demo/mentoring/done/DoneResponse.java @@ -1,8 +1,6 @@ package com.example.demo.mentoring.done; import com.example.demo.mentoring.MentorPost; -import com.example.demo.mentoring.contact.ContactResponse; -import com.example.demo.user.Role; import com.example.demo.user.User; import com.example.demo.user.userInterest.UserInterest; import lombok.Getter; diff --git a/src/main/java/com/example/demo/mentoring/done/DoneRestController.java b/src/main/java/com/example/demo/mentoring/done/DoneRestController.java index 365ac1b9..10b7c910 100644 --- a/src/main/java/com/example/demo/mentoring/done/DoneRestController.java +++ b/src/main/java/com/example/demo/mentoring/done/DoneRestController.java @@ -1,8 +1,7 @@ package com.example.demo.mentoring.done; import com.example.demo.config.auth.CustomUserDetails; -import com.example.demo.config.utils.ApiUtils; -import com.example.demo.user.Role; +import com.example.demo.config.utils.ApiResponseBuilder; import io.swagger.v3.oas.annotations.Operation; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; @@ -23,9 +22,9 @@ public class DoneRestController { public ResponseEntity findAllContacts(@AuthenticationPrincipal CustomUserDetails userDetails) { if (userDetails.getUser().getRole().equals(Role.MENTEE)) { List responseDTO = doneService.findByMentee(userDetails.getUser()); - return ResponseEntity.ok(ApiUtils.success(responseDTO)); + return ResponseEntity.ok(ApiResponseBuilder.success(responseDTO)); } List responseDTO = doneService.findByMentor(userDetails.getUser()); - return ResponseEntity.ok(ApiUtils.success(responseDTO)); + return ResponseEntity.ok(ApiResponseBuilder.success(responseDTO)); } } diff --git a/src/main/java/com/example/demo/refreshToken/TokenService.java b/src/main/java/com/example/demo/refreshToken/TokenService.java index bb1b2118..d2ece77b 100644 --- a/src/main/java/com/example/demo/refreshToken/TokenService.java +++ b/src/main/java/com/example/demo/refreshToken/TokenService.java @@ -1,18 +1,11 @@ package com.example.demo.refreshToken; -import com.example.demo.config.errors.exception.Exception400; import com.example.demo.config.errors.exception.Exception401; import com.example.demo.config.jwt.JWTTokenProvider; -import io.jsonwebtoken.Claims; -import io.jsonwebtoken.Jwts; import lombok.RequiredArgsConstructor; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.Optional; - @Transactional @RequiredArgsConstructor @Service diff --git a/src/main/java/com/example/demo/user/Role.java b/src/main/java/com/example/demo/user/Role.java index 8092be42..58738307 100644 --- a/src/main/java/com/example/demo/user/Role.java +++ b/src/main/java/com/example/demo/user/Role.java @@ -6,22 +6,25 @@ import lombok.Getter; import lombok.NoArgsConstructor; +import java.util.Collections; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; + @Getter @AllArgsConstructor public enum Role { - ADMIN("Admin"), - MENTOR("Mentor"), - MENTEE("Mentee"); + ADMIN("ADMIN", "ADMIN"), + MENTOR("MENTOR", "MENTOR"), + MENTEE("MENTEE", "MENTEE"); + + private final String desc; + private final String value; - private final String role; + private static final Map description = Collections.unmodifiableMap(Stream.of(values()).collect(Collectors.toMap(Role::getValue, Function.identity()))); - @JsonCreator - public static Role parsing(String value) { - for (Role role: Role.values()) { - if (role.getRole().equals(value)) { - return role; - } - } - return null; + public static Role findOf(String findValue) { + return description.get(findValue); } } diff --git a/src/main/java/com/example/demo/user/RoleConverter.java b/src/main/java/com/example/demo/user/RoleConverter.java new file mode 100644 index 00000000..2efe9c08 --- /dev/null +++ b/src/main/java/com/example/demo/user/RoleConverter.java @@ -0,0 +1,20 @@ +package com.example.demo.user; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +import javax.persistence.AttributeConverter; + +@RequiredArgsConstructor +@Component +public class RoleConverter implements AttributeConverter { + @Override + public String convertToDatabaseColumn(Role attribute) { + return attribute.getValue(); + } + + @Override + public Role convertToEntityAttribute(String dbData) { + return Role.findOf(dbData); + } +} \ No newline at end of file diff --git a/src/main/java/com/example/demo/user/UserService.java b/src/main/java/com/example/demo/user/UserService.java index 7ca3140e..684925d8 100644 --- a/src/main/java/com/example/demo/user/UserService.java +++ b/src/main/java/com/example/demo/user/UserService.java @@ -1,9 +1,9 @@ package com.example.demo.user; +import com.example.demo.config.errors.exception.Exception400; import com.example.demo.config.errors.exception.Exception404; import com.example.demo.interest.Interest; import com.example.demo.interest.InterestJPARepository; -import com.example.demo.config.errors.exception.Exception400; import com.example.demo.config.jwt.JWTTokenProvider; import com.example.demo.refreshToken.RefreshToken; import com.example.demo.refreshToken.RefreshTokenJPARepository; @@ -33,7 +33,7 @@ public class UserService { public void emailCheck(UserRequest.EmailCheckDTO requestDTO) { Optional optionalUser = userJPARepository.findByEmail(requestDTO.getEmail()); if (optionalUser.isPresent()) { - throw new Exception400("동일한 이메일이 존재합니다."); + throw new Exception400(null, "동일한 이메일이 존재합니다."); } } @@ -56,7 +56,7 @@ public void signup(UserRequest.SignUpDTO requestDTO) { List categoryList = requestDTO.getCategoryList(); for (String category : categoryList) { Interest interest = interestJPARepository.findByCategory(category) - .orElseThrow(() -> new Exception400("해당 관심사가 존재하지 않습니다.")); + .orElseThrow(() -> new Exception400(null, "해당 관심사가 존재하지 않습니다.")); UserInterest userInterest = UserInterest.builder().user(user).interest(interest).build(); userInterestList.add(userInterest); } @@ -66,10 +66,10 @@ public void signup(UserRequest.SignUpDTO requestDTO) { @Transactional public UserResponse.LoginDTO login(UserRequest.LoginDTO requestDTO) { User user = userJPARepository.findByEmail(requestDTO.getEmail()) - .orElseThrow(() -> new Exception400("잘못된 이메일입니다.")); + .orElseThrow(() -> new Exception400(null, "잘못된 이메일입니다.")); if (!passwordEncoder.matches(requestDTO.getPassword(), user.getPassword())) { - throw new Exception400("잘못된 비밀번호입니다."); + throw new Exception400(null, "잘못된 비밀번호입니다."); } TokenResponse.TokenDTO token = JWTTokenProvider.createToken(user); diff --git a/src/main/java/com/example/demo/video/Subtitle.java b/src/main/java/com/example/demo/video/Subtitle.java index b2107b85..0ab972b9 100644 --- a/src/main/java/com/example/demo/video/Subtitle.java +++ b/src/main/java/com/example/demo/video/Subtitle.java @@ -6,13 +6,17 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.Where; import javax.persistence.*; @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity -@Table(name = "subtitle_tb") +@Where(clause = "deleted_at IS NULL") +@SQLDelete(sql = "UPDATE subtitles SET deleted_at = CURRENT_TIMESTAMP, is_deleted = TRUE where id = ?") +@Table(name = "subtitles") public class Subtitle extends BaseTime { @GeneratedValue(strategy = GenerationType.IDENTITY) @Id diff --git a/src/main/java/com/example/demo/video/SubtitleJPARepository.java b/src/main/java/com/example/demo/video/SubtitleJPARepository.java new file mode 100644 index 00000000..79129499 --- /dev/null +++ b/src/main/java/com/example/demo/video/SubtitleJPARepository.java @@ -0,0 +1,13 @@ +package com.example.demo.video; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import java.util.List; +import java.util.Optional; + +public interface SubtitleJPARepository extends JpaRepository { + @Query("select m from Subtitle m where m.video.id = :video") + List findSubtitleByVideoId(@Param("video") int video); +} diff --git a/src/main/java/com/example/demo/video/Video.java b/src/main/java/com/example/demo/video/Video.java index bdf88b93..945325fa 100644 --- a/src/main/java/com/example/demo/video/Video.java +++ b/src/main/java/com/example/demo/video/Video.java @@ -1,18 +1,23 @@ package com.example.demo.video; import com.example.demo.config.utils.BaseTime; -import io.swagger.v3.oas.annotations.tags.Tag; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.hibernate.annotations.ColumnDefault; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.Where; import javax.persistence.*; +import javax.validation.constraints.NotNull; @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity -@Table(name = "video_tb") +@Where(clause = "deleted_at IS NULL") +@SQLDelete(sql = "UPDATE videos SET deleted_at = CURRENT_TIMESTAMP, is_deleted = TRUE where id = ?") +@Table(name = "videos") public class Video extends BaseTime { @GeneratedValue(strategy = GenerationType.IDENTITY) @Id @@ -22,7 +27,10 @@ public class Video extends BaseTime { private String videoUrl; @Column - private String videoInfo; + private String videoTitleKorean; + + @Column + private String videoTitleEng; @Column private String videoStartTime; @@ -30,11 +38,25 @@ public class Video extends BaseTime { @Column private String videoEndTime; + @Column(nullable = false) + @ColumnDefault("0") + private long views; + + @Column + private String videoThumbnailUrl; + @Builder - public Video(String videoUrl, String videoInfo, String videoStartTime, String videoEndTime) { + public Video(String videoUrl, String videoTitleKorean, String videoTitleEng, String videoStartTime, String videoEndTime, long views, String videoThumbnailUrl) { this.videoUrl = videoUrl; - this.videoInfo = videoInfo; + this.videoTitleKorean = videoTitleKorean; + this.videoTitleEng = videoTitleEng; this.videoStartTime = videoStartTime; this.videoEndTime = videoEndTime; + this.views = views; + this.videoThumbnailUrl = videoThumbnailUrl; + } + + public void addView(){ + this.views += 1; } } diff --git a/src/main/java/com/example/demo/video/VideoHistory.java b/src/main/java/com/example/demo/video/VideoHistory.java new file mode 100644 index 00000000..ebfbeced --- /dev/null +++ b/src/main/java/com/example/demo/video/VideoHistory.java @@ -0,0 +1,39 @@ +package com.example.demo.video; + +import com.example.demo.config.utils.BaseTime; +import com.example.demo.user.User; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.Where; + +import javax.persistence.*; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Entity +@Where(clause = "deleted_at IS NULL") +@SQLDelete(sql = "UPDATE video_histories SET deleted_at = CURRENT_TIMESTAMP, is_deleted = TRUE where id = ?") +@Table(name = "video_histories") +public class VideoHistory extends BaseTime { + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Id + private int id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id") + private User user; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "video_id") + private Video video; + + @Builder + public VideoHistory( User user, Video video) { + this.user = user; + this.video = video; + } + +} diff --git a/src/main/java/com/example/demo/video/VideoHistoryJPARepository.java b/src/main/java/com/example/demo/video/VideoHistoryJPARepository.java new file mode 100644 index 00000000..4f4cfe0f --- /dev/null +++ b/src/main/java/com/example/demo/video/VideoHistoryJPARepository.java @@ -0,0 +1,11 @@ +package com.example.demo.video; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; + +public interface VideoHistoryJPARepository extends JpaRepository { + @Query("select vh from VideoHistory vh where vh.user.id = :id order by vh.createdAt desc") + Page findHistoryVideo(int id, Pageable pageable); +} diff --git a/src/main/java/com/example/demo/video/VideoInterest.java b/src/main/java/com/example/demo/video/VideoInterest.java index a29e7589..b84a0d6c 100644 --- a/src/main/java/com/example/demo/video/VideoInterest.java +++ b/src/main/java/com/example/demo/video/VideoInterest.java @@ -7,13 +7,17 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.Where; import javax.persistence.*; @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity -@Table(name = "videoInterest_tb") +@Where(clause = "deleted_at IS NULL") +@SQLDelete(sql = "UPDATE video_interests SET deleted_at = CURRENT_TIMESTAMP, is_deleted = TRUE where id = ?") +@Table(name = "video_interests") public class VideoInterest extends BaseTime { @GeneratedValue(strategy = GenerationType.IDENTITY) @Id diff --git a/src/main/java/com/example/demo/video/VideoInterestJPARepository.java b/src/main/java/com/example/demo/video/VideoInterestJPARepository.java new file mode 100644 index 00000000..411ee8aa --- /dev/null +++ b/src/main/java/com/example/demo/video/VideoInterestJPARepository.java @@ -0,0 +1,14 @@ +package com.example.demo.video; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import java.util.List; + +public interface VideoInterestJPARepository extends JpaRepository { + @Query("select vi from VideoInterest vi where vi.video.id = :video") + VideoInterest findVideoInterestByVideoId(@Param("video") int video); +} diff --git a/src/main/java/com/example/demo/video/VideoJPARepository.java b/src/main/java/com/example/demo/video/VideoJPARepository.java new file mode 100644 index 00000000..f7a56be4 --- /dev/null +++ b/src/main/java/com/example/demo/video/VideoJPARepository.java @@ -0,0 +1,32 @@ +package com.example.demo.video; + +import com.example.demo.mentoring.MentorPost; +import com.example.demo.user.userInterest.UserInterest; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import java.util.List; +import java.util.Optional; + +public interface VideoJPARepository extends JpaRepository { + Optional