Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v.1.3.0 (#811) #812

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.scheduling.annotation.EnableAsync;

@EnableAsync
@ConfigurationPropertiesScan
@SpringBootApplication
public class VotogetherApplication {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.votogether.domain.alarm.controller;

import com.votogether.domain.alarm.service.AlarmCommandService;
import com.votogether.domain.member.entity.Member;
import com.votogether.global.jwt.Auth;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Positive;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Validated
@RequiredArgsConstructor
@RequestMapping("/alarms")
@RestController
public class AlarmCommandController implements AlarmCommandControllerDocs {

private final AlarmCommandService alarmCommandService;

@PatchMapping("/{id}")
public ResponseEntity<Void> readAlarm(
@PathVariable("id") @Positive(message = "알림 ID는 양수만 가능합니다.") final Long alarmId,
@RequestParam("type") @NotBlank(message = "알림 타입이 공백이거나 존재하지 않습니다.") final String type,
@Auth final Member loginMember
) {
alarmCommandService.readAlarm(alarmId, type, loginMember);
return ResponseEntity.ok().build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.votogether.domain.alarm.controller;

import com.votogether.domain.member.entity.Member;
import com.votogether.global.exception.ExceptionResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
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 jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Positive;
import org.springframework.http.ResponseEntity;

@Tag(name = "알림 커맨드", description = "알림 커맨드 API")
public interface AlarmCommandControllerDocs {

@Operation(
summary = "알림 읽기",
description = "알림을 읽을 수 있는 대상이라면 알림을 읽습니다."
)
@ApiResponses({
@ApiResponse(
responseCode = "200",
description = "알림 읽기 성공"
),
@ApiResponse(
responseCode = "400",
description = """
1.알림 ID가 양수가 아닌 경우

2.알림을 읽을 수 있는 대상이 아닌 경우
""",
content = @Content(schema = @Schema(implementation = ExceptionResponse.class))
),
@ApiResponse(
responseCode = "404",
description = "알림이 존재하지 않은 경우",
content = @Content(schema = @Schema(implementation = ExceptionResponse.class))
)
})
ResponseEntity<Void> readAlarm(
@Parameter(description = "알림 ID", example = "1")
@Positive(message = "알림 ID는 양수만 가능합니다.") final Long alarmId,
@Parameter(description = "알림 타입", example = "CONTENT")
@NotBlank(message = "알림 타입이 공백이거나 존재하지 않습니다.") final String alarmType,
final Member loginMember
);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.votogether.domain.alarm.controller;

import com.votogether.domain.alarm.dto.response.ReportActionAlarmResponse;
import com.votogether.domain.alarm.dto.response.ReportActionResponse;
import com.votogether.domain.alarm.dto.response.PostAlarmResponse;
import com.votogether.domain.alarm.service.AlarmQueryService;
import com.votogether.domain.member.entity.Member;
import com.votogether.global.jwt.Auth;
import jakarta.validation.constraints.PositiveOrZero;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Validated
@RequiredArgsConstructor
@RequestMapping("/alarms")
@RestController
public class AlarmQueryController implements AlarmQueryControllerDocs {

private final AlarmQueryService alarmQueryService;

@GetMapping("/content")
public ResponseEntity<List<PostAlarmResponse>> getPostAlarm(
@RequestParam @PositiveOrZero(message = "페이지는 0이상 정수만 가능합니다.") final int page,
@Auth final Member loginMember
) {
final List<PostAlarmResponse> postAlarmResponses = alarmQueryService.getPostAlarm(loginMember, page);
return ResponseEntity.ok(postAlarmResponses);
}

@GetMapping("/report")
public ResponseEntity<List<ReportActionAlarmResponse>> getReportActionAlarms(
@RequestParam @PositiveOrZero(message = "페이지는 0이상 정수만 가능합니다.") final int page,
@Auth final Member member
) {
final List<ReportActionAlarmResponse> response = alarmQueryService.getReportActionAlarms(member, page);
return ResponseEntity.ok(response);
}

@GetMapping("/report/{id}")
public ResponseEntity<ReportActionResponse> getReportActionAlarm(
@PathVariable("id") final Long reportActionAlarmId,
@Auth final Member member
) {
final ReportActionResponse response =
alarmQueryService.getReportActionAlarm(reportActionAlarmId, member);
return ResponseEntity.ok(response);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.votogether.domain.alarm.controller;

import com.votogether.domain.alarm.dto.response.ReportActionAlarmResponse;
import com.votogether.domain.alarm.dto.response.ReportActionResponse;
import com.votogether.domain.alarm.dto.response.PostAlarmResponse;
import com.votogether.domain.member.entity.Member;
import com.votogether.global.exception.ExceptionResponse;
import com.votogether.global.jwt.Auth;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
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 jakarta.validation.constraints.PositiveOrZero;
import java.util.List;
import org.springframework.http.ResponseEntity;

@Tag(name = "알림 조회", description = "알림 조회 API")
public interface AlarmQueryControllerDocs {

@Operation(
summary = "게시글 내역 알림 조회",
description = "게시글 내역 알림을 조회한다."
)
@ApiResponses({
@ApiResponse(
responseCode = "200",
description = "게시글 내역 알림 조회 성공"
),
@ApiResponse(
responseCode = "400",
description = "0 이상의 정수가 아닌 페이지",
content = @Content(schema = @Schema(implementation = ExceptionResponse.class))
)
})
ResponseEntity<List<PostAlarmResponse>> getPostAlarm(
@PositiveOrZero(message = "페이지는 0이상 정수만 가능합니다.") final int page,
@Auth final Member loginMember
);

@Operation(
summary = "신고조치알림 조회",
description = "신고조치알림목록을 조회한다."
)
@ApiResponses({
@ApiResponse(
responseCode = "201",
description = "신고조치알림 조회 성공"
),
@ApiResponse(
responseCode = "400",
description = "페이지가 0이상 정수가 아닌 경우",
content = @Content(schema = @Schema(implementation = ExceptionResponse.class))
)
})
ResponseEntity<List<ReportActionAlarmResponse>> getReportActionAlarms(
@Parameter(description = "현재 페이지 위치", example = "0")
@PositiveOrZero(message = "페이지는 0이상 정수만 가능합니다.") final int page,
final Member member
);

@Operation(
summary = "신고조치알림 상세 조회",
description = "신고조치알림를 상세 조회한다."
)
@ApiResponse(
responseCode = "201",
description = "신고조치알림 상세 조회 성공"
)
ResponseEntity<ReportActionResponse> getReportActionAlarm(
@Parameter(description = "신고조치알림 ID", example = "1") final Long reportActionAlarmId,
final Member member
);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.votogether.domain.alarm.dto.event;

import com.votogether.domain.alarm.entity.vo.AlarmType;
import com.votogether.domain.member.entity.Member;

public record PostAlarmEvent(
Member member,
String commentWriterNickname,
Long targetId,
AlarmType alarmType,
String detail
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.votogether.domain.alarm.dto.response;

import com.votogether.domain.alarm.entity.Alarm;
import io.swagger.v3.oas.annotations.media.Schema;

@Schema(description = "게시글 내역 세부 사항 응답")
public record PostAlarmDetailResponse(
@Schema(description = "게시글 ID", example = "1")
Long postId,

@Schema(description = "게시글 제목", example = "제목입니다.")
String postTitle,

@Schema(description = "댓글 작성자 닉네임", example = "저문")
String commentWriter
) {

public static PostAlarmDetailResponse of(final Alarm alarm) {
return new PostAlarmDetailResponse(
alarm.getTargetId(),
alarm.getDetail(),
alarm.getCommentWriterNickname()
);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.votogether.domain.alarm.dto.response;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.votogether.domain.alarm.entity.Alarm;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDateTime;

@Schema(description = "게시글 내역 조회 응답")
public record PostAlarmResponse(
@Schema(description = "알림 ID", example = "1")
Long alarmId,

@Schema(description = "알림 세부 사항")
PostAlarmDetailResponse detail,

@Schema(description = "게시글 생성 시각", example = "2023-10-16 21:25")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm")
LocalDateTime createdAt,

@Schema(description = "알림 확인 여부", example = "false")
boolean isChecked
) {

public static PostAlarmResponse of(final Alarm alarm) {
return new PostAlarmResponse(
alarm.getId(),
PostAlarmDetailResponse.of(alarm),
alarm.getCreatedAt(),
alarm.isChecked()
);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.votogether.domain.alarm.dto.response;

import com.votogether.domain.alarm.entity.ReportActionAlarm;
import io.swagger.v3.oas.annotations.media.Schema;

@Schema(description = "신고조치알림 응답")
public record ReportActionAlarmResponse(
@Schema(description = "알림 ID", example = "1")
Long alarmId,

@Schema(description = "확인 여부", example = "false")
boolean isChecked,

@Schema(description = "신고조치 세부정보")
ReportActionResponse detail
) {

public static ReportActionAlarmResponse from(
final ReportActionAlarm reportActionAlarm
) {
return new ReportActionAlarmResponse(
reportActionAlarm.getId(),
reportActionAlarm.isChecked(),
ReportActionResponse.from(reportActionAlarm)
);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.votogether.domain.alarm.dto.response;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.votogether.domain.alarm.entity.ReportActionAlarm;
import com.votogether.domain.report.entity.vo.ReportType;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.LocalDateTime;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Schema(description = "신고조치 응답")
public record ReportActionResponse(
@Schema(description = "신고조치 ID", example = "1")
Long reportActionId,

@Schema(description = "신고조치타입", example = "POST")
ReportType type,

@Schema(description = "신고대상내용", example = "1")
String content,

@Schema(description = "신고사유")
Set<String> reasons,

@Schema(description = "신고조치시간", example = "2023-08-01 13:56")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm")
LocalDateTime createdAt
) {

public static ReportActionResponse from(final ReportActionAlarm reportActionAlarm) {
final Set<String> reasons = Stream.of(reportActionAlarm.getReasons().split(","))
.map(String::strip)
.collect(Collectors.toSet());

return new ReportActionResponse(
reportActionAlarm.getId(),
reportActionAlarm.getReportType(),
reportActionAlarm.getTarget(),
reasons,
reportActionAlarm.getCreatedAt()
);
}
}
Loading
Loading