Skip to content

Commit

Permalink
Merge pull request #11 from Journey-Together/feat/#10
Browse files Browse the repository at this point in the history
feat : member entity
  • Loading branch information
sycuuui authored May 23, 2024
2 parents e10d719 + c1a1d8b commit 5a04aa4
Show file tree
Hide file tree
Showing 24 changed files with 281 additions and 161 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ dependencies {
implementation("software.amazon.awssdk:s3:2.21.0")
implementation 'org.apache.httpcomponents:httpclient:4.5.13'

// Swagger UI - spring doc
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2'

}

tasks.named('test') {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/Journey/Together/ServerApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class ServerApplication {

public static void main(String[] args) {
SpringApplication.run(ServerApplication.class, args);
System.out.println("Server start");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package Journey.Together.domain.member.controller;

import Journey.Together.domain.member.dto.MemberRes;
import Journey.Together.domain.member.service.MemberService;
import Journey.Together.global.common.ApiResponse;
import Journey.Together.global.exception.Success;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/member")
@Tag(name = "Member", description = "사용자 관련 API")
public class MemberController {

private final MemberService memberService;

@GetMapping("")
public ApiResponse<MemberRes> getMember() {
return ApiResponse.success(Success.LOGIN_SUCCESS);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package Journey.Together.domain.member.dto;

public record MemberRes() {
}
65 changes: 65 additions & 0 deletions src/main/java/Journey/Together/domain/member/entity/Member.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package Journey.Together.domain.member.entity;

import Journey.Together.domain.member.enumerate.BloodType;
import Journey.Together.domain.member.enumerate.LoginType;
import Journey.Together.global.common.BaseTimeEntity;
import jakarta.persistence.*;
import lombok.*;

@Getter
@Setter
@Entity
@Table(name = "member")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Member extends BaseTimeEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "member_id", nullable = false, columnDefinition = "bigint")
private Long memberId;

// 이메일은 최대 255자 + 1자(@) + 69자해서 최대 320글자이므로, varchar(320) 사용
@Column(name = "email", nullable = false, columnDefinition = "varchar(320)")
private String email;

@Column(name = "name", nullable = false, columnDefinition = "varchar(50)")
private String name;

@Column(name = "phone", columnDefinition = "varchar(15)")
private String phone;

@Column(name = "profile_url", columnDefinition = "text")
private String profileUrl;

@Column(name = "login_type", nullable = false, columnDefinition = "varchar(255)")
@Enumerated(EnumType.STRING)
private LoginType loginType;

@Column(name = "blood_type", nullable = false, columnDefinition = "varchar(255)")
@Enumerated(EnumType.STRING)
private BloodType bloodType;

@Column(name = "birth", columnDefinition = "varchar(255)")
private String birth;

@Column(name = "disease", columnDefinition = "varchar(255)")
private String disease;

@Column(name = "allergy", columnDefinition = "varchar(255)")
private String allergy;

@Column(name = "medication", columnDefinition = "varchar(255)")
private String medication;

@Builder
public Member(String email, String name, String phone, String profileUrl, String loginType,String bloodType, String birth, String allergy, String medication) {
this.email = email;
this.name = name;
this.phone = phone;
this.profileUrl = profileUrl;
this.loginType = LoginType.valueOf(loginType);
this.bloodType = BloodType.valueOf(bloodType);
this.birth = birth;
this.allergy = allergy;
this.medication=medication;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package Journey.Together.domain.member.enumerate;

public enum BloodType {
A,B,AB,O
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package Journey.Together.domain.member.enumerate;

public enum LoginType {
KAKAO,NAVER
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package Journey.Together.domain.member.repository;

import Journey.Together.domain.member.entity.Member;
import org.springframework.data.jpa.repository.JpaRepository;


public interface MemberRepository extends JpaRepository<Member, Long> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package Journey.Together.domain.member.service;

import Journey.Together.domain.member.repository.MemberRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(readOnly = true)
@RequiredArgsConstructor
public class MemberService {

private final MemberRepository memberRepository;

}
12 changes: 2 additions & 10 deletions src/main/java/Journey/Together/global/common/ApiResponse.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package Journey.Together.global.common;


import Journey.Together.global.exception.ErrorCode;
import Journey.Together.global.exception.Success;
import Journey.Together.global.exception.Error;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
Expand All @@ -22,15 +22,7 @@ public static ApiResponse success(Success success){
return new ApiResponse<>(success.getHttpStatusCode(), success.getMessage());
}

public static <T> ApiResponse<T> success(Success success, T data){
public static <T> ApiResponse<T> success(Success success, T data) {
return new ApiResponse<T>(success.getHttpStatusCode(), success.getMessage(), data);
}

public static ApiResponse error(Error error){
return new ApiResponse<>(error.getErrorCode(), error.getMessage());
}

public static ApiResponse error(Error error, String message){
return new ApiResponse<>(error.getErrorCode(), message);
}
}
35 changes: 35 additions & 0 deletions src/main/java/Journey/Together/global/config/SwaggerConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package Journey.Together.global.config;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SwaggerConfig {

@Bean
public OpenAPI openAPI() {
Info info = new Info().title("Capic Swagger UI")
.description("Capic API 테스트 페이지.")
.version("v0.0.1");

String jwtSchemeName = "JWT Authentication";
SecurityRequirement securityRequirement = new SecurityRequirement().addList(jwtSchemeName);
Components components = new Components()
.addSecuritySchemes(jwtSchemeName, new SecurityScheme()
.name(jwtSchemeName)
.type(SecurityScheme.Type.HTTP)
.scheme("bearer")
.bearerFormat("JWT"));

// Swagger UI 접속 후, 딱 한 번만 accessToken을 입력해주면 모든 API에 토큰 인증 작업이 적용됩니다.
return new OpenAPI()
.info(info)
.addSecurityItem(securityRequirement)
.components(components);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package Journey.Together.global.exception;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class ApplicationException extends RuntimeException {
public ErrorCode errorCode;
}
54 changes: 0 additions & 54 deletions src/main/java/Journey/Together/global/exception/Error.java

This file was deleted.

60 changes: 60 additions & 0 deletions src/main/java/Journey/Together/global/exception/ErrorCode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package Journey.Together.global.exception;

import lombok.Getter;
import lombok.ToString;
import org.springframework.http.HttpStatus;

@Getter
@ToString
public enum ErrorCode {

// 1000: Success Case
SUCCESS(HttpStatus.OK, 1000, "정상적인 요청입니다."),
CREATED(HttpStatus.CREATED, 1001, "정상적으로 생성되었습니다."),

// 2000: Common Error
INTERNAL_SERVER_EXCEPTION(HttpStatus.INTERNAL_SERVER_ERROR, 2000, "예기치 못한 오류가 발생했습니다."),
NOT_FOUND_EXCEPTION(HttpStatus.NOT_FOUND, 2001, "존재하지 않는 리소스입니다."),
INVALID_VALUE_EXCEPTION(HttpStatus.BAD_REQUEST, 2002, "올바르지 않은 요청 값입니다."),
UNAUTHORIZED_EXCEPTION(HttpStatus.UNAUTHORIZED, 2003, "권한이 없는 요청입니다."),
ALREADY_DELETE_EXCEPTION(HttpStatus.BAD_REQUEST, 2004, "이미 삭제된 리소스입니다."),
FORBIDDEN_EXCEPTION(HttpStatus.FORBIDDEN, 2005, "인가되지 않는 요청입니다."),
ALREADY_EXIST_EXCEPTION(HttpStatus.BAD_REQUEST, 2006, "이미 존재하는 리소스입니다."),


// 3000: Auth Error
KAKAO_TOKEN_EXCEPTION(HttpStatus.INTERNAL_SERVER_ERROR, 3000, "토큰 발급에서 오류가 발생했습니다."),
KAKAO_USER_EXCEPTION(HttpStatus.INTERNAL_SERVER_ERROR, 3001, "카카오 프로필 정보를 가져오는 과정에서 오류가 발생했습니디."),
WRONG_TOKEN_EXCEPTION(HttpStatus.UNAUTHORIZED, 3002, "유효하지 않은 토큰입니다."),
LOGOUT_TOKEN_EXCEPTION(HttpStatus.UNAUTHORIZED, 3003, "로그아웃된 토큰입니다"),
WRONG_TOKEN(HttpStatus.UNAUTHORIZED, 3004, "유효하지 않은 토큰입니다."),


//4000: Apply Error
NOT_APPLY_EXCEPTION(HttpStatus.BAD_REQUEST,4000,"지원 기간 지났습니다"),
NOT_FOUND_POST_EXCEPTION(HttpStatus.NOT_FOUND,4001,"존재하지 않는 글입니다."),
NOT_FOUND_APPLY_EXCEPTION(HttpStatus.NOT_FOUND,4002,"존재하지 않는 지원서입니다."),
ALREADY_APPLY_EXCEPTION(HttpStatus.BAD_REQUEST,4003,"이미 지원했습니다."),
ALREADY_DECISION_EXCEPION(HttpStatus.BAD_REQUEST,4004,"이미 지원 결정했습니다."),
NOT_RECRUITING_EXCEPION(HttpStatus.BAD_REQUEST,4005,"이 공고는 모집 중이 아닙니다."),
NOT_FOUND_CATEGORY_EXCEPTION(HttpStatus.NOT_FOUND,4006,"카테고리가 없습니다"),
OVER_APPLY_EXCEPTION(HttpStatus.NOT_FOUND,4007,"지원 파트 정원이 찼습니다."),
INVALID_STACK_TYPE_EXCEPTION(HttpStatus.NOT_FOUND,4008,"기술 스택 없습니다"),

//5000: Post Error
NOT_POST_EXCEPTION(HttpStatus.BAD_REQUEST,5000,"공고를 더 이상 생성할 수 없습니다"),
POST_VALUE_EXCEPTION(HttpStatus.BAD_REQUEST,5001,"올바르지 않은 요청 값입니다."),
NOT_FOUNT_SCRAP_EXCEPTION(HttpStatus.NOT_FOUND,5002,"스크랩 정보가 존재하지 않습니다."),
ALREADY_FINISH_EXCEPTION(HttpStatus.BAD_REQUEST, 5003, "이미 모집 기간이 마감된 공고입니다."),
ILLEGAL_POST_EXCEPTION(HttpStatus.BAD_REQUEST, 5004, "파트별 인원수가 전체 인원수와 일치하지 않습니다.");

private final HttpStatus httpStatus;
private final Integer code;
private final String message;

ErrorCode(HttpStatus httpStatus, Integer code, String message) {
this.httpStatus = httpStatus;
this.code = code;
this.message = message;
}
}
18 changes: 18 additions & 0 deletions src/main/java/Journey/Together/global/exception/ErrorResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package Journey.Together.global.exception;

import java.time.LocalDateTime;


public record ErrorResponse(
LocalDateTime timestamp,
Integer code,
String message) {

public ErrorResponse(ErrorCode errorcode) {
this(LocalDateTime.now(), errorcode.getCode(), errorcode.getMessage());
}

public ErrorResponse(String message) {
this(LocalDateTime.now(), ErrorCode.INTERNAL_SERVER_EXCEPTION.getCode(), message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package Journey.Together.global.exception;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

@ExceptionHandler(ApplicationException.class)
protected ResponseEntity<ErrorResponse> handleApplicationException(ApplicationException e){
log.error(e + " " + e.getErrorCode().toString());
return ResponseEntity.status(e.getErrorCode().getHttpStatus())
.body(new ErrorResponse(e.getErrorCode()));
}

@ExceptionHandler(RuntimeException.class)
protected ResponseEntity<ErrorResponse> handleRuntimeException(RuntimeException e) {
log.error(e.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(new ErrorResponse(e.getMessage()));
}
}

This file was deleted.

Loading

0 comments on commit 5a04aa4

Please sign in to comment.