Skip to content

Commit

Permalink
Merge pull request #70 from moidot/chore/change-url-api
Browse files Browse the repository at this point in the history
chore : 매핑 주소 변경
  • Loading branch information
yujung7768903 authored Aug 21, 2023
2 parents e8188fa + 67bead0 commit 3a32175
Show file tree
Hide file tree
Showing 20 changed files with 174 additions and 180 deletions.
2 changes: 1 addition & 1 deletion scripts/health_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ echo "> Start health check of WAS at 'http://127.0.0.1:${TARGET_PORT}' ..."
for RETRY_COUNT in 1 2 3 4 5 6 7 8 9 10
do
echo "> #${RETRY_COUNT} trying..."
RESPONSE_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:${TARGET_PORT}/api/v1/version)
RESPONSE_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:${TARGET_PORT}/auth/success)

if [ ${RESPONSE_CODE} -eq 200 ]; then
echo "> New WAS successfully running"
Expand Down
11 changes: 2 additions & 9 deletions src/docs/asciidoc/api/groupvote/vote.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,9 @@ include::{snippets}/select-vote/request-headers.adoc[]

include::{snippets}/select-vote/path-parameters.adoc[]

==== Request Parameters
[source,http,options="nowrap"]
----
POST /api/v1/group/1/vote/select?bestPlaceIds=1,3 HTTP/1.1
Authorization: JWT AccessToken
Content-Type: application/x-www-form-urlencoded
Host: localhost:8080
Content-Length: 29
----
==== Request FormParameters
include::{snippets}/select-vote/form-parameters.adoc[]
include::{snippets}/select-vote/http-request.adoc[]

==== HTTP ResponseBody
include::{snippets}/select-vote/http-response.adoc[]
Expand Down
15 changes: 14 additions & 1 deletion src/docs/asciidoc/api/space/group.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ include::{snippets}/participation-exit/form-parameters.adoc[]
include::{snippets}/participation-exit/http-response.adoc[]
include::{snippets}/participation-exit/response-fields.adoc[]

=== 모임 삭제 API

==== HTTP Request Header
include::{snippets}/group-delete/request-headers.adoc[]

==== HTTP Request FormParameter
include::{snippets}/group-delete/form-parameters.adoc[]
include::{snippets}/group-delete/http-request.adoc[]

==== HTTP Response body
include::{snippets}/group-delete/http-response.adoc[]
include::{snippets}/group-delete/response-fields.adoc[]

=== 모임원 내보내기 API

==== HTTP Request Headers
Expand Down Expand Up @@ -90,7 +103,7 @@ include::{snippets}/my-participate/response-fields.adoc[]
include::{snippets}/read-bestPlace-keyword/query-parameters.adoc[]
[source,http,options="nowrap"]
----
GET /api/v1/group/best-region/place?x=127.232943&y=37.6823811&local=성신여대입구역AD&keyword=식당 HTTP/1.1
GET /group/best-region/place?x=127.232943&y=37.6823811&local=성신여대입구역AD&keyword=식당 HTTP/1.1
Host: localhost:8080
----

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.moim.backend.domain.groupvote.controller;

import com.moim.backend.domain.groupvote.entity.Vote;
import com.moim.backend.domain.groupvote.request.VoteRequest;
import com.moim.backend.domain.groupvote.response.VoteResponse;
import com.moim.backend.domain.groupvote.service.VoteService;
Expand All @@ -16,11 +15,11 @@

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/group")
@RequestMapping("/group")
public class VoteController {
private final VoteService voteService;

// 투표 생성(시작)
// 투표 생성 API
@PostMapping("/{groupId}/vote")
public CustomResponseEntity<VoteResponse.Create> createVote(
@PathVariable Long groupId,
Expand All @@ -29,7 +28,7 @@ public CustomResponseEntity<VoteResponse.Create> createVote(
return CustomResponseEntity.success(voteService.createVote(request.toServiceRequest(), groupId, user));
}

// 투표 읽기
// 투표 읽기 API
@GetMapping("/{groupId}/vote")
public CustomResponseEntity<VoteResponse.SelectResult> readVote(
@PathVariable Long groupId, @Login Users user
Expand All @@ -38,7 +37,7 @@ public CustomResponseEntity<VoteResponse.SelectResult> readVote(
}

// TODO: 동시성 문제가 발생할 것 같다
// 투표 하기
// 투표 참여 API
@PostMapping("/{groupId}/vote/select")
public CustomResponseEntity<VoteResponse.SelectResult> selectVote(
@PathVariable Long groupId, @RequestParam List<Long> bestPlaceIds, @Login Users user
Expand All @@ -48,7 +47,7 @@ public CustomResponseEntity<VoteResponse.SelectResult> selectVote(
);
}

// 해당 장소 투표한 인원 리스트 조회하기
// 해당 장소 투표한 인원 리스트 조회하기 API
@GetMapping("/{groupId}/vote/select")
public CustomResponseEntity<List<VoteResponse.SelectPlaceUser>> readSelectPlaceUsers(
@PathVariable Long groupId, @RequestParam Long bestPlaceId, @Login Users user
Expand All @@ -58,7 +57,7 @@ public CustomResponseEntity<List<VoteResponse.SelectPlaceUser>> readSelectPlaceU
);
}

// 투표 종료하기
// 투표 종료하기 API
@PatchMapping("/{groupId}/vote")
public CustomResponseEntity<VoteResponse.SelectResult> conclusionVote(
@PathVariable Long groupId, @Login Users user
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.moim.backend.domain.groupvote.response;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.moim.backend.domain.groupvote.entity.Vote;
import com.moim.backend.domain.space.entity.BestPlace;
import com.moim.backend.domain.space.entity.Groups;
Expand All @@ -9,12 +11,12 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Optional;

import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL;

public class VoteResponse {

@AllArgsConstructor
Expand Down Expand Up @@ -53,6 +55,8 @@ public static class SelectResult {
private Long groupId;
private String groupName;
private String groupDate;
@JsonInclude(value = NON_NULL)
private String confirmPlace;
private Long voteId;
private Boolean isClosed;
private Boolean isAnonymous;
Expand All @@ -76,6 +80,7 @@ public static VoteResponse.SelectResult response(
.groupId(group.getGroupId())
.groupName(group.getName())
.groupDate(groupDate)
.confirmPlace(group.getPlace())
.voteId(vote.getVoteId())
.isClosed(vote.getIsClosed())
.isAnonymous(vote.getIsAnonymous())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;

Expand All @@ -38,6 +39,7 @@ public class VoteService {
private final BestPlaceRepository bestPlaceRepository;
private final SelectPlaceRepository selectPlaceRepository;

// 투표 생성 API
@Transactional
public VoteResponse.Create createVote(VoteServiceRequest.Create request, Long groupId, Users user) {
Groups group = getGroups(groupId);
Expand All @@ -59,6 +61,7 @@ public VoteResponse.Create createVote(VoteServiceRequest.Create request, Long gr
return VoteResponse.Create.response(vote);
}

// 투표 참여 API
@Transactional
public VoteResponse.SelectResult selectVote(Long groupId, List<Long> bestPlaceIds, Users user, LocalDateTime now) {
// 투표 개설 및 투표에 대한 유효성 검증
Expand Down Expand Up @@ -91,11 +94,9 @@ public VoteResponse.SelectResult selectVote(Long groupId, List<Long> bestPlaceId
return VoteResponse.SelectResult.response(group, vote, voteStatuses);
}

// 투표 읽기 API
public VoteResponse.SelectResult readVote(Long groupId, Users user) {
Groups group = getGroups(groupId);

// TODO: 어떤 방식이 프론트엔드에서 처리하기 편한지 확인해봐야 할 것 같음
// 투표가 개설되지 않은 상태면 Exception 발생
Vote vote = getVote(groupId);

// 투표 이후 현재 추천된 장소들의 현황을 조회
Expand All @@ -104,6 +105,7 @@ public VoteResponse.SelectResult readVote(Long groupId, Users user) {
return VoteResponse.SelectResult.response(group, vote, voteStatuses);
}

// 해당 장소 투표한 인원 리스트 조회하기 API
public List<VoteResponse.SelectPlaceUser> readSelectPlaceUsers(Long groupId, Long bestPlaceId, Users user) {
// 그룹의 추천장소와 투표 리스트를 fetch 조회
Groups group = groupRepository.findByIdToFetchJoinBestPlace(groupId)
Expand All @@ -130,6 +132,7 @@ public List<VoteResponse.SelectPlaceUser> readSelectPlaceUsers(Long groupId, Lon
}).toList();
}

// 투표 종료하기 API
@Transactional
public VoteResponse.SelectResult conclusionVote(Long groupId, Users user) {
Groups group = getGroups(groupId);
Expand All @@ -141,9 +144,16 @@ public VoteResponse.SelectResult conclusionVote(Long groupId, Users user) {
// 투표 종료
vote.conclusionVote();

// 가장 높은 투표를 받은 장소 선정
BestPlace confirmPlace = group.getBestPlaces().stream()
.max(Comparator.comparing(bestPlace -> bestPlace.getSelectPlaces().size()))
.orElseThrow(() -> new CustomException(FAIL));
group.confirmPlace(confirmPlace.getPlaceName());

// 종료 이후 현재 추천된 장소들의 현황을 조회
List<BestPlace> bestPlaces = selectPlaceRepository.findByVoteStatus(vote.getGroupId());
List<VoteResponse.VoteStatus> voteStatuses = getVoteStatuses(user, bestPlaces);

return VoteResponse.SelectResult.response(group, vote, voteStatuses);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/group")
@RequestMapping("/group")
public class GroupController {

private final GroupService groupService;

// 모임 생성하기
// 모임 생성 API
@PostMapping("")
public CustomResponseEntity<GroupResponse.Create> createGroup(
@RequestBody @Valid GroupRequest.Create request, @Login Users user
Expand All @@ -34,55 +34,55 @@ public CustomResponseEntity<GroupResponse.Detail> readParticipateGroupByRegion(@
return CustomResponseEntity.success(groupService.readParticipateGroupByRegion(groupId));
}

// 모임 참여하기
// 모임 참여 API
@PostMapping("/participate")
public CustomResponseEntity<GroupResponse.Participate> participateGroup(
@RequestBody @Valid GroupRequest.Participate request, @Login Users user
) {
return CustomResponseEntity.success(groupService.participateGroup(request.toServiceRequest(), user));
}

// 모임 삭제하기
// 모임 삭제 API
@DeleteMapping("")
public CustomResponseEntity<Void> deleteGroup(
@RequestParam Long groupId, @Login Users user
) {
return CustomResponseEntity.success(groupService.participateDelete(groupId, user));
}

// 모임 참여 정보 수정
// 참여 정보 수정 API
@PatchMapping("/participate")
public CustomResponseEntity<GroupResponse.ParticipateUpdate> participateUpdate(
@RequestBody @Valid GroupRequest.ParticipateUpdate request, @Login Users user
) {
return CustomResponseEntity.success(groupService.participateUpdate(request.toServiceRequest(), user));
}

// 모임 나가기
// 모임 나가기 API
@DeleteMapping("/participate")
public CustomResponseEntity<GroupResponse.Exit> participateExit(
@RequestParam Long participateId, @Login Users user
) {
return CustomResponseEntity.success(groupService.participateExit(participateId, user));
}

// 모임원 내보내기 (Admin)
// 모임원 내보내기 API
@DeleteMapping("/participate/removal")
public CustomResponseEntity<Void> participateRemoval(
@RequestParam Long participateId, @Login Users user
) {
return CustomResponseEntity.success(groupService.participateRemoval(participateId, user));
}

// 모임 추천 지역 조회하기
// 모임 추천 지역 조회하기 API
@GetMapping("/best-region")
public CustomResponseEntity<List<PlaceRouteResponse>> getBestRegion(
@RequestParam Long groupId
) {
return CustomResponseEntity.success(groupService.getBestRegion(groupId));
}

// 내 모임 확인하기
// 내 모임 확인하기 API
@GetMapping("/participate")
public CustomResponseEntity<List<GroupResponse.MyParticipate>> getMyParticipate(
@Login Users user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ public class Groups {

@OneToMany(mappedBy = "group")
private List<BestPlace> bestPlaces;

public void confirmPlace(String place) {
this.place = place;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
@Repository
public interface GroupCustomRepository {
Optional<Groups> findByIdToFetchJoinBestPlace(Long groupId);
List<Groups> myParticipationGroups(Long userId);
List<Groups> findByGroupsFetch(Long userId);
Optional<Groups> findByGroupParticipation(Long groupId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public Optional<Groups> findByIdToFetchJoinBestPlace(Long groupId) {
}

@Override
public List<Groups> myParticipationGroups(Long userId) {
public List<Groups> findByGroupsFetch(Long userId) {
return queryFactory
.selectFrom(groups)
.innerJoin(groups.participations, participation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,35 +172,25 @@ public static GroupResponse.Exit response(Boolean isDeletedSpace, String message
public static class MyParticipate {
private Long groupId;
private String groupName;
private String groupAdminName;
private String groupDate;
private Integer groupParticipates;
private List<BestPlaces> bestPlaces;
private String confirmPlace;
private List<String> bestPlaceNames;
private List<String> participantNames;

public static GroupResponse.MyParticipate response(
Groups group, List<GroupResponse.BestPlaces> bestPlaces
Groups group, String groupAdminName, List<String> bestPlaceNames, List<String> participantNames
) {
return MyParticipate.builder()
.groupId(group.getGroupId())
.groupName(group.getName())
.groupAdminName(groupAdminName)
.groupDate(group.getDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")))
.groupParticipates(group.getParticipations().size())
.bestPlaces(bestPlaces)
.build();
}
}

@Getter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public static class BestPlaces {
private Long bestPlaceId;
private String bestPlaceName;

public static GroupResponse.BestPlaces response(BestPlace bestPlace) {
return GroupResponse.BestPlaces.builder()
.bestPlaceId(bestPlace.getBestPlaceId())
.bestPlaceName(bestPlace.getPlaceName())
.confirmPlace(group.getPlace())
.bestPlaceNames(bestPlaceNames)
.participantNames(participantNames)
.build();
}
}
Expand Down
Loading

0 comments on commit 3a32175

Please sign in to comment.