Skip to content

Commit

Permalink
[FIX] #53 과제 점수 부여 및 오류 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
OliviaYJH committed Dec 20, 2022
1 parent ca8429e commit fed92de
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,25 +103,29 @@ public BaseResponse2<MyPlantSaveResponse> save(
return new BaseResponse2<>(POST_SUCCESS);
}

// 광합성
@PutMapping("/sun/{userId}/{myPlantId}")
public ResponseEntity<MyPlantUpdateResponse> putSun(@PathVariable Long userId, @PathVariable Long myPlantId) {
myPlantService.updateSun(userId, myPlantId);
return MyPlantUpdateResponse.newResponse(UPDATE_SUNPLANTLOG_SUCCESS);
}

// 분갈이
@PutMapping("/repot/{userId}/{myPlantId}")
public BaseResponse2<String> putRepot(@PathVariable Long userId, @PathVariable Long myPlantId){
public ResponseEntity<MyPlantUpdateResponse> putRepot(@PathVariable Long userId, @PathVariable Long myPlantId){
myPlantService.updateRepot(userId, myPlantId);
return new BaseResponse2("success");
return MyPlantUpdateResponse.newResponse(UPDATE_REPOTPLANTLOG_SUCCESS);
}

// 물 주기
@PutMapping("/water/{userId}/{myPlantId}")
public ResponseEntity<MyPlantUpdateResponse> putWater(@PathVariable Long userId, @PathVariable Long myPlantId) {
myPlantService.updateWater(userId, myPlantId);
return MyPlantUpdateResponse.newResponse(UPDATE_WATERPLANTLOG_SUCCESS);
}

@PutMapping("look/{userId}/{myPlantId}")
// 관찰
@PutMapping("/look/{userId}/{myPlantId}")
public ResponseEntity<MyPlantUpdateResponse> putLook(@PathVariable Long userId, @PathVariable Long myPlantId) {
myPlantService.updateLook(userId, myPlantId);
return MyPlantUpdateResponse.newResponse(UPDATE_LOOKPLANTLOG_SUCCESS);
Expand Down
35 changes: 35 additions & 0 deletions server/src/main/java/com/plantity/server/domain/users/Users.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ public class Users extends BaseTimeEntity {
private int score;
//private String status;

@JsonIgnore
@OneToMany(mappedBy = "users")
private List<MyPlant> myPlant = new ArrayList<MyPlant>();

@JsonIgnore
@OneToMany(mappedBy = "users")
private List<PlantLog> plantLogs = new ArrayList<>();

@JsonIgnore
@OneToMany(mappedBy = "users")
private List<PlantFollowing> plantFollowings = new ArrayList<PlantFollowing>();

Expand All @@ -54,4 +57,36 @@ public Users(UsersRequestDto usersRequestDto){
//this.status = usersRequestDto.getStatus();
}

// 광합성
public void updateSun(){
score += 5;
checkRating();
}

// 분갈이
public void updateRepot(){
score += 20;
checkRating();
}

// 물 주기
public void updateWater(){
score += 3;
checkRating();
}

// 관찰
public void updateLook(){
score += 2;
checkRating();
}

public void checkRating(){
if(score <= 30)
rating = "비기너";
else if(score <= 100)
rating = "가드너";
else
rating = "마스터";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import com.plantity.server.domain.plantlog.MyPlantLogRequestDto;
import com.plantity.server.domain.plantlog.MyPlantLogResponseDto;
import com.plantity.server.domain.plantlog.PlantLog;
import com.plantity.server.domain.users.Users;
import com.plantity.server.dto.req.DateMyPlantLogRequestDto;
import com.plantity.server.dto.res.plantlog.DatePlantLogResponse;
import com.plantity.server.repository.MyPlantRepository;
import com.plantity.server.repository.PlantLogRepository;
import com.plantity.server.repository.UsersRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -21,6 +23,7 @@ public class MyPlantService {

private final MyPlantRepository myPlantRepository;
private final PlantLogRepository plantLogRepository;
private final UsersRepository usersRepository;

/*
@Transactional
Expand Down Expand Up @@ -56,39 +59,66 @@ public DateMyPlantLogResponseDto datePlantLog(DateMyPlantLogRequestDto requestDt
return DateMyPlantLogResponseDto.from(plantLog);
}

// 광합성
@Transactional
public Long updateSun(Long userId, Long myPlantId) {
PlantLog plantLog = plantLogRepository.findById(myPlantId).orElseThrow(
() -> new IllegalArgumentException("해당 식물이 없습니다.")
);
plantLog.updateSun(true);

Users users = usersRepository.findById(userId).orElseThrow(
() -> new IllegalArgumentException("해당 유저가 없습니다.")
);
users.updateSun();
return plantLog.getPlantId();
}

// 분갈이
@Transactional
public Long updateRepot(Long userId, Long myPlantId) {
PlantLog plantLog = plantLogRepository.findById(myPlantId).orElseThrow(
() -> new IllegalArgumentException("해당 식물이 없습니다")
);
plantLog.updateRepot(true);

Users users = usersRepository.findById(userId).orElseThrow(
() -> new IllegalArgumentException("해당 유저가 없습니다.")
);
users.updateRepot();

return plantLog.getPlantId();
}

// 물 주기
@Transactional
public Long updateWater(Long userId, Long myPlantId) {
PlantLog plantLog = plantLogRepository.findById(myPlantId).orElseThrow(
() -> new IllegalArgumentException("해당 식물이 없습니다.")
);
plantLog.updateWater(true);

Users users = usersRepository.findById(userId).orElseThrow(
() -> new IllegalArgumentException("해당 유저가 없습니다.")
);
users.updateWater();

return plantLog.getPlantId();
}

// 관찰
@Transactional
public Long updateLook(Long userId, Long myPlantId) {
PlantLog plantLog = plantLogRepository.findById(myPlantId).orElseThrow(
() -> new IllegalArgumentException("해당 식물이 없습니다.")
);
plantLog.updateLook(true);

Users users = usersRepository.findById(userId).orElseThrow(
() -> new IllegalArgumentException("해당 유저가 없습니다.")
);
users.updateLook();

return plantLog.getPlantId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public UsersResponseDto userInfo(UsersRequestDto requestDto) {
Users users = userRepository.findById(requestDto.getUserId()).orElseThrow(
() -> new IllegalArgumentException("해당 유저가 없습니다.")
);
users.checkRating();

return UsersResponseDto.from(users);

Expand Down
2 changes: 1 addition & 1 deletion server/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ spring.jpa.hibernate.ddl-auto=update
#spring.jpa.properties.hibernate.globally_quoted_identifiers=true

#port change
server.port=8086
#server.port=8086


cloud.aws.stack.auto=false
Expand Down

0 comments on commit fed92de

Please sign in to comment.