Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[Build] user, plant #136

Merged
merged 9 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class OAuthController implements OAuthSwagger{

@GetMapping("/login/{provider}")
public ResponseEntity<JsonResponse> login(@RequestParam("accessToken") String accessToken, @PathVariable String provider){
log.info("[API] Social Login");
log.info("accessToken : " + accessToken);
String token = oAuthService.oAuthLogin(accessToken, provider);
String email = oAuthService.kakaoLogin(accessToken);
Expand All @@ -34,6 +35,7 @@ public ResponseEntity<JsonResponse> login(@RequestParam("accessToken") String ac

@GetMapping("/api/token")
public ResponseEntity<JsonResponse> validToken(){
log.info("[API] Validate Token");
String token = jwtService.getJwt();
boolean isValid = jwtService.validateToken(token);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ public class PlantController implements PlantSwagger {

/**
* [POST] ์‹๋ฌผ ์ถ”๊ฐ€
* [POST] /plant/add
* @return ์ถ”๊ฐ€ํ•œ ์‹๋ฌผ์˜ ์• ์นญ
*/
@PostMapping(value = "/plant/add", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<JsonResponse> createPlant(@RequestPart("plant") PlantDto.createPlantReq createPlantReq,
@RequestPart("image") MultipartFile file) {
log.info("[API] createPlant - ์‹๋ฌผ ์ถ”๊ฐ€");

String uuid = jwtService.resolveToken();
User user = userService.getUser(uuid);

Expand All @@ -48,6 +49,8 @@ public ResponseEntity<JsonResponse> createPlant(@RequestPart("plant") PlantDto.c
*/
@GetMapping("/plant/{plantIdx}")
public ResponseEntity<JsonResponse> getPlantCard(@PathVariable Long plantIdx) {
log.info("[API]: getPlantCard - ์‹๋ฌผ ์กฐํšŒ");

String uuid = jwtService.resolveToken();
User user = userService.getUser(uuid);

Expand All @@ -63,6 +66,8 @@ public ResponseEntity<JsonResponse> getPlantCard(@PathVariable Long plantIdx) {
*/
@GetMapping("/user/plantList")
public ResponseEntity<JsonResponse> getPlantList() {
log.info("[API]: getPlantList - ๊ฐ™์€ ์‚ฌ๋žŒ์ด ํ‚ค์šฐ๋Š” ์‹๋ฌผ ๋ฆฌ์ŠคํŠธ ์กฐํšŒ");

String uuid = jwtService.resolveToken();
User user = userService.getUser(uuid);

Expand Down Expand Up @@ -96,6 +101,8 @@ public ResponseEntity<JsonResponse> getPlantList() {
*/
@PutMapping("/plant/update/wateredDate/{plantIdx}")
public ResponseEntity<JsonResponse> updateWateredDate(@PathVariable Long plantIdx){
log.info("[API]: updateWateredDate - ์‹๋ฌผ์˜ D-Day ์—…๋ฐ์ดํŠธ");

String uuid = jwtService.resolveToken();
User user = userService.getUser(uuid);

Expand All @@ -105,11 +112,13 @@ public ResponseEntity<JsonResponse> updateWateredDate(@PathVariable Long plantId
}

/**
* [GET] /plant/update
* [GET] ์‹๋ฌผ์„ ์ˆ˜์ •ํ•  ๋•Œ ๋œจ๋Š” ์กฐํšŒ ํ™”๋ฉด
* @return ์ˆ˜์ •ํ•˜๊ธฐ ์ „ ์‹๋ฌผ์˜ ์ •๋ณด
*/
@GetMapping("/plant/update/{plantIdx}")
public ResponseEntity<JsonResponse> getUpdatedPlant(@PathVariable Long plantIdx){
log.info("[API]: getUpdatedPlant - ์‹๋ฌผ์„ ์ˆ˜์ •ํ•  ๋•Œ ๋œจ๋Š” ์กฐํšŒ ํ™”๋ฉด");

String uuid = jwtService.resolveToken();
User user = userService.getUser(uuid);

Expand All @@ -119,13 +128,15 @@ public ResponseEntity<JsonResponse> getUpdatedPlant(@PathVariable Long plantIdx)
}

/**
* [PUT] /plant/update
* [PUT] ์‹๋ฌผ ์ˆ˜์ •
* @return ์ˆ˜์ •ํ•œ ์‹๋ฌผ์˜ ์ •๋ณด
*/
@PutMapping(value = "/plant/update/{plantIdx}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<JsonResponse> updatePlant(@PathVariable Long plantIdx,
@RequestPart("plant") PlantDto.updatePlantReq updatePlantReq,
@RequestPart("image") MultipartFile file){
log.info("[API] updatePlant - ์‹๋ฌผ ์ˆ˜์ •");

String uuid = jwtService.resolveToken();
User user = userService.getUser(uuid);

Expand All @@ -135,12 +146,14 @@ public ResponseEntity<JsonResponse> updatePlant(@PathVariable Long plantIdx,
}

/**
* [DELETE] /plant/delete
* [DELETE] ์‹๋ฌผ ์‚ญ์ œ
* @param plantIdx
* @return ์‚ญ์ œํ•œ ์‹๋ฌผ์˜ ๋‹‰๋„ค์ž„
*/
@DeleteMapping("/plant/delete/{plantIdx}")
public ResponseEntity<JsonResponse> deletePlant(@PathVariable Long plantIdx){
log.info("[API] deletePlant - ์‹๋ฌผ ์‚ญ์ œ");

String uuid = jwtService.resolveToken();
User user = userService.getUser(uuid);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public ResponseEntity<JsonResponse> updatePlant (
) @PathVariable Long plantIdx,
@Parameter(
name = "nickname",
description = "์‹๋ฌผ์˜ ์ƒˆ๋กœ์šด ๋‹‰๋„ค์ž„",
description = "์‹๋ฌผ์˜ ์ƒˆ๋กœ์šด ๋‹‰๋„ค์ž„๊ณผ ๋ฌผ ์ฃผ๊ธฐ ๊ธฐ๊ฐ„ ๊ฐ’",
required = true
) @RequestPart("plant") PlantDto.updatePlantReq updatePlantReq,
@Parameter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public static class getPlantRes{
private String scientificName;
@Schema(description = "์‹๋ฌผ์˜ ๋ฌผ์ฃผ๋Š” ์ฃผ๊ธฐ (Information ์— ์ €์žฅ๋œ ๊ถŒ์žฅ ์ฃผ๊ธฐ)", example = "10")
private Long waterDay;
@Schema(description = "๊ด€๋ฆฌ ํŒ", example = "๋ฌผ์„ ์ข‹์•„ํ•˜๋‚˜ ๊ณผ์Šต์— ์ฃผ์˜ํ•˜์„ธ์š”!")
private String tip;
@Schema(description = "๋น›์˜ ๊ฐ•๋„", example = "๋ฐ์€ ๊ณณ์„ ์ข‹์•„ํ•ด์š”!")
private String sunlight;
@Schema(description = "์ตœ์ € ์˜จ๋„", example = "16")
Expand Down Expand Up @@ -147,8 +149,12 @@ public getMyGardenPlantListRes(Plant plant, Long remainderDate, String recentMem
@NoArgsConstructor
@Data
public static class updatePlantReq{
@Schema(description = "์ˆ˜์ •ํ•˜๋Š” ์‹๋ฌผ์˜ ์ธ๋ฑ์Šค ๊ฐ’")
private Long plantIdx;
@Schema(description = "์‹๋ฌผ์˜ ์ƒˆ๋กœ์šด ๋‹‰๋„ค์ž„", example = "๋จธ๋‹ˆ๋ณผ")
private String nickname;
@Schema(description = "์‹๋ฌผ์˜ ์ƒˆ๋กœ์šด ๋ฌผ์ฃผ๊ธฐ ๊ธฐ๊ฐ„ ๊ฐ’. ์ž…๋ ฅ์€ ๋ฌธ์ž์—ด๋กœ ๋ฐ›์Œ.", example = "15")
private String waterCycle;
}

/**
Expand All @@ -160,6 +166,7 @@ public static class updatePlantReq{
public static class updatePlantRes{
private Long plantIdx;
private String nickname;
private int waterCycle;
private String imgUrl;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ public Plant(Place place, String plantName, String nickname, int waterCycle, Str
/**
* ์‹๋ฌผ ์ˆ˜์ • API ๊ด€๋ จ ๋ฉ”์†Œ๋“œ
*/
public void updatePlant(String imgUrl, String nickname) {
public void updatePlant(String imgUrl, String nickname, int waterCycle) {
this.imgUrl = imgUrl;
this.nickname = nickname;
this.waterCycle = waterCycle;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ public String createPlant(User user, PlantDto.createPlantReq req, MultipartFile
waterCycle = req.getWaterCycle();

if(waterCycle.charAt(0) == 0) {
throw new BadRequestException(ErrorResponseStatus.REGEX_VALIDATION_ERROR);
throw new BadRequestException(ErrorResponseStatus.PLANT_WATERED_DATE_REGEX_VALIDATION_ERROR);
} else if(req.getWaterCycle().matches("^[1-9]\\d*$")){
castedWaterCycle = Integer.parseInt(waterCycle);
} else {
throw new BadRequestException(ErrorResponseStatus.REGEX_VALIDATION_ERROR);
throw new BadRequestException(ErrorResponseStatus.PLANT_WATERED_DATE_REGEX_VALIDATION_ERROR);
}
}

Expand Down Expand Up @@ -154,6 +154,12 @@ public PlantDto.getPlantRes getPlant(User user, Long plantIdx) {

// log.info("getMemoList: " + getAllMemoList);

String tip = null;

if(!infoResponse.get(0).getTip().isEmpty()) {
tip = infoResponse.get(0).getTip();
}

PlantDto.getPlantRes getPlantRes = new PlantDto.getPlantRes(
plant.getPlantIdx(),
plant.getPlantName(),
Expand All @@ -165,6 +171,7 @@ public PlantDto.getPlantRes getPlant(User user, Long plantIdx) {
getAllMemoList,
infoResponse.get(0).getScientificName(),
infoResponse.get(0).getWater_day(),
tip,
infoResponse.get(0).getSunlight(),
infoResponse.get(0).getTemp_min(),
infoResponse.get(0).getTemp_max(),
Expand Down Expand Up @@ -361,21 +368,42 @@ public PlantDto.updatePlantRes updatePlant(User user, Long plantIdx, PlantDto.up
throw new BadRequestException(ErrorResponseStatus.LONG_PLANT_NICKNAME);
}

// TODO: ์‹๋ฌผ์˜ ๋ฌผ ์ฃผ๊ธฐ ๊ธฐ๊ฐ„
String waterCycle = null;
int castedWaterCycle = 0;

if(String.valueOf(req.getWaterCycle()).isEmpty()){
throw new BadRequestException(ErrorResponseStatus.EMPTY_PLANT_WATERED_DATE);
} else {
waterCycle = req.getWaterCycle();

if(waterCycle.charAt(0) == 0) {
throw new BadRequestException(ErrorResponseStatus.PLANT_WATERED_DATE_REGEX_VALIDATION_ERROR);
} else if(req.getWaterCycle().matches("^[1-9]\\d*$")){
castedWaterCycle = Integer.parseInt(waterCycle);
} else {
throw new BadRequestException(ErrorResponseStatus.PLANT_WATERED_DATE_REGEX_VALIDATION_ERROR);
}
}

// TODO: imgUrl
String imgUrl = null;

if (plantImage.getSize() > 0) {
imgUrl = plant.getImgUrl();
imageService.deleteFileInS3(plant.getImgUrl());

imgUrl = imageService.saveImage(plantImage);
} else {
throw new BadRequestException(ErrorResponseStatus.NO_SELECTED_PLANT_IMAGE);
}

plant.updatePlant(imgUrl, plantNickname);
plant.updatePlant(imgUrl, plantNickname, castedWaterCycle);
plantRepository.save(plant);

return new PlantDto.updatePlantRes(
plant.getPlantIdx(),
plantNickname,
castedWaterCycle,
imgUrl
);
}
Expand All @@ -399,6 +427,7 @@ public PlantDto.updatePlantRes getUpdatedPlant(User user, Long plantIdx) {
return new PlantDto.updatePlantRes(
plant.getPlantIdx(),
plant.getNickname(),
plant.getWaterCycle(),
plant.getImgUrl()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,21 @@ public class UserController implements UserSwagger{

@PostMapping(value = "/user", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) //join
public ResponseEntity<JsonResponse> join(@RequestPart("user") UserDto.join req, @RequestParam(value ="image", required = false)MultipartFile image){
log.info("join");
log.info("[API] Join User");
String token = userService.joinUser(req, image);

return ResponseEntity.ok(new JsonResponse(true, 200, "join", token));
}
@GetMapping("/user/{name}") // ํšŒ์›์ •๋ณด ์กฐํšŒ
public ResponseEntity<JsonResponse> getUserByName(@PathVariable String name){
log.info("[API] Get User Info");
User user = userService.getUserByName(name);

return ResponseEntity.ok(new JsonResponse(true, 200, "getUser", user));
}
@GetMapping("/user/{name}/exists")
public ResponseEntity<JsonResponse> checkNameDuplicate(@PathVariable String name){
log.info("[API] Check Duplicated Name");
boolean checkName = userService.checkNameDuplication(name);

return ResponseEntity.ok(new JsonResponse(true, 200, "์‚ฌ์šฉ๊ฐ€๋Šฅํ•œ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค.", checkName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public enum ErrorResponseStatus {
NO_PLANT_NICKNAME(false, 4201, "์‹๋ฌผ์˜ ์• ์นญ์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”!"),
LONG_PLANT_NICKNAME(false, 4202, "์‹๋ฌผ์˜ ์• ์นญ์€ 10์ž ์ดํ•˜๋กœ ์„ค์ •ํ•ด์ฃผ์„ธ์š”!"),
NO_SELECTED_PLANT_IMAGE(false,4203, "์‹๋ฌผ์˜ ์ด๋ฏธ์ง€๋ฅผ ์„ ํƒํ•ด์ฃผ์„ธ์š”!"),
REGEX_VALIDATION_ERROR(false, 4204, "์ •ํ™•ํ•œ ๋ฌผ ์ฃผ๊ธฐ ๊ฐ’์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”!"),

EMPTY_PLANT_WATERED_DATE(false, 4204, "์‹๋ฌผ์˜ ์ƒˆ๋กœ์šด ๋ฌผ ์ฃผ๊ธฐ ๊ธฐ๊ฐ„์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”!"),
PLANT_WATERED_DATE_REGEX_VALIDATION_ERROR(false, 4205, "์ •ํ™•ํ•œ ๋ฌผ ์ฃผ๊ธฐ ๊ธฐ๊ฐ„ ๊ฐ’์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”!"),

// 4300 : Memo
PLANT_NOT_FOUND(false, 4300, "๋“ฑ๋ก๋˜์ง€ ์•Š์€ ์‹๋ฌผ์ž…๋‹ˆ๋‹ค."),
Expand Down
Loading