Skip to content

Commit

Permalink
Merge branch 'develop' into 015-Apply
Browse files Browse the repository at this point in the history
  • Loading branch information
wonho-seo authored Jun 19, 2023
2 parents 5c31efc + d8895d7 commit e5ef26d
Show file tree
Hide file tree
Showing 51 changed files with 928 additions and 205 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ out/

### VS Code ###
.vscode/
src/main/resources/oauth2.yml
/src/main/resources/aws.yml
/src/main/resources/oauth2.yml

2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-security'

//aws cloud
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'
//Jpa
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
//Mysql
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/fab/banggabgo/BanggabgoApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
@SpringBootApplication
public class BanggabgoApplication {

static {
System.setProperty("com.amazonaws.sdk.disableEc2Metadata", "true");
}
public static void main(String[] args) {
SpringApplication.run(BanggabgoApplication.class, args);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.fab.banggabgo.common.exception;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;

public class CustomAuthenticationEntryPoint implements AuthenticationEntryPoint {

@Override
public void commence(HttpServletRequest request, HttpServletResponse response,
AuthenticationException authException) throws IOException, ServletException {

response.sendRedirect("/api/exception");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ public enum ErrorCode implements Code {
*/
USER_IS_NULL(HttpStatus.BAD_REQUEST, "유저 정보를 불러오는데 실패했습니다."),

/**
* 프로필 에러코드
*/
INVALID_PROFILE(HttpStatus.BAD_REQUEST, "프로필이 존재하지 않습니다."),

/**
* 게시글 에러코드
*/
Expand Down Expand Up @@ -45,6 +50,8 @@ public enum ErrorCode implements Code {
*/
PATCH_MY_INFO_CONVERT_FAIL(HttpStatus.BAD_REQUEST, "내정보 데이터 변환오류"),
FAIL_INFO_LOADING(HttpStatus.BAD_REQUEST, "정보를 불러오지 못했습니다."),
AMAZON_S3_UPLOAD_ERROR(HttpStatus.BAD_REQUEST,"S3 이미지 업로드 중 문제가 발생했습니다." ),


/**
* Apply 에러코드
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/com/fab/banggabgo/config/S3Config.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.fab.banggabgo.config;

import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.s3.AmazonS3Client;
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;

@Bean
public AmazonS3Client amazonS3Client(){
BasicAWSCredentials awsCredentials = new BasicAWSCredentials(accessKey,secretKey);

return (AmazonS3Client) AmazonS3ClientBuilder.standard()
.withRegion(region)
.withCredentials(new AWSStaticCredentialsProvider(awsCredentials))
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.fab.banggabgo.config.security;

import com.fab.banggabgo.common.exception.CustomAuthenticationEntryPoint;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down Expand Up @@ -29,12 +30,16 @@ public SecurityFilterChain defaultFilter(HttpSecurity http) throws Exception {
.and()
.authorizeHttpRequests()
.antMatchers("/v3/api-docs/**", "/swagger-ui/**", "/swagger-resources/**").permitAll()
.antMatchers(HttpMethod.GET ,"/api/exception").permitAll()
.antMatchers("/api/users/recommend").authenticated()
.antMatchers("/api/users/**").permitAll()
.antMatchers(HttpMethod.GET ,"/api/articles/**").permitAll()
.antMatchers("/login/oauth2/**").permitAll()
.anyRequest().authenticated()

.and()
.exceptionHandling().authenticationEntryPoint(new CustomAuthenticationEntryPoint())

.and()
.addFilterBefore(new JwtAuthenticationFilter(jwtTokenProvider, redisTemplate),
UsernamePasswordAuthenticationFilter.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ public ResponseEntity<?> getArticle(
return ApiResponse.builder().code(ResponseCode.RESPONSE_SUCCESS).data(result).toEntity();
}

@GetMapping("/users/{userId}")
public ResponseEntity<?> getUserArticles(
@PathVariable int userId
) {
var result = articleService.getUserArticles(userId);
return ApiResponse.builder().code(ResponseCode.RESPONSE_SUCCESS).data(result).toEntity();
}

@PutMapping("/{id}")
public ResponseEntity<?> putArticle(
@AuthenticationPrincipal User user,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.fab.banggabgo.controller;

import com.fab.banggabgo.common.ApiResponse;
import com.fab.banggabgo.common.ResponseCode;
import com.fab.banggabgo.common.exception.CustomException;
import com.fab.banggabgo.common.exception.ErrorCode;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/exception")
public class ExceptionController {

@GetMapping
public ResponseEntity<?> getException() {
throw new CustomException(ErrorCode.USER_IS_NULL);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,24 @@
import com.fab.banggabgo.common.ResponseCode;
import com.fab.banggabgo.dto.mycontent.PatchMyInfoForm;
import com.fab.banggabgo.dto.mycontent.PatchMyNicknameForm;
import com.fab.banggabgo.dto.mycontent.PostMyInfoImageRequestDto;
import com.fab.banggabgo.entity.User;
import com.fab.banggabgo.service.MyContentService;
import java.io.IOException;
import javax.annotation.security.PermitAll;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequiredArgsConstructor
Expand Down Expand Up @@ -60,13 +65,22 @@ public ResponseEntity<?> patchMyInfo(@AuthenticationPrincipal User user,
return ApiResponse.builder().code(ResponseCode.RESPONSE_SUCCESS).data(result).toEntity();
}

@PostMapping(value = "/image", consumes = "multipart/form-data")
public ResponseEntity<?> postMyInfoImage(@AuthenticationPrincipal User user,
@RequestPart MultipartFile image) throws IOException {
var dto= PostMyInfoImageRequestDto.builder().image(image).build();
var result = myContentService.postMyInfoImage(user,dto);
return ApiResponse.builder().code(ResponseCode.RESPONSE_SUCCESS).data(result).toEntity();
}

@GetMapping("/from-applicants")
public ResponseEntity<?> getMyFromApplicant(@AuthenticationPrincipal User user,
@RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "10") Integer size) {
var result = myContentService.getMyFromApplicantList(user, page, size);
return ApiResponse.builder().code(ResponseCode.RESPONSE_SUCCESS).data(result).toEntity();
}

@GetMapping("/to-applicants")
public ResponseEntity<?> getMyToApplicantList(@AuthenticationPrincipal User user,
@RequestParam(defaultValue = "1") Integer page,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,37 @@
import com.fab.banggabgo.common.ApiResponse;
import com.fab.banggabgo.common.ResponseCode;
import com.fab.banggabgo.entity.User;
import com.fab.banggabgo.service.RecommendService;
import com.fab.banggabgo.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/users")
public class RecommendController {
public class UserController {

private final RecommendService recommendService;
private final UserService userService;

@GetMapping("/recommend")
@GetMapping("/recommendation")
public ResponseEntity<?> getRecommendUsers(
@AuthenticationPrincipal User user,
@RequestParam(defaultValue = "9") Integer size
) {
var result = recommendService.getRecommendUsers(user, size);
var result = userService.getRecommendUsers(user, size);
return ApiResponse.builder().code(ResponseCode.RESPONSE_SUCCESS).data(result).toEntity();
}

@GetMapping("/profile/{id}")
public ResponseEntity<?> getUserProfile(
@PathVariable int id
) {
var result = userService.getUserProfile(id);
return ApiResponse.builder().code(ResponseCode.RESPONSE_SUCCESS).data(result).toEntity();
}
}
26 changes: 26 additions & 0 deletions src/main/java/com/fab/banggabgo/dto/article/ArticleInfoDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.fab.banggabgo.dto.article;

import com.fab.banggabgo.entity.Article;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ArticleInfoDto {

private Integer id;
private String title;

public static ArticleInfoDto toDto(Article article) {
return ArticleInfoDto.builder()
.id(article.getId())
.title(article.getTitle())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
public class PatchMyInfoForm {

private String gender;
private int myAge;
private int minAge;
private int maxAge;
private Integer myAge;
private Integer minAge;
private Integer maxAge;
private boolean isSmoke;
private String mbti;
private String region;
private String activityTime;
private List<String> favoriteTag;
private String myText;

public static PatchMyInfoDto toDto(PatchMyInfoForm form){
return PatchMyInfoDto.builder()
public static PatchMyInfoRequestDto toDto(PatchMyInfoForm form){
return PatchMyInfoRequestDto.builder()
.gender(form.getGender())
.myAge(form.getMyAge())
.minAge(form.getMinAge())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class PatchMyInfoDto {
public class PatchMyInfoRequestDto {
private String gender;
private int myAge;
private int minAge;
private int maxAge;
private Integer myAge;
private Integer minAge;
private Integer maxAge;
private boolean isSmoke;
private String mbti;
private String region;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
@ToString
public class PatchMyInfoResultDto {
private String gender;
private int myAge;
private int minAge;
private int maxAge;
private Integer myAge;
private Integer minAge;
private Integer maxAge;
private boolean isSmoke;
private String mbti;
private String region;
Expand All @@ -32,6 +32,8 @@ public static PatchMyInfoResultDto from(User user) {
return PatchMyInfoResultDto.builder()
.gender(user.getGender().getValue())
.myAge(user.getMyAge())
.minAge(user.getMinAge())
.maxAge(user.getMaxAge())
.isSmoke(user.getIsSmoker())
.mbti(user.getMbti().name())
.region(user.getRegion().getValue())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
public class PatchMyNicknameForm {
private String nickname;

public static PatchMyNicknameDto toDto(PatchMyNicknameForm form){
return PatchMyNicknameDto.builder()
public static PatchMyNicknameRequestDto toDto(PatchMyNicknameForm form){
return PatchMyNicknameRequestDto.builder()
.nickname(form.getNickname())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class PatchMyNicknameDto {
public class PatchMyNicknameRequestDto {
private String nickname;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.fab.banggabgo.dto.mycontent;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.web.multipart.MultipartFile;

@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class PostMyInfoImageRequestDto {
private MultipartFile image;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.fab.banggabgo.dto.mycontent;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class PostMyInfoImageResultDto {
private String image;
}
Loading

0 comments on commit e5ef26d

Please sign in to comment.