Skip to content

Commit

Permalink
Merge branch 'develop' into feat/21
Browse files Browse the repository at this point in the history
  • Loading branch information
nykoh2001 authored Mar 3, 2024
2 parents 0fd95a8 + d715c0a commit 578f9a8
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,11 @@ public ApiResponse<?> finishMatching(final @NotNull @PathVariable("postId") Long
public ApiResponse<?> getWaitinglist(final @NotNull @PathVariable("postId") Long postId) {
return ApiResponse.success(matchingService.getWaitingList(postId));
}

@PostMapping("/{postId}/chats")
public ApiResponse<?> createMatchingWaiting(@MemberId Long memberId,
final @NotNull @PathVariable("postId") Long postId) {
matchingService.createMatchingWaiting(memberId, postId);
return ApiResponse.success(SuccessMessage.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public class MockJwtController {

@GetMapping
public JwtTokenResponse getToken(){
return jwtUtil.generateTokens(Long.valueOf(1), Type.SPROUT);
return jwtUtil.generateTokens(Long.valueOf(2), Type.SPROUT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ public ApiResponse<?> createPost(@MemberId Long memberId, @Valid @RequestBody Po
return ApiResponse.success(SuccessMessage.CREATED);
}

@DeleteMapping("/{postId}")
public ApiResponse<?> deletePost(@MemberId Long memberId, @PathVariable Long postId) {
postService.deletePost(memberId, postId);
return ApiResponse.success(SuccessMessage.OK);
}

@GetMapping
public ApiResponse<List<PostResponse>> getAllPosts() {
return ApiResponse.success(postService.getAllPosts());
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/harang/server/domain/Category.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class Category {
@Column(name = "name", nullable = false)
private String name;

@OneToMany(mappedBy = "category")
@OneToMany(mappedBy = "category", cascade = CascadeType.ALL)
private List<PostCategory> postCategoryList = new ArrayList<>();

@Builder
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/harang/server/domain/Help.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class Help {
private String name;

/* Relation Parent Mapping */
@OneToMany(mappedBy = "help")
@OneToMany(mappedBy = "help", cascade = CascadeType.ALL)
private List<MemberHelp> memberHelpList = new ArrayList<>();

@Builder
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/harang/server/domain/Location.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Location {
@Column(name = "id", nullable = false)
private Long id;

@OneToOne(fetch = FetchType.LAZY)
@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "post_id")
private Post post;

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/harang/server/domain/MemberInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public class MemberInfo {
private String refreshToken;

/* Relation Parent Mapping */
@OneToMany(mappedBy = "memberInfo")
@OneToMany(mappedBy = "memberInfo", cascade = CascadeType.ALL)
private List<MemberHelp> memberHelpList = new ArrayList<>();

@OneToMany(mappedBy = "memberInfo")
@OneToMany(mappedBy = "memberInfo", cascade = CascadeType.ALL)
private List<Certification> certificationList = new ArrayList<>();

@Builder
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/harang/server/domain/Post.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ public class Post {
private Status status = Status.WAITING;

/* Relation Parent Mapping */
@OneToMany(mappedBy = "post")
@OneToMany(mappedBy = "post", cascade = CascadeType.ALL)
private List<Matching> matchingList = new ArrayList<>();

@OneToMany(mappedBy = "post")
@OneToMany(mappedBy = "post", cascade = CascadeType.ALL)
private List<PostCategory> postCategoryList = new ArrayList<>();

@OneToMany(mappedBy = "post")
@OneToMany(mappedBy = "post", cascade = CascadeType.ALL)
private List<Waiting> waitingList = new ArrayList<>();

@Builder
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/harang/server/dto/type/ErrorMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public enum ErrorMessage {
MATCHING_ALREADY_DONE("50004", HttpStatus.INTERNAL_SERVER_ERROR, "이미 종료된 매칭입니다."),
ONLY_SPROUT_CAN_CREATE_MATCH("50005", HttpStatus.INTERNAL_SERVER_ERROR, "새싹인 유저만 매칭을 생성할 수 있습니다."),
ONLY_WATERING_CAN_HELP_SPROUT("50006", HttpStatus.INTERNAL_SERVER_ERROR, "물뿌리개인 유저만 새싹을 도와줄 수 있습니다."),
CHAT_ALREADY_STARTED("50007", HttpStatus.INTERNAL_SERVER_ERROR, "이미 채팅을 시작한 게시글입니다."),
;

private String code;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
package org.harang.server.repository;

import jakarta.transaction.Transactional;
import org.harang.server.domain.Location;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

public interface LocationRepository extends JpaRepository<Location, Long> {
}
Location findByPostId(Long PostId);

@Transactional
@Modifying
@Query("DELETE FROM Location l WHERE l.post.id = :postId")
void deleteByPostId(Long postId);
}
27 changes: 27 additions & 0 deletions src/main/java/org/harang/server/service/MatchingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,31 @@ public List<WaitingResponse> getWaitingList(Long postId) {
.build()).toList();
return waitingListResponse;
}

@Transactional
public void createMatchingWaiting(Long memberId, Long postId) {
Post post = postRepository.findByIdOrThrow(postId);
Member member = memberRepository.findByIdOrThrow(memberId);

// 이미 사용자가 채팅을 시작한 글이라면 예외 발생
List<Long> waitingMemberIdList = waitingRepository.findAllByPostId(postId)
.stream().map(w -> w.getMember().getId()).toList();
for (Long m : waitingMemberIdList) {
if (m.equals(memberId)) {
throw new CustomException(ErrorMessage.CHAT_ALREADY_STARTED);
}
}

// 사용자가 물뿌리개가 아니라면 예외 발생
if (!member.getType().equals(Type.WATERING)) {
throw new CustomException(ErrorMessage.ONLY_WATERING_CAN_HELP_SPROUT);
}

Waiting newWaiting = Waiting.builder()
.post(post)
.member(member)
.build();

waitingRepository.save(newWaiting);
}
}
8 changes: 8 additions & 0 deletions src/main/java/org/harang/server/service/PostService.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,13 @@ public List<PostResponse> getSearchResults(String title) {
.stream()
.map(p -> PostResponse.of(p))
.toList();

@Transactional
public void deletePost(Long memberId, Long postId) {
Post post = postRepository.findByIdOrThrow(postId);

locationRepository.deleteByPostId(postId);
postRepository.delete(post);

}
}

0 comments on commit 578f9a8

Please sign in to comment.