Skip to content

Commit

Permalink
Merge branch 'develop' into badge
Browse files Browse the repository at this point in the history
  • Loading branch information
westzeroright authored Jan 17, 2025
2 parents 1cbe086 + a8ee2f7 commit df5fc63
Show file tree
Hide file tree
Showing 140 changed files with 2,443 additions and 401 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/chat-gpt-code-review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Code Review

permissions:
contents: read
pull-requests: write

# Pull Request ? ?? ? ??
# Pull Request ? ??? ??? ???? ??? ? ?
on:
pull_request:
types:
- opened
- synchronize

jobs:
code-review:
runs-on: ubuntu-latest
steps:
- uses: anc95/ChatGPT-CodeReview@main
env:
GITHUB_TOKEN : ${{secrets.BELLMIN_GITHUB_TOKEN}}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
LANGUAGE: Korean
MODEL: gpt-3.5-turbo
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.whoz_in.domain.device;

import com.whoz_in.domain.device.model.Device;
import java.util.List;
import com.whoz_in.domain.device.model.DeviceId;
import java.util.Optional;

public interface DeviceRepository {
void save(Device device);
List<Device> findAll();

//해당 mac을 포함하는 device를 찾는 메서드
Optional<Device> findByMac(String mac);
Optional<Device> findByDeviceId(DeviceId deviceId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.whoz_in.domain.device.event;

import com.whoz_in.domain.shared.event.DomainEvent;

public final class DeviceInfoRegistered extends DomainEvent {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.whoz_in.domain.device.exception;

import com.whoz_in.domain.shared.BusinessException;

public class DeviceAlreadyRegisteredException extends BusinessException {
public static final DeviceAlreadyRegisteredException EXCEPTION = new DeviceAlreadyRegisteredException();
private DeviceAlreadyRegisteredException() {
super("3030", "이미 등록된 기기입니다.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.whoz_in.domain.device.exception;

import com.whoz_in.domain.shared.BusinessException;

public class InvalidDeviceOwnerException extends BusinessException {
private InvalidDeviceOwnerException(String errorMessage) {
super("3020", errorMessage);
}

public static InvalidDeviceOwnerException of(String ownerName){
return new InvalidDeviceOwnerException(String.format("이 기기는 %s 회원의 기기입니다. 해당 회원에게 기기 삭제를 부탁하세요.", ownerName));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import com.whoz_in.domain.shared.BusinessException;

public class InvalidIPv4AddressException extends BusinessException {
public InvalidIPv4AddressException() {
public static final InvalidIPv4AddressException EXCEPTION = new InvalidIPv4AddressException();
private InvalidIPv4AddressException() {
super("3006", "유효하지 않은 IPv4 주소입니다.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import com.whoz_in.domain.shared.BusinessException;

public class InvalidMacAddressException extends BusinessException {
public InvalidMacAddressException() {
public static final InvalidMacAddressException EXCEPTION = new InvalidMacAddressException();
private InvalidMacAddressException() {
super("3005", "유효하지 않은 Mac 주소입니다.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.whoz_in.domain.device.exception;

import com.whoz_in.domain.shared.BusinessException;

public class NoDeviceException extends BusinessException {
public static final NoDeviceException EXCEPTION = new NoDeviceException();
private NoDeviceException() {
super("3001", "등록된 기기가 없습니다.");
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.whoz_in.domain.device.model;

import com.whoz_in.domain.device.event.DeviceCreated;
import com.whoz_in.domain.device.event.DeviceInfoRegistered;
import com.whoz_in.domain.member.model.MemberId;
import com.whoz_in.domain.shared.AggregateRoot;
import java.util.List;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
Expand All @@ -17,13 +19,22 @@ public final class Device extends AggregateRoot {
private final DeviceId id;
private final MemberId memberId; //양도 기능 생기면 final 제거
private String deviceName;
private final List<DeviceInfo> deviceInfos;
private final Set<DeviceInfo> deviceInfos;

public boolean isOwnedBy(MemberId memberId){
return this.getMemberId().equals(memberId);
}

public static Device create(MemberId memberId, List<DeviceInfo> deviceInfos, String deviceName){
public void registerDeviceInfo(DeviceInfo deviceInfo){
this.deviceInfos.add(deviceInfo);
this.register(new DeviceInfoRegistered());
}

public void registerDeviceInfo(Set<DeviceInfo> deviceInfos){
deviceInfos.forEach(this::registerDeviceInfo);
}

public static Device create(MemberId memberId, Set<DeviceInfo> deviceInfos, String deviceName){
Device device = Device.builder()
.id(new DeviceId(UUID.randomUUID()))
.memberId(memberId)
Expand All @@ -34,11 +45,11 @@ public static Device create(MemberId memberId, List<DeviceInfo> deviceInfos, Str
return device;
}

public static Device load(DeviceId id, MemberId memberId, List<DeviceInfo> deviceInfos, String deviceName){
public static Device load(DeviceId id, MemberId memberId, Set<DeviceInfo> deviceInfos, String deviceName){
return Device.builder()
.id(id)
.memberId(memberId)
.deviceInfos(deviceInfos)
.deviceInfos(new HashSet<>(deviceInfos))
.deviceName(deviceName)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@


import lombok.AccessLevel;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@EqualsAndHashCode
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public final class DeviceInfo {
private final String room;
private final String ssid;
@EqualsAndHashCode.Exclude
private final MacAddress mac;

public static DeviceInfo create(String room, String ssid, MacAddress mac){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public final class IpAddress {

public static IpAddress create(String address){
if (!isValid(address)) {
throw new InvalidIPv4AddressException();
throw InvalidIPv4AddressException.EXCEPTION;
}
return new IpAddress(address);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public final class MacAddress {

public static MacAddress create(String address){
if (!isValid(address)) {
throw new InvalidMacAddressException();
throw InvalidMacAddressException.EXCEPTION;
}
return new MacAddress(normalize(address));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.whoz_in.domain.device.service;

import com.whoz_in.domain.device.DeviceRepository;
import com.whoz_in.domain.device.exception.DeviceAlreadyRegisteredException;
import com.whoz_in.domain.device.exception.NoDeviceException;
import com.whoz_in.domain.device.model.Device;
import com.whoz_in.domain.device.model.DeviceId;
import com.whoz_in.domain.shared.DomainService;
import lombok.RequiredArgsConstructor;

@DomainService
@RequiredArgsConstructor
public class DeviceFinderService {
private final DeviceRepository deviceRepository;

public Device find(DeviceId deviceId){
return deviceRepository.findByDeviceId(deviceId).orElseThrow(()-> NoDeviceException.EXCEPTION);
}

public void mustNotExist(DeviceId deviceId){
if (deviceRepository.findByDeviceId(deviceId).isPresent())
throw DeviceAlreadyRegisteredException.EXCEPTION;
}

public void mustNotExistByMac(String mac){
if (deviceRepository.findByMac(mac).isPresent())
throw DeviceAlreadyRegisteredException.EXCEPTION;
}

}
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
package com.whoz_in.domain.device.service;

import com.whoz_in.domain.device.exception.InvalidDeviceOwnerException;
import com.whoz_in.domain.device.model.Device;
import com.whoz_in.domain.member.MemberRepository;
import com.whoz_in.domain.member.model.Member;
import com.whoz_in.domain.member.model.MemberId;
import com.whoz_in.domain.member.service.MemberFinderService;
import com.whoz_in.domain.shared.DomainService;
import lombok.RequiredArgsConstructor;

@DomainService
@RequiredArgsConstructor
public class DeviceOwnershipService {
private final MemberRepository memberRepository;
private final MemberFinderService memberFinderService;

public void validateOwnership(Device device, MemberId memberId){
//기기가 자신의 것이 맞는지 확인합니다.
public void validateIsMine(Device device, MemberId memberId){
if (device.isOwnedBy(memberId)) return;
Member deviceOwner = memberRepository.getByMemberId(device.getMemberId());
throw new IllegalArgumentException("이 기기는 " + deviceOwner.getName() + " 회원의 기기입니다.");
Member deviceOwner = memberFinderService.find(device.getMemberId());
throw InvalidDeviceOwnerException.of(deviceOwner.getName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,7 @@ public interface MemberRepository {
Optional<Member> findByMemberId(MemberId id);
List<Member> findByName(String name);
Optional<Member> findBySocialId(String socialId);
default Member getByLoginId(String loginId){
return findByLoginId(loginId).orElseThrow(NoMemberException::new);
}
default List<Member> getByName(String name){
List<Member> members = findByName(name);
if(members.isEmpty()) throw new NoMemberException();
return members;
}
default Member getByMemberId(MemberId id){
return findByMemberId(id).orElseThrow(NoMemberException::new);
}
default Member getBySocialId(String socialId){
return findBySocialId(socialId).orElseThrow(NoMemberException::new);
return findBySocialId(socialId).orElseThrow(()->NoMemberException.EXCEPTION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import com.whoz_in.domain.shared.BusinessException;

public class InvalidAuthCredentialsException extends BusinessException {

public InvalidAuthCredentialsException() {
public static final InvalidAuthCredentialsException EXCEPTION = new InvalidAuthCredentialsException();
private InvalidAuthCredentialsException() {
super("2003", "아이디 혹은 비밀번호가 틀렸습니다.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import com.whoz_in.domain.shared.BusinessException;

public class LoginIdPolicyViolationException extends BusinessException {

public LoginIdPolicyViolationException() {
public static final LoginIdPolicyViolationException EXCEPTION = new LoginIdPolicyViolationException();
private LoginIdPolicyViolationException() {
super("2001", "아이디는 알파벳 소문자, 숫자로 6자리 이상 16자리 이하여야 합니다.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import com.whoz_in.domain.shared.BusinessException;

public class NoMemberException extends BusinessException {

public NoMemberException() {
public static final NoMemberException EXCEPTION = new NoMemberException();
private NoMemberException() {
super("2008", "존재하지 않는 멤버입니다.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import com.whoz_in.domain.shared.BusinessException;

public class NotAuthMemberException extends BusinessException {
public NotAuthMemberException() {
public static final NotAuthMemberException EXCEPTION = new NotAuthMemberException();
private NotAuthMemberException() {
super("2006", "일반 로그인 정보가 없는 회원입니다.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import com.whoz_in.domain.shared.BusinessException;

public class NotOAuthMemberException extends BusinessException {

public NotOAuthMemberException() {
public static final NotOAuthMemberException EXCEPTION = new NotOAuthMemberException();
private NotOAuthMemberException() {
super("2007", "소셜 로그인 정보가 없는 회원입니다.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import com.whoz_in.domain.shared.BusinessException;

public class PasswordPolicyViolationException extends BusinessException {

public PasswordPolicyViolationException() {
public static final PasswordPolicyViolationException EXCEPTION = new PasswordPolicyViolationException();
private PasswordPolicyViolationException() {
super("2002", "비밀번호는 알파벳 소문자, 숫자로 6자리 이상 16자리 이하여야 합니다.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import com.whoz_in.domain.shared.BusinessException;

public class WrongPasswordException extends BusinessException {

public WrongPasswordException() {
public static final WrongPasswordException EXCEPTION = new WrongPasswordException();
private WrongPasswordException() {
super("2005", "틀린 비밀번호입니다.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static AccountType findAccountType(String accountType){
return Arrays.stream(AccountType.values())
.filter(at -> at.name().equals(accountType))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("no account type"));
.orElseThrow(() -> new IllegalStateException("no account type"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ public final class AuthCredentials {
public static AuthCredentials create(String loginId, String rawPassword, PasswordEncoder passwordEncoder){
//아이디가 정책에 맞는지 확인
if (!Pattern.matches(LOGIN_ID_REGEX, loginId))
throw new LoginIdPolicyViolationException();
throw LoginIdPolicyViolationException.EXCEPTION;
//비밀번호가 정책에 맞는지 확인
if (!Pattern.matches(PASSWORD_REGEX, rawPassword))
throw new PasswordPolicyViolationException();
throw PasswordPolicyViolationException.EXCEPTION;
return new AuthCredentials(loginId, passwordEncoder.encode(rawPassword));
}

Expand All @@ -41,10 +41,10 @@ AuthCredentials changePassword(String rawOldPassword, String rawNewPassword, Pas
String encodedOldPassword = passwordEncoder.encode(rawOldPassword);
//기존 비밀번호가 같은지 확인
if (!encodedPassword.equals(encodedOldPassword))
throw new WrongPasswordException();
throw WrongPasswordException.EXCEPTION;
//새로운 비밀번호가 정책에 맞는지 확인
if (!Pattern.matches(PASSWORD_REGEX, rawNewPassword))
throw new PasswordPolicyViolationException();
throw PasswordPolicyViolationException.EXCEPTION;
return new AuthCredentials(this.loginId, passwordEncoder.encode(rawNewPassword));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static Member load(MemberId id, String name, Position mainPosition, int g

public void changePassword(String rawOldPassword, String rawNewPassword, PasswordEncoder passwordEncoder){
if (authCredentials == null)
throw new NotAuthMemberException();
throw NotAuthMemberException.EXCEPTION;
this.authCredentials = this.authCredentials.changePassword(rawOldPassword, rawNewPassword, passwordEncoder);
this.register(new MemberPasswordChanged(this.getId(), this.authCredentials.getEncodedPassword()));
}
Expand Down
Loading

0 comments on commit df5fc63

Please sign in to comment.