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

Commit

Permalink
#76 #93 영업시간 구현 수정, jpa 적용 (#106)
Browse files Browse the repository at this point in the history
* root package bluedelivery로 변경

* common.authentication 패키지 정리

* user package

* api-application-domain-infra

* config -> common.config

* PasswordValidator를 controller와 같은 패키지로 이동

* test package

* (AddressService) application -> domain 으로 이동

* category package

* shop package

* businesshour package

* closingday package

* menu 패키지 정리

* api(menu) 패키지 분할

* category adapter package

* #101 @AuthenticationRequired + ArgumentResolver 이면 redis를 2번 조회하는 문제 (#102)

* fix: 한 요청내에서 @AuthenticationRequired로 인증객체를 한번 조회하면 ThreadLocal에 저장하여 재사용

* ThreadLocal을 검사하도록 수정

* refactor: business hour

* refactor: BusinessHour를 값 타입으로 변경

* (shop): mybatis mapper 제거

* #93 카테고리 mybatis -> jpa (#108)

* refactor: ShopCategoy 엔티티 추가 및 Category를 JPA로

* fix controller PathVariable error

* ShopCategoryRepository moved into domain package

* fix query typo

* jmeter script

* #96 jmeter script (#109)

* jmeter script

* util: jib 설정 추가, redis 설정 수정, docker-compose 수정 등

* util: jib 설정 추가, redis 설정 수정, docker-compose 수정 등 (#110)

* import 한줄 제거

Co-authored-by: lyh7712 <mmj2rv9@kakao.com>
  • Loading branch information
soongjamm and lyh7712 authored Aug 7, 2021
1 parent 61667ed commit bba9efc
Show file tree
Hide file tree
Showing 68 changed files with 1,415 additions and 899 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ out/

### VS Code ###
.vscode/

### Docker ###
compose/mysql/data/
16 changes: 15 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
plugins {
id 'com.google.cloud.tools.jib' version '3.1.2' // jib
id 'checkstyle' // linter
id 'org.springframework.boot' version '2.4.5'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
Expand All @@ -19,6 +20,20 @@ repositories {
mavenCentral()
}

jib {
from {
image = "adoptopenjdk/openjdk11:alpine"
}
to {
image = "kimstz0/blue-delivery"
tags = ["latest"]
}
container {
creationTime = "USE_CURRENT_TIMESTAMP"
jvmFlags = ["-Dspring.profiles.active=prod"]
}
}

checkstyle {
toolVersion = '8.42'
ignoreFailures = false // 분석결과 error가 발생하면 build 실패
Expand All @@ -32,7 +47,6 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-aop'
implementation 'org.springframework.boot:spring-boot-starter-cache'
implementation 'org.springframework.boot:spring-boot-starter-data-redis' // redis
// implementation 'org.springframework.session:spring-session-data-redis' // session redis
implementation 'redis.clients:jedis:3.6.0' // jedis
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.1.4'
Expand Down
2 changes: 2 additions & 0 deletions compose/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
MYSQL_HOST=localhost
MYSQL_ROOT_PASSWORD=password
37 changes: 21 additions & 16 deletions compose/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,41 @@ version: '3'
services: # 실행 할 컨테이너 정의
db-mysql: # docker run --name db와 같음(컨테이너)
image: mysql:8.0.25 # 사용할 이미지
command: [ '--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci' ]
volumes:
- ~/project/mysql:/var/lib/mysql
- ./mysql/conf.d:/etc/mysql/conf.d # MySQL 설정 파일 위치
- ./mysql/data:/var/lib/mysql # DB 데이터 위치
restart: always
ports:
- 3306:3306
- "3306:3306"
env_file: .env
environment:
MYSQL_ROOT_PASSWORD: password
TZ: Asia/Seoul

redis:
image: redis:6.2.4
ports:
- 6379:6379
- "6379:6379"
restart: always


nginx: # load balancer
image: nginx:1.21.0
volumes:
- ./nginx:/etc/nginx/conf.d
- ./nginx/conf.d:/etc/nginx/conf.d
ports:
- 8080:80
- "8080:80"

blue-delivery1: # app server1
image: blue-delivery:0.1
image: kimstz0/blue-delivery:latest
ports:
- 5000:8080
- "5000:8080"

blue-delivery2: # app server2
image: blue-delivery:0.1
image: kimstz0/blue-delivery:latest
ports:
- 5001:8080
- "5001:8080"

blue-delivery3: # app server3
image: blue-delivery:0.1
image: kimstz0/blue-delivery:latest
ports:
- 5002:8080

volumes:
db_data: { }
- "5002:8080"
11 changes: 11 additions & 0 deletions compose/mysql/conf.d/my.cnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[client]
default-character-set = utf8mb4

[mysql]
default-character-set = utf8mb4

[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
lower_case_table_names = 1
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
upstream appserver {
# 알고리즘을 지정하지 않으면 round-robin 기본 전략
# hash_ip(=sticky session), least_conn, 서버에 weight 지정 등 선택가능
least_conn;
server blue-delivery1:8080;
server blue-delivery2:8080;
server blue-delivery3:8080;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons
if (!(handler instanceof HandlerMethod)) {
return true;
}

if (Authentication.isAnnotated(((HandlerMethod) handler).getMethod())) {
Authentication auth = authenticationService.getAuthentication(request.getHeader(AUTHORIZATION))
.orElseThrow(() -> new ApiException(INVALID_AUTHENTICATION));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
import static com.bluedelivery.common.response.HttpResponse.response;
import static org.springframework.http.HttpStatus.*;

import java.util.NoSuchElementException;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;

import com.bluedelivery.api.authentication.AuthenticationController;
import com.bluedelivery.api.authentication.LoginRequest;
import com.bluedelivery.application.authentication.AuthenticationService;
import com.bluedelivery.common.response.ApiException;
import com.bluedelivery.common.response.ErrorCode;
import com.bluedelivery.common.response.HttpResponse;
import com.bluedelivery.domain.authentication.Authentication;

Expand All @@ -29,8 +32,13 @@ public ResponseEntity<HttpResponse<Authentication>> login(Authentication loggedI
if (loggedIn != null) {
throw new ApiException(ALREADY_LOGGED_IN);
}
Authentication authentication = authService.authenticate(dto.toParam());
return ResponseEntity.ok(response(SUCCESS, authentication));

try {
Authentication authentication = authService.authenticate(dto.toParam());
return ResponseEntity.ok(response(SUCCESS, authentication));
} catch (NoSuchElementException ex) {
throw new ApiException(USER_NOT_FOUND);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.bluedelivery.api.category;

import java.util.List;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -12,7 +10,6 @@
import org.springframework.web.bind.annotation.RequestMapping;

import com.bluedelivery.common.response.HttpResponse;
import com.bluedelivery.domain.category.Categories;

@RequestMapping("/categories")
public interface CategoryManagerController {
Expand All @@ -23,7 +20,7 @@ public interface CategoryManagerController {
* @return 카테고리 정보가 담긴 list
*/
@GetMapping
ResponseEntity<HttpResponse<List<Categories>>> getAllCategories();
ResponseEntity<HttpResponse<?>> getAllCategories();

/**
* 카테고리 추가
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.bluedelivery.common.response.ApiException;
import com.bluedelivery.common.response.ErrorCode;
import com.bluedelivery.common.response.HttpResponse;
import com.bluedelivery.domain.category.Categories;
import com.bluedelivery.domain.category.Category;

@RestController
Expand All @@ -29,7 +28,7 @@ public CategoryManagerControllerImpl(CategoryManagerService categoryManagerServi
this.categoryManagerService = categoryManagerService;
}

public ResponseEntity<HttpResponse<List<Categories>>> getAllCategories() {
public ResponseEntity<HttpResponse<?>> getAllCategories() {
List<Category> categories = categoryManagerService.getAllCategories();
return ResponseEntity.status(HttpStatus.OK).body(response(categories));
}
Expand Down
26 changes: 15 additions & 11 deletions src/main/java/com/bluedelivery/api/shop/ShopUpdateController.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,38 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import com.bluedelivery.api.shop.dto.BusinessHoursRequest;
import com.bluedelivery.common.response.HttpResponse;

@RequestMapping("/shops/{id}")
@RequestMapping("/shops/{shopId}")
public interface ShopUpdateController {

@PutMapping("/business-hours")
void updateBusinessHours(@PathVariable("id") Long id, @RequestBody @Valid UpdateBusinessHoursDto dto);
ResponseEntity<HttpResponse<?>> updateBusinessHours(
@PathVariable Long shopId, @RequestBody @Valid BusinessHoursRequest dto);

@PatchMapping("/introduce")
void editIntroduce(@PathVariable("id") Long id, @RequestBody String introduce);
void editIntroduce(@PathVariable("shopId") Long id, @RequestBody String introduce);

@PatchMapping("/phone")
void editPhoneNumber(@PathVariable("id") Long id,
void editPhoneNumber(@PathVariable("shopId") Long id,
@RequestBody @Valid EditPhoneRequest dto);

@PatchMapping("/delivery-area-guide")
void editDeliveryAreaGuid(@PathVariable("id") Long id, @RequestBody String guide);
void editDeliveryAreaGuid(@PathVariable("shopId") Long id, @RequestBody String guide);

@PatchMapping("/name")
void rename(@PathVariable("id") Long id, @RequestBody String name);
void rename(@PathVariable("shopId") Long id, @RequestBody String name);

/**
* 해당 가게의 카테고리를 입력받은 대로 업데이트
* @param shopId 가게 id
*
* @param shopId 가게 id
* @param dto 추가할 카테고리 enum name을 담은 dto
* @return
*/
@PutMapping("/categories")
ResponseEntity<HttpResponse<?>> updateCategory(@PathVariable("id") Long shopId,
ResponseEntity<HttpResponse<?>> updateCategory(@PathVariable Long shopId,
@RequestBody @Valid UpdateCategoryRequest dto);

/**
Expand All @@ -47,7 +51,7 @@ ResponseEntity<HttpResponse<?>> updateCategory(@PathVariable("id") Long shopId,
* @param closingDays 휴무일 정보
*/
@PutMapping("/closing-days")
void updateClosingDays(@PathVariable("id") Long shopId,
void updateClosingDays(@PathVariable Long shopId,
@RequestBody @Valid UpdateClosingDaysRequest closingDays);

/**
Expand All @@ -57,7 +61,7 @@ void updateClosingDays(@PathVariable("id") Long shopId,
* @param expose 가게 노출 여부
*/
@PostMapping("/expose")
void setExpose(@PathVariable("id") Long shopId, @RequestBody Boolean expose);
void setExpose(@PathVariable Long shopId, @RequestBody Boolean expose);

/**
* 영업을 일시 정지시킨다.
Expand All @@ -68,6 +72,6 @@ void updateClosingDays(@PathVariable("id") Long shopId,
* @param suspension 정지 시작 시간, 정지 기간 정보를 담고 있는 DTO
*/
@PutMapping("/suspend")
void suspendShop(@PathVariable("id") Long shopId,
void suspendShop(@PathVariable Long shopId,
@RequestBody SuspensionRequest suspension);
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
package com.bluedelivery.api.shop.adapter;

import static com.bluedelivery.common.response.HttpResponse.FAIL;
import static com.bluedelivery.common.response.HttpResponse.response;

import java.util.List;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;

import com.bluedelivery.api.shop.EditPhoneRequest;
import com.bluedelivery.api.shop.ShopUpdateController;
import com.bluedelivery.api.shop.SuspensionRequest;
import com.bluedelivery.api.shop.UpdateBusinessHoursDto;
import com.bluedelivery.api.shop.UpdateCategoryRequest;
import com.bluedelivery.api.shop.UpdateClosingDaysRequest;
import com.bluedelivery.api.shop.dto.BusinessHoursRequest;
import com.bluedelivery.application.category.CategoryNotFoundException;
import com.bluedelivery.application.shop.ShopUpdateService;
import com.bluedelivery.common.response.ApiException;
import com.bluedelivery.common.response.ErrorCode;
import com.bluedelivery.common.response.HttpResponse;
import com.bluedelivery.domain.shop.BusinessHour;

@RestController
public class ShopUpdateControllerImpl implements ShopUpdateController {
Expand All @@ -24,9 +31,13 @@ public ShopUpdateControllerImpl(ShopUpdateService updateService) {
this.updateService = updateService;
}

public void updateBusinessHours(
Long id, UpdateBusinessHoursDto dto) {
updateService.updateBusinessHour(id, dto);
public ResponseEntity<HttpResponse<?>> updateBusinessHours(Long shopId, BusinessHoursRequest dto) {
try {
List<BusinessHour> businessHours = updateService.updateBusinessHour(dto.toTarget(shopId));
return ResponseEntity.ok(response(businessHours));
} catch (IllegalArgumentException ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response(FAIL, ex.getMessage()));
}
}

public void editIntroduce(Long id, String introduce) {
Expand All @@ -48,7 +59,7 @@ public void rename(Long id, String name) {
public ResponseEntity<HttpResponse<?>> updateCategory(Long shopId, UpdateCategoryRequest dto) {
try {
updateService.updateCategory(shopId, dto);
return ResponseEntity.ok(HttpResponse.response("successfully updated"));
return ResponseEntity.ok(response("successfully updated"));
} catch (CategoryNotFoundException ex) {
throw new ApiException(ErrorCode.CATEGORY_NOT_FOUND);
}
Expand All @@ -61,7 +72,7 @@ public void updateClosingDays(Long shopId, UpdateClosingDaysRequest closingDays)
public void setExpose(Long shopId, Boolean expose) {
updateService.expose(shopId, expose);
}

public void suspendShop(Long shopId, SuspensionRequest suspension) {
updateService.suspend(shopId, suspension.toEntity());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.bluedelivery.api.shop.dto;

public enum BusinessHourDay {
EVERY_DAY, WEEKDAY, SATURDAY, SUNDAY
}
Loading

0 comments on commit bba9efc

Please sign in to comment.