Skip to content

Commit

Permalink
Merge pull request #107 from Sinchone/develop
Browse files Browse the repository at this point in the history
v1.0.1
  • Loading branch information
Jeongho0805 authored Jun 26, 2023
2 parents 0d3a107 + 0cfab0c commit eea7c38
Show file tree
Hide file tree
Showing 19 changed files with 106 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.lastone.core.common.response.SuccessCode;
import com.lastone.core.dto.mypage.MyPageDto;
import com.lastone.core.dto.mypage.MyPageUpdateDto;
import com.lastone.core.dto.mypage.NicknameCheckDto;
import com.lastone.core.security.principal.UserDetailsImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -24,22 +25,28 @@ public class MyPageController {

private final MyPageService myPageService;

@GetMapping("/nickname-check")
public ResponseEntity<Object> isDuplicatedNickname(String nickname) {
NicknameCheckDto result = myPageService.isDuplicatedNickname(nickname);
return ResponseEntity.ok().body(CommonResponse.success(result, SuccessCode.VALIDATE_NICKNAME.getMessage()));
}

@GetMapping("{memberId}")
public ResponseEntity<Object> getMyPageByMemberId(@PathVariable Long memberId) {
public ResponseEntity<CommonResponse> getMyPageByMemberId(@PathVariable Long memberId) {
MyPageDto myPage = myPageService.getMyPage(memberId);
return ResponseEntity.ok().body(CommonResponse.success(myPage, SuccessCode.INQUIRE_MYPAGE.getMessage()));
}

@GetMapping
@PreAuthorize("isAuthenticated()")
public ResponseEntity<Object> getMyPageByToken(@AuthenticationPrincipal UserDetailsImpl userDetails) {
public ResponseEntity<CommonResponse> getMyPageByToken(@AuthenticationPrincipal UserDetailsImpl userDetails) {
MyPageDto myPagedto = myPageService.getMyPage(userDetails.getId());
return ResponseEntity.ok().body(CommonResponse.success(myPagedto, SuccessCode.INQUIRE_MYPAGE.getMessage()));
}

@PutMapping
@PreAuthorize("isAuthenticated()")
public ResponseEntity<Object> updateMyPage(@AuthenticationPrincipal UserDetailsImpl userDetails,
public ResponseEntity<CommonResponse> updateMyPage(@AuthenticationPrincipal UserDetailsImpl userDetails,
@RequestPart(required = false) @Validated MyPageUpdateDto myPage,
@RequestPart(required = false) MultipartFile profileImg) throws IOException {
myPageService.updateMyPage(userDetails.getId(), myPage, profileImg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import com.lastone.apiserver.service.recruitment.RecruitmentService;
import com.lastone.core.common.response.CommonResponse;
import com.lastone.core.common.response.SuccessCode;
import com.lastone.core.dto.recruitment.RecruitmentRequestDto;
import com.lastone.core.dto.recruitment.RecruitmentDetailDto;
import com.lastone.core.dto.recruitment.RecruitmentListDto;
import com.lastone.core.dto.recruitment.RecruitmentSearchCondition;
import com.lastone.core.dto.recruitment.*;
import com.lastone.core.security.principal.UserDetailsImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -55,10 +52,10 @@ public ResponseEntity<CommonResponse> getRecruitmentListInMain() {
public ResponseEntity<CommonResponse> createRecruitment(@AuthenticationPrincipal UserDetailsImpl userDetails,
@RequestPart @Validated RecruitmentRequestDto recruitment,
@RequestPart(required = false) List<MultipartFile> imgFiles) throws IOException {
recruitmentService.createRecruitment(userDetails.getId(), recruitment, imgFiles);
Long recruitmentId = recruitmentService.createRecruitment(userDetails.getId(), recruitment, imgFiles);
return ResponseEntity
.status(HttpStatus.CREATED)
.body(CommonResponse.success(SuccessCode.RECRUITMENT_CREATE));
.body(CommonResponse.success(SuccessCode.RECRUITMENT_CREATE, new RecruitmentIdDto(recruitmentId)));
}

@PreAuthorize("isAuthenticated()")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

public interface MemberService {

boolean isDuplicateNickname(String nickname);

Member findById(Long memberId);

void update(Member member, MemberUpdateDto memberUpdateDto, MultipartFile profileImg) throws IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private boolean isEqualToPrevious(String nickname, String updateNickname) {
return nickname.equals(updateNickname);
}

private boolean isDuplicateNickname(String updateNickname) {
public boolean isDuplicateNickname(String updateNickname) {
Optional<Member> findMember = memberRepository.findByNickname(updateNickname);
return findMember.isPresent();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import com.lastone.core.dto.mypage.MyPageDto;
import com.lastone.core.dto.mypage.MyPageUpdateDto;
import com.lastone.core.dto.mypage.NicknameCheckDto;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;

public interface MyPageService {

NicknameCheckDto isDuplicatedNickname(String nickname);

MyPageDto getMyPage(Long memberId);

void updateMyPage(Long memberId, MyPageUpdateDto myPageUpdateDto, MultipartFile profileImg) throws IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.lastone.core.dto.member.MemberDto;
import com.lastone.core.dto.mypage.MyPageDto;
import com.lastone.core.dto.mypage.MyPageUpdateDto;
import com.lastone.core.dto.mypage.NicknameCheckDto;
import com.lastone.core.dto.sbd.SbdDto;
import com.lastone.core.util.mapper.MemberMapper;
import lombok.RequiredArgsConstructor;
Expand All @@ -30,6 +31,12 @@ public class MyPageServiceImpl implements MyPageService {

private final MemberMapper memberMapper;

@Override
public NicknameCheckDto isDuplicatedNickname(String nickname) {
boolean result = memberService.isDuplicateNickname(nickname);
return new NicknameCheckDto(result);
}

public MyPageDto getMyPage(Long memberId) {
Member member = memberService.findById(memberId);
return getMyPageDtoByMember(member);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public interface RecruitmentService {

List<RecruitmentListDto> getMainList();

void createRecruitment(Long memberId, RecruitmentRequestDto recruitmentCreateDto, List<MultipartFile> imgFiles) throws IOException;
Long createRecruitment(Long memberId, RecruitmentRequestDto recruitmentCreateDto, List<MultipartFile> imgFiles) throws IOException;

void updateRecruitment(Long recruitmentId, Long memberId, RecruitmentRequestDto recruitment, List<MultipartFile> imgFiles) throws IOException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,16 @@ public List<RecruitmentListDto> getMainList() {

@Transactional(rollbackFor = Exception.class)
@Override
public void createRecruitment(Long memberId, RecruitmentRequestDto recruitmentRequestDto, List<MultipartFile> imgFiles) throws IOException {
public Long createRecruitment(Long memberId, RecruitmentRequestDto recruitmentRequestDto, List<MultipartFile> imgFiles) throws IOException {
Gym gym = findGym(recruitmentRequestDto.getGym());
Member member = memberRepository.findById(memberId).orElseThrow(MemberNotFountException::new);
Recruitment recruitment = Recruitment.create(member, gym, recruitmentRequestDto);

if (imgFileIsExist(imgFiles)) {
recruitment.setImgFiles(saveRecruitmentImg(imgFiles));
}
recruitmentRepository.save(recruitment);
Recruitment saveRecruitment = recruitmentRepository.save(recruitment);
return saveRecruitment.getId();
}

@Transactional(rollbackFor = Exception.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public enum SuccessCode {
GET_CHAT_ROOM_LIST("채팅방 목록 조회에 성공하였습니다."),

/* My Page */
VALIDATE_NICKNAME("닉네임 중복 검증을 완료하였습니다."),
INQUIRE_MYPAGE("마이페이지 정보 조회에 성공하였습니다."),
UPDATE_MYPAGE("마이페이지 수정 작업에 성공하였습니다."),

Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/com/lastone/core/dto/gym/GymDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class GymDto {
@NotBlank(message = "헬스장 이름은 필수 입력 값입니다.")
private String name;

@NotBlank(message = "헬스장 지역은 필수 입력 값입니다.")
private String location;

@Coordinate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class MemberUpdateDto {
@Size(min = 2, max = 15)
private String nickname;

@NotBlank
@Pattern(regexp = "^(남성|여성)$", message = "성별은 남성 또는 여성만 가능합니다.")
private String gender;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@
import lombok.Getter;
import lombok.Setter;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

@Getter
@Setter
public class MyPageUpdateDto {

@Valid
@NotNull
private MemberUpdateDto member;

@Valid
@NotNull
private List<GymDto> gyms;

@Valid
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.lastone.core.dto.mypage;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class NicknameCheckDto {

private Boolean isDuplicated;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class RecruitmentDetailDto {

private Long memberId;
private String nickname;
private String gender;
private String profileUrl;
private String workoutPurpose;
private SbdDto sbd;
Expand Down Expand Up @@ -53,6 +54,7 @@ public static RecruitmentDetailDto toDto(Recruitment recruitment) {
.memberId(recruitment.getMember().getId())
.nickname(recruitment.getMember().getNickname())
.profileUrl(recruitment.getMember().getProfileUrl())
.gender(recruitment.getMember().getGender())
.workoutPurpose(recruitment.getMember().getWorkoutPurpose())
.imgUrls(toImgUrls(recruitment.getRecruitmentImgs()))
.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.lastone.core.dto.recruitment;

public class RecruitmentIdDto {

private final Long id;

public RecruitmentIdDto(Long id) {
this.id = id;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.lastone.core.dto.recruitment;

import com.lastone.core.util.validator.recruitment.RecruitmentDate;
import com.lastone.core.util.validator.recruitment.RecruitmentCreateDate;
import com.lastone.core.util.validator.recruitment.RecruitmentTime;
import lombok.Getter;
import lombok.Setter;
Expand All @@ -16,7 +16,7 @@
public class StartedAtDto {

@NotBlank
@RecruitmentDate
@RecruitmentCreateDate
private String date;

@NotNull
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.lastone.core.util.validator.recruitment;

import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = RecruitmentCreateDateValidator.class)
public @interface RecruitmentCreateDate {
String message() default "유효하지 않은 날짜 형식입니다.";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.lastone.core.util.validator.recruitment;

import org.springframework.util.StringUtils;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;

public class RecruitmentCreateDateValidator implements ConstraintValidator<RecruitmentCreateDate, String> {
@Override
public boolean isValid(String date, ConstraintValidatorContext context) {
if (!StringUtils.hasText(date)) {
return false;
}
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy.MM.dd");
LocalDate dateCondition;
try {
dateCondition = LocalDate.parse(date, formatter);
} catch (DateTimeParseException e) {
return false;
}
LocalDate now = LocalDate.now();
return !now.isAfter(dateCondition);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.lastone.core.util.validator.recruitment;

import org.springframework.util.StringUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.time.LocalDate;
Expand All @@ -10,20 +9,17 @@


public class RecruitmentDateValidator implements ConstraintValidator<RecruitmentDate, String> {

@Override
public boolean isValid(String date, ConstraintValidatorContext context) {
if (!StringUtils.hasText(date)) {
return true;
}
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy.MM.dd");
LocalDate dateCondition;
try {
dateCondition = LocalDate.parse(date, formatter);
LocalDate.parse(date, formatter);
} catch (DateTimeParseException e) {
return false;
}
LocalDate now = LocalDate.now();
return !now.isAfter(dateCondition);
return true;
}
}

0 comments on commit eea7c38

Please sign in to comment.