Skip to content

Commit

Permalink
feat: 기본 회원가입 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
jhsong76 committed Jan 2, 2024
1 parent 2fe619d commit 18a2b97
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 2 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ dependencies {

// swagger
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2'

//implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
}

tasks.named('test') {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/hackerton/demo/DemoApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;

@SpringBootApplication
@SpringBootApplication(exclude = SecurityAutoConfiguration.class)
public class DemoApplication {

public static void main(String[] args) {
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/hackerton/demo/domain/Keyword/Keyword.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.hackerton.demo.domain.Keyword;

import com.hackerton.demo.domain.User.User;
import com.hackerton.demo.domain.common.BaseEntity;
import jakarta.persistence.*;
import lombok.*;
Expand All @@ -19,4 +20,9 @@ public class Keyword extends BaseEntity {
private Long id;

private String optionTitle;

@JoinColumn(name = "user_id")
@ManyToOne
private User user;

}
37 changes: 37 additions & 0 deletions src/main/java/com/hackerton/demo/domain/User/User.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.hackerton.demo.domain.User;

import com.hackerton.demo.domain.Keyword.Keyword;
import com.hackerton.demo.domain.common.BaseEntity;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import java.util.ArrayList;
import java.util.List;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Entity
@Getter
@Setter
@Builder
@NoArgsConstructor(access = AccessLevel.PUBLIC)
@AllArgsConstructor
public class User extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "user_id")
private Long id;

private String nickName;

@OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
private List<Keyword> keywordList = new ArrayList<>();
}
30 changes: 30 additions & 0 deletions src/main/java/com/hackerton/demo/domain/User/UserController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.hackerton.demo.domain.User;

import com.hackerton.demo.domain.User.request.LoginDto;
import com.hackerton.demo.domain.common.ApiResponse;
import com.hackerton.demo.domain.common.ApiResponseStatus;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/users")
public class UserController {
private final UserService userService;

@PostMapping("/sign-ip")
@Operation(summary = "기본 회원가입 API", description = "닉네임을 입력받아 회원가입을 진행합니다.")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "SIGN_IN_SUCCESS", description = "로그인 성공"),
})
public ResponseEntity<ApiResponse<UserDto>> login(@RequestBody LoginDto request){
ApiResponse<UserDto> response = new ApiResponse<>(ApiResponseStatus.SIGN_IN_SUCCESS, userService.login(request));
return ResponseEntity.ok(response);
}
}
11 changes: 11 additions & 0 deletions src/main/java/com/hackerton/demo/domain/User/UserDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.hackerton.demo.domain.User;

import lombok.Builder;
import lombok.Getter;

@Builder
@Getter
public class UserDto {
private Long id;
private String nickName;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.hackerton.demo.domain.User;

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

public interface UserRepository extends JpaRepository<User, Long> {

boolean existsByNickName(String nickName);

}
32 changes: 32 additions & 0 deletions src/main/java/com/hackerton/demo/domain/User/UserService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.hackerton.demo.domain.User;

import com.hackerton.demo.domain.User.request.LoginDto;
import com.hackerton.demo.domain.common.ApiResponse;
import com.hackerton.demo.domain.common.ApiResponseStatus;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class UserService {
private final UserRepository userRepository;

@Transactional
public UserDto login(LoginDto request) {

User user = new User();
user.setNickName(request.getNickName());

userRepository.save(user);

UserDto userDto = UserDto.builder()
.id(user.getId())
.nickName(user.getNickName())
.build();

return userDto;
}

}
10 changes: 10 additions & 0 deletions src/main/java/com/hackerton/demo/domain/User/request/LoginDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.hackerton.demo.domain.User.request;

import jakarta.validation.constraints.NotBlank;
import lombok.Data;

@Data
public class LoginDto {
@NotBlank(message = "닉네임을 입력해주세요.")
private String nickName;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
public enum ApiResponseStatus {
// 응답상태 기록
SEARCH_SUCCESS(true, 201, "검색이 성공적으로 전달되었습니다."),
GET_SUCCESS(true, 202, "조회에 성공하였습니다");
GET_SUCCESS(true, 202, "조회에 성공하였습니다"),
EXIST_NICKNAME(true, 401, "중복된 닉네임입니다."),
SIGN_IN_SUCCESS(true, 203, "회원가입 성공하였습니다");

private final boolean isSuccess;
private final int status;
Expand Down

0 comments on commit 18a2b97

Please sign in to comment.