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

[BE/FEAT] : DTO Validation 수정 #332

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
baf3226
fix/#318 : 내가 추가한 음식 조회 오류 수정
LJH098 Jun 10, 2024
000bc60
fix/#318 : spotless
LJH098 Jun 10, 2024
fc42df3
Merge pull request #319 from JNU-econovation/fix/#318
hwangdaesun Jun 10, 2024
7134744
build/#214 : test시 MariaDB 이용 및 TestContainers관련 의존성 추가
hwangdaesun Jun 24, 2024
44a7b47
test/#214 : testData.sql 수정
hwangdaesun Jun 24, 2024
c08543d
test/#214 : testcontainers 연결
hwangdaesun Jun 24, 2024
040eced
feat/#214: log level info로 변경
hwangdaesun Jun 24, 2024
85b5251
test/#214 : H2 -> MariaDB 변경으로 인한 수정
hwangdaesun Jun 24, 2024
f3a4b65
test/#214 : MariaDB 및 Redis 테스트 컨테이너 생성하는 클래스 추가
hwangdaesun Jun 24, 2024
ddc762b
test/#214 : CommonApiTest -> ControllerTest로 클래스명 수정
hwangdaesun Jun 24, 2024
9780ec4
test/#214 : ContainerTest 클래스 상속
hwangdaesun Jun 24, 2024
2f23dc1
test/#308 : Test 설명 추가
hwangdaesun Jun 24, 2024
d83b912
Merge pull request #322 from JNU-econovation/feat/#214
hwangdaesun Jun 24, 2024
43f69ac
refactor/#321 : 파일명 schema.sql로 수정
hwangdaesun Jun 27, 2024
2ac271e
test/#321 : 애노테이션 ContainerTest 클래스에서 IntegrationTest 클래스로 변경
hwangdaesun Jun 27, 2024
60fa71c
test/#321 : ddl-auto=validate를 이용하여 Schema와 Entity가 서로 매핑되는 지 검사하는 테스…
hwangdaesun Jun 27, 2024
c93fb28
chore/#321 : PR이 Merged될 때 워크플로우 실행하도록 수정
hwangdaesun Jun 27, 2024
3eafeae
chore/#321 : Docker Compose restart 옵션 변경
hwangdaesun Jun 27, 2024
990c8ac
feat/#321 : 테스트 커버리지 확인을 위한 JaCoCO 추가
hwangdaesun Jun 28, 2024
5d81b31
chore/#321 : min-coverage-changed-files 제거
hwangdaesun Jun 28, 2024
9ff1c0f
Merge pull request #329 from JNU-econovation/feat/#321
hwangdaesun Jun 29, 2024
82006cf
fix/#321 : write-all 권한 부여
hwangdaesun Jun 29, 2024
d29d90b
Merge pull request #330 from JNU-econovation/feat/#321
hwangdaesun Jun 30, 2024
bc323a9
feat/#331 : CheckMemberRequest 수정
LJH098 Jun 30, 2024
1181e73
feat/#331 : CreateFoodRequest 수정
LJH098 Jun 30, 2024
8c10ae8
feat/#331 : GetAnalysisRequest 수정
LJH098 Jun 30, 2024
832d71c
feat/#331 : MonthlyMeal 수정
LJH098 Jun 30, 2024
86bfd9d
feat/#331 : OnBoardingMemberRequest 수정
LJH098 Jun 30, 2024
6dca4f4
feat/#331 : TodayMeal 수정
LJH098 Jun 30, 2024
3b24fb1
feat/#331 : UpdateMemberRequest 수정
LJH098 Jun 30, 2024
3c8fb28
feat/#331 : ValidationMessage 수정
LJH098 Jun 30, 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
23 changes: 20 additions & 3 deletions .github/workflows/testAndDeploy.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
name: testAndDeploy

on:
pull_request_review:
types: [submitted]
branches: [ "be" ]
pull_request:
types:
- closed

permissions: write-all

defaults:
run:
working-directory: ./BE/exceed

jobs:
if_merged:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- run: |
echo The PR was merged
build:
runs-on: ubuntu-22.04
permissions:
Expand All @@ -36,6 +44,15 @@ jobs:
- name: Build with Gradle Wrapper
run: ./gradlew build

- name: PR Comment on Jacoco Report
id: jacoco
uses: madrapps/jacoco-report@v1.2
with:
title: 테스트 커버리지 리포트입니다
paths: ${{ github.workspace }}/backend/build/reports/jacoco/test/jacocoTestReport.xml
token: ${{ secrets.GITHUB_TOKEN }}
min-coverage-overall: 30

- name: Send docker-compose.yml
uses: appleboy/scp-action@master
with:
Expand Down
25 changes: 22 additions & 3 deletions BE/exceed/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ plugins {
id "org.asciidoctor.jvm.convert" version "3.3.2"
id "me.champeau.jmh" version "0.7.2"
id 'com.diffplug.spotless' version '6.23.3'
id 'jacoco'
}

group = 'com.gaebaljip'
Expand Down Expand Up @@ -50,13 +51,15 @@ dependencies {
// lombok
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testCompileOnly 'org.projectlombok:lombok'
testAnnotationProcessor 'org.projectlombok:lombok'

//test
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
testRuntimeOnly 'com.h2database:h2'
testImplementation "org.testcontainers:mariadb:1.19.8"
testImplementation "org.testcontainers:testcontainers:1.19.8"
testImplementation "org.testcontainers:junit-jupiter:1.19.8"
testImplementation "org.junit.jupiter:junit-jupiter:5.8.1"


// querydsl
implementation 'com.querydsl:querydsl-jpa'
Expand Down Expand Up @@ -190,4 +193,20 @@ spotless {
// 파일 끝에 새로운 라인 추가
endWithNewline()
}
}

test {
finalizedBy jacocoTestReport
}

jacoco {
toolVersion = "0.8.8" // 버전 명시
}

jacocoTestReport {
dependsOn test // 리포트 생성 전에 test를 반드시 수행해야 한다!
reports { // 어떤 파일들을 생성할지, 어디에 생성할지 설정
xml.required = true // xml과 html형식으로 결과물을 만들어내라!
html.required = true
}
}
6 changes: 3 additions & 3 deletions BE/exceed/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ services:
networks:
- gaebaljip-network
restart:
on-failure
no

grafana:
image: grafana/grafana:latest
container_name: grafana
restart: always
restart: no
ports:
- "3000:3000"
volumes:
Expand All @@ -70,7 +70,7 @@ services:
prometheus:
image: prom/prometheus:latest
container_name: prometheus
restart: always
restart: no
ports:
- "9090:9090"
volumes:
Expand Down
4 changes: 2 additions & 2 deletions BE/exceed/resources/gaebaljip-local-environment/setting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ services:
image: grafana/grafana:latest
container_name: grafana
user: "$UID:$GID"
restart: always
restart: no
ports:
- "3000:3000"
volumes:
Expand All @@ -51,7 +51,7 @@ services:
prometheus:
image: prom/prometheus:latest
container_name: prometheus
restart: always
restart: no
ports:
- "9090:9090"
volumes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ public class ValidationMessage {

public static final String INVALID_PASSWORD =
"비밀번호 형식이 올바르지 않습니다. 비밀번호는 최소 6글자 이상이며, 영어와 특수문자를 포함해야 합니다.";

public static final String NOT_NULL = "입력해 주세요";
public static final String NOT_BLANK = "입력해 주세요";
public static final String MIN_0 = "0이상 입력해 주세요";
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import javax.validation.constraints.NotNull;

import com.gaebaljip.exceed.common.ValidationMessage;
import lombok.Builder;

public record CheckMemberRequest(@NotNull String email, @NotNull String code) {
public record CheckMemberRequest(@NotNull(message = "이메일을 " + ValidationMessage.NOT_NULL) String email,
@NotNull(message = "코드를 " + ValidationMessage.NOT_NULL) String code) {
@Builder
public CheckMemberRequest {}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
package com.gaebaljip.exceed.dto.request;

import com.gaebaljip.exceed.common.ValidationMessage;
import lombok.Builder;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

public record CreateFoodRequest(
String name,
Double sugars,
Double dietaryFiber,
Double sodium,
Double calorie,
Double carbohydrate,
Double protein,
Double fat,
Double servingSize) {
@NotBlank(message = "이름을 " + ValidationMessage.NOT_BLANK) String name,
@NotNull(message = "당을 " + ValidationMessage.NOT_NULL) @Min(value = 0, message = "당은" + ValidationMessage.MIN_0) Double sugars,
@NotNull(message = "식이섬유를 " + ValidationMessage.NOT_NULL) @Min(value = 0, message = "식이섬유는 " + ValidationMessage.MIN_0)Double dietaryFiber,
@NotNull(message = "나트륨을 " + ValidationMessage.NOT_NULL) @Min(value = 0, message = "나트륨은 " + ValidationMessage.MIN_0)Double sodium,
@NotNull(message = "칼로리를 " + ValidationMessage.NOT_NULL) @Min(value = 0, message = "칼로리는 " + ValidationMessage.MIN_0)Double calorie,
@NotNull(message = "탄수화물을 " + ValidationMessage.NOT_NULL) @Min(value = 0, message = "탄수화물은 " + ValidationMessage.MIN_0)Double carbohydrate,
@NotNull(message = "단백질을 " + ValidationMessage.NOT_NULL) @Min(value = 0, message = "단백질은 " + ValidationMessage.MIN_0)Double protein,
@NotNull(message = "지방을 " + ValidationMessage.NOT_NULL) @Min(value = 0, message = "지방은 " + ValidationMessage.MIN_0)Double fat,
@NotNull(message = "1회 제공량을 " + ValidationMessage.NOT_NULL) @Min(value = 0, message = "1회 제공량은 " + ValidationMessage.MIN_0)Double servingSize) {
@Builder
public CreateFoodRequest {}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.gaebaljip.exceed.dto.request;

import com.gaebaljip.exceed.common.ValidationMessage;

import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;

public record GetAnalysisRequest(Long memberId, LocalDateTime date) {}
public record GetAnalysisRequest(@NotNull(message = "memberId을" + ValidationMessage.NOT_NULL) Long memberId,
@NotNull(message = "날짜를 " + ValidationMessage.NOT_NULL) LocalDateTime date) {}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.gaebaljip.exceed.dto.request;

import com.gaebaljip.exceed.common.ValidationMessage;

import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;

public record MonthlyMeal(Long memberId, LocalDateTime date) {}
public record MonthlyMeal(@NotNull(message = "memberId을 " + ValidationMessage.NOT_NULL) Long memberId,
@NotNull(message = "날짜를 " + ValidationMessage.NOT_NULL) LocalDateTime date) {}
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
package com.gaebaljip.exceed.dto.request;

import com.gaebaljip.exceed.common.ValidationMessage;
import com.gaebaljip.exceed.common.annotation.Enum;
import com.gaebaljip.exceed.member.domain.Activity;
import com.gaebaljip.exceed.member.domain.Gender;

import lombok.Builder;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

public record OnBoardingMemberRequest(
Double height,
@NotNull(message = "키를 " + ValidationMessage.NOT_NULL) @Min(value = 0, message = "키는 " + ValidationMessage.MIN_0) Double height,
@Enum(enumClass = Gender.class) String gender,
Double weight,
Double targetWeight,
Integer age,
@NotNull(message = "몸무게를 " + ValidationMessage.NOT_NULL) @Min(value = 0, message = "몸무게는 " + ValidationMessage.MIN_0)Double weight,
@NotNull(message = "목표 몸무게를 " + ValidationMessage.NOT_NULL) @Min(value = 0, message = "목표 몸무게는 " + ValidationMessage.MIN_0)Double targetWeight,
@NotNull(message = "나이를 " + ValidationMessage.NOT_NULL) @Min(value = 0, message = "나이는 " + ValidationMessage.MIN_0)Integer age,
@Enum(enumClass = Activity.class) String activity,
String etc) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

import java.time.LocalDateTime;

import com.gaebaljip.exceed.common.ValidationMessage;
import lombok.Builder;

public record TodayMeal(Long memberId, LocalDateTime date) {
import javax.validation.constraints.NotNull;

public record TodayMeal(@NotNull(message = "memberId을 " + ValidationMessage.NOT_NULL) Long memberId,
@NotNull(message = "날짜를 " + ValidationMessage.NOT_NULL) LocalDateTime date) {

@Builder
public TodayMeal {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package com.gaebaljip.exceed.dto.request;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

import com.gaebaljip.exceed.common.ValidationMessage;
import com.gaebaljip.exceed.common.annotation.Enum;
import com.gaebaljip.exceed.member.domain.Activity;
import com.gaebaljip.exceed.member.domain.Gender;

public record UpdateMemberRequest(
@NotBlank(message = "memberId must not be null") Long memberId,
@NotBlank(message = "memberId must not be null") Double height,
@NotNull(message = "키를 " + ValidationMessage.NOT_NULL) @Min(value = 0, message = "키는 " + ValidationMessage.MIN_0) Double height,
@Enum(enumClass = Gender.class) String gender,
@NotBlank(message = "memberId must not be null") Integer age,
@NotNull(message = "나이를 " + ValidationMessage.NOT_NULL) @Min(value = 0, message = "나이는 " + ValidationMessage.MIN_0) Integer age,
@Enum(enumClass = Activity.class) String activity,
@NotBlank(message = "memberId must not be null") String etc) {}
@NotBlank(message = "기타사항을 " + ValidationMessage.NOT_BLANK) String etc) {}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import com.gaebaljip.exceed.food.domain.Food;
import com.gaebaljip.exceed.member.adapter.out.persistence.MemberEntity;

public interface FoodRepository extends JpaRepository<FoodEntity, Long> {
List<Food> findByMemberEntityId(Long memberId);
List<FoodEntity> findByMemberEntityId(Long memberId);

@Query("delete from FoodEntity f where f.id in :ids")
@Modifying
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void saveAll(List<FoodEntity> foodEntities) {
}

@Override
public List<Food> findByMemberId(Long memberId) {
public List<FoodEntity> findByMemberId(Long memberId) {
return foodRepository.findByMemberEntityId(memberId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public interface FoodPort {

void saveAll(List<FoodEntity> foodEntities);

List<Food> findByMemberId(Long memberId);
List<FoodEntity> findByMemberId(Long memberId);

void deleteByAllByIdInQuery(List<Long> ids);

Expand Down
2 changes: 1 addition & 1 deletion BE/exceed/src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ logging:
hibernate:
type:
descriptor:
sql: trace
sql: info
org:
quartz:
scheduler:
Expand Down
24 changes: 9 additions & 15 deletions BE/exceed/src/main/resources/application-test.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
spring:
datasource:
url: jdbc:h2:mem:exceed;MODE=MariaDB
driver-class-name: org.h2.Driver
username: exceed
password: exceed
redis:
host: localhost
port: 6379
h2:
console:
enabled: true
path: /h2-console
driver-class-name: org.testcontainers.jdbc.ContainerDatabaseDriver
url: jdbc:tc:mariadb:10.6:///test
jpa:
hibernate:
naming:
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
dialect: org.hibernate.dialect.MariaDBDialect
ddl-auto: create-drop
properties:
hibernate:
show_sql : true
format_sql : true
defer-datasource-initialization: true
show_sql: true
format_sql: true
use_sql_comments: true
cloud:
aws:
credentials:
Expand Down Expand Up @@ -59,4 +53,4 @@ logging:
hibernate:
type:
descriptor:
sql: trace
sql: info
Loading
Loading