Skip to content

Commit

Permalink
mrege: career -> activity 변경
Browse files Browse the repository at this point in the history
career activity 변환 작업
  • Loading branch information
hong-sile authored Jul 28, 2023
2 parents d7cb261 + 37fa5f7 commit 0619d4a
Show file tree
Hide file tree
Showing 16 changed files with 90 additions and 481 deletions.
94 changes: 5 additions & 89 deletions backend/emm-sale/src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,93 +6,9 @@
:toclevels: 2
:sectlinks:

== Product
== Activity

=== `GET`: 최근 가격 하락 상품 목록 조회

.HTTP request
include::{snippets}/top-price-drop-products/http-request.adoc[]

.HTTP request parameters
include::{snippets}/top-price-drop-products/request-parameters.adoc[]

.HTTP request headers
include::{snippets}/top-price-drop-products/request-headers.adoc[]

.HTTP response
include::{snippets}/top-price-drop-products/http-response.adoc[]

.HTTP response fields
include::{snippets}/top-price-drop-products/response-fields.adoc[]

=== `GET`: 검색 상품 목록 조회

.HTTP request
include::{snippets}/search-products/http-request.adoc[]

.HTTP request parameters
include::{snippets}/search-products/request-parameters.adoc[]

.HTTP request headers
include::{snippets}/search-products/request-headers.adoc[]

.HTTP response
include::{snippets}/search-products/http-response.adoc[]

.HTTP response fields
include::{snippets}/search-products/response-fields.adoc[]

=== `GET`: 찜 상품 목록 조회

.HTTP request
include::{snippets}/wish-products/http-request.adoc[]

.HTTP request parameters
include::{snippets}/wish-products/request-parameters.adoc[]

.HTTP request headers
include::{snippets}/wish-products/request-headers.adoc[]

.HTTP response
include::{snippets}/wish-products/http-response.adoc[]

.HTTP response fields
include::{snippets}/wish-products/response-fields.adoc[]

=== `GET`: 알림 설정 상품 목록 조회

.HTTP request
include::{snippets}/wish-with-notified-products/http-request.adoc[]

.HTTP request parameters
include::{snippets}/wish-with-notified-products/request-parameters.adoc[]

.HTTP request headers
include::{snippets}/wish-with-notified-products/request-headers.adoc[]

.HTTP response
include::{snippets}/wish-with-notified-products/http-response.adoc[]

.HTTP response fields
include::{snippets}/wish-with-notified-products/response-fields.adoc[]

=== `GET`: AUTHORIZATION 헤더 없이 찜 목록 조회

.HTTP request
include::{snippets}/wish-with-no-authentication-products/http-request.adoc[]

.HTTP request parameters
include::{snippets}/wish-with-no-authentication-products/request-parameters.adoc[]

.HTTP request headers
include::{snippets}/wish-with-no-authentication-products/request-headers.adoc[]

.HTTP response
include::{snippets}/wish-with-no-authentication-products/http-response.adoc[]

== Career

=== `POST`: 커리어 등록 API
=== `POST`: Activity 등록 API

.HTTP request 설명
include::{snippets}/add-activity/request-fields.adoc[]
Expand All @@ -106,7 +22,7 @@ include::{snippets}/add-activity/http-response.adoc[]
.HTTP response 설명
include::{snippets}/add-activity/response-fields.adoc[]

=== `DELETE`: 커리어 삭제 API
=== `DELETE`: Activity 삭제 API

.HTTP request 설명
include::{snippets}/delete-activity/request-fields.adoc[]
Expand All @@ -120,7 +36,7 @@ include::{snippets}/delete-activity/http-response.adoc[]
.HTTP response 설명
include::{snippets}/delete-activity/response-fields.adoc[]

=== `GET`: 존재하는 커리어 전체 조회
=== `GET`: 존재하는 Activity 전체 조회

.HTTP request
include::{snippets}/find-all-activities/http-request.adoc[]
Expand All @@ -131,7 +47,7 @@ include::{snippets}/find-all-activities/http-response.adoc[]
.HTTP response 설명
include::{snippets}/find-all-activities/response-fields.adoc[]

=== `GET`: 사용자의 커리어 조회
=== `GET`: 사용자의 Activity 조회

.HTTP request
include::{snippets}/find-activity/http-request.adoc[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ActivityApi {
private final ActivityService activityService;

@GetMapping
public ResponseEntity<List<ActivityResponses>> findAll(){
public ResponseEntity<List<ActivityResponses>> findAll() {
return ResponseEntity.ok(activityService.findAll());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,31 @@ public ResponseEntity<Void> register(
final Member member,
@RequestBody final MemberActivityInitialRequest memberActivityInitialRequest
) {
memberActivityService.registerCareer(member, memberActivityInitialRequest);
memberActivityService.registerActivities(member, memberActivityInitialRequest);
return ResponseEntity.noContent().build();
}

@PostMapping("/members/activities")
public ResponseEntity<List<MemberActivityResponses>> addCareer(
public ResponseEntity<List<MemberActivityResponses>> addActivity(
final Member member,
@RequestBody final MemberActivityAddRequest memberActivityAddRequest
) {
return ResponseEntity.status(HttpStatus.CREATED)
.body(memberActivityService.addCareer(member, memberActivityAddRequest));
.body(memberActivityService.addActivity(member, memberActivityAddRequest));
}

@DeleteMapping("/members/activities")
public ResponseEntity<List<MemberActivityResponses>> deleteCareer(
public ResponseEntity<List<MemberActivityResponses>> deleteActivity(
final Member member,
@RequestBody final MemberActivityDeleteRequest memberActivityDeleteRequest
) {
return ResponseEntity.ok(
memberActivityService.deleteCareer(member, memberActivityDeleteRequest));
memberActivityService.deleteActivity(member, memberActivityDeleteRequest));
}

@GetMapping("/members/activities")
public ResponseEntity<List<MemberActivityResponses>> findCareer(final Member member) {
return ResponseEntity.ok(memberActivityService.findCareers(member));
public ResponseEntity<List<MemberActivityResponses>> findActivity(final Member member) {
return ResponseEntity.ok(memberActivityService.findActivities(member));
}

@PutMapping("/members/open-profile-url")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,65 +25,65 @@ public class MemberActivityService {
private final MemberActivityRepository memberActivityRepository;
private final ActivityRepository activityRepository;

public void registerCareer(
public void registerActivities(
final Member member,
final MemberActivityInitialRequest memberActivityInitialRequest
) {
final List<Long> careerIds = memberActivityInitialRequest.getActivityIds();
saveMemberCareers(member, careerIds);
final List<Long> activityIds = memberActivityInitialRequest.getActivityIds();
saveMemberActivities(member, activityIds);

member.updateName(memberActivityInitialRequest.getName());
}

private void saveMemberCareers(final Member member, final List<Long> careerIds) {
final List<MemberActivity> memberActivities = activityRepository.findAllById(careerIds)
private void saveMemberActivities(final Member member, final List<Long> activityIds) {
final List<MemberActivity> memberActivities = activityRepository.findAllById(activityIds)
.stream()
.map(it -> new MemberActivity(it, member))
.collect(toList());

validateAllCareerIdsExist(careerIds, memberActivities);
validateAllActivityIdsExist(activityIds, memberActivities);

memberActivityRepository.saveAll(memberActivities);
}

private void validateAllCareerIdsExist(
final List<Long> careerIds,
private void validateAllActivityIdsExist(
final List<Long> activityIds,
final List<MemberActivity> memberActivities
) {
if (memberActivities.size() != careerIds.size()) {
throw new MemberException(MemberExceptionType.INVALID_CAREER_IDS);
if (memberActivities.size() != activityIds.size()) {
throw new MemberException(MemberExceptionType.INVALID_ACTIVITY_IDS);
}
}

public List<MemberActivityResponses> addCareer(
public List<MemberActivityResponses> addActivity(
final Member member,
final MemberActivityAddRequest memberActivityAddRequest
) {
final List<Long> careerIds = memberActivityAddRequest.getActivityIds();
saveMemberCareers(member, careerIds);
final List<Long> activityIds = memberActivityAddRequest.getActivityIds();
saveMemberActivities(member, activityIds);

return MemberActivityResponses.from(memberActivityRepository.findAllByMember(member));
}

public List<MemberActivityResponses> deleteCareer(
public List<MemberActivityResponses> deleteActivity(
final Member member,
final MemberActivityDeleteRequest memberActivityDeleteRequest
) {
final List<Long> deleteCareerIds = memberActivityDeleteRequest.getActivityIds();
final List<Long> deleteActivityIds = memberActivityDeleteRequest.getActivityIds();

final List<Long> savedMemberCareerIds =
memberActivityRepository.findAllByMemberAndCareerIds(member, deleteCareerIds)
final List<Long> savedMemberActivityIds =
memberActivityRepository.findAllByMemberAndActivityIds(member, deleteActivityIds)
.stream()
.map(MemberActivity::getId)
.collect(toList());

memberActivityRepository.deleteAllByIdInBatch(savedMemberCareerIds);
memberActivityRepository.deleteAllByIdInBatch(savedMemberActivityIds);

return MemberActivityResponses.from(memberActivityRepository.findAllByMember(member));
}

@Transactional(readOnly = true)
public List<MemberActivityResponses> findCareers(final Member member) {
public List<MemberActivityResponses> findActivities(final Member member) {
return MemberActivityResponses.from(memberActivityRepository.findAllByMember(member));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class MemberActivityResponses {

public static List<MemberActivityResponses> from(final List<MemberActivity> memberActivities) {
final EnumMap<ActivityType, List<Activity>> groupByActivityType =
groupingByActivityTypeAndSortedByCareerName(memberActivities);
groupingByActivityTypeAndSortedByActivityName(memberActivities);

final List<MemberActivityResponses> responses = new ArrayList<>();

Expand All @@ -46,7 +46,7 @@ private static List<MemberActivityResponse> mapToMemberActivityResponses(
.collect(toList());
}

private static EnumMap<ActivityType, List<Activity>> groupingByActivityTypeAndSortedByCareerName(
private static EnumMap<ActivityType, List<Activity>> groupingByActivityTypeAndSortedByActivityName(
final List<MemberActivity> memberActivities
) {
return memberActivities
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public interface MemberActivityRepository extends JpaRepository<MemberActivity,

@Query("select mc from MemberActivity mc "
+ "where mc.member = :member "
+ "and mc.activity.id in :deleteCareerIds")
List<MemberActivity> findAllByMemberAndCareerIds(
+ "and mc.activity.id in :deleteActivityId")
List<MemberActivity> findAllByMemberAndActivityIds(
@Param("member") final Member member,
@Param("deleteCareerIds") final List<Long> deleteCareerIds
@Param("deleteActivityId") final List<Long> deleteActivityId
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public enum MemberExceptionType implements BaseExceptionType {
"해당 멤버는 존재하지 않습니다."
),

INVALID_CAREER_IDS(
INVALID_ACTIVITY_IDS(
HttpStatus.BAD_REQUEST,
"요청한 career id들 중에 유효하지 않은 값이 존재합니다"
"요청한 activity id들 중에 유효하지 않은 값이 존재합니다"
);

private final HttpStatus httpStatus;
Expand Down
16 changes: 8 additions & 8 deletions backend/emm-sale/src/main/resources/http/member.http
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
### 사용자 초기 커리어 및 이름 저장
### 사용자 초기 Activity 및 이름 저장

POST http://localhost:8080/members
Content-Type: application/json

{
"name": "우르",
"careerIds": [
"activitieIds": [
1,
2
]
}

### 사용자 커리어 추가
POST http://localhost:8080/members/careers
### 사용자 Activity 추가
POST http://localhost:8080/members/activities
Content-Type: application/json

{
"careerIds": [
"activitieIds": [
4,
5,
6
]
}

### 사용자 커리어 제거
DELETE http://localhost:8080/members/careers
### 사용자 Activity 제거
DELETE http://localhost:8080/members/activities
Content-Type: application/json

{
"careerIds": [
"activitieIds": [
1,
2
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ActivityApiTest extends MockMvcTestHelper {
private ActivityService activityService;

@Test
@DisplayName("커리어를 전제 조회할 수 있으면 200 OK를 반환한다.")
@DisplayName("Activity를 전제 조회할 수 있으면 200 OK를 반환한다.")
void findAll() throws Exception {
// given
final ResponseFieldsSnippet responseFields = responseFields(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ActivityServiceTest extends ServiceIntegrationTestHelper {
private ActivityService activityService;

@Test
@DisplayName("존재하고 있는 커리어를 전체 조회할 수 있다.")
@DisplayName("존재하고 있는 Activity를 전체 조회할 수 있다.")
void findAll() throws Exception {
//given
final List<String> expectedActivities = List.of(
Expand Down
Loading

0 comments on commit 0619d4a

Please sign in to comment.