Merge branch 'backend' into be/Lecture
This commit is contained in:
commit
603bc2d8ce
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user