Skip to content

Commit

Permalink
Merge pull request #214 from TEAM-SAMSION/PET-312
Browse files Browse the repository at this point in the history
PET-312 랜딩 API 구현
  • Loading branch information
isprogrammingfun authored Jun 6, 2024
2 parents 70bdf8a + 0a56931 commit 617b78c
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public class IgnoredPathConsts {
"/oauth/**", HttpMethod.GET,
"/jwt", HttpMethod.GET,
"/reissue",HttpMethod.POST,
"/actuator/**", HttpMethod.GET
"/actuator/**", HttpMethod.GET,
"/user/landing", HttpMethod.POST
);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.pawith.userapplication.dto.request;

import java.util.regex.Pattern;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class LandingRequest {

private static final Pattern EMAIL_PATTERN = Pattern.compile("^[A-Za-z0-9+_.-]+@(.+)$");

private String email;
private String name;

public void setEmail(String email) {
if (!EMAIL_PATTERN.matcher(email).matches()) {
throw new IllegalArgumentException("Email should be valid");
}
this.email = email;
}

}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.pawith.userapplication.dto.response;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class UserInfoResponse {
private final String nickname;
private final String email;
private final String profileImageUrl;
private String nickname;
private String email;
private String profileImageUrl;

public UserInfoResponse(String nickname, String email, String profileImageUrl) {
this.nickname = nickname;
this.email = email;
this.profileImageUrl = profileImageUrl;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.pawith.userapplication.mapper;

import com.pawith.userapplication.dto.request.LandingRequest;
import com.pawith.userdomain.entity.Landing;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class LandingMapper {

public static Landing toLandingEntity(LandingRequest landingRequest) {
return new Landing(landingRequest.getEmail(), landingRequest.getName());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.pawith.userapplication.service;

import com.pawith.commonmodule.annotation.ApplicationService;
import com.pawith.userapplication.dto.request.LandingRequest;
import com.pawith.userapplication.mapper.LandingMapper;
import com.pawith.userdomain.entity.Landing;
import com.pawith.userdomain.service.LandingSaveService;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;

@ApplicationService
@RequiredArgsConstructor
public class LandingCreateUseCase {
private final LandingSaveService landingSaveService;

@Transactional
public void createLanding(LandingRequest request){
Landing landing = LandingMapper.toLandingEntity(request);
landingSaveService.saveUserLanding(landing);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.pawith.userdomain.entity;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Landing {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "landing_id")
private Long id;

private String email;

private String name;

public Landing(String email, String name) {
this.email = email;
this.name = name;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.pawith.userdomain.repository;

import com.pawith.userdomain.entity.Landing;
import org.springframework.data.jpa.repository.JpaRepository;

public interface LandingRepository extends JpaRepository<Landing, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.pawith.userdomain.service;

import com.pawith.commonmodule.annotation.DomainService;
import com.pawith.userdomain.entity.Landing;
import com.pawith.userdomain.repository.LandingRepository;
import lombok.RequiredArgsConstructor;

@DomainService
@RequiredArgsConstructor
public class LandingSaveService {
private final LandingRepository landingRepository;

public void saveUserLanding(Landing landing) {
landingRepository.save(landing);
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.pawith.userpresentation;

import com.pawith.userapplication.dto.request.PathHistoryCreateRequest;
import com.pawith.userapplication.dto.request.LandingRequest;
import com.pawith.userapplication.dto.request.UserNicknameChangeRequest;
import com.pawith.userapplication.dto.request.WithdrawReasonCreateRequest;
import com.pawith.userapplication.dto.response.UserInfoResponse;
Expand All @@ -21,6 +22,7 @@ public class UserController {
private final PathHistoryCreateUseCase pathHistoryCreateUseCase;
private final UserDeleteUseCase userDeleteUseCase;
private final WithdrawReasonCreateUseCase withdrawReasonCreateUseCase;
private final LandingCreateUseCase landingCreateUseCase;

@PutMapping("/name")
public void putNicknameOnUser(@RequestBody UserNicknameChangeRequest request){
Expand Down Expand Up @@ -56,4 +58,10 @@ public UserJoinTermResponse getTerm() {
public void postWithdrawReason(@RequestBody WithdrawReasonCreateRequest withDrawCreateRequest){
withdrawReasonCreateUseCase.createWithdrawReason(withDrawCreateRequest);
}

@PostMapping("/landing")
public void postLanding(@RequestBody LandingRequest landingRequest){
landingCreateUseCase.createLanding(landingRequest);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class UserControllerTest extends BaseRestDocsTest {
private UserDeleteUseCase userDeleteUseCase;
@MockBean
private WithdrawReasonCreateUseCase withdrawReasonCreateUseCase;
@MockBean
private LandingCreateUseCase landingCreateUseCase;

private static final String USER_REQUEST_URL = "/user";
private static final String ACCESS_TOKEN = "Bearer accessToken";
Expand Down Expand Up @@ -183,22 +185,23 @@ void getTerm() throws Exception {
@DisplayName("서비스 탈퇴 이유 저장 API 테스트")
void postWithdrawReason() throws Exception {
//given
final WithdrawReasonCreateRequest withdrawReasonCreateRequest = FixtureMonkeyUtils.getConstructBasedFixtureMonkey().giveMeOne(WithdrawReasonCreateRequest.class);
final WithdrawReasonCreateRequest withdrawReasonCreateRequest = FixtureMonkeyUtils.getConstructBasedFixtureMonkey()
.giveMeOne(WithdrawReasonCreateRequest.class);
final MockHttpServletRequestBuilder request = post(USER_REQUEST_URL + "/withdraw")
.content(objectMapper.writeValueAsString(withdrawReasonCreateRequest))
.contentType("application/json")
.header(AUTHORIZATION_HEADER, ACCESS_TOKEN);
.content(objectMapper.writeValueAsString(withdrawReasonCreateRequest))
.contentType("application/json")
.header(AUTHORIZATION_HEADER, ACCESS_TOKEN);
//when
ResultActions result = mvc.perform(request);
//then
result.andExpect(status().isOk())
.andDo(resultHandler.document(
requestHeaders(
headerWithName(AUTHORIZATION_HEADER).description("access 토큰")
),
requestFields(
fieldWithPath("reason").description("탈퇴 이유")
)
));
.andDo(resultHandler.document(
requestHeaders(
headerWithName(AUTHORIZATION_HEADER).description("access 토큰")
),
requestFields(
fieldWithPath("reason").description("탈퇴 이유")
)
));
}
}
}

0 comments on commit 617b78c

Please sign in to comment.