Skip to content
This repository has been archived by the owner on Aug 13, 2022. It is now read-only.

[#29] Service Layer 단위테스트 작성 #30

Merged
merged 24 commits into from
Dec 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
dfc0cc1
[#29] Service Layer 단위테스트 작성
cyj199637 Oct 17, 2020
5d1a5f0
[#31] 팔로우 / 언팔로우 기능 구현
cyj199637 Oct 18, 2020
04ddb7c
Merge branch 'feature/27' into feature/29
cyj199637 Oct 18, 2020
4960907
Merge branch 'feature/29' into feature/31
cyj199637 Oct 18, 2020
aff451a
[#31] 알림 추가 기능 구현
cyj199637 Oct 18, 2020
01725c8
[#31] Follow 테이블 컬럼 변경된 이름 반영
cyj199637 Oct 19, 2020
0ac3f43
[#31] 피드백 반영
cyj199637 Oct 25, 2020
f1acd7b
Merge branch 'develop' into feature/29
cyj199637 Nov 2, 2020
b4dc709
[#29] 피드백 반영
cyj199637 Nov 16, 2020
60974a1
[#29] PostServiceTest의 피드 조회 성공, 피드 조회 실패 테스트 수정
cyj199637 Nov 16, 2020
563fa52
Merge branch 'develop' into feature/29
cyj199637 Nov 21, 2020
84b2fd9
[#29] 피드백 반영
cyj199637 Nov 21, 2020
a1de1bc
[#29] SessionLoginServiceTest 일부 테스트 로직 수정 및 테스트 케이스 추가
cyj199637 Nov 21, 2020
729e227
[#37] Firebase를 활용한 푸시 서비스 (#38)
cyj199637 Nov 26, 2020
d6c48f7
Merge branch 'feature/29' into feature/31
cyj199637 Nov 26, 2020
62ebbc4
Merge pull request #32 from f-lab-edu/feature/31
cyj199637 Nov 26, 2020
2ca0789
Merge branch 'develop' into feature/29
cyj199637 Dec 3, 2020
eca04e4
Merge branch 'feature/29' of https://github.com/f-lab-edu/sns-itda in…
cyj199637 Dec 3, 2020
17c3f71
[#29] Jenkins Failed Test Code 수정
cyj199637 Dec 3, 2020
70856dc
[#29] Jenkins Failed Test Code 수정
cyj199637 Dec 3, 2020
1d7c050
[#43] 추가된 단위 테스트에 따른 Service Layer 로직 수정 (#44)
cyj199637 Dec 6, 2020
3400848
[#29] UserControllerTest 코드 수정
cyj199637 Dec 10, 2020
b473ab9
Merge branch 'develop' into feature/29
cyj199637 Dec 18, 2020
7847135
[#29] Jenkins Failed Test Code 수정
cyj199637 Dec 18, 2020
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
12 changes: 11 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
<artifactId>firebase-admin</artifactId>
<version>6.8.1</version>
</dependency>

<!--
jasypt-spring-boot-starter
: jasypt를 사용하기 위한 스타터
Expand All @@ -159,6 +159,16 @@
<version>3.0.3</version>
</dependency>

<!--
spring-boot-starter-validation
: Bean Validation을 사용하기 위한 스타터
-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>


<!--
spring-boot-starter-test
: Spring Boot 애플리케이션을 테스트하기 위한 스타터
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/me/liiot/snsserver/config/RedisConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class RedisConfig {

@Bean
RedisConnectionFactory redisConnectionFactory() {

RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();
redisStandaloneConfiguration.setHostName(hostName);
redisStandaloneConfiguration.setPort(port);
Expand All @@ -30,6 +31,7 @@ RedisConnectionFactory redisConnectionFactory() {

@Bean
RedisTemplate<String, Object> redisTemplate() {

RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(redisConnectionFactory());
redisTemplate.setKeySerializer(new StringRedisSerializer());
Expand Down
16 changes: 13 additions & 3 deletions src/main/java/me/liiot/snsserver/controller/PostController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import lombok.RequiredArgsConstructor;
import me.liiot.snsserver.annotation.CheckLogin;
import me.liiot.snsserver.annotation.CurrentUser;
import me.liiot.snsserver.exception.NotExistUserIdException;
import me.liiot.snsserver.model.post.Post;
import me.liiot.snsserver.model.user.User;
import me.liiot.snsserver.service.PostService;
import me.liiot.snsserver.util.HttpResponses;
import org.springframework.expression.AccessException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -39,16 +41,24 @@ public ResponseEntity<Post> getPost(@PathVariable int postId) {

Post post = postService.getPost(postId);

return new ResponseEntity<>(post, HttpStatus.OK);
if (post == null) {
return RESPONSE_NOT_FOUND;
}

return ResponseEntity.ok(post);
}

@GetMapping
@CheckLogin
public ResponseEntity<List<Post>> getUserFeed(@RequestParam(value = "userId") String userId) {

List<Post> posts = postService.getPostsByUser(userId);
try {
List<Post> posts = postService.getPostsByUser(userId);

return new ResponseEntity<>(posts, HttpStatus.OK);
return ResponseEntity.ok(posts);
} catch (NotExistUserIdException e) {
return RESPONSE_NOT_FOUND;
}
}

@PatchMapping("/{postId}")
Expand Down
29 changes: 18 additions & 11 deletions src/main/java/me/liiot/snsserver/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@
import lombok.RequiredArgsConstructor;
import me.liiot.snsserver.annotation.CheckLogin;
import me.liiot.snsserver.annotation.CurrentUser;
import me.liiot.snsserver.exception.FileDeleteException;
import me.liiot.snsserver.exception.FileUploadException;
import me.liiot.snsserver.exception.*;
import me.liiot.snsserver.model.user.*;
import me.liiot.snsserver.service.LoginService;
import me.liiot.snsserver.exception.InvalidValueException;
import me.liiot.snsserver.exception.NotUniqueIdException;
import me.liiot.snsserver.service.UserService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;

import static me.liiot.snsserver.util.HttpResponses.*;

/*
Expand All @@ -24,6 +23,9 @@

@RequestMapping
: 요청 URL과 해당 URL을 처리할 클래스나 메소드에 연결

@Valid
: 클래스에 정의된 제약조건을 바탕으로 지정된 아규먼트에 대한 유효성 검사 실시
*/
@RestController
@RequiredArgsConstructor
Expand All @@ -35,7 +37,7 @@ public class UserController {
private final LoginService loginService;

@PostMapping
public ResponseEntity<Void> signUpUser(UserSignUpParam userSignUpParam) {
public ResponseEntity<Void> signUpUser(@Valid UserSignUpParam userSignUpParam) {

userService.signUpUser(userSignUpParam);
return RESPONSE_CREATED;
Expand All @@ -46,23 +48,28 @@ public ResponseEntity<Void> checkUserIdDupe(@PathVariable String userId) {

try {
userService.checkUserIdDupe(userId);
} catch (NotUniqueIdException e) {
} catch (NotUniqueUserIdException e) {
return RESPONSE_CONFLICT;
}
return RESPONSE_OK;
}

@PostMapping("/login")
public ResponseEntity<Void> loginUser(UserIdAndPassword userIdAndPassword) {
public ResponseEntity<Void> loginUser(@Valid UserIdAndPassword userIdAndPassword) {

User user = userService.getLoginUser(userIdAndPassword);

if (user == null) {
return RESPONSE_UNAUTHORIZED;
}

loginService.loginUser(user.getUserId());
return RESPONSE_OK;
try {
loginService.loginUser(user.getUserId());

return RESPONSE_OK;
} catch (AlreadyLoginException e) {
return RESPONSE_BAD_REQUEST;
}
}

@GetMapping("/logout")
Expand All @@ -74,7 +81,7 @@ public ResponseEntity<Void> logoutUser() {

@PutMapping("/my-account")
@CheckLogin
public ResponseEntity<String> updateUser(UserUpdateParam userUpdateParam,
public ResponseEntity<String> updateUser(@Valid UserUpdateParam userUpdateParam,
@RequestPart("profileImage") MultipartFile profileImage,
@CurrentUser User currentUser) {

Expand All @@ -89,7 +96,7 @@ public ResponseEntity<String> updateUser(UserUpdateParam userUpdateParam,

@PutMapping("/my-account/password")
@CheckLogin
public ResponseEntity<String> updateUserPassword(UserPasswordUpdateParam userPasswordUpdateParam,
public ResponseEntity<String> updateUserPassword(@Valid UserPasswordUpdateParam userPasswordUpdateParam,
@CurrentUser User currentUser) {

try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package me.liiot.snsserver.exception;

public class AlreadyLoginException extends RuntimeException {

public AlreadyLoginException() {
super();
}

public AlreadyLoginException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package me.liiot.snsserver.exception;

public class NotExistUserIdException extends RuntimeException {

public NotExistUserIdException() {
super();
}

public NotExistUserIdException(String message) {
super(message);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package me.liiot.snsserver.exception;

public class NotUniqueUserIdException extends RuntimeException {

public NotUniqueUserIdException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
import lombok.AllArgsConstructor;
import lombok.Getter;

import javax.validation.constraints.NotBlank;

@Getter
@AllArgsConstructor
public class UserIdAndPassword {

@NotBlank(message = "아이디를 입력해주세요.")
private final String userId;

@NotBlank(message = "비밀번호를 입력해주세요.")
private final String password;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
import lombok.AllArgsConstructor;
import lombok.Getter;

import javax.validation.constraints.NotBlank;

@Getter
@AllArgsConstructor
public class UserPasswordUpdateParam {

@NotBlank(message = "기존 비밀번호를 입력해주세요.")
private final String existPassword;

@NotBlank(message = "새로운 비밀번호를 입력해주세요.")
private final String newPassword;

@NotBlank(message = "새로운 비밀번호를 한 번 더 입력해주세요.")
private final String checkNewPassword;
}
19 changes: 19 additions & 0 deletions src/main/java/me/liiot/snsserver/model/user/UserSignUpParam.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,40 @@
import lombok.Builder;
import lombok.Getter;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
import java.sql.Date;

/*
@NotBlank
: 지정된 필드 값이 비어있는지 확인

@Pattern
: 지정된 필드 값이 사용자가 정의한 형식인지 확인

@Email
: 지정된 필드 값이 이메일 형식인지 확인
*/
@Getter
@Builder
@AllArgsConstructor
public class UserSignUpParam {

@NotBlank(message = "아이디를 입력해주세요.")
private final String userId;

@NotBlank(message = "비밀번호를 입력해주세요.")
private final String password;

@NotBlank(message = "이름을 입력해주세요.")
private final String name;

@NotBlank(message = "핸드폰 번호를 입력해주세요.")
@Pattern(regexp = "[0-9]{10,11}", message = "핸드폰 번호는 10~11자리의 숫자만 입력해주세요.")
private final String phoneNumber;

@Email(message = "이메일 형식에 맞춰 입력해주세요.")
private final String email;

private final Date birth;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,24 @@
import lombok.Builder;
import lombok.Getter;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
import java.sql.Date;

@Getter
@Builder
@AllArgsConstructor
public class UserUpdateParam {

@NotBlank(message = "이름을 입력해주세요.")
private final String name;

@NotBlank(message = "핸드폰 번호를 입력해주세요.")
@Pattern(regexp = "[0-9]{10,11}", message = "핸드폰 번호는 10~11자리의 숫자만 입력해주세요.")
private final String phoneNumber;

@Email(message = "이메일 형식에 맞춰 입력해주세요.")
private final String email;

private final Date birth;
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/me/liiot/snsserver/service/AwsFileService.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public List<Image> getImages(int postId) {

@Override
public void deleteFile(String filePath) {

if (filePath != null) {
String key = filePath.substring(baseUrl.length());

Expand All @@ -104,7 +105,8 @@ public void deleteFile(String filePath) {
}

@Override
public void deleteDirectory(String userId) {
public void deleteDirectory(String userId) throws FileDeleteException {

ListObjectsRequest listObjects = ListObjectsRequest
.builder()
.bucket(bucket)
Expand All @@ -122,7 +124,8 @@ public void deleteDirectory(String userId) {
}

@Override
public void deleteImages(int postId) {
public void deleteImages(int postId) throws FileDeleteException {

List<String> imagePaths = fileMapper.getImagePaths(postId);

List<ObjectIdentifier> toDelete = imagePaths.stream()
Expand All @@ -134,7 +137,7 @@ public void deleteImages(int postId) {
fileMapper.deleteImages(postId);
}

private FileInfo createFileInfo(MultipartFile file, String userId, String newFileName) {
private FileInfo createFileInfo(MultipartFile file, String userId, String newFileName) throws FileUploadException {
StringBuilder key = new StringBuilder();
key.append(userId).append("/").append(newFileName);

Expand Down Expand Up @@ -162,7 +165,7 @@ private FileInfo createFileInfo(MultipartFile file, String userId, String newFil
}
}

private void sendDeleteObjectsRequest(List<ObjectIdentifier> toDelete) {
private void sendDeleteObjectsRequest(List<ObjectIdentifier> toDelete) throws FileDeleteException {

try {
DeleteObjectsRequest request = DeleteObjectsRequest.builder()
Expand Down
Loading