-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
125 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/java/com/app3/server/user/controller/UserController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.app3.server.user.controller; | ||
|
||
import com.app3.server.user.controller.dto.response.UserGetResponse; | ||
import com.app3.server.user.repository.UserJpaRepository; | ||
import com.app3.server.user.service.UserService; | ||
import jakarta.persistence.EntityNotFoundException; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/api/user") | ||
@RequiredArgsConstructor | ||
public class UserController { | ||
|
||
private final UserService userService; | ||
|
||
// 목록 조회 | ||
@GetMapping("/{id}") | ||
public ResponseEntity<UserGetResponse> getUserProfile(@PathVariable Long id) { | ||
return ResponseEntity.ok(userService.getUserById(id)); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/app3/server/user/controller/dto/response/UserGetResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.app3.server.user.controller.dto.response; | ||
|
||
import com.app3.server.user.domain.User; | ||
|
||
public record UserGetResponse ( | ||
String nickname | ||
) { | ||
public static UserGetResponse of(User user) { | ||
return new UserGetResponse( | ||
user.getNickname() | ||
); | ||
} | ||
} | ||
|
||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.app3.server.user.domain; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class User { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
private String nickname; | ||
|
||
|
||
@Builder | ||
public User(String nickname) { | ||
this.nickname = nickname; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
src/main/java/com/app3/server/user/repository/UserJpaRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.app3.server.user.repository; | ||
|
||
|
||
import com.app3.server.user.domain.User; | ||
import jakarta.persistence.EntityNotFoundException; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface UserJpaRepository extends JpaRepository<User, Long> { | ||
default User findByIdOrThrow(Long id) { | ||
return findById(id).orElseThrow( | ||
() -> new EntityNotFoundException("회원이 존재하지 않습니다.")); | ||
} | ||
} |
Empty file.
23 changes: 23 additions & 0 deletions
23
src/main/java/com/app3/server/user/service/UserService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.app3.server.user.service; | ||
|
||
import com.app3.server.user.controller.dto.response.UserGetResponse; | ||
import com.app3.server.user.domain.User; | ||
import com.app3.server.user.repository.UserJpaRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Transactional | ||
@Service | ||
@RequiredArgsConstructor | ||
public class UserService { | ||
private final UserJpaRepository userJpaRepository; | ||
|
||
public UserGetResponse getUserById(Long id) { | ||
return UserGetResponse.of(userJpaRepository.findByIdOrThrow(id)); | ||
} | ||
} | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
spring: | ||
datasource: | ||
driver-class-name: com.mysql.cj.jdbc.Driver | ||
url: jdbc:mysql://localhost:3306/demo?serverTimezone=UTC&characterEncoding=UTF-8 | ||
username: root | ||
password: sb03sb04!! | ||
|
||
config: | ||
activate: | ||
on-profile: dev | ||
|
||
jpa: | ||
database-platform: org.hibernate.dialect.MySQL8Dialect | ||
hibernate: | ||
ddl-auto: create |