-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from Mojacknong/feature_6/farmclub-기본-api
Feature 6/farmclub 기본 api
- Loading branch information
Showing
52 changed files
with
986 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...ain/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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)); | ||
} | ||
} |
4 changes: 0 additions & 4 deletions
4
src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/TestController.java
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/TestDto.java
This file was deleted.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
.../java/com/modernfarmer/farmusspring/domain/farmclub/dto/req/CreateFarmClubRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...va/com/modernfarmer/farmusspring/domain/farmclub/dto/req/CreateMissionPostRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...ava/com/modernfarmer/farmusspring/domain/farmclub/dto/req/RegisterFarmClubRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.modernfarmer.farmusspring.domain.farmclub.dto.req; | ||
|
||
public record RegisterFarmClubRequestDto ( | ||
|
||
Long farmClubId, | ||
Long myVeggieId | ||
|
||
){ | ||
} |
14 changes: 14 additions & 0 deletions
14
...java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/CreateFarmClubResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...a/com/modernfarmer/farmusspring/domain/farmclub/dto/res/CreateMissionPostResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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(); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...in/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetFarmClubResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package 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(); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...a/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetMyFarmClubListResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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()); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
.../java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetMyFarmClubResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
) { | ||
|
||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...va/com/modernfarmer/farmusspring/domain/farmclub/dto/res/RegisterFarmClubResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/SearchFarmClubResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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()); | ||
} | ||
} |
Oops, something went wrong.