1414import com .Rootin .domain .plant .entity .enums .GrowthStage ;
1515import com .Rootin .domain .plant .repository .PlantRepository ;
1616import com .Rootin .global .exception .CustomException ;
17+ import com .Rootin .global .exception .ErrorCode ;
1718import lombok .RequiredArgsConstructor ;
1819import org .springframework .stereotype .Service ;
1920import org .springframework .transaction .annotation .Transactional ;
@@ -69,7 +70,7 @@ public PotPlantOptionsResponse getPlantOptions(Long userId, Long potId) {
6970 @ Transactional
7071 public PotPlantResponse plant (Long userId , Long potId , PotPlantRequest request ) {
7172 Pot pot = potRepository .findByIdWithLock (potId )
72- .orElseThrow (() -> CustomException .notFound ( "존재하지 않는 화분입니다. ID: " + potId ));
73+ .orElseThrow (() -> CustomException .of ( ErrorCode . POT_NOT_FOUND ));
7374 validateOwner (pot , userId );
7475
7576 List <PlantItem > activeItems = plantItemRepository .findActivePlantItemsByPotId (pot .getId ());
@@ -97,14 +98,14 @@ public PotPlantResponse plant(Long userId, Long potId, PotPlantRequest request)
9798
9899 private Pot getOwnedPot (Long userId , Long potId ) {
99100 Pot pot = potRepository .findById (potId )
100- .orElseThrow (() -> CustomException .notFound ( "존재하지 않는 화분입니다. ID: " + potId ));
101+ .orElseThrow (() -> CustomException .of ( ErrorCode . POT_NOT_FOUND ));
101102 validateOwner (pot , userId );
102103 return pot ;
103104 }
104105
105106 private void validateOwner (Pot pot , Long userId ) {
106107 if (!pot .getUserId ().equals (userId )) {
107- throw CustomException .forbidden ( "해당 화분에 접근할 권한이 없습니다." );
108+ throw CustomException .of ( ErrorCode . POT_FORBIDDEN );
108109 }
109110 }
110111
@@ -135,7 +136,7 @@ private Plant selectHarvestedPlantSeed(Long userId, Long sourcePlantItemId) {
135136 }
136137
137138 Plant sourcePlant = plantRepository .findById (sourceItem .getPlantId ())
138- .orElseThrow (() -> CustomException .notFound ( "식물 마스터 데이터를 찾을 수 없습니다." ));
139+ .orElseThrow (() -> CustomException .of ( ErrorCode . PLANT_NOT_FOUND ));
139140
140141 if (sourcePlant .getGrowthStage () != GrowthStage .SEED ) {
141142 throw CustomException .badRequest ("수확 식물 아이템은 씨앗 단계 식물 마스터 데이터와 연결되어야 합니다." );
@@ -152,7 +153,7 @@ private Plant selectRandomSeedPlant() {
152153 candidates = plantRepository .findByGradeAndGrowthStage (Grade .COMMON , GrowthStage .SEED );
153154 }
154155 if (candidates .isEmpty ()) {
155- throw CustomException .notFound ( "배정 가능한 식물 마스터 데이터가 없습니다." );
156+ throw CustomException .of ( ErrorCode . PLANT_NOT_FOUND );
156157 }
157158
158159 return candidates .get (ThreadLocalRandom .current ().nextInt (candidates .size ()));
@@ -201,7 +202,7 @@ private Map<Long, Plant> getPlantMap(PlantItem currentPlantItem, List<PlantItem>
201202
202203 private PotPlantResponse toPotPlantResponse (PlantItem plantItem , Plant plant ) {
203204 if (plant == null ) {
204- throw CustomException .notFound ( "식물 마스터 데이터를 찾을 수 없습니다." );
205+ throw CustomException .of ( ErrorCode . PLANT_NOT_FOUND );
205206 }
206207 return new PotPlantResponse (
207208 plantItem .getPotId (),
@@ -216,7 +217,7 @@ private PotPlantResponse toPotPlantResponse(PlantItem plantItem, Plant plant) {
216217
217218 private PlantOptionResponse toPlantOptionResponse (PlantItem plantItem , Plant plant ) {
218219 if (plant == null ) {
219- throw CustomException .notFound ( "식물 마스터 데이터를 찾을 수 없습니다." );
220+ throw CustomException .of ( ErrorCode . PLANT_NOT_FOUND );
220221 }
221222 return new PlantOptionResponse (
222223 plantItem .getId (),
0 commit comments