Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
DB_URL=jdbc:mysql://localhost:3306/settleflow?serverTimezone=Asia/Seoul&characterEncoding=UTF-8
DB_USERNAME=settleflow
DB_PASSWORD=

MYSQL_DATABASE=settleflow
MYSQL_USER=settleflow
MYSQL_PASSWORD=
MYSQL_ROOT_PASSWORD=
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,8 @@ out/

### VS Code ###
.vscode/

### Local environment ###
.env
.env.*
!.env.example
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.kafka:spring-kafka'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.17'
runtimeOnly 'com.mysql:mysql-connector-j'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.kafka:spring-kafka-test'
Expand Down
8 changes: 4 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ services:
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: settleflow
MYSQL_USER:
MYSQL_PASSWORD:
MYSQL_ROOT_PASSWORD:
MYSQL_DATABASE: ${MYSQL_DATABASE:-settleflow}
MYSQL_USER: ${MYSQL_USER:-settleflow}
MYSQL_PASSWORD: ${MYSQL_PASSWORD:?MYSQL_PASSWORD is required}
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:?MYSQL_ROOT_PASSWORD is required}
TZ: Asia/Seoul
command:
- --character-set-server=utf8mb4
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.example.settleflowbackend.menu.domain;

public enum MenuStatus {
/**
* 판매가능
*/
ACTIVE,
/**
* 판매불가능
*/
INACTIVE
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.example.settleflowbackend.store.controller;

import jakarta.validation.Valid;
import org.example.settleflowbackend.store.dto.StoreCreateRequest;
import org.example.settleflowbackend.store.dto.StoreResponse;
import org.example.settleflowbackend.store.service.StoreService;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/stores")
public class StoreController {
private final StoreService storeService;

public StoreController(StoreService storeService) {
this.storeService = storeService;
}

/**
* @param storeCreateRequest
* @return
* @RequestBody: HTTP 요청 body에 있는 JSON을 Java 객체로 변환해라.
* @Valid: Request DTO에 붙은 Bean Validation 어노테이션을 검사해라.
*/
@PostMapping
@ResponseStatus(HttpStatus.CREATED) // 생성 API에서는 보통 201 created 가 적합
public StoreResponse createStore(@RequestBody @Valid StoreCreateRequest storeCreateRequest) {
return storeService.createStore(storeCreateRequest);
}

@GetMapping("/{storeId}")
public StoreResponse getStore(@PathVariable Long storeId) {
return storeService.getStore(storeId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.example.settleflowbackend.store.service;


import org.example.settleflowbackend.store.domain.Store;
import org.example.settleflowbackend.store.dto.StoreCreateRequest;
import org.example.settleflowbackend.store.dto.StoreResponse;
import org.example.settleflowbackend.store.repository.StoreRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class StoreService {

private final StoreRepository storeRepository;

public StoreService(StoreRepository storeRepository) {
this.storeRepository = storeRepository;
}

@Transactional
public StoreResponse createStore(StoreCreateRequest storeCreateRequest) {
Store savedStore = storeRepository.save(Store.create(storeCreateRequest.name()));
return StoreResponse.from(savedStore);
}

@Transactional(readOnly = true)
public StoreResponse getStore(Long storeId) {
Store store = storeRepository.findById(storeId).orElseThrow(() -> new IllegalArgumentException("상점이 존재하지 않습니다. storeId=" + storeId));
return StoreResponse.from(store);

}
}
9 changes: 6 additions & 3 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ server:
port: 8080

spring:
config:
import: optional:file:.env[.properties]

application:
name: settleflow-backend

datasource:
url: jdbc:mysql://localhost:3306/settleflow?serverTimezone=Asia/Seoul&characterEncoding=UTF-8
username:
password:
url: ${DB_URL:jdbc:mysql://localhost:3306/settleflow?serverTimezone=Asia/Seoul&characterEncoding=UTF-8}
username: ${DB_USERNAME:settleflow}
password: ${DB_PASSWORD:}
driver-class-name: com.mysql.cj.jdbc.Driver

jpa:
Expand Down