diff --git a/.idea/modules.xml b/.idea/modules.xml
index 7e7eefc..e21ecee 100644
--- a/.idea/modules.xml
+++ b/.idea/modules.xml
@@ -3,6 +3,7 @@
+
\ No newline at end of file
diff --git a/.idea/modules/JWTLogIn.JWT.main.iml b/.idea/modules/JWTLogIn.JWT.main.iml
index e52f99e..a02b577 100644
--- a/.idea/modules/JWTLogIn.JWT.main.iml
+++ b/.idea/modules/JWTLogIn.JWT.main.iml
@@ -3,6 +3,7 @@
+
\ No newline at end of file
diff --git a/JWT/src/main/java/JWTLogIn/JWT/user/controller/UserController.java b/JWT/src/main/java/JWTLogIn/JWT/user/controller/UserController.java
index e69671d..4862b31 100644
--- a/JWT/src/main/java/JWTLogIn/JWT/user/controller/UserController.java
+++ b/JWT/src/main/java/JWTLogIn/JWT/user/controller/UserController.java
@@ -2,12 +2,19 @@
import JWTLogIn.JWT.user.dto.LogInDTO;
import JWTLogIn.JWT.user.dto.UserDTO;
+import JWTLogIn.JWT.user.dto.UserRequestDTO;
+import JWTLogIn.JWT.user.dto.UserResponseDTO;
import JWTLogIn.JWT.user.service.UserService;
+import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
+import java.lang.reflect.Member;
+
+import static org.springframework.data.jpa.domain.AbstractPersistable_.id;
+
@RestController
@RequestMapping("/tgwing.kr")
@RequiredArgsConstructor
@@ -59,4 +66,16 @@ public ResponseEntity deleteId(@PathVariable Long id) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
}// 회원 탈퇴
+
+
+ //@RequestMapping(value = "/profile/{id}", method = RequestMethod.GET)
+ @PutMapping("/profile/{id}")
+ public ResponseEntity changeProfile(@PathVariable Long id, @RequestBody @Valid UserRequestDTO request){
+ UserDTO change = userService.changeUser(id, request);
+ if(change != null){
+ return ResponseEntity.ok().build(); //요거가 response다시
+ }
+ return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
+ }
+
}
diff --git a/JWT/src/main/java/JWTLogIn/JWT/user/dto/UserDTO.java b/JWT/src/main/java/JWTLogIn/JWT/user/dto/UserDTO.java
index b81e7d2..d098383 100644
--- a/JWT/src/main/java/JWTLogIn/JWT/user/dto/UserDTO.java
+++ b/JWT/src/main/java/JWTLogIn/JWT/user/dto/UserDTO.java
@@ -37,3 +37,4 @@ public static UserEntity toUserEntity(UserDTO userDTO) {
.build();
}
}
+
diff --git a/JWT/src/main/java/JWTLogIn/JWT/user/dto/UserRequestDTO.java b/JWT/src/main/java/JWTLogIn/JWT/user/dto/UserRequestDTO.java
new file mode 100644
index 0000000..006b985
--- /dev/null
+++ b/JWT/src/main/java/JWTLogIn/JWT/user/dto/UserRequestDTO.java
@@ -0,0 +1,18 @@
+package JWTLogIn.JWT.user.dto;
+
+import JWTLogIn.JWT.user.entity.Enum.Status;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class UserRequestDTO {
+ private String name; // 이름
+ private Status status; // 재학/휴학 상태
+ private String semester; // 학년, 학기(3글자로 설정)
+ private String phoneNumber;
+}
diff --git a/JWT/src/main/java/JWTLogIn/JWT/user/dto/UserResponseDTO.java b/JWT/src/main/java/JWTLogIn/JWT/user/dto/UserResponseDTO.java
new file mode 100644
index 0000000..20d099b
--- /dev/null
+++ b/JWT/src/main/java/JWTLogIn/JWT/user/dto/UserResponseDTO.java
@@ -0,0 +1,21 @@
+package JWTLogIn.JWT.user.dto;
+
+import JWTLogIn.JWT.user.entity.Enum.Status;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class UserResponseDTO {
+ private Long id;
+ private String studentId; // 아이디
+ private String email; // 이메일
+ private String name; // 이름
+ private Status status; // 재학/휴학 상태
+ private String semester; // 학년, 학기(3글자로 설정)
+ private String phoneNumber;
+}
diff --git a/JWT/src/main/java/JWTLogIn/JWT/user/entity/UserEntity.java b/JWT/src/main/java/JWTLogIn/JWT/user/entity/UserEntity.java
index d30bb45..08160ea 100644
--- a/JWT/src/main/java/JWTLogIn/JWT/user/entity/UserEntity.java
+++ b/JWT/src/main/java/JWTLogIn/JWT/user/entity/UserEntity.java
@@ -4,6 +4,8 @@
import JWTLogIn.JWT.user.entity.Enum.Level;
import JWTLogIn.JWT.user.entity.Enum.Status;
import com.fasterxml.jackson.annotation.JsonValue;
+import io.swagger.v3.oas.annotations.Hidden;
+import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.DynamicInsert;
@@ -17,6 +19,7 @@
@Table(name = "user")
public class UserEntity extends BaseEntity{
@Id
+ @Schema(hidden = true)
@GeneratedValue(strategy = GenerationType.IDENTITY) // 점직적 증가
private Long id; // 기본 키.
diff --git a/JWT/src/main/java/JWTLogIn/JWT/user/repository/UserRepository.java b/JWT/src/main/java/JWTLogIn/JWT/user/repository/UserRepository.java
index 4ae2ee5..de3f01c 100644
--- a/JWT/src/main/java/JWTLogIn/JWT/user/repository/UserRepository.java
+++ b/JWT/src/main/java/JWTLogIn/JWT/user/repository/UserRepository.java
@@ -1,6 +1,7 @@
package JWTLogIn.JWT.user.repository;
import JWTLogIn.JWT.user.entity.Enum.Level;
+import JWTLogIn.JWT.user.entity.Enum.Status;
import JWTLogIn.JWT.user.entity.UserEntity;
import jakarta.transaction.Transactional;
import org.springframework.data.domain.Page;
@@ -22,6 +23,7 @@ public interface UserRepository extends JpaRepository {
@Query("DELETE FROM UserEntity U WHERE U.id = :id")
void deleteUser(@Param("id") Long id);
+
// @Modifying
// @Transactional
// @Query("UPDATE UserEntity u SET " +
@@ -35,4 +37,10 @@ public interface UserRepository extends JpaRepository {
// "WHERE b.boardId = :boardId")
Page findAll(Pageable pageable);
+
+ @Transactional
+ @Modifying
+ @Query("UPDATE UserEntity U SET U.name = :name, U.status = :status, U.semester = :semester, U.phoneNumber = :phoneNumber WHERE U.id = :id")
+ void changeUser(Long id, String name, Status status, String semester, String phoneNumber);
+
}
diff --git a/JWT/src/main/java/JWTLogIn/JWT/user/service/UserService.java b/JWT/src/main/java/JWTLogIn/JWT/user/service/UserService.java
index 3aa91de..151efd5 100644
--- a/JWT/src/main/java/JWTLogIn/JWT/user/service/UserService.java
+++ b/JWT/src/main/java/JWTLogIn/JWT/user/service/UserService.java
@@ -2,7 +2,10 @@
import JWTLogIn.JWT.user.dto.LogInDTO;
import JWTLogIn.JWT.user.dto.UserDTO;
+import JWTLogIn.JWT.user.dto.UserRequestDTO;
+import JWTLogIn.JWT.user.dto.UserResponseDTO;
import JWTLogIn.JWT.user.entity.Enum.Level;
+import JWTLogIn.JWT.user.entity.Enum.Status;
import JWTLogIn.JWT.user.entity.UserEntity;
import JWTLogIn.JWT.user.repository.UserRepository;
import JWTLogIn.JWT.user.security.JwtUtil;
@@ -72,6 +75,30 @@ public Boolean deleteUser(Long id) {
}
}// 회원 삭제
+ public UserDTO changeUser(Long id, UserRequestDTO request){
+ Optional user = userRepository.findById(id);
+ // 만약 사용자 정보가 존재한다면 업데이트를 수행
+ if (user.isPresent()) {
+ userRepository.changeUser(id, request.getName(), request.getStatus(), request.getSemester(), request.getPhoneNumber());
+ }
+ Optional updatedUserOptional = userRepository.findById(id);
+
+ // 업데이트된 사용자 정보가 존재한다면 UserDTO로 변환하여 반환
+ if (updatedUserOptional.isPresent()) {
+ UserEntity updatedUser = updatedUserOptional.get();
+ return UserDTO.builder()
+ .id(updatedUser.getId())
+ .name(updatedUser.getName())
+ .status(updatedUser.getStatus())
+ .semester(updatedUser.getSemester())
+ .phoneNumber(updatedUser.getPhoneNumber())
+ .build();
+ }
+ else{
+ return null;
+ }
+ };
+
public List findUserAll() {
List allUser = userRepository.findAll();