Skip to content

Commit

Permalink
Merge pull request #101 from Team-odongdong/feature/patch/bathroomInfo
Browse files Browse the repository at this point in the history
화장실 수정 구현
  • Loading branch information
tkddls23 authored Dec 4, 2022
2 parents 3838491 + 722a5ca commit f45f8a8
Show file tree
Hide file tree
Showing 9 changed files with 291 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
package com.graduate.odondong.controller;

import static com.graduate.odondong.util.BaseResponseStatus.SUCCESS;
import static com.graduate.odondong.util.ErrorLogWriter.*;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.graduate.odondong.domain.UpdatedBathroom;
import com.graduate.odondong.dto.*;
import com.graduate.odondong.util.BaseResponseStatus;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import com.graduate.odondong.domain.Bathroom;
import com.graduate.odondong.dto.BathroomRequestDto;
import com.graduate.odondong.dto.BathroomResponseDto;
import com.graduate.odondong.dto.BathroomResponseInterface;
import com.graduate.odondong.dto.CoordinateInfoDto;
import com.graduate.odondong.service.AwsS3Service;
import com.graduate.odondong.service.BathroomService.BathroomService;
import com.graduate.odondong.util.BaseException;
Expand Down Expand Up @@ -68,6 +63,18 @@ public BaseResponse<String> RegisterBathroomRequest(HttpServletRequest request,
}
}

@ResponseBody
@PostMapping("/api/bathroom/edit")
public BaseResponse<BaseResponseStatus> postUpdatedBathroomRequest(HttpServletRequest request, @RequestBody BathroomUpdateRequestDto bathroomUpdateRequestDto) {
try {
bathroomService.registerUpdatedBathroomInfo(bathroomUpdateRequestDto);
return new BaseResponse<>(SUCCESS);
} catch (BaseException e) {
writeExceptionWithRequest(e, request);
return new BaseResponse<>(e.getStatus());
}
}

@GetMapping("/admin/bathroom/not-registered")
public String NotRegisterBathroomList(Model model) {
List<Bathroom> bathrooms = bathroomService.NotRegisterBathroomList();
Expand All @@ -81,13 +88,33 @@ public String RegisterBathroom(@RequestParam("id") Long id) {
return "redirect:/not-register-bathroom";
}

@GetMapping("/admin/bathroom/not-edited")
public String getNotEditedBathroomList(Model model) {
List<UpdatedBathroom> updatedBathrooms = bathroomService.notEditBathroomList();
model.addAttribute("updatedBathrooms", updatedBathrooms);
return "edit";
}

@PostMapping("/admin/bathroom/edit")
public String postUpdatedBathroom(HttpServletRequest request, @RequestParam("id") Long id) {
bathroomService.registerUpdatedBathroom(id);
return "redirect:/admin/bathroom/not-edited";
}

@DeleteMapping("/admin/bathroom/delete")
@ResponseBody
public String DeleteBathroom(@RequestParam("id") Long id) {
bathroomService.DeleteBathroom(id);
return "Delete";
}

@DeleteMapping("/admin/bathroom/delete-updated")
@ResponseBody
public String deleteUpdatedBathroom(@RequestParam("id") Long id) {
bathroomService.deleteUpdatedBathroom(id);
return "deleteUpdated";
}

@ResponseBody
@GetMapping("/api/bathroom/address")
public BaseResponse<CoordinateInfoDto> AllAddressInfo(HttpServletRequest request,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ public Bathroom(Long id, String title, Double latitude, Double longitude, String
this.isUnisex = isUnisex;
}

public void update(UpdatedBathroom updatedBathroom) {
this.title = updatedBathroom.getTitle();
this.latitude = updatedBathroom.getLatitude();
this.longitude = updatedBathroom.getLongitude();
this.isLocked = updatedBathroom.getIsLocked();
this.address = updatedBathroom.getAddress();
this.addressDetail = updatedBathroom.getAddressDetail();
this.operationTime = updatedBathroom.getOperationTime();
this.imageUrl = updatedBathroom.getImageUrl();
this.register = updatedBathroom.getRegister();
this.isUnisex = updatedBathroom.getIsUnisex();
}

public void setRegister(Boolean register) {
this.register = register;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.graduate.odondong.domain;

import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.time.LocalDateTime;

@Entity()
@Data
@NoArgsConstructor
@Setter
@EntityListeners(AuditingEntityListener.class)
public class UpdatedBathroom {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="bathroom_id")
private Bathroom bathroom;
private Long userId;
private String title;
private Double latitude;
private Double longitude;
private String isLocked;
private String address;
private String addressDetail;
private String imageUrl;
private String operationTime;
private Boolean isUnisex;
private Boolean register;

@CreatedDate
@Column(updatable = false)
private LocalDateTime created_at;
@LastModifiedDate
private LocalDateTime updated_at;

@Builder
public UpdatedBathroom(Long id, Long userId, Bathroom bathroom, String title, Double latitude, Double longitude, String isLocked, String address, String addressDetail, String imageUrl, String operationTime, Boolean isUnisex, Boolean register) {
this.id = id;
this.userId = userId;
this.bathroom = bathroom;
this.title = title;
this.latitude = latitude;
this.longitude = longitude;
this.isLocked = isLocked;
this.address = address;
this.addressDetail = addressDetail;
this.imageUrl = imageUrl;
this.operationTime = operationTime;
this.isUnisex = isUnisex;
this.register = register;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.graduate.odondong.dto;

import com.graduate.odondong.domain.Bathroom;
import com.graduate.odondong.domain.UpdatedBathroom;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
public class BathroomUpdateRequestDto {

private Long bathroomId;
private Long userId;
private String title;
private Double latitude;
private Double longitude;
private String isLocked;
private String address;
private String addressDetail;
private String imageUrl;
private String operationTime;
private Boolean isUnisex;

@Builder
public BathroomUpdateRequestDto(Long bathroomId, Long userId, String title, Double latitude, Double longitude, String isLocked, String address, String addressDetail, String imageUrl,String operationTime, Boolean isUnisex) {
this.bathroomId = bathroomId;
this.userId = userId;
this.title = title;
this.latitude = latitude;
this.longitude = longitude;
this.isLocked = isLocked;
this.address = address;
this.addressDetail = addressDetail;
this.imageUrl = imageUrl;
this.operationTime = operationTime;
this.isUnisex = isUnisex;
}


public UpdatedBathroom toUpdatedBathroom(Bathroom bathroom) {
return UpdatedBathroom.builder()
.title(title)
.userId(userId)
.bathroom(bathroom)
.latitude(latitude)
.longitude(longitude)
.isLocked(isLocked)
.address(address)
.addressDetail(addressDetail)
.register(false)
.imageUrl(imageUrl)
.operationTime(operationTime)
.isUnisex(isUnisex)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.graduate.odondong.domain.Bathroom;
import com.graduate.odondong.dto.BathroomResponseInterface;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.graduate.odondong.repository;

import com.graduate.odondong.domain.UpdatedBathroom;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface UpdatedBathroomRepository extends JpaRepository<UpdatedBathroom, Long> {

List<UpdatedBathroom> findUpdatedBathroomsByRegisterIsFalse();

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@
import java.util.List;
import java.util.stream.Collectors;

import com.graduate.odondong.domain.UpdatedBathroom;
import com.graduate.odondong.dto.*;
import com.graduate.odondong.repository.UpdatedBathroomRepository;
import com.graduate.odondong.util.operationTime.OperationTimeValidation;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.graduate.odondong.domain.Bathroom;
import com.graduate.odondong.domain.Rating;
import com.graduate.odondong.dto.BathroomRequestDto;
import com.graduate.odondong.dto.BathroomResponseDto;
import com.graduate.odondong.dto.BathroomResponseInterface;
import com.graduate.odondong.dto.CoordinateInfoDto;
import com.graduate.odondong.dto.LocationDto;
import com.graduate.odondong.repository.BathroomRepository;
import com.graduate.odondong.repository.RatingRepository;
import com.graduate.odondong.util.BaseException;
Expand All @@ -36,6 +34,7 @@
@Transactional(rollbackFor = Exception.class)
public class BathroomService {
private final BathroomRepository bathroomRepository;
private final UpdatedBathroomRepository updatedBathroomRepository;
private final RatingRepository ratingRepository;
private final ChangeByGeocoderKakao changeByGeocoderKakao;
private final ChangeByGeocoderNaver changeByGeocoderNaver;
Expand All @@ -54,6 +53,10 @@ public List<Bathroom> NotRegisterBathroomList() {
return bathroomRepository.findBathroomsByRegisterIsFalse();
}

public List<UpdatedBathroom> notEditBathroomList() {
return updatedBathroomRepository.findUpdatedBathroomsByRegisterIsFalse();
}

public void UpdateBathroom(Long id) {
Bathroom bathroom = bathroomRepository.findById(id).get();
bathroom.setRegister(true);
Expand All @@ -66,6 +69,22 @@ public void DeleteBathroom(Long id) {
bathroomRepository.deleteById(id);
}

public void deleteUpdatedBathroom(Long id) {
UpdatedBathroom updatedBathroom = updatedBathroomRepository.findById(id).orElseThrow();
updatedBathroomRepository.deleteById(id);
}

public void registerUpdatedBathroom(Long id) {
UpdatedBathroom updatedBathroom = updatedBathroomRepository.findById(id).orElseThrow(() -> new IllegalArgumentException("요청된 화장실 정보가 없습니다"));
updatedBathroom.setRegister(true);
updatedBathroomRepository.save(updatedBathroom);

Bathroom bathroom = bathroomRepository.findById(updatedBathroom.getBathroom().getId()).orElseThrow(() -> new IllegalArgumentException("요청된 화장실 정보가 없습니다"));
bathroom.update(updatedBathroom);
bathroomRepository.save(bathroom);
updatedBathroomRepository.deleteById(id);
}

public String RegisterBathroomRequest(BathroomRequestDto bathroomRequestDto, String bathroomImgUrl) throws BaseException{
try {
Bathroom bathroom = Bathroom.builder()
Expand All @@ -91,6 +110,16 @@ public String RegisterBathroomRequest(BathroomRequestDto bathroomRequestDto, Str
}
}

public void registerUpdatedBathroomInfo(BathroomUpdateRequestDto bathroomUpdateRequestDto) throws BaseException{
try {
Bathroom bathroom = bathroomRepository.findById(bathroomUpdateRequestDto.getBathroomId()).get();
UpdatedBathroom updatedBathroom = bathroomUpdateRequestDto.toUpdatedBathroom(bathroom);
updatedBathroomRepository.save(updatedBathroom);
} catch (Exception e) {
throw new BaseException(DATABASE_ERROR);
}
}

public BaseResponse<List<BathroomResponseDto>> get1kmByLongitudeLatitude(Double x, Double y, Double distance) throws BaseException {
try {
LocationDto locationDto = LocationDto.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ public enum BaseResponseStatus {

// 6000 : 필요시 만들어서 쓰세요

TIME_PARSE_ERR(false, 6001, "현재시간 파싱 에러");
TIME_PARSE_ERR(false, 6001, "현재시간 파싱 에러"),

// 7000 : 화장실 갱신 오류
PERMIT_UPDATE_BATHROOM_FAIL(false, 7001, "화장실 정보 수정 요청 허가에 실패했습니다."),
UPDATE_BATHROOM_FAIL(false, 7002, "화장실 정보 갱신에 실패했습니다.");


private final boolean isSuccess;
Expand Down
Loading

0 comments on commit f45f8a8

Please sign in to comment.