-
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.
Browse files
Browse the repository at this point in the history
Feat/#11 get main view
- Loading branch information
Showing
10 changed files
with
216 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
32 changes: 32 additions & 0 deletions
32
src/main/java/org/sopt/sopkerton/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,32 @@ | ||
package org.sopt.sopkerton.user.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.sopt.sopkerton.common.response.ApiResponse; | ||
import org.sopt.sopkerton.user.domain.exception.UserSuccess; | ||
import org.sopt.sopkerton.user.dto.response.MainView; | ||
import org.sopt.sopkerton.user.service.UserService; | ||
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; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1/user") | ||
public class UserController { | ||
|
||
private final UserService userService; | ||
|
||
@GetMapping("/info/{userId}") | ||
public ResponseEntity<ApiResponse<MainView>> orderMainView( | ||
@PathVariable("userId") Long userId | ||
) { | ||
MainView mainViewInfo = userService.getMainViewInfo(userId); | ||
return ResponseEntity | ||
.status(UserSuccess.USER_MAIN_VIEW_SUCCESS.getHttpStatus()) | ||
.body( | ||
ApiResponse.success(UserSuccess.USER_MAIN_VIEW_SUCCESS, mainViewInfo) | ||
); | ||
} | ||
} |
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,33 @@ | ||
package org.sopt.sopkerton.user.domain; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.*; | ||
import org.sopt.sopkerton.user.domain.enums.Gender; | ||
|
||
@Getter | ||
@Entity | ||
@Table(schema = "skt-t1-app", name = "users") | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@Builder | ||
public class User { | ||
|
||
@Id | ||
@Column(name = "id") | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
Long id; | ||
|
||
@Column(name = "name", nullable = false) | ||
String name; | ||
|
||
@Column(name = "gender", nullable = false) | ||
@Enumerated(value = EnumType.STRING) | ||
Gender gender; | ||
|
||
@Column(name = "thumbnail") | ||
String thumbnail; | ||
|
||
@Column(name = "age", nullable = false) | ||
int age; | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/org/sopt/sopkerton/user/domain/enums/Gender.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,5 @@ | ||
package org.sopt.sopkerton.user.domain.enums; | ||
|
||
public enum Gender { | ||
MALE, FEMALE | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/org/sopt/sopkerton/user/domain/exception/UserError.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,30 @@ | ||
package org.sopt.sopkerton.user.domain.exception; | ||
|
||
import lombok.AllArgsConstructor; | ||
import org.sopt.sopkerton.common.exception.base.ErrorBase; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@AllArgsConstructor | ||
public enum UserError implements ErrorBase { | ||
USER_NOT_FOUND(HttpStatus.NOT_FOUND, "Can not found User."), | ||
; | ||
|
||
private final HttpStatus status; | ||
private final String errorMessage; | ||
|
||
|
||
@Override | ||
public int getHttpStatusCode() { | ||
return this.status.value(); | ||
} | ||
|
||
@Override | ||
public HttpStatus getHttpStatus() { | ||
return this.status; | ||
} | ||
|
||
@Override | ||
public String getErrorMessage() { | ||
return this.errorMessage; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/org/sopt/sopkerton/user/domain/exception/UserException.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,9 @@ | ||
package org.sopt.sopkerton.user.domain.exception; | ||
|
||
import org.sopt.sopkerton.common.exception.base.ExceptionBase; | ||
|
||
public class UserException extends ExceptionBase { | ||
public UserException(UserError userError) { | ||
super(userError); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/org/sopt/sopkerton/user/domain/exception/UserSuccess.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,29 @@ | ||
package org.sopt.sopkerton.user.domain.exception; | ||
|
||
import lombok.AllArgsConstructor; | ||
import org.sopt.sopkerton.common.exception.base.SuccessBase; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@AllArgsConstructor | ||
public enum UserSuccess implements SuccessBase { | ||
USER_MAIN_VIEW_SUCCESS(HttpStatus.OK, "Get User Main View Data Successful.") | ||
; | ||
|
||
private final HttpStatus status; | ||
private final String successMessage; | ||
|
||
@Override | ||
public int getHttpStatusCode() { | ||
return this.status.value(); | ||
} | ||
|
||
@Override | ||
public HttpStatus getHttpStatus() { | ||
return this.status; | ||
} | ||
|
||
@Override | ||
public String getSuccessMessage() { | ||
return this.successMessage; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/org/sopt/sopkerton/user/dto/response/MainView.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,17 @@ | ||
package org.sopt.sopkerton.user.dto.response; | ||
|
||
|
||
public record MainView( | ||
long userId, | ||
String thumbnail, | ||
String name, | ||
String gender, // 남성 || 여성 | ||
int age, | ||
String criminalHistory, | ||
String criminalHistoryDate, | ||
int volunteerHours, | ||
int completedProgramCount, | ||
int certificateCount, | ||
double ringRate | ||
) { | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/org/sopt/sopkerton/user/infrastructure/UserRepository.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,8 @@ | ||
package org.sopt.sopkerton.user.infrastructure; | ||
|
||
|
||
import org.sopt.sopkerton.user.domain.User; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface UserRepository extends JpaRepository<User, Long> { | ||
} |
50 changes: 50 additions & 0 deletions
50
src/main/java/org/sopt/sopkerton/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,50 @@ | ||
package org.sopt.sopkerton.user.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.sopt.sopkerton.user.domain.User; | ||
import org.sopt.sopkerton.user.domain.enums.Gender; | ||
import org.sopt.sopkerton.user.domain.exception.UserError; | ||
import org.sopt.sopkerton.user.domain.exception.UserException; | ||
import org.sopt.sopkerton.user.dto.response.MainView; | ||
import org.sopt.sopkerton.user.infrastructure.UserRepository; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class UserService { | ||
private static final String CRIMINAL_HISTORY = "단순 절도죄"; | ||
private static final String CRIMINAL_HISTORY_DATE = "3년전"; | ||
private static final String MALE = "남성"; | ||
private static final String FEMALE = "여성"; | ||
|
||
private static final int VOLUNTEER_HOURS = 50; | ||
private static final int COMPLETED_PROGRAM_COUNT = 4; | ||
private static final int CERTIFICATE_COUNT = 4; | ||
private static final double RING_RATE = 0.65; | ||
|
||
private final UserRepository userRepository; | ||
|
||
public MainView getMainViewInfo(Long userId) { | ||
User targetUser = userRepository.findById(userId) | ||
.orElseThrow(() -> new UserException(UserError.USER_NOT_FOUND)); | ||
String gender; | ||
if (targetUser.getGender().equals(Gender.MALE)) { | ||
gender = MALE; | ||
} else { | ||
gender = FEMALE; | ||
} | ||
return new MainView( | ||
targetUser.getId(), | ||
targetUser.getThumbnail(), | ||
targetUser.getName(), | ||
gender, | ||
targetUser.getAge(), | ||
CRIMINAL_HISTORY, | ||
CRIMINAL_HISTORY_DATE, | ||
VOLUNTEER_HOURS, | ||
COMPLETED_PROGRAM_COUNT, | ||
CERTIFICATE_COUNT, | ||
RING_RATE | ||
); | ||
} | ||
} |