Skip to content

Commit

Permalink
[feat] 게시글 상세조회, 게시글 조회, CRUD
Browse files Browse the repository at this point in the history
  • Loading branch information
dongseoki committed Nov 10, 2023
1 parent c9e4397 commit 608b969
Show file tree
Hide file tree
Showing 33 changed files with 1,111 additions and 222 deletions.
87 changes: 45 additions & 42 deletions server/build.gradle
Original file line number Diff line number Diff line change
@@ -1,84 +1,87 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.1.5'
id 'io.spring.dependency-management' version '1.1.3'
id 'java'
id 'org.springframework.boot' version '3.1.5'
id 'io.spring.dependency-management' version '1.1.3'
// id "com.ewerk.gradle.plugins.querydsl" version "1.0.10"
}

group = 'com.bside'
version = '0.0.1-SNAPSHOT'

java {
sourceCompatibility = '17'
sourceCompatibility = '17'
}

configurations {
compileOnly {
extendsFrom annotationProcessor
}
compileOnly {
extendsFrom annotationProcessor
}
}

repositories {
mavenCentral()
mavenCentral()
}

//ext.profile = (!project.hasProperty('profile') || !profile) ? 'local' : profile

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:3.0.2'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'

// https://mvnrepository.com/artifact/org.springdoc/springdoc-openapi-ui
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:3.0.2'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'

// https://mvnrepository.com/artifact/org.springdoc/springdoc-openapi-ui
// implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.7.0'

implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2")
// Spring Security
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2")
// Spring Security
implementation 'org.springframework.boot:spring-boot-starter-security'

// Bouncy Castle Provider → Argon2
implementation 'org.bouncycastle:bcprov-jdk15on:1.70'
// Bouncy Castle Provider → Argon2
implementation 'org.bouncycastle:bcprov-jdk15on:1.70'

// https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt
implementation group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.1'
// https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt
implementation group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.1'

// com.sun.xml.bind
implementation 'com.sun.xml.bind:jaxb-impl:4.0.1'
implementation 'com.sun.xml.bind:jaxb-core:4.0.1'
// javax.xml.bind
implementation 'javax.xml.bind:jaxb-api:2.4.0-b180830.0359'
// com.sun.xml.bind
implementation 'com.sun.xml.bind:jaxb-impl:4.0.1'
implementation 'com.sun.xml.bind:jaxb-core:4.0.1'
// javax.xml.bind
implementation 'javax.xml.bind:jaxb-api:2.4.0-b180830.0359'

// https://mvnrepository.com/artifact/org.apache.commons/commons-collections4
implementation group: 'org.apache.commons', name: 'commons-collections4', version: '4.4'


// if (profile == "localh2") {
// runtimeOnly 'com.h2database:h2'
// }else {
// runtimeOnly 'com.mysql:mysql-connector-j'
// }
runtimeOnly 'com.mysql:mysql-connector-j'
runtimeOnly 'com.mysql:mysql-connector-j'

runtimeOnly 'com.mysql:mysql-connector-j'
runtimeOnly 'com.mysql:mysql-connector-j'

annotationProcessor 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'

// spring boot 3.0 query dsl setting.
implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta'
annotationProcessor "com.querydsl:querydsl-apt:${dependencyManagement.importedProperties['querydsl.version']}:jakarta"
annotationProcessor "jakarta.annotation:jakarta.annotation-api"
annotationProcessor "jakarta.persistence:jakarta.persistence-api"
// spring boot 3.0 query dsl setting.
implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta'
annotationProcessor "com.querydsl:querydsl-apt:${dependencyManagement.importedProperties['querydsl.version']}:jakarta"
annotationProcessor "jakarta.annotation:jakarta.annotation-api"
annotationProcessor "jakarta.persistence:jakarta.persistence-api"

// p6spy : sql 로그 남기기(바인딩된 파라미터 간편 확인.)
implementation 'com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.9.0'
// p6spy : sql 로그 남기기(바인딩된 파라미터 간편 확인.)
implementation 'com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.9.0'

testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter-test:3.0.2'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter-test:3.0.2'
}

tasks.named('test') {
useJUnitPlatform()
useJUnitPlatform()
}

//def querydslDir = "$buildDir/generated/querydsl"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ public class AlcoholController {
@Operation(summary = "[o]술 등록 ", description = "술 등록 API")
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public AddAlcoholResponseDto addAlcohol(@RequestBody @Valid AddAlcoholRequestDto addAlcoholRequestDto){
public AddAlcoholResponseDto addAlcohol(
@RequestBody @Valid AddAlcoholRequestDto addAlcoholRequestDto) {
log.info(">>> AlcoholController.addAlcohol");
return alcoholService.addAlcohol(Alcohol.of(addAlcoholRequestDto));
}

@Operation(summary = "[o]술 수정", description = "술 수정 API")
@PatchMapping("/{alcoholNo}")
public void editAlcohol(@PathVariable("alcoholNo") Long alcoholNo, @RequestBody @Valid EditAlcoholRequestDto editAlcoholRequestDto) {
public void editAlcohol(@PathVariable("alcoholNo") Long alcoholNo,
@RequestBody @Valid EditAlcoholRequestDto editAlcoholRequestDto) {
log.info(">>> AlcoholController.editAlcohol");
alcoholService.editAlcohol(alcoholNo, editAlcoholRequestDto);
}
Expand All @@ -60,13 +62,18 @@ public void deleteAlcohol(@PathVariable("alcoholNo") Long alcoholNo) {
@Operation(summary = "[~]술 목록 조회", description = "술 조회 API")
@GetMapping
public GetAlcoholResponseDto getAlcohol(
@RequestParam(name = "page", defaultValue = "0") @Schema(description = "페이지번호(0부터), 기본값 0.", example = "0") Long page,
@RequestParam(name = "size", defaultValue = "10") @Schema(description = "사이즈, 기본값 10.", example = "10") Long size,
@RequestParam(required = false, name = "orderColumn") @Schema(description = "정렬 컬럼", example = "alcohol_no") String orderColumn,
@RequestParam(required = false, name = "orderType") @Schema(description = "정렬 타입",example = "DESC") String orderType,
@RequestParam(required = false, name = "searchAlcoholKeyword") @Schema(description = "알코올 키워드", example = "키워드") String searchAlcoholKeyword) {
@RequestParam(name = "page", defaultValue = "0")
@Schema(description = "페이지번호(0부터), 기본값 0.", example = "0") Long page,
@RequestParam(name = "size", defaultValue = "10")
@Schema(description = "사이즈, 기본값 10.", example = "10") Long size,
@RequestParam(required = false, name = "orderColumn")
@Schema(description = "정렬 컬럼", example = "alcohol_no") String orderColumn,
@RequestParam(required = false, name = "orderType")
@Schema(description = "정렬 타입", example = "DESC") String orderType,
@RequestParam(required = false, name = "searchKeyword")
@Schema(description = "알코올 키워드", example = "키워드") String searchKeyword) {
log.info(">>> AlcoholController.getAlcohol");
return alcoholService.getAlcohol(page, size, orderColumn, orderType, searchAlcoholKeyword);
return alcoholService.getAlcohol(page, size, orderColumn, orderType, searchKeyword);
}

@Operation(summary = "[o]술 상세 조회", description = "술 상세 조회 API")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
import com.bside.bside_311.dto.AddCommentResponseDto;
import com.bside.bside_311.dto.AddPostRequestDto;
import com.bside.bside_311.dto.AddPostResponseDto;
import com.bside.bside_311.dto.CommentResponseDto;
import com.bside.bside_311.dto.EditCommentRequestDto;
import com.bside.bside_311.dto.EditPostRequestDto;
import com.bside.bside_311.dto.GetPostCommentsResponseDto;
import com.bside.bside_311.dto.GetPostResponseDto;
import com.bside.bside_311.dto.PostDetailResponseDto;
import com.bside.bside_311.dto.PostResponseDto;
import com.bside.bside_311.dto.QuoteInfoDto;
import com.bside.bside_311.entity.Post;
import com.bside.bside_311.service.PostService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -40,43 +41,59 @@
@RequestMapping("/posts")
@Tag(name = "게시글", description = "게시글 API")
public class PostController {
private final PostService postService;

@Operation(summary = "게시글 등록 ", description = "게시글 등록 API")
@Operation(summary = "[o]게시글 등록 ", description = "게시글 등록 API")
@PostMapping
public AddPostResponseDto addPost(@ModelAttribute @Valid AddPostRequestDto addPostRequestDto) {
public AddPostResponseDto addPost(@RequestBody @Valid AddPostRequestDto addPostRequestDto) {
log.info(">>> PostController.addPost");
return null;
return postService.addPost(Post.of(addPostRequestDto), addPostRequestDto.getAlcoholNo(),
addPostRequestDto.getAlcoholFeature(), addPostRequestDto.getTagList());
}

@Operation(summary = "게시글 수정", description = "게시글 수정 API")
@PatchMapping
public void editPost(@RequestBody @Valid EditPostRequestDto editPostRequestDto) {
@Operation(summary = "[o]게시글 수정", description = "게시글 수정 API")
@PatchMapping("/{postNo}")
public void editPost(@PathVariable("postNo") Long postNo,
@RequestBody @Valid EditPostRequestDto editPostRequestDto) {
log.info(">>> PostController.editPost");
return ;

postService.editPost(postNo, editPostRequestDto);
return;
}

@Operation(summary = "게시글 삭제", description = "게시글 삭제 API")
@DeleteMapping
public void deletePost() {
@Operation(summary = "[o]게시글 삭제", description = "게시글 삭제 API")
@DeleteMapping("/{postNo}")
public void deletePost(@PathVariable("postNo") Long postNo) {
log.info(">>> PostController.deletePost");
postService.deletePost(postNo);
}

@Operation(summary = "게시글 목록 조회", description = "게시글 조회 API")
@Operation(summary = "[~]게시글 목록 조회", description = "게시글 조회 API")
@GetMapping
public GetPostResponseDto getPost(@RequestParam Long page,
@RequestParam Long size,
@RequestParam(required = false) String orderColumn,
@RequestParam(required = false) String orderType,
@RequestParam(required = false) String keyWord) {
public GetPostResponseDto getPosts(@RequestParam(name = "page", defaultValue = "0")
@Schema(description = "페이지번호(0부터), 기본값 0.", example = "0")
Long page,
@RequestParam(name = "size", defaultValue = "10")
@Schema(description = "사이즈, 기본값 10.", example = "10")
Long size,
@RequestParam(required = false, name = "orderColumn")
@Schema(description = "정렬 컬럼", example = "alcohol_no")
String orderColumn,
@RequestParam(required = false, name = "orderType")
@Schema(description = "정렬 타입", example = "DESC")
String orderType,
@RequestParam(required = false, name = "searchKeyword")
@Schema(description = "키워드", example = "키워드")
String searchKeyword) {
log.info(">>> PostController.getPost");
return null;
return postService.getPosts(page, size, orderColumn, orderType, searchKeyword);
}

@Operation(summary = "게시글 상세 조회", description = "게시글 상세 조회 API")
@Operation(summary = "[~]게시글 상세 조회", description = "게시글 상세 조회 API")
@GetMapping("/{postNo}")
public PostResponseDto getPostDetail(@PathVariable Long postNo) {
public PostResponseDto getPostDetail(@PathVariable("postNo") Long postNo) {
log.info(">>> PostController.getPostDetail");
return null;
return postService.getPostDetail(postNo);
}

@Operation(summary = "게시글 댓글 등록", description = "게시글 댓글 등록 API")
Expand All @@ -96,10 +113,11 @@ public GetPostCommentsResponseDto getPostComments(@PathVariable Long postNo) {
return null;
}

@Operation(summary = "게시글 댓글 수정", description = "게시글 댓글 수정 API")
@Operation(summary = "[o]게시글 댓글 수정", description = "게시글 댓글 수정 API")
@PatchMapping("/{postNo}/comments/{commentNo}")
public void editComment(@PathVariable Long postNo, @PathVariable Long commentNo, @Valid @RequestBody
EditCommentRequestDto EditCommentRequestDto) {
public void editComment(@PathVariable Long postNo, @PathVariable Long commentNo,
@Valid @RequestBody
EditCommentRequestDto EditCommentRequestDto) {
log.info(">>> PostController.editComment");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

Expand All @@ -10,14 +12,22 @@

@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
@Builder
@AllArgsConstructor
public class AddPostRequestDto {
@Schema(example = "1", description = "선택 주류 번호")
private Long alcoholNo;
@Schema(example = "산뜻함. 달콤함.", description = "주류 특징")
private String alcoholFeature;
@Schema(example = "게시글 내용", description = "게시글 내용")
private String postContent;
@Schema(example = "BASIC", description = "게시글 타입")
private String postType;
@Schema(example = "위치 정보", description = "위치에 대한 정보")
private String positionInfo;

@Schema(example = "[\"test\", \"외로울때\", \"파스타\"", description = "태그 리스트. 해당 문자열 없을경우 데이터 생성.")
private List<String> tagList;

@Builder.Default
@Schema(description = "태그 리스트. 해당 문자열 없을경우 데이터 생성.")
private List<String> tagList = new ArrayList<>();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bside.bside_311.dto;

import com.bside.bside_311.entity.Post;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AccessLevel;
import lombok.Getter;
Expand All @@ -10,4 +11,12 @@
public class AddPostResponseDto {
@Schema(example = "1", description = "게시글 번호")
private Long postNo;

public AddPostResponseDto(Long postNo) {
this.postNo = postNo;
}

public static AddPostResponseDto of(Post post) {
return new AddPostResponseDto(post.getId());
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
package com.bside.bside_311.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.List;

@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
public class EditPostRequestDto {
@Schema(example = "1", description = "선택 주류 번호")
private Long alcoholNo;
@Schema(example = "게시글 내용", description = "게시글 내용")
private String postContent;

@Schema(example = "[\"test\", \"외로울때\", \"파스타\"", description = "태그 리스트. 해당 문자열 없을경우 데이터 생성.")
private List<String> tagList;
public class EditPostRequestDto extends AddPostRequestDto {
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.bside.bside_311.dto;

import lombok.Builder;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;

Expand All @@ -14,16 +13,16 @@ public class GetAlcoholsVo {

String orderColumn;
String orderType;
String searchAlcoholKeyword;
String searchKeyword;

@Builder
public GetAlcoholsVo(Long page, Long size, Long offset, String orderColumn,
String orderType, String searchAlcoholKeyword) {
String orderType, String searchKeyword) {
this.page = page;
this.size = size;
this.offset = offset;
this.orderColumn = orderColumn;
this.orderType = orderType;
this.searchAlcoholKeyword = searchAlcoholKeyword;
this.searchKeyword = searchKeyword;
}
}
Loading

0 comments on commit 608b969

Please sign in to comment.