-
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.
* [GOORM-39]-feat: yml 파일 server port 명시 및 ddl-auto 수정 * [GOORM-39]-feat: 기본 질문 생성 API 구현 * [GOORM-39]-refactor: yml 파일 ddl-auto 수정 * [GOORM-39]-refactor: BaseQuestionController URL 수정 * [GOORM-39]-refactor: BaseQuestion의 content 칼럼 nullable = false 제약 추가 * [GOORM-39]-refactor: BaseQuestionResponseList로 반환하도록 수정 * [GOORM-39]-refactor: 코드 컨벤션 통일
- Loading branch information
1 parent
342bc9c
commit bf4e6ec
Showing
11 changed files
with
228 additions
and
1 deletion.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
...va/goorm/kgu/familynote/domain/question/baseQuestion/application/BaseQuestionService.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,33 @@ | ||
package goorm.kgu.familynote.domain.question.baseQuestion.application; | ||
|
||
import goorm.kgu.familynote.domain.question.baseQuestion.domain.BaseQuestion; | ||
import goorm.kgu.familynote.domain.question.baseQuestion.domain.BaseQuestionRepository; | ||
import goorm.kgu.familynote.domain.question.baseQuestion.presentation.request.BaseQuestionCreateRequest; | ||
import goorm.kgu.familynote.domain.question.baseQuestion.presentation.response.BaseQuestionResponse; | ||
import goorm.kgu.familynote.domain.question.baseQuestion.presentation.response.BaseQuestionResponseList; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class BaseQuestionService { | ||
private final BaseQuestionRepository baseQuestionRepository; | ||
|
||
@Transactional | ||
public BaseQuestionResponseList saveBaseQuestions(List<BaseQuestionCreateRequest> requests) { | ||
List<BaseQuestionResponse> baseQuestionResponseList = requests.stream() | ||
.map(this::saveBaseQuestion) | ||
.collect(Collectors.toList()); | ||
return BaseQuestionResponseList.of(baseQuestionResponseList); | ||
} | ||
|
||
private BaseQuestionResponse saveBaseQuestion(BaseQuestionCreateRequest request) { | ||
BaseQuestion baseQuestion = BaseQuestion.create(request.content()); | ||
baseQuestionRepository.save(baseQuestion); | ||
return BaseQuestionResponse.of(baseQuestion); | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/goorm/kgu/familynote/domain/question/baseQuestion/domain/BaseQuestion.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,41 @@ | ||
package goorm.kgu.familynote.domain.question.baseQuestion.domain; | ||
|
||
import goorm.kgu.familynote.common.domain.BaseTimeEntity; | ||
import goorm.kgu.familynote.domain.family.family.domain.Family; | ||
import goorm.kgu.familynote.domain.family.member.domain.FamilyMember; | ||
import goorm.kgu.familynote.domain.user.domain.User; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import static jakarta.persistence.GenerationType.IDENTITY; | ||
|
||
@Getter | ||
@Entity | ||
@Builder | ||
@Table(name = "base_question") | ||
@AllArgsConstructor | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class BaseQuestion extends BaseTimeEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = IDENTITY) | ||
private Long id; | ||
|
||
@Column(nullable = false) | ||
private String content; | ||
|
||
public static BaseQuestion create(String content) { | ||
return BaseQuestion.builder() | ||
.content(content) | ||
.build(); | ||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
...java/goorm/kgu/familynote/domain/question/baseQuestion/domain/BaseQuestionRepository.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,8 @@ | ||
package goorm.kgu.familynote.domain.question.baseQuestion.domain; | ||
|
||
|
||
public interface BaseQuestionRepository { | ||
|
||
BaseQuestion save(BaseQuestion baseQuestion); | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
...gu/familynote/domain/question/baseQuestion/infrastructure/BaseQuestionRepositoryImpl.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,17 @@ | ||
package goorm.kgu.familynote.domain.question.baseQuestion.infrastructure; | ||
|
||
import goorm.kgu.familynote.domain.question.baseQuestion.domain.BaseQuestion; | ||
import goorm.kgu.familynote.domain.question.baseQuestion.domain.BaseQuestionRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class BaseQuestionRepositoryImpl implements BaseQuestionRepository { | ||
private final JpaBaseQuestionRepository jpaBaseQuestionRepository; | ||
|
||
@Override | ||
public BaseQuestion save(BaseQuestion baseQuestion) { | ||
return jpaBaseQuestionRepository.save(baseQuestion); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...kgu/familynote/domain/question/baseQuestion/infrastructure/JpaBaseQuestionRepository.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,7 @@ | ||
package goorm.kgu.familynote.domain.question.baseQuestion.infrastructure; | ||
|
||
import goorm.kgu.familynote.domain.question.baseQuestion.domain.BaseQuestion; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface JpaBaseQuestionRepository extends JpaRepository<BaseQuestion, Long> { | ||
} |
52 changes: 52 additions & 0 deletions
52
...oorm/kgu/familynote/domain/question/baseQuestion/presentation/BaseQuestionController.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,52 @@ | ||
package goorm.kgu.familynote.domain.question.baseQuestion.presentation; | ||
|
||
import goorm.kgu.familynote.common.exception.ExceptionResponse; | ||
import goorm.kgu.familynote.domain.family.family.presentation.response.FamilyPersistResponse; | ||
import goorm.kgu.familynote.domain.family.member.presentation.request.FamilyMemberCreateRequest; | ||
import goorm.kgu.familynote.domain.question.baseQuestion.application.BaseQuestionService; | ||
import goorm.kgu.familynote.domain.question.baseQuestion.presentation.request.BaseQuestionCreateRequest; | ||
import goorm.kgu.familynote.domain.question.baseQuestion.presentation.response.BaseQuestionResponse; | ||
import goorm.kgu.familynote.domain.question.baseQuestion.presentation.response.BaseQuestionResponseList; | ||
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.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import jakarta.validation.Valid; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import static org.springframework.http.HttpStatus.CREATED; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1/question/base") | ||
@Tag(name = "Base Question", description = "기본 질문 관련 api / 담당자 : 전민주") | ||
public class BaseQuestionController { | ||
private final BaseQuestionService baseQuestionService; | ||
|
||
@Operation(summary = "기본 질문 등록", description = "기본 질문을 등록합니다. 개발자/관리자가 API를 통해서 조작할 수 있습니다.") | ||
@ApiResponses({ | ||
@ApiResponse( | ||
responseCode = "201", | ||
description = "기본 질문 등록 성공", | ||
content = @Content(schema = @Schema(implementation = FamilyPersistResponse.class)) | ||
) | ||
}) | ||
@ResponseStatus(CREATED) | ||
@PostMapping | ||
public ResponseEntity<BaseQuestionResponseList> createBaseQuestions( | ||
@Valid @RequestBody List<BaseQuestionCreateRequest> requests | ||
) { | ||
BaseQuestionResponseList response = baseQuestionService.saveBaseQuestions(requests); | ||
return ResponseEntity.ok(response); | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
...milynote/domain/question/baseQuestion/presentation/request/BaseQuestionCreateRequest.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,11 @@ | ||
package goorm.kgu.familynote.domain.question.baseQuestion.presentation.request; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
|
||
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED; | ||
|
||
public record BaseQuestionCreateRequest( | ||
@Schema(description = "기본 질문 내용", example = "탕수육 먹을 때 부먹 vs 찍먹", requiredMode = REQUIRED) | ||
String content | ||
) { | ||
} |
30 changes: 30 additions & 0 deletions
30
...u/familynote/domain/question/baseQuestion/presentation/response/BaseQuestionResponse.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,30 @@ | ||
package goorm.kgu.familynote.domain.question.baseQuestion.presentation.response; | ||
|
||
import goorm.kgu.familynote.domain.question.baseQuestion.domain.BaseQuestion; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED; | ||
|
||
public record BaseQuestionResponse( | ||
@Schema(description = "기본 질문 id", example = "1", requiredMode = REQUIRED) | ||
Long baseQuestionId, | ||
|
||
@Schema(description = "기본 질문 내용", example = "짜장면 vs 짬뽕", requiredMode = REQUIRED) | ||
String content | ||
) { | ||
|
||
public static List<BaseQuestionResponse> of(List<BaseQuestion> baseQuestions) { | ||
return baseQuestions.stream() | ||
.map(BaseQuestionResponse::of) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
public static BaseQuestionResponse of(BaseQuestion baseQuestion) { | ||
return new BaseQuestionResponse( | ||
baseQuestion.getId(), | ||
baseQuestion.getContent() | ||
); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...milynote/domain/question/baseQuestion/presentation/response/BaseQuestionResponseList.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,25 @@ | ||
package goorm.kgu.familynote.domain.question.baseQuestion.presentation.response; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import java.util.List; | ||
|
||
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED; | ||
|
||
public record BaseQuestionResponseList ( | ||
@Schema( | ||
description = "기본 질문 리스트", | ||
example = | ||
" [{\"content\": \"오늘 하루 중 가장 즐거웠던 일은 무엇이었나요?\"},\n" + | ||
" {\"content\": \"요즘 가장 관심 있는 취미나 활동은 무엇인가요?\"},\n" + | ||
" {\"content\": \"어렸을 때의 꿈은 무엇이었나요? 지금도 그 꿈이 있나요?\"}]", | ||
requiredMode = REQUIRED | ||
) | ||
List<BaseQuestionResponse> contents | ||
) { | ||
|
||
public static BaseQuestionResponseList of(List<BaseQuestionResponse> baseQuestionResponseList) { | ||
return new BaseQuestionResponseList( | ||
baseQuestionResponseList | ||
); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
spring: | ||
jpa: | ||
hibernate: | ||
ddl-auto: update | ||
ddl-auto: create |
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
server: | ||
port: 5252 | ||
|
||
spring: | ||
application: | ||
name: family-note-server | ||
|