Skip to content

Commit

Permalink
fix: 병합 충돌 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
firefox1234123 committed Jul 29, 2024
2 parents e4e6857 + 9f2a2ab commit d19eb78
Show file tree
Hide file tree
Showing 20 changed files with 650 additions and 6 deletions.
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ repositories {
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-security'
//implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
Expand All @@ -36,11 +36,12 @@ dependencies {
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

// jwt
implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5'
//aws
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'
}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package net.skhu.likelion12thteam03be.category.api;

import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import net.skhu.likelion12thteam03be.category.api.dto.request.CategorySaveReqDto;
import net.skhu.likelion12thteam03be.category.api.dto.request.CategoryUpdateReqDto;
import net.skhu.likelion12thteam03be.category.api.dto.response.CategoryListResDto;
import net.skhu.likelion12thteam03be.category.application.CategoryService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/categories")
public class CategoryController {

private final CategoryService categoryService;

@PostMapping
public ResponseEntity<String> categorySave(@RequestBody @Valid CategorySaveReqDto categorySaveReqDto) {
categoryService.categorySave(categorySaveReqDto);
return new ResponseEntity<>("Successful Category Save!", HttpStatus.CREATED);
}

@GetMapping()
public ResponseEntity<CategoryListResDto> categoryFindAll() {
CategoryListResDto categoryListResDto = categoryService.categoryFindAll();
return new ResponseEntity<>(categoryListResDto, HttpStatus.OK);
}

@PatchMapping("/{categoryId}")
public ResponseEntity<String> categoryUpdate(@PathVariable Long categoryId, @RequestBody @Valid CategoryUpdateReqDto categoryUpdateReqDto) {
categoryService.categoryUpdate(categoryId, categoryUpdateReqDto);
return new ResponseEntity<>("Successful Category Update! categoryId = " + categoryId, HttpStatus.OK);
}

@DeleteMapping("/{categoryId}")
public ResponseEntity<String> categoryDelete(@PathVariable Long categoryId) {
categoryService.categoryDelete(categoryId);
return new ResponseEntity<>("Successful Category Delete! categoryId = " + categoryId, HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package net.skhu.likelion12thteam03be.category.api.dto.request;

public record CategorySaveReqDto(
String name
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package net.skhu.likelion12thteam03be.category.api.dto.request;

public record CategoryUpdateReqDto(
String name
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package net.skhu.likelion12thteam03be.category.api.dto.response;

import lombok.Builder;
import net.skhu.likelion12thteam03be.category.domain.Category;

@Builder
public record CategoryInfoResDto(
Long categoryId,
String name
) {
public static CategoryInfoResDto from(Category category) {
return CategoryInfoResDto.builder()
.name(category.getName())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package net.skhu.likelion12thteam03be.category.api.dto.response;

import lombok.Builder;

import java.util.List;

@Builder
public record CategoryListResDto(
List<CategoryInfoResDto> categoryList
) {
public static CategoryListResDto from(List<CategoryInfoResDto> categoryList) {
return CategoryListResDto.builder()
.categoryList(categoryList)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package net.skhu.likelion12thteam03be.category.application;

import lombok.RequiredArgsConstructor;
import net.skhu.likelion12thteam03be.category.api.dto.request.CategorySaveReqDto;
import net.skhu.likelion12thteam03be.category.api.dto.request.CategoryUpdateReqDto;
import net.skhu.likelion12thteam03be.category.api.dto.response.CategoryInfoResDto;
import net.skhu.likelion12thteam03be.category.api.dto.response.CategoryListResDto;
import net.skhu.likelion12thteam03be.category.domain.Category;
import net.skhu.likelion12thteam03be.category.domain.repository.CategoryRepository;
import net.skhu.likelion12thteam03be.post.api.dto.response.PostInfoResDto;
import net.skhu.likelion12thteam03be.post.api.dto.response.PostListResDto;
import net.skhu.likelion12thteam03be.post.domain.Post;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
@RequiredArgsConstructor
public class CategoryService {
private final CategoryRepository categoryRepository;

@Transactional
public void categorySave(CategorySaveReqDto categorySaveReqDto) {
if (categoryRepository.existsByName(categorySaveReqDto.name())) {
throw new IllegalArgumentException("해당 카테고리가 이미 존재합니다.");
}
Category category = Category.builder()
.name(categorySaveReqDto.name())
.build();

categoryRepository.save(category);
}

public CategoryListResDto categoryFindAll() {
List<Category> categories = categoryRepository.findAll();

List<CategoryInfoResDto> categoryInfoResDtoList = categories.stream()
.map(CategoryInfoResDto::from)
.toList();

return CategoryListResDto.from(categoryInfoResDtoList);
}

@Transactional
public void categoryUpdate(Long categoryId, CategoryUpdateReqDto categoryUpdateReqDto) {
Category category = categoryRepository.findById(categoryId).orElseThrow(
() -> new IllegalArgumentException("해당 카테고리가 존재하지 않습니다.")
);
category.update(categoryUpdateReqDto.name());
}

@Transactional
public void categoryDelete(Long categoryId) {
Category category = categoryRepository.findById(categoryId).orElseThrow(
() -> new IllegalArgumentException("해당 카테고리가 존재하지 않습니다.")
);
categoryRepository.deleteById(categoryId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package net.skhu.likelion12thteam03be.category.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import net.skhu.likelion12thteam03be.post.domain.Post;

import java.util.ArrayList;
import java.util.List;

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

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "category_id")
private Long categoryId;

private String name;

@JsonIgnore
@OneToMany(mappedBy = "category", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Post> postList = new ArrayList<>();

@Builder
public Category(String name) {
this.name = name;
}

public void update(String name) {
this.name = name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package net.skhu.likelion12thteam03be.category.domain.repository;

import net.skhu.likelion12thteam03be.category.domain.Category;
import org.springframework.data.jpa.repository.JpaRepository;

public interface CategoryRepository extends JpaRepository<Category, Long> {
boolean existsByName(String name);
}
37 changes: 37 additions & 0 deletions src/main/java/net/skhu/likelion12thteam03be/config/S3Config.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package net.skhu.likelion12thteam03be.config;

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class S3Config {

@Value("${cloud.aws.credentials.access-key}")
private String accessKey;

@Value("${cloud.aws.credentials.secret-key}")
private String secretKey;

@Value("${cloud.aws.region.static}")
private String region;

// AmazonS3 클라이언트를 생성하는 Bean을 정의
@Bean
public AmazonS3 s3Builder() {
// AWS 자격 증명 생성
AWSCredentials basicAWSCredentials = new BasicAWSCredentials(accessKey, secretKey);

// AmazonS3 클라이언트 생성, 자격 증명 및 region 설정
return AmazonS3ClientBuilder
.standard()
.withCredentials(new AWSStaticCredentialsProvider(basicAWSCredentials))
.withRegion(region)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package net.skhu.likelion12thteam03be.post.api.dto;

import net.skhu.likelion12thteam03be.post.api.dto.request.PostSaveReqDto;
import net.skhu.likelion12thteam03be.post.api.dto.request.PostUpdateReqDto;
import net.skhu.likelion12thteam03be.post.api.dto.response.PostInfoResDto;
import net.skhu.likelion12thteam03be.post.api.dto.response.PostListResDto;
import net.skhu.likelion12thteam03be.post.application.PostService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/posts")
public class PostController {
private final PostService postService;

public PostController(PostService postService) { this.postService = postService; }

// 글 저장
@PostMapping()
public ResponseEntity<String> postSave(@RequestBody PostSaveReqDto postSaveReqDto) {
postService.postSave(postSaveReqDto);
return new ResponseEntity<>("Successful Post Save", HttpStatus.CREATED);
}

// 글 전체 조회
@GetMapping()
public ResponseEntity<PostListResDto> postFindAll() {
PostListResDto postListResDto = postService.postFindAll();
return new ResponseEntity<>(postListResDto, HttpStatus.OK);
}

// 글 개별 조회
@GetMapping("/{postId}")
public ResponseEntity<PostInfoResDto> postFindById(@PathVariable Long postId) {
PostInfoResDto postInfoResDto = postService.postFindById(postId);
return new ResponseEntity<>(postInfoResDto, HttpStatus.OK);
}

// 글 카테고리별 조회
@GetMapping("/categories/{categoryId}")
public ResponseEntity<PostListResDto> postFindByCategoryId(@PathVariable("categoryId") Long categoryId) {
PostListResDto postListResDto = postService.postFindByCategoryId(categoryId);
return new ResponseEntity<>(postListResDto, HttpStatus.OK);
}

// 글 작성자별 조회(내 글 조회)
/*@GetMapping("/users/{userId}")
public ResponseEntity<PostListResDto> postFindByUserId(@PathVariable("userId") Long userId) {
PostListResDto postListResDto = postService.postFindByUserId(userId);
return new ResponseEntity<>(postListResDto, HttpStatus.OK);
}*/

// 글 검색 조회


// 글 수정
@PatchMapping("/{postId}")
public ResponseEntity<String> postUpdate(@PathVariable("postId") Long postId, @RequestBody PostUpdateReqDto postUpdateReqDto) {
postService.postUpdate(postId, postUpdateReqDto);
return new ResponseEntity<>("Successful Post Update", HttpStatus.OK);
}

// 글 삭제
@DeleteMapping("/{postId}")
public ResponseEntity<String> postDelete(@PathVariable("postId") Long postId) {
postService.postDelete(postId);
return new ResponseEntity<>("Successful Post Delete", HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package net.skhu.likelion12thteam03be.post.api.dto.request;

public record PostSaveReqDto(
String title,
String content,
String imgUrl,
String locationId,
Integer time,
Integer price,
Long categoryId,
String emotionId,
String colorId
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package net.skhu.likelion12thteam03be.post.api.dto.request;

public record PostUpdateReqDto(
String title,
String content,
String imgUrl,
String locationId,
Integer time,
Integer price,
Long categoryId,
String emotionId,
String colorId
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package net.skhu.likelion12thteam03be.post.api.dto.response;

import lombok.Builder;
import net.skhu.likelion12thteam03be.category.domain.Category;
import net.skhu.likelion12thteam03be.post.domain.Post;

@Builder
public record PostInfoResDto(
String title,
String content,
String imgUrl,
String locationId,
Integer time,
Integer price,
Category category,
String emotionId,
String colorId
) {
public static PostInfoResDto from(Post post) {
return PostInfoResDto.builder()
.title(post.getTitle())
.content(post.getContent())
.imgUrl(post.getImgUrl())
.locationId(post.getLocationId())
.time(post.getTime())
.price(post.getPrice())
.category(post.getCategory())
.emotionId(post.getEmotionId())
.colorId(post.getColorId())
.build();
}
}
Loading

0 comments on commit d19eb78

Please sign in to comment.