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

[Feat] spot domain 구현 ( Feature/17 -> dev ) #46

Merged
merged 34 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
593b1de
[Feat] Spot.java 구현
sanggae4133 Jan 22, 2024
81eb69b
[Feat] spot service createspot 구현
sanggae4133 Jan 30, 2024
df07706
[Feat] spot service createspot 구현
sanggae4133 Jan 30, 2024
8b21e5b
[Feat] implement basic part of image domain
sanggae4133 Jan 30, 2024
7f1d255
[Feat] checkout origin
sanggae4133 Feb 1, 2024
bfd7f4c
[Feat] compare to merge
sanggae4133 Feb 1, 2024
b72fea1
[Feat] compare to merge
sanggae4133 Feb 1, 2024
9f244fa
Merge pull request #33 from AR-TTUBEOG/feature/29
sanggae4133 Feb 1, 2024
23b2ce5
[Feat] commit modified by transfer
sanggae4133 Feb 1, 2024
474d8fa
[Feat] 산책스팟 createSpot, findBySpotId 구현
sanggae4133 Feb 1, 2024
d75f1a4
[Feat] updateSpot API 구현
sanggae4133 Feb 1, 2024
eed4365
[Feat] deleteSpot API implement
sanggae4133 Feb 1, 2024
36e9a05
[Feat] deleteSpot API implement
sanggae4133 Feb 1, 2024
6488380
[Feat] spotController request 수령 구체화
sanggae4133 Feb 1, 2024
37c8a9b
[Feat] guestbookservice 초안
sanggae4133 Feb 1, 2024
72791c6
[Feat] createImage 구현
sanggae4133 Feb 1, 2024
68f661d
[Feat] updateImage 구현
sanggae4133 Feb 1, 2024
12909ad
[Feat] deleteImage 구현
sanggae4133 Feb 1, 2024
036253a
[Feat] deleteImage 구현
sanggae4133 Feb 1, 2024
f6e3a9b
[Refac] spot service 리펙토링
sanggae4133 Feb 1, 2024
01cee50
Merge branch 'feature/17' into dev
sanggae4133 Feb 2, 2024
0b4de1a
Merge branch 'dev' of https://github.com/AR-TTUBEOG/Back-Spring into …
sanggae4133 Feb 2, 2024
fbcf059
Merge branch 'dev' into feature/17
sanggae4133 Feb 8, 2024
a1464e3
Merge remote-tracking branch 'origin/dev' into dev
sanggae4133 Feb 8, 2024
79e6990
Merge branch 'dev' into feature/17
sanggae4133 Feb 8, 2024
e27a740
[refac] merge with dev
sanggae4133 Feb 8, 2024
7096525
[feat] change user princible to httpserveletrequest
sanggae4133 Feb 8, 2024
7e82c45
[refac] refac security config
sanggae4133 Feb 8, 2024
52d0709
[feat] implement just spot service
sanggae4133 Feb 8, 2024
0cf029a
[Feat] : 사용하지 않은 import문 삭제
sanggae4133 Feb 8, 2024
e005f9f
[Feat] : 사용하지 않은 import문 삭제
sanggae4133 Feb 8, 2024
5115b61
[Docs] add swagger annotation
sanggae4133 Feb 8, 2024
fb9b3e5
[Docs] add swagger annotation2
sanggae4133 Feb 8, 2024
784352f
[Refac] unuse import 삭제
sanggae4133 Feb 8, 2024
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
2 changes: 2 additions & 0 deletions src/main/java/com/ttubeog/domain/area/domain/DongArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import lombok.Getter;

@Getter
@Entity
public class DongArea extends BaseEntity {

Expand Down
23 changes: 15 additions & 8 deletions src/main/java/com/ttubeog/domain/auth/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;
Expand All @@ -27,15 +28,20 @@ public AuthenticationManager authenticationManager(
@Bean
public SecurityFilterChain configure(final HttpSecurity httpSecurity) throws Exception {
return httpSecurity.cors(withDefaults())
.csrf((csrf) -> csrf.disable())
.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests((authorize) -> authorize
.requestMatchers("/auth/login/**").permitAll()
.requestMatchers("/swagger-ui/**", "/v3/api-docs", "/swagger-resources/**", "/api/**").permitAll()
.requestMatchers("/swagger-ui/**",
"/v2/api-docs",
"/swagger-resources/**",
"/h2-console/**",
"/favicon.ico",
"/v3/api-docs/**",
"/api/**").permitAll()
// .requestMatchers("/api/**").hasAuthority(MemberRole.USER.getRole())
.anyRequest().authenticated())
.sessionManagement((session) -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.formLogin(httpSecurityFormLoginConfigurer -> httpSecurityFormLoginConfigurer.disable()) // 기본 로그인 폼 미사용
.httpBasic(httpSecurityHttpBasicConfigurer -> httpSecurityHttpBasicConfigurer.disable()) // 기본 http 미사용
.formLogin(AbstractHttpConfigurer::disable) // 기본 로그인 폼 미사용
.httpBasic(AbstractHttpConfigurer::disable) // 기본 http 미사용
.build();
}

Expand All @@ -58,12 +64,13 @@ public boolean matches(CharSequence rawPassword, String encodedPassword) {
public WebSecurityCustomizer webSecurityCustomizer(){
return web ->
web.ignoring()
.requestMatchers("/auth/login/**")
.requestMatchers("/swagger-ui/**",
.requestMatchers("/auth/login/**",
"/swagger-ui/**",
"/v2/api-docs",
"/swagger-resources/**",
"/h2-console/**",
"/favicon.ico",
"/v3/api-docs/**");
"/v3/api-docs/**",
"/api/**");
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
package com.ttubeog.domain.guestbook.application;

import com.ttubeog.domain.guestbook.dto.CreateGuestBookRequestDto;
import com.ttubeog.global.config.security.token.UserPrincipal;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@RequiredArgsConstructor
@Service
@Transactional(readOnly = true)
public class GuestBookService {
public ResponseEntity<?> createGuestBook(HttpServletRequest request, Integer spotId, CreateGuestBookRequestDto createGuestBookRequestDto) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.ttubeog.domain.guestbook.dto;

public class CreateGuestBookRequestDto {
}
104 changes: 104 additions & 0 deletions src/main/java/com/ttubeog/domain/image/application/ImageService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package com.ttubeog.domain.image.application;

import com.ttubeog.domain.image.domain.Image;
import com.ttubeog.domain.image.domain.repository.ImageRepository;
import com.ttubeog.domain.image.dto.request.CreateImageRequestDto;
import com.ttubeog.domain.image.dto.request.UpdateImageRequestDto;
import com.ttubeog.domain.image.dto.response.ImageResponseDto;
import com.ttubeog.domain.image.exception.InvalidImageException;
import com.ttubeog.domain.spot.domain.repository.SpotRepository;
import com.ttubeog.domain.spot.exception.InvalidSpotIdException;
import com.ttubeog.domain.store.domain.repository.StoreRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

import static com.ttubeog.domain.image.dto.request.ImageRequestType.SPOT;

@RequiredArgsConstructor
@Service
@Transactional(readOnly = true)
public class ImageService {

private final ImageRepository imageRepository;
private final SpotRepository spotRepository;
private final StoreRepository storeRepository;

public static List<String> getImageString(List<Image> imageList) {
List<String> imageString = new ArrayList<>();

for (Image image : imageList) {
imageString.add(imageString.size(), image.getImage());
}

return imageString;
}

@Transactional
public ImageResponseDto createImage(CreateImageRequestDto createImageRequestDto) {

Image image;
ImageResponseDto imageResponseDto;
if (createImageRequestDto.imageRequestType == SPOT) {
image = Image.builder()
.image(createImageRequestDto.getImage())
.spot(spotRepository.findById(createImageRequestDto.getPlaceId()).orElseThrow(InvalidSpotIdException::new))
.build();

imageResponseDto = ImageResponseDto.builder()
.id(image.getId())
.placeId(image.getSpot().getId())
.build();
} else {
image = Image.builder()
.image(createImageRequestDto.getImage())
.store(storeRepository.findById(createImageRequestDto.getPlaceId()).orElseThrow(InvalidSpotIdException::new))
.build();

imageResponseDto = ImageResponseDto.builder()
.id(image.getId())
.placeId(image.getStore().getId())
.build();
}
imageRepository.save(image);

return imageResponseDto;
}

@Transactional
public ImageResponseDto updateImage(UpdateImageRequestDto updateImageRequestDto) {

Image image = imageRepository.findById(updateImageRequestDto.getId()).orElseThrow(InvalidImageException::new);
ImageResponseDto imageResponseDto;

if (updateImageRequestDto.imageRequestType == SPOT) {
image.updateImage(updateImageRequestDto.getImage(), spotRepository.findById(updateImageRequestDto.getPlaceId()).orElseThrow(InvalidSpotIdException::new));
imageResponseDto = ImageResponseDto.builder()
.id(image.getId())
.placeId(image.getSpot().getId())
.build();
} else {
image.updateImage(updateImageRequestDto.getImage(), storeRepository.findById(updateImageRequestDto.getPlaceId()).orElseThrow(InvalidSpotIdException::new));
imageResponseDto = ImageResponseDto.builder()
.id(image.getId())
.placeId(image.getStore().getId())
.build();
}

imageRepository.save(image);

return imageResponseDto;
}

@Transactional
public void deleteImage(Long imageId) {

Image image = imageRepository.findById(imageId).orElseThrow(InvalidImageException::new);
imageRepository.delete(image);

}
}
51 changes: 51 additions & 0 deletions src/main/java/com/ttubeog/domain/image/domain/Image.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.ttubeog.domain.image.domain;

import com.ttubeog.domain.common.BaseEntity;
import com.ttubeog.domain.spot.domain.Spot;
import com.ttubeog.domain.store.domain.Store;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.apache.ibatis.annotations.Many;


@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
@Builder
@Entity
@Table(name = "image")
public class Image extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

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

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "spot")
private Spot spot;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "store")
private Store store;

public Image(Long id, String image, Spot spot, Store store) {
this.id = id;
this.image = image;
this.spot = spot;
this.store = store;
}

public void updateImage(String image, Spot spot) {
this.image = image;
this.spot = spot;
}

public void updateImage(String image, Store store) {
this.image = image;
this.store = store;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.ttubeog.domain.image.domain.repository;

import com.ttubeog.domain.image.domain.Image;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

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

@Repository
public interface ImageRepository extends JpaRepository<Image, Long> {

@Override
List<Image> findAll();

List<Image> findBySpotId(Long id);

List<Image> findByStoreId(Long id);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.ttubeog.domain.image.dto.request;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
@AllArgsConstructor
public class CreateImageRequestDto {

public String image;
public ImageRequestType imageRequestType;
public Long placeId;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.ttubeog.domain.image.dto.request;

public enum ImageRequestType {
SPOT,
STORE
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.ttubeog.domain.image.dto.request;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
@AllArgsConstructor
public class UpdateImageRequestDto {

public Long id;
public String image;
public ImageRequestType imageRequestType;
public Long placeId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.ttubeog.domain.image.dto.response;

import com.ttubeog.domain.image.dto.request.ImageRequestType;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
@AllArgsConstructor
public class ImageResponseDto {

public Long id;
public String image;
public Long placeId;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.ttubeog.domain.image.exception;

public class InvalidImageException extends RuntimeException {

public InvalidImageException() {
super("유효하지 않은 이미지입니다.");
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.ttubeog.domain.member.exception;


public class InvalidMemberException extends RuntimeException {

public InvalidMemberException(){
super("멤버가 올바르지 않습니다.");
}

public InvalidMemberException(String message) {
super(message);
}
}
Loading
Loading