Skip to content

Commit

Permalink
Merge branch 'weekly' into feat/Step3-kakao-tech-campus#112-testcode
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-mae authored Nov 10, 2023
2 parents 248e3f1 + 32c762c commit 15759f7
Show file tree
Hide file tree
Showing 26 changed files with 372 additions and 156 deletions.
Binary file added dump.rdb
Binary file not shown.
6 changes: 6 additions & 0 deletions src/main/java/com/example/tily/alarm/AlarmRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.springframework.data.domain.Sort;
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;

Expand All @@ -15,5 +16,10 @@ public interface AlarmRepository extends JpaRepository<Alarm, Long> {
"where a.receiver.id=:receiverId and a.comment.writer.id!=:receiverId")
List<Alarm> findAllByReceiverId(@Param("receiverId") Long receiverId, Sort sort);

@Modifying
void deleteByCommentId(Long commentId);

@Modifying
@Query("delete from Alarm a where a.comment.id in :commentIds")
void deleteByCommentIds(List<Long> commentIds);
}
1 change: 0 additions & 1 deletion src/main/java/com/example/tily/alarm/AlarmRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
public class AlarmRequest {

public record ReadAlarmDTO(List<AlarmDTO> alarms) {

public record AlarmDTO(Long id) {
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/com/example/tily/alarm/AlarmResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ public class AlarmResponse {

public record RoadmapDTO(Long id, String name) {
public RoadmapDTO(Roadmap roadmap) {
this(roadmap.getId(), roadmap.getName());
this(roadmap.getId(), roadmap.getName()
);
}
}

Expand Down Expand Up @@ -41,10 +42,11 @@ public AlarmDTO(Alarm alarm){
alarm.getCreatedDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")),
new RoadmapDTO(alarm.getTil().getRoadmap()),
new StepDTO(alarm.getTil().getStep()),
new SenderDTO(alarm.getComment().getWriter()));
new SenderDTO(alarm.getComment().getWriter())
);
}
}

public record FindAllDTO(List<AlarmDTO> alarms) {
public record FindAllDTO(List<AlarmDTO> alarms) {
}
}
11 changes: 10 additions & 1 deletion src/main/java/com/example/tily/comment/CommentRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,23 @@
import java.util.List;

public interface CommentRepository extends JpaRepository<Comment, Long> {

@Modifying
@Query("select c from Comment c join fetch c.writer where c.til.id=:tilId")
List<Comment> findByTilId(@Param("tilId") Long tilId);

List<Comment> findByWriterId(Long writerId);

@Query("select c from Comment c where c.til.id in :tilIds")
List<Comment> findByTilIds(@Param("tilIds") List<Long> tilIds);

@Modifying
@Query("update Comment c SET c.isDeleted = true WHERE c.isDeleted = false AND c.id = :commentId")
void softDeleteCommentById(Long commentId);

@Modifying
@Query("update Comment c SET c.isDeleted = true WHERE c.isDeleted = false AND c.id IN :commentIds")
void softDeleteCommentsByIds(List<Long> commentIds);

@Modifying
@Query("update Comment c SET c.isDeleted = true WHERE c.isDeleted = false AND c.til.id = :tilId")
void softDeleteCommentsByTilId(Long tilId);
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/example/tily/comment/CommentRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

public class CommentRequest {

public record CreateCommentDTO(Long roadmapId, Long stepId, Long tilId, @NotBlank(message = "댓글 내용을 입력해주세요.") String content) {
public record CreateCommentDTO(Long roadmapId,
Long stepId,
Long tilId,
@NotBlank(message = "댓글 내용을 입력해주세요.") String content) {
}

public record UpdateCommentDTO(@NotBlank(message = "댓글 내용을 입력해주세요.") String content) {
Expand Down
20 changes: 17 additions & 3 deletions src/main/java/com/example/tily/comment/CommentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
@RequiredArgsConstructor
@Service
public class CommentService {

private final RoadmapRepository roadmapRepository;
private final StepRepository stepRepository;
private final TilRepository tilRepository;
Expand All @@ -43,19 +44,32 @@ public CommentResponse.CreateCommentDTO createComment(CommentRequest.CreateComme

String content = requestDTO.content();

Comment comment = Comment.builder().roadmap(roadmap).step(step).writer(user).til(til).content(content).build();
Comment comment = Comment.builder().
roadmap(roadmap).
step(step).
writer(user).
til(til).
content(content).
build();
commentRepository.save(comment);

// 댓글 작성하면 알림 생성
Alarm alarm = Alarm.builder().til(til).receiver(til.getWriter()).comment(comment).isRead(false).build();
Alarm alarm = Alarm.builder().
til(til).
receiver(til.getWriter()).
comment(comment).
isRead(false).
build();
alarmRepository.save(alarm);

// til내 댓글 갯수 증가
til.addCommentNum();

return new CommentResponse.CreateCommentDTO(comment);
}

@Transactional
public void updateComment(CommentRequest.UpdateCommentDTO requestDTO, Long commentId, User user) {

Comment comment = commentRepository.findById(commentId)
.orElseThrow(() -> new CustomException(ExceptionCode.COMMENT_NOT_FOUND));

Expand Down
10 changes: 6 additions & 4 deletions src/main/java/com/example/tily/roadmap/Roadmap.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.example.tily.roadmap;

import com.example.tily.BaseTimeEntity;
import com.example.tily.roadmap.relation.UserRoadmap;
import com.example.tily.user.User;
import lombok.AccessLevel;
import lombok.Builder;
Expand All @@ -11,8 +10,6 @@
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand All @@ -21,6 +18,7 @@
@SQLDelete(sql = "UPDATE roadmap_tb SET is_deleted = true WHERE id = ?")
@Where(clause = "is_deleted = false")
public class Roadmap extends BaseTimeEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
Expand Down Expand Up @@ -75,12 +73,16 @@ public Roadmap(Long id, User creator, Category category, String name, String des
this.image = image;
}

public void update(RoadmapRequest.UpdateGroupRoadmapDTO roadmap){
public void update(RoadmapRequest.UpdateRoadmapDTO roadmap){
this.name = roadmap.name();
this.description = roadmap.description();
this.isPublic = roadmap.isPublic();
this.isRecruit = roadmap.isRecruit();
}

public void addStepNum() {
this.stepNum++;
}

public void updateImage (String image) {this.image = image; }
}
46 changes: 23 additions & 23 deletions src/main/java/com/example/tily/roadmap/RoadmapController.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,40 @@ public class RoadmapController {
// 로드맵 생성하기
@PostMapping("/roadmaps")
public ResponseEntity<?> createRoadmap(@RequestBody @Valid RoadmapRequest.CreateRoadmapDTO requestDTO, Errors errors,
@AuthenticationPrincipal CustomUserDetails userDetails){
@AuthenticationPrincipal CustomUserDetails userDetails){
RoadmapResponse.CreateRoadmapDTO responseDTO = roadmapService.createRoadmap(requestDTO, userDetails.getUser());
return ResponseEntity.ok().body(ApiUtils.success(responseDTO));
}

// 틸리 로드맵 생성하기 - 임시 api
@PostMapping("/roadmaps/tily")
public ResponseEntity<?> createTilyRoadmap(@RequestBody @Valid RoadmapRequest.CreateTilyRoadmapDTO requestDTO, Errors errors,
@AuthenticationPrincipal CustomUserDetails userDetails){
@AuthenticationPrincipal CustomUserDetails userDetails){
RoadmapResponse.CreateRoadmapDTO responseDTO = roadmapService.createTilyRoadmap(requestDTO, userDetails.getUser());
return ResponseEntity.ok().body(ApiUtils.success(responseDTO));
}

// 틸리, 그룹 로드맵 정보 조회하기
// 로드맵 정보 조회하기 (틸리, 그룹)
@GetMapping("/roadmaps/{id}")
public ResponseEntity<?> findGroupRoadmap(@PathVariable Long id, @AuthenticationPrincipal CustomUserDetails userDetails){
public ResponseEntity<?> findRoadmap(@PathVariable Long id, @AuthenticationPrincipal CustomUserDetails userDetails){
User user = Optional.ofNullable(userDetails).map(CustomUserDetails::getUser).orElse(null);
RoadmapResponse.FindGroupRoadmapDTO responseDTO = roadmapService.findGroupRoadmap(id, user);
RoadmapResponse.FindRoadmapDTO responseDTO = roadmapService.findRoadmap(id, user);

return ResponseEntity.ok().body(ApiUtils.success(responseDTO));
}

// 그룹 로드맵 정보 수정하기
// 로드맵 정보 수정하기
@PatchMapping("/roadmaps/{id}")
public ResponseEntity<?> updateGroupRoadmap(@RequestBody @Valid RoadmapRequest.UpdateGroupRoadmapDTO requestDTO, Errors errors,
@PathVariable Long id, @AuthenticationPrincipal CustomUserDetails userDetails){
roadmapService.updateGroupRoadmap(id, requestDTO, userDetails.getUser());
public ResponseEntity<?> updateRoadmap(@RequestBody @Valid RoadmapRequest.UpdateRoadmapDTO requestDTO, Errors errors,
@PathVariable Long id, @AuthenticationPrincipal CustomUserDetails userDetails){
roadmapService.updateRoadmap(id, requestDTO, userDetails.getUser());
return ResponseEntity.ok().body(ApiUtils.success(null));
}

// 로드맵 삭제
@DeleteMapping("/roadmaps/{id}")
public ResponseEntity<?> deleteRoadmap(@PathVariable Long id, @AuthenticationPrincipal CustomUserDetails userDetails){
roadmapService.deleteRoadmap(id, userDetails.getUser());
return ResponseEntity.ok().body(ApiUtils.success(null));
}

Expand Down Expand Up @@ -84,22 +91,22 @@ public ResponseEntity<?> applyTilyRoadmap(@PathVariable("tilyId") Long tilyId, @
return ResponseEntity.ok().body(ApiUtils.success(null));
}

// 참가 코드로 로드맵 참여하기
// 참가 코드로 그룹 로드맵 참여하기
@PostMapping("/roadmaps/groups/participate")
public ResponseEntity<?> participateRoadmap(@RequestBody @Valid RoadmapRequest.ParticipateRoadmapDTO requestDTO, Errors errors,
@AuthenticationPrincipal CustomUserDetails userDetails){
RoadmapResponse.ParticipateRoadmapDTO responseDTO = roadmapService.participateRoadmap(requestDTO, userDetails.getUser());
return ResponseEntity.ok().body(ApiUtils.success(responseDTO));
}

// 로드맵의 구성원 전체 조회하기
// 그룹 로드맵의 구성원 전체 조회하기
@GetMapping("/roadmaps/groups/{groupId}/members")
public ResponseEntity<?> findRoadmapMembers(@PathVariable Long groupId, @AuthenticationPrincipal CustomUserDetails userDetails){
RoadmapResponse.FindRoadmapMembersDTO responseDTO = roadmapService.findRoadmapMembers(groupId, userDetails.getUser());
return ResponseEntity.ok().body(ApiUtils.success(responseDTO));
}

// 로드맵의 구성원 역할 바꾸기
// 그룹 로드맵의 구성원 역할 바꾸기
@PatchMapping("/roadmaps/groups/{groupId}/members/{memberId}")
public ResponseEntity<?> changeMemberRole(@RequestBody @Valid RoadmapRequest.ChangeMemberRoleDTO requestDTO, Errors errors,
@PathVariable Long groupId, @PathVariable Long memberId,
Expand All @@ -108,40 +115,33 @@ public ResponseEntity<?> changeMemberRole(@RequestBody @Valid RoadmapRequest.Cha
return ResponseEntity.ok().body(ApiUtils.success(null));
}

// 로드맵의 구성원 강퇴하기
// 그룹 로드맵의 구성원 강퇴하기
@DeleteMapping("/roadmaps/groups/{groupId}/members/{memberId}")
public ResponseEntity<?> dismissMember(@PathVariable Long groupId, @PathVariable Long memberId,
@AuthenticationPrincipal CustomUserDetails userDetails){
roadmapService.dismissMember(groupId, memberId, userDetails.getUser());
return ResponseEntity.ok().body(ApiUtils.success(null));
}

// 로드맵에 신청한 사람들 목록 조회하기
// 그룹 로드맵에 신청한 사람들 목록 조회하기
@GetMapping("/roadmaps/groups/{groupId}/members/apply")
public ResponseEntity<?> findAppliedUsers(@PathVariable Long groupId, @AuthenticationPrincipal CustomUserDetails userDetails){
RoadmapResponse.FindAppliedUsersDTO responseDTO = roadmapService.findAppliedUsers(groupId, userDetails.getUser());
return ResponseEntity.ok().body(ApiUtils.success(responseDTO));
}

// 로드맵 참여 신청 승인
// 그룹 로드맵 참여 신청 승인
@PostMapping("/roadmaps/groups/{groupId}/members/{memberId}/accept")
public ResponseEntity<?> acceptApplication(@PathVariable Long groupId, @PathVariable Long memberId, @AuthenticationPrincipal CustomUserDetails userDetails){
roadmapService.acceptApplication(groupId, memberId, userDetails.getUser());
return ResponseEntity.ok().body(ApiUtils.success(null));
}

// 로드맵 참여 신청 거절
// 그룹 로드맵 참여 신청 거절
@DeleteMapping("/roadmaps/groups/{groupId}/members/{memberId}/reject")
public ResponseEntity<?> rejectApplication(@PathVariable Long groupId, @PathVariable Long memberId,
@AuthenticationPrincipal CustomUserDetails userDetails){
roadmapService.rejectApplication(groupId, memberId, userDetails.getUser());
return ResponseEntity.ok().body(ApiUtils.success(null));
}

// 그룹 로드맵 삭제
@DeleteMapping("/roadmaps/{id}")
public ResponseEntity<?> deleteRoadmap(@PathVariable Long id, @AuthenticationPrincipal CustomUserDetails userDetails){
roadmapService.deleteRoadmap(id, userDetails.getUser());
return ResponseEntity.ok().body(ApiUtils.success(null));
}
}
16 changes: 1 addition & 15 deletions src/main/java/com/example/tily/roadmap/RoadmapRequest.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,13 @@
package com.example.tily.roadmap;

import com.example.tily.roadmap.relation.GroupRole;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import java.time.LocalDateTime;
import java.util.List;

public class RoadmapRequest {

public record CreateIndividualRoadmapDTO(
@NotBlank(message = "이름을 입력해주세요.")
@Size(min=2, max=20, message = "이름은 2자에서 20자 이내여야 합니다.")
String name
) { }
public record CreateGroupRoadmapDTO(
String name,
String description,
boolean isPublic
) { }

public record CreateRoadmapDTO (
@NotBlank(message = "카테고리를 선택해주세요.")
String category,
Expand All @@ -37,7 +23,7 @@ public record CreateTilyRoadmapDTO(
List<StepDTO> steps
) { }

public record UpdateGroupRoadmapDTO(
public record UpdateRoadmapDTO(
String name,
String description,
boolean isPublic,
Expand Down
Loading

0 comments on commit 15759f7

Please sign in to comment.