Skip to content

Commit

Permalink
/
Browse files Browse the repository at this point in the history
  • Loading branch information
djdongjae committed Aug 5, 2024
2 parents 6d8bfe8 + 1929c47 commit e0c8796
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 40 deletions.
149 changes: 148 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,148 @@
# Back-End
# Tasty-Inventory: Back-End

### 1. ๊ฐœ์š”

---

#### 1.1. ์†Œ๊ฐœ

์‰ฝ๊ณ  ๊ฐ„ํŽธํ•œ ์žฌ๊ณ  ๊ด€๋ฆฌ, ๋ง›์žˆ๋Š” ์žฌ๊ณ ์™€ ํ•จ๊ป˜ ์‹œ์ž‘ํ•ด์š”! - [๋ฐ”๋กœ๊ฐ€๊ธฐ](https://tasty-inventory-fe.vercel.app/)

* โœ… **์ œ์ž‘ ์˜๋„**: ๋งค์ผ ์—‘์…€ ํŒŒ์ผ์— ์ •๋ฆฌํ–ˆ๋˜ ์žฌ๊ณ ๋ฅผ ๋ง›์žˆ๋Š” ์žฌ๊ณ ์—์„œ ๊ฐ„ํŽธํ•˜๊ฒŒ ์ž…๋ ฅํ•˜๊ณ , ๋‚จ์€ ์ˆ˜๋Ÿ‰์„ ์˜ˆ์ธกํ•  ์ˆ˜ ์žˆ์–ด์š”.

#### 1.2. ๊ธฐ์ˆ  ์Šคํƒ


| Category | Used |
| --- | --- |
| Java version | Java 17 |
| Spring version | 3.2.4 |
| Cloud Computing | AWS EC2 (Ubuntu 22.04 LTS) |
| Database | AWS RDS (Mariadb 10.6.18) |
| File Upload | AWS S3 |
| CI/CD | Github Actions, S3, CodeDeploy, Nginx |
| Monitoring | Sentry, Slack |
| API Docs | Swagger, Notion |

### 2. ์‹คํ–‰๋ฐฉ๋ฒ•

---

#### 2.1. Config

* `application.yml` ํŒŒ์ผ `Tasty-Inventory_BE/src/main/resources` ๋””๋ ‰ํ† ๋ฆฌ์— ์œ„์น˜

<br>

![alt text](<./image/Screenshot 2024-06-19 at 10.59.19โ€ฏAM.png>)

<br>

* `build.gradle`์—์„œ ๋กœ์ปฌ ์ปดํ“จํ„ฐ์— ์„ค์น˜๋œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ข…๋ฅ˜ ์ถ”๊ฐ€

<br>

![alt text](<./image/Screenshot 2024-06-19 at 11.04.16โ€ฏAM.png>)

* `application.yml` ํŒŒ์ผ์—์„œ DB ์„ค์ • ์ •๋ณด ๋ณ€๊ฒฝ

<br>

![alt text](<./image/Screenshot 2024-06-19 at 11.07.15โ€ฏAM.png>)

<br>

#### 2.2. Project Build

```shell
chmod a+x gradlew
./gradlew clean build -x test
```

#### 2.3. Run jar

```shell
cd ./build/libs
java -jar Tasty-Inventory_BE-0.0.1-SNAPSHOT.jar &
```


### 3. ๐Ÿค Code Convention

---

#### 3.1 โœ“ File Naming
- ํŒŒ์ผ ์ด๋ฆ„ ๋ฐ ํด๋ž˜์Šค, ์ธํ„ฐํŽ˜์ด์Šค ์ด๋ฆ„: **ํŒŒ์Šค์นผ ์ผ€์ด์Šค(Pascal Case)**
- Entity์—์„œ ์‚ฌ์šฉ๋˜๋Š” ์†์„ฑ๊ฐ’๋“ค์€ ? **์นด๋ฉœ ์ผ€์ด์Šค(camel Case)**
- ๋‚ด๋ถ€์—์„œ ์‚ฌ์šฉ๋˜๋Š” ํ•จ์ˆ˜ ๋ฐ ๊ธฐํƒ€ ์‚ฌ์šฉ: **์นด๋ฉœ ์ผ€์ด์Šค(camelCase)**

#### 3.2 โœ“ ์ธํ„ฐํŽ˜์ด์Šค ์ด๋ฆ„์— ๋ช…์‚ฌ/ํ˜•์šฉ์‚ฌ ์‚ฌ์šฉ [interface-noun-adj]
์ธํ„ฐํŽ˜์ด์Šค(interface)์˜ ์ด๋ฆ„์€ ๋ช…์‚ฌ/๋ช…์‚ฌ์ ˆ๋กœ ํ˜น์€ ํ˜•์šฉ์‚ฌ/ํ˜•์šฉ์‚ฌ์ ˆ๋กœ ์ง“๋Š”๋‹ค.

#### 3.3 โœ“ ํด๋ž˜์Šค ์ด๋ฆ„์— ๋ช…์‚ฌ ์‚ฌ์šฉ [class-noun]

ํด๋ž˜์Šค ์ด๋ฆ„์€ ๋ช…์‚ฌ๋‚˜ ๋ช…์‚ฌ์ ˆ๋กœ ์ง“๋Š”๋‹ค.

#### 3.4 โœ“ ๋ฉ”์„œ๋“œ ์ด๋ฆ„์€ ๋™์‚ฌ/์ „์น˜์‚ฌ๋กœ ์‹œ์ž‘ [method-verb-preposition]

๋ฉ”์„œ๋“œ๋ช…์€ ๊ธฐ๋ณธ์ ์œผ๋กœ ๋™์‚ฌ๋กœ ์‹œ์ž‘ํ•œ๋‹ค.

๋‹ค๋ฅธ ํƒ€์ž…์œผ๋กœ ์ „ํ™˜ํ•˜๋Š” ๋ฉ”์„œ๋“œ๋‚˜ ๋นŒ๋” ํŒจํ„ด์„ ๊ตฌํ˜„ํ•œ ํด๋ž˜์Šค์˜ ๋ฉ”์„œ๋“œ์—์„œ๋Š” ์ „์น˜์‚ฌ๋ฅผ ์“ธ ์ˆ˜ ์žˆ๋‹ค.

#### 3.5 โœ“ ์ƒ์ˆ˜๋Š” ๋Œ€๋ฌธ์ž์™€ ์–ธ๋”์Šค์ฝ”์–ด๋กœ ๊ตฌ์„ฑ[constant_uppercase]

"static final"๋กœ ์„ ์–ธ๋˜์–ด ์žˆ๋Š” ํ•„๋“œ์ผ ๋•Œ ์ƒ์ˆ˜๋กœ ๊ฐ„์ฃผํ•œ๋‹ค.

์ƒ์ˆ˜ ์ด๋ฆ„์€ ๋Œ€๋ฌธ์ž๋กœ ์ž‘์„ฑํ•˜๋ฉฐ, ๋ณตํ•ฉ์–ด๋Š” ์–ธ๋”์Šค์ฝ”์–ด'_'๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋‹จ์–ด๋ฅผ ๊ตฌ๋ถ„ํ•œ๋‹ค.

#### 3.6 โœ“ ๋ณ€์ˆ˜์— ์†Œ๋ฌธ์ž ์นด๋ฉœํ‘œ๊ธฐ๋ฒ• ์ ์šฉ [var-lower-camelcase]

์ƒ์ˆ˜๊ฐ€ ์•„๋‹Œ ํด๋ž˜์Šค์˜ ๋ฉค๋ฒ„๋ณ€์ˆ˜/์ง€์—ญ๋ณ€์ˆ˜/๋ฉ”์„œ๋“œ ํŒŒ๋ผ๋ฏธํ„ฐ์—๋Š” ์†Œ๋ฌธ์ž ์นด๋ฉœํ‘œ๊ธฐ๋ฒ•(Lower camel case)์„ ์‚ฌ์šฉํ•œ๋‹ค.

#### 3.7 โœ“ ์ž„์‹œ ๋ณ€์ˆ˜ ์™ธ์—๋Š” 1 ๊ธ€์ž ์ด๋ฆ„ ์‚ฌ์šฉ ๊ธˆ์ง€ [avoid-1-char-var]

๋ฉ”์„œ๋“œ ๋ธ”๋Ÿญ ๋ฒ”์œ„ ์ด์ƒ์˜ ์ƒ๋ช… ์ฃผ๊ธฐ๋ฅผ ๊ฐ€์ง€๋Š” ๋ณ€์ˆ˜์—๋Š” 1๊ธ€์ž๋กœ ๋œ ์ด๋ฆ„์„ ์“ฐ์ง€ ์•Š๋Š”๋‹ค.

**๋ฐ˜๋ณต๋ฌธ์˜ ์ธ๋ฑ์Šค๋‚˜ ๋žŒ๋‹ค ํ‘œํ˜„์‹์˜ ํŒŒ๋ผ๋ฏธํ„ฐ ๋“ฑ ์งง์€ ๋ฒ”์œ„์˜ ์ž„์‹œ ๋ณ€์ˆ˜**์—๋Š” ๊ด€๋ก€์ ์œผ๋กœ 1๊ธ€์ž ๋ณ€์ˆ˜๋ช…์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.
<br><br>

### 4. ๐Ÿค Git Convention

---


#### 4.1 Issue

๋ชจ๋“  ์ž‘์—…์˜ ๋‹จ์œ„๋Š” github์— ์ƒ์„ฑ๋œ Issue๋ฅผ ๊ธฐ์ค€์œผ๋กœ ํ•ฉ๋‹ˆ๋‹ค.

Issue์˜ ๋ณผ๋ฅจ์€ ์ตœ์†Œ ํ•˜๋‚˜์˜ ๊ธฐ๋Šฅ์œผ๋กœ ํ•ฉ๋‹ˆ๋‹ค.

ํ•˜๋‚˜์˜ ์ด์Šˆ๋ฅผ ๋งˆ๋ฌด๋ฆฌํ•˜๊ธฐ ์ „์—๋Š” ํŠน๋ณ„ํ•œ ์ƒํ™ฉ์ด ์•„๋‹Œ ์ด์ƒ ๋‹ค๋ฅธ ์ž‘์—…์— ๋Œ€ํ•œ ์ด์Šˆ๋ฅผ ์ƒ์„ฑํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

#### 4.2 PR (Pull Request)

Issue โ‰ค PR

ํ•˜๋‚˜์˜ ์ด์Šˆ์— ๋Œ€ํ•ด์„œ ๋ฐ˜๋“œ์‹œ ํ•˜๋‚˜์˜ PR์ด ์—ด๋ ค์•ผํ•˜๋Š” ๊ฑด ์•„๋‹™๋‹ˆ๋‹ค.

์›ํ™œํ•œ ์ฝ”๋“œ๋ฆฌ๋ทฐ์™€ ๋ฆฌ๋ทฐ์— ๋Œ€ํ•œ ๋‚ด์šฉ์„ ๋ฐ˜์˜ํ•˜๊ธฐ ์œ„ํ•ด์„œ PR์€ 3๊ฐœ์˜ commit์„ ๋„˜์–ด๊ฐ€์ง€ ์•Š์•„์•ผํ•ฉ๋‹ˆ๋‹ค.

ํ•˜๋‚˜์˜ PR์— 3๊ฐœ ์ด์ƒ์˜ File Change๋Š” ์ง€์–‘ํ•ฉ๋‹ˆ๋‹ค.


### 5. Commit

---

| ์ปค๋ฐ‹ ๊ตฌ๋ถ„ | ์„ค๋ช… |
| --- | --- |
| Feature | (Feature) ๊ฐœ์„  ๋˜๋Š” ๊ธฐ๋Šฅ ์ถ”๊ฐ€ |
| Bug | (Bug Fix) ๋ฒ„๊ทธ ์ˆ˜์ • |
| Doc | (Documentation) ๋ฌธ์„œ ์ž‘์—… |
| Test | (Test) ํ…Œ์ŠคํŠธ ์ถ”๊ฐ€/์ˆ˜์ • |
| Build | (Build) ๋นŒ๋“œ ํ”„๋กœ์„ธ์Šค ๊ด€๋ จ ์ˆ˜์ •(yml) |
| Performance | (Performance) ์†๋„ ๊ฐœ์„  |
| Refactor | (Cleanup) ์ฝ”๋“œ ์ •๋ฆฌ/๋ฆฌํŒฉํ† ๋ง |

- ์ด์Šˆ๋ฒˆํ˜ธ์™€ ํ•จ๊ป˜ ์ปค๋ฐ‹ ๋‚ด์šฉ์„ ์ ๋Š”๋‹ค.
- ์˜ˆ์‹œ : [#1] feataure : ~
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,15 @@
public class SoldController {
private final SoldService soldService;

/* @PostMapping
@ResponseStatus(HttpStatus.CREATED)
public BaseResponse<?> registerSold(@RequestBody @Valid SoldRequestDto requestDto) {
soldService.registerSold(requestDto);
return BaseResponse.success(SuccessCode.SOLD_CREATE_SUCCESS);
}*/

@GetMapping
public BaseResponse<List<SoldResponseDto>> findAllSold() {
List<SoldResponseDto> soldResponseDtoList = soldService.findAllSold();
return BaseResponse.success(SuccessCode.GET_SUCCESS, soldResponseDtoList);
}

@PutMapping("/{id}")
public BaseResponse<?> updateSold(@PathVariable("id") Long id, @RequestBody @Valid SoldRequestDto requestDto) {
soldService.updateSold(id, requestDto);
@PutMapping
public BaseResponse<?> updateAllSold(@RequestBody @Valid SoldRequestDto requestDto) {
soldService.updateAllSold(requestDto);
return BaseResponse.success(SuccessCode.SOLD_PATCH_SUCCESSCODE);
}

/* @DeleteMapping("/{id}")
public BaseResponse<?> deleteSold(@PathVariable("id") Long id) {
soldService.deleteSold(id);
return BaseResponse.success(SuccessCode.SOLD_DELETE_SUCCESSCODE);
}*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@
@AllArgsConstructor
@NoArgsConstructor
public class SoldRequestDto {
@NotBlank(message = "๋‚ ์งœ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”")
@Pattern(
regexp="^\\d{4}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])$",
message = "YYYY-MM-DD ํ˜•์‹์œผ๋กœ ์ž…๋ ฅํ•˜์„ธ์š”"
)
private String date;

@NotNull
private List<SoldMenuDto> soldMenuList;
}
23 changes: 7 additions & 16 deletions src/main/java/net/skhu/tastyinventory_be/service/SoldService.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public List<SoldResponseDto> findAllSold() {
.map(menu -> {
Sold sold = soldRepository.findByMenuId(menu.getId())
.stream()
.findFirst() // ์กด์žฌํ•˜๋Š” ๊ฒฝ์šฐ ์ฒซ ๋ฒˆ์งธ ํŒ๋งค ์—”ํ‹ฐํ‹ฐ ๊ฐ€์ ธ์˜ค๊ธฐ
.findFirst()
.orElse(null);
Long soldCount = sold != null ? sold.getCount() : 0L;
return new SoldResponseDto(menu.getId(), menu.getName(), soldCount);
Expand All @@ -42,18 +42,19 @@ public List<SoldResponseDto> findAllSold() {
}

@Transactional
public void updateSold(Long id, SoldRequestDto requestDto) {
public void updateAllSold(SoldRequestDto requestDto) {
LocalDate currentDate = LocalDate.now();
for (SoldMenuDto soldMenuDto : requestDto.getSoldMenuList()) {
Menu menu = menuRepository.findById(soldMenuDto.getMenuId()).orElseThrow(
() -> new NotFoundException(
ErrorCode.NOT_FOUND_MENU_EXCEPTION,
ErrorCode.NOT_FOUND_MENU_EXCEPTION.getMessage() + id));
ErrorCode.NOT_FOUND_MENU_EXCEPTION.getMessage() + soldMenuDto.getMenuId()));

List<Sold> soldList = soldRepository.findByMenuId(menu.getId());
Sold sold;
if (soldList.isEmpty()) {
sold = Sold.builder()
.date(LocalDate.parse(requestDto.getDate()))
.date(currentDate)
.menu(menu)
.count(soldMenuDto.getSoldCount())
.build();
Expand All @@ -64,24 +65,14 @@ public void updateSold(Long id, SoldRequestDto requestDto) {
soldRepository.save(sold);
}
}
/*
@Transactional
public void deleteSold(Long id) {
Sold sold = soldRepository.findById(id).orElseThrow(
() -> new NotFoundException(
ErrorCode.NOT_FOUND_SOLD_EXCEPTION,
ErrorCode.NOT_FOUND_SOLD_EXCEPTION.getMessage() + id));
soldRepository.delete(sold);
}*/
@Scheduled(cron = "0 0 0 * * *") // ๋งค์ผ ์ž์ •์— ์‹คํ–‰

@Scheduled(cron = "0 0 0 * * *")
@Transactional
public void resetSoldCounts() {
// Sold ์—”ํ‹ฐํ‹ฐ์˜ ๋ชจ๋“  ํŒ๋งค๋Ÿ‰(count)์„ 0์œผ๋กœ ์ดˆ๊ธฐํ™”ํ•ฉ๋‹ˆ๋‹ค.
List<Sold> soldList = soldRepository.findAll();
for (Sold sold : soldList) {
sold.setCount(0L);
}
soldRepository.saveAll(soldList);
}

}

0 comments on commit e0c8796

Please sign in to comment.