Skip to content

Commit

Permalink
Merge branch 'dev' into 653-feature-admin-category-add
Browse files Browse the repository at this point in the history
  • Loading branch information
AreSain authored Mar 8, 2024
2 parents 2aa1656 + 06d6316 commit a0b23ce
Show file tree
Hide file tree
Showing 27 changed files with 514 additions and 23 deletions.
16 changes: 10 additions & 6 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ flags:
unitTest:
paths:
- gg-pingpong-api/src/main/java/gg/pingpong/api
- gg-pingpong-repo/src/main/java/gg/pingpong/repo
- gg-pingpong-admin-repo/src/main/java/gg/pingpong/admin/repo
- gg-pingpong-data/src/main/java/gg/pingpong/data
- gg-repo/src/main/java/gg/repo
- gg-admin-repo/src/main/java/gg/admin/repo
- gg-data/src/main/java/gg/data
- gg-auth/src/main/java/gg/auth
- gg-utils/src/main/java/gg/utils
integrationTest:
paths:
- gg-pingpong-api/src/main/java/gg/pingpong/api
- gg-pingpong-repo/src/main/java/gg/pingpong/repo
- gg-pingpong-admin-repo/src/main/java/gg/pingpong/admin/repo
- gg-pingpong-data/src/main/java/gg/pingpong/data
- gg-repo/src/main/java/gg/repo
- gg-admin-repo/src/main/java/gg/admin/repo
- gg-data/src/main/java/gg/data
- gg-auth/src/main/java/gg/auth
- gg-utils/src/main/java/gg/utils
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@
import gg.data.party.Category;

public interface CategoryAdminRepository extends JpaRepository<Category, Long> {

Boolean existsByName(String categoryName);
}
48 changes: 48 additions & 0 deletions gg-data/src/main/java/gg/data/party/PartyPenalty.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package gg.data.party;

import java.time.LocalDateTime;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.validation.constraints.NotNull;

import gg.data.BaseTimeEntity;
import gg.data.user.User;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Entity
public class PartyPenalty extends BaseTimeEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@NotNull
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User user;

@NotNull
@Column(name = "penalty_type", length = 20)
private String penaltyType;

@Column(name = "message", length = 100)
private String message;

@NotNull
@Column(name = "start_time")
private LocalDateTime startTime;

@NotNull
@Column(name = "penalty_time")
private Integer penaltyTime;
}
7 changes: 7 additions & 0 deletions gg-data/src/main/java/gg/data/party/RoomReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,11 @@ public class RoomReport extends BaseTimeEntity {

@Column(length = 100)
private String message;

public RoomReport(User reporter, User reportee, Room room, String message) {
this.reporter = reporter;
this.reportee = reportee;
this.room = room;
this.message = message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
Expand All @@ -12,8 +13,8 @@

import gg.data.party.type.RoomType;
import gg.party.api.admin.room.controller.request.RoomShowChangeReqDto;
import gg.party.api.admin.room.controller.response.AdminRoomListResDto;
import gg.party.api.admin.room.service.RoomAdminService;
import gg.utils.exception.ErrorCode;
import gg.utils.exception.party.RoomNotFoundException;
import gg.utils.exception.party.RoomStatNotFoundException;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -45,4 +46,14 @@ public ResponseEntity<Void> changeRoomVisibility(@PathVariable Long roomId,
roomAdminService.modifyRoomStatus(roomId, roomType);
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}

/**
* 방 전체 조회
* @return 방 정보 dto
*/
@GetMapping
public ResponseEntity<AdminRoomListResDto> adminAllRoomList() {
AdminRoomListResDto adminRoomListResDto = roomAdminService.findAllRoomList();
return ResponseEntity.status(HttpStatus.OK).body(adminRoomListResDto);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package gg.party.api.admin.room.controller.response;

import java.util.List;

import lombok.Getter;
import lombok.NoArgsConstructor;

@NoArgsConstructor(access = lombok.AccessLevel.PROTECTED)
@Getter
public class AdminRoomListResDto {
private List<AdminRoomResDto> roomList;

public AdminRoomListResDto(List<AdminRoomResDto> roomList) {
this.roomList = roomList;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package gg.party.api.admin.room.controller.response;

import java.time.LocalDateTime;

import gg.data.party.Room;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class AdminRoomResDto {
private Long roomId;
private Long hostId;
private String creatorIntraId;
private Long categoryId;
private String title;
private String content;
private Integer currentPeople;
private Integer maxPeople;
private Integer minPeople;
private LocalDateTime dueDate;
private LocalDateTime createDate;
private String status;

public AdminRoomResDto(Room room) {
this.roomId = room.getId();
this.hostId = room.getHost().getId();
this.creatorIntraId = room.getCreator().getIntraId();
this.categoryId = room.getCategory().getId();
this.title = room.getTitle();
this.content = room.getContent();
this.currentPeople = room.getCurrentPeople();
this.maxPeople = room.getMaxPeople();
this.minPeople = room.getMinPeople();
this.dueDate = room.getDueDate();
this.createDate = room.getCreatedAt();
this.status = room.getStatus().toString();
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package gg.party.api.admin.room.service;

import java.util.List;
import java.util.stream.Collectors;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import gg.data.party.Room;
import gg.data.party.type.RoomType;
import gg.party.api.admin.room.controller.response.AdminRoomListResDto;
import gg.party.api.admin.room.controller.response.AdminRoomResDto;
import gg.repo.party.RoomRepository;
import gg.utils.exception.party.RoomNotFoundException;
import gg.utils.exception.party.RoomSameStatusException;
Expand Down Expand Up @@ -34,4 +39,19 @@ public void modifyRoomStatus(Long roomId, RoomType newStatus) {
room.updateRoomStatus(newStatus);
roomRepository.save(room);
}

/**
* 방 전체 조회
* @return 방 정보 dto
*/
@Transactional
public AdminRoomListResDto findAllRoomList() {
List<Room> allRooms = roomRepository.findAll();

List<AdminRoomResDto> adminRoomListResDto = allRooms.stream()
.map(AdminRoomResDto::new)
.collect(Collectors.toList());

return new AdminRoomListResDto(adminRoomListResDto);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package gg.party.api.admin.templates.controller;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import gg.party.api.admin.templates.service.TemplateAdminService;
import lombok.RequiredArgsConstructor;

@RestController
@RequiredArgsConstructor
@RequestMapping("/party/admin/templates")
public class TemplateAdminController {
private final TemplateAdminService templateAdminService;

/**
* 템플릿 삭제
* return 204 status code(성공적인 삭제 status)
*/
@DeleteMapping("/{templateId}")
public ResponseEntity<Void> removeTemplate(@PathVariable Long templateId) {
templateAdminService.removeTemplate(templateId);
return ResponseEntity.noContent().build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package gg.party.api.admin.templates.service;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import gg.repo.party.TemplateRepository;
import gg.utils.exception.party.TemplateNotFoundException;
import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class TemplateAdminService {
private final TemplateRepository templateRepository;

/**
* 템플릿 삭제
*/
@Transactional
public void removeTemplate(Long templateId) {
if (!templateRepository.existsById(templateId)) {
throw new TemplateNotFoundException();
}
templateRepository.deleteById(templateId);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,39 @@
package gg.pingpong.api.party.user.report.controller;
package gg.party.api.user.report.controller;

import javax.validation.Valid;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import gg.auth.UserDto;
import gg.auth.argumentresolver.Login;
import gg.party.api.user.report.request.ReportRoomReqDto;
import gg.party.api.user.report.service.ReportService;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;

@RestController
@RequiredArgsConstructor
@RequestMapping("/party/reports")
public class ReportController {
private final ReportService reportService;

/**
* 방을 신고한다.
* @param reportRoomReqDto 신고 내용
* @param roomId 방 번호
* @return 참여중인 방 전체 List
*/
@PostMapping("/rooms/{room_id}")
public ResponseEntity<Long> reportRoomAdd(@PathVariable("room_id") Long roomId,
@RequestBody @Valid ReportRoomReqDto reportRoomReqDto,
@Parameter(hidden = true) @Login UserDto user) {
return ResponseEntity.status(HttpStatus.CREATED)
.body(reportService.addReportRoom(roomId, reportRoomReqDto, user));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package gg.party.api.user.report.request;

import javax.validation.constraints.Size;

import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class ReportRoomReqDto {
@Size(min = 1, max = 200)
private String content;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package gg.party.api.user.report.service;

import java.util.List;
import java.util.Optional;

import javax.transaction.Transactional;

import org.springframework.stereotype.Service;

import gg.auth.UserDto;
import gg.data.party.Room;
import gg.data.party.RoomReport;
import gg.data.party.type.RoomType;
import gg.data.user.User;
import gg.party.api.user.report.request.ReportRoomReqDto;
import gg.repo.party.RoomReportRepository;
import gg.repo.party.RoomRepository;
import gg.repo.party.UserRoomRepository;
import gg.repo.user.UserRepository;
import gg.utils.exception.party.AlredayReportedRoomException;
import gg.utils.exception.party.RoomNotFoundException;
import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class ReportService {
private final RoomRepository roomRepository;
private final UserRepository userRepository;
private final UserRoomRepository userRoomRepository;
private final RoomReportRepository roomReportRepository;

/**
* 방을 신고한다.
* @param roomId 방 번호
* @param reportRoomReqDto 신고 내용
* @param user 신고자
* @exception RoomNotFoundException 방을 찾을 수 없음
* @exception AlredayReportedRoomException 이미 신고한 방
* @return 방 번호
*/
@Transactional
public Long addReportRoom(Long roomId, ReportRoomReqDto reportRoomReqDto, UserDto user) {
Room targetRoom = roomRepository.findById(roomId)
.orElseThrow(RoomNotFoundException::new);
User userEntity = userRepository.findById(user.getId()).get();
Optional<RoomReport> existingReport = roomReportRepository.findByReporterAndRoomId(userEntity,
targetRoom.getId());
if (existingReport.isPresent()) {
throw new AlredayReportedRoomException();
}
RoomReport roomReport = new RoomReport(userEntity, targetRoom.getCreator(), targetRoom,
reportRoomReqDto.getContent());
roomReportRepository.save(roomReport);

List<RoomReport> allReportRoom = roomReportRepository.findByRoomId(targetRoom.getId());
if (allReportRoom.size() == 3) {
targetRoom.updateStatus(RoomType.HIDDEN);
roomRepository.save(targetRoom);
}
// 사용자 정지
//partyGivePenalty(targetRoom.getCreator().getIntraId(), 24, "신고 3회 이상");
return roomId;
}
}
Loading

0 comments on commit a0b23ce

Please sign in to comment.