-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Feat : 정보 댓글 생성, 수정, 삭제 * Feat : 댓글 조회 정보 조회 시 댓글도 같이 조회 댓글만 페이지 단위로 조회 * Style : 불필요한 import 삭제 * Fix : CreatedDate 삭제, validation 예외 처리 로직 추가 * Fix : validation 추가, modifiedDate 어노테이션 추가
- Loading branch information
Showing
17 changed files
with
396 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/main/java/solitour_backend/solitour/information/repository/InformationRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
package solitour_backend.solitour.information.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import solitour_backend.solitour.information.entity.Information; | ||
import solitour_backend.solitour.user.entity.User; | ||
|
||
import java.util.Optional; | ||
|
||
|
||
public interface InformationRepository extends JpaRepository<Information, Long>, InformationRepositoryCustom { | ||
|
||
@Query("SELECT i FROM Information i WHERE i.user.id = :userId") | ||
Optional<Information> findByUserId(Long userId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
...olitour_backend/solitour/information_comment/controller/InformationCommentController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package solitour_backend.solitour.information_comment.controller; | ||
|
||
|
||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.validation.BindingResult; | ||
import org.springframework.web.bind.annotation.*; | ||
import solitour_backend.solitour.auth.config.Authenticated; | ||
import solitour_backend.solitour.auth.config.AuthenticationPrincipal; | ||
import solitour_backend.solitour.error.Utils; | ||
import solitour_backend.solitour.information_comment.dto.request.InformationCommentRequest; | ||
import solitour_backend.solitour.information_comment.dto.respose.InformationCommentListResponse; | ||
import solitour_backend.solitour.information_comment.dto.respose.InformationCommentResponse; | ||
import solitour_backend.solitour.information_comment.service.InformationCommentService; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/informations/comments") | ||
public class InformationCommentController { | ||
|
||
private final InformationCommentService informationCommentService; | ||
|
||
|
||
@Authenticated | ||
@PostMapping("/{informationId}") | ||
public ResponseEntity<InformationCommentResponse> createInformationComment(@AuthenticationPrincipal Long userId, | ||
@PathVariable Long informationId, | ||
@Valid @RequestBody InformationCommentRequest informationCommentRequest, | ||
BindingResult bindingResult) { | ||
Utils.validationRequest(bindingResult); | ||
|
||
InformationCommentResponse informationCommentResponse = informationCommentService.createInformationComment( | ||
userId, informationId, informationCommentRequest); | ||
|
||
return ResponseEntity | ||
.status(HttpStatus.CREATED) | ||
.body(informationCommentResponse); | ||
} | ||
|
||
@GetMapping("/{informationId}") | ||
public ResponseEntity<Page<InformationCommentListResponse>> getPageInformationComment( | ||
@RequestParam(defaultValue = "0") int page, | ||
@PathVariable Long informationId) { | ||
|
||
final int PAGE_SIZE = 5; | ||
Pageable pageable = PageRequest.of(page, PAGE_SIZE); | ||
Page<InformationCommentListResponse> pageInformation = informationCommentService.getPageInformationComment( | ||
pageable, informationId); | ||
|
||
return ResponseEntity | ||
.status(HttpStatus.OK) | ||
.body(pageInformation); | ||
} | ||
|
||
@Authenticated | ||
@PutMapping("/{informationCommentId}") | ||
public ResponseEntity<Void> modifyInformationComment(@AuthenticationPrincipal Long userId, | ||
@PathVariable Long informationCommentId, | ||
@Valid @RequestBody InformationCommentRequest informationCommentRequest, | ||
BindingResult bindingResult) { | ||
Utils.validationRequest(bindingResult); | ||
|
||
informationCommentService.modifyInformationComment(userId, informationCommentId, informationCommentRequest); | ||
|
||
return ResponseEntity.noContent().build(); | ||
} | ||
|
||
@Authenticated | ||
@DeleteMapping("/{informationCommentId}") | ||
public ResponseEntity<Void> deleteInformationComment(@AuthenticationPrincipal Long userId, | ||
@PathVariable Long informationCommentId) { | ||
informationCommentService.deleteInformationComment(userId, informationCommentId); | ||
|
||
return ResponseEntity.noContent().build(); | ||
} | ||
} | ||
|
14 changes: 14 additions & 0 deletions
14
.../solitour_backend/solitour/information_comment/dto/request/InformationCommentRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package solitour_backend.solitour.information_comment.dto.request; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class InformationCommentRequest { | ||
@NotBlank | ||
private String comment; | ||
} |
20 changes: 20 additions & 0 deletions
20
...tour_backend/solitour/information_comment/dto/respose/InformationCommentListResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package solitour_backend.solitour.information_comment.dto.respose; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@ToString | ||
public class InformationCommentListResponse { | ||
private Long commentId; | ||
private Long userId; | ||
private String userNickname; | ||
private String userProfile; | ||
private String content; | ||
private LocalDateTime createdAt; | ||
private LocalDateTime updatedAt; | ||
} |
12 changes: 12 additions & 0 deletions
12
...solitour_backend/solitour/information_comment/dto/respose/InformationCommentResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package solitour_backend.solitour.information_comment.dto.respose; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class InformationCommentResponse { | ||
@NotBlank | ||
private Long commentId; | ||
} |
54 changes: 54 additions & 0 deletions
54
src/main/java/solitour_backend/solitour/information_comment/entity/InformationComment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package solitour_backend.solitour.information_comment.entity; | ||
|
||
import jakarta.persistence.*; | ||
import jakarta.validation.Valid; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.springframework.data.annotation.CreatedDate; | ||
import org.springframework.data.annotation.LastModifiedDate; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
import solitour_backend.solitour.information.entity.Information; | ||
import solitour_backend.solitour.information_comment.dto.request.InformationCommentRequest; | ||
import solitour_backend.solitour.user.entity.User; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Entity | ||
@Table(name = "information_comment") | ||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@EntityListeners(AuditingEntityListener.class) | ||
public class InformationComment { | ||
|
||
@Id | ||
@Column(name = "information_comment_id") | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "information_id") | ||
private Information information; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "user_id") | ||
private User user; | ||
|
||
@Column(name = "information_comment_content") | ||
private String content; | ||
|
||
@CreatedDate | ||
@Column(name = "information_comment_created_date") | ||
private LocalDateTime createdDate; | ||
|
||
@LastModifiedDate | ||
@Column(name = "information_comment_updated_date") | ||
private LocalDateTime updatedDate; | ||
|
||
public void updateComment(@Valid InformationCommentRequest informationCommentRequest) { | ||
this.content = informationCommentRequest.getComment(); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...ava/solitour_backend/solitour/information_comment/exception/CommentNotOwnerException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package solitour_backend.solitour.information_comment.exception; | ||
|
||
public class CommentNotOwnerException extends RuntimeException { | ||
|
||
public CommentNotOwnerException(String message) { | ||
super(message); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
..._backend/solitour/information_comment/exception/InformationCommentNotExistsException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package solitour_backend.solitour.information_comment.exception; | ||
|
||
public class InformationCommentNotExistsException extends RuntimeException { | ||
|
||
public InformationCommentNotExistsException(String message) { | ||
super(message); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...olitour_backend/solitour/information_comment/repository/InformationCommentRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package solitour_backend.solitour.information_comment.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import solitour_backend.solitour.information_comment.entity.InformationComment; | ||
|
||
|
||
public interface InformationCommentRepository extends JpaRepository<InformationComment, Long>, InformationCommentRepositoryCustom { | ||
} | ||
|
12 changes: 12 additions & 0 deletions
12
...r_backend/solitour/information_comment/repository/InformationCommentRepositoryCustom.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package solitour_backend.solitour.information_comment.repository; | ||
|
||
import org.springframework.data.domain.PageImpl; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.repository.NoRepositoryBean; | ||
import solitour_backend.solitour.information_comment.dto.respose.InformationCommentListResponse; | ||
|
||
|
||
@NoRepositoryBean | ||
public interface InformationCommentRepositoryCustom { | ||
PageImpl<InformationCommentListResponse> getPageInformationComment(Pageable pageable, Long id); | ||
} |
Oops, something went wrong.