From 4e9d8087e1f83b9121df4322be0db01167102596 Mon Sep 17 00:00:00 2001 From: wellbeing-dough Date: Sat, 14 Oct 2023 16:09:48 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20=EC=88=A0=20=EC=97=85=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=8A=B8=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../drink/controller/DrinkController.java | 15 ++++++++----- .../drink/controller/request/UpdateDrink.java | 22 +++++++++++++++++++ .../jurumarble/drink/domain/entity/Drink.java | 16 ++++++++++++++ .../drink/service/DrinkService.java | 8 +++++++ 4 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 src/main/java/co/kr/jurumarble/drink/controller/request/UpdateDrink.java diff --git a/src/main/java/co/kr/jurumarble/drink/controller/DrinkController.java b/src/main/java/co/kr/jurumarble/drink/controller/DrinkController.java index 3ebb615..c0a3258 100644 --- a/src/main/java/co/kr/jurumarble/drink/controller/DrinkController.java +++ b/src/main/java/co/kr/jurumarble/drink/controller/DrinkController.java @@ -1,10 +1,7 @@ package co.kr.jurumarble.drink.controller; import co.kr.jurumarble.comment.enums.Region; -import co.kr.jurumarble.drink.controller.request.AddDrink; -import co.kr.jurumarble.drink.controller.request.AddImage; -import co.kr.jurumarble.drink.controller.request.DrinkData; -import co.kr.jurumarble.drink.controller.request.EnjoyDrinkRequest; +import co.kr.jurumarble.drink.controller.request.*; import co.kr.jurumarble.drink.controller.response.GetDrinkResponse; import co.kr.jurumarble.drink.controller.response.GetEnjoyedResponse; import co.kr.jurumarble.drink.controller.response.GetHotDrinksResponse; @@ -92,11 +89,19 @@ public ResponseEntity addDrinkImage(@RequestBody AddImage image) { return ResponseEntity.ok().build(); } - @Operation(summary = "전통주 추가") + @Operation(summary = "전통주 추가 테스트") @PostMapping("/add-test") public ResponseEntity addDrink(@RequestBody AddDrink drink) { Long id = drinkService.addDrink(drink); return new ResponseEntity(id, HttpStatus.OK); } + @Operation(summary = "전통주 수정 테스트") + @PutMapping("/update-test") + public ResponseEntity updateDrink(@RequestBody UpdateDrink drink) { + Long id = drinkService.updateDrink(drink); + return new ResponseEntity(id, HttpStatus.OK); + } + + } diff --git a/src/main/java/co/kr/jurumarble/drink/controller/request/UpdateDrink.java b/src/main/java/co/kr/jurumarble/drink/controller/request/UpdateDrink.java new file mode 100644 index 0000000..22504ae --- /dev/null +++ b/src/main/java/co/kr/jurumarble/drink/controller/request/UpdateDrink.java @@ -0,0 +1,22 @@ +package co.kr.jurumarble.drink.controller.request; + +import lombok.Getter; + +@Getter +public class UpdateDrink { + private Long drinkId; + private String name; + private String type; + private String manufacturer; + private String alcoholicBeverage; + private String rawMaterial; + private String capacity; + private String manufactureAddress; + private String region; + private String price; + private String image; + private Double latitude; + private Double longitude; + + +} diff --git a/src/main/java/co/kr/jurumarble/drink/domain/entity/Drink.java b/src/main/java/co/kr/jurumarble/drink/domain/entity/Drink.java index 4a33724..0f4c5bf 100644 --- a/src/main/java/co/kr/jurumarble/drink/domain/entity/Drink.java +++ b/src/main/java/co/kr/jurumarble/drink/domain/entity/Drink.java @@ -1,5 +1,6 @@ package co.kr.jurumarble.drink.domain.entity; +import co.kr.jurumarble.drink.controller.request.UpdateDrink; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; @@ -82,4 +83,19 @@ public int hashCode() { public boolean hasSameRegion(Drink drink) { return region.equals(drink.getRegion()); } + + public void updateDrink(UpdateDrink info) { + this.name = info.getName(); + this.type = info.getType(); + this.manufacturer = info.getManufacturer(); + this.alcoholicBeverage = info.getAlcoholicBeverage(); + this.rawMaterial = info.getRawMaterial(); + this.capacity = info.getCapacity(); + this.manufactureAddress = info.getManufactureAddress(); + this.region = info.getRegion(); + this.price = info.getPrice(); + this.image = info.getImage(); + this.latitude = info.getLatitude(); + this.longitude = info.getLongitude(); + } } diff --git a/src/main/java/co/kr/jurumarble/drink/service/DrinkService.java b/src/main/java/co/kr/jurumarble/drink/service/DrinkService.java index 7df78b5..8255111 100644 --- a/src/main/java/co/kr/jurumarble/drink/service/DrinkService.java +++ b/src/main/java/co/kr/jurumarble/drink/service/DrinkService.java @@ -3,6 +3,7 @@ import co.kr.jurumarble.drink.controller.request.AddDrink; import co.kr.jurumarble.drink.controller.request.AddImage; import co.kr.jurumarble.drink.controller.request.DrinkData; +import co.kr.jurumarble.drink.controller.request.UpdateDrink; import co.kr.jurumarble.drink.controller.response.GetHotDrinksResponse; import co.kr.jurumarble.drink.controller.response.GetMapInDrinksResponse; import co.kr.jurumarble.drink.domain.dto.MapInDrinkData; @@ -142,4 +143,11 @@ public Long addDrink(AddDrink drinkInfo) { Drink drink = drinkInfo.toEntity(); return drinkRepository.save(drink).getId(); } + + @Transactional + public Long updateDrink(UpdateDrink drinkInfo) { + Drink drink = drinkRepository.findById(drinkInfo.getDrinkId()).orElseThrow(RuntimeException::new); + drink.updateDrink(drinkInfo); + return drink.getId(); + } }