Skip to content

Commit 759525f

Browse files
authored
Merge pull request #10 from Chalkac/dev
Dev
2 parents 40687d7 + fca8cba commit 759525f

File tree

19 files changed

+221
-13
lines changed

19 files changed

+221
-13
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ dependencies {
3636
implementation 'org.springframework.boot:spring-boot-starter-security'
3737
implementation 'software.amazon.awssdk:mediaconvert:2.20.0'
3838
implementation 'software.amazon.awssdk:s3:2.20.0'
39+
implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server'
3940
}
4041

4142
tasks.named('test') {

src/main/java/com/rtu/chalkac/domain/category/controller/CategoryController.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
import com.rtu.chalkac.domain.category.service.CategoryService;
66
import lombok.RequiredArgsConstructor;
77
import org.springframework.http.ResponseEntity;
8+
import org.springframework.security.access.prepost.PreAuthorize;
89
import org.springframework.web.bind.annotation.*;
910

1011
import java.util.List;
1112

1213
@RestController
1314
@RequestMapping("/api/v1/category")
1415
@RequiredArgsConstructor
16+
@PreAuthorize("hasAnyRole('USER', 'ADMIN')")
1517
public class CategoryController {
1618

1719
private final CategoryService categoryService;
@@ -31,13 +33,15 @@ public ResponseEntity<CategoryResponseDto> getCategoryById(@PathVariable Long id
3133
}
3234

3335
// 3. 생성
36+
@PreAuthorize("hasRole('ADMIN')")
3437
@PostMapping
3538
public ResponseEntity<CategoryResponseDto> createCategory(@RequestBody CreateCategoryRequestDto requestDto) {
3639
CategoryResponseDto createdCategory = categoryService.createCategory(requestDto);
3740
return ResponseEntity.ok(createdCategory);
3841
}
3942

4043
// 4. 삭제
44+
@PreAuthorize("hasRole('ADMIN')")
4145
@DeleteMapping("/{id}")
4246
public ResponseEntity<Void> deleteCategoryById(@PathVariable Long id) {
4347
categoryService.deleteCategoryById(id);

src/main/java/com/rtu/chalkac/domain/comment/controller/CommentController.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
import org.springframework.data.domain.PageRequest;
1010
import org.springframework.data.domain.Pageable;
1111
import org.springframework.http.ResponseEntity;
12+
import org.springframework.security.access.prepost.PreAuthorize;
1213
import org.springframework.web.bind.annotation.*;
1314

1415
@RestController
1516
@RequestMapping("/api/v1/comment")
1617
@RequiredArgsConstructor
18+
@PreAuthorize("hasAnyRole('USER', 'ADMIN')")
1719
public class CommentController {
1820
private final CommentService commentService;
1921

src/main/java/com/rtu/chalkac/domain/comment/model/Comment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class Comment {
2727
@JoinColumn(name = "user_id", nullable = false)
2828
private Users user;
2929

30-
@Column(name = "content", nullable = false)
30+
@Column(name = "content", nullable = false, length = 1000)
3131
private String content;
3232

3333
@Column(name = "like_cnt", nullable = false)

src/main/java/com/rtu/chalkac/domain/comment/repository/CommentRepository.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import org.springframework.data.repository.query.Param;
99

1010
public interface CommentRepository extends JpaRepository<Comment, String> {
11-
@Query("SELECT c FROM Comment c WHERE c.video.videoId = :videoId ORDER BY (c.likeCnt - c.dislikeCnt) DESC")
12-
Page<Comment> findByVideoIdOrderByLikeDislikeSumDesc(@Param("videoId") String videoId, Pageable pageable);
11+
@Query("SELECT c FROM Comment c WHERE c.video.videoId = :videoId ORDER BY (c.likeCnt - c.dislikeCnt) ASC")
12+
Page<Comment> findByVideoIdOrderByLikeDislikeSumAsc(@Param("videoId") String videoId, Pageable pageable);
1313

14-
Page<Comment> findByVideoVideoIdOrderByDateDesc(String videoId, Pageable pageable);
14+
Page<Comment> findByVideoVideoIdOrderByDateAsc(String videoId, Pageable pageable);
1515
}

src/main/java/com/rtu/chalkac/domain/comment/service/CommentService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ public Comment getComment(String commentId){
3131

3232
// 해당 비디오의 댓글 조회, Page, CommentResponseDto 사용, likeCnt 높은순
3333
public PageableDto<CommentResponseDto> findCommentsByLikes(String videoId, Pageable pageable) {
34-
return new PageableDto<>(commentRepository.findByVideoIdOrderByLikeDislikeSumDesc(videoId, pageable)
34+
return new PageableDto<>(commentRepository.findByVideoIdOrderByLikeDislikeSumAsc(videoId, pageable)
3535
.map(CommentResponseDto::new));
3636
}
3737

3838
// 해당 비디오의 댓글 조회, Page, CommentResponseDto 사용, date 최신순
3939
public PageableDto<CommentResponseDto> findCommentsByDate(String videoId, Pageable pageable) {
40-
return new PageableDto<>(commentRepository.findByVideoVideoIdOrderByDateDesc(videoId, pageable)
40+
return new PageableDto<>(commentRepository.findByVideoVideoIdOrderByDateAsc(videoId, pageable)
4141
.map(CommentResponseDto::new));
4242
}
4343

src/main/java/com/rtu/chalkac/domain/reply/controller/ReplyController.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
import com.rtu.chalkac.global.util.PageableDto;
77
import lombok.RequiredArgsConstructor;
88
import org.springframework.http.ResponseEntity;
9+
import org.springframework.security.access.prepost.PreAuthorize;
910
import org.springframework.web.bind.annotation.*;
1011

1112
@RestController
1213
@RequestMapping("/api/v1/reply")
1314
@RequiredArgsConstructor
15+
@PreAuthorize("hasAnyRole('USER', 'ADMIN')")
1416
public class ReplyController {
1517
private final ReplyService replyService;
1618

src/main/java/com/rtu/chalkac/domain/reply/model/Reply.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class Reply {
2727
@JoinColumn(name = "user_id", nullable = false)
2828
private Users user;
2929

30-
@Column(name = "content", nullable = false)
30+
@Column(name = "content", nullable = false, length = 1000)
3131
private String content;
3232

3333
@Column(name = "like_cnt", nullable = false)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.rtu.chalkac.domain.users.controller;
2+
3+
import com.rtu.chalkac.domain.users.dto.request.UpdateUserNicknameRequestDto;
4+
import com.rtu.chalkac.domain.users.dto.request.UpdateUserProfileRequestDto;
5+
import com.rtu.chalkac.domain.users.dto.response.UserResponseDto;
6+
import com.rtu.chalkac.domain.users.service.UserService;
7+
import lombok.RequiredArgsConstructor;
8+
import org.springframework.http.ResponseEntity;
9+
import org.springframework.security.access.prepost.PreAuthorize;
10+
import org.springframework.web.bind.annotation.*;
11+
12+
@RestController
13+
@RequestMapping("/api/v1/users")
14+
@RequiredArgsConstructor
15+
@PreAuthorize("hasAnyRole('USER', 'ADMIN')")
16+
public class UserController {
17+
private final UserService userService;
18+
19+
// 유저 정보 불러오기
20+
@GetMapping("/{userId}")
21+
public ResponseEntity<UserResponseDto> getUser(@PathVariable String userId) {
22+
UserResponseDto user = userService.findUser(userId);
23+
return ResponseEntity.ok(user);
24+
}
25+
26+
// 유저 닉네임 수정
27+
@PatchMapping("/nickname")
28+
public ResponseEntity<Void> updateNickname(@RequestBody UpdateUserNicknameRequestDto dto) {
29+
userService.updateNickname(dto);
30+
return ResponseEntity.ok().build();
31+
}
32+
33+
// 유저 프로필 수정
34+
@PatchMapping("/profile")
35+
public ResponseEntity<Void> updateProfile(@RequestBody UpdateUserProfileRequestDto dto) {
36+
userService.updateProfile(dto);
37+
return ResponseEntity.ok().build();
38+
}
39+
40+
// 유저 탈퇴
41+
@DeleteMapping("/{userId}")
42+
public ResponseEntity<Void> deleteUser(@PathVariable String userId) {
43+
userService.deleteUser(userId);
44+
return ResponseEntity.ok().build();
45+
}
46+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.rtu.chalkac.domain.users.dto.request;
2+
3+
import lombok.Getter;
4+
import lombok.Setter;
5+
6+
@Getter
7+
@Setter
8+
public class UpdateUserNicknameRequestDto {
9+
private String userId;
10+
private String nickname;
11+
}

0 commit comments

Comments
 (0)