From 09287ab26f644b5947e14deb1396c88711b06a96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=BB=A4=EC=B0=AC?= <44027393+leegwichan@users.noreply.github.com> Date: Fri, 27 Dec 2024 20:01:03 +0900 Subject: [PATCH] =?UTF-8?q?[FEAT]=20=EB=A9=A4=EB=B2=84=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20API=20=EA=B5=AC=ED=98=84=20(#34)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/debatetimer/controller/.gitkeep | 0 .../controller/member/MemberController.java | 34 +++++++++++ .../member/MemberControllerSwagger.java | 45 +++++++++++++++ .../domain/{ => member}/Member.java | 2 +- .../ParliamentaryTable.java | 8 +-- .../ParliamentaryTimeBox.java | 2 +- .../dto/member/MemberCreateRequest.java | 14 +++++ .../dto/member/MemberCreateResponse.java | 17 ++++++ .../debatetimer/dto/member/TableResponse.java | 20 +++++++ .../dto/member/TableResponses.java | 22 +++++++ .../com/debatetimer/dto/member/TableType.java | 7 +++ .../java/com/debatetimer/repository/.gitkeep | 0 .../repository/member/MemberRepository.java | 11 ++++ .../ParliamentaryTableRepository.java | 11 ++++ .../java/com/debatetimer/service/.gitkeep | 0 .../service/member/MemberService.java | 34 +++++++++++ .../com/debatetimer/BaseControllerTest.java | 9 +++ .../java/com/debatetimer/BaseServiceTest.java | 9 +++ .../member/MemberControllerTest.java | 57 +++++++++++++++++++ .../domain/{ => member}/MemberTest.java | 2 +- .../ParliamentaryTableTest.java | 38 +++++++++---- .../ParliamentaryTimeBoxTest.java | 2 +- .../service/member/MemberServiceTest.java | 52 +++++++++++++++++ 23 files changed, 378 insertions(+), 18 deletions(-) delete mode 100644 src/main/java/com/debatetimer/controller/.gitkeep create mode 100644 src/main/java/com/debatetimer/controller/member/MemberController.java create mode 100644 src/main/java/com/debatetimer/controller/member/MemberControllerSwagger.java rename src/main/java/com/debatetimer/domain/{ => member}/Member.java (96%) rename src/main/java/com/debatetimer/domain/{parliamentary_debate => parliamentary}/ParliamentaryTable.java (87%) rename src/main/java/com/debatetimer/domain/{parliamentary_debate => parliamentary}/ParliamentaryTimeBox.java (97%) create mode 100644 src/main/java/com/debatetimer/dto/member/MemberCreateRequest.java create mode 100644 src/main/java/com/debatetimer/dto/member/MemberCreateResponse.java create mode 100644 src/main/java/com/debatetimer/dto/member/TableResponse.java create mode 100644 src/main/java/com/debatetimer/dto/member/TableResponses.java create mode 100644 src/main/java/com/debatetimer/dto/member/TableType.java delete mode 100644 src/main/java/com/debatetimer/repository/.gitkeep create mode 100644 src/main/java/com/debatetimer/repository/member/MemberRepository.java create mode 100644 src/main/java/com/debatetimer/repository/parliamentary/ParliamentaryTableRepository.java delete mode 100644 src/main/java/com/debatetimer/service/.gitkeep create mode 100644 src/main/java/com/debatetimer/service/member/MemberService.java create mode 100644 src/test/java/com/debatetimer/controller/member/MemberControllerTest.java rename src/test/java/com/debatetimer/domain/{ => member}/MemberTest.java (96%) rename src/test/java/com/debatetimer/domain/{parliamentary_debate => parliamentary}/ParliamentaryTableTest.java (51%) rename src/test/java/com/debatetimer/domain/{parliamentary_debate => parliamentary}/ParliamentaryTimeBoxTest.java (95%) create mode 100644 src/test/java/com/debatetimer/service/member/MemberServiceTest.java diff --git a/src/main/java/com/debatetimer/controller/.gitkeep b/src/main/java/com/debatetimer/controller/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/src/main/java/com/debatetimer/controller/member/MemberController.java b/src/main/java/com/debatetimer/controller/member/MemberController.java new file mode 100644 index 0000000..7730699 --- /dev/null +++ b/src/main/java/com/debatetimer/controller/member/MemberController.java @@ -0,0 +1,34 @@ +package com.debatetimer.controller.member; + +import com.debatetimer.dto.member.MemberCreateRequest; +import com.debatetimer.dto.member.MemberCreateResponse; +import com.debatetimer.dto.member.TableResponses; +import com.debatetimer.service.member.MemberService; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +public class MemberController implements MemberControllerSwagger{ + + private final MemberService memberService; + + @Override + @GetMapping("/api/table") + public TableResponses getTables(@RequestParam Long memberId) { + return memberService.getTables(memberId); + } + + @Override + @PostMapping("/api/member") + @ResponseStatus(HttpStatus.CREATED) + public MemberCreateResponse createMember(@RequestBody MemberCreateRequest request) { + return memberService.createMember(request); + } +} diff --git a/src/main/java/com/debatetimer/controller/member/MemberControllerSwagger.java b/src/main/java/com/debatetimer/controller/member/MemberControllerSwagger.java new file mode 100644 index 0000000..6db2b07 --- /dev/null +++ b/src/main/java/com/debatetimer/controller/member/MemberControllerSwagger.java @@ -0,0 +1,45 @@ +package com.debatetimer.controller.member; + +import com.debatetimer.dto.member.MemberCreateRequest; +import com.debatetimer.dto.member.MemberCreateResponse; +import com.debatetimer.dto.member.TableResponses; +import com.debatetimer.swagger.annotation.ErrorCode400; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.parameters.RequestBody; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.tags.Tag; + +@Tag(name = "Member API") +public interface MemberControllerSwagger { + + @Operation( + summary = "멤버의 토론 시간표 조회", + responses = { + @ApiResponse( + responseCode = "200", + description = "멤버의 토론 시간표 조회 성공", + content = @Content(schema = @Schema(implementation = TableResponses.class)) + ) + } + ) + @ErrorCode400 + TableResponses getTables(Long memberId); + + @Operation( + summary = "멤버 생성", + requestBody = @RequestBody( + content = @Content(schema = @Schema(implementation = MemberCreateRequest.class)) + ), + responses = { + @ApiResponse( + responseCode = "201", + description = "멤버 생성 성공", + content = @Content(schema = @Schema(implementation = MemberCreateResponse.class)) + ) + } + ) + @ErrorCode400 + MemberCreateResponse createMember(MemberCreateRequest request); +} diff --git a/src/main/java/com/debatetimer/domain/Member.java b/src/main/java/com/debatetimer/domain/member/Member.java similarity index 96% rename from src/main/java/com/debatetimer/domain/Member.java rename to src/main/java/com/debatetimer/domain/member/Member.java index bc46f53..4681a8b 100644 --- a/src/main/java/com/debatetimer/domain/Member.java +++ b/src/main/java/com/debatetimer/domain/member/Member.java @@ -1,4 +1,4 @@ -package com.debatetimer.domain; +package com.debatetimer.domain.member; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; diff --git a/src/main/java/com/debatetimer/domain/parliamentary_debate/ParliamentaryTable.java b/src/main/java/com/debatetimer/domain/parliamentary/ParliamentaryTable.java similarity index 87% rename from src/main/java/com/debatetimer/domain/parliamentary_debate/ParliamentaryTable.java rename to src/main/java/com/debatetimer/domain/parliamentary/ParliamentaryTable.java index b6e5831..86e4937 100644 --- a/src/main/java/com/debatetimer/domain/parliamentary_debate/ParliamentaryTable.java +++ b/src/main/java/com/debatetimer/domain/parliamentary/ParliamentaryTable.java @@ -1,6 +1,6 @@ -package com.debatetimer.domain.parliamentary_debate; +package com.debatetimer.domain.parliamentary; -import com.debatetimer.domain.Member; +import com.debatetimer.domain.member.Member; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; @@ -18,7 +18,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) public class ParliamentaryTable { - private static final String NAME_REGEX = "^[a-zA-Z가-힣]+$"; + private static final String NAME_REGEX = "^[a-zA-Z가-힣 ]+$"; public static final int NAME_MAX_LENGTH = 20; @Id @@ -48,7 +48,7 @@ public ParliamentaryTable(Member member, String name, String agenda, int duratio } private void validate(String name, int duration) { - if (name.isEmpty() || name.length() > NAME_MAX_LENGTH) { + if (name.isBlank() || name.length() > NAME_MAX_LENGTH) { throw new IllegalArgumentException("테이블 이름은 1자 이상 %d자 이하여야 합니다".formatted(NAME_MAX_LENGTH)); } if (!name.matches(NAME_REGEX)) { diff --git a/src/main/java/com/debatetimer/domain/parliamentary_debate/ParliamentaryTimeBox.java b/src/main/java/com/debatetimer/domain/parliamentary/ParliamentaryTimeBox.java similarity index 97% rename from src/main/java/com/debatetimer/domain/parliamentary_debate/ParliamentaryTimeBox.java rename to src/main/java/com/debatetimer/domain/parliamentary/ParliamentaryTimeBox.java index d3152ec..38e86ac 100644 --- a/src/main/java/com/debatetimer/domain/parliamentary_debate/ParliamentaryTimeBox.java +++ b/src/main/java/com/debatetimer/domain/parliamentary/ParliamentaryTimeBox.java @@ -1,4 +1,4 @@ -package com.debatetimer.domain.parliamentary_debate; +package com.debatetimer.domain.parliamentary; import com.debatetimer.domain.BoxType; import com.debatetimer.domain.Stance; diff --git a/src/main/java/com/debatetimer/dto/member/MemberCreateRequest.java b/src/main/java/com/debatetimer/dto/member/MemberCreateRequest.java new file mode 100644 index 0000000..d8f9e0f --- /dev/null +++ b/src/main/java/com/debatetimer/dto/member/MemberCreateRequest.java @@ -0,0 +1,14 @@ +package com.debatetimer.dto.member; + +import com.debatetimer.domain.member.Member; +import io.swagger.v3.oas.annotations.media.Schema; + +public record MemberCreateRequest( + @Schema(description = "멤버 닉네임", example = "콜리") + String nickname +) { + + public Member toMember() { + return new Member(nickname); + } +} diff --git a/src/main/java/com/debatetimer/dto/member/MemberCreateResponse.java b/src/main/java/com/debatetimer/dto/member/MemberCreateResponse.java new file mode 100644 index 0000000..3eafd93 --- /dev/null +++ b/src/main/java/com/debatetimer/dto/member/MemberCreateResponse.java @@ -0,0 +1,17 @@ +package com.debatetimer.dto.member; + +import com.debatetimer.domain.member.Member; +import io.swagger.v3.oas.annotations.media.Schema; + +public record MemberCreateResponse( + @Schema(description = "멤버 아이디", example = "1") + long id, + + @Schema(description = "멤버 닉네임", example = "콜리") + String nickname +) { + + public MemberCreateResponse(Member member) { + this(member.getId(), member.getNickname()); + } +} diff --git a/src/main/java/com/debatetimer/dto/member/TableResponse.java b/src/main/java/com/debatetimer/dto/member/TableResponse.java new file mode 100644 index 0000000..288115d --- /dev/null +++ b/src/main/java/com/debatetimer/dto/member/TableResponse.java @@ -0,0 +1,20 @@ +package com.debatetimer.dto.member; + +import com.debatetimer.domain.parliamentary.ParliamentaryTable; +import io.swagger.v3.oas.annotations.media.Schema; + +public record TableResponse( + @Schema(description = "테이블 이름", example = "테이블1") + String name, + + @Schema(description = "토론 타입", example = "PARLIAMENTARY") + TableType type, + + @Schema(description = "소요 시간 (초 단위)", example = "1800") + int duration +) { + + public TableResponse(ParliamentaryTable parliamentaryTable) { + this(parliamentaryTable.getName(), TableType.PARLIAMENTARY, parliamentaryTable.getDuration()); + } +} diff --git a/src/main/java/com/debatetimer/dto/member/TableResponses.java b/src/main/java/com/debatetimer/dto/member/TableResponses.java new file mode 100644 index 0000000..a5c3b6b --- /dev/null +++ b/src/main/java/com/debatetimer/dto/member/TableResponses.java @@ -0,0 +1,22 @@ +package com.debatetimer.dto.member; + +import com.debatetimer.domain.parliamentary.ParliamentaryTable; +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Schema; +import java.util.List; + +public record TableResponses( + @ArraySchema(schema = @Schema(description = "테이블들", implementation = TableResponse.class)) + List tables +) { + + public static TableResponses from(List parliamentaryTables) { + return new TableResponses(toTableResponses(parliamentaryTables)); + } + + private static List toTableResponses(List parliamentaryTables) { + return parliamentaryTables.stream() + .map(TableResponse::new) + .toList(); + } +} diff --git a/src/main/java/com/debatetimer/dto/member/TableType.java b/src/main/java/com/debatetimer/dto/member/TableType.java new file mode 100644 index 0000000..4d63442 --- /dev/null +++ b/src/main/java/com/debatetimer/dto/member/TableType.java @@ -0,0 +1,7 @@ +package com.debatetimer.dto.member; + +public enum TableType { + + PARLIAMENTARY, + ; +} diff --git a/src/main/java/com/debatetimer/repository/.gitkeep b/src/main/java/com/debatetimer/repository/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/src/main/java/com/debatetimer/repository/member/MemberRepository.java b/src/main/java/com/debatetimer/repository/member/MemberRepository.java new file mode 100644 index 0000000..0333067 --- /dev/null +++ b/src/main/java/com/debatetimer/repository/member/MemberRepository.java @@ -0,0 +1,11 @@ +package com.debatetimer.repository.member; + +import com.debatetimer.domain.member.Member; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface MemberRepository extends JpaRepository { + + default Member getById(Long id) { + return findById(id).orElseThrow(() -> new IllegalArgumentException("해당 회원이 존재하지 않습니다")); + } +} diff --git a/src/main/java/com/debatetimer/repository/parliamentary/ParliamentaryTableRepository.java b/src/main/java/com/debatetimer/repository/parliamentary/ParliamentaryTableRepository.java new file mode 100644 index 0000000..a2ac335 --- /dev/null +++ b/src/main/java/com/debatetimer/repository/parliamentary/ParliamentaryTableRepository.java @@ -0,0 +1,11 @@ +package com.debatetimer.repository.parliamentary; + +import com.debatetimer.domain.member.Member; +import com.debatetimer.domain.parliamentary.ParliamentaryTable; +import java.util.List; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface ParliamentaryTableRepository extends JpaRepository { + + List findAllByMember(Member member); +} diff --git a/src/main/java/com/debatetimer/service/.gitkeep b/src/main/java/com/debatetimer/service/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/src/main/java/com/debatetimer/service/member/MemberService.java b/src/main/java/com/debatetimer/service/member/MemberService.java new file mode 100644 index 0000000..d17e8c1 --- /dev/null +++ b/src/main/java/com/debatetimer/service/member/MemberService.java @@ -0,0 +1,34 @@ +package com.debatetimer.service.member; + +import com.debatetimer.dto.member.MemberCreateRequest; +import com.debatetimer.dto.member.MemberCreateResponse; +import com.debatetimer.dto.member.TableResponses; +import com.debatetimer.domain.member.Member; +import com.debatetimer.domain.parliamentary.ParliamentaryTable; +import com.debatetimer.repository.member.MemberRepository; +import com.debatetimer.repository.parliamentary.ParliamentaryTableRepository; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +public class MemberService { + + private final MemberRepository memberRepository; + private final ParliamentaryTableRepository parliamentaryTableRepository; + + @Transactional(readOnly = true) + public TableResponses getTables(Long memberId) { + Member member = memberRepository.getById(memberId); + List parliamentaryTable = parliamentaryTableRepository.findAllByMember(member); + return TableResponses.from(parliamentaryTable); + } + + @Transactional + public MemberCreateResponse createMember(MemberCreateRequest request) { + Member member = memberRepository.save(request.toMember()); + return new MemberCreateResponse(member); + } +} diff --git a/src/test/java/com/debatetimer/BaseControllerTest.java b/src/test/java/com/debatetimer/BaseControllerTest.java index 38b802a..b9acead 100644 --- a/src/test/java/com/debatetimer/BaseControllerTest.java +++ b/src/test/java/com/debatetimer/BaseControllerTest.java @@ -1,8 +1,11 @@ package com.debatetimer; +import com.debatetimer.repository.member.MemberRepository; +import com.debatetimer.repository.parliamentary.ParliamentaryTableRepository; import io.restassured.RestAssured; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.server.LocalServerPort; @@ -17,4 +20,10 @@ public abstract class BaseControllerTest { void setPort() { RestAssured.port = port; } + + @Autowired + protected MemberRepository memberRepository; + + @Autowired + protected ParliamentaryTableRepository parliamentaryTableRepository; } diff --git a/src/test/java/com/debatetimer/BaseServiceTest.java b/src/test/java/com/debatetimer/BaseServiceTest.java index c2a1b70..3d51eaa 100644 --- a/src/test/java/com/debatetimer/BaseServiceTest.java +++ b/src/test/java/com/debatetimer/BaseServiceTest.java @@ -1,9 +1,18 @@ package com.debatetimer; +import com.debatetimer.repository.member.MemberRepository; +import com.debatetimer.repository.parliamentary.ParliamentaryTableRepository; import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @ExtendWith(DataBaseCleaner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE) public abstract class BaseServiceTest { + + @Autowired + protected MemberRepository memberRepository; + + @Autowired + protected ParliamentaryTableRepository parliamentaryTableRepository; } diff --git a/src/test/java/com/debatetimer/controller/member/MemberControllerTest.java b/src/test/java/com/debatetimer/controller/member/MemberControllerTest.java new file mode 100644 index 0000000..d681408 --- /dev/null +++ b/src/test/java/com/debatetimer/controller/member/MemberControllerTest.java @@ -0,0 +1,57 @@ +package com.debatetimer.controller.member; + +import static org.assertj.core.api.Assertions.assertThat; + +import com.debatetimer.BaseControllerTest; +import com.debatetimer.dto.member.MemberCreateRequest; +import com.debatetimer.dto.member.MemberCreateResponse; +import com.debatetimer.dto.member.TableResponses; +import com.debatetimer.domain.member.Member; +import com.debatetimer.domain.parliamentary.ParliamentaryTable; +import io.restassured.RestAssured; +import io.restassured.http.ContentType; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + +class MemberControllerTest extends BaseControllerTest { + + @Nested + class CreateMember { + + @Test + void 회원을_생성한다() { + MemberCreateRequest request = new MemberCreateRequest("커찬"); + + MemberCreateResponse response = RestAssured.given().log().all() + .contentType(ContentType.JSON) + .body(request) + .when().post("/api/member") + .then().log().all() + .statusCode(201) + .extract().as(MemberCreateResponse.class); + + assertThat(response.nickname()).isEqualTo(request.nickname()); + } + } + + @Nested + class getTables { + + @Test + void 회원의_전체_토론_시간표를_조회한다() { + Member member = memberRepository.save(new Member("커찬")); + parliamentaryTableRepository.save(new ParliamentaryTable(member, "토론 시간표 A", "주제", 1800)); + parliamentaryTableRepository.save(new ParliamentaryTable(member, "토론 시간표 B", "주제", 1900)); + + TableResponses response = RestAssured.given().log().all() + .contentType(ContentType.JSON) + .queryParam("memberId", member.getId()) + .when().get("/api/table") + .then().log().all() + .statusCode(200) + .extract().as(TableResponses.class); + + assertThat(response.tables()).hasSize(2); + } + } +} diff --git a/src/test/java/com/debatetimer/domain/MemberTest.java b/src/test/java/com/debatetimer/domain/member/MemberTest.java similarity index 96% rename from src/test/java/com/debatetimer/domain/MemberTest.java rename to src/test/java/com/debatetimer/domain/member/MemberTest.java index c8f0e49..232b0f0 100644 --- a/src/test/java/com/debatetimer/domain/MemberTest.java +++ b/src/test/java/com/debatetimer/domain/member/MemberTest.java @@ -1,4 +1,4 @@ -package com.debatetimer.domain; +package com.debatetimer.domain.member; import org.junit.jupiter.api.Nested; import org.junit.jupiter.params.ParameterizedTest; diff --git a/src/test/java/com/debatetimer/domain/parliamentary_debate/ParliamentaryTableTest.java b/src/test/java/com/debatetimer/domain/parliamentary/ParliamentaryTableTest.java similarity index 51% rename from src/test/java/com/debatetimer/domain/parliamentary_debate/ParliamentaryTableTest.java rename to src/test/java/com/debatetimer/domain/parliamentary/ParliamentaryTableTest.java index 48ef977..79a900f 100644 --- a/src/test/java/com/debatetimer/domain/parliamentary_debate/ParliamentaryTableTest.java +++ b/src/test/java/com/debatetimer/domain/parliamentary/ParliamentaryTableTest.java @@ -1,18 +1,26 @@ -package com.debatetimer.domain.parliamentary_debate; +package com.debatetimer.domain.parliamentary; -import com.debatetimer.domain.Member; +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import com.debatetimer.domain.member.Member; import org.junit.jupiter.api.Nested; -import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - class ParliamentaryTableTest { @Nested class Validate { + @ParameterizedTest + @ValueSource(strings = {"a bc가다", "가나 다ab"}) + void 테이블_이름은_영문과_한글_띄어쓰기만_가능하다(String name) { + Member member = new Member("member"); + assertThatCode(() -> new ParliamentaryTable(member, name, "agenda", 10)) + .doesNotThrowAnyException(); + } + @ParameterizedTest @ValueSource(ints = {0, ParliamentaryTable.NAME_MAX_LENGTH + 1}) void 테이블_이름은_정해진_길이_이내여야_한다(int length) { @@ -23,18 +31,28 @@ class Validate { } @ParameterizedTest - @ValueSource(strings = {"abc12", "가나다12"}) - void 테이블_이름은_영문과_한글만_가능하다(String name) { + @ValueSource(strings = {"", "\t", "\n"}) + void 테이블_이름은_적어도_한_자_있어야_한다(String name) { + Member member = new Member("member"); + assertThatThrownBy(() -> new ParliamentaryTable(member, name, "agenda", 10)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("테이블 이름은 1자 이상 %d자 이하여야 합니다".formatted(ParliamentaryTable.NAME_MAX_LENGTH)); + } + + @ParameterizedTest + @ValueSource(strings = {"abc12", "가나다12", "abc\tde"}) + void 허용된_글자_이외의_문자는_불가능하다(String name) { Member member = new Member("member"); assertThatThrownBy(() -> new ParliamentaryTable(member, name, "agenda", 10)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("테이블 이름은 영문/한글만 가능합니다"); } - @Test - void 테이블_시간은_양수만_가능하다() { + @ParameterizedTest + @ValueSource(ints = {0, -1, -60}) + void 테이블_시간은_양수만_가능하다(int duration) { Member member = new Member("member"); - assertThatThrownBy(() -> new ParliamentaryTable(member, "name", "agenda", 0)) + assertThatThrownBy(() -> new ParliamentaryTable(member, "name", "agenda", duration)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("시간은 양수만 가능합니다"); } diff --git a/src/test/java/com/debatetimer/domain/parliamentary_debate/ParliamentaryTimeBoxTest.java b/src/test/java/com/debatetimer/domain/parliamentary/ParliamentaryTimeBoxTest.java similarity index 95% rename from src/test/java/com/debatetimer/domain/parliamentary_debate/ParliamentaryTimeBoxTest.java rename to src/test/java/com/debatetimer/domain/parliamentary/ParliamentaryTimeBoxTest.java index 3e88c54..41ac68e 100644 --- a/src/test/java/com/debatetimer/domain/parliamentary_debate/ParliamentaryTimeBoxTest.java +++ b/src/test/java/com/debatetimer/domain/parliamentary/ParliamentaryTimeBoxTest.java @@ -1,4 +1,4 @@ -package com.debatetimer.domain.parliamentary_debate; +package com.debatetimer.domain.parliamentary; import com.debatetimer.domain.BoxType; import com.debatetimer.domain.Stance; diff --git a/src/test/java/com/debatetimer/service/member/MemberServiceTest.java b/src/test/java/com/debatetimer/service/member/MemberServiceTest.java new file mode 100644 index 0000000..14c02b2 --- /dev/null +++ b/src/test/java/com/debatetimer/service/member/MemberServiceTest.java @@ -0,0 +1,52 @@ +package com.debatetimer.service.member; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertAll; + +import com.debatetimer.BaseServiceTest; +import com.debatetimer.dto.member.MemberCreateRequest; +import com.debatetimer.dto.member.MemberCreateResponse; +import com.debatetimer.dto.member.TableResponses; +import com.debatetimer.domain.member.Member; +import com.debatetimer.domain.parliamentary.ParliamentaryTable; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; + +class MemberServiceTest extends BaseServiceTest { + + @Autowired + private MemberService memberService; + + @Nested + class CreateMember { + + @Test + void 회원를_생성한다() { + MemberCreateRequest request = new MemberCreateRequest("커찬"); + + MemberCreateResponse actual = memberService.createMember(request); + + long memberCount = memberRepository.count(); + assertAll( + () -> assertThat(actual.nickname()).isEqualTo(request.nickname()), + () -> assertThat(memberCount).isEqualTo(1L) + ); + } + } + + @Nested + class GetTables { + + @Test + void 회원의_전체_토론_시간표를_조회한다() { + Member member = memberRepository.save(new Member("커찬")); + parliamentaryTableRepository.save(new ParliamentaryTable(member, "토론 시간표 A", "주제", 1800)); + parliamentaryTableRepository.save(new ParliamentaryTable(member, "토론 시간표 B", "주제", 1900)); + + TableResponses response = memberService.getTables(member.getId()); + + assertThat(response.tables()).hasSize(2); + } + } +}