Skip to content

Commit

Permalink
Merge pull request #12 from Mojacknong/feature_6/farmclub-기본-api
Browse files Browse the repository at this point in the history
Feature 6/farmclub 기본 api
  • Loading branch information
MinchoGreenT authored Apr 28, 2024
2 parents 8d73054 + 47e442e commit ac77599
Show file tree
Hide file tree
Showing 52 changed files with 986 additions and 88 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 24 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,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'
Expand All @@ -64,3 +70,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)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
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.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;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/farm-club")
public class FarmClubController {

private final FarmClubService farmClubService;
private final MissionPostService missionPostService;

// 요청 : 이름, 설명, 최대인원, 모집기한, 내 채소 id, 채소정보 id
// 응답 : 팜클럽 id
@PostMapping
public BaseResponseDto<?> createFarmClub(
@RequestBody CreateFarmClubRequestDto requestDto
) {
return BaseResponseDto.of(SuccessCode.CREATED, farmClubService.createFarmClub(requestDto));
}

@PostMapping("/register")
public BaseResponseDto<?> registerFarmClub(
@RequestBody CreateFarmClubRequestDto requestDto
) {
return BaseResponseDto.of(SuccessCode.CREATED, farmClubService.createFarmClub(requestDto));
}

@GetMapping("/search")
public BaseResponseDto<?> searchFarmClub(
@RequestParam List<String> difficulties,
@RequestParam String keyword
) {
return BaseResponseDto.of(SuccessCode.SUCCESS, farmClubService.searchFarmClub(difficulties, keyword));
}

@GetMapping("/{id}")
public BaseResponseDto<?> getFarmClub(
@PathVariable Long id
) {
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()));
}

@GetMapping("/me/{farmClubId}")
public BaseResponseDto<?> getMyFarmClub(
@PathVariable Long farmClubId,
@AuthenticationPrincipal CustomUser user
) {
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));
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +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;

public record CreateFarmClubRequestDto (

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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.modernfarmer.farmusspring.domain.farmclub.dto.req;

public record RegisterFarmClubRequestDto (

Long farmClubId,
Long myVeggieId

){
}
Original file line number Diff line number Diff line change
@@ -0,0 +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 CreateFarmClubResponseDto.builder()
.farmClubId(farmClubId)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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,
String farmClubDescription,
String veggieName,
String veggieImage,
String startedAt,
int maxMemberCount,
int currentMemberCount,
List<String> help
){
public static GetFarmClubResponseDto of(FarmClub farmClub, int currentMemberCount, List<String> 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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.modernfarmer.farmusspring.domain.farmclub.dto.res;

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,
String farmClubName,
String veggieName
) {
public static GetMyFarmClubListResponseDto of(Long farmClubId, String farmClubImage, String farmClubName, String veggieName) {
return GetMyFarmClubListResponseDto.builder()
.farmClubId(farmClubId)
.farmClubImage(farmClubImage)
.farmClubName(farmClubName)
.veggieName(veggieName)
.build();
}

@QueryProjection
public GetMyFarmClubListResponseDto(FarmClub farmClub) {
this(
farmClub.getId(),
farmClub.getVeggieImage(),
farmClub.getName(),
farmClub.getVeggieName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.modernfarmer.farmusspring.domain.farmclub.dto.res;

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,
Long wholeMemberCount,
List<Step> steps,
String advice,
int daysSinceStart
) {

public static GetMyFarmClubResponseDto of(GetMyFarmClubVo farmClubInfo, List<Step> steps, String advice) {
return GetMyFarmClubResponseDto.builder()
.farmClubName(farmClubInfo.farmClubName())
.farmClubImage(farmClubInfo.farmClubImage())
.wholeMemberCount(farmClubInfo.wholeMemberCount())
.steps(steps)
.advice(advice)
.daysSinceStart(farmClubInfo.daySinceStart())
.build();
}

public static List<Step> createSteps(List<StepVo> stepVoList, List<GetMissionPostListWithStepCountsAndImagesVo> missionList) {
List<Step> 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<String> images,
int stepNum,
String stepName,
Long completeMemberCount
) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +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 RegisterFarmClubResponseDto.builder()
.userFarmClubId(userFarmClubId)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +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 id,
String name,
String veggieName,
String veggieImage,
String difficulty,
String startedAt,
Integer maxUser
) {
@QueryProjection
public SearchFarmClubResponseDto(FarmClub farmClub) {
this(
farmClub.getId(),
farmClub.getName(),
farmClub.getVeggieName(),
farmClub.getVeggieImage(),
farmClub.getDifficulty(),
farmClub.getStartedAt().toString(),
farmClub.getMaxUser());
}
}
Loading

0 comments on commit ac77599

Please sign in to comment.