Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
ef7d876
updateREAEME
Jiwon-cho Jan 27, 2022
e561bf3
swagger,h2
Feb 3, 2022
b53e4ed
Merge branch 'feature/README' into main
Feb 3, 2022
587503f
swagger,h2
Feb 3, 2022
677ab6d
swagger 수정
Jiwon-cho Feb 3, 2022
9eb7cf8
board CRUD,SEARCH
Jiwon-cho Feb 7, 2022
0539af5
board CRUD,find
Jiwon-cho Feb 8, 2022
0185d14
swagger,CRD
Feb 10, 2022
1affd5c
Merge branch 'main' of https://github.com/Jiwon-cho/Anonymous_Server …
Feb 14, 2022
0888eea
swagger,CRD
Feb 15, 2022
dd17471
Merge branch 'main' into feature/README
choipureum Feb 16, 2022
39e816b
swagger,respons 적용중
Feb 16, 2022
fe343ce
Merge remote-tracking branch 'origin/feature/README' into feature/README
Feb 16, 2022
e45ad7b
Common class 생성
Jiwon-cho Feb 16, 2022
b3498c9
Merge branch 'main' of https://github.com/IloveDev-Crew/anonymous-ser…
Feb 25, 2022
2b5bfdf
BoardResponse,SaveRequestDTO 생성,Controller 수정
Feb 25, 2022
ed6b474
BoardResponse,SaveRequestDTO 생성,Controller 수정
Feb 25, 2022
664fe20
Merge branch 'main' of https://github.com/IloveDev-Crew/anonymous-ser…
Feb 25, 2022
d24d6f0
BoardResponse,SaveRequestDTO 생성,Controller 수정
Feb 25, 2022
7259335
Merge remote-tracking branch 'origin/main' into main
Mar 2, 2022
e6c216c
swagger,h2
Feb 3, 2022
49674f0
swagger 수정
Jiwon-cho Feb 3, 2022
275975a
board CRUD,SEARCH
Jiwon-cho Feb 7, 2022
4adc451
board CRUD,find
Jiwon-cho Feb 8, 2022
80c4238
swagger,CRD
Feb 10, 2022
aba21fc
swagger,CRD
Feb 15, 2022
9fc60c6
swagger,respons 적용중
Feb 16, 2022
a8841c6
Common class 생성
Jiwon-cho Feb 16, 2022
d0fe5a6
BoardResponse,SaveRequestDTO 생성,Controller 수정
Feb 25, 2022
999f72b
BoardResponse,SaveRequestDTO 생성,Controller 수정
Feb 25, 2022
e202620
BoardResponse,SaveRequestDTO 생성,Controller 수정
Feb 25, 2022
6c3d5b4
Board CRUD 브랜치 REBASE
Mar 3, 2022
56048f6
Merge remote-tracking branch 'origin/feature/Board_CRUD' into feature…
Mar 3, 2022
bcefa98
Board CRUD delte
Mar 4, 2022
fc65c58
Merge branch 'main' of https://github.com/IloveDev-Crew/anonymous-ser…
Mar 7, 2022
9da8222
Board CRUD,update,selectAll
Mar 7, 2022
e5c64f9
User,UserController 삭제,Transactional 변경
Mar 8, 2022
1199562
BoardResponse,SaveRequestDTO 삭제
Mar 11, 2022
343630c
controllerTest test
Jiwon-cho Mar 14, 2022
9f09d9f
controllerTest createTest
Jiwon-cho Mar 16, 2022
cf4c836
BoardControllerTest,deleteBoardTest 작성
Mar 17, 2022
5097be2
controllerTest,selectBoardTest,serviceTest
Jiwon-cho Mar 17, 2022
128f516
BoardControllerTest,When 추가
Mar 23, 2022
70df3ab
BoardControllerTest,When 추가
Mar 23, 2022
37bb9f6
BoardControllerTest,select,create test 로직 변경
Mar 24, 2022
5541e51
BoardRepositoryTest 작성,BoardFixture 내 메소드 추가
Jiwon-cho Mar 30, 2022
8725965
BoardServiceTest 추가
Jiwon-cho Mar 31, 2022
c5c1225
Post로 이름 수정,ServiceTest 코드 추가작성, 향후 메소드명 변경 계획
Jiwon-cho Apr 1, 2022
f8dce5a
method명 변경,Controller-updateTest 추가
Apr 4, 2022
e226d67
build Fail 확인용 커밋
Apr 5, 2022
6029a85
build Fail 확인용 커밋
Apr 5, 2022
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
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.makefire.anonymous.domain.common;

import lombok.Getter;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
import java.time.LocalDateTime;

@Getter
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public abstract class BasicEntity {
@Id
@GeneratedValue
protected Long id;

@CreatedDate
@Column(name = "created_date",updatable = false)
private LocalDateTime createdDate;

@LastModifiedDate
@Column(name = "modifiedDate",insertable = false)
private LocalDateTime modifiedDate;


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.makefire.anonymous.domain.post.entity;


import com.makefire.anonymous.domain.common.BasicEntity;
import com.makefire.anonymous.rest.dto.request.post.PostRequest;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import javax.persistence.Entity;
import javax.validation.constraints.NotNull;


@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Post extends BasicEntity {


@NotNull(message = "Title must not be null")
private String title;

private String content;

@NotNull(message = "Author must not be null")
private String author;

private Long authorId;

@Builder
public Post(String title, String content, String author, Long authorId) {
this.title = title;
this.content = content;
this.author = author;
this.authorId = authorId;
}

public void update(PostRequest postRequest){
this.id = postRequest.getId();
this.title = postRequest.getTitle();
this.content = postRequest.getContent();
this.author = postRequest.getAuthor();
this.authorId = postRequest.getAuthorId();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.makefire.anonymous.domain.post.repository;

import com.makefire.anonymous.domain.post.entity.Post;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface PostRepository extends JpaRepository<Post, Long> {


}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.makefire.anonymous.rest.controller.api;


import com.makefire.anonymous.rest.RestSupport;
import com.makefire.anonymous.rest.dto.request.post.PostRequest;
import com.makefire.anonymous.rest.dto.response.Response;
import com.makefire.anonymous.service.post.PostService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;

@RestController
@RequiredArgsConstructor
@RequestMapping("/post")
@Slf4j
public class PostController extends RestSupport {

private final PostService postService;

@PostMapping
public ResponseEntity<Response> createPost(
@Valid @RequestBody PostRequest postRequest) {
log.info("createPost", postRequest.toString());
return response(postService.createPost(postRequest));
}

@GetMapping("/{id}")
public ResponseEntity<Response> selectPost(@PathVariable("id") Long id) {
return response(postService.selectPost(id));
}

@GetMapping("/list")
public ResponseEntity<Response> selectPosts() {
return response(postService.selectPosts());
}

@PutMapping
public ResponseEntity<Response> updatePost(@Valid @RequestBody PostRequest postRequest) {
return response(postService.updatePost(postRequest));
}

@DeleteMapping("/{id}")
public ResponseEntity<Response> deletePost(@PathVariable("id") Long id) {
return response(postService.deletePost(id));
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.makefire.anonymous.rest.dto.request.post;

import com.makefire.anonymous.domain.post.entity.Post;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class PostRequest {
private Long id;
private String title;
private String content;
private String author;
private Long authorId;

@Builder
public PostRequest(Long id, String title, String content, String author, Long authorId) {
this.id = id;
this.title = title;
this.content = content;
this.author = author;
this.authorId = authorId;
}

public static Post toEntity(PostRequest postRequest) {
return Post.builder()
.title(postRequest.title)
.content(postRequest.content)
.author(postRequest.author)
.authorId(postRequest.authorId)
.build();

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.makefire.anonymous.rest.dto.response;

import lombok.Data;

@Data
public class Message {

private StatusEnum status;
private String message;
private Object data;

public Message() {
this.status = StatusEnum.BAD_REQUEST;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BAD_REQUEST로 고정될 경우 다른 경우는 현재 반환이 어려워보입니다. 좀 더 확장성있는 구조 설계를 해야할 것 같습니다

this.data = null;
this.message = null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.makefire.anonymous.rest.dto.response;

public enum StatusEnum {

OK(200, "OK"),
BAD_REQUEST(400, "BAD_REQUEST"),
NOT_FOUND(404, "NOT_FOUND"),
INTERNAL_SERER_ERROR(500, "INTERNAL_SERVER_ERROR");

int statusCode;
String code;

StatusEnum(int statusCode, String code) {
this.statusCode = statusCode;
this.code = code;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.makefire.anonymous.rest.dto.response.post;

import com.makefire.anonymous.domain.post.entity.Post;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class PostResponse {

private Long id, authorId;
private String title, content, author;
private LocalDateTime createdDate, modifiedDate;


@Builder
public PostResponse(Long id, Long authorId, String title, String content, String author, LocalDateTime createdDate, LocalDateTime modifiedDate) {
this.id = id;
this.authorId = authorId;
this.title = title;
this.content = content;
this.author = author;
this.createdDate = createdDate;
this.modifiedDate = modifiedDate;

}

public static PostResponse from(Post post) {
return PostResponse.builder()
.id(post.getId())
.authorId(post.getAuthorId())
.title(post.getTitle())
.content(post.getContent())
.author(post.getAuthor())
.createdDate(post.getCreatedDate())
.modifiedDate(post.getModifiedDate())
.build();
}

public static List<PostResponse> fromList(List<Post> postList) {
List<PostResponse> postResponseList = new ArrayList<>();
for (Post post : postList
) {
postResponseList.add(PostResponse.builder()
.id(post.getId())
.authorId(post.getAuthorId())
.title(post.getTitle())
.content(post.getContent())
.author(post.getAuthor())
.createdDate(post.getCreatedDate())
.modifiedDate(post.getModifiedDate())
.build());
}
return postResponseList;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.makefire.anonymous.service.post;

import com.makefire.anonymous.domain.post.entity.Post;
import com.makefire.anonymous.domain.post.repository.PostRepository;
import com.makefire.anonymous.rest.dto.request.post.PostRequest;
import com.makefire.anonymous.rest.dto.response.post.PostResponse;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import java.util.List;

@Service
@AllArgsConstructor
public class PostService {
private final PostRepository postRepository;

public PostResponse selectPost(Long id) {
Post post = postRepository.findById(id).orElseThrow(() -> new IllegalArgumentException());
return PostResponse.from(post);
}

public List<PostResponse> selectPosts() {
List<Post> postList = postRepository.findAll();
return PostResponse.fromList(postList);
}

@Transactional
public PostResponse createPost(PostRequest postRequest) {
Post post = PostRequest.toEntity(postRequest);
return PostResponse.from(postRepository.save(post));
}

@Transactional(rollbackFor = IllegalArgumentException.class)
public PostResponse updatePost(PostRequest postRequest) {
Post post = postRepository.findById(postRequest.getId()).orElseThrow(() -> new IllegalArgumentException());
post.update(postRequest);
return PostResponse.from(post);
}

public Boolean deletePost(Long id) {
Post post = postRepository.findById(id).orElseThrow(() -> new IllegalArgumentException());
postRepository.delete(post);
return true;
}
}
3 changes: 2 additions & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ spring:
include: local, config.oauth
mvc:
pathmatch:
matching-strategy: ant_path_matcher
matching-strategy: ant_path_matcher

Loading