Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Feat/lostandfound [#7] #9

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package bssm.bsm.domain.board.lostfound.domain;

import bssm.bsm.domain.board.lostfound.domain.type.Process;
import bssm.bsm.domain.board.lostfound.domain.type.State;
import bssm.bsm.domain.user.domain.User;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import org.springframework.data.annotation.CreatedDate;

import javax.persistence.Column;
Expand All @@ -23,6 +26,7 @@
@Getter
@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Where(clause = "process = \"IN_PROGRESS\"")
public class LostFound {

@Id
Expand All @@ -44,22 +48,27 @@ public class LostFound {
@Enumerated(EnumType.STRING)
private Process process;

@Enumerated(EnumType.STRING)
private State state;

@OneToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "code", nullable = false)
private User foundUser;

@CreatedDate
private LocalDateTime createdLocalDateTime;


@Builder
public LostFound(Long id, String objectName, String imgSrc, String location, LocalDateTime findDateTime, String description, Process process, User user, LocalDateTime createdLocalDateTime) {
public LostFound(Long id, String objectName, String imgSrc, String location, LocalDateTime findDateTime, String description, Process process, User user, LocalDateTime createdLocalDateTime, State state) {
this.id = id;
this.objectName = objectName;
this.imgSrc = imgSrc;
this.location = location;
this.findDateTime = findDateTime;
this.description = description;
this.process = process;
this.state = state;
this.foundUser = user;
this.createdLocalDateTime = createdLocalDateTime;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package bssm.bsm.domain.board.lostfound.domain.repository;

import bssm.bsm.domain.board.lostfound.domain.type.Process;
import bssm.bsm.domain.board.lostfound.domain.type.State;
import bssm.bsm.domain.board.lostfound.presentation.dto.res.LostFoundCompactRes;

import java.util.List;

public interface CustomLostFoundRepository {
List<LostFoundCompactRes> findAllByProcess(Process process);
List<LostFoundCompactRes> findAllByState(State state);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package bssm.bsm.domain.board.lostfound.domain.repository;

import bssm.bsm.domain.board.lostfound.domain.type.Process;
import bssm.bsm.domain.board.lostfound.domain.type.State;
import bssm.bsm.domain.board.lostfound.presentation.dto.res.LostFoundCompactRes;
import com.querydsl.core.types.Projections;
import com.querydsl.jpa.impl.JPAQueryFactory;
Expand All @@ -15,16 +15,17 @@ public class CustomLostFoundRepositoryImpl implements CustomLostFoundRepository
private final JPAQueryFactory jpaQueryFactory;

@Override
public List<LostFoundCompactRes> findAllByProcess(Process process) {
public List<LostFoundCompactRes> findAllByState(State state) {
return jpaQueryFactory
.select(Projections.constructor(
LostFoundCompactRes.class,
lostFound.id,
lostFound.objectName,
lostFound.imgSrc,
lostFound.process))
lostFound.process,
lostFound.state))
.from(lostFound)
.where(lostFound.process.eq(process))
.where(lostFound.state.eq(state))
.orderBy(lostFound.createdLocalDateTime.desc())
.fetch();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package bssm.bsm.domain.board.lostfound.domain.type;

public enum State {
LOST,
FOUND
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@
import bssm.bsm.domain.board.lostfound.presentation.dto.res.LostFoundRes;
import bssm.bsm.domain.board.lostfound.service.LostFoundDefinitionService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
Expand All @@ -24,8 +20,8 @@ public LostFoundRes create(@Valid @RequestBody LostFoundReq lostFoundReq) {
return lostFoundDefinitionService.create(lostFoundReq);
}

@PutMapping("/update/{id}")
public LostFoundRes updateProcess(@PathVariable Long id, @Valid @RequestBody UpdateProcessReq updateProcessReq) {
return lostFoundDefinitionService.updateProcess(id, updateProcessReq);
@DeleteMapping("/{id}")
public LostFoundRes updateProcess(@PathVariable Long id) {
return lostFoundDefinitionService.updateProcess(id);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PutMapping에서 DeleteMapping으로 변경하신 이유가 있나요?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

process가 Fininsh로 바뀌는 것이 사용자관점에서 삭제를 하는 것으로 보고 바꾸었습니다.

}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package bssm.bsm.domain.board.lostfound.presentation;

import bssm.bsm.domain.board.lostfound.domain.type.Process;
import bssm.bsm.domain.board.lostfound.domain.type.State;
import bssm.bsm.domain.board.lostfound.presentation.dto.res.LostFoundCompactRes;
import bssm.bsm.domain.board.lostfound.presentation.dto.res.LostFoundRes;
import bssm.bsm.domain.board.lostfound.service.LostFoundInformationService;
Expand All @@ -19,9 +19,9 @@ public class LostFoundInformationController {

private final LostFoundInformationService lostFoundInformationService;

@GetMapping("process/{process}")
public List<LostFoundCompactRes> findAllByProcess(@PathVariable Process process) {
return lostFoundInformationService.findByProcess(process);
@GetMapping("state/{state}")
public List<LostFoundCompactRes> findAllByProcess(@PathVariable State state) {
return lostFoundInformationService.findByProcess(state);
qlido marked this conversation as resolved.
Show resolved Hide resolved
}

@GetMapping("/{id}")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package bssm.bsm.domain.board.lostfound.presentation.dto.req;

import bssm.bsm.domain.board.lostfound.domain.type.State;
import lombok.Getter;

import javax.validation.constraints.NotBlank;
Expand All @@ -24,4 +25,7 @@ public class LostFoundReq {
@NotBlank
private String description;

@NotNull
private State state;

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package bssm.bsm.domain.board.lostfound.presentation.dto.res;

import bssm.bsm.domain.board.lostfound.domain.type.Process;
import bssm.bsm.domain.board.lostfound.domain.type.State;
import lombok.Getter;

@Getter
Expand All @@ -10,11 +11,13 @@ public class LostFoundCompactRes {
private final String objectName;
private final String imgSrc;
private final Process process;
private final State state;

public LostFoundCompactRes(Long id, String objectName, String imgSrc, Process process) {
public LostFoundCompactRes(Long id, String objectName, String imgSrc, Process process,State state) {
qlido marked this conversation as resolved.
Show resolved Hide resolved
this.id = id;
this.objectName = objectName;
this.imgSrc = imgSrc;
this.process = process;
this.state = state;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import bssm.bsm.domain.board.lostfound.domain.LostFound;
import bssm.bsm.domain.board.lostfound.domain.type.Process;
import bssm.bsm.domain.board.lostfound.domain.type.State;
import bssm.bsm.domain.user.presentation.dto.res.UserRes;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
Expand All @@ -18,6 +19,7 @@ public class LostFoundRes {
private final LocalDateTime findDateTime;
private final String description;
private final Process process;
private final State state;

@JsonProperty
private final UserRes foundUser;
Expand All @@ -30,6 +32,7 @@ public LostFoundRes(LostFound newLostFound) {
this.description = newLostFound.getDescription();
this.process = newLostFound.getProcess();
this.location = newLostFound.getLocation();
this.state = newLostFound.getState();
this.foundUser = new UserRes(newLostFound.getFoundUser());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public LostFoundRes create(LostFoundReq lostFoundReq) {
.location(lostFoundReq.getLocation())
.findDateTime(lostFoundReq.getFindDateTime())
.process(Process.IN_PROGRESS)
.state(lostFoundReq.getState())
.user(currentUser.getUser())
.createdLocalDateTime(LocalDateTime.now())
.build();
Expand All @@ -43,15 +44,15 @@ public LostFoundRes create(LostFoundReq lostFoundReq) {
}

@Transactional
public LostFoundRes updateProcess(Long lostFoundId, UpdateProcessReq updateProcessReq) {
public LostFoundRes updateProcess(Long lostFoundId) {
LostFound lostFound = lostFoundRepository.findById(lostFoundId)
.orElseThrow(NoSuchLostFoundException::new);

if (!Objects.equals(currentUser.getUser().getCode(), lostFound.getFoundUser().getCode())) {
throw new NotCreatorException();
}

lostFound.updateProcess(updateProcessReq.getProcess());
lostFound.updateProcess(Process.FINISHED);

return new LostFoundRes(lostFound);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import bssm.bsm.domain.board.lostfound.domain.LostFound;
import bssm.bsm.domain.board.lostfound.domain.repository.LostFoundRepository;
import bssm.bsm.domain.board.lostfound.domain.type.Process;
import bssm.bsm.domain.board.lostfound.domain.type.State;
import bssm.bsm.domain.board.lostfound.exception.NoSuchLostFoundException;
import bssm.bsm.domain.board.lostfound.presentation.dto.res.LostFoundCompactRes;
import bssm.bsm.domain.board.lostfound.presentation.dto.res.LostFoundRes;
Expand All @@ -19,8 +19,8 @@ public class LostFoundInformationService {

private final LostFoundRepository lostFoundRepository;

public List<LostFoundCompactRes> findByProcess(Process process) {
return lostFoundRepository.findAllByProcess(process);
public List<LostFoundCompactRes> findByProcess(State state) {
return lostFoundRepository.findAllByState(state);
}

public LostFoundRes findOne(Long id) {
Expand Down