-
Notifications
You must be signed in to change notification settings - Fork 17
7주차 미션 / 서버 1조 정연석 #8
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package com.kuit.baemin.controller; | ||
|
|
||
| import com.kuit.baemin.common.dto.ApiResponse; | ||
| import com.kuit.baemin.dto.request.CreateAddressReq; | ||
| import com.kuit.baemin.dto.request.UpdateAddressReq; | ||
| import com.kuit.baemin.dto.response.AddressListRes; | ||
| import com.kuit.baemin.dto.response.AddressRes; | ||
| import com.kuit.baemin.dto.response.DefaultAddressRes; | ||
| import com.kuit.baemin.dto.response.DeleteAddressRes; | ||
| import com.kuit.baemin.service.AddressService; | ||
| import jakarta.validation.Valid; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| public class AddressController { | ||
| private final AddressService addressService; | ||
|
|
||
| @PostMapping("/users/{userId}/addresses") | ||
| public ApiResponse<AddressRes> createAddress( | ||
| @PathVariable Long userId, | ||
| @Valid @RequestBody CreateAddressReq req | ||
| ){ | ||
| return ApiResponse.of(addressService.createAddress(userId, req)); | ||
| } | ||
| @GetMapping("/users/{userId}/addresses") | ||
| public ApiResponse<AddressListRes> getAddresses( | ||
| @PathVariable Long userId | ||
| ){ | ||
| return ApiResponse.of(addressService.getAddresses(userId)); | ||
| } | ||
| @PatchMapping("/addresses/{addressId}") | ||
| public ApiResponse<AddressRes>updateAddress( | ||
| @PathVariable Long addressId, | ||
| @Valid @RequestBody UpdateAddressReq req | ||
| ){ | ||
| return ApiResponse.of(addressService.updateAddress(addressId, req)); | ||
| } | ||
| @DeleteMapping("/addresses/{addressId}") | ||
| public ApiResponse<DeleteAddressRes> deleteAddress( | ||
| @PathVariable Long addressId | ||
| ){ | ||
| return ApiResponse.of(addressService.deleteAddress(addressId)); | ||
| } | ||
| @PatchMapping("/addresses/{addressId}/default") | ||
| public ApiResponse<DefaultAddressRes> changeDefaultAddress( | ||
| @PathVariable Long addressId | ||
| ){ | ||
| return ApiResponse.of(addressService.changeDefaultAddress((addressId))); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package com.kuit.baemin.controller; | ||
|
|
||
| import com.kuit.baemin.common.dto.ApiResponse; | ||
| import com.kuit.baemin.dto.response.MenuListRes; | ||
| import com.kuit.baemin.service.MenuService; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| public class MenuController { | ||
| private final MenuService menuService; | ||
|
|
||
| @GetMapping("/stores/{storeId}/menus") | ||
| public ApiResponse<MenuListRes> getMenus( | ||
| @PathVariable Long storeId | ||
| ){ | ||
| return ApiResponse.of(menuService.getMenus(storeId)); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package com.kuit.baemin.controller; | ||
|
|
||
| import com.kuit.baemin.common.dto.ApiResponse; | ||
| import com.kuit.baemin.dto.request.CreateOrderReq; | ||
| import com.kuit.baemin.dto.response.CreateOrderRes; | ||
| import com.kuit.baemin.service.OrderService; | ||
| import jakarta.validation.Valid; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| public class OrderController { | ||
| private final OrderService orderService; | ||
|
|
||
| @PostMapping("/orders") | ||
| public ApiResponse<CreateOrderRes> createOrder( | ||
| @Valid @RequestBody CreateOrderReq req | ||
| ) { | ||
| return ApiResponse.of(orderService.createOrder(req)); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package com.kuit.baemin.controller; | ||
|
|
||
| import com.kuit.baemin.common.dto.ApiResponse; | ||
| import com.kuit.baemin.dto.response.RestaurantListRes; | ||
| import com.kuit.baemin.service.RestaurantService; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.data.domain.Pageable; | ||
| import org.springframework.data.web.PageableDefault; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| public class RestaurantController { | ||
| private final RestaurantService RestaurantService; | ||
|
|
||
| @GetMapping("/stores") | ||
| public ApiResponse<RestaurantListRes> getStores( | ||
| @PageableDefault(size=10) Pageable pageable | ||
| ){ | ||
| return ApiResponse.of(RestaurantService.getStores(pageable)); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,20 +4,22 @@ | |
| import jakarta.persistence.*; | ||
| import lombok.*; | ||
|
|
||
| import java.math.BigDecimal; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| // TODO: 본인이 설계한 ERD에 맞게 수정 | ||
| @Entity | ||
| @Getter | ||
| @Builder | ||
| @Table(name = "restaurants") | ||
| @Table(name = "stores") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 테이블명 변경에 대한 DB 마이그레이션이 필요합니다.
As per coding guidelines 🤖 Prompt for AI Agents |
||
| @AllArgsConstructor | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| public class Restaurant extends BaseEntity { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| @Column(name = "store_id") | ||
| private Long id; | ||
|
|
||
| @Column(nullable = false, length = 100) | ||
|
|
@@ -26,8 +28,35 @@ public class Restaurant extends BaseEntity { | |
| @Column(nullable = false, length = 200) | ||
| private String address; | ||
|
|
||
| @Column(name = "category", length = 50, nullable = false) | ||
| private String category; | ||
|
|
||
| @Column(name = "phone", length = 20, nullable = false) | ||
| private String phone; | ||
|
|
||
| @Column(name = "min_order_price", nullable = false) | ||
| private Integer minOrderPrice = 0; | ||
|
|
||
| @Column(name = "delivery_fee", nullable = false) | ||
| private Integer deliveryFee = 0; | ||
|
Comment on lines
+37
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 금액 필드의 음수 방지 제약을 명시해 주세요.
As per coding guidelines 🤖 Prompt for AI Agents |
||
|
|
||
| @Column(name = "rating", precision = 2, scale = 1, nullable = false) | ||
| private BigDecimal rating; | ||
|
|
||
| @Column(name = "is_open", nullable = false) | ||
| private Boolean isOpen; | ||
|
|
||
| @Column(name = "latitude", precision = 10, scale = 7, nullable = false) | ||
| private BigDecimal latitude; | ||
|
|
||
| @Column(name="description", length = 255) | ||
| private String description; | ||
|
|
||
| @Column(name = "longitude", precision = 10, scale = 7, nullable = false) | ||
| private BigDecimal longitude; | ||
|
|
||
| @Enumerated(EnumType.STRING) | ||
| @Column(nullable = false, length = 10) | ||
| private RestaurantStatus status; | ||
| private RestaurantStatus status = RestaurantStatus.ACTIVE; | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,100 @@ | ||||||||||
| package com.kuit.baemin.domain.address; | ||||||||||
|
|
||||||||||
| import com.kuit.baemin.domain.BaseEntity; | ||||||||||
| import com.kuit.baemin.domain.member.Member; | ||||||||||
| import jakarta.persistence.*; | ||||||||||
| import lombok.AccessLevel; | ||||||||||
| import lombok.Builder; | ||||||||||
| import lombok.Getter; | ||||||||||
| import lombok.NoArgsConstructor; | ||||||||||
|
|
||||||||||
| @Getter | ||||||||||
| @Entity | ||||||||||
| @Table(name="addresses") | ||||||||||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||||||||||
| public class Address extends BaseEntity { | ||||||||||
|
|
||||||||||
| @Id | ||||||||||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||||||||||
| @Column(name = "address_id") | ||||||||||
| private Long id; | ||||||||||
|
|
||||||||||
| @Column(name="address_name", length =50) | ||||||||||
| private String addressName; | ||||||||||
|
|
||||||||||
| @Column(name = "address", length = 255, nullable = false) | ||||||||||
| private String address; | ||||||||||
|
|
||||||||||
| @Column(name = "is_default", nullable = false) | ||||||||||
| private Boolean isDefault; | ||||||||||
|
|
||||||||||
| @Column(name = "latitude", nullable = false) | ||||||||||
| private Double latitude; | ||||||||||
|
|
||||||||||
| @Column(name = "longitude", nullable = false) | ||||||||||
| private Double longitude; | ||||||||||
|
|
||||||||||
| @Enumerated(EnumType.STRING) | ||||||||||
| @Column(name = "status", length = 20, nullable = false) | ||||||||||
| private AddressStatus status; | ||||||||||
|
|
||||||||||
| @ManyToOne(fetch = FetchType.LAZY) | ||||||||||
| @JoinColumn(name = "user_id", nullable = false) | ||||||||||
| private Member member; | ||||||||||
|
|
||||||||||
| @Builder | ||||||||||
| public Address( | ||||||||||
| String addressName, | ||||||||||
| String address, | ||||||||||
| Boolean isDefault, | ||||||||||
| Double latitude, | ||||||||||
| Double longitude, | ||||||||||
| Member member | ||||||||||
| ){ | ||||||||||
| this.addressName = addressName; | ||||||||||
| this.address = address; | ||||||||||
| this.isDefault = isDefault !=null ? isDefault:false; | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 띄어쓰기를 수정하세요. 연산자 양쪽에 공백이 필요합니다. ✏️ 수정 제안- this.isDefault = isDefault !=null ? isDefault:false;
+ this.isDefault = isDefault != null ? isDefault : false;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||
| this. latitude = latitude; | ||||||||||
| this. longitude = longitude; | ||||||||||
|
Comment on lines
+57
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 불필요한 공백을 제거하세요.
✏️ 수정 제안- this. latitude = latitude;
- this. longitude = longitude;
+ this.latitude = latitude;
+ this.longitude = longitude;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||
| this.member = member; | ||||||||||
| this.status = AddressStatus.ACTIVE; | ||||||||||
| } | ||||||||||
| public void updateInfo( | ||||||||||
| String address, | ||||||||||
| String addressName, | ||||||||||
| Boolean isDefault, | ||||||||||
| Double latitude, | ||||||||||
| Double longitude | ||||||||||
| ){ | ||||||||||
| if(addressName!=null){ | ||||||||||
| this.addressName = addressName; | ||||||||||
| } | ||||||||||
| if(address!=null){ | ||||||||||
| this.address = address; | ||||||||||
| } | ||||||||||
| if(isDefault!=null){ | ||||||||||
| this.isDefault = isDefault; | ||||||||||
| } | ||||||||||
| if(latitude !=null){ | ||||||||||
| this.latitude = latitude; | ||||||||||
| } | ||||||||||
| if(longitude!=null) { | ||||||||||
| this.longitude = longitude; | ||||||||||
| } | ||||||||||
| } | ||||||||||
| public boolean isDeleted(){ | ||||||||||
| return this.status == AddressStatus.DELETED; | ||||||||||
| } | ||||||||||
| public void delete(){ | ||||||||||
| this.status = AddressStatus.DELETED; | ||||||||||
| } | ||||||||||
| public void setDefault(){ | ||||||||||
| this.isDefault = true; | ||||||||||
| } | ||||||||||
| public void unsetDefault(){ | ||||||||||
| this.isDefault = false; | ||||||||||
| } | ||||||||||
| public boolean isAlreadyDefault(){ | ||||||||||
| return Boolean.TRUE.equals(this.isDefault); | ||||||||||
| } | ||||||||||
| } | ||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package com.kuit.baemin.domain.address; | ||
|
|
||
| public enum AddressStatus { | ||
| ACTIVE, | ||
| DELETED | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,7 +8,7 @@ | |||||||||||||
| @Entity | ||||||||||||||
| @Getter | ||||||||||||||
| @Builder | ||||||||||||||
| @Table(name = "members") | ||||||||||||||
| @Table(name = "users") | ||||||||||||||
| @AllArgsConstructor | ||||||||||||||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||||||||||||||
| public class Member extends BaseEntity { | ||||||||||||||
|
|
@@ -17,23 +17,41 @@ public class Member extends BaseEntity { | |||||||||||||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||||||||||||||
| private Long id; | ||||||||||||||
|
|
||||||||||||||
| @Column(nullable = false, length = 50) | ||||||||||||||
| @Column(nullable = false, length = 100) | ||||||||||||||
| private String email; | ||||||||||||||
|
|
||||||||||||||
| @Column(nullable = false, length = 200) | ||||||||||||||
| @Column(nullable = false, length = 255) | ||||||||||||||
| private String password; | ||||||||||||||
|
|
||||||||||||||
| @Column(nullable = false, length = 20) | ||||||||||||||
| private String phoneNumber; | ||||||||||||||
| private String phone; | ||||||||||||||
|
|
||||||||||||||
| @Column(length = 25) | ||||||||||||||
| @Column(length = 50) | ||||||||||||||
| private String nickname; | ||||||||||||||
|
|
||||||||||||||
| @Column(length = 300) | ||||||||||||||
| private String profileImage; | ||||||||||||||
| @Column(length = 50) | ||||||||||||||
| private String name; | ||||||||||||||
|
|
||||||||||||||
| @Enumerated(EnumType.STRING) | ||||||||||||||
| @Column(nullable = false, length = 10) | ||||||||||||||
| @Column(nullable = false, length = 20) | ||||||||||||||
| private MemberStatus status; | ||||||||||||||
|
|
||||||||||||||
| public void updateInfo(String name, String nickname, String phone){ | ||||||||||||||
| if(name != null){ | ||||||||||||||
| this.name = name; | ||||||||||||||
| } | ||||||||||||||
| if(name != null){ | ||||||||||||||
| this.nickname = nickname; | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+43
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 닉네임 갱신 조건이 잘못되어 부분 수정이 깨집니다.
수정 제안- if(name != null){
+ if(nickname != null){
this.nickname = nickname;
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
| if(phone!=null){ | ||||||||||||||
| this.phone = phone; | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| public void delete(){ | ||||||||||||||
| this.status = MemberStatus.DELETED; | ||||||||||||||
| } | ||||||||||||||
| public boolean isDeleted(){ | ||||||||||||||
| return this.status == MemberStatus.DELETED; | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
페이지 크기 상한을 강제해 주세요.
현재는 클라이언트가 매우 큰
size를 전달할 수 있어 대량 조회로 성능 저하/타임아웃 위험이 있습니다.spring.data.web.pageable.max-page-size설정 또는 서비스 단 검증으로 상한을 두는 것이 필요합니다.🤖 Prompt for AI Agents