redis, batch, mongodb is infra
This commit is contained in:
@@ -45,9 +45,6 @@ One Day Lifetime SNS
|
||||
│ │ │ │ ├── request
|
||||
│ │ │ │ └── response
|
||||
│ │ │ ├── config
|
||||
│ │ │ │ ├── RedisConfig.java
|
||||
│ │ │ │ ├── BatchConfig.java
|
||||
│ │ │ │ ├── MongoConfig.java
|
||||
│ │ │ │ └── security
|
||||
│ │ │ │ ├── InterceptorConfig.java
|
||||
│ │ │ │ └── WebSecurityConfig.java
|
||||
@@ -60,6 +57,9 @@ One Day Lifetime SNS
|
||||
│ │ │ └── BatchScheduler.java
|
||||
│ │ └── infra
|
||||
│ │ ├── config
|
||||
│ │ │ ├── RedisConfig.java
|
||||
│ │ │ ├── MongoConfig.java
|
||||
│ │ │ ├── BatchConfig.java
|
||||
│ │ │ ├── KafkaConsumerConfig.java
|
||||
│ │ │ └── KafkaProducerConfig.java
|
||||
│ │ ├── dto
|
||||
|
||||
@@ -24,7 +24,7 @@ import com.example.oneul.domain.user.domain.UserEntity;
|
||||
|
||||
@Entity
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
@Table(indexes = @Index(name = "i_post", columnList="createdAt"))
|
||||
@Table(name = "post", indexes = @Index(name = "i_post", columnList="createdAt"))
|
||||
public class Post implements Serializable {
|
||||
@Id @GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@@ -4,6 +4,7 @@ import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
@@ -13,6 +14,8 @@ import com.example.oneul.domain.user.domain.UserEntity;
|
||||
import com.example.oneul.domain.user.dto.LoginDTO;
|
||||
import com.example.oneul.domain.user.dto.SignUpDTO;
|
||||
import com.example.oneul.domain.user.service.UserService;
|
||||
import com.example.oneul.global.common.Code;
|
||||
import com.example.oneul.global.common.Response;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/user")
|
||||
@@ -26,30 +29,24 @@ public class UserApi {
|
||||
}
|
||||
|
||||
@RequestMapping(value="/signup/", method=RequestMethod.POST)
|
||||
public UserEntity signUp(@RequestBody SignUpDTO signUpDTO) {
|
||||
public ResponseEntity<Response> signUp(@RequestBody SignUpDTO signUpDTO) {
|
||||
// TODO: password1, password2 같은지 validator로 검사
|
||||
UserEntity user = userService.signUp(signUpDTO.toEntity());
|
||||
log.info("signUp: " + user.toString());
|
||||
return user;
|
||||
return ResponseEntity.ok(new Response(Code.SUCESS, "유저 생성 성공"));
|
||||
}
|
||||
|
||||
@RequestMapping(value="/login/", method=RequestMethod.POST)
|
||||
public UserEntity login(HttpSession httpSession, @RequestBody LoginDTO loginDTO) {
|
||||
public ResponseEntity<Response> login(HttpSession httpSession, @RequestBody LoginDTO loginDTO) {
|
||||
UserEntity user = userService.login(loginDTO.toEntity(), httpSession);
|
||||
log.info("login: " + user.toString());
|
||||
return user;
|
||||
return ResponseEntity.ok(new Response(Code.SUCESS, "로그인 성공"));
|
||||
}
|
||||
|
||||
@RequestMapping(value="/logout/", method=RequestMethod.POST)
|
||||
public String logout(HttpSession httpSession) {
|
||||
public ResponseEntity<Response> logout(HttpSession httpSession) {
|
||||
log.info("logout: " + httpSession.toString());
|
||||
userService.logout(httpSession);
|
||||
return "logout";
|
||||
return ResponseEntity.ok(new Response(Code.SUCESS, "로그아웃 성공"));
|
||||
}
|
||||
|
||||
@RequestMapping(value="", method=RequestMethod.GET)
|
||||
public String hello() {
|
||||
return "hello";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,36 +3,28 @@ package com.example.oneul.domain.user.domain;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EntityListeners;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
import com.example.oneul.domain.post.domain.Post;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import org.hibernate.annotations.CreationTimestamp;
|
||||
|
||||
@Entity
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
@Table(name = "user")
|
||||
public class UserEntity implements Serializable {
|
||||
@Id @GeneratedValue
|
||||
@Column(name = "id", updatable = false)
|
||||
private Long id;
|
||||
@Column(nullable = false, unique = true)
|
||||
@Column(name = "username", nullable = false, unique = true)
|
||||
private String username;
|
||||
@JsonIgnore @Column(nullable = false)
|
||||
@Column(name = "password", nullable = false)
|
||||
private String password;
|
||||
@JsonIgnore @CreatedDate
|
||||
@CreationTimestamp
|
||||
@Column(name = "createAt", nullable = false, updatable = false)
|
||||
private LocalDateTime createdAt;
|
||||
@JsonIgnore
|
||||
@OneToMany(orphanRemoval = true, cascade = CascadeType.REMOVE)
|
||||
private Set<Post> posts;
|
||||
|
||||
public Long getId(){
|
||||
return this.id;
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.example.oneul.domain.user.dto;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import com.example.oneul.domain.user.domain.UserEntity;
|
||||
import com.example.oneul.global.common.Code;
|
||||
import com.example.oneul.global.common.Response;
|
||||
|
||||
public class UserInfo {
|
||||
@NotNull
|
||||
private Long id;
|
||||
@NotBlank
|
||||
private String username;
|
||||
|
||||
public Long getId(){
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void setId(Long id){
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getUsername(){
|
||||
return this.username;
|
||||
}
|
||||
|
||||
public void setUsername(String username){
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public UserInfo() {}
|
||||
|
||||
public UserInfo(Long id, String username){
|
||||
this.id = id;
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public static class UserResponse extends Response {
|
||||
private UserInfo body;
|
||||
public UserResponse(Code code, String message, UserEntity user){
|
||||
super(code, message);
|
||||
this.body = new UserInfo(user.getId(), user.getUsername());
|
||||
}
|
||||
|
||||
public UserInfo getUserInfo(){
|
||||
return this.body;
|
||||
}
|
||||
}
|
||||
}
|
||||
6
src/main/java/com/example/oneul/global/common/Code.java
Normal file
6
src/main/java/com/example/oneul/global/common/Code.java
Normal file
@@ -0,0 +1,6 @@
|
||||
package com.example.oneul.global.common;
|
||||
|
||||
public enum Code {
|
||||
SUCESS,
|
||||
ERROR
|
||||
}
|
||||
33
src/main/java/com/example/oneul/global/common/Response.java
Normal file
33
src/main/java/com/example/oneul/global/common/Response.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package com.example.oneul.global.common;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
public class Response {
|
||||
@NotBlank
|
||||
private Code code;
|
||||
@NotBlank
|
||||
private String message;
|
||||
|
||||
public Code getCode(){
|
||||
return this.code;
|
||||
}
|
||||
|
||||
public void setCode(Code code){
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getMessage(){
|
||||
return this.message;
|
||||
}
|
||||
|
||||
public void setMessage(String message){
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public Response() {}
|
||||
|
||||
public Response(Code code, String message){
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ spring:
|
||||
properties:
|
||||
hibernate:
|
||||
show-sql: true
|
||||
ddl-auto: update
|
||||
ddl-auto: create
|
||||
hbm2ddl:
|
||||
auto: update
|
||||
format_sql: true
|
||||
|
||||
Reference in New Issue
Block a user