Skip to content

Commit

Permalink
Merge pull request #83 from study-hub-inu/feat/SH-303-delete-all
Browse files Browse the repository at this point in the history
Feat/sh 303 delete all
  • Loading branch information
wellbeing-dough authored Feb 11, 2024
2 parents 360e338 + 015482d commit 8786aad
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package kr.co.studyhubinu.studyhubserver.apply.domain;

import static com.querydsl.core.types.PathMetadataFactory.*;

import com.querydsl.core.types.dsl.*;

import com.querydsl.core.types.PathMetadata;
import javax.annotation.processing.Generated;
import com.querydsl.core.types.Path;


/**
* QRejectEntity is a Querydsl query type for RejectEntity
*/
@Generated("com.querydsl.codegen.DefaultEntitySerializer")
public class QRejectEntity extends EntityPathBase<RejectEntity> {

private static final long serialVersionUID = -1259208686L;

public static final QRejectEntity rejectEntity = new QRejectEntity("rejectEntity");

public final kr.co.studyhubinu.studyhubserver.common.domain.QBaseTimeEntity _super = new kr.co.studyhubinu.studyhubserver.common.domain.QBaseTimeEntity(this);

//inherited
public final DateTimePath<java.time.LocalDateTime> createdDate = _super.createdDate;

public final NumberPath<Long> id = createNumber("id", Long.class);

//inherited
public final DateTimePath<java.time.LocalDateTime> modifiedDate = _super.modifiedDate;

public final NumberPath<Long> rejectedUserId = createNumber("rejectedUserId", Long.class);

public final StringPath rejectReason = createString("rejectReason");

public final NumberPath<Long> studyId = createNumber("studyId", Long.class);

public QRejectEntity(String variable) {
super(RejectEntity.class, forVariable(variable));
}

public QRejectEntity(Path<? extends RejectEntity> path) {
super(path.getType(), path.getMetadata());
}

public QRejectEntity(PathMetadata metadata) {
super(RejectEntity.class, metadata);
}

}

Binary file removed build/jacoco/test.exec
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import kr.co.studyhubinu.studyhubserver.bookmark.service.BookmarkService;
import kr.co.studyhubinu.studyhubserver.user.dto.data.UserId;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

Expand All @@ -30,4 +31,11 @@ public ResponseEntity<GetBookmarkedResponse> checkBookmarked(@PathVariable final
return ResponseEntity.ok().body(new GetBookmarkedResponse(result));
}

@Operation(summary = "북마크 전체 삭제", description = "헤더에 userId 보내주시면 됩니다.")
@DeleteMapping("/v1/bookmark")
public ResponseEntity<HttpStatus> deleteAllBookmark(final UserId userId) {
bookmarkService.deleteAllBookmark(userId.getId());
return ResponseEntity.noContent().build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import kr.co.studyhubinu.studyhubserver.bookmark.domain.BookmarkEntity;
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;
import org.springframework.stereotype.Repository;

import java.util.List;
Expand All @@ -15,4 +18,7 @@ public interface BookmarkRepository extends JpaRepository<BookmarkEntity, Long>,
Long countByUserId(Long userId);

List<BookmarkEntity> findByUserId(Long id);
@Modifying(clearAutomatically = true, flushAutomatically = true)
@Query("DELETE FROM BookmarkEntity bm WHERE bm.userId = :userId")
void deleteAllBookmarksByUserId(@Param("userId") Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@Transactional(readOnly = true)
public class BookmarkService {

private final BookmarkRepository bookMarkRepository;
private final BookmarkRepository bookmarkRepository;
private final UserRepository userRepository;
private final StudyPostRepository studyPostRepository;

Expand All @@ -26,14 +26,14 @@ public boolean doBookMark(Long userId, Long postId) {
AtomicBoolean created = new AtomicBoolean(false);
validateUserExist(userId);
validateStudyPostExist(postId);
bookMarkRepository.findByUserIdAndPostId(userId, postId).ifPresentOrElse(
bookmarkRepository.findByUserIdAndPostId(userId, postId).ifPresentOrElse(
bookMark -> {
bookMarkRepository.delete(bookMark);
bookmarkRepository.delete(bookMark);
created.set(false);
},
() -> {
BookmarkEntity bookmark = new BookmarkEntity(postId, userId);
bookMarkRepository.save(bookmark);
bookmarkRepository.save(bookmark);
created.set(true);
}
);
Expand All @@ -43,7 +43,7 @@ public boolean doBookMark(Long userId, Long postId) {
public boolean checkBookmarked(Long userId, Long postId) {
validateUserExist(userId);
validateStudyPostExist(postId);
return bookMarkRepository.findByUserIdAndPostId(userId, postId).isPresent();
return bookmarkRepository.findByUserIdAndPostId(userId, postId).isPresent();
}

private void validateUserExist(Long userId) {
Expand All @@ -53,5 +53,10 @@ private void validateUserExist(Long userId) {
private void validateStudyPostExist(Long postId) {
studyPostRepository.findById(postId).orElseThrow(PostNotFoundException::new);
}


@Transactional
public void deleteAllBookmark(Long userId) {
validateUserExist(userId);
bookmarkRepository.deleteAllBookmarksByUserId(userId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,11 @@ public ResponseEntity<HttpStatus> closePost(@PathVariable("post-id") Long postId
public ResponseEntity<FindRecommendPostsResponse> findRecommendPosts(@RequestParam String keyword) {
return ResponseEntity.ok().body(studyPostFindService.findRecommendPosts(keyword));
}

@Operation(summary = "내가쓴 게시글 전체 삭제", description = "헤더에 userId 보내주시면 됩니다.")
@DeleteMapping("/v1/all/study-post")
public ResponseEntity<HttpStatus> deleteAllPosts(final UserId userId) {
studyPostService.deleteAllPosts(userId.getId());
return ResponseEntity.noContent().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ public interface StudyPostRepository extends JpaRepository<StudyPostEntity, Long
List<StudyPostEntity> findByPostedUserId(Long id);

@Transactional
@Modifying(clearAutomatically = true)
@Modifying(clearAutomatically = true, flushAutomatically = true)
@Query("UPDATE StudyPostEntity sp SET sp.close = true WHERE sp.studyStartDate = :studyStartDate AND sp.close = false")
void closeStudyPostsByStartDate(@Param("studyStartDate") LocalDate studyStartDate);

Optional<StudyPostEntity> findByStudyId(Long studyId);

@Modifying(clearAutomatically = true, flushAutomatically = true)
@Query("DELETE FROM StudyPostEntity sp WHERE sp.postedUserId = :userId")
void deleteAllStudyPostByUserId(@Param("userId") Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,10 @@ private void validateStartDateOverEndDate(LocalDate studyStartDate, LocalDate st
throw new PostEndDateConflictException();
}
}

@Transactional
public void deleteAllPosts(Long userId) {
isExistUser(userId);
studyPostRepository.deleteAllStudyPostByUserId(userId);
}
}

0 comments on commit 8786aad

Please sign in to comment.