feat:유저 로그인
This commit is contained in:
parent
3b88c03d9e
commit
ea611db970
@ -23,6 +23,10 @@ dependencies {
|
|||||||
implementation 'mysql:mysql-connector-java:8.0.33'
|
implementation 'mysql:mysql-connector-java:8.0.33'
|
||||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||||
implementation group: 'io.livekit', name: 'livekit-server', version: '0.6.1'
|
implementation group: 'io.livekit', name: 'livekit-server', version: '0.6.1'
|
||||||
|
implementation 'org.projectlombok:lombok'
|
||||||
|
annotationProcessor 'org.projectlombok:lombok'
|
||||||
|
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0'
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
package com.edufocus.edufocus.swagger;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.models.Components;
|
||||||
|
import io.swagger.v3.oas.models.OpenAPI;
|
||||||
|
import io.swagger.v3.oas.models.info.Info;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class SwaggerConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public OpenAPI openAPI() {
|
||||||
|
return new OpenAPI()
|
||||||
|
.info(new Info()
|
||||||
|
.title("에듀포커스 API")
|
||||||
|
.description("")
|
||||||
|
.version("1.0.0"));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
package com.edufocus.edufocus.user.controller;
|
||||||
|
|
||||||
|
import com.edufocus.edufocus.user.model.entity.User;
|
||||||
|
import com.edufocus.edufocus.user.model.service.UserService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
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
|
||||||
|
@RequestMapping("/user")
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class UserController {
|
||||||
|
|
||||||
|
private final UserService userService;
|
||||||
|
|
||||||
|
@PostMapping("/join")
|
||||||
|
public ResponseEntity<String> join(@RequestBody User user) throws Exception {
|
||||||
|
|
||||||
|
System.out.println("!!!");
|
||||||
|
userService.join(user);
|
||||||
|
return ResponseEntity.ok("User registered successfully");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("/login")
|
||||||
|
public ResponseEntity<User> login(@RequestBody User user) {
|
||||||
|
try {
|
||||||
|
User loggedInUser = userService.login(user);
|
||||||
|
return ResponseEntity.ok(loggedInUser);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
package com.edufocus.edufocus.user.model.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class User {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY) // 자동 증가 설정
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private String user_id;
|
||||||
|
private String email;
|
||||||
|
private String password;
|
||||||
|
@Enumerated(EnumType.STRING) // 혹은 EnumType.ORDINAL
|
||||||
|
private UserRole role;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
package com.edufocus.edufocus.user.model.entity;
|
||||||
|
|
||||||
|
public enum UserRole {
|
||||||
|
STUDENT,ADMIN
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
package com.edufocus.edufocus.user.model.exception;
|
||||||
|
|
||||||
|
public class UserException extends RuntimeException{
|
||||||
|
|
||||||
|
public UserException(String message){
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
package com.edufocus.edufocus.user.model.repository;
|
||||||
|
|
||||||
|
import com.edufocus.edufocus.user.model.entity.User;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface UserRepository extends JpaRepository<User,Long> {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
package com.edufocus.edufocus.user.model.service;
|
||||||
|
|
||||||
|
import com.edufocus.edufocus.user.model.entity.User;
|
||||||
|
|
||||||
|
public interface UserService {
|
||||||
|
void join(User user) throws Exception;
|
||||||
|
User login(User user) throws Exception;
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
package com.edufocus.edufocus.user.model.service;
|
||||||
|
|
||||||
|
|
||||||
|
import com.edufocus.edufocus.user.model.entity.User;
|
||||||
|
import com.edufocus.edufocus.user.model.exception.UserException;
|
||||||
|
import com.edufocus.edufocus.user.model.repository.UserRepository;
|
||||||
|
import jakarta.transaction.Transactional;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Transactional
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class UserServiceImpl implements UserService{
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private final UserRepository userRepository;
|
||||||
|
|
||||||
|
|
||||||
|
public void join(User user)
|
||||||
|
{
|
||||||
|
userRepository.save(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public User login(User user) throws SQLException
|
||||||
|
{
|
||||||
|
Optional<User> findUser = userRepository.findById(user.getId());
|
||||||
|
|
||||||
|
if(findUser.isEmpty())
|
||||||
|
{
|
||||||
|
throw new UserException("없는 유저");
|
||||||
|
|
||||||
|
}
|
||||||
|
return findUser.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
spring.application.name=edufocus
|
spring.application.name=edufocus
|
||||||
|
server.port=8080
|
||||||
|
|
||||||
server.port=${SERVER_PORT:6080}
|
|
||||||
server.ssl.enabled=false
|
server.ssl.enabled=false
|
||||||
|
|
||||||
# LiveKit configuration
|
# LiveKit configuration
|
||||||
@ -8,10 +8,12 @@ livekit.api.key=${LIVEKIT_API_KEY:devkey}
|
|||||||
livekit.api.secret=${LIVEKIT_API_SECRET:secret}
|
livekit.api.secret=${LIVEKIT_API_SECRET:secret}
|
||||||
|
|
||||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||||
spring.datasource.url=jdbc:mysql://localhost:3306/edufocus?serverTimezone=Asia/Seoul
|
spring.datasource.url=jdbc:mysql://localhost:3306/edufocus?useSSL=false
|
||||||
spring.datasource.username=root
|
spring.datasource.username=root
|
||||||
spring.datasource.password=root
|
spring.datasource.password=root
|
||||||
|
spring.mvc.pathmatch.matching-strategy=ant_path_matcher
|
||||||
|
|
||||||
spring.jpa.database=mysql
|
spring.jpa.database=mysql
|
||||||
spring.jpa.hibernate.ddl-auto=update
|
spring.jpa.hibernate.ddl-auto=create
|
||||||
spring.jpa.show-sql=true
|
spring.jpa.show-sql=true
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user