From f8cc5ec51089a1752e0e96e650d3f74e22ed3b0c Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Mon, 1 Apr 2024 17:13:45 +0900 Subject: [PATCH 01/40] =?UTF-8?q?[feat]=20-=20=EA=B2=80=EC=83=89=20?= =?UTF-8?q?=EC=BF=BC=EB=A6=AC=20=EC=83=9D=EC=84=B1=20-=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1,=20=EA=B2=80=EC=83=89=20=EC=BB=A8=ED=8A=B8=EB=A1=A4?= =?UTF-8?q?=EB=9F=AC=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EB=B0=8F=20dto=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20-=20querydsl=20=EC=9D=98=EC=A1=B4=EC=84=B1?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 + build.gradle | 24 +++++++++++ .../controller/FarmClubController.java | 42 +++++++++++++++++++ .../farmclub/controller/TestController.java | 4 -- .../domain/farmclub/dto/TestDto.java | 4 -- .../dto/req/CreateFarmClubRequestDto.java | 18 ++++++++ .../dto/req/RegisterFarmClubRequestDto.java | 6 +++ .../dto/res/CreateFarmClubResponseDto.java | 11 +++++ .../dto/res/GetFarmClubResponseDto.java | 7 ++++ .../dto/res/RegisterFarmClubResponseDto.java | 9 ++++ .../dto/res/SearchFarmClubResponseDto.java | 14 +++++++ .../domain/farmclub/entity/FarmClub.java | 6 +++ .../domain/farmclub/entity/TestEntitiy.java | 6 --- .../repository/FarmClubRepository.java | 13 ++++++ .../repository/FarmClubRepositoryCustom.java | 10 +++++ .../repository/FarmClubRepositoryImpl.java | 37 ++++++++++++++++ .../farmclub/repository/TestRepository.java | 4 -- .../farmclub/service/FarmClubService.java | 31 ++++++++++++++ .../domain/farmclub/service/TestService.java | 4 -- 19 files changed, 230 insertions(+), 22 deletions(-) create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java delete mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/TestController.java delete mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/TestDto.java create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/req/CreateFarmClubRequestDto.java create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/req/RegisterFarmClubRequestDto.java create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/CreateFarmClubResponseDto.java create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetFarmClubResponseDto.java create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/RegisterFarmClubResponseDto.java create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/SearchFarmClubResponseDto.java delete mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/TestEntitiy.java create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepository.java create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryCustom.java create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryImpl.java delete mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/TestRepository.java create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java delete mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/TestService.java diff --git a/.gitignore b/.gitignore index a57ec1d5..b3d0f392 100644 --- a/.gitignore +++ b/.gitignore @@ -208,4 +208,6 @@ application-prod.yml application-db.yml application-aws.yml +**/generated + # End of https://www.toptal.com/developers/gitignore/api/java,gradle,intellij+all,windows,macos \ No newline at end of file diff --git a/build.gradle b/build.gradle index ee392a62..32ea5fc0 100644 --- a/build.gradle +++ b/build.gradle @@ -37,6 +37,12 @@ dependencies { runtimeOnly group: 'io.jsonwebtoken', name: 'jjwt-impl', version: '0.11.2' runtimeOnly group: 'io.jsonwebtoken', name: 'jjwt-jackson', version: '0.11.2' + // Spring boot 3.0 querydsl 설정 + implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta' + annotationProcessor 'com.querydsl:querydsl-apt:5.0.0:jakarta' + annotationProcessor "jakarta.annotation:jakarta.annotation-api" + annotationProcessor "jakarta.persistence:jakarta.persistence-api" + runtimeOnly 'com.h2database:h2' compileOnly 'org.projectlombok:lombok' runtimeOnly 'com.mysql:mysql-connector-j' @@ -51,3 +57,21 @@ tasks.named('bootBuildImage') { tasks.named('test') { useJUnitPlatform() } + +// Querydsl 설정부 +def generated = 'src/main/generated' + +// querydsl QClass 파일 생성 위치를 지정 +tasks.withType(JavaCompile) { + options.getGeneratedSourceOutputDirectory().set(file(generated)) +} + +// java source set 에 querydsl QClass 위치 추가 +sourceSets { + main.java.srcDirs += [ generated ] +} + +// gradle clean 시에 QClass 디렉토리 삭제 +clean { + delete file(generated) +} \ No newline at end of file diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java new file mode 100644 index 00000000..6cab7e12 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java @@ -0,0 +1,42 @@ +package com.modernfarmer.farmusspring.domain.farmclub.controller; + +import com.modernfarmer.farmusspring.domain.farmclub.dto.req.CreateFarmClubRequestDto; +import com.modernfarmer.farmusspring.domain.farmclub.service.FarmClubService; +import com.modernfarmer.farmusspring.global.response.BaseResponseDto; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/farm-club") +public class FarmClubController { + + private final FarmClubService farmClubService; + + // 요청 : 이름, 설명, 최대인원, 모집기한, 내 채소 id, 채소정보 id + // 응답 : 팜클럽 id + @PostMapping + public BaseResponseDto createFarmClub( + @RequestBody CreateFarmClubRequestDto requestDto + ) { + + + return null; + } + + @PostMapping("/register") + public BaseResponseDto registerFarmClub( + @RequestBody CreateFarmClubRequestDto requestDto + ) { + + return null; + } + + @GetMapping("/search") + public BaseResponseDto searchFarmClub( + @RequestParam String keyword + ) { + + return null; + } +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/TestController.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/TestController.java deleted file mode 100644 index 9134d9ba..00000000 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/TestController.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.modernfarmer.farmusspring.domain.farmclub.controller; - -public class TestController { -} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/TestDto.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/TestDto.java deleted file mode 100644 index 0a28f954..00000000 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/TestDto.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.modernfarmer.farmusspring.domain.farmclub.dto; - -public class TestDto { -} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/req/CreateFarmClubRequestDto.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/req/CreateFarmClubRequestDto.java new file mode 100644 index 00000000..4788b1ef --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/req/CreateFarmClubRequestDto.java @@ -0,0 +1,18 @@ +package com.modernfarmer.farmusspring.domain.farmclub.dto.req; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@AllArgsConstructor +@NoArgsConstructor +@Getter +public class CreateFarmClubRequestDto { + + private String farmClubName; + private String farmClubDescription; + private int maxMemberCount; + private String startDate; + private Long myVeggieId; + private String veggieInfoId; +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/req/RegisterFarmClubRequestDto.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/req/RegisterFarmClubRequestDto.java new file mode 100644 index 00000000..78f1c80a --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/req/RegisterFarmClubRequestDto.java @@ -0,0 +1,6 @@ +package com.modernfarmer.farmusspring.domain.farmclub.dto.req; + +public record RegisterFarmClubRequestDto ( + +){ +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/CreateFarmClubResponseDto.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/CreateFarmClubResponseDto.java new file mode 100644 index 00000000..e866a1da --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/CreateFarmClubResponseDto.java @@ -0,0 +1,11 @@ +package com.modernfarmer.farmusspring.domain.farmclub.dto.res; + +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; + +@AllArgsConstructor(staticName = "of") +@NoArgsConstructor +public class CreateFarmClubResponseDto { + + private Long farmClubId; +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetFarmClubResponseDto.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetFarmClubResponseDto.java new file mode 100644 index 00000000..5ae8efde --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetFarmClubResponseDto.java @@ -0,0 +1,7 @@ +package com.modernfarmer.farmusspring.domain.farmclub.dto.res; + +public record GetFarmClubResponseDto ( + +){ + +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/RegisterFarmClubResponseDto.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/RegisterFarmClubResponseDto.java new file mode 100644 index 00000000..c908cca5 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/RegisterFarmClubResponseDto.java @@ -0,0 +1,9 @@ +package com.modernfarmer.farmusspring.domain.farmclub.dto.res; + +public record RegisterFarmClubResponseDto ( + Long userFarmClubId +){ + public static RegisterFarmClubResponseDto of(Long userFarmClubId) { + return new RegisterFarmClubResponseDto(userFarmClubId); + } +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/SearchFarmClubResponseDto.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/SearchFarmClubResponseDto.java new file mode 100644 index 00000000..42b4a296 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/SearchFarmClubResponseDto.java @@ -0,0 +1,14 @@ +package com.modernfarmer.farmusspring.domain.farmclub.dto.res; + +public record SearchFarmClubResponseDto ( + Long farmClubId, + String farmClubName, + String farmClubDescription, + String veggieName, + String veggieImage, + String difficulty, + String startedAt, + int maxMemberCount +) { + +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/FarmClub.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/FarmClub.java index 12b89b69..7474dea7 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/FarmClub.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/FarmClub.java @@ -34,6 +34,12 @@ public class FarmClub extends BaseEntity { @Column(nullable = false) private String difficulty; + @Column(nullable = false) + private String veggieImage; + + @Column(nullable = false) + private String veggieName; + @Column(nullable = false) private int maxUser; diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/TestEntitiy.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/TestEntitiy.java deleted file mode 100644 index 4d45a5f0..00000000 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/TestEntitiy.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.modernfarmer.farmusspring.domain.farmclub.entity; - -public class TestEntitiy { - - -} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepository.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepository.java new file mode 100644 index 00000000..f3c2aecd --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepository.java @@ -0,0 +1,13 @@ +package com.modernfarmer.farmusspring.domain.farmclub.repository; + +import com.modernfarmer.farmusspring.domain.farmclub.entity.FarmClub; +import org.joda.time.LocalDate; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; + +import java.util.List; + + +public interface FarmClubRepository extends JpaRepository, FarmClubRepositoryCustom { + +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryCustom.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryCustom.java new file mode 100644 index 00000000..0116e0c3 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryCustom.java @@ -0,0 +1,10 @@ +package com.modernfarmer.farmusspring.domain.farmclub.repository; + +import com.modernfarmer.farmusspring.domain.farmclub.dto.res.SearchFarmClubResponseDto; +import com.modernfarmer.farmusspring.domain.farmclub.entity.FarmClub; + +import java.util.List; + +public interface FarmClubRepositoryCustom { + List findByConditions(List difficulties, boolean isBefore, boolean isAfter, String keyword); +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryImpl.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryImpl.java new file mode 100644 index 00000000..aad80a4d --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryImpl.java @@ -0,0 +1,37 @@ +package com.modernfarmer.farmusspring.domain.farmclub.repository; + +import com.modernfarmer.farmusspring.domain.farmclub.dto.res.SearchFarmClubResponseDto; +import com.modernfarmer.farmusspring.domain.farmclub.entity.QFarmClub; +import com.querydsl.core.types.Projections; +import com.querydsl.jpa.impl.JPAQueryFactory; +import jakarta.persistence.EntityManager; +import jakarta.persistence.PersistenceContext; +import org.joda.time.LocalDate; + +import java.util.List; + +public class FarmClubRepositoryImpl implements FarmClubRepositoryCustom{ + + @PersistenceContext + private EntityManager em; + + @Override + public List findByConditions(List difficulties, boolean isBefore, boolean isAfter, String keyword) { + QFarmClub farmClub = QFarmClub.farmClub; + JPAQueryFactory queryFactory = new JPAQueryFactory(em); + + return queryFactory + .select(Projections.constructor(SearchFarmClubResponseDto.class, + farmClub.id, + farmClub.name, + farmClub.description, + farmClub.veggieImage, + farmClub.difficulty, + farmClub.startedAt)) + .from(farmClub) + .where(farmClub.difficulty.in(difficulties) + .and(isBefore ? farmClub.startedAt.after(LocalDate.now()) : null) + .and(isAfter ? farmClub.startedAt.before(LocalDate.now()) : null)) + .fetch(); + } +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/TestRepository.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/TestRepository.java deleted file mode 100644 index 08f79dbc..00000000 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/TestRepository.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.modernfarmer.farmusspring.domain.farmclub.repository; - -public class TestRepository { -} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java new file mode 100644 index 00000000..63597a03 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java @@ -0,0 +1,31 @@ +package com.modernfarmer.farmusspring.domain.farmclub.service; + +import com.modernfarmer.farmusspring.domain.farmclub.dto.req.CreateFarmClubRequestDto; +import com.modernfarmer.farmusspring.domain.farmclub.dto.res.CreateFarmClubResponseDto; +import com.modernfarmer.farmusspring.domain.farmclub.dto.res.SearchFarmClubResponseDto; +import com.modernfarmer.farmusspring.domain.farmclub.repository.FarmClubRepository; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +@RequiredArgsConstructor +@Slf4j +public class FarmClubService { + + private final FarmClubRepository farmClubRepository; + + public CreateFarmClubResponseDto createFarmClub(CreateFarmClubRequestDto request) { + // 몽고에서 이미지, 난이도 가져오기 + + return null; + } + + public List searchFarmClub(String keyword) { + // 몽고에서 이미지, 난이도 가져오기 + + return null; + } +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/TestService.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/TestService.java deleted file mode 100644 index 478539a3..00000000 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/TestService.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.modernfarmer.farmusspring.domain.farmclub.service; - -public class TestService { -} From a44ca05346c4166e895d07f0bdafe8edad8a7bce Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Sun, 7 Apr 2024 02:33:01 +0900 Subject: [PATCH 02/40] =?UTF-8?q?[fix]=20=ED=8C=9C=ED=81=B4=EB=9F=BD=20?= =?UTF-8?q?=EA=B2=80=EC=83=89=20=EA=B8=B0=EB=8A=A5=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EC=8B=9C=EC=9E=91=EC=A0=84,=ED=9B=84=20=EC=A1=B0=EA=B1=B4=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farmclub/repository/FarmClubRepositoryCustom.java | 2 +- .../domain/farmclub/repository/FarmClubRepositoryImpl.java | 7 +++---- .../domain/farmclub/service/FarmClubService.java | 6 ++---- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryCustom.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryCustom.java index 0116e0c3..f9140fdc 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryCustom.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryCustom.java @@ -6,5 +6,5 @@ import java.util.List; public interface FarmClubRepositoryCustom { - List findByConditions(List difficulties, boolean isBefore, boolean isAfter, String keyword); + List findByConditions(List difficulties, String keyword); } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryImpl.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryImpl.java index aad80a4d..d54a9f1b 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryImpl.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryImpl.java @@ -16,7 +16,7 @@ public class FarmClubRepositoryImpl implements FarmClubRepositoryCustom{ private EntityManager em; @Override - public List findByConditions(List difficulties, boolean isBefore, boolean isAfter, String keyword) { + public List findByConditions(List difficulties, String keyword) { QFarmClub farmClub = QFarmClub.farmClub; JPAQueryFactory queryFactory = new JPAQueryFactory(em); @@ -29,9 +29,8 @@ public List findByConditions(List difficultie farmClub.difficulty, farmClub.startedAt)) .from(farmClub) - .where(farmClub.difficulty.in(difficulties) - .and(isBefore ? farmClub.startedAt.after(LocalDate.now()) : null) - .and(isAfter ? farmClub.startedAt.before(LocalDate.now()) : null)) + .where(farmClub.difficulty.in(difficulties)) + .where(farmClub.name.contains(keyword)) .fetch(); } } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java index 63597a03..fcf11629 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java @@ -23,9 +23,7 @@ public CreateFarmClubResponseDto createFarmClub(CreateFarmClubRequestDto request return null; } - public List searchFarmClub(String keyword) { - // 몽고에서 이미지, 난이도 가져오기 - - return null; + public List searchFarmClub(List difficulties, String keyword) { + return farmClubRepository.findByConditions(difficulties, keyword); } } From 5116bbbbd167b90cb7988772a4f46a1aaf3071ff Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Mon, 8 Apr 2024 02:27:54 +0900 Subject: [PATCH 03/40] =?UTF-8?q?[feat]=20=ED=8C=9C=ED=81=B4=EB=9F=BD=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EB=B0=8F=20?= =?UTF-8?q?dto=20=EC=83=9D=EC=84=B1=20(=EB=A1=9C=EC=A7=81=20x)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farmclub/controller/FarmClubController.java | 8 ++++++++ .../farmclub/dto/res/GetFarmClubResponseDto.java | 13 ++++++++++++- .../domain/farmclub/service/FarmClubService.java | 12 ++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java index 6cab7e12..9074f7c4 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java @@ -39,4 +39,12 @@ public BaseResponseDto searchFarmClub( return null; } + + @GetMapping("/{id}") + public BaseResponseDto getFarmClub( + @PathVariable Long id + ) { + + return null; + } } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetFarmClubResponseDto.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetFarmClubResponseDto.java index 5ae8efde..fa22c354 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetFarmClubResponseDto.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetFarmClubResponseDto.java @@ -1,7 +1,18 @@ package com.modernfarmer.farmusspring.domain.farmclub.dto.res; -public record GetFarmClubResponseDto ( +import lombok.AllArgsConstructor; +@AllArgsConstructor(staticName = "of") +public record GetFarmClubResponseDto ( + Long farmClubId, + String farmClubName, + String farmClubDescription, + String veggieName, + String veggieImage, + String startedAt, + int maxMemberCount, + int currentMemberCount, + String preparation ){ } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java index fcf11629..cea32522 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java @@ -2,7 +2,9 @@ import com.modernfarmer.farmusspring.domain.farmclub.dto.req.CreateFarmClubRequestDto; import com.modernfarmer.farmusspring.domain.farmclub.dto.res.CreateFarmClubResponseDto; +import com.modernfarmer.farmusspring.domain.farmclub.dto.res.GetFarmClubResponseDto; import com.modernfarmer.farmusspring.domain.farmclub.dto.res.SearchFarmClubResponseDto; +import com.modernfarmer.farmusspring.domain.farmclub.entity.FarmClub; import com.modernfarmer.farmusspring.domain.farmclub.repository.FarmClubRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -23,7 +25,17 @@ public CreateFarmClubResponseDto createFarmClub(CreateFarmClubRequestDto request return null; } + public GetFarmClubResponseDto getFarmClub(Long id) { + FarmClub farmClub = getFarmClubEntity(id); + + return null; + } + public List searchFarmClub(List difficulties, String keyword) { return farmClubRepository.findByConditions(difficulties, keyword); } + + private FarmClub getFarmClubEntity(Long id) { + return farmClubRepository.findById(id).orElseThrow(() -> new IllegalArgumentException("존재하지 않는 팜클럽입니다.")); + } } From aa5398ffcacc838eaf6039c3988ce740e452e54e Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Mon, 8 Apr 2024 16:10:47 +0900 Subject: [PATCH 04/40] =?UTF-8?q?[feat]=20=ED=8C=9C=ED=81=B4=EB=9F=BD=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20api=20=EC=99=84=EC=84=B1=20=EB=B0=8F=20?= =?UTF-8?q?=EA=B2=80=EC=83=89=20api=20(=ED=8E=98=EC=9D=B4=EC=A7=95=20?= =?UTF-8?q?=EB=AF=B8=EC=A0=81=EC=9A=A9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/FarmClubController.java | 11 +++++---- .../dto/req/CreateFarmClubRequestDto.java | 22 +++++++++-------- .../dto/res/CreateFarmClubResponseDto.java | 14 +++++------ .../dto/res/GetFarmClubResponseDto.java | 7 +++--- .../dto/res/SearchFarmClubResponseDto.java | 24 +++++++++++++++---- .../domain/farmclub/entity/FarmClub.java | 3 ++- .../repository/FarmClubRepositoryImpl.java | 11 ++------- .../farmclub/service/FarmClubService.java | 23 +++++++++++++++++- .../dto/res/InfoForCreateFarmClub.java | 4 ++-- .../common/security/SecurityConfig.java | 6 +++-- 10 files changed, 78 insertions(+), 47 deletions(-) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java index 9074f7c4..02d3260f 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java @@ -3,9 +3,12 @@ import com.modernfarmer.farmusspring.domain.farmclub.dto.req.CreateFarmClubRequestDto; import com.modernfarmer.farmusspring.domain.farmclub.service.FarmClubService; import com.modernfarmer.farmusspring.global.response.BaseResponseDto; +import com.modernfarmer.farmusspring.global.response.SuccessCode; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; +import java.util.List; + @RestController @RequiredArgsConstructor @RequestMapping("/api/farm-club") @@ -19,9 +22,7 @@ public class FarmClubController { public BaseResponseDto createFarmClub( @RequestBody CreateFarmClubRequestDto requestDto ) { - - - return null; + return BaseResponseDto.of(SuccessCode.CREATED, farmClubService.createFarmClub(requestDto)); } @PostMapping("/register") @@ -34,10 +35,10 @@ public BaseResponseDto registerFarmClub( @GetMapping("/search") public BaseResponseDto searchFarmClub( + @RequestParam List difficulties, @RequestParam String keyword ) { - - return null; + return BaseResponseDto.of(SuccessCode.SUCCESS, farmClubService.searchFarmClub(difficulties, keyword)); } @GetMapping("/{id}") diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/req/CreateFarmClubRequestDto.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/req/CreateFarmClubRequestDto.java index 4788b1ef..4aecba9e 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/req/CreateFarmClubRequestDto.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/req/CreateFarmClubRequestDto.java @@ -1,18 +1,20 @@ package com.modernfarmer.farmusspring.domain.farmclub.dto.req; +import com.modernfarmer.farmusspring.domain.veggieinfo.enums.Difficulty; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; -@AllArgsConstructor -@NoArgsConstructor -@Getter -public class CreateFarmClubRequestDto { +public record CreateFarmClubRequestDto ( - private String farmClubName; - private String farmClubDescription; - private int maxMemberCount; - private String startDate; - private Long myVeggieId; - private String veggieInfoId; + String farmClubName, + String farmClubDescription, + int maxMemberCount, + String startDate, + Long myVeggieId, + String veggieInfoId +) { + public static CreateFarmClubRequestDto of(String farmClubName, String farmClubDescription, int maxMemberCount, String startDate, Long myVeggieId, String veggieInfoId) { + return new CreateFarmClubRequestDto(farmClubName, farmClubDescription, maxMemberCount, startDate, myVeggieId, veggieInfoId); + } } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/CreateFarmClubResponseDto.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/CreateFarmClubResponseDto.java index e866a1da..403ab968 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/CreateFarmClubResponseDto.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/CreateFarmClubResponseDto.java @@ -1,11 +1,9 @@ package com.modernfarmer.farmusspring.domain.farmclub.dto.res; -import lombok.AllArgsConstructor; -import lombok.NoArgsConstructor; - -@AllArgsConstructor(staticName = "of") -@NoArgsConstructor -public class CreateFarmClubResponseDto { - - private Long farmClubId; +public record CreateFarmClubResponseDto ( + Long farmClubId +){ + public static CreateFarmClubResponseDto of(Long farmClubId) { + return new CreateFarmClubResponseDto(farmClubId); + } } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetFarmClubResponseDto.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetFarmClubResponseDto.java index fa22c354..a4189032 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetFarmClubResponseDto.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetFarmClubResponseDto.java @@ -1,8 +1,5 @@ package com.modernfarmer.farmusspring.domain.farmclub.dto.res; -import lombok.AllArgsConstructor; - -@AllArgsConstructor(staticName = "of") public record GetFarmClubResponseDto ( Long farmClubId, String farmClubName, @@ -14,5 +11,7 @@ public record GetFarmClubResponseDto ( int currentMemberCount, String preparation ){ - + public static GetFarmClubResponseDto of(Long farmClubId, String farmClubName, String farmClubDescription, String veggieName, String veggieImage, String startedAt, int maxMemberCount, int currentMemberCount, String preparation) { + return new GetFarmClubResponseDto(farmClubId, farmClubName, farmClubDescription, veggieName, veggieImage, startedAt, maxMemberCount, currentMemberCount, preparation); + } } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/SearchFarmClubResponseDto.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/SearchFarmClubResponseDto.java index 42b4a296..642d335a 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/SearchFarmClubResponseDto.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/SearchFarmClubResponseDto.java @@ -1,14 +1,28 @@ package com.modernfarmer.farmusspring.domain.farmclub.dto.res; +import com.modernfarmer.farmusspring.domain.farmclub.entity.FarmClub; +import com.querydsl.core.annotations.QueryProjection; + +import java.time.LocalDate; + public record SearchFarmClubResponseDto ( - Long farmClubId, - String farmClubName, - String farmClubDescription, + Long id, + String name, String veggieName, String veggieImage, String difficulty, String startedAt, - int maxMemberCount + Integer maxUser ) { - + @QueryProjection + public SearchFarmClubResponseDto(FarmClub farmClub) { + this( + farmClub.getId(), + farmClub.getName(), + farmClub.getVeggieName(), + farmClub.getVeggieImage(), + farmClub.getDifficulty(), + farmClub.getStartedAt().toString(), + farmClub.getMaxUser()); + } } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/FarmClub.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/FarmClub.java index 7474dea7..4cad829a 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/FarmClub.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/FarmClub.java @@ -54,12 +54,13 @@ public class FarmClub extends BaseEntity { @Builder.Default private List diaries = new ArrayList<>(); - public static FarmClub createFarmClub(String veggieInfoId, String name, String description, String difficulty, int maxUser, LocalDate startedAt){ + public static FarmClub createFarmClub(String veggieInfoId, String name, String description, String difficulty, String veggieImage, int maxUser, LocalDate startedAt){ return FarmClub.builder() .veggieInfoId(veggieInfoId) .name(name) .description(description) .difficulty(difficulty) + .veggieImage(veggieImage) .maxUser(maxUser) .startedAt(startedAt) .build(); diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryImpl.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryImpl.java index d54a9f1b..e46373ca 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryImpl.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryImpl.java @@ -1,12 +1,11 @@ package com.modernfarmer.farmusspring.domain.farmclub.repository; +import com.modernfarmer.farmusspring.domain.farmclub.dto.res.QSearchFarmClubResponseDto; import com.modernfarmer.farmusspring.domain.farmclub.dto.res.SearchFarmClubResponseDto; import com.modernfarmer.farmusspring.domain.farmclub.entity.QFarmClub; -import com.querydsl.core.types.Projections; import com.querydsl.jpa.impl.JPAQueryFactory; import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceContext; -import org.joda.time.LocalDate; import java.util.List; @@ -21,13 +20,7 @@ public List findByConditions(List difficultie JPAQueryFactory queryFactory = new JPAQueryFactory(em); return queryFactory - .select(Projections.constructor(SearchFarmClubResponseDto.class, - farmClub.id, - farmClub.name, - farmClub.description, - farmClub.veggieImage, - farmClub.difficulty, - farmClub.startedAt)) + .select(new QSearchFarmClubResponseDto(farmClub)) .from(farmClub) .where(farmClub.difficulty.in(difficulties)) .where(farmClub.name.contains(keyword)) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java index cea32522..6f64b43c 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java @@ -6,8 +6,11 @@ import com.modernfarmer.farmusspring.domain.farmclub.dto.res.SearchFarmClubResponseDto; import com.modernfarmer.farmusspring.domain.farmclub.entity.FarmClub; import com.modernfarmer.farmusspring.domain.farmclub.repository.FarmClubRepository; +import com.modernfarmer.farmusspring.domain.veggieinfo.dto.res.InfoForCreateFarmClub; +import com.modernfarmer.farmusspring.domain.veggieinfo.service.VeggieInfoService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.joda.time.LocalDate; import org.springframework.stereotype.Service; import java.util.List; @@ -18,11 +21,16 @@ public class FarmClubService { private final FarmClubRepository farmClubRepository; + private final VeggieInfoService veggieInfoService; public CreateFarmClubResponseDto createFarmClub(CreateFarmClubRequestDto request) { // 몽고에서 이미지, 난이도 가져오기 + InfoForCreateFarmClub veggieInfo = veggieInfoService.getVeggieInfoForCreateFarmClub(request.veggieInfoId()); + FarmClub farmClub = createFarmClubEntity(request, veggieInfo); + Long newFarmClubId = farmClubRepository.save(farmClub).getId(); + // 채소 id로 팜클럽에 가입하는 메서드 추가 - return null; + return CreateFarmClubResponseDto.of(newFarmClubId); } public GetFarmClubResponseDto getFarmClub(Long id) { @@ -38,4 +46,17 @@ public List searchFarmClub(List difficulties, private FarmClub getFarmClubEntity(Long id) { return farmClubRepository.findById(id).orElseThrow(() -> new IllegalArgumentException("존재하지 않는 팜클럽입니다.")); } + + private FarmClub createFarmClubEntity(CreateFarmClubRequestDto request, InfoForCreateFarmClub veggieInfo) { + return FarmClub.builder() + .name(request.farmClubName()) + .description(request.farmClubDescription()) + .maxUser(request.maxMemberCount()) + .startedAt(LocalDate.parse(request.startDate())) + .veggieInfoId(request.veggieInfoId()) + .veggieName(veggieInfo.name()) + .difficulty(veggieInfo.difficulty().name()) + .veggieImage(veggieInfo.veggieImage()) + .build(); + } } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/dto/res/InfoForCreateFarmClub.java b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/dto/res/InfoForCreateFarmClub.java index 748ce160..016ed977 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/dto/res/InfoForCreateFarmClub.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/dto/res/InfoForCreateFarmClub.java @@ -3,8 +3,8 @@ import com.modernfarmer.farmusspring.domain.veggieinfo.enums.Difficulty; public record InfoForCreateFarmClub( - String veggieInfoId, - String veggieName, + String _id, + String name, String veggieImage, Difficulty difficulty ) { diff --git a/src/main/java/com/modernfarmer/farmusspring/global/common/security/SecurityConfig.java b/src/main/java/com/modernfarmer/farmusspring/global/common/security/SecurityConfig.java index 0a8854f8..dcb3bb54 100644 --- a/src/main/java/com/modernfarmer/farmusspring/global/common/security/SecurityConfig.java +++ b/src/main/java/com/modernfarmer/farmusspring/global/common/security/SecurityConfig.java @@ -43,7 +43,7 @@ public SecurityFilterChain filterChain(HttpSecurity http, HandlerMappingIntrospe .csrf(csrf -> csrf.disable()) .cors(withDefaults()) .headers(headers -> headers.frameOptions(frameOptions -> frameOptions.disable())) - .addFilterBefore(new JwtAuthenticationFilter(jwtTokenProvider), UsernamePasswordAuthenticationFilter.class) +// .addFilterBefore(new JwtAuthenticationFilter(jwtTokenProvider), UsernamePasswordAuthenticationFilter.class) .sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) .authorizeHttpRequests(request -> request .requestMatchers( @@ -56,7 +56,9 @@ public SecurityFilterChain filterChain(HttpSecurity http, HandlerMappingIntrospe "/api/user/profile-image", "/api/user/profile", "/api/veggie-info", - "/api/veggie-info/**" + "/api/veggie-info/**", + "/api/farm-club", + "/api/farm-club/**" ).permitAll() ) .authorizeHttpRequests(request -> request.anyRequest().authenticated()); From 08b70598a1daf54c9001cd8267db26c84a7501b1 Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Fri, 12 Apr 2024 14:14:44 +0900 Subject: [PATCH 05/40] =?UTF-8?q?[fix]=20=ED=8C=9C=ED=81=B4=EB=9F=BD=20?= =?UTF-8?q?=EC=B0=B8=EC=97=AC=20=EC=8B=9C=20=ED=98=84=EC=9E=AC=20=EC=8A=A4?= =?UTF-8?q?=ED=85=9D=EC=9D=84=201=EB=A1=9C=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farmusspring/domain/farmclub/entity/UserFarmClub.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/UserFarmClub.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/UserFarmClub.java index a4e3741f..230db14b 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/UserFarmClub.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/UserFarmClub.java @@ -42,10 +42,10 @@ public class UserFarmClub extends BaseEntity { @JoinColumn(name = "my_veggie_id") private MyVeggie myVeggie; - public static UserFarmClub createUserFarmClub(Long userId, int currentStep, String currentStepName, FarmClub farmClub, MyVeggie myVeggie){ + public static UserFarmClub createUserFarmClub(Long userId, String currentStepName, FarmClub farmClub, MyVeggie myVeggie){ UserFarmClub newUserFarmClub = UserFarmClub.builder() .userId(userId) - .currentStep(currentStep) + .currentStep(1) .currentStepName(currentStepName) .farmClub(farmClub) .myVeggie(myVeggie) From 7283ee4f55f1f50df8e6581e75f5b0560e0ececf Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Fri, 12 Apr 2024 14:15:06 +0900 Subject: [PATCH 06/40] =?UTF-8?q?[feat]=20=ED=8C=9C=ED=81=B4=EB=9F=BD=20?= =?UTF-8?q?=EC=B0=B8=EC=97=AC=20Dto?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/farmclub/dto/req/RegisterFarmClubRequestDto.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/req/RegisterFarmClubRequestDto.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/req/RegisterFarmClubRequestDto.java index 78f1c80a..2c6ea047 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/req/RegisterFarmClubRequestDto.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/req/RegisterFarmClubRequestDto.java @@ -2,5 +2,8 @@ public record RegisterFarmClubRequestDto ( + Long farmClubId, + Long myVeggieId + ){ } From 454e006a14db936d3658238cdb8a7405f6ed0bb7 Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Fri, 12 Apr 2024 14:28:05 +0900 Subject: [PATCH 07/40] =?UTF-8?q?[feat]=20FarmClub=20=EB=8F=84=EB=A9=94?= =?UTF-8?q?=EC=9D=B8=20Helper=20=ED=8C=A8=ED=84=B4=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/FarmClubController.java | 4 +- .../farmclub/helper/FarmClubHelper.java | 26 +++++++++++++ .../farmclub/service/FarmClubService.java | 38 +++++++++++-------- .../dto/res/InfoForCreateFarmClub.java | 2 +- 4 files changed, 52 insertions(+), 18 deletions(-) create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/farmclub/helper/FarmClubHelper.java diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java index 02d3260f..3bc92763 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java @@ -1,6 +1,7 @@ package com.modernfarmer.farmusspring.domain.farmclub.controller; import com.modernfarmer.farmusspring.domain.farmclub.dto.req.CreateFarmClubRequestDto; +import com.modernfarmer.farmusspring.domain.farmclub.helper.FarmClubHelper; import com.modernfarmer.farmusspring.domain.farmclub.service.FarmClubService; import com.modernfarmer.farmusspring.global.response.BaseResponseDto; import com.modernfarmer.farmusspring.global.response.SuccessCode; @@ -15,6 +16,7 @@ public class FarmClubController { private final FarmClubService farmClubService; + private final FarmClubHelper farmClubHelper; // 요청 : 이름, 설명, 최대인원, 모집기한, 내 채소 id, 채소정보 id // 응답 : 팜클럽 id @@ -38,7 +40,7 @@ public BaseResponseDto searchFarmClub( @RequestParam List difficulties, @RequestParam String keyword ) { - return BaseResponseDto.of(SuccessCode.SUCCESS, farmClubService.searchFarmClub(difficulties, keyword)); + return BaseResponseDto.of(SuccessCode.SUCCESS, farmClubHelper.searchFarmClub(difficulties, keyword)); } @GetMapping("/{id}") diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/helper/FarmClubHelper.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/helper/FarmClubHelper.java new file mode 100644 index 00000000..c2a55e41 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/helper/FarmClubHelper.java @@ -0,0 +1,26 @@ +package com.modernfarmer.farmusspring.domain.farmclub.helper; + +import com.modernfarmer.farmusspring.domain.farmclub.dto.res.SearchFarmClubResponseDto; +import com.modernfarmer.farmusspring.domain.farmclub.entity.FarmClub; +import com.modernfarmer.farmusspring.domain.farmclub.repository.FarmClubRepository; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Slf4j +@Component +@RequiredArgsConstructor +public class FarmClubHelper { + + private final FarmClubRepository farmClubRepository; + + public FarmClub getFarmClubEntity(Long id) { + return farmClubRepository.findById(id).orElseThrow(() -> new IllegalArgumentException("존재하지 않는 팜클럽입니다.")); + } + + public List searchFarmClub(List difficulties, String keyword) { + return farmClubRepository.findByConditions(difficulties, keyword); + } +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java index 6f64b43c..bab87337 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java @@ -1,11 +1,16 @@ package com.modernfarmer.farmusspring.domain.farmclub.service; import com.modernfarmer.farmusspring.domain.farmclub.dto.req.CreateFarmClubRequestDto; +import com.modernfarmer.farmusspring.domain.farmclub.dto.req.RegisterFarmClubRequestDto; import com.modernfarmer.farmusspring.domain.farmclub.dto.res.CreateFarmClubResponseDto; import com.modernfarmer.farmusspring.domain.farmclub.dto.res.GetFarmClubResponseDto; +import com.modernfarmer.farmusspring.domain.farmclub.dto.res.RegisterFarmClubResponseDto; import com.modernfarmer.farmusspring.domain.farmclub.dto.res.SearchFarmClubResponseDto; import com.modernfarmer.farmusspring.domain.farmclub.entity.FarmClub; +import com.modernfarmer.farmusspring.domain.farmclub.entity.UserFarmClub; +import com.modernfarmer.farmusspring.domain.farmclub.helper.FarmClubHelper; import com.modernfarmer.farmusspring.domain.farmclub.repository.FarmClubRepository; +import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.MyVeggie; import com.modernfarmer.farmusspring.domain.veggieinfo.dto.res.InfoForCreateFarmClub; import com.modernfarmer.farmusspring.domain.veggieinfo.service.VeggieInfoService; import lombok.RequiredArgsConstructor; @@ -21,6 +26,7 @@ public class FarmClubService { private final FarmClubRepository farmClubRepository; + private final FarmClubHelper farmClubHelper; private final VeggieInfoService veggieInfoService; public CreateFarmClubResponseDto createFarmClub(CreateFarmClubRequestDto request) { @@ -34,29 +40,29 @@ public CreateFarmClubResponseDto createFarmClub(CreateFarmClubRequestDto request } public GetFarmClubResponseDto getFarmClub(Long id) { - FarmClub farmClub = getFarmClubEntity(id); + FarmClub farmClub = farmClubHelper.getFarmClubEntity(id); return null; } - public List searchFarmClub(List difficulties, String keyword) { - return farmClubRepository.findByConditions(difficulties, keyword); + public RegisterFarmClubResponseDto registerFarmClub(RegisterFarmClubRequestDto request) { + // 채소 id로 채소 불러옴 + FarmClub farmClub = farmClubHelper.getFarmClubEntity(request.farmClubId()); + return null; } - private FarmClub getFarmClubEntity(Long id) { - return farmClubRepository.findById(id).orElseThrow(() -> new IllegalArgumentException("존재하지 않는 팜클럽입니다.")); + private FarmClub createFarmClubEntity(CreateFarmClubRequestDto request, InfoForCreateFarmClub veggieInfo) { + return FarmClub.createFarmClub( + request.veggieInfoId(), + request.farmClubName(), + request.farmClubDescription(), + veggieInfo.difficulty(), + veggieInfo.veggieImage(), + request.maxMemberCount(), + LocalDate.now()); } - private FarmClub createFarmClubEntity(CreateFarmClubRequestDto request, InfoForCreateFarmClub veggieInfo) { - return FarmClub.builder() - .name(request.farmClubName()) - .description(request.farmClubDescription()) - .maxUser(request.maxMemberCount()) - .startedAt(LocalDate.parse(request.startDate())) - .veggieInfoId(request.veggieInfoId()) - .veggieName(veggieInfo.name()) - .difficulty(veggieInfo.difficulty().name()) - .veggieImage(veggieInfo.veggieImage()) - .build(); + private UserFarmClub createUserFarmClubEntity(Long userId, String stepName, FarmClub farmClub, MyVeggie myVeggie) { + return UserFarmClub.createUserFarmClub(userId, stepName, farmClub, myVeggie); } } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/dto/res/InfoForCreateFarmClub.java b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/dto/res/InfoForCreateFarmClub.java index 016ed977..48be37cd 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/dto/res/InfoForCreateFarmClub.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/dto/res/InfoForCreateFarmClub.java @@ -6,6 +6,6 @@ public record InfoForCreateFarmClub( String _id, String name, String veggieImage, - Difficulty difficulty + String difficulty ) { } From d0caa161da159db936d47d1a8b554ef0e6eb48d0 Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Fri, 12 Apr 2024 14:35:52 +0900 Subject: [PATCH 08/40] =?UTF-8?q?[fix]=20farmClub=20->=20userFarmClub=20ca?= =?UTF-8?q?scade.all=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farmusspring/domain/farmclub/entity/FarmClub.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/FarmClub.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/FarmClub.java index 4cad829a..bd1a2a9c 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/FarmClub.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/FarmClub.java @@ -46,7 +46,7 @@ public class FarmClub extends BaseEntity { @Column(nullable = false) private LocalDate startedAt; - @OneToMany(mappedBy = "farmClub") + @OneToMany(mappedBy = "farmClub", cascade = CascadeType.ALL) @Builder.Default private List userFarmClubs = new ArrayList<>(); From 2b1088643b855bf6250455b6158aeda0bbf233b5 Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Fri, 12 Apr 2024 14:48:05 +0900 Subject: [PATCH 09/40] =?UTF-8?q?[feat]=20=ED=8C=9C=ED=81=B4=EB=9F=BD=20?= =?UTF-8?q?=EC=B0=B8=EC=97=AC=20=EB=A1=9C=EC=A7=81=20=EC=9E=91=EC=84=B1=20?= =?UTF-8?q?->=20=EC=95=84=EC=A7=81=20=EB=AF=B8=EA=B5=AC=ED=98=84=20(?= =?UTF-8?q?=EB=82=B4=20=EC=B1=84=EC=86=8C=20=EB=B6=88=EB=9F=AC=EC=98=A4?= =?UTF-8?q?=EA=B8=B0=20=EA=B5=AC=ED=98=84=20=ED=9B=84=20=EC=9E=91=EC=84=B1?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/farmclub/service/FarmClubService.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java index bab87337..51cf13dc 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java @@ -17,6 +17,7 @@ import lombok.extern.slf4j.Slf4j; import org.joda.time.LocalDate; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.List; @@ -45,9 +46,15 @@ public GetFarmClubResponseDto getFarmClub(Long id) { return null; } - public RegisterFarmClubResponseDto registerFarmClub(RegisterFarmClubRequestDto request) { + @Transactional + public RegisterFarmClubResponseDto registerFarmClub(RegisterFarmClubRequestDto request, Long userId) { // 채소 id로 채소 불러옴 + MyVeggie myVeggie = null; FarmClub farmClub = farmClubHelper.getFarmClubEntity(request.farmClubId()); + // 채소정보 id로 채소의 첫 스텝명 불러옴 + String stepName = ""; +// UserFarmClub userFarmClub = createUserFarmClubEntity(userId, stepName, farmClub, myVeggie); +// farmClub.addUserFarmClub(userFarmClub); return null; } From 755fe59cf0ca339be35825579ddadcc732e4a187 Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Fri, 12 Apr 2024 14:49:07 +0900 Subject: [PATCH 10/40] =?UTF-8?q?[feat]=20=ED=8C=9C=ED=81=B4=EB=9F=BD=20?= =?UTF-8?q?=EC=B0=B8=EC=97=AC=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=A0=95?= =?UTF-8?q?=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/farmclub/controller/FarmClubController.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java index 3bc92763..f0f12db0 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java @@ -31,8 +31,7 @@ public BaseResponseDto createFarmClub( public BaseResponseDto registerFarmClub( @RequestBody CreateFarmClubRequestDto requestDto ) { - - return null; + return BaseResponseDto.of(SuccessCode.CREATED, farmClubService.createFarmClub(requestDto)); } @GetMapping("/search") From 863bbdbe0972f376513f40af6952cc2db8f5eb6f Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Fri, 12 Apr 2024 16:34:00 +0900 Subject: [PATCH 11/40] =?UTF-8?q?[feat]=20=ED=8C=9C=ED=81=B4=EB=9F=BD=20?= =?UTF-8?q?=ED=83=90=EC=83=89=20=EB=8B=A8=EC=9D=BC=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/farmclub/controller/FarmClubController.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java index f0f12db0..ef801456 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java @@ -46,7 +46,6 @@ public BaseResponseDto searchFarmClub( public BaseResponseDto getFarmClub( @PathVariable Long id ) { - - return null; + return BaseResponseDto.of(SuccessCode.SUCCESS, farmClubService.getFarmClub(id)); } } From 489822cbe0327956505c7b483c53284a9c6f82a5 Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Fri, 12 Apr 2024 16:34:08 +0900 Subject: [PATCH 12/40] =?UTF-8?q?[feat]=20=ED=8C=9C=ED=81=B4=EB=9F=BD=20?= =?UTF-8?q?=ED=83=90=EC=83=89=20=EB=8B=A8=EC=9D=BC=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EC=84=9C=EB=B9=84=EC=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/farmclub/service/FarmClubService.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java index 51cf13dc..154e78c2 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java @@ -12,6 +12,7 @@ import com.modernfarmer.farmusspring.domain.farmclub.repository.FarmClubRepository; import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.MyVeggie; import com.modernfarmer.farmusspring.domain.veggieinfo.dto.res.InfoForCreateFarmClub; +import com.modernfarmer.farmusspring.domain.veggieinfo.helper.VeggieInfoHelper; import com.modernfarmer.farmusspring.domain.veggieinfo.service.VeggieInfoService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -29,6 +30,7 @@ public class FarmClubService { private final FarmClubRepository farmClubRepository; private final FarmClubHelper farmClubHelper; private final VeggieInfoService veggieInfoService; + private final VeggieInfoHelper veggieInfoHelper; public CreateFarmClubResponseDto createFarmClub(CreateFarmClubRequestDto request) { // 몽고에서 이미지, 난이도 가져오기 @@ -42,8 +44,8 @@ public CreateFarmClubResponseDto createFarmClub(CreateFarmClubRequestDto request public GetFarmClubResponseDto getFarmClub(Long id) { FarmClub farmClub = farmClubHelper.getFarmClubEntity(id); - - return null; + List help = veggieInfoHelper.getVeggieInfoHelp(farmClub.getVeggieInfoId()); + return GetFarmClubResponseDto.of(farmClub, farmClub.getUserFarmClubs().size(), help); } @Transactional From 68280a8645eb404fcbe35043d3c404ae84eeb915 Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Fri, 12 Apr 2024 16:34:42 +0900 Subject: [PATCH 13/40] =?UTF-8?q?[feat]=20VeggieInfo=20=EC=98=88=EC=99=B8?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC=EC=84=B1=20?= =?UTF-8?q?+=20=EB=8B=A8=EC=9D=BC=EC=A1=B0=ED=9A=8C=20=EC=98=88=EC=99=B8?= =?UTF-8?q?=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/VeggieInfoErrorCode.java | 15 +++++++++++++ .../exception/VeggieInfoExceptionHandler.java | 21 +++++++++++++++++++ .../custom/VeggieInfoNotFoundException.java | 8 +++++++ 3 files changed, 44 insertions(+) create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/exception/VeggieInfoErrorCode.java create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/exception/VeggieInfoExceptionHandler.java create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/exception/custom/VeggieInfoNotFoundException.java diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/exception/VeggieInfoErrorCode.java b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/exception/VeggieInfoErrorCode.java new file mode 100644 index 00000000..4e7d0388 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/exception/VeggieInfoErrorCode.java @@ -0,0 +1,15 @@ +package com.modernfarmer.farmusspring.domain.veggieinfo.exception; + +import com.modernfarmer.farmusspring.global.response.ResponseCode; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum VeggieInfoErrorCode implements ResponseCode { + + NotFoundVeggieInfo(5001, "채소 정보를 찾을 수 없습니다."); + + private final int code; + private final String message; +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/exception/VeggieInfoExceptionHandler.java b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/exception/VeggieInfoExceptionHandler.java new file mode 100644 index 00000000..a168a7dc --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/exception/VeggieInfoExceptionHandler.java @@ -0,0 +1,21 @@ +package com.modernfarmer.farmusspring.domain.veggieinfo.exception; + +import com.modernfarmer.farmusspring.domain.veggieinfo.exception.custom.VeggieInfoNotFoundException; +import com.modernfarmer.farmusspring.global.response.BaseResponseDto; +import jakarta.servlet.http.HttpServletRequest; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +@Slf4j +@RestControllerAdvice +public class VeggieInfoExceptionHandler { + @ExceptionHandler(VeggieInfoNotFoundException.class) + public BaseResponseDto handleVeggieInfoNotFoundException(VeggieInfoNotFoundException e, HttpServletRequest request) { + log.error("VeggieInfoNotFoundException : {} {} errMessage={}\n", + request.getMethod(), + request.getRequestURI(), + e.getMessage()); + return BaseResponseDto.of(VeggieInfoErrorCode.NotFoundVeggieInfo, e.getMessage()); + } +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/exception/custom/VeggieInfoNotFoundException.java b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/exception/custom/VeggieInfoNotFoundException.java new file mode 100644 index 00000000..cd84acc6 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/exception/custom/VeggieInfoNotFoundException.java @@ -0,0 +1,8 @@ +package com.modernfarmer.farmusspring.domain.veggieinfo.exception.custom; + +public class VeggieInfoNotFoundException extends RuntimeException { + + public VeggieInfoNotFoundException(String message) { + super(message); + } +} From becc7bb8b57d79c0024444182bf12a030fdc6e9e Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Fri, 12 Apr 2024 16:35:07 +0900 Subject: [PATCH 14/40] =?UTF-8?q?[feat]=20VeggieInfo=20Helper=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9=20=EB=B0=8F=20=EC=A4=80=EB=B9=84=EC=82=AC=ED=95=AD=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../veggieinfo/helper/VeggieInfoHelper.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/helper/VeggieInfoHelper.java diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/helper/VeggieInfoHelper.java b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/helper/VeggieInfoHelper.java new file mode 100644 index 00000000..90b53dfe --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/helper/VeggieInfoHelper.java @@ -0,0 +1,26 @@ +package com.modernfarmer.farmusspring.domain.veggieinfo.helper; + +import com.modernfarmer.farmusspring.domain.veggieinfo.entity.VeggieInfo; +import com.modernfarmer.farmusspring.domain.veggieinfo.exception.custom.VeggieInfoNotFoundException; +import com.modernfarmer.farmusspring.domain.veggieinfo.repository.VeggieInfoRepository; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.bson.types.ObjectId; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Slf4j +@Component +@RequiredArgsConstructor +public class VeggieInfoHelper { + + private final VeggieInfoRepository veggieInfoRepository; + + public List getVeggieInfoHelp(String veggieInfoId) { + VeggieInfo veggieInfo = veggieInfoRepository.findById(new ObjectId(veggieInfoId)) + .orElseThrow(() -> new VeggieInfoNotFoundException("존재하지 않는 채소 정보 아이디입니다.")); + + return veggieInfo.getHelp(); + } +} From 28ab79608c657a34caced35a55b8b0dbfb0ccfd6 Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Fri, 12 Apr 2024 16:35:37 +0900 Subject: [PATCH 15/40] =?UTF-8?q?[feat]=20=ED=8C=9C=ED=81=B4=EB=9F=BD=20?= =?UTF-8?q?=ED=83=90=EC=83=89=20=EB=8B=A8=EC=9D=BC=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EC=9D=91=EB=8B=B5=20Dto=20=EB=A7=A4=ED=95=91=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/res/GetFarmClubResponseDto.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetFarmClubResponseDto.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetFarmClubResponseDto.java index a4189032..08ff4d07 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetFarmClubResponseDto.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetFarmClubResponseDto.java @@ -1,5 +1,9 @@ package com.modernfarmer.farmusspring.domain.farmclub.dto.res; +import com.modernfarmer.farmusspring.domain.farmclub.entity.FarmClub; + +import java.util.List; + public record GetFarmClubResponseDto ( Long farmClubId, String farmClubName, @@ -9,9 +13,19 @@ public record GetFarmClubResponseDto ( String startedAt, int maxMemberCount, int currentMemberCount, - String preparation + List help ){ - public static GetFarmClubResponseDto of(Long farmClubId, String farmClubName, String farmClubDescription, String veggieName, String veggieImage, String startedAt, int maxMemberCount, int currentMemberCount, String preparation) { - return new GetFarmClubResponseDto(farmClubId, farmClubName, farmClubDescription, veggieName, veggieImage, startedAt, maxMemberCount, currentMemberCount, preparation); + public static GetFarmClubResponseDto of(FarmClub farmClub, int currentMemberCount, List help) { + return new GetFarmClubResponseDto( + farmClub.getId(), + farmClub.getName(), + farmClub.getDescription(), + farmClub.getVeggieName(), + farmClub.getVeggieImage(), + farmClub.getStartedAt().toString(), + farmClub.getMaxUser(), + currentMemberCount, + help + ); } } From 18d2e758e6feb899cfcb427f6078c533abf76a18 Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Fri, 12 Apr 2024 16:35:42 +0900 Subject: [PATCH 16/40] =?UTF-8?q?[feat]=20=ED=8C=9C=ED=81=B4=EB=9F=BD=20?= =?UTF-8?q?=ED=83=90=EC=83=89=20=EB=8B=A8=EC=9D=BC=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EC=84=9C=EB=B9=84=EC=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/veggieinfo/service/VeggieInfoService.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/service/VeggieInfoService.java b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/service/VeggieInfoService.java index 490abd14..ca08eb00 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/service/VeggieInfoService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/service/VeggieInfoService.java @@ -2,8 +2,10 @@ import com.modernfarmer.farmusspring.domain.veggieinfo.dto.res.InfoForCreateFarmClub; import com.modernfarmer.farmusspring.domain.veggieinfo.dto.res.InfoForRegister; +import com.modernfarmer.farmusspring.domain.veggieinfo.entity.VeggieInfo; import com.modernfarmer.farmusspring.domain.veggieinfo.repository.VeggieInfoRepository; import lombok.RequiredArgsConstructor; +import org.bson.types.ObjectId; import org.springframework.stereotype.Service; import java.util.List; @@ -23,4 +25,10 @@ public InfoForCreateFarmClub getVeggieInfoForCreateFarmClub(String veggieInfoId) // Get veggie info for create farm club return veggieInfoRepository.getVeggieInfoForCreateFarmClub(veggieInfoId); } + + public String getFirstStepName(String veggieInfoId) { + VeggieInfo veggieInfo = veggieInfoRepository.findById(new ObjectId(veggieInfoId)).orElseThrow(() -> new IllegalArgumentException("존재하지 않는 채소 정보입니다.")); + + return veggieInfo.getSteps().get(0).getContent(); + } } From bfac5d04c38048a5f4e08343bc615e6bf699558e Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Fri, 12 Apr 2024 17:47:56 +0900 Subject: [PATCH 17/40] =?UTF-8?q?[feat]=20=EB=82=B4=20=ED=8C=9C=ED=81=B4?= =?UTF-8?q?=EB=9F=BD=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?Dto?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/res/GetMyFarmClubListResponseDto.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetMyFarmClubListResponseDto.java diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetMyFarmClubListResponseDto.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetMyFarmClubListResponseDto.java new file mode 100644 index 00000000..779717ca --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetMyFarmClubListResponseDto.java @@ -0,0 +1,24 @@ +package com.modernfarmer.farmusspring.domain.farmclub.dto.res; + +import com.modernfarmer.farmusspring.domain.farmclub.entity.FarmClub; +import com.querydsl.core.annotations.QueryProjection; + +public record GetMyFarmClubListResponseDto( + Long farmClubId, + String farmClubImage, + String farmClubName, + String veggieName +) { + public static GetMyFarmClubListResponseDto of(Long farmClubId, String farmClubImage, String farmClubName, String veggieName) { + return new GetMyFarmClubListResponseDto(farmClubId, farmClubImage, farmClubName, veggieName); + } + + @QueryProjection + public GetMyFarmClubListResponseDto(FarmClub farmClub) { + this( + farmClub.getId(), + farmClub.getVeggieImage(), + farmClub.getName(), + farmClub.getVeggieName()); + } +} From 54c1d1cdc557f2b55aaecda120d9d8be9f853be6 Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Fri, 12 Apr 2024 17:48:02 +0900 Subject: [PATCH 18/40] =?UTF-8?q?[feat]=20=EB=82=B4=20=ED=8C=9C=ED=81=B4?= =?UTF-8?q?=EB=9F=BD=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EC=84=9C=EB=B9=84=EC=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/farmclub/service/FarmClubService.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java index 154e78c2..c764b7d0 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java @@ -2,10 +2,7 @@ import com.modernfarmer.farmusspring.domain.farmclub.dto.req.CreateFarmClubRequestDto; import com.modernfarmer.farmusspring.domain.farmclub.dto.req.RegisterFarmClubRequestDto; -import com.modernfarmer.farmusspring.domain.farmclub.dto.res.CreateFarmClubResponseDto; -import com.modernfarmer.farmusspring.domain.farmclub.dto.res.GetFarmClubResponseDto; -import com.modernfarmer.farmusspring.domain.farmclub.dto.res.RegisterFarmClubResponseDto; -import com.modernfarmer.farmusspring.domain.farmclub.dto.res.SearchFarmClubResponseDto; +import com.modernfarmer.farmusspring.domain.farmclub.dto.res.*; import com.modernfarmer.farmusspring.domain.farmclub.entity.FarmClub; import com.modernfarmer.farmusspring.domain.farmclub.entity.UserFarmClub; import com.modernfarmer.farmusspring.domain.farmclub.helper.FarmClubHelper; @@ -60,6 +57,10 @@ public RegisterFarmClubResponseDto registerFarmClub(RegisterFarmClubRequestDto r return null; } + public List getMyFarmClubList(Long userId) { + return farmClubRepository.findMyFarmClubList(userId); + } + private FarmClub createFarmClubEntity(CreateFarmClubRequestDto request, InfoForCreateFarmClub veggieInfo) { return FarmClub.createFarmClub( request.veggieInfoId(), From 7e5a348e6ad685e5c0dad359153a083599b859e1 Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Fri, 12 Apr 2024 17:48:16 +0900 Subject: [PATCH 19/40] =?UTF-8?q?[feat]=20=EB=82=B4=20=ED=8C=9C=ED=81=B4?= =?UTF-8?q?=EB=9F=BD=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EC=BF=BC=EB=A6=AC=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/FarmClubRepositoryCustom.java | 2 ++ .../repository/FarmClubRepositoryImpl.java | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryCustom.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryCustom.java index f9140fdc..fc0a15e0 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryCustom.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryCustom.java @@ -1,5 +1,6 @@ package com.modernfarmer.farmusspring.domain.farmclub.repository; +import com.modernfarmer.farmusspring.domain.farmclub.dto.res.GetMyFarmClubListResponseDto; import com.modernfarmer.farmusspring.domain.farmclub.dto.res.SearchFarmClubResponseDto; import com.modernfarmer.farmusspring.domain.farmclub.entity.FarmClub; @@ -7,4 +8,5 @@ public interface FarmClubRepositoryCustom { List findByConditions(List difficulties, String keyword); + List findMyFarmClubList(Long userId); } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryImpl.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryImpl.java index e46373ca..3497e37d 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryImpl.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryImpl.java @@ -1,14 +1,22 @@ package com.modernfarmer.farmusspring.domain.farmclub.repository; +import com.modernfarmer.farmusspring.domain.farmclub.dto.res.GetMyFarmClubListResponseDto; +import com.modernfarmer.farmusspring.domain.farmclub.dto.res.QGetMyFarmClubListResponseDto; import com.modernfarmer.farmusspring.domain.farmclub.dto.res.QSearchFarmClubResponseDto; import com.modernfarmer.farmusspring.domain.farmclub.dto.res.SearchFarmClubResponseDto; import com.modernfarmer.farmusspring.domain.farmclub.entity.QFarmClub; +import com.modernfarmer.farmusspring.domain.farmclub.entity.QUserFarmClub; import com.querydsl.jpa.impl.JPAQueryFactory; import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceContext; import java.util.List; +import static com.modernfarmer.farmusspring.domain.farmclub.entity.QFarmClub.farmClub; +import static com.modernfarmer.farmusspring.domain.farmclub.entity.QUserFarmClub.userFarmClub; +import static com.modernfarmer.farmusspring.domain.myveggiegarden.entity.QMyVeggie.myVeggie; +import static com.modernfarmer.farmusspring.domain.user.entity.QUser.user; + public class FarmClubRepositoryImpl implements FarmClubRepositoryCustom{ @PersistenceContext @@ -26,4 +34,18 @@ public List findByConditions(List difficultie .where(farmClub.name.contains(keyword)) .fetch(); } + + @Override + public List findMyFarmClubList(Long userId) { + JPAQueryFactory queryFactory = new JPAQueryFactory(em); + + return queryFactory + .select(new QGetMyFarmClubListResponseDto(farmClub)) + .from(user) + .join(user.myVeggies, myVeggie) + .join(myVeggie.userFarmClub, userFarmClub) + .join(userFarmClub.farmClub, farmClub) + .where(user.id.eq(userId)) + .fetch(); + } } From 81d1fd9a7a6eb92d5bea462630d43808b53ea385 Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Fri, 12 Apr 2024 17:48:24 +0900 Subject: [PATCH 20/40] =?UTF-8?q?[feat]=20=EB=82=B4=20=ED=8C=9C=ED=81=B4?= =?UTF-8?q?=EB=9F=BD=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/farmclub/controller/FarmClubController.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java index ef801456..8ce7508b 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java @@ -1,11 +1,13 @@ package com.modernfarmer.farmusspring.domain.farmclub.controller; +import com.modernfarmer.farmusspring.domain.auth.entity.CustomUser; import com.modernfarmer.farmusspring.domain.farmclub.dto.req.CreateFarmClubRequestDto; import com.modernfarmer.farmusspring.domain.farmclub.helper.FarmClubHelper; import com.modernfarmer.farmusspring.domain.farmclub.service.FarmClubService; import com.modernfarmer.farmusspring.global.response.BaseResponseDto; import com.modernfarmer.farmusspring.global.response.SuccessCode; import lombok.RequiredArgsConstructor; +import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; import java.util.List; @@ -48,4 +50,11 @@ public BaseResponseDto getFarmClub( ) { return BaseResponseDto.of(SuccessCode.SUCCESS, farmClubService.getFarmClub(id)); } + + @GetMapping("/me") + public BaseResponseDto getMyFarmClubList( + @AuthenticationPrincipal CustomUser user + ) { + return BaseResponseDto.of(SuccessCode.SUCCESS, farmClubService.getMyFarmClubList(user.getUserId())); + } } From 1995312f9675df27aea147b2bc39c046cb2b177c Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Fri, 12 Apr 2024 23:17:25 +0900 Subject: [PATCH 21/40] =?UTF-8?q?[feat]=20=ED=8C=9C=ED=81=B4=EB=9F=BD=20?= =?UTF-8?q?=EB=8B=A8=EC=9D=BC=EC=A1=B0=ED=9A=8C=20=EC=98=88=EC=99=B8?= =?UTF-8?q?=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farmclub/exception/FarmClubErrorCode.java | 15 +++++++++++++ .../exception/FarmClubExceptionHandler.java | 22 +++++++++++++++++++ .../custom/FarmClubNotFoundException.java | 8 +++++++ 3 files changed, 45 insertions(+) create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/FarmClubErrorCode.java create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/FarmClubExceptionHandler.java create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/custom/FarmClubNotFoundException.java diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/FarmClubErrorCode.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/FarmClubErrorCode.java new file mode 100644 index 00000000..1f8efa0c --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/FarmClubErrorCode.java @@ -0,0 +1,15 @@ +package com.modernfarmer.farmusspring.domain.farmclub.exception; + +import com.modernfarmer.farmusspring.global.response.ResponseCode; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum FarmClubErrorCode implements ResponseCode { + + FARM_CLUB_NOT_FOUND(3001, "해당 팜클럽을 찾을 수 없습니다."); + + private final int code; + private final String message; +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/FarmClubExceptionHandler.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/FarmClubExceptionHandler.java new file mode 100644 index 00000000..e3849bea --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/FarmClubExceptionHandler.java @@ -0,0 +1,22 @@ +package com.modernfarmer.farmusspring.domain.farmclub.exception; + +import com.modernfarmer.farmusspring.domain.farmclub.exception.custom.FarmClubNotFoundException; +import com.modernfarmer.farmusspring.global.response.BaseResponseDto; +import jakarta.servlet.http.HttpServletRequest; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +@Slf4j +@RestControllerAdvice(basePackages = "com.modernfarmer.farmusspring.domain.farmclub") +public class FarmClubExceptionHandler { + + @ExceptionHandler(FarmClubNotFoundException.class) + public BaseResponseDto handleFarmClubNotFoundException(FarmClubNotFoundException e, HttpServletRequest request) { + log.error("FarmClubNotFoundException : {} {} errMessage={}\n", + request.getMethod(), + request.getRequestURI(), + e.getMessage()); + return BaseResponseDto.of(FarmClubErrorCode.FARM_CLUB_NOT_FOUND, e.getMessage()); + } +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/custom/FarmClubNotFoundException.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/custom/FarmClubNotFoundException.java new file mode 100644 index 00000000..4082b554 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/custom/FarmClubNotFoundException.java @@ -0,0 +1,8 @@ +package com.modernfarmer.farmusspring.domain.farmclub.exception.custom; + +public class FarmClubNotFoundException extends RuntimeException { + + public FarmClubNotFoundException(String message) { + super(message); + } +} From 33b8470735c15c952eead8462a66349c53e64617 Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Fri, 12 Apr 2024 23:17:48 +0900 Subject: [PATCH 22/40] =?UTF-8?q?[feat]=20=EB=AF=B8=EC=85=98=20=EA=B2=8C?= =?UTF-8?q?=EC=8B=9C=EA=B8=80=20=EC=8A=A4=ED=85=9D=EB=B3=84=20=EB=B6=84?= =?UTF-8?q?=EB=A5=98=20=EC=BF=BC=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/MissionPostRepository.java | 7 ++++ .../MissionPostRepositoryCustom.java | 11 ++++++ .../repository/MissionPostRepositoryImpl.java | 39 +++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepository.java create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepositoryCustom.java create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepositoryImpl.java diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepository.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepository.java new file mode 100644 index 00000000..6776ecc2 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepository.java @@ -0,0 +1,7 @@ +package com.modernfarmer.farmusspring.domain.farmclub.repository; + +import com.modernfarmer.farmusspring.domain.farmclub.entity.MissionPost; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface MissionPostRepository extends JpaRepository, MissionPostRepositoryCustom { +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepositoryCustom.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepositoryCustom.java new file mode 100644 index 00000000..2552ab20 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepositoryCustom.java @@ -0,0 +1,11 @@ +package com.modernfarmer.farmusspring.domain.farmclub.repository; + + +import com.modernfarmer.farmusspring.domain.farmclub.vo.GetMissionPostListWithStepCountsAndImages; + +import java.util.List; + +public interface MissionPostRepositoryCustom { + + List getMissionPostStepNumAndImage(Long farmClubId); +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepositoryImpl.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepositoryImpl.java new file mode 100644 index 00000000..3ed76767 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepositoryImpl.java @@ -0,0 +1,39 @@ +package com.modernfarmer.farmusspring.domain.farmclub.repository; + + +import com.modernfarmer.farmusspring.domain.farmclub.vo.GetMissionPostListWithStepCountsAndImages; +import com.modernfarmer.farmusspring.domain.farmclub.vo.QGetMissionPostListWithStepCountsAndImages; +import com.querydsl.core.group.GroupBy; +import com.querydsl.jpa.impl.JPAQueryFactory; +import jakarta.persistence.EntityManager; +import jakarta.persistence.PersistenceContext; + +import java.util.List; + +import static com.modernfarmer.farmusspring.domain.farmclub.entity.QFarmClub.farmClub; +import static com.modernfarmer.farmusspring.domain.farmclub.entity.QMissionPost.missionPost; +import static com.modernfarmer.farmusspring.domain.farmclub.entity.QUserFarmClub.userFarmClub; + +public class MissionPostRepositoryImpl implements MissionPostRepositoryCustom { + + @PersistenceContext + private EntityManager em; + + @Override + public List getMissionPostStepNumAndImage(Long farmClubId) { + JPAQueryFactory queryFactory = new JPAQueryFactory(em); + + return queryFactory + .from(missionPost) + .join(missionPost.userFarmClub, userFarmClub) + .join(userFarmClub.farmClub, farmClub) + .where(farmClub.id.eq(farmClubId)) + .transform( + GroupBy.groupBy(missionPost.stepNum) + .list(new QGetMissionPostListWithStepCountsAndImages( + missionPost.stepNum.count(), + GroupBy.list(missionPost.image) + )) + ); + } +} From bcb4e17a2c341b86a302da25965c10c910e3d439 Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Fri, 12 Apr 2024 23:18:06 +0900 Subject: [PATCH 23/40] =?UTF-8?q?[feat]=20=EB=AF=B8=EC=85=98=20=EA=B2=8C?= =?UTF-8?q?=EC=8B=9C=EA=B8=80=20=EC=8A=A4=ED=85=9D=EB=B3=84=20=EB=B6=84?= =?UTF-8?q?=EB=A5=98=20=EC=BF=BC=EB=A6=AC=20Vo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...GetMissionPostListWithStepCountsAndImages.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/farmclub/vo/GetMissionPostListWithStepCountsAndImages.java diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/vo/GetMissionPostListWithStepCountsAndImages.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/vo/GetMissionPostListWithStepCountsAndImages.java new file mode 100644 index 00000000..ae1d2869 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/vo/GetMissionPostListWithStepCountsAndImages.java @@ -0,0 +1,15 @@ +package com.modernfarmer.farmusspring.domain.farmclub.vo; + +import com.modernfarmer.farmusspring.domain.farmclub.entity.MissionPost; +import com.querydsl.core.annotations.QueryProjection; + +import java.util.List; + +public record GetMissionPostListWithStepCountsAndImages( + Long count, + List images +) { + @QueryProjection + public GetMissionPostListWithStepCountsAndImages { + } +} From f4b807ff7308faad4af2eae06115346f4c76ea32 Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Fri, 12 Apr 2024 23:18:33 +0900 Subject: [PATCH 24/40] =?UTF-8?q?[feat]=20=EC=B0=B8=EC=97=AC=EC=A4=91?= =?UTF-8?q?=EC=9D=B8=20=ED=8C=9C=ED=81=B4=EB=9F=BD=20=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EC=BF=BC=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/FarmClubRepositoryCustom.java | 3 +- .../repository/FarmClubRepositoryImpl.java | 42 ++++++++++++++++--- .../domain/farmclub/vo/GetMyFarmClubVo.java | 39 +++++++++++++++++ 3 files changed, 77 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/farmclub/vo/GetMyFarmClubVo.java diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryCustom.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryCustom.java index fc0a15e0..28a7e715 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryCustom.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryCustom.java @@ -1,12 +1,13 @@ package com.modernfarmer.farmusspring.domain.farmclub.repository; import com.modernfarmer.farmusspring.domain.farmclub.dto.res.GetMyFarmClubListResponseDto; +import com.modernfarmer.farmusspring.domain.farmclub.vo.GetMyFarmClubVo; import com.modernfarmer.farmusspring.domain.farmclub.dto.res.SearchFarmClubResponseDto; -import com.modernfarmer.farmusspring.domain.farmclub.entity.FarmClub; import java.util.List; public interface FarmClubRepositoryCustom { List findByConditions(List difficulties, String keyword); List findMyFarmClubList(Long userId); + GetMyFarmClubVo findMyFarmClub(Long farmClubId, Long userId); } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryImpl.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryImpl.java index 3497e37d..1e8d1ae0 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryImpl.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryImpl.java @@ -1,11 +1,10 @@ package com.modernfarmer.farmusspring.domain.farmclub.repository; -import com.modernfarmer.farmusspring.domain.farmclub.dto.res.GetMyFarmClubListResponseDto; -import com.modernfarmer.farmusspring.domain.farmclub.dto.res.QGetMyFarmClubListResponseDto; -import com.modernfarmer.farmusspring.domain.farmclub.dto.res.QSearchFarmClubResponseDto; -import com.modernfarmer.farmusspring.domain.farmclub.dto.res.SearchFarmClubResponseDto; +import com.modernfarmer.farmusspring.domain.farmclub.dto.res.*; import com.modernfarmer.farmusspring.domain.farmclub.entity.QFarmClub; -import com.modernfarmer.farmusspring.domain.farmclub.entity.QUserFarmClub; +import com.modernfarmer.farmusspring.domain.farmclub.exception.custom.FarmClubNotFoundException; +import com.modernfarmer.farmusspring.domain.farmclub.vo.GetMyFarmClubVo; +import com.modernfarmer.farmusspring.domain.farmclub.vo.QGetMyFarmClubVo_BaseInfo; import com.querydsl.jpa.impl.JPAQueryFactory; import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceContext; @@ -17,7 +16,7 @@ import static com.modernfarmer.farmusspring.domain.myveggiegarden.entity.QMyVeggie.myVeggie; import static com.modernfarmer.farmusspring.domain.user.entity.QUser.user; -public class FarmClubRepositoryImpl implements FarmClubRepositoryCustom{ +public class FarmClubRepositoryImpl implements FarmClubRepositoryCustom { @PersistenceContext private EntityManager em; @@ -48,4 +47,35 @@ public List findMyFarmClubList(Long userId) { .where(user.id.eq(userId)) .fetch(); } + + @Override + public GetMyFarmClubVo findMyFarmClub(Long farmClubId, Long userId) { + JPAQueryFactory queryFactory = new JPAQueryFactory(em); + + GetMyFarmClubVo.BaseInfo baseInfo = queryFactory + .select(new QGetMyFarmClubVo_BaseInfo(farmClub)) + .from(farmClub) + .where(farmClub.id.eq(farmClubId)) + .fetchOne(); + + if (baseInfo != null) { + Long userFarmClubCount = queryFactory + .select(userFarmClub.count()) + .from(userFarmClub) + .where(userFarmClub.farmClub.id.eq(farmClubId)) + .fetchOne(); + + Integer daySinceStart = queryFactory + .select(userFarmClub.createdDate.dayOfYear().subtract(farmClub.startedAt.dayOfYear())) + .from(userFarmClub) + .where(userFarmClub.farmClub.id.eq(farmClubId)) + .where(userFarmClub.userId.eq(userId)) + .fetchOne(); + + return GetMyFarmClubVo.of(baseInfo, userFarmClubCount, daySinceStart); + } else { + throw new FarmClubNotFoundException("내 팜클럽을 불러오는 도중 에러가 발생했습니다."); + } + } + } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/vo/GetMyFarmClubVo.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/vo/GetMyFarmClubVo.java new file mode 100644 index 00000000..044e6fdc --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/vo/GetMyFarmClubVo.java @@ -0,0 +1,39 @@ +package com.modernfarmer.farmusspring.domain.farmclub.vo; + +import com.modernfarmer.farmusspring.domain.farmclub.entity.FarmClub; +import com.querydsl.core.annotations.QueryProjection; + +public record GetMyFarmClubVo( + + String farmClubName, + String farmClubImage, + String veggieInfoId, + Long wholeMemberCount, + Integer daySinceStart +) { + public static GetMyFarmClubVo of(BaseInfo baseInfo, Long wholeMemberCount, Integer daySinceStart) { + return new GetMyFarmClubVo( + baseInfo.farmClubName(), + baseInfo.farmClubImage(), + baseInfo.veggieInfoId(), + wholeMemberCount, + daySinceStart + ); + } + + public record BaseInfo( + String farmClubName, + String farmClubImage, + String veggieInfoId + ) { + + @QueryProjection + public BaseInfo(FarmClub farmClub) { + this( + farmClub.getName(), + farmClub.getVeggieImage(), + farmClub.getVeggieInfoId() + ); + } + } +} From 3653ab596d49247521fd30b76f824fda7d3f4104 Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Fri, 12 Apr 2024 23:19:03 +0900 Subject: [PATCH 25/40] =?UTF-8?q?[feat]=20=EC=8A=A4=ED=85=9D=20=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D=20=EC=A0=84=EC=B2=B4=20=EC=A1=B0=ED=9A=8C=20=EC=BF=BC?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/veggieinfo/helper/VeggieInfoHelper.java | 5 +++++ .../repository/CustomVeggieInfoRepository.java | 3 ++- .../repository/VeggieInfoRepositoryImpl.java | 13 +++++++++++++ .../farmusspring/domain/veggieinfo/vo/StepVo.java | 10 ++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/vo/StepVo.java diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/helper/VeggieInfoHelper.java b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/helper/VeggieInfoHelper.java index 90b53dfe..850255ef 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/helper/VeggieInfoHelper.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/helper/VeggieInfoHelper.java @@ -3,6 +3,7 @@ import com.modernfarmer.farmusspring.domain.veggieinfo.entity.VeggieInfo; import com.modernfarmer.farmusspring.domain.veggieinfo.exception.custom.VeggieInfoNotFoundException; import com.modernfarmer.farmusspring.domain.veggieinfo.repository.VeggieInfoRepository; +import com.modernfarmer.farmusspring.domain.veggieinfo.vo.StepVo; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.bson.types.ObjectId; @@ -23,4 +24,8 @@ public List getVeggieInfoHelp(String veggieInfoId) { return veggieInfo.getHelp(); } + + public List getStepList(String veggieInfoId) { + return veggieInfoRepository.getVeggieInfoStepList(veggieInfoId); + } } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/repository/CustomVeggieInfoRepository.java b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/repository/CustomVeggieInfoRepository.java index f8326c89..e910851f 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/repository/CustomVeggieInfoRepository.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/repository/CustomVeggieInfoRepository.java @@ -2,12 +2,13 @@ import com.modernfarmer.farmusspring.domain.veggieinfo.dto.res.InfoForCreateFarmClub; import com.modernfarmer.farmusspring.domain.veggieinfo.dto.res.InfoForRegister; +import com.modernfarmer.farmusspring.domain.veggieinfo.vo.StepVo; import java.util.List; public interface CustomVeggieInfoRepository { List getVeggieInfoListForRegister(); - InfoForCreateFarmClub getVeggieInfoForCreateFarmClub(String veggieInfoId); + List getVeggieInfoStepList(String veggieInfoId); } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/repository/VeggieInfoRepositoryImpl.java b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/repository/VeggieInfoRepositoryImpl.java index 1dbcfe72..4f18c281 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/repository/VeggieInfoRepositoryImpl.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/repository/VeggieInfoRepositoryImpl.java @@ -3,6 +3,7 @@ import com.modernfarmer.farmusspring.domain.veggieinfo.dto.res.InfoForCreateFarmClub; import com.modernfarmer.farmusspring.domain.veggieinfo.dto.res.InfoForRegister; +import com.modernfarmer.farmusspring.domain.veggieinfo.vo.StepVo; import lombok.RequiredArgsConstructor; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.query.Criteria; @@ -45,4 +46,16 @@ public InfoForCreateFarmClub getVeggieInfoForCreateFarmClub(String veggieInfoId) return mongoTemplate.findOne(query, InfoForCreateFarmClub.class, "veggie_info"); } + + @Override + public List getVeggieInfoStepList(String veggieInfoId) { + // Query to get all steps from veggieInfo collection + // and return as List + Query query = new Query(); + query.addCriteria(Criteria.where("_id").is(veggieInfoId)) + .fields() + .include("steps"); + + return mongoTemplate.find(query, StepVo.class, "veggie_info"); + } } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/vo/StepVo.java b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/vo/StepVo.java new file mode 100644 index 00000000..9cc76725 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/vo/StepVo.java @@ -0,0 +1,10 @@ +package com.modernfarmer.farmusspring.domain.veggieinfo.vo; + +import java.util.List; + +public record StepVo( + int num, + String content, + List tips +) { +} From 0a3d16bb2c7f67058e2200639b21f28d4ed1c8ad Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Fri, 12 Apr 2024 23:19:38 +0900 Subject: [PATCH 26/40] =?UTF-8?q?[fix]=20MissionPost=20=EC=BB=AC=EB=9F=BC?= =?UTF-8?q?=20=EB=84=A4=EC=9D=B4=EB=B0=8D=20=EC=98=A4=EB=A5=98=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farmusspring/domain/farmclub/entity/MissionPost.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPost.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPost.java index 68661129..ae45c469 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPost.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPost.java @@ -24,7 +24,7 @@ public class MissionPost extends BaseEntity { private String content; @Column(nullable = false) - private Long step_num; + private Long stepNum; @Column(nullable = false) private String image; @@ -41,10 +41,10 @@ public class MissionPost extends BaseEntity { @JoinColumn(name = "user_farm_club_id") private UserFarmClub userFarmClub; - public static MissionPost createMissionPost(String content, Long step_num, String image, UserFarmClub userFarmClub){ + public static MissionPost createMissionPost(String content, Long stepNum, String image, UserFarmClub userFarmClub){ MissionPost newMissionPost = MissionPost.builder() .content(content) - .step_num(step_num) + .stepNum(stepNum) .image(image) .userFarmClub(userFarmClub) .build(); From 6294e0a0b9354736b7d6a451c865434dcee616f8 Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Fri, 12 Apr 2024 23:19:57 +0900 Subject: [PATCH 27/40] =?UTF-8?q?[feat]=20=EB=82=B4=20=ED=8C=9C=ED=81=B4?= =?UTF-8?q?=EB=9F=BD=20=EB=8B=A8=EC=9D=BC=20=EC=A1=B0=ED=9A=8C=20API=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/FarmClubController.java | 8 +++ .../dto/res/GetMyFarmClubResponseDto.java | 51 +++++++++++++++++++ .../farmclub/service/FarmClubService.java | 27 ++++++++++ 3 files changed, 86 insertions(+) create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetMyFarmClubResponseDto.java diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java index 8ce7508b..8e2184c7 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java @@ -57,4 +57,12 @@ public BaseResponseDto getMyFarmClubList( ) { return BaseResponseDto.of(SuccessCode.SUCCESS, farmClubService.getMyFarmClubList(user.getUserId())); } + + @GetMapping("/me/{farmClubId}") + public BaseResponseDto getMyFarmClub( + @PathVariable Long farmClubId, + @AuthenticationPrincipal CustomUser user + ) { + return BaseResponseDto.of(SuccessCode.SUCCESS, farmClubService.getMyFarmClub(farmClubId, user.getUserId())); + } } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetMyFarmClubResponseDto.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetMyFarmClubResponseDto.java new file mode 100644 index 00000000..686492e9 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetMyFarmClubResponseDto.java @@ -0,0 +1,51 @@ +package com.modernfarmer.farmusspring.domain.farmclub.dto.res; + +import com.modernfarmer.farmusspring.domain.farmclub.vo.GetMissionPostListWithStepCountsAndImages; +import com.modernfarmer.farmusspring.domain.farmclub.vo.GetMyFarmClubVo; +import com.modernfarmer.farmusspring.domain.veggieinfo.vo.StepVo; + +import java.util.ArrayList; +import java.util.List; + +public record GetMyFarmClubResponseDto( + String farmClubName, + String farmClubImage, + Long wholeMemberCount, + List steps, + String advice, + int daysSinceStart +) { + + public static GetMyFarmClubResponseDto of(GetMyFarmClubVo farmClubInfo, List steps, String advice) { + return new GetMyFarmClubResponseDto( + farmClubInfo.farmClubName(), + farmClubInfo.farmClubImage(), + farmClubInfo.wholeMemberCount(), + steps, + advice, + farmClubInfo.daySinceStart()); + } + + public static List createSteps(List stepVoList, List missionList) { + List steps = new ArrayList<>(); + for (int i = 0; i < stepVoList.size(); i++) { + Step step = new Step( + missionList.get(i).images(), + stepVoList.get(i).num(), + stepVoList.get(i).content(), + missionList.get(i).count() + ); + steps.add(step); + } + return steps; + } + + public record Step( + List images, + int stepNum, + String stepName, + Long completeMemberCount + ) { + + } +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java index c764b7d0..6fb1a7f9 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java @@ -7,16 +7,21 @@ import com.modernfarmer.farmusspring.domain.farmclub.entity.UserFarmClub; import com.modernfarmer.farmusspring.domain.farmclub.helper.FarmClubHelper; import com.modernfarmer.farmusspring.domain.farmclub.repository.FarmClubRepository; +import com.modernfarmer.farmusspring.domain.farmclub.repository.MissionPostRepository; +import com.modernfarmer.farmusspring.domain.farmclub.vo.GetMissionPostListWithStepCountsAndImages; +import com.modernfarmer.farmusspring.domain.farmclub.vo.GetMyFarmClubVo; import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.MyVeggie; import com.modernfarmer.farmusspring.domain.veggieinfo.dto.res.InfoForCreateFarmClub; import com.modernfarmer.farmusspring.domain.veggieinfo.helper.VeggieInfoHelper; import com.modernfarmer.farmusspring.domain.veggieinfo.service.VeggieInfoService; +import com.modernfarmer.farmusspring.domain.veggieinfo.vo.StepVo; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.joda.time.LocalDate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; import java.util.List; @Service @@ -28,6 +33,7 @@ public class FarmClubService { private final FarmClubHelper farmClubHelper; private final VeggieInfoService veggieInfoService; private final VeggieInfoHelper veggieInfoHelper; + private final MissionPostRepository missionPostRepository; public CreateFarmClubResponseDto createFarmClub(CreateFarmClubRequestDto request) { // 몽고에서 이미지, 난이도 가져오기 @@ -57,10 +63,31 @@ public RegisterFarmClubResponseDto registerFarmClub(RegisterFarmClubRequestDto r return null; } + // 팜클럽으로부터 채소 정보 id, 이름, 이미지, 시작일, 전체 멤버 수 가져옴 + // 채소 정보로부터 랜덤 도움말 1, 스텝 정보(스텝수, 스텝명) 가져옴 + // 미션포스트로부터 각 스텝 별 완료 수, 이미지 3개 가져옴 + // 가져온 스텝 정보들을 조합해서 최종 GetMyFarmClubResponseDto 생성 + public GetMyFarmClubResponseDto getMyFarmClub(Long userId, Long farmClubId) { + GetMyFarmClubVo farmClubInfo = farmClubRepository.findMyFarmClub(farmClubId, userId); + String veggieInfoId = farmClubInfo.veggieInfoId(); + List stepList = veggieInfoHelper.getStepList(veggieInfoId); + String randomTip = getRandomTip(stepList); + List missionList = + missionPostRepository.getMissionPostStepNumAndImage(farmClubId); + + return GetMyFarmClubResponseDto.of(farmClubInfo, GetMyFarmClubResponseDto.createSteps(stepList, missionList), randomTip); + } + public List getMyFarmClubList(Long userId) { return farmClubRepository.findMyFarmClubList(userId); } + private String getRandomTip(List stepList) { + List tips = new ArrayList<>(); + stepList.forEach(step -> tips.addAll(step.tips())); + return tips.get((int) (Math.random() * tips.size())); + } + private FarmClub createFarmClubEntity(CreateFarmClubRequestDto request, InfoForCreateFarmClub veggieInfo) { return FarmClub.createFarmClub( request.veggieInfoId(), From a9f474fcc7ec257713b2f67bd80963651a936364 Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Mon, 15 Apr 2024 13:25:15 +0900 Subject: [PATCH 28/40] =?UTF-8?q?[fix]=20=ED=8C=9C=ED=81=B4=EB=9F=BD=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20=EC=A0=95=EB=B3=B4=20=EC=B6=94=EC=B6=9C=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20Service=20->=20Helper=20=EB=A1=9C?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD=20=EB=B0=8F=20VO=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/farmclub/service/FarmClubService.java | 11 +++++------ ...foForCreateFarmClub.java => CreateFarmClubVo.java} | 4 +--- .../domain/veggieinfo/helper/VeggieInfoHelper.java | 6 ++++++ .../repository/CustomVeggieInfoRepository.java | 4 ++-- .../repository/VeggieInfoRepositoryImpl.java | 6 +++--- .../domain/veggieinfo/service/VeggieInfoService.java | 6 ------ 6 files changed, 17 insertions(+), 20 deletions(-) rename src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/dto/res/{InfoForCreateFarmClub.java => CreateFarmClubVo.java} (57%) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java index 6fb1a7f9..6e0ce15c 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java @@ -11,9 +11,8 @@ import com.modernfarmer.farmusspring.domain.farmclub.vo.GetMissionPostListWithStepCountsAndImages; import com.modernfarmer.farmusspring.domain.farmclub.vo.GetMyFarmClubVo; import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.MyVeggie; -import com.modernfarmer.farmusspring.domain.veggieinfo.dto.res.InfoForCreateFarmClub; +import com.modernfarmer.farmusspring.domain.veggieinfo.dto.res.CreateFarmClubVo; import com.modernfarmer.farmusspring.domain.veggieinfo.helper.VeggieInfoHelper; -import com.modernfarmer.farmusspring.domain.veggieinfo.service.VeggieInfoService; import com.modernfarmer.farmusspring.domain.veggieinfo.vo.StepVo; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -29,15 +28,15 @@ @Slf4j public class FarmClubService { - private final FarmClubRepository farmClubRepository; private final FarmClubHelper farmClubHelper; - private final VeggieInfoService veggieInfoService; private final VeggieInfoHelper veggieInfoHelper; + private final MissionPostRepository missionPostRepository; + private final FarmClubRepository farmClubRepository; public CreateFarmClubResponseDto createFarmClub(CreateFarmClubRequestDto request) { // 몽고에서 이미지, 난이도 가져오기 - InfoForCreateFarmClub veggieInfo = veggieInfoService.getVeggieInfoForCreateFarmClub(request.veggieInfoId()); + CreateFarmClubVo veggieInfo = veggieInfoHelper.getVeggieInfoForCreateFarmClub(request.veggieInfoId()); FarmClub farmClub = createFarmClubEntity(request, veggieInfo); Long newFarmClubId = farmClubRepository.save(farmClub).getId(); // 채소 id로 팜클럽에 가입하는 메서드 추가 @@ -88,7 +87,7 @@ private String getRandomTip(List stepList) { return tips.get((int) (Math.random() * tips.size())); } - private FarmClub createFarmClubEntity(CreateFarmClubRequestDto request, InfoForCreateFarmClub veggieInfo) { + private FarmClub createFarmClubEntity(CreateFarmClubRequestDto request, CreateFarmClubVo veggieInfo) { return FarmClub.createFarmClub( request.veggieInfoId(), request.farmClubName(), diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/dto/res/InfoForCreateFarmClub.java b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/dto/res/CreateFarmClubVo.java similarity index 57% rename from src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/dto/res/InfoForCreateFarmClub.java rename to src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/dto/res/CreateFarmClubVo.java index 48be37cd..fda4050a 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/dto/res/InfoForCreateFarmClub.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/dto/res/CreateFarmClubVo.java @@ -1,8 +1,6 @@ package com.modernfarmer.farmusspring.domain.veggieinfo.dto.res; -import com.modernfarmer.farmusspring.domain.veggieinfo.enums.Difficulty; - -public record InfoForCreateFarmClub( +public record CreateFarmClubVo( String _id, String name, String veggieImage, diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/helper/VeggieInfoHelper.java b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/helper/VeggieInfoHelper.java index 850255ef..7b3a3385 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/helper/VeggieInfoHelper.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/helper/VeggieInfoHelper.java @@ -1,5 +1,6 @@ package com.modernfarmer.farmusspring.domain.veggieinfo.helper; +import com.modernfarmer.farmusspring.domain.veggieinfo.dto.res.CreateFarmClubVo; import com.modernfarmer.farmusspring.domain.veggieinfo.entity.VeggieInfo; import com.modernfarmer.farmusspring.domain.veggieinfo.exception.custom.VeggieInfoNotFoundException; import com.modernfarmer.farmusspring.domain.veggieinfo.repository.VeggieInfoRepository; @@ -25,6 +26,11 @@ public List getVeggieInfoHelp(String veggieInfoId) { return veggieInfo.getHelp(); } + public CreateFarmClubVo getVeggieInfoForCreateFarmClub(String veggieInfoId) { + // Get veggie info for create farm club + return veggieInfoRepository.getVeggieInfoForCreateFarmClub(veggieInfoId); + } + public List getStepList(String veggieInfoId) { return veggieInfoRepository.getVeggieInfoStepList(veggieInfoId); } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/repository/CustomVeggieInfoRepository.java b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/repository/CustomVeggieInfoRepository.java index e910851f..20e25c7e 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/repository/CustomVeggieInfoRepository.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/repository/CustomVeggieInfoRepository.java @@ -1,6 +1,6 @@ package com.modernfarmer.farmusspring.domain.veggieinfo.repository; -import com.modernfarmer.farmusspring.domain.veggieinfo.dto.res.InfoForCreateFarmClub; +import com.modernfarmer.farmusspring.domain.veggieinfo.dto.res.CreateFarmClubVo; import com.modernfarmer.farmusspring.domain.veggieinfo.dto.res.InfoForRegister; import com.modernfarmer.farmusspring.domain.veggieinfo.vo.StepVo; @@ -9,6 +9,6 @@ public interface CustomVeggieInfoRepository { List getVeggieInfoListForRegister(); - InfoForCreateFarmClub getVeggieInfoForCreateFarmClub(String veggieInfoId); + CreateFarmClubVo getVeggieInfoForCreateFarmClub(String veggieInfoId); List getVeggieInfoStepList(String veggieInfoId); } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/repository/VeggieInfoRepositoryImpl.java b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/repository/VeggieInfoRepositoryImpl.java index 4f18c281..fa6271f6 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/repository/VeggieInfoRepositoryImpl.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/repository/VeggieInfoRepositoryImpl.java @@ -1,7 +1,7 @@ package com.modernfarmer.farmusspring.domain.veggieinfo.repository; -import com.modernfarmer.farmusspring.domain.veggieinfo.dto.res.InfoForCreateFarmClub; +import com.modernfarmer.farmusspring.domain.veggieinfo.dto.res.CreateFarmClubVo; import com.modernfarmer.farmusspring.domain.veggieinfo.dto.res.InfoForRegister; import com.modernfarmer.farmusspring.domain.veggieinfo.vo.StepVo; import lombok.RequiredArgsConstructor; @@ -34,7 +34,7 @@ public List getVeggieInfoListForRegister() { } @Override - public InfoForCreateFarmClub getVeggieInfoForCreateFarmClub(String veggieInfoId) { + public CreateFarmClubVo getVeggieInfoForCreateFarmClub(String veggieInfoId) { Query query = new Query(); query.addCriteria(Criteria.where("_id").is(veggieInfoId)) @@ -44,7 +44,7 @@ public InfoForCreateFarmClub getVeggieInfoForCreateFarmClub(String veggieInfoId) .include("veggieImage") .include("difficulty"); - return mongoTemplate.findOne(query, InfoForCreateFarmClub.class, "veggie_info"); + return mongoTemplate.findOne(query, CreateFarmClubVo.class, "veggie_info"); } @Override diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/service/VeggieInfoService.java b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/service/VeggieInfoService.java index ca08eb00..ff5d2e08 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/service/VeggieInfoService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/service/VeggieInfoService.java @@ -1,6 +1,5 @@ package com.modernfarmer.farmusspring.domain.veggieinfo.service; -import com.modernfarmer.farmusspring.domain.veggieinfo.dto.res.InfoForCreateFarmClub; import com.modernfarmer.farmusspring.domain.veggieinfo.dto.res.InfoForRegister; import com.modernfarmer.farmusspring.domain.veggieinfo.entity.VeggieInfo; import com.modernfarmer.farmusspring.domain.veggieinfo.repository.VeggieInfoRepository; @@ -21,11 +20,6 @@ public List getVeggieInfoListForRegister() { return veggieInfoRepository.getVeggieInfoListForRegister(); } - public InfoForCreateFarmClub getVeggieInfoForCreateFarmClub(String veggieInfoId) { - // Get veggie info for create farm club - return veggieInfoRepository.getVeggieInfoForCreateFarmClub(veggieInfoId); - } - public String getFirstStepName(String veggieInfoId) { VeggieInfo veggieInfo = veggieInfoRepository.findById(new ObjectId(veggieInfoId)).orElseThrow(() -> new IllegalArgumentException("존재하지 않는 채소 정보입니다.")); From d5f5b2ad3009e6057452c7f4c0d9862433929835 Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Mon, 15 Apr 2024 20:01:43 +0900 Subject: [PATCH 29/40] =?UTF-8?q?[feat]=20=EB=AF=B8=EC=85=98=20=EC=9D=B8?= =?UTF-8?q?=EC=A6=9D=20API=20DTO=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/req/CreateMissionPostRequestDto.java | 16 ++++++++++++++++ .../dto/res/CreateMissionPostResponseDto.java | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/req/CreateMissionPostRequestDto.java create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/CreateMissionPostResponseDto.java diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/req/CreateMissionPostRequestDto.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/req/CreateMissionPostRequestDto.java new file mode 100644 index 00000000..3447f961 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/req/CreateMissionPostRequestDto.java @@ -0,0 +1,16 @@ +package com.modernfarmer.farmusspring.domain.farmclub.dto.req; + +import com.modernfarmer.farmusspring.domain.farmclub.entity.MissionPost; +import com.modernfarmer.farmusspring.domain.farmclub.entity.UserFarmClub; + +public record CreateMissionPostRequestDto( + // 사진, 내용, 스텝번호 + Long userFarmClubId, + String content, + Long stepNum +) { + + public MissionPost toEntity(UserFarmClub userFarmClub, String imageUrl) { + return MissionPost.createMissionPost(this.content, this.stepNum, imageUrl, userFarmClub); + } +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/CreateMissionPostResponseDto.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/CreateMissionPostResponseDto.java new file mode 100644 index 00000000..9636f3fd --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/CreateMissionPostResponseDto.java @@ -0,0 +1,16 @@ +package com.modernfarmer.farmusspring.domain.farmclub.dto.res; + +import lombok.Builder; + +@Builder +public record CreateMissionPostResponseDto( + + Long missionPostId +) { + + public static CreateMissionPostResponseDto of(Long missionPostId) { + return CreateMissionPostResponseDto.builder() + .missionPostId(missionPostId) + .build(); + } +} From 433699229ecf023ed503ffe6cacc492c2bbb2792 Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Mon, 15 Apr 2024 20:02:03 +0900 Subject: [PATCH 30/40] =?UTF-8?q?[feat]=20=ED=8C=9C=ED=81=B4=EB=9F=BD=20?= =?UTF-8?q?=EB=8F=84=EB=A9=94=EC=9D=B8=20=EC=98=88=EC=99=B8=20=EC=83=81?= =?UTF-8?q?=EC=9C=84=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/custom/FarmClubBaseException.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/custom/FarmClubBaseException.java diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/custom/FarmClubBaseException.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/custom/FarmClubBaseException.java new file mode 100644 index 00000000..8cbb7c0a --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/custom/FarmClubBaseException.java @@ -0,0 +1,15 @@ +package com.modernfarmer.farmusspring.domain.farmclub.exception.custom; + +import com.modernfarmer.farmusspring.domain.farmclub.exception.FarmClubErrorCode; +import lombok.Getter; + +@Getter +public class FarmClubBaseException extends RuntimeException { + + private final FarmClubErrorCode errorCode; + + public FarmClubBaseException(String message, FarmClubErrorCode errorCode) { + super(message); + this.errorCode = errorCode; + } +} From e7ee6f0949f22935c2e04b96b49e6f7ff0174bf3 Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Mon, 15 Apr 2024 20:02:45 +0900 Subject: [PATCH 31/40] =?UTF-8?q?[feat]=20=EC=97=94=ED=8B=B0=ED=8B=B0=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EB=B6=88=EA=B0=80=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/custom/EntityNotFoundException.java | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/custom/EntityNotFoundException.java diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/custom/EntityNotFoundException.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/custom/EntityNotFoundException.java new file mode 100644 index 00000000..9f21bdb8 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/custom/EntityNotFoundException.java @@ -0,0 +1,10 @@ +package com.modernfarmer.farmusspring.domain.farmclub.exception.custom; + +import com.modernfarmer.farmusspring.domain.farmclub.exception.FarmClubErrorCode; + +public class EntityNotFoundException extends FarmClubBaseException { + + public EntityNotFoundException(String message, FarmClubErrorCode errorCode) { + super(message, errorCode); + } +} From ab0f72ffb260e2df443af3e1ffaa8dad5e041828 Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Mon, 15 Apr 2024 20:04:41 +0900 Subject: [PATCH 32/40] =?UTF-8?q?[feat]=20UserFarmClub=20=EA=B8=B0?= =?UTF-8?q?=EB=B3=B8=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=83=9D=EC=84=B1=20?= =?UTF-8?q?=EB=B0=8F=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farmclub/helper/UserFarmClubHelper.java | 22 +++++++++++++++++++ .../repository/UserFarmClubRepository.java | 7 ++++++ 2 files changed, 29 insertions(+) create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/farmclub/helper/UserFarmClubHelper.java create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/UserFarmClubRepository.java diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/helper/UserFarmClubHelper.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/helper/UserFarmClubHelper.java new file mode 100644 index 00000000..b195297f --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/helper/UserFarmClubHelper.java @@ -0,0 +1,22 @@ +package com.modernfarmer.farmusspring.domain.farmclub.helper; + +import com.modernfarmer.farmusspring.domain.farmclub.entity.UserFarmClub; +import com.modernfarmer.farmusspring.domain.farmclub.exception.FarmClubErrorCode; +import com.modernfarmer.farmusspring.domain.farmclub.exception.custom.EntityNotFoundException; +import com.modernfarmer.farmusspring.domain.farmclub.repository.UserFarmClubRepository; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +@Slf4j +@Component +@RequiredArgsConstructor +public class UserFarmClubHelper { + + private final UserFarmClubRepository userFarmClubRepository; + + public UserFarmClub getUserFarmClubEntity(Long id) { + return userFarmClubRepository.findById(id) + .orElseThrow(() -> new EntityNotFoundException("존재하지 않는 등록 정보입니다.", FarmClubErrorCode.USER_FARM_CLUB_NOT_FOUND)); + } +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/UserFarmClubRepository.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/UserFarmClubRepository.java new file mode 100644 index 00000000..2ece949d --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/UserFarmClubRepository.java @@ -0,0 +1,7 @@ +package com.modernfarmer.farmusspring.domain.farmclub.repository; + +import com.modernfarmer.farmusspring.domain.farmclub.entity.UserFarmClub; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface UserFarmClubRepository extends JpaRepository { +} From 47b6753b76bdc83212b3777172b8014a492a597b Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Mon, 15 Apr 2024 20:05:09 +0900 Subject: [PATCH 33/40] =?UTF-8?q?[feat]=20MissionPost=20Helper=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/farmclub/helper/MissionPostHelper.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/farmclub/helper/MissionPostHelper.java diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/helper/MissionPostHelper.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/helper/MissionPostHelper.java new file mode 100644 index 00000000..4e570e75 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/helper/MissionPostHelper.java @@ -0,0 +1,9 @@ +package com.modernfarmer.farmusspring.domain.farmclub.helper; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class MissionPostHelper { +} From 6d733545a41c14bc8748327b0fb6e09f1eb9fa68 Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Mon, 15 Apr 2024 20:05:19 +0900 Subject: [PATCH 34/40] =?UTF-8?q?[feat]=20=EB=AF=B8=EC=85=98=20=EA=B2=8C?= =?UTF-8?q?=EC=8B=9C=EA=B8=80=20=EC=83=9D=EC=84=B1=20=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farmclub/service/MissionPostService.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/MissionPostService.java diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/MissionPostService.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/MissionPostService.java new file mode 100644 index 00000000..029070fc --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/MissionPostService.java @@ -0,0 +1,36 @@ +package com.modernfarmer.farmusspring.domain.farmclub.service; + +import com.modernfarmer.farmusspring.domain.farmclub.dto.req.CreateMissionPostRequestDto; +import com.modernfarmer.farmusspring.domain.farmclub.dto.res.CreateMissionPostResponseDto; +import com.modernfarmer.farmusspring.domain.farmclub.entity.MissionPost; +import com.modernfarmer.farmusspring.domain.farmclub.entity.UserFarmClub; +import com.modernfarmer.farmusspring.domain.farmclub.helper.UserFarmClubHelper; +import com.modernfarmer.farmusspring.domain.farmclub.repository.MissionPostRepository; +import com.modernfarmer.farmusspring.infra.s3.S3Service; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +@Service +@Slf4j +@RequiredArgsConstructor +public class MissionPostService { + + private final MissionPostRepository missionPostRepository; + + private final UserFarmClubHelper userFarmClubHelper; + + private final S3Service s3Service; + + public CreateMissionPostResponseDto createMissionPost(CreateMissionPostRequestDto request, MultipartFile image) { + UserFarmClub userFarmClub = userFarmClubHelper.getUserFarmClubEntity(request.userFarmClubId()); + String imageUrl = s3Service.uploadImage(image, "mission-post"); + Long missionPostId = saveMissionPost(request.toEntity(userFarmClub, imageUrl)).getId(); + return CreateMissionPostResponseDto.of(missionPostId); + } + + private MissionPost saveMissionPost(MissionPost missionPost) { + return missionPostRepository.save(missionPost); + } +} From 32cabd1b00573fdaee142736a2a37f46645bf744 Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Mon, 15 Apr 2024 20:05:47 +0900 Subject: [PATCH 35/40] =?UTF-8?q?[fix]=20=ED=8C=9C=ED=81=B4=EB=9F=BD=20?= =?UTF-8?q?=EA=B2=80=EC=83=89=20=EA=B8=B0=EB=8A=A5=20Helper=20=EC=97=90?= =?UTF-8?q?=EC=84=9C=20Service=20=EB=A1=9C=20=EC=9D=B4=EA=B4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farmusspring/domain/farmclub/helper/FarmClubHelper.java | 4 ---- .../farmusspring/domain/farmclub/service/FarmClubService.java | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/helper/FarmClubHelper.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/helper/FarmClubHelper.java index c2a55e41..2d2bc7dd 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/helper/FarmClubHelper.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/helper/FarmClubHelper.java @@ -19,8 +19,4 @@ public class FarmClubHelper { public FarmClub getFarmClubEntity(Long id) { return farmClubRepository.findById(id).orElseThrow(() -> new IllegalArgumentException("존재하지 않는 팜클럽입니다.")); } - - public List searchFarmClub(List difficulties, String keyword) { - return farmClubRepository.findByConditions(difficulties, keyword); - } } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java index 6e0ce15c..9bcd780f 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java @@ -50,6 +50,10 @@ public GetFarmClubResponseDto getFarmClub(Long id) { return GetFarmClubResponseDto.of(farmClub, farmClub.getUserFarmClubs().size(), help); } + public List searchFarmClub(List difficulties, String keyword) { + return farmClubRepository.findByConditions(difficulties, keyword); + } + @Transactional public RegisterFarmClubResponseDto registerFarmClub(RegisterFarmClubRequestDto request, Long userId) { // 채소 id로 채소 불러옴 From d369fcbbc25e8a62846028d3a39bec48d11b4a40 Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Mon, 15 Apr 2024 20:05:59 +0900 Subject: [PATCH 36/40] =?UTF-8?q?[fix]=20=EA=B8=B0=EC=A1=B4=20=EC=98=88?= =?UTF-8?q?=EC=99=B8=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/custom/FarmClubNotFoundException.java | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/custom/FarmClubNotFoundException.java diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/custom/FarmClubNotFoundException.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/custom/FarmClubNotFoundException.java deleted file mode 100644 index 4082b554..00000000 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/custom/FarmClubNotFoundException.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.modernfarmer.farmusspring.domain.farmclub.exception.custom; - -public class FarmClubNotFoundException extends RuntimeException { - - public FarmClubNotFoundException(String message) { - super(message); - } -} From 8240fd907a3e6d5b26ce2107fc9ee20fdabd28f9 Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Mon, 15 Apr 2024 20:06:22 +0900 Subject: [PATCH 37/40] =?UTF-8?q?[feat]=20=EB=93=B1=EB=A1=9D=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EC=A1=B0=ED=9A=8C=20=EC=97=90=EB=9F=AC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/farmclub/exception/FarmClubErrorCode.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/FarmClubErrorCode.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/FarmClubErrorCode.java index 1f8efa0c..c0189345 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/FarmClubErrorCode.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/FarmClubErrorCode.java @@ -8,7 +8,8 @@ @RequiredArgsConstructor public enum FarmClubErrorCode implements ResponseCode { - FARM_CLUB_NOT_FOUND(3001, "해당 팜클럽을 찾을 수 없습니다."); + FARM_CLUB_NOT_FOUND(3001, "해당 팜클럽을 찾을 수 없습니다."), + USER_FARM_CLUB_NOT_FOUND(3002, "해당 등록 정보를 찾을 수 없습니다."); private final int code; private final String message; From b08130603e13bd82351985c52dfd861a7ce25fc7 Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Mon, 15 Apr 2024 20:06:37 +0900 Subject: [PATCH 38/40] =?UTF-8?q?[feat]=20=EB=AF=B8=EC=85=98=20=EC=9D=B8?= =?UTF-8?q?=EC=A6=9D=20API=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farmclub/controller/FarmClubController.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java index 8e2184c7..d584a4c7 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java @@ -2,13 +2,16 @@ import com.modernfarmer.farmusspring.domain.auth.entity.CustomUser; import com.modernfarmer.farmusspring.domain.farmclub.dto.req.CreateFarmClubRequestDto; +import com.modernfarmer.farmusspring.domain.farmclub.dto.req.CreateMissionPostRequestDto; import com.modernfarmer.farmusspring.domain.farmclub.helper.FarmClubHelper; import com.modernfarmer.farmusspring.domain.farmclub.service.FarmClubService; +import com.modernfarmer.farmusspring.domain.farmclub.service.MissionPostService; import com.modernfarmer.farmusspring.global.response.BaseResponseDto; import com.modernfarmer.farmusspring.global.response.SuccessCode; import lombok.RequiredArgsConstructor; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import java.util.List; @@ -18,7 +21,7 @@ public class FarmClubController { private final FarmClubService farmClubService; - private final FarmClubHelper farmClubHelper; + private final MissionPostService missionPostService; // 요청 : 이름, 설명, 최대인원, 모집기한, 내 채소 id, 채소정보 id // 응답 : 팜클럽 id @@ -41,7 +44,7 @@ public BaseResponseDto searchFarmClub( @RequestParam List difficulties, @RequestParam String keyword ) { - return BaseResponseDto.of(SuccessCode.SUCCESS, farmClubHelper.searchFarmClub(difficulties, keyword)); + return BaseResponseDto.of(SuccessCode.SUCCESS, farmClubService.searchFarmClub(difficulties, keyword)); } @GetMapping("/{id}") @@ -65,4 +68,12 @@ public BaseResponseDto getMyFarmClub( ) { return BaseResponseDto.of(SuccessCode.SUCCESS, farmClubService.getMyFarmClub(farmClubId, user.getUserId())); } + + @PostMapping("/mission") + public BaseResponseDto createMissionPost( + @RequestPart CreateMissionPostRequestDto requestDto, + @RequestPart(value = "image") MultipartFile image + ) { + return BaseResponseDto.of(SuccessCode.CREATED, missionPostService.createMissionPost(requestDto, image)); + } } From aa1678e7ca281a14e9eda774c80853e4485471c0 Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Mon, 15 Apr 2024 20:06:47 +0900 Subject: [PATCH 39/40] =?UTF-8?q?[feat]=20=EB=B3=80=EA=B2=BD=EB=90=9C=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=20=EC=B2=98=EB=A6=AC=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farmclub/exception/FarmClubExceptionHandler.java | 9 +++++---- .../farmclub/repository/FarmClubRepositoryImpl.java | 5 +++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/FarmClubExceptionHandler.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/FarmClubExceptionHandler.java index e3849bea..21e4376a 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/FarmClubExceptionHandler.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/FarmClubExceptionHandler.java @@ -1,6 +1,7 @@ package com.modernfarmer.farmusspring.domain.farmclub.exception; -import com.modernfarmer.farmusspring.domain.farmclub.exception.custom.FarmClubNotFoundException; +import com.modernfarmer.farmusspring.domain.farmclub.exception.custom.FarmClubBaseException; +import com.modernfarmer.farmusspring.domain.farmclub.exception.custom.EntityNotFoundException; import com.modernfarmer.farmusspring.global.response.BaseResponseDto; import jakarta.servlet.http.HttpServletRequest; import lombok.extern.slf4j.Slf4j; @@ -11,12 +12,12 @@ @RestControllerAdvice(basePackages = "com.modernfarmer.farmusspring.domain.farmclub") public class FarmClubExceptionHandler { - @ExceptionHandler(FarmClubNotFoundException.class) - public BaseResponseDto handleFarmClubNotFoundException(FarmClubNotFoundException e, HttpServletRequest request) { + @ExceptionHandler(FarmClubBaseException.class) + public BaseResponseDto handleFarmClubNotFoundException(EntityNotFoundException e, HttpServletRequest request) { log.error("FarmClubNotFoundException : {} {} errMessage={}\n", request.getMethod(), request.getRequestURI(), e.getMessage()); - return BaseResponseDto.of(FarmClubErrorCode.FARM_CLUB_NOT_FOUND, e.getMessage()); + return BaseResponseDto.of(e.getErrorCode(), e.getMessage()); } } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryImpl.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryImpl.java index 1e8d1ae0..35c7e86d 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryImpl.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryImpl.java @@ -2,7 +2,8 @@ import com.modernfarmer.farmusspring.domain.farmclub.dto.res.*; import com.modernfarmer.farmusspring.domain.farmclub.entity.QFarmClub; -import com.modernfarmer.farmusspring.domain.farmclub.exception.custom.FarmClubNotFoundException; +import com.modernfarmer.farmusspring.domain.farmclub.exception.FarmClubErrorCode; +import com.modernfarmer.farmusspring.domain.farmclub.exception.custom.EntityNotFoundException; import com.modernfarmer.farmusspring.domain.farmclub.vo.GetMyFarmClubVo; import com.modernfarmer.farmusspring.domain.farmclub.vo.QGetMyFarmClubVo_BaseInfo; import com.querydsl.jpa.impl.JPAQueryFactory; @@ -74,7 +75,7 @@ public GetMyFarmClubVo findMyFarmClub(Long farmClubId, Long userId) { return GetMyFarmClubVo.of(baseInfo, userFarmClubCount, daySinceStart); } else { - throw new FarmClubNotFoundException("내 팜클럽을 불러오는 도중 에러가 발생했습니다."); + throw new EntityNotFoundException("내 팜클럽을 불러오는 도중 에러가 발생했습니다.", FarmClubErrorCode.FARM_CLUB_NOT_FOUND); } } From 47e442eb5fe5de0cf0c0151cc953d86599b49255 Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Mon, 29 Apr 2024 02:11:45 +0900 Subject: [PATCH 40/40] =?UTF-8?q?[fix]=20DTO,VO=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=EB=84=A4=EC=9D=B4=EB=B0=8D,=20=ED=8C=A8=ED=82=A4=EC=A7=95=20?= =?UTF-8?q?=ED=86=B5=EC=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/res/CreateFarmClubResponseDto.java | 7 +++++- .../dto/res/GetFarmClubResponseDto.java | 24 ++++++++++--------- .../dto/res/GetMyFarmClubListResponseDto.java | 9 ++++++- .../dto/res/GetMyFarmClubResponseDto.java | 21 +++++++++------- .../dto/res/RegisterFarmClubResponseDto.java | 7 +++++- .../MissionPostRepositoryCustom.java | 4 ++-- .../repository/MissionPostRepositoryImpl.java | 8 +++---- .../farmclub/service/FarmClubService.java | 6 ++--- ...ionPostListWithStepCountsAndImagesVo.java} | 5 ++-- .../dto/res/GetVeggieInfoListResponseDto.java | 14 ----------- .../veggieinfo/dto/res/InfoForRegister.java | 17 ------------- .../veggieinfo/helper/VeggieInfoHelper.java | 2 +- .../CustomVeggieInfoRepository.java | 6 ++--- .../repository/VeggieInfoRepositoryImpl.java | 8 +++---- .../veggieinfo/service/VeggieInfoService.java | 4 ++-- .../{dto/res => vo}/CreateFarmClubVo.java | 2 +- .../veggieinfo/vo/InfoForRegisterVo.java | 13 ++++++++++ 17 files changed, 80 insertions(+), 77 deletions(-) rename src/main/java/com/modernfarmer/farmusspring/domain/farmclub/vo/{GetMissionPostListWithStepCountsAndImages.java => GetMissionPostListWithStepCountsAndImagesVo.java} (54%) delete mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/dto/res/GetVeggieInfoListResponseDto.java delete mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/dto/res/InfoForRegister.java rename src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/{dto/res => vo}/CreateFarmClubVo.java (64%) create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/vo/InfoForRegisterVo.java diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/CreateFarmClubResponseDto.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/CreateFarmClubResponseDto.java index 403ab968..ce9353a3 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/CreateFarmClubResponseDto.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/CreateFarmClubResponseDto.java @@ -1,9 +1,14 @@ package com.modernfarmer.farmusspring.domain.farmclub.dto.res; +import lombok.Builder; + +@Builder public record CreateFarmClubResponseDto ( Long farmClubId ){ public static CreateFarmClubResponseDto of(Long farmClubId) { - return new CreateFarmClubResponseDto(farmClubId); + return CreateFarmClubResponseDto.builder() + .farmClubId(farmClubId) + .build(); } } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetFarmClubResponseDto.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetFarmClubResponseDto.java index 08ff4d07..b010e7b8 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetFarmClubResponseDto.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetFarmClubResponseDto.java @@ -1,9 +1,11 @@ package com.modernfarmer.farmusspring.domain.farmclub.dto.res; import com.modernfarmer.farmusspring.domain.farmclub.entity.FarmClub; +import lombok.Builder; import java.util.List; +@Builder public record GetFarmClubResponseDto ( Long farmClubId, String farmClubName, @@ -16,16 +18,16 @@ public record GetFarmClubResponseDto ( List help ){ public static GetFarmClubResponseDto of(FarmClub farmClub, int currentMemberCount, List help) { - return new GetFarmClubResponseDto( - farmClub.getId(), - farmClub.getName(), - farmClub.getDescription(), - farmClub.getVeggieName(), - farmClub.getVeggieImage(), - farmClub.getStartedAt().toString(), - farmClub.getMaxUser(), - currentMemberCount, - help - ); + return GetFarmClubResponseDto.builder() + .farmClubId(farmClub.getId()) + .farmClubName(farmClub.getName()) + .farmClubDescription(farmClub.getDescription()) + .veggieName(farmClub.getVeggieName()) + .veggieImage(farmClub.getVeggieImage()) + .startedAt(String.valueOf(farmClub.getStartedAt())) + .maxMemberCount(farmClub.getMaxUser()) + .currentMemberCount(currentMemberCount) + .help(help) + .build(); } } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetMyFarmClubListResponseDto.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetMyFarmClubListResponseDto.java index 779717ca..3119697d 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetMyFarmClubListResponseDto.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetMyFarmClubListResponseDto.java @@ -2,7 +2,9 @@ import com.modernfarmer.farmusspring.domain.farmclub.entity.FarmClub; import com.querydsl.core.annotations.QueryProjection; +import lombok.Builder; +@Builder public record GetMyFarmClubListResponseDto( Long farmClubId, String farmClubImage, @@ -10,7 +12,12 @@ public record GetMyFarmClubListResponseDto( String veggieName ) { public static GetMyFarmClubListResponseDto of(Long farmClubId, String farmClubImage, String farmClubName, String veggieName) { - return new GetMyFarmClubListResponseDto(farmClubId, farmClubImage, farmClubName, veggieName); + return GetMyFarmClubListResponseDto.builder() + .farmClubId(farmClubId) + .farmClubImage(farmClubImage) + .farmClubName(farmClubName) + .veggieName(veggieName) + .build(); } @QueryProjection diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetMyFarmClubResponseDto.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetMyFarmClubResponseDto.java index 686492e9..08cc627c 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetMyFarmClubResponseDto.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetMyFarmClubResponseDto.java @@ -1,12 +1,14 @@ package com.modernfarmer.farmusspring.domain.farmclub.dto.res; -import com.modernfarmer.farmusspring.domain.farmclub.vo.GetMissionPostListWithStepCountsAndImages; +import com.modernfarmer.farmusspring.domain.farmclub.vo.GetMissionPostListWithStepCountsAndImagesVo; import com.modernfarmer.farmusspring.domain.farmclub.vo.GetMyFarmClubVo; import com.modernfarmer.farmusspring.domain.veggieinfo.vo.StepVo; +import lombok.Builder; import java.util.ArrayList; import java.util.List; +@Builder public record GetMyFarmClubResponseDto( String farmClubName, String farmClubImage, @@ -17,16 +19,17 @@ public record GetMyFarmClubResponseDto( ) { public static GetMyFarmClubResponseDto of(GetMyFarmClubVo farmClubInfo, List steps, String advice) { - return new GetMyFarmClubResponseDto( - farmClubInfo.farmClubName(), - farmClubInfo.farmClubImage(), - farmClubInfo.wholeMemberCount(), - steps, - advice, - farmClubInfo.daySinceStart()); + return GetMyFarmClubResponseDto.builder() + .farmClubName(farmClubInfo.farmClubName()) + .farmClubImage(farmClubInfo.farmClubImage()) + .wholeMemberCount(farmClubInfo.wholeMemberCount()) + .steps(steps) + .advice(advice) + .daysSinceStart(farmClubInfo.daySinceStart()) + .build(); } - public static List createSteps(List stepVoList, List missionList) { + public static List createSteps(List stepVoList, List missionList) { List steps = new ArrayList<>(); for (int i = 0; i < stepVoList.size(); i++) { Step step = new Step( diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/RegisterFarmClubResponseDto.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/RegisterFarmClubResponseDto.java index c908cca5..fc9f3aa4 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/RegisterFarmClubResponseDto.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/RegisterFarmClubResponseDto.java @@ -1,9 +1,14 @@ package com.modernfarmer.farmusspring.domain.farmclub.dto.res; +import lombok.Builder; + +@Builder public record RegisterFarmClubResponseDto ( Long userFarmClubId ){ public static RegisterFarmClubResponseDto of(Long userFarmClubId) { - return new RegisterFarmClubResponseDto(userFarmClubId); + return RegisterFarmClubResponseDto.builder() + .userFarmClubId(userFarmClubId) + .build(); } } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepositoryCustom.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepositoryCustom.java index 2552ab20..864ecdf8 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepositoryCustom.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepositoryCustom.java @@ -1,11 +1,11 @@ package com.modernfarmer.farmusspring.domain.farmclub.repository; -import com.modernfarmer.farmusspring.domain.farmclub.vo.GetMissionPostListWithStepCountsAndImages; +import com.modernfarmer.farmusspring.domain.farmclub.vo.GetMissionPostListWithStepCountsAndImagesVo; import java.util.List; public interface MissionPostRepositoryCustom { - List getMissionPostStepNumAndImage(Long farmClubId); + List getMissionPostStepNumAndImage(Long farmClubId); } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepositoryImpl.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepositoryImpl.java index 3ed76767..b126d63a 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepositoryImpl.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepositoryImpl.java @@ -1,8 +1,8 @@ package com.modernfarmer.farmusspring.domain.farmclub.repository; -import com.modernfarmer.farmusspring.domain.farmclub.vo.GetMissionPostListWithStepCountsAndImages; -import com.modernfarmer.farmusspring.domain.farmclub.vo.QGetMissionPostListWithStepCountsAndImages; +import com.modernfarmer.farmusspring.domain.farmclub.vo.GetMissionPostListWithStepCountsAndImagesVo; +import com.modernfarmer.farmusspring.domain.farmclub.vo.QGetMissionPostListWithStepCountsAndImagesVo; import com.querydsl.core.group.GroupBy; import com.querydsl.jpa.impl.JPAQueryFactory; import jakarta.persistence.EntityManager; @@ -20,7 +20,7 @@ public class MissionPostRepositoryImpl implements MissionPostRepositoryCustom { private EntityManager em; @Override - public List getMissionPostStepNumAndImage(Long farmClubId) { + public List getMissionPostStepNumAndImage(Long farmClubId) { JPAQueryFactory queryFactory = new JPAQueryFactory(em); return queryFactory @@ -30,7 +30,7 @@ public List getMissionPostStepNumAndI .where(farmClub.id.eq(farmClubId)) .transform( GroupBy.groupBy(missionPost.stepNum) - .list(new QGetMissionPostListWithStepCountsAndImages( + .list(new QGetMissionPostListWithStepCountsAndImagesVo( missionPost.stepNum.count(), GroupBy.list(missionPost.image) )) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java index 9bcd780f..51ec94e1 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/FarmClubService.java @@ -8,10 +8,10 @@ import com.modernfarmer.farmusspring.domain.farmclub.helper.FarmClubHelper; import com.modernfarmer.farmusspring.domain.farmclub.repository.FarmClubRepository; import com.modernfarmer.farmusspring.domain.farmclub.repository.MissionPostRepository; -import com.modernfarmer.farmusspring.domain.farmclub.vo.GetMissionPostListWithStepCountsAndImages; +import com.modernfarmer.farmusspring.domain.farmclub.vo.GetMissionPostListWithStepCountsAndImagesVo; import com.modernfarmer.farmusspring.domain.farmclub.vo.GetMyFarmClubVo; import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.MyVeggie; -import com.modernfarmer.farmusspring.domain.veggieinfo.dto.res.CreateFarmClubVo; +import com.modernfarmer.farmusspring.domain.veggieinfo.vo.CreateFarmClubVo; import com.modernfarmer.farmusspring.domain.veggieinfo.helper.VeggieInfoHelper; import com.modernfarmer.farmusspring.domain.veggieinfo.vo.StepVo; import lombok.RequiredArgsConstructor; @@ -75,7 +75,7 @@ public GetMyFarmClubResponseDto getMyFarmClub(Long userId, Long farmClubId) { String veggieInfoId = farmClubInfo.veggieInfoId(); List stepList = veggieInfoHelper.getStepList(veggieInfoId); String randomTip = getRandomTip(stepList); - List missionList = + List missionList = missionPostRepository.getMissionPostStepNumAndImage(farmClubId); return GetMyFarmClubResponseDto.of(farmClubInfo, GetMyFarmClubResponseDto.createSteps(stepList, missionList), randomTip); diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/vo/GetMissionPostListWithStepCountsAndImages.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/vo/GetMissionPostListWithStepCountsAndImagesVo.java similarity index 54% rename from src/main/java/com/modernfarmer/farmusspring/domain/farmclub/vo/GetMissionPostListWithStepCountsAndImages.java rename to src/main/java/com/modernfarmer/farmusspring/domain/farmclub/vo/GetMissionPostListWithStepCountsAndImagesVo.java index ae1d2869..ecac9988 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/vo/GetMissionPostListWithStepCountsAndImages.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/vo/GetMissionPostListWithStepCountsAndImagesVo.java @@ -1,15 +1,14 @@ package com.modernfarmer.farmusspring.domain.farmclub.vo; -import com.modernfarmer.farmusspring.domain.farmclub.entity.MissionPost; import com.querydsl.core.annotations.QueryProjection; import java.util.List; -public record GetMissionPostListWithStepCountsAndImages( +public record GetMissionPostListWithStepCountsAndImagesVo( Long count, List images ) { @QueryProjection - public GetMissionPostListWithStepCountsAndImages { + public GetMissionPostListWithStepCountsAndImagesVo { } } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/dto/res/GetVeggieInfoListResponseDto.java b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/dto/res/GetVeggieInfoListResponseDto.java deleted file mode 100644 index 269a4c60..00000000 --- a/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/dto/res/GetVeggieInfoListResponseDto.java +++ /dev/null @@ -1,14 +0,0 @@ -//package com.modernfarmer.farmusspring.domain.veggie.dto.res; -// -// -//import lombok.AllArgsConstructor; -//import lombok.Getter; -//import lombok.NoArgsConstructor; -// -//@AllArgsConstructor(staticName = "of") -//@NoArgsConstructor -//@Getter -//public class GetVeggieInfoListResponseDto { -// -// -//} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/dto/res/InfoForRegister.java b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/dto/res/InfoForRegister.java deleted file mode 100644 index 9d95ff4a..00000000 --- a/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/dto/res/InfoForRegister.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.modernfarmer.farmusspring.domain.veggieinfo.dto.res; - -import com.modernfarmer.farmusspring.domain.veggieinfo.enums.Difficulty; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import org.bson.types.ObjectId; - - -public record InfoForRegister ( - String _id, - String name, - Difficulty difficulty, - String veggieImage, - String period -){ -} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/helper/VeggieInfoHelper.java b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/helper/VeggieInfoHelper.java index 7b3a3385..7bc117fb 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/helper/VeggieInfoHelper.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/helper/VeggieInfoHelper.java @@ -1,6 +1,6 @@ package com.modernfarmer.farmusspring.domain.veggieinfo.helper; -import com.modernfarmer.farmusspring.domain.veggieinfo.dto.res.CreateFarmClubVo; +import com.modernfarmer.farmusspring.domain.veggieinfo.vo.CreateFarmClubVo; import com.modernfarmer.farmusspring.domain.veggieinfo.entity.VeggieInfo; import com.modernfarmer.farmusspring.domain.veggieinfo.exception.custom.VeggieInfoNotFoundException; import com.modernfarmer.farmusspring.domain.veggieinfo.repository.VeggieInfoRepository; diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/repository/CustomVeggieInfoRepository.java b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/repository/CustomVeggieInfoRepository.java index 20e25c7e..8773f7bd 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/repository/CustomVeggieInfoRepository.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/repository/CustomVeggieInfoRepository.java @@ -1,14 +1,14 @@ package com.modernfarmer.farmusspring.domain.veggieinfo.repository; -import com.modernfarmer.farmusspring.domain.veggieinfo.dto.res.CreateFarmClubVo; -import com.modernfarmer.farmusspring.domain.veggieinfo.dto.res.InfoForRegister; +import com.modernfarmer.farmusspring.domain.veggieinfo.vo.CreateFarmClubVo; +import com.modernfarmer.farmusspring.domain.veggieinfo.vo.InfoForRegisterVo; import com.modernfarmer.farmusspring.domain.veggieinfo.vo.StepVo; import java.util.List; public interface CustomVeggieInfoRepository { - List getVeggieInfoListForRegister(); + List getVeggieInfoListForRegister(); CreateFarmClubVo getVeggieInfoForCreateFarmClub(String veggieInfoId); List getVeggieInfoStepList(String veggieInfoId); } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/repository/VeggieInfoRepositoryImpl.java b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/repository/VeggieInfoRepositoryImpl.java index fa6271f6..14429465 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/repository/VeggieInfoRepositoryImpl.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/repository/VeggieInfoRepositoryImpl.java @@ -1,8 +1,8 @@ package com.modernfarmer.farmusspring.domain.veggieinfo.repository; -import com.modernfarmer.farmusspring.domain.veggieinfo.dto.res.CreateFarmClubVo; -import com.modernfarmer.farmusspring.domain.veggieinfo.dto.res.InfoForRegister; +import com.modernfarmer.farmusspring.domain.veggieinfo.vo.CreateFarmClubVo; +import com.modernfarmer.farmusspring.domain.veggieinfo.vo.InfoForRegisterVo; import com.modernfarmer.farmusspring.domain.veggieinfo.vo.StepVo; import lombok.RequiredArgsConstructor; import org.springframework.data.mongodb.core.MongoTemplate; @@ -19,7 +19,7 @@ public class VeggieInfoRepositoryImpl implements CustomVeggieInfoRepository{ private final MongoTemplate mongoTemplate; @Override - public List getVeggieInfoListForRegister() { + public List getVeggieInfoListForRegister() { // Query to get all name, difficulty, veggieImage, period from veggieInfo collection // and return as List Query query = new Query(); @@ -30,7 +30,7 @@ public List getVeggieInfoListForRegister() { .include("veggieImage") .include("period"); - return mongoTemplate.find(query, InfoForRegister.class, "veggie_info"); + return mongoTemplate.find(query, InfoForRegisterVo.class, "veggie_info"); } @Override diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/service/VeggieInfoService.java b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/service/VeggieInfoService.java index ff5d2e08..786a02cc 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/service/VeggieInfoService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/service/VeggieInfoService.java @@ -1,6 +1,6 @@ package com.modernfarmer.farmusspring.domain.veggieinfo.service; -import com.modernfarmer.farmusspring.domain.veggieinfo.dto.res.InfoForRegister; +import com.modernfarmer.farmusspring.domain.veggieinfo.vo.InfoForRegisterVo; import com.modernfarmer.farmusspring.domain.veggieinfo.entity.VeggieInfo; import com.modernfarmer.farmusspring.domain.veggieinfo.repository.VeggieInfoRepository; import lombok.RequiredArgsConstructor; @@ -15,7 +15,7 @@ public class VeggieInfoService { private final VeggieInfoRepository veggieInfoRepository; - public List getVeggieInfoListForRegister() { + public List getVeggieInfoListForRegister() { // Get all veggie info list for register return veggieInfoRepository.getVeggieInfoListForRegister(); } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/dto/res/CreateFarmClubVo.java b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/vo/CreateFarmClubVo.java similarity index 64% rename from src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/dto/res/CreateFarmClubVo.java rename to src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/vo/CreateFarmClubVo.java index fda4050a..8904ccc7 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/dto/res/CreateFarmClubVo.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/vo/CreateFarmClubVo.java @@ -1,4 +1,4 @@ -package com.modernfarmer.farmusspring.domain.veggieinfo.dto.res; +package com.modernfarmer.farmusspring.domain.veggieinfo.vo; public record CreateFarmClubVo( String _id, diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/vo/InfoForRegisterVo.java b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/vo/InfoForRegisterVo.java new file mode 100644 index 00000000..a133f879 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/veggieinfo/vo/InfoForRegisterVo.java @@ -0,0 +1,13 @@ +package com.modernfarmer.farmusspring.domain.veggieinfo.vo; + +import com.modernfarmer.farmusspring.domain.veggieinfo.enums.Difficulty; + + +public record InfoForRegisterVo( + String _id, + String name, + Difficulty difficulty, + String veggieImage, + String period +){ +}