From 49a1163847c38e949908e5f9260443366d312186 Mon Sep 17 00:00:00 2001 From: stopmin Date: Mon, 23 Sep 2024 14:14:23 +0900 Subject: [PATCH 01/24] =?UTF-8?q?feat:=20Farm=20Entity=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20#2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/poomasi/domain/farm/entity/Farm.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/main/java/poomasi/domain/farm/entity/Farm.java diff --git a/src/main/java/poomasi/domain/farm/entity/Farm.java b/src/main/java/poomasi/domain/farm/entity/Farm.java new file mode 100644 index 00000000..4957eca8 --- /dev/null +++ b/src/main/java/poomasi/domain/farm/entity/Farm.java @@ -0,0 +1,41 @@ +package poomasi.domain.farm.entity; + +import jakarta.persistence.*; +import org.hibernate.annotations.CreationTimestamp; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.SQLSelect; +import org.hibernate.annotations.UpdateTimestamp; + +import java.time.LocalDateTime; + +@Entity +@Table(name = "farm") +@SQLDelete(sql = "UPDATE farm SET deleted = true WHERE id = ?") +@SQLSelect(sql = "SELECT * FROM farm WHERE deleted = false") +public class Farm { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String name; + + // FIXME: owner_id는 Member의 id를 참조해야 합니다. + @Column(name = "owner_id") + private Long ownerId; + + private String address; // 도로명 주소 + private String addressDetail; // 상세 주소 + + private Double latitude; + private Double longitude; + + private boolean deleted = false; + + @CreationTimestamp + @Column(name = "created_at") + private LocalDateTime createdAt = LocalDateTime.now(); + + @Column(name = "updated_at") + @UpdateTimestamp + private LocalDateTime updatedAt = LocalDateTime.now(); +} From 7e5e03517faf090e3ae54b7920f8af1b6a7645f1 Mon Sep 17 00:00:00 2001 From: stopmin Date: Mon, 23 Sep 2024 14:32:22 +0900 Subject: [PATCH 02/24] =?UTF-8?q?feat:=20Farm=20Entity=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20-=20=EB=B9=8C=EB=8D=94=ED=8C=A8=ED=84=B4=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9=20-=20=EC=83=81=ED=83=9C=EB=A5=BC=20?= =?UTF-8?q?=EB=82=98=ED=83=80=EB=82=B4=EB=8A=94=20=EA=B0=92=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=20#2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/poomasi/domain/farm/entity/Farm.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main/java/poomasi/domain/farm/entity/Farm.java b/src/main/java/poomasi/domain/farm/entity/Farm.java index 4957eca8..64c49983 100644 --- a/src/main/java/poomasi/domain/farm/entity/Farm.java +++ b/src/main/java/poomasi/domain/farm/entity/Farm.java @@ -1,6 +1,10 @@ package poomasi.domain.farm.entity; import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; import org.hibernate.annotations.CreationTimestamp; import org.hibernate.annotations.SQLDelete; import org.hibernate.annotations.SQLSelect; @@ -9,7 +13,9 @@ import java.time.LocalDateTime; @Entity +@Getter @Table(name = "farm") +@NoArgsConstructor(access = AccessLevel.PROTECTED) @SQLDelete(sql = "UPDATE farm SET deleted = true WHERE id = ?") @SQLSelect(sql = "SELECT * FROM farm WHERE deleted = false") public class Farm { @@ -29,6 +35,8 @@ public class Farm { private Double latitude; private Double longitude; + private FarmStatus status = FarmStatus.WAITING; + private boolean deleted = false; @CreationTimestamp @@ -38,4 +46,15 @@ public class Farm { @Column(name = "updated_at") @UpdateTimestamp private LocalDateTime updatedAt = LocalDateTime.now(); + + @Builder + public Farm(String name, Long ownerId, String address, String addressDetail, Double latitude, Double longitude) { + this.name = name; + this.ownerId = ownerId; + this.address = address; + this.addressDetail = addressDetail; + this.latitude = latitude; + this.longitude = longitude; + } + } From c1379577bb4a42e30abeb293e43f4098d3af3b25 Mon Sep 17 00:00:00 2001 From: stopmin Date: Mon, 23 Sep 2024 14:32:34 +0900 Subject: [PATCH 03/24] =?UTF-8?q?feat:=20FarmManageService=20=EC=A0=95?= =?UTF-8?q?=EC=9D=98=20-=20=EB=93=B1=EB=A1=9D=20=EC=9D=B8=ED=84=B0?= =?UTF-8?q?=ED=8E=98=EC=9D=B4=EC=8A=A4=EB=A7=8C=20=EC=A0=95=EC=9D=98=20#2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farm/service/FarmManageService.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/main/java/poomasi/domain/farm/service/FarmManageService.java diff --git a/src/main/java/poomasi/domain/farm/service/FarmManageService.java b/src/main/java/poomasi/domain/farm/service/FarmManageService.java new file mode 100644 index 00000000..bc7a1438 --- /dev/null +++ b/src/main/java/poomasi/domain/farm/service/FarmManageService.java @@ -0,0 +1,21 @@ +package poomasi.domain.farm.service; + +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Service; +import poomasi.domain.farm.dto.FarmRegisterRequest; +import poomasi.domain.farm.repository.FarmRepository; + +@Service +@AllArgsConstructor +public class FarmManageService { + private final FarmRepository farmRepository; + + public Long registerFarm(FarmRegisterRequest request) { + // TODO: 판매자 인가? + + // TODO: 이미 등록된 농장 인가? + + + return farmRepository.save(request.toEntity()).getId(); + } +} From 8ddbdcd44c2985dc01147393208299df8e7b74f3 Mon Sep 17 00:00:00 2001 From: stopmin Date: Mon, 23 Sep 2024 14:32:43 +0900 Subject: [PATCH 04/24] =?UTF-8?q?feat:=20FarmRegisterRequest=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20#2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/farm/dto/FarmRegisterRequest.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/main/java/poomasi/domain/farm/dto/FarmRegisterRequest.java diff --git a/src/main/java/poomasi/domain/farm/dto/FarmRegisterRequest.java b/src/main/java/poomasi/domain/farm/dto/FarmRegisterRequest.java new file mode 100644 index 00000000..0a1b6814 --- /dev/null +++ b/src/main/java/poomasi/domain/farm/dto/FarmRegisterRequest.java @@ -0,0 +1,25 @@ +package poomasi.domain.farm.dto; + +import poomasi.domain.farm.entity.Farm; + +public record FarmRegisterRequest( + String name, + Long ownerId, + String address, + String addressDetail, + Double latitude, + Double longitude, + String phoneNumber, + String description +) { + public Farm toEntity() { + return Farm.builder() + .name(name) + .ownerId(ownerId) + .address(address) + .addressDetail(addressDetail) + .latitude(latitude) + .longitude(longitude) + .build(); + } +} From b64486755218883952b6725194f52bc002ee69d5 Mon Sep 17 00:00:00 2001 From: stopmin Date: Mon, 23 Sep 2024 14:32:55 +0900 Subject: [PATCH 05/24] =?UTF-8?q?feat:=20FarmStatus=20=EC=A0=95=EC=9D=98?= =?UTF-8?q?=20-=20=ED=9A=8C=EC=9D=98=20=EB=94=B0=EB=A1=9C=20=ED=95=84?= =?UTF-8?q?=EC=9A=94=ED=95=A8.=20#2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/poomasi/domain/farm/entity/FarmStatus.java | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/main/java/poomasi/domain/farm/entity/FarmStatus.java diff --git a/src/main/java/poomasi/domain/farm/entity/FarmStatus.java b/src/main/java/poomasi/domain/farm/entity/FarmStatus.java new file mode 100644 index 00000000..c309dba0 --- /dev/null +++ b/src/main/java/poomasi/domain/farm/entity/FarmStatus.java @@ -0,0 +1,6 @@ +package poomasi.domain.farm.entity; + +// TODO: 농장 상태에 대한 Enum 논의 필요 +public enum FarmStatus { + OPEN, CLOSE, WAITING +} From 047f6791d570436bfd75a0a064f4726fb3ce698e Mon Sep 17 00:00:00 2001 From: stopmin Date: Mon, 23 Sep 2024 14:33:08 +0900 Subject: [PATCH 06/24] =?UTF-8?q?feat:=20FarmMangeController=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20-=20=EB=93=B1=EB=A1=9D=20API=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=20#2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farm/controller/FarmMangeController.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/main/java/poomasi/domain/farm/controller/FarmMangeController.java diff --git a/src/main/java/poomasi/domain/farm/controller/FarmMangeController.java b/src/main/java/poomasi/domain/farm/controller/FarmMangeController.java new file mode 100644 index 00000000..30401e74 --- /dev/null +++ b/src/main/java/poomasi/domain/farm/controller/FarmMangeController.java @@ -0,0 +1,19 @@ +package poomasi.domain.farm.controller; + +import lombok.AllArgsConstructor; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RestController; +import poomasi.domain.farm.dto.FarmRegisterRequest; +import poomasi.domain.farm.service.FarmManageService; + +// TODO: 판매자만 접근가능하도록 인증/인가 annotation 추가 +@RestController +@AllArgsConstructor +public class FarmMangeController { + private final FarmManageService farmManageService; + + @PostMapping("/api/farm") + public Long registerFarm(FarmRegisterRequest request) { + return farmManageService.registerFarm(request); + } +} From aecc7c2e26ac07b57e4a30c397cae8ac1a7abe3d Mon Sep 17 00:00:00 2001 From: stopmin Date: Mon, 23 Sep 2024 14:33:21 +0900 Subject: [PATCH 07/24] =?UTF-8?q?feat:=20FarmRepository=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20#2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../poomasi/domain/farm/repository/FarmRepository.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/main/java/poomasi/domain/farm/repository/FarmRepository.java diff --git a/src/main/java/poomasi/domain/farm/repository/FarmRepository.java b/src/main/java/poomasi/domain/farm/repository/FarmRepository.java new file mode 100644 index 00000000..2ed9a241 --- /dev/null +++ b/src/main/java/poomasi/domain/farm/repository/FarmRepository.java @@ -0,0 +1,9 @@ +package poomasi.domain.farm.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; +import poomasi.domain.farm.entity.Farm; + +@Repository +public interface FarmRepository extends JpaRepository { +} From 41d6e3560d116ee74f21de40bf72f9142b24361d Mon Sep 17 00:00:00 2001 From: stopmin Date: Mon, 23 Sep 2024 14:34:06 +0900 Subject: [PATCH 08/24] =?UTF-8?q?feat:=20FarmMangeController=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20-=20ResponseEntity=20=EB=A6=AC=ED=84=B4=ED=95=9C?= =?UTF-8?q?=EB=8B=A4=20#2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/farm/controller/FarmMangeController.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/poomasi/domain/farm/controller/FarmMangeController.java b/src/main/java/poomasi/domain/farm/controller/FarmMangeController.java index 30401e74..57a8d926 100644 --- a/src/main/java/poomasi/domain/farm/controller/FarmMangeController.java +++ b/src/main/java/poomasi/domain/farm/controller/FarmMangeController.java @@ -1,7 +1,10 @@ package poomasi.domain.farm.controller; import lombok.AllArgsConstructor; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import poomasi.domain.farm.dto.FarmRegisterRequest; import poomasi.domain.farm.service.FarmManageService; @@ -13,7 +16,7 @@ public class FarmMangeController { private final FarmManageService farmManageService; @PostMapping("/api/farm") - public Long registerFarm(FarmRegisterRequest request) { - return farmManageService.registerFarm(request); + public ResponseEntity registerFarm(@RequestBody FarmRegisterRequest request) { + return ResponseEntity.ok(farmManageService.registerFarm(request)); } } From 5226bdba03a831f92d886155ca4ec8b0bd93941c Mon Sep 17 00:00:00 2001 From: stopmin Date: Mon, 23 Sep 2024 14:34:06 +0900 Subject: [PATCH 09/24] =?UTF-8?q?feat:=20FarmMangeController=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20-=20ResponseEntity=20=EB=A6=AC=ED=84=B4=ED=95=9C?= =?UTF-8?q?=EB=8B=A4=20#2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../poomasi/domain/farm/controller/FarmMangeController.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/poomasi/domain/farm/controller/FarmMangeController.java b/src/main/java/poomasi/domain/farm/controller/FarmMangeController.java index 30401e74..8ecc90be 100644 --- a/src/main/java/poomasi/domain/farm/controller/FarmMangeController.java +++ b/src/main/java/poomasi/domain/farm/controller/FarmMangeController.java @@ -1,7 +1,9 @@ package poomasi.domain.farm.controller; import lombok.AllArgsConstructor; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; import poomasi.domain.farm.dto.FarmRegisterRequest; import poomasi.domain.farm.service.FarmManageService; @@ -13,7 +15,7 @@ public class FarmMangeController { private final FarmManageService farmManageService; @PostMapping("/api/farm") - public Long registerFarm(FarmRegisterRequest request) { - return farmManageService.registerFarm(request); + public ResponseEntity registerFarm(@RequestBody FarmRegisterRequest request) { + return ResponseEntity.ok(farmManageService.registerFarm(request)); } } From ff43dfd93033f157c21e0bec60fbae7f7900484d Mon Sep 17 00:00:00 2001 From: stopmin Date: Mon, 23 Sep 2024 14:40:52 +0900 Subject: [PATCH 10/24] =?UTF-8?q?feat:=20FarmResponse=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=20#2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../poomasi/domain/farm/dto/FarmResponse.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/main/java/poomasi/domain/farm/dto/FarmResponse.java diff --git a/src/main/java/poomasi/domain/farm/dto/FarmResponse.java b/src/main/java/poomasi/domain/farm/dto/FarmResponse.java new file mode 100644 index 00000000..b349f266 --- /dev/null +++ b/src/main/java/poomasi/domain/farm/dto/FarmResponse.java @@ -0,0 +1,24 @@ +package poomasi.domain.farm.dto; + +import poomasi.domain.farm.entity.Farm; + + +public record FarmResponse( // FIXME: 사용자 정보 추가 및 설명/전화번호 추가 + Long id, + String name, + String address, + String addressDetail, + Double latitude, + Double longitude +) { + public static FarmResponse fromEntity(Farm farm) { + return new FarmResponse( + farm.getId(), + farm.getName(), + farm.getAddress(), + farm.getAddressDetail(), + farm.getLatitude(), + farm.getLongitude() + ); + } +} From ab7ab24c0d195632019ba838db18a53aabedad70 Mon Sep 17 00:00:00 2001 From: stopmin Date: Mon, 23 Sep 2024 14:41:05 +0900 Subject: [PATCH 11/24] =?UTF-8?q?feat:=20=EB=86=8D=EC=9E=A5=20=EB=8B=A8?= =?UTF-8?q?=EA=B1=B4=20=EC=A1=B0=ED=9A=8C=20API=20=EC=83=9D=EC=84=B1=20#2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farm/controller/FarmMangeController.java | 15 +++++++++++---- .../domain/farm/service/FarmManageService.java | 9 +++++++++ .../java/poomasi/global/error/BusinessError.java | 10 +++++++--- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/main/java/poomasi/domain/farm/controller/FarmMangeController.java b/src/main/java/poomasi/domain/farm/controller/FarmMangeController.java index 8ecc90be..0d8dfdc8 100644 --- a/src/main/java/poomasi/domain/farm/controller/FarmMangeController.java +++ b/src/main/java/poomasi/domain/farm/controller/FarmMangeController.java @@ -2,20 +2,27 @@ import lombok.AllArgsConstructor; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import poomasi.domain.farm.dto.FarmRegisterRequest; import poomasi.domain.farm.service.FarmManageService; -// TODO: 판매자만 접근가능하도록 인증/인가 annotation 추가 + @RestController @AllArgsConstructor public class FarmMangeController { private final FarmManageService farmManageService; + @GetMapping("/api/farm/{farmId}") + public ResponseEntity getFarm(@RequestParam Long farmId) { + return ResponseEntity.ok(farmManageService.getFarm(farmId)); + + } + + // TODO: 판매자만 접근가능하도록 인증/인가 annotation 추가 @PostMapping("/api/farm") public ResponseEntity registerFarm(@RequestBody FarmRegisterRequest request) { return ResponseEntity.ok(farmManageService.registerFarm(request)); } + + } diff --git a/src/main/java/poomasi/domain/farm/service/FarmManageService.java b/src/main/java/poomasi/domain/farm/service/FarmManageService.java index bc7a1438..c28a01b6 100644 --- a/src/main/java/poomasi/domain/farm/service/FarmManageService.java +++ b/src/main/java/poomasi/domain/farm/service/FarmManageService.java @@ -3,7 +3,10 @@ import lombok.AllArgsConstructor; import org.springframework.stereotype.Service; import poomasi.domain.farm.dto.FarmRegisterRequest; +import poomasi.domain.farm.dto.FarmResponse; import poomasi.domain.farm.repository.FarmRepository; +import poomasi.global.error.BusinessError; +import poomasi.global.error.BusinessException; @Service @AllArgsConstructor @@ -18,4 +21,10 @@ public Long registerFarm(FarmRegisterRequest request) { return farmRepository.save(request.toEntity()).getId(); } + + public FarmResponse getFarm(Long farmId) { + return farmRepository.findById(farmId) + .map(FarmResponse::fromEntity) + .orElseThrow(() -> new BusinessException(BusinessError.FARM_NOT_FOUND)); + } } diff --git a/src/main/java/poomasi/global/error/BusinessError.java b/src/main/java/poomasi/global/error/BusinessError.java index b412b56d..302f2377 100644 --- a/src/main/java/poomasi/global/error/BusinessError.java +++ b/src/main/java/poomasi/global/error/BusinessError.java @@ -8,9 +8,13 @@ @Getter @AllArgsConstructor public enum BusinessError { - EXAMPLE_ERROR(HttpStatus.BAD_REQUEST, "에러 예시입니다."); + EXAMPLE_ERROR(HttpStatus.BAD_REQUEST, "에러 예시입니다."), - private final HttpStatus httpStatus; + // Farm + FARM_NOT_FOUND(HttpStatus.NOT_FOUND, "농장을 찾을 수 없습니다."), + ; - private final String message; + private final HttpStatus httpStatus; + + private final String message; } From 86e469129a560c1683d0659dc378027ce2d9f3bf Mon Sep 17 00:00:00 2001 From: stopmin Date: Mon, 23 Sep 2024 14:41:46 +0900 Subject: [PATCH 12/24] =?UTF-8?q?refactor:=20=ED=95=A8=EC=88=98=20?= =?UTF-8?q?=EB=84=A4=EC=9D=B4=EB=B0=8D=20=EC=88=98=EC=A0=95=20-=20getFarm?= =?UTF-8?q?=20->=20getFarmByFarmId=20#2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../poomasi/domain/farm/controller/FarmMangeController.java | 2 +- .../java/poomasi/domain/farm/service/FarmManageService.java | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/poomasi/domain/farm/controller/FarmMangeController.java b/src/main/java/poomasi/domain/farm/controller/FarmMangeController.java index 0d8dfdc8..4271b73d 100644 --- a/src/main/java/poomasi/domain/farm/controller/FarmMangeController.java +++ b/src/main/java/poomasi/domain/farm/controller/FarmMangeController.java @@ -14,7 +14,7 @@ public class FarmMangeController { @GetMapping("/api/farm/{farmId}") public ResponseEntity getFarm(@RequestParam Long farmId) { - return ResponseEntity.ok(farmManageService.getFarm(farmId)); + return ResponseEntity.ok(farmManageService.getFarmByFarmId(farmId)); } diff --git a/src/main/java/poomasi/domain/farm/service/FarmManageService.java b/src/main/java/poomasi/domain/farm/service/FarmManageService.java index c28a01b6..ea8ad142 100644 --- a/src/main/java/poomasi/domain/farm/service/FarmManageService.java +++ b/src/main/java/poomasi/domain/farm/service/FarmManageService.java @@ -22,9 +22,11 @@ public Long registerFarm(FarmRegisterRequest request) { return farmRepository.save(request.toEntity()).getId(); } - public FarmResponse getFarm(Long farmId) { + public FarmResponse getFarmByFarmId(Long farmId) { return farmRepository.findById(farmId) .map(FarmResponse::fromEntity) .orElseThrow(() -> new BusinessException(BusinessError.FARM_NOT_FOUND)); } + + } From 2fb3780c44fb17c3419998c572685b42e8826149 Mon Sep 17 00:00:00 2001 From: stopmin Date: Mon, 23 Sep 2024 16:31:13 +0900 Subject: [PATCH 13/24] =?UTF-8?q?refactor:=20=ED=8C=90=EB=A7=A4=EC=9E=90?= =?UTF-8?q?=20&=20=EC=9D=BC=EB=B0=98=20=EC=9C=A0=EC=A0=80=20API=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC=20-=20Seller:=20=ED=8C=90=EB=A7=A4=EC=9E=90?= =?UTF-8?q?=20#2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farm/controller/FarmController.java | 20 +++++++++++++ .../farm/controller/FarmMangeController.java | 28 ------------------- .../farm/controller/FarmSellerController.java | 23 +++++++++++++++ .../farm/service/FarmSellerService.java | 21 ++++++++++++++ ...armManageService.java => FarmService.java} | 12 +------- 5 files changed, 65 insertions(+), 39 deletions(-) create mode 100644 src/main/java/poomasi/domain/farm/controller/FarmController.java delete mode 100644 src/main/java/poomasi/domain/farm/controller/FarmMangeController.java create mode 100644 src/main/java/poomasi/domain/farm/controller/FarmSellerController.java create mode 100644 src/main/java/poomasi/domain/farm/service/FarmSellerService.java rename src/main/java/poomasi/domain/farm/service/{FarmManageService.java => FarmService.java} (67%) diff --git a/src/main/java/poomasi/domain/farm/controller/FarmController.java b/src/main/java/poomasi/domain/farm/controller/FarmController.java new file mode 100644 index 00000000..0dc02892 --- /dev/null +++ b/src/main/java/poomasi/domain/farm/controller/FarmController.java @@ -0,0 +1,20 @@ +package poomasi.domain.farm.controller; + +import lombok.AllArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import poomasi.domain.farm.service.FarmService; + + +@RestController() +@RequestMapping("/api/farm") +@AllArgsConstructor + +public class FarmController { + private final FarmService farmService; + + @GetMapping("/{farmId}") + public ResponseEntity getFarm(@RequestParam Long farmId) { + return ResponseEntity.ok(farmService.getFarmByFarmId(farmId)); + } +} diff --git a/src/main/java/poomasi/domain/farm/controller/FarmMangeController.java b/src/main/java/poomasi/domain/farm/controller/FarmMangeController.java deleted file mode 100644 index 4271b73d..00000000 --- a/src/main/java/poomasi/domain/farm/controller/FarmMangeController.java +++ /dev/null @@ -1,28 +0,0 @@ -package poomasi.domain.farm.controller; - -import lombok.AllArgsConstructor; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; -import poomasi.domain.farm.dto.FarmRegisterRequest; -import poomasi.domain.farm.service.FarmManageService; - - -@RestController -@AllArgsConstructor -public class FarmMangeController { - private final FarmManageService farmManageService; - - @GetMapping("/api/farm/{farmId}") - public ResponseEntity getFarm(@RequestParam Long farmId) { - return ResponseEntity.ok(farmManageService.getFarmByFarmId(farmId)); - - } - - // TODO: 판매자만 접근가능하도록 인증/인가 annotation 추가 - @PostMapping("/api/farm") - public ResponseEntity registerFarm(@RequestBody FarmRegisterRequest request) { - return ResponseEntity.ok(farmManageService.registerFarm(request)); - } - - -} diff --git a/src/main/java/poomasi/domain/farm/controller/FarmSellerController.java b/src/main/java/poomasi/domain/farm/controller/FarmSellerController.java new file mode 100644 index 00000000..3a2faaa7 --- /dev/null +++ b/src/main/java/poomasi/domain/farm/controller/FarmSellerController.java @@ -0,0 +1,23 @@ +package poomasi.domain.farm.controller; + +import lombok.AllArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import poomasi.domain.farm.dto.FarmRegisterRequest; +import poomasi.domain.farm.service.FarmSellerService; + +@RestController +@RequestMapping("/api/farm/seller") +@AllArgsConstructor +public class FarmSellerController { + private final FarmSellerService farmSellerService; + + // TODO: 판매자만 접근가능하도록 인증/인가 annotation 추가 + @PostMapping("") + public ResponseEntity registerFarm(@RequestBody FarmRegisterRequest request) { + return ResponseEntity.ok(farmSellerService.registerFarm(request)); + } +} diff --git a/src/main/java/poomasi/domain/farm/service/FarmSellerService.java b/src/main/java/poomasi/domain/farm/service/FarmSellerService.java new file mode 100644 index 00000000..1a4d4a4b --- /dev/null +++ b/src/main/java/poomasi/domain/farm/service/FarmSellerService.java @@ -0,0 +1,21 @@ +package poomasi.domain.farm.service; + +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Service; +import poomasi.domain.farm.dto.FarmRegisterRequest; +import poomasi.domain.farm.repository.FarmRepository; + +@Service +@AllArgsConstructor +public class FarmSellerService { + private final FarmRepository farmRepository; + + public Long registerFarm(FarmRegisterRequest request) { + // TODO: 판매자 인가? + + // TODO: 이미 등록된 농장 인가? + + return farmRepository.save(request.toEntity()).getId(); + + } +} diff --git a/src/main/java/poomasi/domain/farm/service/FarmManageService.java b/src/main/java/poomasi/domain/farm/service/FarmService.java similarity index 67% rename from src/main/java/poomasi/domain/farm/service/FarmManageService.java rename to src/main/java/poomasi/domain/farm/service/FarmService.java index ea8ad142..fcf3eaa9 100644 --- a/src/main/java/poomasi/domain/farm/service/FarmManageService.java +++ b/src/main/java/poomasi/domain/farm/service/FarmService.java @@ -2,7 +2,6 @@ import lombok.AllArgsConstructor; import org.springframework.stereotype.Service; -import poomasi.domain.farm.dto.FarmRegisterRequest; import poomasi.domain.farm.dto.FarmResponse; import poomasi.domain.farm.repository.FarmRepository; import poomasi.global.error.BusinessError; @@ -10,18 +9,9 @@ @Service @AllArgsConstructor -public class FarmManageService { +public class FarmService { private final FarmRepository farmRepository; - public Long registerFarm(FarmRegisterRequest request) { - // TODO: 판매자 인가? - - // TODO: 이미 등록된 농장 인가? - - - return farmRepository.save(request.toEntity()).getId(); - } - public FarmResponse getFarmByFarmId(Long farmId) { return farmRepository.findById(farmId) .map(FarmResponse::fromEntity) From 7a19ae7281c32852161d111621701fea835547ee Mon Sep 17 00:00:00 2001 From: stopmin Date: Mon, 23 Sep 2024 16:31:13 +0900 Subject: [PATCH 14/24] =?UTF-8?q?refactor:=20=ED=8C=90=EB=A7=A4=EC=9E=90?= =?UTF-8?q?=20&=20=EC=9D=BC=EB=B0=98=20=EC=9C=A0=EC=A0=80=20API=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC=20-=20Seller:=20=ED=8C=90=EB=A7=A4=EC=9E=90?= =?UTF-8?q?=20#2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farm/controller/FarmController.java | 19 +++++++++++++ .../farm/controller/FarmMangeController.java | 28 ------------------- .../farm/controller/FarmSellerController.java | 23 +++++++++++++++ .../farm/service/FarmSellerService.java | 21 ++++++++++++++ ...armManageService.java => FarmService.java} | 12 +------- 5 files changed, 64 insertions(+), 39 deletions(-) create mode 100644 src/main/java/poomasi/domain/farm/controller/FarmController.java delete mode 100644 src/main/java/poomasi/domain/farm/controller/FarmMangeController.java create mode 100644 src/main/java/poomasi/domain/farm/controller/FarmSellerController.java create mode 100644 src/main/java/poomasi/domain/farm/service/FarmSellerService.java rename src/main/java/poomasi/domain/farm/service/{FarmManageService.java => FarmService.java} (67%) diff --git a/src/main/java/poomasi/domain/farm/controller/FarmController.java b/src/main/java/poomasi/domain/farm/controller/FarmController.java new file mode 100644 index 00000000..9b2ae69d --- /dev/null +++ b/src/main/java/poomasi/domain/farm/controller/FarmController.java @@ -0,0 +1,19 @@ +package poomasi.domain.farm.controller; + +import lombok.AllArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import poomasi.domain.farm.service.FarmService; + + +@RestController +@AllArgsConstructor +@RequestMapping("/api/farm") +public class FarmController { + private final FarmService farmService; + + @GetMapping("/{farmId}") + public ResponseEntity getFarm(@RequestParam Long farmId) { + return ResponseEntity.ok(farmService.getFarmByFarmId(farmId)); + } +} diff --git a/src/main/java/poomasi/domain/farm/controller/FarmMangeController.java b/src/main/java/poomasi/domain/farm/controller/FarmMangeController.java deleted file mode 100644 index 4271b73d..00000000 --- a/src/main/java/poomasi/domain/farm/controller/FarmMangeController.java +++ /dev/null @@ -1,28 +0,0 @@ -package poomasi.domain.farm.controller; - -import lombok.AllArgsConstructor; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; -import poomasi.domain.farm.dto.FarmRegisterRequest; -import poomasi.domain.farm.service.FarmManageService; - - -@RestController -@AllArgsConstructor -public class FarmMangeController { - private final FarmManageService farmManageService; - - @GetMapping("/api/farm/{farmId}") - public ResponseEntity getFarm(@RequestParam Long farmId) { - return ResponseEntity.ok(farmManageService.getFarmByFarmId(farmId)); - - } - - // TODO: 판매자만 접근가능하도록 인증/인가 annotation 추가 - @PostMapping("/api/farm") - public ResponseEntity registerFarm(@RequestBody FarmRegisterRequest request) { - return ResponseEntity.ok(farmManageService.registerFarm(request)); - } - - -} diff --git a/src/main/java/poomasi/domain/farm/controller/FarmSellerController.java b/src/main/java/poomasi/domain/farm/controller/FarmSellerController.java new file mode 100644 index 00000000..a0766572 --- /dev/null +++ b/src/main/java/poomasi/domain/farm/controller/FarmSellerController.java @@ -0,0 +1,23 @@ +package poomasi.domain.farm.controller; + +import lombok.AllArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import poomasi.domain.farm.dto.FarmRegisterRequest; +import poomasi.domain.farm.service.FarmSellerService; + +@RestController +@AllArgsConstructor +@RequestMapping("/api/farm/seller") +public class FarmSellerController { + private final FarmSellerService farmSellerService; + + // TODO: 판매자만 접근가능하도록 인증/인가 annotation 추가 + @PostMapping("") + public ResponseEntity registerFarm(@RequestBody FarmRegisterRequest request) { + return ResponseEntity.ok(farmSellerService.registerFarm(request)); + } +} diff --git a/src/main/java/poomasi/domain/farm/service/FarmSellerService.java b/src/main/java/poomasi/domain/farm/service/FarmSellerService.java new file mode 100644 index 00000000..1a4d4a4b --- /dev/null +++ b/src/main/java/poomasi/domain/farm/service/FarmSellerService.java @@ -0,0 +1,21 @@ +package poomasi.domain.farm.service; + +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Service; +import poomasi.domain.farm.dto.FarmRegisterRequest; +import poomasi.domain.farm.repository.FarmRepository; + +@Service +@AllArgsConstructor +public class FarmSellerService { + private final FarmRepository farmRepository; + + public Long registerFarm(FarmRegisterRequest request) { + // TODO: 판매자 인가? + + // TODO: 이미 등록된 농장 인가? + + return farmRepository.save(request.toEntity()).getId(); + + } +} diff --git a/src/main/java/poomasi/domain/farm/service/FarmManageService.java b/src/main/java/poomasi/domain/farm/service/FarmService.java similarity index 67% rename from src/main/java/poomasi/domain/farm/service/FarmManageService.java rename to src/main/java/poomasi/domain/farm/service/FarmService.java index ea8ad142..fcf3eaa9 100644 --- a/src/main/java/poomasi/domain/farm/service/FarmManageService.java +++ b/src/main/java/poomasi/domain/farm/service/FarmService.java @@ -2,7 +2,6 @@ import lombok.AllArgsConstructor; import org.springframework.stereotype.Service; -import poomasi.domain.farm.dto.FarmRegisterRequest; import poomasi.domain.farm.dto.FarmResponse; import poomasi.domain.farm.repository.FarmRepository; import poomasi.global.error.BusinessError; @@ -10,18 +9,9 @@ @Service @AllArgsConstructor -public class FarmManageService { +public class FarmService { private final FarmRepository farmRepository; - public Long registerFarm(FarmRegisterRequest request) { - // TODO: 판매자 인가? - - // TODO: 이미 등록된 농장 인가? - - - return farmRepository.save(request.toEntity()).getId(); - } - public FarmResponse getFarmByFarmId(Long farmId) { return farmRepository.findById(farmId) .map(FarmResponse::fromEntity) From 79659c300c11a5576a6e54a9ff9a4fcfd6b2949a Mon Sep 17 00:00:00 2001 From: stopmin Date: Wed, 25 Sep 2024 12:42:31 +0900 Subject: [PATCH 15/24] refactor: seller -> farmer #2 --- ...SellerController.java => FarmFarmerController.java} | 10 +++++----- .../{FarmSellerService.java => FarmFarmerService.java} | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) rename src/main/java/poomasi/domain/farm/controller/{FarmSellerController.java => FarmFarmerController.java} (73%) rename src/main/java/poomasi/domain/farm/service/{FarmSellerService.java => FarmFarmerService.java} (94%) diff --git a/src/main/java/poomasi/domain/farm/controller/FarmSellerController.java b/src/main/java/poomasi/domain/farm/controller/FarmFarmerController.java similarity index 73% rename from src/main/java/poomasi/domain/farm/controller/FarmSellerController.java rename to src/main/java/poomasi/domain/farm/controller/FarmFarmerController.java index a0766572..90b9cd6a 100644 --- a/src/main/java/poomasi/domain/farm/controller/FarmSellerController.java +++ b/src/main/java/poomasi/domain/farm/controller/FarmFarmerController.java @@ -7,17 +7,17 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import poomasi.domain.farm.dto.FarmRegisterRequest; -import poomasi.domain.farm.service.FarmSellerService; +import poomasi.domain.farm.service.FarmFarmerService; @RestController @AllArgsConstructor -@RequestMapping("/api/farm/seller") -public class FarmSellerController { - private final FarmSellerService farmSellerService; +@RequestMapping("/api/farm/farmer") +public class FarmFarmerController { + private final FarmFarmerService farmFarmerService; // TODO: 판매자만 접근가능하도록 인증/인가 annotation 추가 @PostMapping("") public ResponseEntity registerFarm(@RequestBody FarmRegisterRequest request) { - return ResponseEntity.ok(farmSellerService.registerFarm(request)); + return ResponseEntity.ok(farmFarmerService.registerFarm(request)); } } diff --git a/src/main/java/poomasi/domain/farm/service/FarmSellerService.java b/src/main/java/poomasi/domain/farm/service/FarmFarmerService.java similarity index 94% rename from src/main/java/poomasi/domain/farm/service/FarmSellerService.java rename to src/main/java/poomasi/domain/farm/service/FarmFarmerService.java index 1a4d4a4b..4337c23c 100644 --- a/src/main/java/poomasi/domain/farm/service/FarmSellerService.java +++ b/src/main/java/poomasi/domain/farm/service/FarmFarmerService.java @@ -7,7 +7,7 @@ @Service @AllArgsConstructor -public class FarmSellerService { +public class FarmFarmerService { private final FarmRepository farmRepository; public Long registerFarm(FarmRegisterRequest request) { From 5bfda1fcb9c7e4a8ab2a8ddd8823e581c6a4922d Mon Sep 17 00:00:00 2001 From: stopmin Date: Wed, 25 Sep 2024 12:43:00 +0900 Subject: [PATCH 16/24] =?UTF-8?q?refactor:=20endpoint=20=EC=88=98=EC=A0=95?= =?UTF-8?q?=20#2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../poomasi/domain/farm/controller/FarmFarmerController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/poomasi/domain/farm/controller/FarmFarmerController.java b/src/main/java/poomasi/domain/farm/controller/FarmFarmerController.java index 90b9cd6a..df6e1570 100644 --- a/src/main/java/poomasi/domain/farm/controller/FarmFarmerController.java +++ b/src/main/java/poomasi/domain/farm/controller/FarmFarmerController.java @@ -11,7 +11,7 @@ @RestController @AllArgsConstructor -@RequestMapping("/api/farm/farmer") +@RequestMapping("/api/farm") public class FarmFarmerController { private final FarmFarmerService farmFarmerService; From 9ebb1df2135fcde0ab6eed7165f7b51e09d0a3bf Mon Sep 17 00:00:00 2001 From: stopmin Date: Wed, 25 Sep 2024 12:44:30 +0900 Subject: [PATCH 17/24] =?UTF-8?q?chore:=20=EC=A3=BC=EC=84=9D=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0=20#2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/poomasi/domain/farm/entity/FarmStatus.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/poomasi/domain/farm/entity/FarmStatus.java b/src/main/java/poomasi/domain/farm/entity/FarmStatus.java index c309dba0..f1723a19 100644 --- a/src/main/java/poomasi/domain/farm/entity/FarmStatus.java +++ b/src/main/java/poomasi/domain/farm/entity/FarmStatus.java @@ -1,6 +1,5 @@ package poomasi.domain.farm.entity; -// TODO: 농장 상태에 대한 Enum 논의 필요 public enum FarmStatus { OPEN, CLOSE, WAITING } From 4d4020669da4ee17346d3f95ad4522aab2e7e770 Mon Sep 17 00:00:00 2001 From: stopmin Date: Wed, 25 Sep 2024 12:52:19 +0900 Subject: [PATCH 18/24] =?UTF-8?q?feat:=20=EB=86=8D=EC=9E=A5=20=EC=84=A4?= =?UTF-8?q?=EB=AA=85=20=EC=B6=94=EA=B0=80=20#2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/poomasi/domain/farm/controller/FarmController.java | 6 ++++++ .../java/poomasi/domain/farm/dto/FarmRegisterRequest.java | 1 + src/main/java/poomasi/domain/farm/entity/Farm.java | 5 ++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/poomasi/domain/farm/controller/FarmController.java b/src/main/java/poomasi/domain/farm/controller/FarmController.java index 9b2ae69d..d322a156 100644 --- a/src/main/java/poomasi/domain/farm/controller/FarmController.java +++ b/src/main/java/poomasi/domain/farm/controller/FarmController.java @@ -16,4 +16,10 @@ public class FarmController { public ResponseEntity getFarm(@RequestParam Long farmId) { return ResponseEntity.ok(farmService.getFarmByFarmId(farmId)); } + + // 농장 조회 페이지네이션 + @GetMapping("") + public ResponseEntity getFarmList(@RequestParam int page, @RequestParam int size) { + return ResponseEntity.ok(farmService.getFarmList(page, size)); + } } diff --git a/src/main/java/poomasi/domain/farm/dto/FarmRegisterRequest.java b/src/main/java/poomasi/domain/farm/dto/FarmRegisterRequest.java index 0a1b6814..2f60d40a 100644 --- a/src/main/java/poomasi/domain/farm/dto/FarmRegisterRequest.java +++ b/src/main/java/poomasi/domain/farm/dto/FarmRegisterRequest.java @@ -20,6 +20,7 @@ public Farm toEntity() { .addressDetail(addressDetail) .latitude(latitude) .longitude(longitude) + .description(description) .build(); } } diff --git a/src/main/java/poomasi/domain/farm/entity/Farm.java b/src/main/java/poomasi/domain/farm/entity/Farm.java index 64c49983..5a950101 100644 --- a/src/main/java/poomasi/domain/farm/entity/Farm.java +++ b/src/main/java/poomasi/domain/farm/entity/Farm.java @@ -29,6 +29,8 @@ public class Farm { @Column(name = "owner_id") private Long ownerId; + private String description; + private String address; // 도로명 주소 private String addressDetail; // 상세 주소 @@ -48,13 +50,14 @@ public class Farm { private LocalDateTime updatedAt = LocalDateTime.now(); @Builder - public Farm(String name, Long ownerId, String address, String addressDetail, Double latitude, Double longitude) { + public Farm(String name, Long ownerId, String address, String addressDetail, Double latitude, Double longitude, String description) { this.name = name; this.ownerId = ownerId; this.address = address; this.addressDetail = addressDetail; this.latitude = latitude; this.longitude = longitude; + this.description = description; } } From 41c65a7f03e4e2b5249906bbb4d0ec94723df48d Mon Sep 17 00:00:00 2001 From: stopmin Date: Wed, 25 Sep 2024 13:17:02 +0900 Subject: [PATCH 19/24] feat: application-secret.yml ignore #2 --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 04219c70..65b66315 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,6 @@ out/ ### Mac OS ### .DS_Store + +## applicaion-secret +application-secret.yml From 8d03b7c8951fc91d40b47fd0b6e66923d041270e Mon Sep 17 00:00:00 2001 From: stopmin Date: Wed, 25 Sep 2024 13:17:39 +0900 Subject: [PATCH 20/24] =?UTF-8?q?build:=20mysql=20=EC=A2=85=EC=86=8D?= =?UTF-8?q?=EC=84=B1=20=EC=B6=94=EA=B0=80=20-=208.0.33=20#2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 3 +++ 1 file changed, 3 insertions(+) diff --git a/build.gradle b/build.gradle index 3c9fdd2e..d951b553 100644 --- a/build.gradle +++ b/build.gradle @@ -25,6 +25,9 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-validation' + // mysql + implementation 'mysql:mysql-connector-java:8.0.33' + // Spring Security implementation 'org.springframework.security:spring-security-crypto:5.7.1' From 0093985a202377f750a2ffc6985e473d7d409c42 Mon Sep 17 00:00:00 2001 From: stopmin Date: Wed, 25 Sep 2024 13:17:58 +0900 Subject: [PATCH 21/24] =?UTF-8?q?feat:=20=EB=86=8D=EC=9E=A5=20=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20#2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../poomasi/domain/farm/controller/FarmController.java | 6 +++--- .../poomasi/domain/farm/repository/FarmRepository.java | 3 +++ .../java/poomasi/domain/farm/service/FarmService.java | 9 +++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/java/poomasi/domain/farm/controller/FarmController.java b/src/main/java/poomasi/domain/farm/controller/FarmController.java index d322a156..9f073ce0 100644 --- a/src/main/java/poomasi/domain/farm/controller/FarmController.java +++ b/src/main/java/poomasi/domain/farm/controller/FarmController.java @@ -1,6 +1,7 @@ package poomasi.domain.farm.controller; import lombok.AllArgsConstructor; +import org.springframework.data.domain.Pageable; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import poomasi.domain.farm.service.FarmService; @@ -17,9 +18,8 @@ public ResponseEntity getFarm(@RequestParam Long farmId) { return ResponseEntity.ok(farmService.getFarmByFarmId(farmId)); } - // 농장 조회 페이지네이션 @GetMapping("") - public ResponseEntity getFarmList(@RequestParam int page, @RequestParam int size) { - return ResponseEntity.ok(farmService.getFarmList(page, size)); + public ResponseEntity getFarmList(Pageable pageable) { + return ResponseEntity.ok(farmService.getFarmList(pageable)); } } diff --git a/src/main/java/poomasi/domain/farm/repository/FarmRepository.java b/src/main/java/poomasi/domain/farm/repository/FarmRepository.java index 2ed9a241..7c4c6e9b 100644 --- a/src/main/java/poomasi/domain/farm/repository/FarmRepository.java +++ b/src/main/java/poomasi/domain/farm/repository/FarmRepository.java @@ -1,9 +1,12 @@ package poomasi.domain.farm.repository; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import poomasi.domain.farm.entity.Farm; @Repository public interface FarmRepository extends JpaRepository { + Page findAll(Pageable pageable); } diff --git a/src/main/java/poomasi/domain/farm/service/FarmService.java b/src/main/java/poomasi/domain/farm/service/FarmService.java index fcf3eaa9..753a2c87 100644 --- a/src/main/java/poomasi/domain/farm/service/FarmService.java +++ b/src/main/java/poomasi/domain/farm/service/FarmService.java @@ -1,12 +1,16 @@ package poomasi.domain.farm.service; import lombok.AllArgsConstructor; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import poomasi.domain.farm.dto.FarmResponse; import poomasi.domain.farm.repository.FarmRepository; import poomasi.global.error.BusinessError; import poomasi.global.error.BusinessException; +import java.util.List; +import java.util.stream.Collectors; + @Service @AllArgsConstructor public class FarmService { @@ -19,4 +23,9 @@ public FarmResponse getFarmByFarmId(Long farmId) { } + public List getFarmList(Pageable pageable) { + return farmRepository.findAll(pageable).stream() + .map(FarmResponse::fromEntity) + .collect(Collectors.toList()); + } } From ec46e99ea5780baa83bc6b406f70e96e17eb984c Mon Sep 17 00:00:00 2001 From: stopmin Date: Wed, 25 Sep 2024 13:20:45 +0900 Subject: [PATCH 22/24] =?UTF-8?q?feat:=20=EC=98=88=EC=8B=9C=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=20=EC=82=AD=EC=A0=9C=20#2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/poomasi/global/error/BusinessError.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/poomasi/global/error/BusinessError.java b/src/main/java/poomasi/global/error/BusinessError.java index 302f2377..6b00359a 100644 --- a/src/main/java/poomasi/global/error/BusinessError.java +++ b/src/main/java/poomasi/global/error/BusinessError.java @@ -8,8 +8,6 @@ @Getter @AllArgsConstructor public enum BusinessError { - EXAMPLE_ERROR(HttpStatus.BAD_REQUEST, "에러 예시입니다."), - // Farm FARM_NOT_FOUND(HttpStatus.NOT_FOUND, "농장을 찾을 수 없습니다."), ; From bce6f4da7540d144c231580bbe7a340b00f8ee84 Mon Sep 17 00:00:00 2001 From: stopmin Date: Wed, 25 Sep 2024 14:56:20 +0900 Subject: [PATCH 23/24] =?UTF-8?q?feat:=20=EB=86=8D=EC=9E=A5=20=EC=97=85?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=8A=B8=20#2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farm/controller/FarmFarmerController.java | 9 ++++++++ .../domain/farm/dto/FarmUpdateRequest.java | 18 +++++++++++++++ .../java/poomasi/domain/farm/entity/Farm.java | 10 +++++++++ .../farm/service/FarmFarmerService.java | 22 +++++++++++++++++++ .../poomasi/global/error/BusinessError.java | 1 + 5 files changed, 60 insertions(+) create mode 100644 src/main/java/poomasi/domain/farm/dto/FarmUpdateRequest.java diff --git a/src/main/java/poomasi/domain/farm/controller/FarmFarmerController.java b/src/main/java/poomasi/domain/farm/controller/FarmFarmerController.java index df6e1570..71a3aa33 100644 --- a/src/main/java/poomasi/domain/farm/controller/FarmFarmerController.java +++ b/src/main/java/poomasi/domain/farm/controller/FarmFarmerController.java @@ -1,5 +1,6 @@ package poomasi.domain.farm.controller; +import jakarta.validation.Valid; import lombok.AllArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; @@ -7,6 +8,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import poomasi.domain.farm.dto.FarmRegisterRequest; +import poomasi.domain.farm.dto.FarmUpdateRequest; import poomasi.domain.farm.service.FarmFarmerService; @RestController @@ -20,4 +22,11 @@ public class FarmFarmerController { public ResponseEntity registerFarm(@RequestBody FarmRegisterRequest request) { return ResponseEntity.ok(farmFarmerService.registerFarm(request)); } + + @PostMapping("/update") + public ResponseEntity updateFarm(@Valid @RequestBody FarmUpdateRequest request) { + // TODO: 판매자 ID(Spring Security Context)로 대체 + Long farmerId = 1L; + return ResponseEntity.ok(farmFarmerService.updateFarm(farmerId, request)); + } } diff --git a/src/main/java/poomasi/domain/farm/dto/FarmUpdateRequest.java b/src/main/java/poomasi/domain/farm/dto/FarmUpdateRequest.java new file mode 100644 index 00000000..23e5ebbe --- /dev/null +++ b/src/main/java/poomasi/domain/farm/dto/FarmUpdateRequest.java @@ -0,0 +1,18 @@ +package poomasi.domain.farm.dto; + +import jakarta.validation.constraints.NotNull; +import poomasi.domain.farm.entity.Farm; + +public record FarmUpdateRequest( + @NotNull(message = "Farm ID는 필수 값입니다.") Long farmId, + String name, + String description, + String address, + String addressDetail, + Double latitude, + Double longitude +) { + public Farm toEntity(Farm farm) { + return farm.updateFarm(this); + } +} diff --git a/src/main/java/poomasi/domain/farm/entity/Farm.java b/src/main/java/poomasi/domain/farm/entity/Farm.java index 5a950101..e89db2bf 100644 --- a/src/main/java/poomasi/domain/farm/entity/Farm.java +++ b/src/main/java/poomasi/domain/farm/entity/Farm.java @@ -9,6 +9,7 @@ import org.hibernate.annotations.SQLDelete; import org.hibernate.annotations.SQLSelect; import org.hibernate.annotations.UpdateTimestamp; +import poomasi.domain.farm.dto.FarmUpdateRequest; import java.time.LocalDateTime; @@ -60,4 +61,13 @@ public Farm(String name, Long ownerId, String address, String addressDetail, Dou this.description = description; } + public Farm updateFarm(FarmUpdateRequest farmUpdateRequest) { + this.name = farmUpdateRequest.name(); + this.address = farmUpdateRequest.address(); + this.addressDetail = farmUpdateRequest.addressDetail(); + this.latitude = farmUpdateRequest.latitude(); + this.longitude = farmUpdateRequest.longitude(); + this.description = farmUpdateRequest.description(); + return this; + } } diff --git a/src/main/java/poomasi/domain/farm/service/FarmFarmerService.java b/src/main/java/poomasi/domain/farm/service/FarmFarmerService.java index 4337c23c..d5f144a5 100644 --- a/src/main/java/poomasi/domain/farm/service/FarmFarmerService.java +++ b/src/main/java/poomasi/domain/farm/service/FarmFarmerService.java @@ -3,7 +3,13 @@ import lombok.AllArgsConstructor; import org.springframework.stereotype.Service; import poomasi.domain.farm.dto.FarmRegisterRequest; +import poomasi.domain.farm.dto.FarmUpdateRequest; +import poomasi.domain.farm.entity.Farm; import poomasi.domain.farm.repository.FarmRepository; +import poomasi.global.error.BusinessException; + +import static poomasi.global.error.BusinessError.FARM_NOT_FOUND; +import static poomasi.global.error.BusinessError.FARM_OWNER_MISMATCH; @Service @AllArgsConstructor @@ -18,4 +24,20 @@ public Long registerFarm(FarmRegisterRequest request) { return farmRepository.save(request.toEntity()).getId(); } + + public Long updateFarm(Long farmerId, FarmUpdateRequest request) { + Farm farm = this.getFarmByFarmId(request.farmId()); + if (!farm.getOwnerId().equals(farmerId)) { + throw new BusinessException(FARM_OWNER_MISMATCH); + } + + // TODO: 변경 가능한 상태인가? + + return farmRepository.save(request.toEntity(farm)).getId(); + } + + public Farm getFarmByFarmId(Long farmId) { + return farmRepository.findById(farmId).orElseThrow(() -> new BusinessException(FARM_NOT_FOUND)); + } + } diff --git a/src/main/java/poomasi/global/error/BusinessError.java b/src/main/java/poomasi/global/error/BusinessError.java index 6b00359a..f344c4c4 100644 --- a/src/main/java/poomasi/global/error/BusinessError.java +++ b/src/main/java/poomasi/global/error/BusinessError.java @@ -10,6 +10,7 @@ public enum BusinessError { // Farm FARM_NOT_FOUND(HttpStatus.NOT_FOUND, "농장을 찾을 수 없습니다."), + FARM_OWNER_MISMATCH(HttpStatus.FORBIDDEN, "해당 농장의 소유자가 아닙니다."), ; private final HttpStatus httpStatus; From 3447bbcce417c43bf04c97357e8be2663ef0fbe1 Mon Sep 17 00:00:00 2001 From: stopmin Date: Wed, 25 Sep 2024 15:10:55 +0900 Subject: [PATCH 24/24] =?UTF-8?q?feat:=20FarmResponse=20=EC=88=98=EC=A0=95?= =?UTF-8?q?=20-=20description=20=EC=B6=94=EA=B0=80=20#2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/poomasi/domain/farm/dto/FarmResponse.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/poomasi/domain/farm/dto/FarmResponse.java b/src/main/java/poomasi/domain/farm/dto/FarmResponse.java index b349f266..74021c34 100644 --- a/src/main/java/poomasi/domain/farm/dto/FarmResponse.java +++ b/src/main/java/poomasi/domain/farm/dto/FarmResponse.java @@ -9,8 +9,9 @@ public record FarmResponse( // FIXME: 사용자 정보 추가 및 설명/전화 String address, String addressDetail, Double latitude, - Double longitude -) { + Double longitude, + String description + ) { public static FarmResponse fromEntity(Farm farm) { return new FarmResponse( farm.getId(), @@ -18,7 +19,8 @@ public static FarmResponse fromEntity(Farm farm) { farm.getAddress(), farm.getAddressDetail(), farm.getLatitude(), - farm.getLongitude() + farm.getLongitude(), + farm.getDescription() ); } }