Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@

@RestController
@RequestMapping("/api/comment")
public class CommentController {
public class CommentCommandController {
private final CommentService commentService;
private final JwtUtil jwtUtil;

public CommentController(CommentService commentService, JwtUtil jwtUtil) {
public CommentCommandController(CommentService commentService, JwtUtil jwtUtil) {
this.commentService = commentService;
this.jwtUtil = jwtUtil;
}
Expand All @@ -31,44 +31,12 @@ public CommentController(CommentService commentService, JwtUtil jwtUtil) {
})
@PostMapping
public ResponseEntity<CommentSingleResponseDTO> registComment(
@RequestBody CommentRegistRequestDTO commentRegistRequestDTO,
@RequestHeader(name = "Authorization") String authorizationHeader) throws Exception {
@RequestBody CommentRegistRequestDTO commentRegistRequestDTO) {

String accountId = jwtUtil.getSubjectFromAuthHeaderWithoutAuth(authorizationHeader);
CommentSingleResponseDTO comment = commentService.registComment(commentRegistRequestDTO, accountId);
CommentSingleResponseDTO comment = commentService.registComment(commentRegistRequestDTO);
return ResponseEntity.status(HttpStatus.CREATED).body(comment);
}

@Operation(summary = "댓글 조회", description = "ID를 사용하여 댓글을 조회합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "댓글이 성공적으로 조회되었습니다."),
@ApiResponse(responseCode = "404", description = "해당 댓글을 찾을 수 없습니다.")
})
@GetMapping("/{commentId}")
public ResponseEntity<CommentSingleResponseDTO> findCommentByCommentId(@PathVariable Long commentId) {
CommentSingleResponseDTO comment = commentService.findCommentByCommentId(commentId);
return comment != null ? ResponseEntity.ok(comment) : ResponseEntity.notFound().build();
}

@Operation(summary = "요청 ID로 댓글 조회", description = "특정 요청에 연관된 모든 댓글을 조회합니다.")
@ApiResponse(responseCode = "200", description = "댓글 목록이 성공적으로 조회되었습니다.")
@GetMapping("/request/{requestId}")
public ResponseEntity<CommentListResponseDTO> findCommentsByRequestId(@PathVariable Long requestId) {
CommentListResponseDTO comments = commentService.findCommentsByProjectId(requestId);
return ResponseEntity.ok(comments);
}

@Operation(summary = "사용자 ID로 댓글 조회", description = "특정 사용자가 작성한 모든 댓글을 조회합니다.")
@ApiResponse(responseCode = "200", description = "사용자의 댓글 목록이 성공적으로 조회되었습니다.")
@GetMapping("/account")
public ResponseEntity<CommentListResponseDTO> findCommentsByAccountId(
@RequestHeader(name = "Authorization") String authorizationHeader) throws Exception {

String accountId = jwtUtil.getSubjectFromAuthHeaderWithoutAuth(authorizationHeader);
CommentListResponseDTO comments = commentService.findCommentsByAccountId(accountId);
return ResponseEntity.ok(comments);
}

@Operation(summary = "댓글 수정", description = "기존 댓글의 내용을 수정합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "댓글이 성공적으로 수정되었습니다."),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.mtvs.devlinkbackend.comment.controller;

import com.mtvs.devlinkbackend.comment.dto.response.CommentListResponseDTO;
import com.mtvs.devlinkbackend.comment.dto.response.CommentSingleResponseDTO;
import com.mtvs.devlinkbackend.comment.service.CommentViewService;
import com.mtvs.devlinkbackend.common.util.JwtUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/api/comment")
public class CommentQueryController {

private final JwtUtil jwtUtil;
private final CommentViewService commentViewService;

public CommentQueryController(JwtUtil jwtUtil, CommentViewService commentViewService) {
this.jwtUtil = jwtUtil;
this.commentViewService = commentViewService;
}

@Operation(summary = "댓글 조회", description = "ID를 사용하여 댓글을 조회합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "댓글이 성공적으로 조회되었습니다."),
@ApiResponse(responseCode = "404", description = "해당 댓글을 찾을 수 없습니다.")
})
@GetMapping("/{commentId}")
public ResponseEntity<CommentSingleResponseDTO> findCommentByCommentId(@PathVariable Long commentId) {
CommentSingleResponseDTO comment = commentViewService.findCommentByCommentId(commentId);
return comment != null ? ResponseEntity.ok(comment) : ResponseEntity.notFound().build();
}

@Operation(summary = "CommentIdList로 댓글 조회", description = "CommentIdList에 포함된 모든 댓글을 조회합니다.")
@ApiResponse(responseCode = "200", description = "댓글 목록이 성공적으로 조회되었습니다.")
@GetMapping("/list")
public ResponseEntity<CommentListResponseDTO> findCommentsByCommentIdList(
@RequestParam("ids") Long[] idList) {

List<Long> commentIdList = Arrays.stream(idList).toList();
CommentListResponseDTO comments = commentViewService.findCommentsByCommentIdList(commentIdList);
return ResponseEntity.ok(comments);
}

@Operation(summary = "사용자 ID로 댓글 조회", description = "특정 사용자가 작성한 모든 댓글을 조회합니다.")
@ApiResponse(responseCode = "200", description = "사용자의 댓글 목록이 성공적으로 조회되었습니다.")
@GetMapping("/account")
public ResponseEntity<CommentListResponseDTO> findCommentsByAccountId(
@RequestHeader(name = "Authorization") String authorizationHeader) throws Exception {

String accountId = jwtUtil.getSubjectFromAuthHeaderWithoutAuth(authorizationHeader);
CommentListResponseDTO comments = commentViewService.findCommentsByAccountId(accountId);
return ResponseEntity.ok(comments);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
@AllArgsConstructor
@ToString
public class CommentRegistRequestDTO {
private Long userId;
private String content;
private Long requestId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
@Entity(name = "Comment")
@NoArgsConstructor
@Getter
@ToString(exclude = "project") // request 필드를 toString에서 제외
public class Comment {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,4 @@

@Repository
public interface CommentRepository extends JpaRepository<Comment, Long> {
List<Comment> findCommentsByAccountId(String accountId);
List<Comment> findCommentsByProject_ProjectId(Long requestId);

@Query("SELECT c FROM Comment c WHERE c.project.projectId = :projectId")
List<Comment> findCommentIdsByProjectId(@Param("projectId") Long projectId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.mtvs.devlinkbackend.comment.repository;

import com.mtvs.devlinkbackend.comment.entity.Comment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CommentViewRepository extends JpaRepository<Comment, Long> {
List<Comment> findAllByUserId(Long userId);

List<Comment> findByCommentIdIn(List<Long> commentIdList);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import com.mtvs.devlinkbackend.comment.repository.CommentRepository;
import com.mtvs.devlinkbackend.project.entity.Project;
import com.mtvs.devlinkbackend.project.repository.ProjectRepository;
import com.mtvs.devlinkbackend.user.command.model.entity.User;
import com.mtvs.devlinkbackend.user.query.service.UserViewService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -16,41 +18,28 @@
@Service
public class CommentService {
private final CommentRepository commentRepository;
private final ProjectRepository projectRepository;
private final UserViewService userViewService;

public CommentService(CommentRepository commentRepository, ProjectRepository projectRepository) {
public CommentService(CommentRepository commentRepository, UserViewService userViewService) {
this.commentRepository = commentRepository;
this.projectRepository = projectRepository;
this.userViewService = userViewService;
}

@Transactional
public CommentSingleResponseDTO registComment(CommentRegistRequestDTO commentRegistRequestDTO, String accountId) {
Project project = projectRepository.findById(commentRegistRequestDTO.getRequestId()).orElse(null);
public CommentSingleResponseDTO registComment(CommentRegistRequestDTO commentRegistRequestDTO) {
return new CommentSingleResponseDTO(commentRepository.save(new Comment(
commentRegistRequestDTO.getContent(),
accountId,
project
commentRegistRequestDTO.getUserId()
)));
}

public CommentSingleResponseDTO findCommentByCommentId(Long commentId) {
return new CommentSingleResponseDTO(commentRepository.findById(commentId).orElse(null));
}

public CommentListResponseDTO findCommentsByProjectId(Long requestId) {
return new CommentListResponseDTO(commentRepository.findCommentsByProject_ProjectId(requestId));
}

public CommentListResponseDTO findCommentsByAccountId(String accountId) {
return new CommentListResponseDTO(commentRepository.findCommentsByAccountId(accountId));
}

@Transactional
public CommentSingleResponseDTO updateComment(CommentUpdateRequestDTO commentUpdateRequestDTO, String accountId) {
Optional<Comment> comment = commentRepository.findById(commentUpdateRequestDTO.getCommentId());
User user = userViewService.findUserByEpicAccountId(accountId);
if (comment.isPresent()) {
Comment foundComment = comment.get();
if(foundComment.getAccountId().equals(accountId)) {
if(foundComment.getUserId().equals(user.getUserId())) {
foundComment.setContent(commentUpdateRequestDTO.getContent());
return new CommentSingleResponseDTO(foundComment);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.mtvs.devlinkbackend.comment.service;

import com.mtvs.devlinkbackend.comment.dto.response.CommentListResponseDTO;
import com.mtvs.devlinkbackend.comment.dto.response.CommentSingleResponseDTO;
import com.mtvs.devlinkbackend.comment.repository.CommentViewRepository;
import com.mtvs.devlinkbackend.user.command.model.entity.User;
import com.mtvs.devlinkbackend.user.query.service.UserViewService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentViewService {

private final CommentViewRepository commentViewRepository;
private final UserViewService userViewService;

public CommentViewService(CommentViewRepository commentViewRepository, UserViewService userViewService) {
this.commentViewRepository = commentViewRepository;
this.userViewService = userViewService;
}

public CommentSingleResponseDTO findCommentByCommentId(Long commentId) {
return new CommentSingleResponseDTO(commentViewRepository.findById(commentId).orElse(null));
}

public CommentListResponseDTO findCommentsByAccountId(String accountId) {
User user = userViewService.findUserByEpicAccountId(accountId);
return new CommentListResponseDTO(commentViewRepository.findAllByUserId(user.getUserId()));
}

public CommentListResponseDTO findCommentsByCommentIdList(List<Long> commentIdList) {
return new CommentListResponseDTO(commentViewRepository.findByCommentIdIn(commentIdList));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@Entity(name = "Evaluation")
@Getter
@Setter
@ToString(exclude = "categoryInfo")
@ToString(exclude = "skillCategoryInfo")
@NoArgsConstructor
public class Evaluation {
@Id
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
package com.mtvs.devlinkbackend.project.repository;

import com.mtvs.devlinkbackend.project.entity.Project;
import com.mtvs.devlinkbackend.project.repository.projection.ProjectIdAndContent;
import com.mtvs.devlinkbackend.project.repository.projection.ProjectSummary;
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 org.springframework.stereotype.Repository;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Repository
public interface ProjectRepository extends JpaRepository<Project, Long> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,15 @@

import com.mtvs.devlinkbackend.project.entity.Project;
import com.mtvs.devlinkbackend.project.repository.projection.ProjectIdAndContent;
import com.mtvs.devlinkbackend.project.repository.projection.ProjectSummary;
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.time.LocalDate;
import java.util.List;

public interface ProjectViewRepository extends JpaRepository<Project, Long> {
// AccountId로 프로젝트 조회 (페이징 추가)
Page<Project> findProjectsByAccountId(String accountId, Pageable pageable);
Page<Project> findProjectsByUserId(Long userId, Pageable pageable);

// WorkType으로 프로젝트 조회 (페이징 추가)
Page<Project> findProjectsByWorkType(String workType, Pageable pageable);
Expand All @@ -26,24 +22,9 @@ public interface ProjectViewRepository extends JpaRepository<Project, Long> {
Page<Project> findProjectsByTitleContainingIgnoreCase(String title, Pageable pageable);

// 시작일과 종료일 기준으로 프로젝트 조회 (페이징 추가)
Page<Project> findProjectsByStartDateTimeLessThanEqualOrEndDateTimeGreaterThanEqual(
LocalDate startDateTime, LocalDate endDateTime, Pageable pageable);

// required 값들이 넘겨준 값보다 큰 row를 조회하는 쿼리 (페이징 추가)
@Query("SELECT p FROM Project p WHERE " +
"(:requiredClient IS NULL OR p.requiredClient > :requiredClient) AND " +
"(:requiredServer IS NULL OR p.requiredServer > :requiredServer) AND " +
"(:requiredDesign IS NULL OR p.requiredDesign > :requiredDesign) AND " +
"(:requiredPlanner IS NULL OR p.requiredPlanner > :requiredPlanner) AND " +
"(:requiredAIEngineer IS NULL OR p.requiredAIEngineer > :requiredAIEngineer)")
Page<Project> findProjectsWithLargerRequirements(
@Param("requiredClient") Integer requiredClient,
@Param("requiredServer") Integer requiredServer,
@Param("requiredDesign") Integer requiredDesign,
@Param("requiredPlanner") Integer requiredPlanner,
@Param("requiredAIEngineer") Integer requiredAIEngineer,
Pageable pageable
);
Page<Project> findProjectsByStartDateLessThanEqualOrEndDateGreaterThanEqual(
LocalDate startDate, LocalDate endDate, Pageable pageable);


ProjectIdAndContent findProjectIdAndContentByProjectId(Long projectId);

Expand Down
Loading