Skip to content

Commit

Permalink
Merge pull request #21 from WE-ARE-RACCOONS/RAC-78
Browse files Browse the repository at this point in the history
RAC-78 feat: νšŒμ›κ°€μž… 및 둜그인
  • Loading branch information
ay-eonii authored Oct 31, 2023
2 parents 9a5b069 + b918cdb commit fed623c
Show file tree
Hide file tree
Showing 18 changed files with 323 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class AuthController {
public ResponseDto<?> getUserDetails(@RequestBody KakaoLoginRequest request) {
AuthUserResponse authUser = kakaoSignInUseCase.getUser(request.getAccessToken());
if (authUser.getSocialId() != null) {
return ResponseDto.create(NOT_FOUND.value(), NOT_REGISTERED_USER_MESSAGE.getMessage(), authUser);
return ResponseDto.create(OK.value(), NOT_REGISTERED_USER_MESSAGE.getMessage(), authUser);
}
JwtTokenResponse jwtToken = jwtUseCase.signIn(authUser.getUser());
return ResponseDto.create(OK.value(), SUCCESS_AUTH_MESSAGE.getMessage(), jwtToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,30 @@ public class Mentoring {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long mentoringId;

@ManyToOne
private User user;

@ManyToOne
private Senior senior;

@Column(nullable = false)
private String topic;

@Column(nullable = false)
private String question;

@Column(nullable = false)
private String date;

@Column(nullable = false)
private int pay;

@Enumerated(EnumType.STRING)
private Status status;

@CreationTimestamp
private LocalDate createdAt;

private LocalDate deletedAt;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@ public class Payment {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long paymentId;

@OneToOne
private Mentoring mentoring;

@CreationTimestamp
private LocalDate createdAt;

private LocalDate paidAt;

private LocalDate deletedAt;

@Enumerated(EnumType.STRING)
@Column(nullable = false)
@Builder.Default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,22 @@ public class Review {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long reviewId;

@OneToOne
private Mentoring mentoring;

@Lob
@Column(nullable = false)
private String content;

@Column(nullable = false)
@Enumerated(EnumType.STRING)
@Builder.Default
private Status status = Status.REJECT;

@CreationTimestamp
private LocalDate createdAt;

@UpdateTimestamp
private LocalDate updatedAt;
// μ‚­μ œκ°€ μΆ”κ°€λœλ‹€λ©΄ μ‚­μ œμΈμ§€ μ•„λ‹Œμ§€ μƒνƒœκ°€ μžˆμ–΄μ•Όν•˜λŠ”λ°, μ—†μ–΄μ„œ 일단 뺌
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.postgraduate.domain.senior.application.dto.req;

import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@NoArgsConstructor
public class SeniorProfileRequest {
@NotNull
private String info;
@NotNull
private String target;
@NotNull
private String chatLink;
@NotNull
private String time;
@NotNull
private int term;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.postgraduate.domain.senior.application.dto.req;

import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@NoArgsConstructor
public class SeniorSignUpRequest {
@NotNull
private String college;
@NotNull
private String major;
@NotNull
private String postgradu;
@NotNull
private String professor;
@NotNull
private String lab;
@NotNull
private String field;
@NotNull
private String certification;
@NotNull
private String account;
@NotNull
private String bank;
@NotNull
private String rrn;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.postgraduate.domain.senior.application.mapper;

import com.postgraduate.domain.senior.application.dto.req.SeniorSignUpRequest;
import com.postgraduate.domain.senior.domain.entity.Senior;
import com.postgraduate.domain.user.domain.entity.User;

public class SeniorMapper {

public static Senior mapToSenior(User user, SeniorSignUpRequest request) {
return Senior.builder()
.user(user)
.college(request.getCollege())
.major(request.getMajor())
.postgradu(request.getPostgradu())
.professor(request.getProfessor())
.lab(request.getLab())
.field(request.getField())
.certification(request.getCertification())
.account(request.getAccount())
.bank(request.getBank())
.rrn(request.getRrn())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.postgraduate.domain.senior.application.usecase;

import com.postgraduate.domain.senior.application.dto.req.SeniorSignUpRequest;
import com.postgraduate.domain.senior.domain.service.SeniorSaveService;
import com.postgraduate.domain.user.domain.entity.User;
import com.postgraduate.domain.user.domain.entity.constant.Role;
import com.postgraduate.domain.user.domain.service.UserUpdateService;
import com.postgraduate.global.auth.AuthDetails;
import com.postgraduate.global.config.security.util.SecurityUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
@RequiredArgsConstructor
public class SeniorSignUpUseCase {
private final UserUpdateService userUpdateService;
private final SeniorSaveService seniorSaveService;
private final SecurityUtils securityUtils;

public void signUp(AuthDetails authDetails, SeniorSignUpRequest request) {
User user = securityUtils.getLoggedInUser(authDetails);
userUpdateService.updateRole(user.getUserId(), Role.SENIOR);
seniorSaveService.saveSenior(user, request);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.postgraduate.domain.senior.application.usecase;

import com.postgraduate.domain.senior.application.dto.req.SeniorProfileRequest;
import com.postgraduate.domain.senior.domain.entity.Senior;
import com.postgraduate.domain.senior.domain.service.SeniorGetService;
import com.postgraduate.domain.senior.domain.service.SeniorSaveService;
import com.postgraduate.domain.user.domain.entity.User;
import com.postgraduate.domain.user.domain.service.UserGetService;
import com.postgraduate.global.auth.AuthDetails;
import com.postgraduate.global.config.security.util.SecurityUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
@RequiredArgsConstructor
public class SeniorUpdateUseCase {
private final SeniorSaveService seniorSaveService;
private final SeniorGetService seniorGetService;
private final SecurityUtils securityUtils;

public void updateProfile(AuthDetails authDetails, SeniorProfileRequest request) {
User user = securityUtils.getLoggedInUser(authDetails);
Senior senior = seniorGetService.byUser(user);
seniorSaveService.saveSenior(senior, request);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,60 @@ public class Senior {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long seniorId;

@OneToOne
private User user;
@Column(nullable = false)
private String name;

@Column(nullable = false)
private String college;

@Column(nullable = false)
private String major;

@Column(nullable = false)
private String postgradu;

@Column(nullable = false)
private String professor;

@Column(nullable = false)
private String lab;

@Column(nullable = false)
private String field;
@Column(nullable = false, length = 500)

private String info;
@Column(nullable = false)

private String target;
@Column(nullable = false)

private String chatLink;
@Column(nullable = false)

private String time;
@Column(nullable = false)

private int term;

@Column(nullable = false)
private String account;

@Column(nullable = false)
private String bank;

private String certification;

@Column(nullable = false)
private String rrn;

@Column(nullable = false)
private boolean status;

@Column(nullable = false)
private int hit;

public void updateProfile(String info, String target, String chatLink, String time, int term) {
this.info = info;
this.target = target;
this.chatLink = chatLink;
this.time = time;
this.term = term;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.postgraduate.domain.senior.domain.entity.repository;

import com.postgraduate.domain.senior.domain.entity.Senior;
import com.postgraduate.domain.user.domain.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;

public interface SeniorRepository extends JpaRepository<Senior, Long> {
Optional<Senior> findByUser(User user);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.postgraduate.domain.senior.domain.service;

import com.postgraduate.domain.senior.domain.entity.Senior;
import com.postgraduate.domain.senior.domain.entity.repository.SeniorRepository;
import com.postgraduate.domain.user.domain.entity.User;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class SeniorGetService {
private final SeniorRepository seniorRepository;

public Senior byUser(User user) {
return seniorRepository.findByUser(user).orElseThrow(/**μ˜ˆμ™Έ 처리**/);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.postgraduate.domain.senior.domain.service;

import com.postgraduate.domain.senior.application.dto.req.SeniorProfileRequest;
import com.postgraduate.domain.senior.application.dto.req.SeniorSignUpRequest;
import com.postgraduate.domain.senior.application.mapper.SeniorMapper;
import com.postgraduate.domain.senior.domain.entity.Senior;
import com.postgraduate.domain.senior.domain.entity.repository.SeniorRepository;
import com.postgraduate.domain.user.domain.entity.User;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class SeniorSaveService {
private final SeniorRepository seniorRepository;

public Senior saveSenior(User user, SeniorSignUpRequest request) {
Senior senior = SeniorMapper.mapToSenior(user, request);
return seniorRepository.save(senior);
}

public Senior saveSenior(Senior senior, SeniorProfileRequest request) {
senior.updateProfile(request.getInfo(), request.getTarget(), request.getChatLink(), request.getTime(), request.getTerm());
return seniorRepository.save(senior);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.postgraduate.domain.senior.presentation;

import com.postgraduate.domain.senior.application.dto.req.SeniorProfileRequest;
import com.postgraduate.domain.senior.application.dto.req.SeniorSignUpRequest;
import com.postgraduate.domain.senior.application.usecase.SeniorSignUpUseCase;
import com.postgraduate.domain.senior.application.usecase.SeniorUpdateUseCase;
import com.postgraduate.global.auth.AuthDetails;
import com.postgraduate.global.dto.ResponseDto;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

import static com.postgraduate.domain.senior.presentation.constant.SeniorResponseMessage.SUCCESS_SENIOR_SIGN_UP_MESSAGE;
import static com.postgraduate.domain.senior.presentation.constant.SeniorResponseMessage.SUCCESS_UPDATE_PROFILE_MESSAGE;
import static org.springframework.http.HttpStatus.OK;


@RestController
@RequiredArgsConstructor
@RequestMapping("/senior")
@Tag(name = "SENIOR Controller")
public class SeniorController {
private final SeniorSignUpUseCase signUpUseCase;
private final SeniorUpdateUseCase updateUseCase;

@PostMapping("/signup")
@Operation(summary = "λŒ€ν•™μ›μƒ κ°€μž…", description = "λŒ€ν•™μ›μƒ νšŒμ›κ°€μž…")
public ResponseDto singUpSenior(@AuthenticationPrincipal AuthDetails authDetails,
@RequestBody SeniorSignUpRequest request) {
signUpUseCase.signUp(authDetails, request);
return ResponseDto.create(OK.value(), SUCCESS_SENIOR_SIGN_UP_MESSAGE.getMessage());
}

@PatchMapping("/profile")
@Operation(summary = "λŒ€ν•™μ›μƒ ν”„λ‘œν•„ 등둝", description = "μ†Œκ°œκΈ€, μΆ”μ²œλŒ€μƒ, μ˜€ν”ˆμ±„νŒ…λ°© 링크, κ°€λŠ₯ μ‹œκ°„λŒ€, μ†Œν†΅μ‹œκ°„")
public ResponseDto singUpSenior(@AuthenticationPrincipal AuthDetails authDetails,
@RequestBody SeniorProfileRequest request) {
updateUseCase.updateProfile(authDetails, request);
return ResponseDto.create(OK.value(), SUCCESS_UPDATE_PROFILE_MESSAGE.getMessage());
}
}
Loading

0 comments on commit fed623c

Please sign in to comment.