레스토랑 관리 - 레스토랑 등록

2022. 12. 19. 01:31·혼자하는 프로젝트/배달의 민족 클론코딩

배달의 민족 앱에서 유저 등록 만큼 중요한 것이 바로 레스토랑 등록이다.

레스토랑은 가계주인이 등록 할 것이므로 일반 유저가 사용하는 부분이 아니다. 

레스토랑은 유저관리 보다 필요한 정보가 많으므로 생각할게 좀더 많은 것 같다.

 

레스토랑 등록

Model package

PostRestaurantReq

package com.example.delivery.src.restaurant.model;

import lombok.*;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class PostRestaurantReq {
    private String name;
    private String delivery_category;
    private String category;
    private int minimumCost;
    private int deliveryCost;
    private int deliveryTime;
    private String location;
    private String operatingTime;
    private String holiday;
    private String explantion;
}

한 레스토랑 마다 등록하기 위해 필요한 정보이다.

 

PostRestaurantRes

package com.example.delivery.src.restaurant.model;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@AllArgsConstructor
public class PostRestaurantRes {
    private int restaurantIdx;
}

입력에대한 결과는 레스토랑 번호만 출력하도록 만들었다.

RestaurantController

/***
     * 레스토랑 추가 API
     * [POST] /restaurants
     */
    @ResponseBody
    @PostMapping("/regist")
    public BaseResponse<PostRestaurantRes> registRestaurant(@RequestBody PostRestaurantReq postRestaurantReq){
        //레스토랑 이름이 안들어오면 에러 발생
				if(postRestaurantReq.getName() == null){
            return new BaseResponse<>(BaseResponseStatus.POST_RESTAURANTS_EMPTY_NAME);
        }
        try{
            PostRestaurantRes postRestaurantRes =  restaurantService.registRestaurant(postRestaurantReq);
            return new BaseResponse<>(postRestaurantRes);
        } catch(BaseException exception){
            return new BaseResponse<>(exception.getStatus());
        }
    }

유저를 추가하는 부분과 매우 비슷하다.레스토랑 이름이 안들어오면 에러를 발생하게 만들었다.

RestaurantService

public PostRestaurantRes registRestaurant (PostRestaurantReq postRestaurantReq) throws BaseException {
        try{
            int restaurantIdx = restaurantDao.registRestaurant(postRestaurantReq);
            return new PostRestaurantRes(restaurantIdx);
        } catch (Exception exception){
            throw new BaseException(BaseResponseStatus.DATABASE_ERROR);
        }
    }
```

RestaurantDao

public PostRestaurantRes registRestaurant (PostRestaurantReq postRestaurantReq) throws BaseException {
        try{
            int restaurantIdx = restaurantDao.registRestaurant(postRestaurantReq);
            return new PostRestaurantRes(restaurantIdx);
        } catch (Exception exception){
            throw new BaseException(BaseResponseStatus.DATABASE_ERROR);
        }
    }

실행결과

간단하게 가계를 등록하는 API를 구현해보았다.

'혼자하는 프로젝트 > 배달의 민족 클론코딩' 카테고리의 다른 글

레스토랑 관리 - 레스토랑 조회(Paging 처리)  (0) 2022.12.19
유저관리 - 회원정보 변경 및 조회  (0) 2022.12.19
유저관리 - 로그인  (0) 2022.12.16
유저 관리 - 회원 가입  (0) 2022.12.14
유저 관리 - 준비 단계  (0) 2022.12.14
'혼자하는 프로젝트/배달의 민족 클론코딩' 카테고리의 다른 글
  • 레스토랑 관리 - 레스토랑 조회(Paging 처리)
  • 유저관리 - 회원정보 변경 및 조회
  • 유저관리 - 로그인
  • 유저 관리 - 회원 가입
인프라 감자
인프라 감자
  • 인프라 감자
    삶은 인프라
    인프라 감자
  • 전체
    오늘
    어제
    • 분류 전체보기 (243)
      • 클라우드&인프라 (28)
        • 인프라 공부 (4)
        • AWS 구조와 서비스 (18)
        • 클라우드 공부 (4)
        • Terraform (2)
      • AWS Cloud School (13)
        • project (5)
        • Linux, Network (6)
        • Docker (2)
      • BackEnd (162)
        • JAVA 공부 (15)
        • 알고리즘 공부 (71)
        • MySQL 문제 풀기 (8)
        • 스프링 핵심 원리 - 기본편 (18)
        • 스프링 MVC 1편 (4)
        • 자바 ORM 표준 JPA 프로그래밍 (21)
        • 실전! 스프링 부트와 JPA 활용1 (8)
        • 실전! 스프링 부트와 JPA 활용2 (5)
        • 스프링 데이터 JPA (8)
        • Querydsl (4)
      • 혼자하는 프로젝트 (32)
        • 배달의 민족 클론코딩 (7)
        • 나만의 프로젝트 (10)
        • 스프링 부트로 구현한 웹 (15)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

    • Email
    • GitHub
  • 공지사항

  • 인기 글

  • 태그

    정렬
    이것이 자바다
    완전탐색
    VPN
    linux
    dp
    자동 배포
    쿼드 압축
    조합
    스프링 핵심 원리-기본편
    백트래킹
    다이나믹 프로그래밍
    디팬스 게임
    querydsl
    중첩 선언
    상속
    프로그래머스
    자바
    네트워크 기본 용어
    유니온 파인드
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
인프라 감자
레스토랑 관리 - 레스토랑 등록
상단으로

티스토리툴바