Skip to content
This repository has been archived by the owner on Aug 13, 2022. It is now read-only.

Commit

Permalink
Merge pull request #12 from f-lab-edu/feature/3
Browse files Browse the repository at this point in the history
#10 Feature/3
  • Loading branch information
yyy9942 authored Oct 18, 2019
2 parents 4262310 + 1d2884b commit d8b2935
Show file tree
Hide file tree
Showing 12 changed files with 570 additions and 49 deletions.
81 changes: 77 additions & 4 deletions src/main/java/com/delfood/controller/OwnerController.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -26,13 +26,55 @@
@RequestMapping("/owners/")
@Log4j2
public class OwnerController {

@Autowired
private OwnerService ownerService;

/**
* 회원 로그인 기능 수행.
* 사장님 회원가입 메서드.
*
* @author jun
* @param ownerInfo 회원가입할 사장님 정보
*/
@PostMapping
public ResponseEntity<SignUpResponse> signUp(@RequestBody OwnerDTO ownerInfo) {
if (OwnerDTO.hasNullDataBeforeSignUp(ownerInfo)) {
throw new NullPointerException("사장님 회원가입에 필요한 정보에 NULL이 존재합니다.");
}

// id 중복체크
if (ownerService.isDuplicatedId(ownerInfo.getId())) {
return new ResponseEntity<OwnerController.SignUpResponse>(SignUpResponse.ID_DUPLICATED,
HttpStatus.CONFLICT);
}

ownerService.signUp(ownerInfo);
return new ResponseEntity<OwnerController.SignUpResponse>(SignUpResponse.SUCCESS,
HttpStatus.CREATED);
}

/**
* id 중복 체크 메서드.
*
* @author jun
* @param id 중복체크를 진행할 사장님 ID
* @return 중복된 아이디 일시 true
*/
@GetMapping("idCheck/{id}")
public ResponseEntity<IdDuplResponse> idCheck(@PathVariable("id") String id) {
boolean isDupl = ownerService.isDuplicatedId(id);
if (isDupl) {
return new ResponseEntity<OwnerController.IdDuplResponse>(IdDuplResponse.ID_DUPLICATED,
HttpStatus.CONFLICT);
} else {
return new ResponseEntity<OwnerController.IdDuplResponse>(IdDuplResponse.SUCCESS,
HttpStatus.OK);
}
}



/**
* 회원 로그인 기능 수행.
* @param loginRequest 로그인 요청 ( id, password )
* @return
*/
Expand Down Expand Up @@ -69,7 +111,7 @@ public ResponseEntity<OwnerLoginResponse> login(@RequestBody OwnerLoginRequest l
* @param session 현재 사용자 세션
* @return
*/
@PostMapping("logout")
@GetMapping("logout")
public ResponseEntity<logoutResponse> logout(HttpSession session) {
String id = (String) session.getAttribute("LOGIN_OWNER_ID");
if (id != null) {
Expand Down Expand Up @@ -223,6 +265,37 @@ private static class UpdateOwnerPasswordRequest {

// ============ resopnse 객체 =====================

@Getter
@RequiredArgsConstructor
private static class SignUpResponse {
enum SignUpStatus {
SUCCESS, ID_DUPLICATED
}

@NonNull
private SignUpStatus result;

private static final SignUpResponse SUCCESS = new SignUpResponse(SignUpStatus.SUCCESS);
private static final SignUpResponse ID_DUPLICATED =
new SignUpResponse(SignUpStatus.ID_DUPLICATED);
}

@Getter
@RequiredArgsConstructor
private static class IdDuplResponse {
enum DuplStatus {
SUCCESS, ID_DUPLICATED
}

@NonNull
private DuplStatus result;

private static final IdDuplResponse SUCCESS = new IdDuplResponse(DuplStatus.SUCCESS);
private static final IdDuplResponse ID_DUPLICATED =
new IdDuplResponse(DuplStatus.ID_DUPLICATED);
}


@Getter
@AllArgsConstructor
@RequiredArgsConstructor
Expand Down
77 changes: 77 additions & 0 deletions src/main/java/com/delfood/controller/ShopController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.delfood.controller;

import com.delfood.dto.ShopDTO;
import com.delfood.service.ShopService;
import javax.servlet.http.HttpSession;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
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;

@RestController
@RequestMapping("/owners/shops/")
@Log4j2
public class ShopController {
@Autowired
private ShopService shopService;

/**
* 입점 메서드.
*
* @author jun
* @param session 로그인한 사장님 정보를 불러오기 위한 세션
* @param shopInfo 입력받은 매장 정보
* @return
*/
@PostMapping
public ResponseEntity<OpenShopResponse> openShop(HttpSession session,
@RequestBody ShopDTO shopInfo) {
String ownerId = (String) session.getAttribute("LOGIN_OWNER_ID");

// 로그인 하지 않았을 시 401코드를 반환한다.
if (ownerId == null) {
return new ResponseEntity<ShopController.OpenShopResponse>(OpenShopResponse.NO_LOGIN,
HttpStatus.UNAUTHORIZED);
}

shopInfo.setOwnerId(ownerId);

// 입력한 데이터 중 필수 데이터가 null일 경우 400 에러코드를 반환한다.
if (ShopDTO.hasNullDataBeforeCreate(shopInfo)) {
return new ResponseEntity<ShopController.OpenShopResponse>(OpenShopResponse.NULL_ARGUMENTS,
HttpStatus.BAD_REQUEST);
}

shopService.newShop(shopInfo);


return new ResponseEntity<ShopController.OpenShopResponse>(OpenShopResponse.SUCCESS,
HttpStatus.CREATED);
}



// Response 객체
@Getter
@RequiredArgsConstructor
private static class OpenShopResponse {
enum Result {
SUCCESS, NO_LOGIN, NULL_ARGUMENTS
}

@NonNull
Result result;

private static OpenShopResponse SUCCESS = new OpenShopResponse(Result.SUCCESS);
private static OpenShopResponse NO_LOGIN = new OpenShopResponse(Result.NO_LOGIN);
private static OpenShopResponse NULL_ARGUMENTS = new OpenShopResponse(Result.NULL_ARGUMENTS);
}

}
8 changes: 2 additions & 6 deletions src/main/java/com/delfood/dto/MemberDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,9 @@ public void copyData(MemberDTO param) {
* @return
*/
public static boolean hasNullDataBeforeSignup(MemberDTO memberInfo) {
if (memberInfo.getId() == null || memberInfo.getPassword() == null
return memberInfo.getId() == null || memberInfo.getPassword() == null
|| memberInfo.getName() == null || memberInfo.getTel() == null
|| memberInfo.getMail() == null) {
return false;
}

return true;
|| memberInfo.getMail() == null;
}


Expand Down
23 changes: 23 additions & 0 deletions src/main/java/com/delfood/dto/MenuCategoryDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.delfood.dto;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Getter
@Setter
@ToString
public class MenuCategoryDTO {
// 주력 메뉴
// 한식, 분식, 카페, 일식,
// 치킨, 피자, 아시안, 양식,
// 중국집, 족발보쌈, 야식, 찜탕,
// 도시락, 패스트푸드, 프렌차이즈

// KOREAN, SCHOOL_FOOD, CAFE, JAPANESE,
// CHICKEN, PIZZA, ASIAN, WESTERN,
// CHINESE, BOSSAM, MIDNIGHT_MEAL, SOUP,
// LUNCHBOX, FAST_FOOD, FRANCHISE
private Long id;
private String name;
}
18 changes: 17 additions & 1 deletion src/main/java/com/delfood/dto/OwnerDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,23 @@ public enum Status {
private String tel;
private LocalDateTime createdAt;
private LocalDateTime updatedAt;
private Status status;
private Status status;
/**
* 회원가입 전 null 정보 체크 메서드
* @author jun
* @param ownerInfo nullCheck할 사장님 정보
* @return null이 존재할 시 true
*/
public static boolean hasNullDataBeforeSignUp(OwnerDTO ownerInfo) {
return ownerInfo.getId() == null
|| ownerInfo.getPassword() == null
|| ownerInfo.getName() == null
|| ownerInfo.getTel() == null
|| ownerInfo.getTel() == null;
}





}
124 changes: 124 additions & 0 deletions src/main/java/com/delfood/dto/ShopDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package com.delfood.dto;

import java.time.LocalDateTime;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;

@Getter
@Setter
@ToString
public class ShopDTO {

// 배달 타입. 자체배달, 라이더 매칭 배달
enum DeliveeryType {
SELF_DELIVERY, COMPANY_DELIVERY
}



enum Status {
DEFAULT, DELETED
}

// 즉시 결제, 만나서 결제
enum OrderType {
THIS_PAYMENT, MEET_PAYMENT
}

enum WorkCondition {
OPEN, CLOSE
}


// 아아디
@NonNull
private Long id;

// 가게 이름
@NonNull
private String name;

// 배달형태
@NonNull
private DeliveeryType deliveryType;

// 주력메뉴 치킨, 피자, 분식 등
@NonNull
private Long signatureMenuId;

// 가게 전화번호
private String tel;

// 우편 번호
private String zipcode;

// 주소
private String address;

// 상세주소
private String addressDetail;

// 사업자번호
@NonNull
private String bizNumber;

// 가게 소개
@NonNull
private String info;

// 최소 주문금액
@NonNull
private Long minOrderPrice;

// 안내 및 혜택
private String notice;

// 운영 시간
private String operatingTime;

// 배달지역
private String deliveryLocation;

// 사장 아이디
private String ownerId;

// 가게 등록일
private LocalDateTime createdAt;

// 최종 수정일
private LocalDateTime updatedAt;

// 상태 삭제되었을시 DELETE 평소에는 DEFAULT
private Status status;

// 주문 타입 바로결제, 전화결제 등 결정
@NonNull
private OrderType orderType;

// 원산지 정보 원산지 표기정보를 작성
private String originInfo;

// 영업 상태 OPEN, CLOSED 등
private WorkCondition workCondition;

/**
* 매장 입점 전 필수 입력 데이터가 누락된 것이 없는지 확인.
* @author jun
* @param shopInfo 매장 데이터
* @return 누락된 데이터가 있다면 true
*/
public static boolean hasNullDataBeforeCreate(ShopDTO shopInfo) {
if (shopInfo.getName() == null
|| shopInfo.getDeliveryType() == null
|| shopInfo.getSignatureMenuId() == null
|| shopInfo.getBizNumber() == null
|| shopInfo.getInfo() == null
|| shopInfo.getMinOrderPrice() == null
|| shopInfo.getOrderType() == null) {
return true;
}
return false;
}
}
5 changes: 4 additions & 1 deletion src/main/java/com/delfood/mapper/OwnerMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

@Repository
public interface OwnerMapper {

public int insertOwner(OwnerDTO ownerInfo);

public int idCheck(String id);

OwnerDTO findByIdAndPassword(String id, String password);

OwnerDTO findById(String id);
Expand Down
Loading

0 comments on commit d8b2935

Please sign in to comment.