Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] Member, Auth 엔티티, 패키지 구조 설정 #13

Closed
wants to merge 12 commits into from
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.whoz_in.api.auth;

public class AuthController {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.whoz_in.api.device;


import com.whoz_in.domain.device.application.DeviceService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
public class DeviceController {
private final DeviceService deviceService;

@PostMapping("/device")
public ResponseEntity<?> test(){
deviceService.save();
return ResponseEntity.ok().body("test");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.whoz_in.api.memebr;

public class MemberController {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.whoz_in.api.shared;

import java.io.Serializable;
import lombok.AllArgsConstructor;
import lombok.Getter;

public class ApiResponseBody {
@Getter
@AllArgsConstructor
public static class FailureBody implements Serializable {
private String status;
private String code;
private String message;
}

@Getter
@AllArgsConstructor
public static class SuccessBody<D> implements Serializable {
private D data;
private String message;
private String code;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.whoz_in.domain.shared.domain.bus.command.CommandBus;
import com.whoz_in.domain.shared.domain.bus.query.Query;
import com.whoz_in.domain.shared.domain.bus.query.QueryBus;
import com.whoz_in.domain.shared.domain.bus.query.Response;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//package com.gyuzal.whozin.shared.infrastructure.presentation;
//
//import java.util.List;
//import lombok.experimental.UtilityClass;
//import org.springframework.http.HttpStatus;
//import org.springframework.http.ResponseEntity;
//import org.springframework.validation.BindingResult;
//import org.springframework.validation.FieldError;
//
//@UtilityClass
//public class ResponseEntityGenerator {
//
// public static ResponseEntity<ApiResponseBody.SuccessBody<Void>> success(
// final HttpStatus status) {
// return new ResponseEntity<>(
// new ApiResponseBody.SuccessBody<>(null, , ), status);
// }
//
// public static <D> ResponseEntity<ApiResponseBody.SuccessBody<D>> success(
// D data, HttpStatus status, ) {
// return new ResponseEntity<>(
// new ApiResponseBody.SuccessBody<>(data, code.getMessage(), code.getCode()), status);
// }
//
// public static ResponseEntity<ApiResponseBody.FailureBody> fail(
// String message, String code, HttpStatus status) {
// return new ResponseEntity<>(
// new ApiResponseBody.FailureBody(String.valueOf(status.value()), code, message), status);
// }
//
// public static ResponseEntity<ApiResponseBody.FailureBody> fail(
// BindingResult bindingResult, String code, HttpStatus status) {
// return new ResponseEntity<>(
// new ApiResponseBody.FailureBody(
// String.valueOf(status.value()), code, createErrorMessage(bindingResult)),
// status);
// }
//
// private static String createErrorMessage(BindingResult bindingResult) {
// StringBuilder sb = new StringBuilder();
// boolean isFirst = true;
//
// List<FieldError> fieldErrors = bindingResult.getFieldErrors();
// for (FieldError fieldError : fieldErrors) {
// if (!isFirst) {
// sb.append(", ");
// } else {
// isFirst = false;
// }
// sb.append("[");
// sb.append(fieldError.getField());
// sb.append("] ");
// sb.append(fieldError.getDefaultMessage());
// }
//
// return sb.toString();
// }
//}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.whoz_in.domain.auth.application;

public class AuthService {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.whoz_in.domain.auth.domain;

import com.whoz_in.domain.shared.domain.AggregateRoot;

public class Auth extends AggregateRoot {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.whoz_in.domain.auth.domain;

public interface AuthRepository {
void save();

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

import com.whoz_in.domain.device.domain.DeviceRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class DeviceService {
private final DeviceRepository deviceRepository;

public void save(){
deviceRepository.save();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.whoz_in.domain.member.application;

public class MemberService {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.whoz_in.domain.member.domain;

import com.whoz_in.domain.shared.domain.AggregateRoot;

public class Member extends AggregateRoot {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.whoz_in.domain.member.domain;

public interface MemberRepository {
void save();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.whoz_in.infra.jpa.auth;

import com.whoz_in.domain.auth.domain.Auth;
import com.whoz_in.infra.jpa.member.MemberEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.OneToOne;

@Entity
public class AuthEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

// 회원은 여러 계정을 만들 수 있지만
// 계정 하나당 회원 정보 하나씩 고유로 가지므로 일대일
@OneToOne
@JoinColumn(name = "member_id")
private MemberEntity memberEntity;

@Column(name = "name", nullable = false)
private String loginId;

@Column(name = "name", nullable = false)
private String password;

protected AuthEntity() { }

public AuthEntity(MemberEntity memberEntity, String loginId, String password) {
this.memberEntity = memberEntity;
this.loginId = loginId;
this.password = password;
}

public Long getId() {
return id;
}

public MemberEntity getMemberEntity() {
return memberEntity;
}

public String getLoginId() {
return loginId;
}

public String getPassword() {
return password;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.whoz_in.infra.jpa.auth;

import com.whoz_in.domain.auth.domain.AuthRepository;
import org.springframework.stereotype.Repository;

@Repository
public class AuthJpaAdapter implements AuthRepository {

@Override
public void save() {
System.out.println("1");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.whoz_in.infra.jpa.auth;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

public interface AuthJpaRepository extends JpaRepository<AuthEntity, Long> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ public class DeviceJpaAdapter implements DeviceRepository {

@Override
public void save(Device device) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.whoz_in.infra.jpa.member;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;

@Entity
public class MemberEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(name = "name", nullable = false)
private String name;

@Column(name = "generation", nullable = false)
private int generation;

@Column(name = "position", nullable = false)
private String position;

@Column(name = "status_message", nullable = false)
private String statusMessage;

public MemberEntity(String name, int generation, String position, String statusMessage) {
this.name = name;
this.generation = generation;
this.position = position;
this.statusMessage = statusMessage;
}

protected MemberEntity() { }

public Long getId() {
return id;
}

public String getName() {
return name;
}

public int getGeneration() {
return generation;
}

public String getPosition() {
return position;
}

public String getStatusMessage() {
return statusMessage;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.whoz_in.infra.jpa.member;

import org.springframework.stereotype.Repository;

@Repository
public class MemberJpaAdapter implements MemberRepository{

@Override
public void save() {
System.out.println("1");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.whoz_in.infra.jpa.member;

import org.springframework.data.jpa.repository.JpaRepository;

public interface MemberJpaRepository extends JpaRepository<MemberEntity, Long> {

}
3 changes: 3 additions & 0 deletions modules/infrastructure/jpa/src/main/resources/env.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
MYSQL_URL=jdbc:mysql://localhost:3306/whozin?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC&useUnicode=true&characterSetResults=utf8mb4
MYSQL_USERNAME=root
MYSQL_PASSWORD=qwer1234
1 change: 0 additions & 1 deletion modules/infrastructure/spring/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ repositories {

dependencies {
implementation project(':modules:domain')

testImplementation platform('org.junit:junit-bom:5.9.1')
testImplementation 'org.junit.jupiter:junit-jupiter'
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.whoz_in.infra.spring.event;


import com.whoz_in.domain.shared.domain.bus.event.DomainEvent;
import com.whoz_in.domain.shared.domain.bus.event.EventBus;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;


/*
기본적인 이벤트 퍼블리셔
추후에 카프카나 토끼MQ를 공부하면 새로운 구현체를 만들어봅시다.
*/
@Service
@RequiredArgsConstructor
public final class SpringApplicationEventBus implements EventBus {
private final ApplicationEventPublisher publisher;

@Override
public void publish(List<DomainEvent> events) {
events.forEach(this.publisher::publishEvent);
}
}