Skip to content

Commit

Permalink
Merge branch 'release-1.0.3' into Fix/remain-only-one-part2
Browse files Browse the repository at this point in the history
  • Loading branch information
wochae authored Feb 14, 2024
2 parents 4f63d9f + 1d24aa8 commit ae5cbcb
Show file tree
Hide file tree
Showing 22 changed files with 398 additions and 205 deletions.
12 changes: 12 additions & 0 deletions src/main/java/peer/backend/annotation/ValidUserId.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package peer.backend.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface ValidUserId {

}
37 changes: 37 additions & 0 deletions src/main/java/peer/backend/aspect/ValidUserIdAspect.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package peer.backend.aspect;

import java.lang.reflect.Method;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;
import peer.backend.exception.BadRequestException;

@Aspect
@Component
public class ValidUserIdAspect {

@Pointcut("@annotation(peer.backend.annotation.ValidUserId)")
public void validUserId() {
}

@Before("validUserId()")
public void validUserId(JoinPoint joinPoint) {
Object[] args = joinPoint.getArgs();

MethodSignature signature = (MethodSignature) joinPoint.getSignature();
Method method = signature.getMethod();

for (int i = 0; i < method.getParameters().length; i++) {
String parameterName = method.getParameters()[i].getName();
if (parameterName.equals("userId")) {
Long userId = (Long) args[i];
if (userId < 0) {
throw new BadRequestException("임시 혹은 탈퇴한 유저입니다!");
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import peer.backend.dto.noti.NotificationDTO;
import peer.backend.dto.noti.enums.NotificationType;
import peer.backend.dto.user.UserAlarmSettingDTO;
import peer.backend.entity.user.User;
import peer.backend.exception.BadRequestException;
import peer.backend.repository.user.UserRepository;
import peer.backend.service.noti.NotificationMainService;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping(NotificationController.MAPPING_URL)
Expand All @@ -31,28 +35,38 @@ public class NotificationController {
@GetMapping("/spring")
public ResponseEntity<?> getAlarmList(Authentication auth,
@Param("type") NotificationType type,
@Param("pgIdx") Long pageIndex,
@Param("pgIdx") Long pgIdx,
@Param("Size") Long size) {
//TODO : making code logic
//TODO: User-> newAlarmCounter = 0 으로 만들어버리기(전체 일때만)

return new ResponseEntity<>(HttpStatus.OK);
List<NotificationDTO> result = new ArrayList<>();
try {
result = this.notificationMainService.getNotificationList(User.authenticationToUser(auth), type, pgIdx, size);
} catch (BadRequestException e) {
return ResponseEntity.badRequest().build();
}
return ResponseEntity.ok().body(result);
}

///api/v1/noti/spring/delete-all?type=${}
@DeleteMapping("/spring/delete-all")
public ResponseEntity<?> deleteAlarmAll(Authentication auth,
public ResponseEntity<Void> deleteAlarmAll(Authentication auth,
@Param("type") NotificationType type) {
//TODO : making code logic
return new ResponseEntity<>(HttpStatus.OK);
this.notificationMainService.deleteNotificationAll(
User.authenticationToUser(auth),
type);
return ResponseEntity.ok().build();
}

///api/v1/noti/spring/delete-taget?targetId=${alarmId}
@DeleteMapping("/spring/delete-target")
public ResponseEntity<?> deleteAlarmTarget(Authentication auth,
@Param("targetId") Long alarmId) {
//TODO : making code logic
return new ResponseEntity<>(HttpStatus.OK);
@Param("notificationId") Long notificationId) {
try {
this.notificationMainService.deleteNotification(
User.authenticationToUser(auth),
notificationId
);
} catch (BadRequestException e) {
return ResponseEntity.badRequest().body(e);
}
return ResponseEntity.ok().build();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ public class ObjectController {

private final ObjectService objectService;

@PostMapping("/editor/image")
public String uploadImage(@RequestParam("image")MultipartFile image, Authentication auth) throws IOException {
return objectService.uploadImage(image, "editor/" + User.authenticationToUser(auth).getId());
@PostMapping({"/editor/image", "/admin/editor/image"})
public String uploadImage(@RequestParam("image") MultipartFile image, Authentication auth)
throws IOException {
return objectService.uploadImage(image,
"editor/" + User.authenticationToUser(auth).getId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ public class AboutAnnouncementResponse {

private String content;

private String image;

private Long view;

@JsonFormat(shape = Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm", timezone = "Asia/Seoul")
Expand All @@ -29,7 +27,6 @@ public AboutAnnouncementResponse(Announcement announcement) {
this.title = announcement.getTitle();
this.writer = announcement.getWriter();
this.content = announcement.getContent();
this.image = announcement.getImage();
this.view = announcement.getView();
this.createdAt = announcement.getCreatedAt();
this.updatedAt = announcement.getUpdatedAt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ public class AnnouncementListResponse {
private final Long announcementId;
private final AnnouncementStatus announcementStatus;
private final String title;
private final String image;

public AnnouncementListResponse(Announcement announcement) {
this.announcementId = announcement.getId();
this.announcementStatus = announcement.getAnnouncementStatus();
this.title = announcement.getTitle();
this.image = announcement.getImage();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public class AnnouncementResponse {
private final String title;
private final String writer;
private final String content;
private final String image;
private final Long view;
private final AnnouncementStatus announcementStatus;
@JsonFormat(shape = Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm", timezone = "Asia/Seoul")
Expand All @@ -23,7 +22,6 @@ public AnnouncementResponse(Announcement announcement) {
this.title = announcement.getTitle();
this.writer = announcement.getWriter();
this.content = announcement.getContent();
this.image = announcement.getImage();
this.view = announcement.getView();
this.announcementStatus = announcement.getAnnouncementStatus();
if (this.announcementStatus.equals(AnnouncementStatus.RESERVATION)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ public class CreateAnnouncementRequest {
@Size(max = 10000, message = "길이는 10000 이하여야합니다.")
private String content;

@NotBlank(message = "이미지는 필수입니다.")
private String image;

@ValidEnum(enumClass = AnnouncementNoticeStatus.class)
private AnnouncementNoticeStatus announcementNoticeStatus;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,10 @@
package peer.backend.dto.announcement;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonFormat.Shape;
import java.time.LocalDateTime;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import lombok.Getter;
import peer.backend.annotation.ValidEnum;
import peer.backend.entity.announcement.AnnouncementNoticeStatus;

@Getter
public class UpdateAnnouncementRequest {

@NotBlank(message = "제목은 필수입니다.")
@Size(max = 30, message = "길이는 30 이하여야합니다.")
private String title;

@NotBlank(message = "작성자는 필수입니다.")
@Size(max = 10, message = "길이는 10 이하여야합니다.")
private String writer;

@NotBlank(message = "내용은 필수입니다.")
@Size(max = 10000, message = "길이는 10000 이하여야합니다.")
private String content;

private String image;

@ValidEnum(enumClass = AnnouncementNoticeStatus.class)
private AnnouncementNoticeStatus announcementNoticeStatus;

@JsonFormat(shape = Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm", timezone = "Asia/Seoul")
private LocalDateTime reservationDate;
public class UpdateAnnouncementRequest extends CreateAnnouncementRequest {

@NotNull(message = "공지사항 ID는 필수입니다.")
private Long announcementId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class PostCommentListResponse {
private String createAt;
@JsonProperty("isAuthor")
private boolean isAuthor;
private Long authorId;

public PostCommentListResponse(PostComment comment, User user){
User author = comment.getUser();
Expand All @@ -31,5 +32,6 @@ public PostCommentListResponse(PostComment comment, User user){
this.content = comment.getContent();
this.createAt = comment.getCreatedAt().toString();
this.isAuthor = Objects.equals(author, user);
this.authorId = (author == null) ? -1 : author.getId();
}
}
32 changes: 31 additions & 1 deletion src/main/java/peer/backend/dto/noti/NotificationDTO.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
package peer.backend.dto.noti;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Builder;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import peer.backend.entity.noti.Notification;

import java.time.LocalDateTime;

@Getter
@RequiredArgsConstructor
public class NotificationDTO {
//TODO: 포어그라운드에서 전달하는 알람 형태 DTO
private String title;
private String body;
private String redirectUrl;
private LocalDateTime issuedAt;
private Long notificationId;
private String type;
private String iconUrl;

@JsonProperty("isEnd")
private boolean end;

public NotificationDTO(Notification data, boolean end) {
this.title = data.getTitle();
this.body = data.getBody();
this.redirectUrl = data.getLinkData();
this.issuedAt = data.getCreatedAt();
this.notificationId = data.getId();
this.type = data.getMessageType().getValue();
this.iconUrl = data.getImageUrl();
this.end = end;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
@Getter
@RequiredArgsConstructor
public enum NotificationType {

ALL("ALL"),
MESSAGE("MESSAGE"),
TEAM("TEAM"),
SYSTEM("SYSTEM");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ public class Announcement extends BaseEntity {
@Column(nullable = false, columnDefinition = "LONGTEXT")
private String content;

@Column(nullable = false, columnDefinition = "TEXT")
private String image;

@Column(nullable = false)
private Long view;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/peer/backend/entity/noti/Notification.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ public class Notification extends BaseEntity {
@Column
private Integer referenceCounter;

@OneToMany(mappedBy = "specificEvent", cascade = CascadeType.ALL)
@OneToMany(mappedBy = "specificEvent", cascade = CascadeType.PERSIST)
private List<NotificationTarget> targetList;
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public class NotificationTarget extends BaseEntity {
private Notification specificEvent;

private void repackUserIds(List<Long> userIds) {
if (userIds == null) {
this.userList = "";
return;
}
this.userList = "";
userIds.forEach(l -> this.userList += l + "###");
}
Expand Down
15 changes: 9 additions & 6 deletions src/main/java/peer/backend/entity/team/Team.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,11 @@ public void update(TeamSettingInfoDto teamSettingInfoDto) {
this.name = teamSettingInfoDto.getName();
this.dueTo = RecruitDueEnum.from(teamSettingInfoDto.getDueTo());
this.status = teamSettingInfoDto.getStatus();
if (this.status != TeamStatus.RECRUITING)
if (this.status != TeamStatus.RECRUITING) {
recruit.setStatus(RecruitStatus.DONE);
else
} else {
recruit.setStatus(RecruitStatus.ONGOING);
}
String[] regions = teamSettingInfoDto.getRegion();
if (teamSettingInfoDto.getRegion().length == 2) {
this.region1 = regions[0];
Expand All @@ -155,11 +156,11 @@ public void update(RecruitUpdateRequestDTO request) {
this.region2 = request.getRegion2();
}
this.operationFormat = TeamOperationFormat.from(request.getPlace());
if (request.getType().equals(TeamType.STUDY.getValue()))
{
if (request.getType().equals(TeamType.STUDY.getValue())) {
TeamJob data;
// this.jobs.stream().filter(job -> job.getName().equals("STUDY")).findFirst().get().setMax(request.getMax());
data = this.jobs.stream().filter(job -> job.getName().equals("STUDY")).findFirst().orElseThrow(() -> new NoSuchElementException("업데이트 중 문제가 발생하였습니다."));
data = this.jobs.stream().filter(job -> job.getName().equals("STUDY")).findFirst()
.orElseThrow(() -> new NoSuchElementException("업데이트 중 문제가 발생하였습니다."));
data.setMax(request.getMax());
}
}
Expand Down Expand Up @@ -200,12 +201,14 @@ public boolean deleteTeamUser(Long deletingToUserId) {
return this.teamUsers.removeIf(teamUser -> teamUser.getUserId().equals(deletingToUserId));
}

public void grantLeaderPermission(Long grantingUserId, TeamUserRoleType teamUserRoleType) {
public boolean grantLeaderPermission(Long grantingUserId, TeamUserRoleType teamUserRoleType) {
for (TeamUser teamUser : this.teamUsers) {
if (teamUser.getUserId().equals(grantingUserId)) {
teamUser.grantLeader(teamUserRoleType);
return true;
}
}
return false;
}

public void setTeamLogoPath(String teamLogoPath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.lettuce.core.dynamic.annotation.Param;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import peer.backend.entity.noti.Notification;

Expand Down
Loading

0 comments on commit ae5cbcb

Please sign in to comment.