Skip to content

Commit

Permalink
Merge branch 'master' into feat/certification
Browse files Browse the repository at this point in the history
  • Loading branch information
lsm-del authored Apr 6, 2024
2 parents ee497d9 + 91d14f2 commit 35f0050
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 3 deletions.
24 changes: 24 additions & 0 deletions src/main/java/com/kukerton/controller/MemberController.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.kukerton.controller;

import com.amazonaws.Response;
import com.kukerton.dto.request.CertificationRequestDto;
import com.kukerton.dto.request.OnboardingRequest;
import com.kukerton.global.enums.GlobalSuccessCode;
import com.kukerton.global.exception.OnboardingException;
import com.kukerton.global.response.BfResponse;
import com.kukerton.service.MemberService;
import jakarta.validation.Valid;
Expand All @@ -10,8 +13,11 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -21,6 +27,9 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import static com.kukerton.global.enums.MemberErrorCode.ONBOARDING_INPUT_FORMAT;

@Slf4j
@RestController
@RequestMapping("/member")
@RequiredArgsConstructor
Expand All @@ -37,6 +46,7 @@ public ResponseEntity<BfResponse<?>> login(@RequestParam(name = "code") String c
Map.of("id", memberService.getUserInfoFromResourceServer(code))));
}


@Operation(summary = "쿠폰 목록 조회 API", description = "회원 프로필에서 쿠폰 목록 조회 api입니다.")
@GetMapping("/{memberId}")
public ResponseEntity<BfResponse<?>> getCoupon(@PathVariable("memberId") Long memberId) {
Expand All @@ -46,4 +56,18 @@ public ResponseEntity<BfResponse<?>> getCoupon(@PathVariable("memberId") Long me
}


@Operation(summary = "온보딩 화면 API", description = "온보딩 화면에서 관심분야, 자제분야를 저장하는 API 입니다.")
@PostMapping("/onboarding")
public ResponseEntity<BfResponse<?>> onboarding(@Validated @RequestBody OnboardingRequest onboardingRequest, BindingResult bindingResult){

if(bindingResult.hasErrors()){
throw new OnboardingException(ONBOARDING_INPUT_FORMAT);
}

memberService.createOnboardingConfig(onboardingRequest);

return ResponseEntity.status(HttpStatus.OK)
.body(new BfResponse<>(GlobalSuccessCode.CREATE));
}

}
28 changes: 28 additions & 0 deletions src/main/java/com/kukerton/dto/request/OnboardingRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.kukerton.dto.request;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.kukerton.global.enums.Category;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class OnboardingRequest{

@JsonProperty("user_id")
@NotNull(message = "사용자 ID는 필수 항목입니다.")
@Positive(message = "사용자 ID는 음수일 수 없습니다.")
Long user_id;

@NotNull(message = "interested_categories는 필수 항목입니다.")
List<String> interested_categories;

@NotNull(message = "restrained_categories는 필수 항목입니다.")
List<String> restrained_categories;
}
37 changes: 37 additions & 0 deletions src/main/java/com/kukerton/global/enums/Category.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.kukerton.global.enums;

import lombok.Getter;

@Getter
public enum Category {

SELF_IMPROVEMENT("자기계발"),
WORKOUT("운동"),
ACTIVITY("액티비티"),
NIGHT_EATING("야식"),
MUSIC("음악"),
GAME("게임"),
WATCHING_MEDIA("미디어 시청"),
OUTGOING("외출"),
CLEANING("청결(청소)"),
ETC("기타"),
DRINKING_AND_SMOKING("음주&흡연"),
DELIVERY_FOOD("배달음식"),
IMPULSE_BUYING("충동구매"),
CAFFEINE("카페인"),
OVERSPENDING("과소비");

private String category;

Category(String category){
this.category = category;
}

public static Category fromRequest(String category){
for(Category e : Category.values()){
if(e.category.equals(category))
return e;
}
return null;
}
}
3 changes: 2 additions & 1 deletion src/main/java/com/kukerton/global/enums/MemberErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public enum MemberErrorCode implements BaseErrorCode{
OAUTH_ACCECC_TOKEN_400(500,"소셜 로그인 토큰 발급 에러입니다.",HttpStatus.INTERNAL_SERVER_ERROR),
KAKAO_USERINFO_400(400,"소셜 로그인 토큰 발급 에러입니다.",HttpStatus.INTERNAL_SERVER_ERROR),
KAKAO_USERINFO_500(500,"소셜 로그인 토큰 발급 에러입니다.",HttpStatus.INTERNAL_SERVER_ERROR),
IMAGE_FILE_FORM(400,"이미지 형태 에러입니다.",HttpStatus.BAD_REQUEST);
IMAGE_FILE_FORM(400,"이미지 형태 에러입니다.",HttpStatus.BAD_REQUEST),
ONBOARDING_INPUT_FORMAT(600, "올바르지 않은 요청 형식입니다.", HttpStatus.BAD_REQUEST);

private final int errorCode;
private final String errorMessage;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.kukerton.global.exception;

import com.kukerton.global.enums.MemberErrorCode;
import lombok.Getter;

@Getter
public class OnboardingException extends RuntimeException{
private final MemberErrorCode errorCode;

public OnboardingException(MemberErrorCode errorCode) {
super(errorCode.getErrorMessage());
this.errorCode = errorCode;
}
}
32 changes: 30 additions & 2 deletions src/main/java/com/kukerton/service/MemberService.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package com.kukerton.service;



import com.kukerton.domain.entity.Coupon;
import com.kukerton.domain.entity.Member;
import com.kukerton.domain.repository.CouponRepository;
import com.kukerton.dto.response.CouponResponseDto;
import com.kukerton.domain.entity.Config;
import com.kukerton.domain.entity.Member;
import com.kukerton.domain.repository.ConfigRepository;
import com.kukerton.domain.repository.MemberRepository;
import com.kukerton.dto.request.CertificationRequestDto;
import com.kukerton.dto.response.CouponResponseDto;
import com.kukerton.dto.request.OnboardingRequest;
import com.kukerton.dto.response.KakaoAccessToken;
import com.kukerton.dto.response.KakaoUserInfo;
import com.kukerton.global.enums.Category;
import com.kukerton.global.enums.MemberErrorCode;
import com.kukerton.global.exception.MemberException;
import java.time.LocalDate;
Expand All @@ -32,6 +37,7 @@
public class MemberService {

private final MemberRepository memberRepository;
private final ConfigRepository configRepository;

private final ImageService imageService;

Expand Down Expand Up @@ -141,4 +147,26 @@ public List<CouponResponseDto> getCoupon(Long memberId) {
}


public void createOnboardingConfig(OnboardingRequest onboardingRequest) {

Optional<Member> member = memberRepository.findById(onboardingRequest.getUser_id());

for(String category : onboardingRequest.getInterested_categories()){
configRepository.save(Config.builder()
.category(Category.fromRequest(category).getCategory())
.is_want(true)
.member(member.orElse(null))
.build()
);
}

for(String category : onboardingRequest.getRestrained_categories()){
configRepository.save(Config.builder()
.category(Category.fromRequest(category).getCategory())
.is_want(false)
.member(member.orElse(null))
.build()
);
}
}
}

0 comments on commit 35f0050

Please sign in to comment.