Skip to content

Commit

Permalink
Merge branch 'main' into 342-fcm-setting-refector
Browse files Browse the repository at this point in the history
  • Loading branch information
lyutvs authored Mar 2, 2022
2 parents 2c04f01 + 5bb8c5f commit dab17ba
Show file tree
Hide file tree
Showing 194 changed files with 3,901 additions and 1,030 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build on Dockerhub
- name: Docker Build
run: docker build -t teamwalkhub/walkhub-server .

- name: Push on Dockerhub
Expand Down
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ dependencies {
implementation 'org.hibernate:hibernate-ehcache:5.4.30.Final'
implementation 'org.hibernate:hibernate-jcache:5.6.5.Final'
implementation 'org.ehcache:ehcache:3.9.2'

}

test {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.walkhub.walkhub.domain.auth.exception;

import com.walkhub.walkhub.global.error.exception.ErrorCode;
import com.walkhub.walkhub.global.error.exception.WalkhubException;

public class PhoneNumberNotFoundException extends WalkhubException {

public static final WalkhubException EXCEPTION =
new PhoneNumberNotFoundException();

private PhoneNumberNotFoundException() {
super(ErrorCode.PHONE_NUMBER_NOT_FOUND);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.walkhub.walkhub.domain.auth.presentation;

import com.walkhub.walkhub.domain.auth.presentation.dto.request.CheckAuthCodeRequest;
import com.walkhub.walkhub.domain.auth.presentation.dto.request.CheckAccountIdRequest;
import com.walkhub.walkhub.domain.auth.presentation.dto.request.SignInRequest;
import com.walkhub.walkhub.domain.auth.presentation.dto.response.UserAccessTokenResponse;
import com.walkhub.walkhub.domain.auth.presentation.dto.response.UserTokenResponse;
import com.walkhub.walkhub.domain.auth.service.CheckAccountIdExistsService;
import com.walkhub.walkhub.domain.auth.service.CheckAuthCodeExistsService;
import com.walkhub.walkhub.domain.auth.service.TokenRefreshService;
import com.walkhub.walkhub.domain.auth.service.UserSignInService;
import lombok.RequiredArgsConstructor;
Expand All @@ -11,25 +15,38 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RequiredArgsConstructor
@RestController
@RequestMapping("/users/token")
@RequestMapping("/users")
public class AuthController {

private final UserSignInService userSignInService;
private final TokenRefreshService tokenRefreshService;
private final CheckAccountIdExistsService checkAccountIdExistsService;
private final CheckAuthCodeExistsService checkAuthCodeExistsService;

@PostMapping
@PostMapping("/token")
public UserTokenResponse userSignIn(@RequestBody @Valid SignInRequest request) {
return userSignInService.execute(request);
}

@PatchMapping
@PatchMapping("/token")
public UserAccessTokenResponse userTokenRefresh(@RequestHeader("Refresh-Token") String refreshToken) {
return tokenRefreshService.execute(refreshToken);
}

@RequestMapping(value = "/account-id", method = RequestMethod.HEAD)
public void checkAccountIdExists(@RequestBody @Valid CheckAccountIdRequest request) {
checkAccountIdExistsService.execute(request);
}

@RequestMapping(value = "/verification-codes", method = RequestMethod.HEAD)
public void checkAuthCodeExists(@RequestBody @Valid CheckAuthCodeRequest request) {
checkAuthCodeExistsService.execute(request);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.walkhub.walkhub.domain.auth.presentation.dto.request;

import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotBlank;

@Getter
@NoArgsConstructor
public class CheckAccountIdRequest {
@NotBlank(message = "account_id는 Null, 공백, 띄어쓰기를 허용하지 않습니다.")
private String accountId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.walkhub.walkhub.domain.auth.presentation.dto.request;

import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotBlank;

@Getter
@NoArgsConstructor
public class CheckAuthCodeRequest {

@NotBlank(message = "phone_number는 Null, 공백, 띄어쓰기를 허용하지 않습니다.")
private String phoneNumber;

@NotBlank(message = "auth_code는 Null, 공백, 띄어쓰기를 허용하지 않습니다.")
private String authCode;

}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.walkhub.walkhub.domain.auth.presentation.dto.response;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Builder;
import lombok.Getter;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDateTime;
import java.time.ZonedDateTime;

@Getter
@Builder
public class UserAccessTokenResponse {

private final String accessToken;

@DateTimeFormat(pattern = "yyyy-MM-ddThh:mm:SS")
private final LocalDateTime expiredAt;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss")
private final ZonedDateTime expiredAt;
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
package com.walkhub.walkhub.domain.auth.presentation.dto.response;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.walkhub.walkhub.domain.user.domain.type.Sex;
import com.walkhub.walkhub.global.enums.Authority;
import lombok.Builder;
import lombok.Getter;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDateTime;
import java.math.BigDecimal;
import java.time.ZonedDateTime;

@Getter
@Builder
public class UserTokenResponse {

private final String accessToken;

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss")
private final ZonedDateTime expiredAt;
private final String refreshToken;

@DateTimeFormat(pattern = "yyyy-MM-ddThh:mm:SS")
private final LocalDateTime expiredAt;

private final Authority authority;
private final BigDecimal height;
private final Integer weight;
private final Sex sex;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.walkhub.walkhub.domain.auth.service;

import com.walkhub.walkhub.domain.auth.presentation.dto.request.CheckAccountIdRequest;
import com.walkhub.walkhub.domain.user.facade.UserFacade;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@RequiredArgsConstructor
@Service
public class CheckAccountIdExistsService {

private final UserFacade userFacade;

public void execute(CheckAccountIdRequest request) {
userFacade.checkUserExists(request.getAccountId());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.walkhub.walkhub.domain.auth.service;

import com.walkhub.walkhub.domain.auth.exception.PhoneNumberNotFoundException;
import com.walkhub.walkhub.domain.auth.presentation.dto.request.CheckAuthCodeRequest;
import com.walkhub.walkhub.domain.user.domain.UserAuthCode;
import com.walkhub.walkhub.domain.user.domain.repository.UserAuthCodeRepository;
import com.walkhub.walkhub.domain.user.exception.UserAuthCodeNotFoundException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@RequiredArgsConstructor
@Service
public class CheckAuthCodeExistsService {

private final UserAuthCodeRepository userAuthCodeRepository;

public void execute(CheckAuthCodeRequest request) {
UserAuthCode authCode = userAuthCodeRepository.findById(request.getPhoneNumber())
.orElseThrow(() -> PhoneNumberNotFoundException.EXCEPTION);

if (!authCode.getCode().equals(request.getAuthCode())) {
throw UserAuthCodeNotFoundException.EXCEPTION;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.time.ZonedDateTime;

@RequiredArgsConstructor
@Service
Expand All @@ -29,7 +29,7 @@ public UserAccessTokenResponse execute(String refreshToken) {
String accessToken = jwtTokenProvider.generateAccessToken(redisRefreshToken.getAccountId());
return UserAccessTokenResponse.builder()
.accessToken(accessToken)
.expiredAt(LocalDateTime.now().plusSeconds(jwtProperties.getAccessExp()))
.expiredAt(ZonedDateTime.now().plusSeconds(jwtProperties.getAccessExp()))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.walkhub.walkhub.domain.auth.service;

import com.walkhub.walkhub.domain.auth.domain.RefreshToken;
import com.walkhub.walkhub.domain.auth.domain.repository.RefreshTokenRepository;
import com.walkhub.walkhub.domain.auth.exception.PasswordMismatchException;
import com.walkhub.walkhub.domain.auth.presentation.dto.request.SignInRequest;
import com.walkhub.walkhub.domain.auth.presentation.dto.response.UserTokenResponse;
import com.walkhub.walkhub.domain.user.domain.User;
import com.walkhub.walkhub.domain.user.domain.repository.UserRepository;
import com.walkhub.walkhub.domain.user.domain.type.HealthInfo;
import com.walkhub.walkhub.domain.user.exception.UserNotFoundException;
import com.walkhub.walkhub.global.security.jwt.JwtProperties;
import com.walkhub.walkhub.global.security.jwt.JwtTokenProvider;
Expand All @@ -15,23 +14,22 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.time.ZonedDateTime;

@RequiredArgsConstructor
@Service
public class UserSignInService {

private final UserRepository userRepository;
private final JwtProperties jwtProperties;
private final RefreshTokenRepository refreshTokenRepository;
private final JwtTokenProvider jwtTokenProvider;
private final PasswordEncoder passwordEncoder;

@Transactional
public UserTokenResponse execute(SignInRequest request) {
User user = userRepository.findByAccountId(request.getAccountId())
.orElseThrow(() -> UserNotFoundException.EXCEPTION);

HealthInfo healthInfo = user.getHealthInfo();
if (!passwordEncoder.matches(request.getPassword(), user.getPassword())) {
throw PasswordMismatchException.EXCEPTION;
}
Expand All @@ -41,20 +39,14 @@ public UserTokenResponse execute(SignInRequest request) {
String accessToken = jwtTokenProvider.generateAccessToken(user.getAccountId());
String refreshToken = jwtTokenProvider.generateRefreshToken(user.getAccountId());


refreshTokenRepository.save(
RefreshToken.builder()
.accountId(user.getAccountId())
.token(refreshToken)
.timeToLive(jwtProperties.getRefreshExp())
.build()
);

return UserTokenResponse.builder()
.accessToken(accessToken)
.expiredAt(LocalDateTime.now().plusSeconds(jwtProperties.getAccessExp()))
.expiredAt(ZonedDateTime.now().plusSeconds(jwtProperties.getAccessExp()))
.refreshToken(refreshToken)
.authority(user.getAuthority())
.height(healthInfo.getHeight())
.weight(healthInfo.getWeight())
.sex(user.getSex())
.build();
}

Expand Down
13 changes: 10 additions & 3 deletions src/main/java/com/walkhub/walkhub/domain/badge/domain/Badge.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
import org.hibernate.annotations.ColumnDefault;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.persistence.OneToMany;
import java.util.List;

Expand All @@ -26,18 +27,24 @@ public class Badge extends BaseTimeEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(length = 20, nullable = false)
@NotNull
@Size(max = 20)
private String name;

@ColumnDefault(DefaultImage.BADGE_IMAGE)
private String imageUrl;

@NotNull
private String unlockCondition;

@OneToMany(mappedBy = "badge", cascade = CascadeType.REMOVE)
private List<BadgeCollection> badgeCollections;

@Builder
public Badge(String name, String imageUrl) {
public Badge(String name, String imageUrl,
String unlockCondition) {
this.name = name;
this.imageUrl = imageUrl;
this.unlockCondition = unlockCondition;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import com.walkhub.walkhub.domain.user.domain.User;
import org.springframework.data.repository.CrudRepository;

import java.util.List;
import java.util.Optional;

public interface BadgeCollectionRepository extends CrudRepository<BadgeCollection, BadgeCollectionId> {

List<BadgeCollection> findAllByUserId(Long userId);
Optional<BadgeCollection> findByBadgeIdAndUser(Long badgeId, User user);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.walkhub.walkhub.domain.badge.domain.repository;

import com.walkhub.walkhub.domain.badge.domain.repository.vo.ClaimBadgeVO;
import com.walkhub.walkhub.domain.badge.domain.repository.vo.DefaultBadgeVO;
import com.walkhub.walkhub.domain.badge.domain.repository.vo.MyBadgeVo;

import java.util.List;

public interface CustomBadgeRepository {
List<ClaimBadgeVO> findAllByBadgeCollectionsNotIn(Long userId);
List<DefaultBadgeVO> findAllByBadgeCollectionsNotIn(Long userId);
List<MyBadgeVo> findAllByBadgeCollections(Long userId);
}
Loading

0 comments on commit dab17ba

Please sign in to comment.