Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
shinheekim committed Jul 30, 2024
2 parents 13a7c57 + 10bcbd4 commit 2655a76
Show file tree
Hide file tree
Showing 25 changed files with 201 additions and 168 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@SpringBootApplication
@EnableJpaAuditing
public class LikeLion12thTeam03BeApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package net.skhu.likelion12thteam03be.category.api;

import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import net.skhu.likelion12thteam03be.category.api.dto.request.CategorySaveReqDto;
import net.skhu.likelion12thteam03be.category.api.dto.request.CategoryUpdateReqDto;
import net.skhu.likelion12thteam03be.category.api.dto.response.CategoryListResDto;
import net.skhu.likelion12thteam03be.category.application.CategoryService;
import org.springframework.http.HttpStatus;
Expand All @@ -14,30 +11,11 @@
@RequiredArgsConstructor
@RequestMapping("/categories")
public class CategoryController {

private final CategoryService categoryService;

@PostMapping
public ResponseEntity<String> categorySave(@RequestBody @Valid CategorySaveReqDto categorySaveReqDto) {
categoryService.categorySave(categorySaveReqDto);
return new ResponseEntity<>("Successful Category Save!", HttpStatus.CREATED);
}

@GetMapping()
public ResponseEntity<CategoryListResDto> categoryFindAll() {
CategoryListResDto categoryListResDto = categoryService.categoryFindAll();
return new ResponseEntity<>(categoryListResDto, HttpStatus.OK);
}

@PatchMapping("/{categoryId}")
public ResponseEntity<String> categoryUpdate(@PathVariable Long categoryId, @RequestBody @Valid CategoryUpdateReqDto categoryUpdateReqDto) {
categoryService.categoryUpdate(categoryId, categoryUpdateReqDto);
return new ResponseEntity<>("Successful Category Update! categoryId = " + categoryId, HttpStatus.OK);
}

@DeleteMapping("/{categoryId}")
public ResponseEntity<String> categoryDelete(@PathVariable Long categoryId) {
categoryService.categoryDelete(categoryId);
return new ResponseEntity<>("Successful Category Delete! categoryId = " + categoryId, HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
package net.skhu.likelion12thteam03be.category.application;

import lombok.RequiredArgsConstructor;
import net.skhu.likelion12thteam03be.category.api.dto.request.CategorySaveReqDto;
import net.skhu.likelion12thteam03be.category.api.dto.request.CategoryUpdateReqDto;
import net.skhu.likelion12thteam03be.category.api.dto.response.CategoryInfoResDto;
import net.skhu.likelion12thteam03be.category.api.dto.response.CategoryListResDto;
import net.skhu.likelion12thteam03be.category.domain.Category;
import net.skhu.likelion12thteam03be.category.domain.repository.CategoryRepository;
import net.skhu.likelion12thteam03be.post.api.dto.response.PostInfoResDto;
import net.skhu.likelion12thteam03be.post.api.dto.response.PostListResDto;
import net.skhu.likelion12thteam03be.post.domain.Post;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -21,18 +16,6 @@
public class CategoryService {
private final CategoryRepository categoryRepository;

@Transactional
public void categorySave(CategorySaveReqDto categorySaveReqDto) {
if (categoryRepository.existsByName(categorySaveReqDto.name())) {
throw new IllegalArgumentException("해당 카테고리가 이미 존재합니다.");
}
Category category = Category.builder()
.name(categorySaveReqDto.name())
.build();

categoryRepository.save(category);
}

public CategoryListResDto categoryFindAll() {
List<Category> categories = categoryRepository.findAll();

Expand All @@ -42,20 +25,4 @@ public CategoryListResDto categoryFindAll() {

return CategoryListResDto.from(categoryInfoResDtoList);
}

@Transactional
public void categoryUpdate(Long categoryId, CategoryUpdateReqDto categoryUpdateReqDto) {
Category category = categoryRepository.findById(categoryId).orElseThrow(
() -> new IllegalArgumentException("해당 카테고리가 존재하지 않습니다.")
);
category.update(categoryUpdateReqDto.name());
}

@Transactional
public void categoryDelete(Long categoryId) {
Category category = categoryRepository.findById(categoryId).orElseThrow(
() -> new IllegalArgumentException("해당 카테고리가 존재하지 않습니다.")
);
categoryRepository.deleteById(categoryId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Category {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "category_id")
@Column(name = "categoryId")
private Long categoryId;

private String name;
Expand All @@ -31,8 +31,4 @@ public class Category {
public Category(String name) {
this.name = name;
}

public void update(String name) {
this.name = name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
import org.springframework.data.jpa.repository.JpaRepository;

public interface CategoryRepository extends JpaRepository<Category, Long> {
boolean existsByName(String name);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package net.skhu.likelion12thteam03be.location.api.dto;

import lombok.RequiredArgsConstructor;
import net.skhu.likelion12thteam03be.category.api.dto.response.CategoryListResDto;
import net.skhu.likelion12thteam03be.location.api.dto.request.LocationSaveReqDto;
import net.skhu.likelion12thteam03be.location.api.dto.request.LocationUpdateReqDto;
import net.skhu.likelion12thteam03be.location.api.dto.response.LocationListResDto;
import net.skhu.likelion12thteam03be.location.application.LocationService;
import org.springframework.http.HttpStatus;
Expand All @@ -16,27 +13,9 @@
public class LocationController {
private final LocationService locationService;

@PostMapping()
public ResponseEntity<String> locationSave(@RequestBody LocationSaveReqDto locationSaveReqDto) {
locationService.locationSave(locationSaveReqDto);
return new ResponseEntity<>("Successful Location Save!", HttpStatus.CREATED);
}

@GetMapping()
public ResponseEntity<LocationListResDto> locationFindAll() {
LocationListResDto locationListResDto = locationService.locationFindAll();
return new ResponseEntity<>(locationListResDto, HttpStatus.OK);
}

@PatchMapping("/{locationId}")
public ResponseEntity<String> locationUpdate(@PathVariable Long locationId, @RequestBody LocationUpdateReqDto locationUpdateReqDto) {
locationService.locationUpdate(locationId, locationUpdateReqDto);
return new ResponseEntity<>("Successful Location Update! locationId = " + locationId, HttpStatus.OK);
}

@DeleteMapping("/{locationId}")
public ResponseEntity<String> locationDelete(@PathVariable Long locationId) {
locationService.locationDelete(locationId);
return new ResponseEntity<>("Successful Location Delete! locationId = " + locationId, HttpStatus.OK);
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package net.skhu.likelion12thteam03be.location.application;

import lombok.RequiredArgsConstructor;
import net.skhu.likelion12thteam03be.location.api.dto.request.LocationSaveReqDto;
import net.skhu.likelion12thteam03be.location.api.dto.request.LocationUpdateReqDto;
import net.skhu.likelion12thteam03be.location.api.dto.response.LocationInfoResDto;
import net.skhu.likelion12thteam03be.location.api.dto.response.LocationListResDto;
import net.skhu.likelion12thteam03be.location.domain.Location;
Expand All @@ -18,18 +16,6 @@
public class LocationService {
private final LocationRepository locationRepository;

@Transactional
public void locationSave(LocationSaveReqDto locationSaveReqDto) {
if (locationRepository.existsByName(locationSaveReqDto.name())) {
throw new IllegalArgumentException("해당 위치가 이미 존재합니다.");
}
Location location = Location.builder()
.name(locationSaveReqDto.name())
.build();

locationRepository.save(location);
}

public LocationListResDto locationFindAll() {
List<Location> locations = locationRepository.findAll();

Expand All @@ -39,20 +25,4 @@ public LocationListResDto locationFindAll() {

return LocationListResDto.from(locationInfoResDtoList);
}

@Transactional
public void locationUpdate(Long locationId, LocationUpdateReqDto locationUpdateReqDto) {
Location location = locationRepository.findById(locationId).orElseThrow(
() -> new IllegalArgumentException("해당 위치가 존재하지 않습니다. 새 위치로 등록해주세요.")
);
location.update(locationUpdateReqDto.name());
}

@Transactional
public void locationDelete(Long locationId) {
Location location = locationRepository.findById(locationId).orElseThrow(
() -> new IllegalArgumentException("해당 위치가 존재하지 않습니다.")
);
locationRepository.delete(location);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Location {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "location_id")
@Column(name = "locationId")
private Long locationId;

private String name;
Expand All @@ -31,8 +31,4 @@ public class Location {
public Location(String name) {
this.name = name;
}

public void update(String name) {
this.name = name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
import org.springframework.data.jpa.repository.JpaRepository;

public interface LocationRepository extends JpaRepository<Location, Long> {
boolean existsByName(String name);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package net.skhu.likelion12thteam03be.mood.api.dto;

import lombok.RequiredArgsConstructor;
import net.skhu.likelion12thteam03be.mood.api.dto.response.MoodListResDto;
import net.skhu.likelion12thteam03be.mood.application.MoodService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/moods")
public class MoodController {
private final MoodService moodService;

@GetMapping
public ResponseEntity<MoodListResDto> moodFindAll() {
MoodListResDto moodListResDto = moodService.moodFindAll();
return new ResponseEntity<>(moodListResDto, HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package net.skhu.likelion12thteam03be.mood.api.dto.response;

import lombok.Builder;
import net.skhu.likelion12thteam03be.mood.domain.Mood;

@Builder
public record MoodInfoResDto(
Long moodId,
String name
) {
public static MoodInfoResDto from(Mood mood) {
return MoodInfoResDto.builder()
.name(mood.getName())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package net.skhu.likelion12thteam03be.mood.api.dto.response;

import lombok.Builder;

import java.util.List;

@Builder
public record MoodListResDto(
List<MoodInfoResDto> moodList
) {
public static MoodListResDto from(List<MoodInfoResDto> moodList) {
return MoodListResDto.builder()
.moodList(moodList)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package net.skhu.likelion12thteam03be.mood.application;

import lombok.RequiredArgsConstructor;
import net.skhu.likelion12thteam03be.mood.api.dto.response.MoodInfoResDto;
import net.skhu.likelion12thteam03be.mood.api.dto.response.MoodListResDto;
import net.skhu.likelion12thteam03be.mood.domain.Mood;
import net.skhu.likelion12thteam03be.mood.domain.repository.MoodRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
@RequiredArgsConstructor
public class MoodService {
private final MoodRepository moodRepository;

@Transactional
public MoodListResDto moodFindAll() {
List<Mood> moods = moodRepository.findAll();

List<MoodInfoResDto> moodInfoResDtoList = moods.stream()
.map(MoodInfoResDto::from)
.toList();

return MoodListResDto.from(moodInfoResDtoList);
}
}
34 changes: 34 additions & 0 deletions src/main/java/net/skhu/likelion12thteam03be/mood/domain/Mood.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package net.skhu.likelion12thteam03be.mood.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import net.skhu.likelion12thteam03be.post.domain.Post;

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

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Mood {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "moodId")
private Long moodId;

private String name;

@JsonIgnore
@OneToMany(mappedBy = "mood", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Post> postList = new ArrayList<>();

@Builder
public Mood(String name) {
this.name = name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package net.skhu.likelion12thteam03be.mood.domain.repository;

import net.skhu.likelion12thteam03be.mood.domain.Mood;
import org.springframework.data.jpa.repository.JpaRepository;

public interface MoodRepository extends JpaRepository<Mood, Long> {
}
Loading

0 comments on commit 2655a76

Please sign in to comment.