-
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.
test : #140 게시판, 게시판 좋아요 더미데이터 API 생성
- Loading branch information
Showing
6 changed files
with
122 additions
and
1 deletion.
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
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
40 changes: 40 additions & 0 deletions
40
src/main/java/com/server/capple/dummy/DummyController.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,40 @@ | ||
package com.server.capple.dummy; | ||
|
||
import com.server.capple.global.common.BaseResponse; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Tag(name = "더미데이터 생성 API", description = "더미데이터 생성을 위한 API입니다.") | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/dummy") | ||
public class DummyController { | ||
|
||
private final DummyService dummyService; | ||
|
||
@Operation(summary = "게시글,게시글 좋아요 더미 생성 API", description = "게시글과 게시글 좋아요 더미를 생성합니다." + | ||
"멤버 더미 먼저 생성 후 실행해주세요.") | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "COMMON200", description = "성공"), | ||
}) | ||
@PostMapping("/board") | ||
private BaseResponse<Object> generateDummyBoards(@RequestParam("num") int num) { | ||
return BaseResponse.onSuccess(dummyService.generateDummyBoards(num)); | ||
} | ||
|
||
@Operation(summary = "멤버 더미 생성 API", description = "멤버 더미를 생성합니다.") | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "COMMON200", description = "성공"), | ||
}) | ||
@PostMapping("/member") | ||
private BaseResponse<Object> generateDummyMembers() { | ||
return BaseResponse.onSuccess(dummyService.generateDummyMembers()); | ||
} | ||
} |
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,56 @@ | ||
package com.server.capple.dummy; | ||
|
||
|
||
import com.server.capple.domain.board.repository.BoardHeartRedisRepository; | ||
import com.server.capple.domain.board.repository.BoardRepository; | ||
import com.server.capple.domain.member.entity.Member; | ||
import com.server.capple.domain.member.repository.MemberRepository; | ||
import jakarta.persistence.EntityManager; | ||
import jakarta.persistence.PersistenceContext; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static com.server.capple.domain.member.entity.Role.ROLE_ACADEMIER; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class DummyService { | ||
private final BoardRepository boardRepository; | ||
private final BoardHeartRedisRepository boardHeartRedisRepository; | ||
private final MemberRepository memberRepository; | ||
|
||
@PersistenceContext | ||
private EntityManager em; | ||
|
||
@Transactional | ||
public Object generateDummyBoards(int num) { | ||
boardRepository.generateDummyBoards(num); | ||
em.flush(); | ||
boardHeartRedisRepository.generateDummyBoardLikes(num); | ||
return null; | ||
} | ||
|
||
@Transactional | ||
public Object generateDummyMembers() { | ||
List<Member> members = new ArrayList<>(); | ||
|
||
for (long i = 1; i <= 10; i++) { | ||
Member member = Member.builder() | ||
.id(i) | ||
.nickname("User" + i) | ||
.email("user" + i + "@example.com") | ||
.sub("sub" + i) | ||
.role(ROLE_ACADEMIER) | ||
.build(); | ||
|
||
members.add(member); | ||
} | ||
|
||
memberRepository.saveAll(members); | ||
return null; | ||
} | ||
} |