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
1 change: 1 addition & 0 deletions 김수빈/EC2 인스턴스 도메인.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
http://ec2-43-201-121-159.ap-northeast-2.compute.amazonaws.com:8080/
1 change: 1 addition & 0 deletions 김수빈/freelec-springboot2-websevice/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.gradle
.idea
/src/main/java/org/example/
application-oauth.properties
60 changes: 60 additions & 0 deletions 김수빈/freelec-springboot2-websevice/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@


plugins {
id 'org.springframework.boot' version '2.6.7'
id 'io.spring.dependency-management' version '1.0.14.RELEASE'
id 'java'
}

group 'org.example'
version '1.0-SNAPSHOT'

group = 'com.spring-study'
version = '0.0.1-SNAPSHOT'
// Java 소스를 컴파일할 때 사용할 Java 버전
sourceCompatibility = '14'

repositories {
mavenCentral()
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.projectlombok:lombok:1.18.22'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'

//3장
//implementation 'org.springframework.boot:spring-boot-starter-web'
//implementation 'org.projectlombok:lombok'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
//implementation 'com.h2database:h2' 버전 수정하기
implementation 'com.h2database:h2:1.4.197'
//testImplementation 'org.springframework.boot:spring-boot-starter-test'

//4장
implementation('org.springframework.boot:spring-boot-starter-mustache')

//5장
// spring security
implementation('org.springframework.boot:spring-boot-starter-oauth2-client')
testImplementation('org.springframework.security:spring-security-test')

// session
implementation('org.springframework.session:spring-session-jdbc')

//8장(MaridDB 드라이버 등록)
implementation('org.mariadb.jdbc:mariadb-java-client')
}

test {
useJUnitPlatform()
}

//8장
//-plain.jar를 생성하지 않기 위해
jar {
enabled = false
}

2 changes: 2 additions & 0 deletions 김수빈/freelec-springboot2-websevice/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
rootProject.name = 'freelec-springboot2-websevice'

Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,19 @@ protected void configure(HttpSecurity http) throws Exception {
.headers().frameOptions().disable()
.and()
.authorizeRequests()
.antMatchers("/", "/css/**", "/images/**", "/js/**", "/h2-console/**").permitAll()
.antMatchers("/", "/css/**", "/images/**", "/js/**", "/h2-console/**", "/profile").permitAll()
//.antMatchers("/", "/css/**", "/images/**", "/js/**", "/h2-console/**").permitAll()
.antMatchers("/api/v1/**").hasRole(Role.USER.name())
.anyRequest().authenticated()
.and()
.logout().logoutSuccessUrl("/")
.logout()
.logoutSuccessUrl("/")

.and()
.oauth2Login()
.userInfoEndpoint()
.userService(customOAuth2UserService);
.userInfoEndpoint()
.userService(customOAuth2UserService);


}
}
Original file line number Diff line number Diff line change
@@ -1,46 +1,45 @@
package com.book.springboot.web;

import com.book.springboot.web.dto.PostsSaveRequestDto;
import com.book.springboot.service.posts.PostsService;
import com.book.springboot.web.dto.PostsListResponseDto;
import com.book.springboot.web.dto.PostsResponseDto;
import com.book.springboot.web.dto.PostsUpdateRequestDto; //

import com.book.springboot.web.dto.PostsListResponseDto; //
import java.util.List; //

import com.book.springboot.web.dto.PostsSaveRequestDto;
import com.book.springboot.web.dto.PostsUpdateRequestDto;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequiredArgsConstructor
@RequestMapping("/api/v1/posts")
@RestController
public class PostsApiController {

private final PostsService postsService;

@PostMapping("/api/v1/posts")
public Long save(@RequestBody PostsSaveRequestDto requestDto) {
@PostMapping
public Long save(@RequestBody PostsSaveRequestDto requestDto){
return postsService.save(requestDto);
}

@PostMapping("/api/v1/posts/{id}")
public Long update(@PathVariable Long id, @RequestBody PostsUpdateRequestDto requestDto) {
@PutMapping("{id}")
public Long update(@PathVariable Long id, @RequestBody PostsUpdateRequestDto requestDto){
return postsService.update(id, requestDto);
}

@GetMapping("/api/v1/posts/{id}")
public PostsResponseDto findById (@PathVariable Long id) {
@GetMapping("{id}")
public PostsResponseDto findById(@PathVariable Long id){
return postsService.findById(id);
}

@DeleteMapping("/api/v1/posts/{id}")
public Long delete(@PathVariable Long id) {
@DeleteMapping("{id}")
public Long delete(@PathVariable Long id){
postsService.delete(id);
return id;
}
//목록 얻어오기
@GetMapping("/api/v1/posts/")

@GetMapping
public List<PostsListResponseDto> getPostsList(){
return postsService.findAllDesc();
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
spring.profiles.include=oauth,real-db
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
spring.session.store-type=jdbc
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ spring.jpa.show_sql = true

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect

spring.h2.console.enabled=true
spring.h2.console.enabled=true

spring.profiles.include=oauth

spring.session.store-type=jdbc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ var main = {
_this.update();
});

$('#btn-delete').on('click', function () {
_this.delete();
});
},
save : function () {
var data = {
Expand Down Expand Up @@ -50,6 +53,21 @@ var main = {
}).fail(function (error) {
alert(JSON.stringify(error));
});
},
delete : function () {
var id = $('#id').val();

$.ajax({
type: 'DELETE',
url: '/api/v1/posts/'+id,
dataType: 'json',
contentType:'application/json; charset=utf-8'
}).done(function() {
alert('글이 삭제되었습니다.');
window.location.href = '/';
}).fail(function (error) {
alert(JSON.stringify(error));
});
}

};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
{{/userName}}
{{^userName}}
<a href="/oauth2/authorization/google" class="btn btn-success active" role="button">Google Login</a>
<a href="/oauth2/authorization/naver" class="btn btn-secondary active" role="button">Naver Login</a>
<!--<a href="/oauth2/authorization/naver" class="btn btn-secondary active" role="button">Naver Login</a>-->
{{/userName}}
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>

<!--index.js 추가-->
<script src="/js/app/index.js"></script>
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<head>
<title>스프링부트 웹서비스</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
</head>
<body>
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
{{>layout/header}}

<h1>게시글 수정</h1>
<h1>게시글 등록</h1>

<div class="col-md-12">
<div class="col-md-4">
<form>
<div class="form-group">
<label for="title">글 번호</label>
<input type="text" class="form-control" id="id" value="{{post.id}}" readonly>
</div>
<div class="form-group">
<label for="title">제목</label>
<input type="text" class="form-control" id="title" value="{{post.title}}">
<input type="text" class="form-control" id="title" placeholder="제목을 입력하세요">
</div>
<div class="form-group">
<label for="author"> 작성자 </label>
<input type="text" class="form-control" id="author" value="{{post.author}}" readonly>
<input type="text" class="form-control" id="author" placeholder="작성자를 입력하세요">
</div>
<div class="form-group">
<label for="content"> 내용 </label>
<textarea class="form-control" id="content">{{post.content}}</textarea>
<textarea class="form-control" id="content" placeholder="내용을 입력하세요"></textarea>
</div>
</form>
<a href="/" role="button" class="btn btn-secondary">취소</a>
<button type="button" class="btn btn-primary" id="btn-update">수정 완료</button>
<button type="button" class="btn btn-primary" id="btn-save">등록</button>
</div>
</div>

Expand Down
Loading