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
Binary file added .DS_Store
Binary file not shown.
76 changes: 0 additions & 76 deletions .github/workflows/deployment.yml

This file was deleted.

34 changes: 34 additions & 0 deletions .github/workflows/run_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle

name: Deployment

on:
workflow_dispatch:
pull_request:
branches: [ "main" ]

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: gradle
- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Test with Gradle
run: ./gradlew test
7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.junit.jupiter:junit-jupiter:5.8.1'
testImplementation 'org.projectlombok:lombok:1.18.22'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok' //TODO: annotation build 활성화 언급하기
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2'
Expand All @@ -36,3 +38,8 @@ dependencies {
tasks.named('test') {
useJUnitPlatform()
}
test {
testLogging {
events "PASSED", "SKIPPED", "FAILED"
}
}
Binary file added src/.DS_Store
Binary file not shown.
Binary file added src/main/.DS_Store
Binary file not shown.
14 changes: 14 additions & 0 deletions src/main/java/com/cnu/real_coding_server/error/ErrorResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.cnu.real_coding_server.error;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.http.HttpStatus;

@Getter
@NoArgsConstructor
@AllArgsConstructor
public class ErrorResponse {
String code; // 클라이언트랑 약속한 작동
String message;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.cnu.real_coding_server.error;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class RealCodingExceptionHandler {
@ExceptionHandler(SlangBadRequestException.class)
public ResponseEntity<ErrorResponse> handleSlangRequestException(SlangBadRequestException exception) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(exception.getErrorResponse());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.cnu.real_coding_server.error;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;

@ResponseStatus(code = HttpStatus.BAD_REQUEST)
public class SlangBadRequestException extends RuntimeException {
private static final long serialVersionUID = -4785136912743477236L;

public SlangBadRequestException() {
super("비속어가 포함된 글은 등록할 수 없습니다");
}

public ErrorResponse getErrorResponse() {
return new ErrorResponse("slangInput", this.getMessage());
}
}
23 changes: 17 additions & 6 deletions src/main/java/com/cnu/real_coding_server/service/PostService.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,45 @@
package com.cnu.real_coding_server.service;

import com.cnu.real_coding_server.entity.Post;
import com.cnu.real_coding_server.error.SlangBadRequestException;
import com.cnu.real_coding_server.model.request.PostRequest;
import com.cnu.real_coding_server.repository.PostRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import com.cnu.real_coding_server.service.valid.PostValidService;
import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@RequiredArgsConstructor
public class PostService {

private final PostRepository postRepository;
private static final List<String> slangList = List.of("비속어1", "비속어2");
private final PostValidService postValidService;

public Post createPost(PostRequest postRequest) {

if (postValidService.isSlangInclude(slangList, postRequest.getTitle(), postRequest.getContents())) {
throw new SlangBadRequestException();
}
log.info("정상 저장 확인");
return postRepository.save(postRequest.toEntity());
}

public List<Post> getPosts() {
return postRepository.findAll();
}

public Optional<Post> getPost(Integer postId) {
return postRepository.findById(postId);
}

public Optional<Post> updatePost(Integer postId, PostRequest postRequest) {
if (postValidService.isSlangInclude(slangList, postRequest.getTitle(), postRequest.getContents())) {
throw new SlangBadRequestException();
}
return postRepository.findById(postId)
.map(post -> {
post.setTitle(postRequest.getTitle());
Expand All @@ -36,9 +48,8 @@ public Optional<Post> updatePost(Integer postId, PostRequest postRequest) {
return postRepository.save(post);
});
}

public void deletePost(Integer postId) {
postRepository.findById(postId)
.ifPresent(postRepository::delete);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.cnu.real_coding_server.service.valid;

import java.util.List;
import org.springframework.stereotype.Service;

@Service
public class PostValidService {
public boolean isSlangInclude(List<String> slangList,
String title,
String postContent) {
for (String slang : slangList) {
if(title.contains(slang)
|| postContent.contains(slang)) {
return true;
}
}
return false;
}
}
Binary file added src/main/resources/.DS_Store
Binary file not shown.
25 changes: 25 additions & 0 deletions src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
spring:
# H2 Setting Info (H2 Console? ???? ?? ???? ??)
h2:
console:
enabled: true # H2 Console? ???? ?? (H2 Console? H2 Database? UI? ????? ??)
path: /h2-console # H2 Console? Path
# Database Setting Info (Database? H2? ???? ?? H2?? ?? ??)
datasource:
driver-class-name: org.h2.Driver # Database? H2? ?????.
url: jdbc:h2:file:~/demodb # H2 ?? ??
username: sa # H2 ?? ? ??? username ?? (??? ??? ??)
password: # H2 ?? ? ??? password ?? (??? ??? ??)

jpa:
hibernate:
ddl-auto: none # ??????? ??? ? ??????? ????? ?? ??? ??
naming:
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
implicit-strategy: org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl
properties:
hibernate:
format_sql: true # ???? query? ???

logging.level:
org.hibernate.SQL: debug
22 changes: 22 additions & 0 deletions src/main/resources/application-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
spring:
# H2 Setting Info (H2 Console? ???? ?? ???? ??)
h2:
console:
enabled: true # H2 Console? ???? ?? (H2 Console? H2 Database? UI? ????? ??)
path: /h2-console # H2 Console? Path
# Database Setting Info (Database? H2? ???? ?? H2?? ?? ??)
datasource:
driver-class-name: org.h2.Driver # Database? H2? ?????.
url: jdbc:h2:mem:devblog # H2 ?? ??
username: sa # H2 ?? ? ??? username ?? (??? ??? ??)
password: # H2 ?? ? ??? password ?? (??? ??? ??)

jpa:
hibernate:
ddl-auto: create-drop # ??????? ??? ? ??????? ????? ?? ??? ??
properties:
hibernate:
format_sql: true # ???? query? ???

logging.level:
org.hibernate.SQL: debug
3 changes: 2 additions & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ spring:

jpa:
hibernate:
ddl-auto: create # ??????? ??? ? ??????? ????? ?? ??? ??
ddl-auto: none # ??????? ??? ? ??????? ????? ?? ??? ??
properties:
hibernate:
format_sql: true # ???? query? ???
open-in-view: false

logging.level:
org.hibernate.SQL: debug
Binary file added src/test/.DS_Store
Binary file not shown.
Binary file added src/test/java/.DS_Store
Binary file not shown.
Binary file added src/test/java/com/.DS_Store
Binary file not shown.
Binary file added src/test/java/com/cnu/.DS_Store
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading