Skip to content

Commit

Permalink
Merge pull request #167 from dnd-side-project/refactor/#166
Browse files Browse the repository at this point in the history
overall code formatting
  • Loading branch information
miraexhoi authored Sep 26, 2024
2 parents 5a5a6db + 37571d8 commit 837e452
Show file tree
Hide file tree
Showing 95 changed files with 511 additions and 412 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ public ReadAccountInfoDto findBy(String email) {

private Account findAccount(String email) {
return accountRepository.findBy(email)
.orElseThrow(AccountUnauthorizedException::new);
.orElseThrow(AccountUnauthorizedException::new);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public class ValidateAccountService {

public boolean isValidAccount(String email) {
return accountRepository.findBy(email)
.isPresent();
.isPresent();
}
}
11 changes: 6 additions & 5 deletions src/main/java/com/dnd/spaced/domain/account/domain/Company.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.dnd.spaced.domain.account.domain;

import com.dnd.spaced.domain.account.domain.exception.InvalidCompanyException;

import java.util.Arrays;

import lombok.Getter;

@Getter
Expand All @@ -12,8 +14,7 @@ public enum Company {
STARTUP("스타트업"),
FOREIGN("외국계"),
JOB_HUNTER_INTERN("취준생/인턴"),
BLIND("비공개")
;
BLIND("비공개");

private final String name;

Expand All @@ -23,8 +24,8 @@ public enum Company {

public static Company find(String name) {
return Arrays.stream(Company.values())
.filter(company -> company.name.equals(name))
.findAny()
.orElseThrow(InvalidCompanyException::new);
.filter(company -> company.name.equals(name))
.findAny()
.orElseThrow(InvalidCompanyException::new);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.dnd.spaced.domain.account.domain;

import com.dnd.spaced.domain.account.domain.exception.InvalidExperienceException;

import java.util.Arrays;

import lombok.Getter;

@Getter
Expand All @@ -13,8 +15,7 @@ public enum Experience {
BETWEEN_THIRD_FOURTH("3~4년 차"),
BETWEEN_FOURTH_FIFTH("4~5년 차"),
OVER_FIFTH("5년 차 이상"),
BLIND("비공개")
;
BLIND("비공개");

private final String name;

Expand All @@ -24,8 +25,8 @@ public enum Experience {

public static Experience find(String name) {
return Arrays.stream(Experience.values())
.filter(experience -> experience.name.equals(name))
.findAny()
.orElseThrow(InvalidExperienceException::new);
.filter(experience -> experience.name.equals(name))
.findAny()
.orElseThrow(InvalidExperienceException::new);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.dnd.spaced.domain.account.domain;

import com.dnd.spaced.domain.account.domain.exception.InvalidJobGroupException;

import java.util.Arrays;

import lombok.Getter;

@Getter
Expand All @@ -16,8 +18,8 @@ public enum JobGroup {

public static JobGroup find(String name) {
return Arrays.stream(JobGroup.values())
.filter(jobGroup -> jobGroup.name.equals(name))
.findAny()
.orElseThrow(InvalidJobGroupException::new);
.filter(jobGroup -> jobGroup.name.equals(name))
.findAny()
.orElseThrow(InvalidJobGroupException::new);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.dnd.spaced.domain.account.domain;

import com.dnd.spaced.domain.account.domain.exception.InvalidRoleNameException;

import java.util.Arrays;

public enum Role {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.dnd.spaced.domain.account.domain.repository;

import com.dnd.spaced.domain.account.domain.Account;

import java.util.Optional;

public interface AccountRepository {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.dnd.spaced.domain.account.domain.repository;

import com.dnd.spaced.domain.account.domain.NicknameMetadata;

import java.util.Optional;

public interface NicknameMetadataRepository {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import com.dnd.spaced.domain.account.domain.Account;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.impl.JPAQueryFactory;

import java.util.Optional;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

Expand All @@ -24,8 +26,8 @@ public Account save(Account account) {
@Override
public Optional<Account> findBy(String email) {
Account result = queryFactory.selectFrom(account)
.where(eqEmail(email))
.fetchOne();
.where(eqEmail(email))
.fetchOne();

return Optional.ofNullable(result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import com.dnd.spaced.domain.account.domain.NicknameMetadata;
import com.querydsl.jpa.impl.JPAQueryFactory;
import jakarta.persistence.LockModeType;

import java.util.Optional;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

Expand All @@ -25,9 +27,9 @@ public NicknameMetadata save(NicknameMetadata nicknameMetadata) {
@Override
public Optional<NicknameMetadata> findBy(String nickname) {
NicknameMetadata result = queryFactory.selectFrom(nicknameMetadata)
.where(nicknameMetadata.nickname.eq(nickname))
.setLockMode(LockModeType.PESSIMISTIC_READ)
.fetchOne();
.where(nicknameMetadata.nickname.eq(nickname))
.setLockMode(LockModeType.PESSIMISTIC_READ)
.fetchOne();

return Optional.ofNullable(result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@ public class AdminService {
private final AdminRepository adminRepository;

public List<AdminWordResponse> findAllBy(AdminWordConditionInfoDto dto) {
AdminWordConditionDto adminWordConditionDto = AdminRepositoryMapper.to(
dto.categoryName(),
dto.lastWordName(),
dto.pageable()
);
AdminWordConditionDto adminWordConditionDto = AdminRepositoryMapper.to(dto.categoryName(), dto.lastWordName(), dto.pageable());
List<Word> result = adminRepository.findAllBy(adminWordConditionDto);

return AdminServiceMapper.toAdminWordResponseList(result);
Expand Down Expand Up @@ -84,9 +80,7 @@ public void ignoreReport(Long reportId) {
public List<ReportInfoDto> findReports(Long lastReportId) {
List<Report> reports = reportRepository.findReportsAfterId(lastReportId, PAGE_SIZE);

return reports.stream()
.map(AdminServiceMapper::toReportInfoDto)
.toList();
return reports.stream().map(AdminServiceMapper::toReportInfoDto).toList();
}

public AdminWordResponse getWord(Long wordId) {
Expand All @@ -95,18 +89,15 @@ public AdminWordResponse getWord(Long wordId) {
}

private Report getReport(Long reportId) {
return reportRepository.findById(reportId)
.orElseThrow(ReportedCommentNotFoundException::new);
return reportRepository.findById(reportId).orElseThrow(ReportedCommentNotFoundException::new);
}

private Comment getComment(Long commentId) {
return commentRepository.findBy(commentId)
.orElseThrow(CommentNotFoundException::new);
return commentRepository.findBy(commentId).orElseThrow(CommentNotFoundException::new);
}

private Word findWordById(Long wordId) {
return wordRepository.findBy(wordId)
.orElseThrow(WordNotFoundException::new);
return wordRepository.findBy(wordId).orElseThrow(WordNotFoundException::new);
}

private void validateReportExists(Long reportId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.dnd.spaced.domain.admin.application;
package com.dnd.spaced.domain.admin.application;

import com.dnd.spaced.domain.admin.application.dto.request.AdminWordConditionInfoDto;
import com.dnd.spaced.domain.admin.application.dto.request.AdminWordRequestDto;
Expand All @@ -10,18 +10,19 @@
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.springframework.data.domain.Pageable;

import java.util.List;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class AdminServiceMapper {

public static AdminWordConditionInfoDto to(
String categoryName,
String lastWordName,
Pageable pageable
) {
return new AdminWordConditionInfoDto(categoryName, lastWordName, pageable);
}
public static AdminWordConditionInfoDto to(
String categoryName,
String lastWordName,
Pageable pageable
) {
return new AdminWordConditionInfoDto(categoryName, lastWordName, pageable);
}

public static List<AdminWordResponse> toAdminWordResponseList(List<Word> words) {
return words.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@
public record AdminWordConditionInfoDto(
String categoryName,
String lastWordName,
Pageable pageable)
{
Pageable pageable) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ public record AdminWordRequestDto(

@Schema(description = "등록할 용어 출처")
String resource
) {}
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@

public class ReportNotFoundException extends BaseClientException {

public ReportNotFoundException() {super(ExceptionCode.REPORT_NOT_FOUND);}
public ReportNotFoundException() {
super(ExceptionCode.REPORT_NOT_FOUND);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@

public interface AdminRepository {
List<Word> findAllBy(AdminWordConditionDto adminWordConditionDto);

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

@Repository
@RequiredArgsConstructor
public class QuerydslAdminRepository implements AdminRepository{
public class QuerydslAdminRepository implements AdminRepository {

private static final String SORT_CONDITION = "name";
private static final String IGNORE_CATEGORY = "전체 실무";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@
public record AdminWordConditionDto(
String categoryName,
String lastWordName,
Pageable pageable)
{
Pageable pageable) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ public record AdminWordResponse(

@Schema(description = "출처")
String resource
) {}
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
import com.dnd.spaced.domain.auth.domain.TokenType;
import com.dnd.spaced.domain.auth.infrastructure.JwtDecoder;
import com.dnd.spaced.domain.auth.infrastructure.PrivateClaims;

import java.time.LocalDateTime;
import java.util.Map;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -35,7 +37,7 @@ public void saveCareerInfo(String email, String jobGroup, String company, String

public TokenDto refreshToken(String refreshToken) {
PrivateClaims privateClaims = tokenDecoder.decode(TokenType.REFRESH, refreshToken)
.orElseThrow(ExpiredTokenException::new);
.orElseThrow(ExpiredTokenException::new);
String generateAccessToken = tokenEncoder.encode(
LocalDateTime.now(),
TokenType.ACCESS,
Expand All @@ -59,6 +61,6 @@ public void withdrawal(String email) {

private Account findAccount(String email) {
return accountRepository.findBy(email)
.orElseThrow(ForbiddenAccountException::new);
.orElseThrow(ForbiddenAccountException::new);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.dnd.spaced.domain.auth.domain;

import com.dnd.spaced.domain.auth.infrastructure.PrivateClaims;

import java.util.Optional;

public interface TokenDecoder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
import io.jsonwebtoken.JwtException;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.security.Keys;

import java.nio.charset.StandardCharsets;
import java.util.Optional;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

Expand All @@ -30,7 +32,7 @@ public Optional<PrivateClaims> decode(TokenType tokenType, String token) {
validateBearerToken(token);

return this.parse(tokenType, token)
.map(this::convert);
.map(this::convert);
}

private void validateBearerToken(String token) {
Expand All @@ -55,10 +57,10 @@ private Optional<Claims> parse(TokenType tokenType, String token) {
try {
return Optional.of(
Jwts.parserBuilder()
.setSigningKey(Keys.hmacShaKeyFor(key.getBytes(StandardCharsets.UTF_8)))
.build()
.parseClaimsJws(findPureToken(token))
.getBody()
.setSigningKey(Keys.hmacShaKeyFor(key.getBytes(StandardCharsets.UTF_8)))
.build()
.parseClaimsJws(findPureToken(token))
.getBody()
);
} catch (JwtException ignored) {
return Optional.empty();
Expand Down
Loading

0 comments on commit 837e452

Please sign in to comment.