Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[최종점검] 스터디 과제 제출 #2

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
be318b2
[FEAT] 서비스 단에서 도메인 로직 분리
sung-silver Mar 21, 2024
6e2ec20
[STYLE] enum 위치 도메인 아래로 변경
sung-silver Mar 21, 2024
ad8387c
[DOMAIN] AgeEnumTest 작성
sung-silver Mar 21, 2024
6154145
[DOMAIN] Result 엔티티에서 getTestDateToString 함수 테스트 작성
sung-silver Mar 21, 2024
86e90bf
[REFACTOR] saveMember 리팩터링, repository에서 명시하지 않아도 되는 메서드 삭제
sung-silver Mar 26, 2024
093d3e8
[FEAT] RestDoc 설정 & 확인
sung-silver Mar 26, 2024
a9bc1ca
[REFACOTR] request, response에서 DTO 키워드 제거
sung-silver Mar 26, 2024
02b592d
[FIX] MemberControllerTest initializeController 위치 수정
sung-silver Mar 26, 2024
bbde1c6
[FEAT] QuestionControllerTest 작성
sung-silver Mar 26, 2024
36115b4
[FEAT] ResultControllerTest 구현
sung-silver Mar 26, 2024
92b5eea
[FEAT] MemberJpaRepositoryTest 테스트코드 작성
sung-silver Mar 26, 2024
f2c0405
[FEAT] ResultJpaRepositoryTest 구현
sung-silver Mar 27, 2024
015bdbc
[ADD] questionJpaRepostiory에 대한 tearDown 추가
sung-silver Mar 27, 2024
4a1e0d3
[FEAT] ResultJpaRepositoryTest 구현
sung-silver Mar 27, 2024
5ef8081
[DEL] 안쓰는 주석 삭제
sung-silver Mar 27, 2024
0d0a196
[MODIFY] AgeEnumTest 각 나이 경계값을 기준으로 테스트 하도록 수정
sung-silver Mar 27, 2024
9285048
[FEAT] MemberServiceTest 구현
sung-silver Mar 27, 2024
cea44a2
[FEAT] ResultServiceTest 구현
sung-silver Mar 27, 2024
ee9e70f
[FEAT] restdoc .adoc 파일 모두 만들기
sung-silver Mar 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions howoldareu_clone/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,50 @@ plugins {
id 'java'
id 'org.springframework.boot' version '3.2.0'
id 'io.spring.dependency-management' version '1.1.4'
id 'org.asciidoctor.convert' version '1.5.8'
}

group = 'com.sopt'
version = '0.0.1-SNAPSHOT'

java {
sourceCompatibility = '17'
}

configurations {
compileOnly {
extendsFrom annotationProcessor
}
}

ext {
set('snippetsDir', file("build/generated-snippets"))
}

repositories {
mavenCentral()
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.mysql:mysql-connector-j'

// h2
runtimeOnly 'com.h2database:h2'

annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'

// Rest Docs
testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'
testImplementation 'org.springframework.restdocs:spring-restdocs-asciidoctor'
}

tasks.named('test') {
outputs.dir snippetsDir
useJUnitPlatform()
}

tasks.named('asciidoctor') {
inputs.dir snippetsDir
dependsOn test
}
9 changes: 9 additions & 0 deletions howoldareu_clone/src/docs/asciidoc/api/member.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[[save-member]]
== Save Member

=== HTTP Request
include::{snippets}/save-member/http-request.adoc[]

=== HTTP Response
include::{snippets}/save-member/http-response.adoc[]
include::{snippets}/save-member/response-fields.adoc[]
9 changes: 9 additions & 0 deletions howoldareu_clone/src/docs/asciidoc/api/question.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[[get-question]]
== GET Question

=== HTTP Request
include::{snippets}/get-questions/http-request.adoc[]

=== HTTP Response
include::{snippets}/get-questions/http-response.adoc[]
include::{snippets}/get-questions/response-fields.adoc[]
19 changes: 19 additions & 0 deletions howoldareu_clone/src/docs/asciidoc/api/result.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[[save-result]]
== SAVE RESULT

=== HTTP Request
include::{snippets}/save-result/http-request.adoc[]

=== HTTP Response
include::{snippets}/save-result/http-response.adoc[]
include::{snippets}/save-result/response-fields.adoc[]

[[get-all-results]]
== GET ALL RESULTS

=== HTTP Request
include::{snippets}/get-all-results/http-request.adoc[]

=== HTTP Response
include::{snippets}/get-all-results/http-response.adoc[]
include::{snippets}/get-all-results/response-fields.adoc[]
23 changes: 23 additions & 0 deletions howoldareu_clone/src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
ifndef::snippets[]
:snippets: "../../build/generated-snippets"
endif::[]

= HOWOLDAREYOU REST API 문서
:doctype: book
:icons: font
:source-highlighter: highlightjs
:toc: left
:toclevels: 2
:seclinks:

[[Member-API]]
== Member API
include::api/member.adoc[]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

파일 분리하는 것 좋네요 ~


[[Question-API]]
== Question API
include::api/question.adoc[]

[[Result-API]]
== Result API
include::api/result.adoc[]
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@SpringBootApplication
@EnableJpaAuditing
public class ServerApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.sopt.Server.common;

import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.stereotype.Component;

@Component
@EnableJpaAuditing
public class JpaAuditingConfiguration {
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,25 @@
import com.sopt.Server.controller.response.MemberGetResponse;
import com.sopt.Server.service.MemberService;
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.RestController;

import java.net.URI;

import static com.sopt.Server.exception.Success.CREATE_MEMBER_SUCCESS;

@RestController
@RequiredArgsConstructor
public class MemberController {

private final MemberService memberService;

@PostMapping("/member")
public ApiResponse<MemberGetResponse> saveMember(@RequestBody MemberPostRequest request) {

ApiResponse<MemberGetResponse> response = memberService.saveMember(request.nickName(), request.age());
return response;
public ResponseEntity<ApiResponse<MemberGetResponse>> saveMember(@RequestBody MemberPostRequest request) {
MemberGetResponse response = memberService.saveMember(request);
URI uri = URI.create("/member"+response.memberId());
return ResponseEntity.created(uri).body(ApiResponse.success(CREATE_MEMBER_SUCCESS, response));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.sopt.Server.controller;

import com.sopt.Server.common.ApiResponse;
import com.sopt.Server.controller.response.GetQuestionResponseDTO;
import com.sopt.Server.controller.response.GetQuestionResponse;
import com.sopt.Server.exception.Success;
import com.sopt.Server.service.QuestionService;
import lombok.RequiredArgsConstructor;
Expand All @@ -18,8 +18,8 @@ public class QuestionController {
private final QuestionService questionService;

@GetMapping("")
public ApiResponse<List<GetQuestionResponseDTO>> getQuestionResponseDTOList() {
return ApiResponse.success(Success.GET_QUESTION_LIST_SUCCESS,questionService.getQuestionResponseDTOList());
public ApiResponse<List<GetQuestionResponse>> getQuestionResponseList() {
return ApiResponse.success(Success.GET_QUESTION_LIST_SUCCESS,questionService.getQuestionResponseList());
}

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package com.sopt.Server.controller;

import com.sopt.Server.common.ApiResponse;
import com.sopt.Server.controller.request.AnswerListRequestDTO;
import com.sopt.Server.controller.response.AllResultsResponseDTO;
import com.sopt.Server.controller.response.ResultResponseDTO;
import com.sopt.Server.controller.request.AnswerListRequest;
import com.sopt.Server.controller.response.AllResultsResponse;
import com.sopt.Server.controller.response.ResultResponse;
import com.sopt.Server.exception.Success;
import com.sopt.Server.service.ResultService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.net.URI;
import java.util.List;

@RestController
Expand All @@ -18,12 +20,14 @@ public class ResultController {
private final ResultService resultService;

@PostMapping("")
public ApiResponse<ResultResponseDTO> saveResult(@RequestBody AnswerListRequestDTO answerListRequestDTO){
return ApiResponse.success(Success.CREATE_RESULT_SUCCESS,resultService.saveResult(answerListRequestDTO));
public ResponseEntity<ApiResponse<ResultResponse>> saveResult(@RequestBody AnswerListRequest answerListRequestDTO){
ResultResponse response = resultService.saveResult(answerListRequestDTO);
URI uri = URI.create("/result");
return ResponseEntity.created(uri).body(ApiResponse.success(Success.CREATE_RESULT_SUCCESS,response));
}

@GetMapping("/{memberId}")
public ApiResponse<List<AllResultsResponseDTO>> getAllResults(@PathVariable Long memberId) {
public ApiResponse<List<AllResultsResponse>> getAllResults(@PathVariable Long memberId) {
return ApiResponse.success(Success.GET_USER_LIST_SUCCESS, resultService.getAllResults(memberId));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.sopt.Server.controller.request;

import java.util.List;

public record AnswerListRequest(String nickname, List<AnswerRequest> results) {
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.sopt.Server.controller.request;

public record AnswerRequest(Long questionId, boolean answerType) {
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.sopt.Server.controller.response;

import com.sopt.Server.domain.Result;

import java.util.List;

public record AllResultsResponse(Long id, int resultAge, String title, String content, String testedDate, String imgUrl1, String imgUrl2) {
public static AllResultsResponse of(Result result, String title, String content, String testedDate, String imgUrl1, String imgUrl2) {
return new AllResultsResponse(result.getId(), result.getResultAge(), title, content, testedDate, imgUrl1, imgUrl2);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.sopt.Server.controller.response;

public record GetQuestionResponse(Long questionId, String questionContent) {
static public GetQuestionResponse of(Long questionId, String questionContent) {
return new GetQuestionResponse(questionId, questionContent);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.sopt.Server.controller.response;

public record ResultResponse(String nickname, int resultAge, String title, String content, String imgUrl1, String imgUrl2) {
public static ResultResponse of(String nickname, int resultAge, String title, String content, String imgUrl1, String imgUrl2) {
return new ResultResponse(nickname, resultAge, title, content, imgUrl1, imgUrl2);
}
}

This file was deleted.

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

import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

Expand All @@ -14,11 +15,17 @@ public class Answer {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long answerId;

@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
private Question question;

private boolean answerType;

private int answerScore;

@Builder
public Answer(Question question, boolean answerType, int answerScore) {
this.question = question;
this.answerType = answerType;
this.answerScore = answerScore;
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
package com.sopt.Server.domain;

import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
@Table(name = "QUESTIONS")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Question {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long questionId;
private String questionContent;

@Builder
public Question(Long questionId, String questionContent) {
this.questionId = questionId;
this.questionContent = questionContent;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ public Result(Long id, Member member, int resultAge, LocalDateTime testedDate) {
this.resultAge = resultAge;
this.testedDate = testedDate;
}

public String getTestedDateToString(){
return testedDate.getMonthValue() + "월 " + testedDate.getDayOfMonth() + "일";
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.sopt.Server.common;
package com.sopt.Server.domain.enums;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
Expand All @@ -18,5 +18,18 @@ public enum AgeEnum {
private final String imageUrl1;
private final String imageUrl2;

public static AgeEnum getAgeEnum(int age){
if(age < 20)
return AgeEnum.TEENAGER;
else if(age < 30)
return AgeEnum.TWENTIES;
else if(age < 40)
return AgeEnum.THIRTIES;
else if(age < 50)
return AgeEnum.FORTIES;
else
return AgeEnum.FIFTIES;
}

}

Loading