Skip to content

Commit

Permalink
Merge pull request #15 from Network-office/feat/#6
Browse files Browse the repository at this point in the history
모임 기능 1차 프로토타입 개발
  • Loading branch information
sss4920 authored Oct 14, 2024
2 parents ae3b46a + 06afcfe commit f8e0dd9
Show file tree
Hide file tree
Showing 26 changed files with 1,011 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package dev.office.networkoffice.gathering.controller;

import dev.office.networkoffice.gathering.controller.docs.GatheringApiDocs;
import dev.office.networkoffice.gathering.controller.dto.request.GatheringCancelDto;
import dev.office.networkoffice.gathering.controller.dto.request.GatheringDto;
import dev.office.networkoffice.gathering.controller.dto.request.GatheringSuccessDto;
import dev.office.networkoffice.gathering.controller.dto.response.GatheringClosedResponse;
import dev.office.networkoffice.gathering.controller.dto.response.GatheringListResponseDto;
import dev.office.networkoffice.gathering.controller.dto.response.GatheringResponseDto;
import dev.office.networkoffice.gathering.service.GatheringService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.security.Principal;

@RestController
@RequestMapping("api/v1/gathering")
@RequiredArgsConstructor
public class GatheringController implements GatheringApiDocs {

private final GatheringService gatheringService;

@GetMapping
public GatheringListResponseDto findGatheringList(Principal principal,
@RequestParam("si") String si,
@RequestParam("dong") String dong,
@RequestParam("gu") String gu) {
return gatheringService.getGatheringByPlace(si, dong, gu);
}

@PostMapping
public GatheringResponseDto createGathering(Principal principal,
@RequestBody GatheringDto gatheringDto) {
Long userId = getUserId(principal);
return gatheringService.createGathering(userId, gatheringDto);
}

@PutMapping("{gatheringId}")
public GatheringResponseDto modifyGatheringByHost(Principal principal,
@PathVariable("gatheringId") Long gatheringId,
@RequestBody GatheringDto gatheringDto) {
Long userId = getUserId(principal);
return gatheringService.modifyGatheringInfoByHost(userId, gatheringId, gatheringDto);
}

@PostMapping("{gatheringId}/success")
public GatheringClosedResponse successGatheringByHost(Principal principal,
@PathVariable("gatheringId") Long gatheringId,
GatheringSuccessDto successDto) {
Long userId = getUserId(principal);
return gatheringService.successGatheringByHost(userId, gatheringId, successDto);
}

@PostMapping("{gatheringId}/cancel")
public GatheringClosedResponse cancelGatheringByHost(Principal principal,
@PathVariable("gatheringId") Long gatheringId,
GatheringCancelDto cancelDto) {
Long userId = getUserId(principal);
return gatheringService.cancelGatheringByHost(userId, gatheringId, cancelDto);
}

private Long getUserId(Principal principal) {
return Long.parseLong(principal.getName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package dev.office.networkoffice.gathering.controller.docs;

import dev.office.networkoffice.gathering.controller.dto.request.GatheringCancelDto;
import dev.office.networkoffice.gathering.controller.dto.request.GatheringDto;
import dev.office.networkoffice.gathering.controller.dto.request.GatheringSuccessDto;
import dev.office.networkoffice.gathering.controller.dto.response.GatheringClosedResponse;
import dev.office.networkoffice.gathering.controller.dto.response.GatheringListResponseDto;
import dev.office.networkoffice.gathering.controller.dto.response.GatheringResponseDto;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;

import java.security.Principal;

@Tag(name = "모임", description = "모임 관련 API")
public interface GatheringApiDocs {

@Operation(summary = "모임 조회")
@ApiResponses(value = {
@ApiResponse(
responseCode = "200",
description = "요청이 정상적으로 처리되었을 때"
),
@ApiResponse(
responseCode = "400",
description = "유효하지 않은 코드가 전달되었을 때"
)
})
GatheringListResponseDto findGatheringList(Principal principal, String si, String dong, String gu);

@Operation(summary = "모임 생성")
@ApiResponses(value = {
@ApiResponse(
responseCode = "200",
description = "요청이 정상적으로 처리되었을 때"
),
@ApiResponse(
responseCode = "400",
description = "유효하지 않은 코드가 전달되었을 때"
)
})
GatheringResponseDto createGathering(Principal principal, GatheringDto gatheringDto);

@Operation(summary = "모임 수정")
@ApiResponses(value = {
@ApiResponse(
responseCode = "200",
description = "요청이 정상적으로 처리되었을 때"
),
@ApiResponse(
responseCode = "400",
description = "유효하지 않은 코드가 전달되었을 때"
)
})
GatheringResponseDto modifyGatheringByHost(Principal principal,
Long gatheringId,
GatheringDto gatheringDto);

@Operation(summary = "모임 파토")
@ApiResponses(value = {
@ApiResponse(
responseCode = "200",
description = "요청이 정상적으로 처리되었을 때"
),
@ApiResponse(
responseCode = "400",
description = "유효하지 않은 코드가 전달되었을 때"
)
})
GatheringClosedResponse cancelGatheringByHost(Principal principal,
Long gatheringId,
GatheringCancelDto cancelDto);

@Operation(summary = "모임 성공적 종료")
@ApiResponses(value = {
@ApiResponse(
responseCode = "200",
description = "요청이 정상적으로 처리되었을 때"
),
@ApiResponse(
responseCode = "400",
description = "유효하지 않은 코드가 전달되었을 때"
)
})
GatheringClosedResponse successGatheringByHost(Principal principal,
Long gatheringId,
GatheringSuccessDto successDto);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package dev.office.networkoffice.gathering.controller.dto.request;

import dev.office.networkoffice.gathering.domain.ReasonForCanceled;

public record GatheringCancelDto(
ReasonForCanceled reason
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package dev.office.networkoffice.gathering.controller.dto.request;

import java.time.LocalDateTime;
import dev.office.networkoffice.gathering.entity.PlaceInfo;
import dev.office.networkoffice.gathering.entity.TimeInfo;

public record GatheringDto(
String title,
String category,
String description,

String place,
String detailPlace,

String si,
String dong,
String gu,

Double x,
Double y,

String date,
LocalDateTime startTime,
LocalDateTime endTime
) {
public PlaceInfo placeInfoConstructor() {
return PlaceInfo.builder()
.place(place).detailPlace(detailPlace)
.si(si).dong(dong).gu(gu)
.x(x).y(y)
.build();
}

public TimeInfo timeInfoConstructor() {
return TimeInfo.builder()
.date(date)
.startTime(startTime)
.endTime(endTime)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package dev.office.networkoffice.gathering.controller.dto.request;

public record GatheringSuccessDto(
String review,
Integer star
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dev.office.networkoffice.gathering.controller.dto.response;

public record GatheringClosedResponse(
String gatheringStatus
) {
public static GatheringClosedResponse from(String gatheringStatus) {
return new GatheringClosedResponse(gatheringStatus);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package dev.office.networkoffice.gathering.controller.dto.response;

import java.util.List;

public record GatheringListResponseDto(
List<GatheringResponseDto> gatherings
) {
public static GatheringListResponseDto from(List<GatheringResponseDto> gatherings) {
return new GatheringListResponseDto(gatherings);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package dev.office.networkoffice.gathering.controller.dto.response;

import java.time.LocalDateTime;

import dev.office.networkoffice.gathering.entity.Gathering;
import lombok.Builder;

@Builder
public record GatheringResponseDto(
Long id,
String title,
String category,
String description,

String place,
String detailPlace,

Double x,
Double y,

String date,
LocalDateTime startTime,
LocalDateTime endTime
) {
public static GatheringResponseDto from(Gathering gathering) {
return GatheringResponseDto.builder()
.id(gathering.getId())
.title(gathering.getTitle())
.category(String.valueOf(gathering.getCategory()))
.description(gathering.getDescription())
.place(gathering.getPlaceInfo().getPlace())
.detailPlace(gathering.getPlaceInfo().getDetailPlace())
.x(gathering.getPlaceInfo().getX())
.y(gathering.getPlaceInfo().getY())
.date(gathering.getTimeInfo().getDate())
.startTime(gathering.getTimeInfo().getStartTime())
.endTime(gathering.getTimeInfo().getEndTime())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package dev.office.networkoffice.gathering.domain;

public enum Category {
SPORT,
CULTURE,
PARTY,
FOOD,
VOLUNTEER,
COFFEE,
STUDY,
WALK,
ETC
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package dev.office.networkoffice.gathering.domain;

/**
* 모임의 상태를 정의 합니다.
*/
public enum GatheringStatus {
CANCELED,
SUCCESSFUL,
REPORT,
IN_PROGRESS
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package dev.office.networkoffice.gathering.domain;

/**
* 모임 터짐 사유 종류를 정의 합니다.
*/
public enum ReasonForCanceled {
INSUFFICIENT_PEOPLE,
PERSONAL_REASON,
BAD_CONTENTS_GATHERINGS
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package dev.office.networkoffice.gathering.domain;

/**
* 모임 추방 사유를 정의 합니다.
*/
public enum ReasonForDeportation {
PAPERING,
CUSS_WORD,
SEXUAL_CONTENTS,
ADVERTISEMENT,
RELIGIOUS_POLITICAL_SPEECH,
CRIMINAL_ACTS
}
Loading

0 comments on commit f8e0dd9

Please sign in to comment.