Skip to content

Commit

Permalink
[8주차/수콩] 워크북 제출합니다.
Browse files Browse the repository at this point in the history
[8주차/수콩] 워크북 제출합니다.
  • Loading branch information
InSooBeen authored Nov 24, 2024
2 parents 1d172bd + 33db35e commit 8042dc4
Show file tree
Hide file tree
Showing 65 changed files with 1,054 additions and 26 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ repositories {
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.3.0'
implementation 'org.springframework.boot:spring-boot-starter-validation'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.mysql:mysql-connector-j'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ public enum ErrorStatus implements BaseErrorCode {
MEMBER_NOT_FOUND(HttpStatus.BAD_REQUEST, "MEMBER4001", "사용자가 없습니다."),
NICKNAME_NOT_EXIST(HttpStatus.BAD_REQUEST, "MEMBER4002", "닉네임은 필수 입니다."),

MISSION_NOT_FOUND(HttpStatus.NOT_FOUND, "MEMBER_MISSION_4001", "미션이 존재하지 않습니다."),

MEMBER_MISSION_ALREADY_IN_CHALLENGING(HttpStatus.CONFLICT, "MEMBER_MISSION4002", "이미 진행 중인 미션입니다."),

FOOD_CATEGORY_NOT_FOUND(HttpStatus.NOT_FOUND, "FOOD_CATEGORY4001", "음식 카테고리가 없습니다."),

RESTAURANT_NOT_FOUND(HttpStatus.NOT_FOUND, "RESTAURANT4001", "식당이 없습니다."),

REGION_NOT_FOUND(HttpStatus.NOT_FOUND, "REGION4001", "지역이 없습니다."),

ARTICLE_NOT_FOUND(HttpStatus.NOT_FOUND, "ARTICLE4001", "게시글이 없습니다."),

TEMP_EXCEPTION(HttpStatus.BAD_REQUEST, "TEMP4001", "이거는 테스트");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package javalab.umc7th_mission.study.config;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import io.swagger.v3.oas.models.servers.Server;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SwaggerConfig {

@Bean
public OpenAPI UMCstudyAPI() {
Info info = new Info()
.title("UMC Server WorkBook API")
.description("UMC Server WorkBook API 명세서")
.version("1.0.0");

String jwtSchemeName = "JWT TOKEN";
SecurityRequirement securityRequirement = new SecurityRequirement().addList(jwtSchemeName);

Components components = new Components()
.addSecuritySchemes(jwtSchemeName, new SecurityScheme()
.name(jwtSchemeName)
.type(SecurityScheme.Type.HTTP)
.scheme("bearer")
.bearerFormat("JWT"));

return new OpenAPI()
.addServersItem(new Server().url("/"))
.info(info)
.addSecurityItem(securityRequirement)
.components(components);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import javalab.umc7th_mission.study.apiPayload.ApiResponse;
import javalab.umc7th_mission.study.converter.TempConverter;
import javalab.umc7th_mission.study.dto.TempResponse;
import javalab.umc7th_mission.study.web.dto.TempResponse;
import javalab.umc7th_mission.study.service.TempService.TempQueryService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package javalab.umc7th_mission.study.converter;

import javalab.umc7th_mission.study.domain.Member;
import javalab.umc7th_mission.study.web.dto.member.MemberRequestDTO;
import javalab.umc7th_mission.study.web.dto.member.MemberResponseDTO;

import java.time.LocalDateTime;
import java.util.ArrayList;

public class MemberConverter {
public static MemberResponseDTO.JoinResultDTO toJoinResultDTO(Member member) {
return MemberResponseDTO.JoinResultDTO.builder()
.memberId(member.getId())
.createdAt(LocalDateTime.now())
.build();
}

public static Member toMember(MemberRequestDTO.JoinDto request){
return Member.builder()
.name(request.getName())
.birth(request.getBirth())
.address(request.getAddress())
.memberFoodList(new ArrayList<>())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package javalab.umc7th_mission.study.converter;

import javalab.umc7th_mission.study.domain.Food;
import javalab.umc7th_mission.study.domain.mapping.MemberFood;

import java.util.List;
import java.util.stream.Collectors;

public class MemberFoodConverter {
public static List<MemberFood> toMemberFoodList(List<Food> foodList){
return foodList.stream()
.map(food -> MemberFood.builder()
.food(food)
.build()
).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package javalab.umc7th_mission.study.converter;

import javalab.umc7th_mission.study.domain.Member;
import javalab.umc7th_mission.study.domain.Mission;
import javalab.umc7th_mission.study.domain.mapping.MemberMission;
import javalab.umc7th_mission.study.web.dto.member_mission.MemberMissionRequestDTO;
import javalab.umc7th_mission.study.web.dto.member_mission.MemberMissionResponseDTO;

import java.time.LocalDate;

public class MemberMissionConverter {
public static MemberMissionResponseDTO.AddMemberMissionResultDTO toAddMemberMissionResultDTO(MemberMission memberMission){
return MemberMissionResponseDTO.AddMemberMissionResultDTO.builder()
.memberMissionId(memberMission.getId())
.createdAt(LocalDate.now())
.build();
}

public static MemberMission toMemberMission(Member member, Mission mission){
return MemberMission.builder()
.member(member)
.mission(mission)
.startDate(LocalDate.now())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package javalab.umc7th_mission.study.converter;

import javalab.umc7th_mission.study.domain.Mission;
import javalab.umc7th_mission.study.domain.Restaurant;
import javalab.umc7th_mission.study.web.dto.mission.MissionRequestDTO;
import javalab.umc7th_mission.study.web.dto.mission.MissionResponseDTO;

import java.time.LocalDate;

public class MissionConverter {
public static MissionResponseDTO.AddMissionResultDTO toAddMissionResultDTO(Mission mission){
return new MissionResponseDTO.AddMissionResultDTO().builder()
.missionId(mission.getId())
.createdAt(LocalDate.now())
.build();
}
public static Mission toMission(MissionRequestDTO.AddMissionDto request, Restaurant restaurant){
return Mission.builder()
.name(request.getName())
.content(request.getContent())
.point(request.getPoint())
.deadline(request.getDeadline())
.restaurant(restaurant)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package javalab.umc7th_mission.study.converter;

import javalab.umc7th_mission.study.domain.Region;
import javalab.umc7th_mission.study.domain.Restaurant;
import javalab.umc7th_mission.study.web.dto.restaurant.RestaurantRequestDTO;
import javalab.umc7th_mission.study.web.dto.restaurant.RestaurantResponseDTO;

import java.time.LocalDate;

public class RestaurantConverter {
public static RestaurantResponseDTO.AddRestaurantResultDTO toAddRestaurantResultDTO(Restaurant restaurant) {
return RestaurantResponseDTO.AddRestaurantResultDTO.builder()
.restaurantId(restaurant.getId())
.createdAt(LocalDate.now())
.build();
}
public static Restaurant toRestaurant(RestaurantRequestDTO.AddRestaurantDto request, Region region){
return Restaurant.builder()
.name(request.getName())
.address(request.getAddress())
.type(request.getType())
.region(region)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package javalab.umc7th_mission.study.converter;

import javalab.umc7th_mission.study.domain.Member;
import javalab.umc7th_mission.study.domain.Restaurant;
import javalab.umc7th_mission.study.domain.Review;
import javalab.umc7th_mission.study.web.dto.review.ReviewRequestDTO;
import javalab.umc7th_mission.study.web.dto.review.ReviewResponseDTO;

import java.time.LocalDateTime;

public class ReviewConverter {
public static ReviewResponseDTO.AddReviewResultDTO toAddReviewResultDTO(Review review) {
return ReviewResponseDTO.AddReviewResultDTO.builder()
.reviewId(review.getId())
.createdAt(LocalDateTime.now())
.build();
}

public static Review toReview(ReviewRequestDTO.AddReviewDto request, Member member, Restaurant restaurant) {
return Review.builder()
.score(request.getScore())
.content(request.getContent())
.member(member)
.restaurant(restaurant)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package javalab.umc7th_mission.study.converter;

import javalab.umc7th_mission.study.dto.TempResponse;
import javalab.umc7th_mission.study.web.dto.TempResponse;

public class TempConverter {
public static TempResponse.TempTestDTO toTempDTO(){
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/javalab/umc7th_mission/study/domain/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import javalab.umc7th_mission.study.domain.mapping.MemberMission;
import javalab.umc7th_mission.study.domain.mapping.MemberQuestion;
import javalab.umc7th_mission.study.domain.mapping.MemberTerm;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import java.time.LocalDate;
import java.util.ArrayList;
Expand All @@ -18,6 +21,8 @@

@Entity
@Getter
@DynamicUpdate
@DynamicInsert
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
Expand All @@ -42,15 +47,15 @@ public class Member extends BaseEntity {
@Column(nullable = true, length = 15)
private String phoneNumber;

@Column(nullable = false)
@ColumnDefault("0")
private Integer point;

@Enumerated(EnumType.STRING)
@Column(columnDefinition = "VARCHAR(10)")
private Role role;

@Enumerated(EnumType.STRING)
@Column(columnDefinition = "VARCHAR(10)")
@Column(columnDefinition = "VARCHAR(10) DEFAULT 'ACTIVE'")
private MemberStatus status;

@Column(nullable = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@
import javalab.umc7th_mission.study.domain.Review;
import javalab.umc7th_mission.study.domain.enums.RestaurantStatus;
import javalab.umc7th_mission.study.domain.common.BaseEntity;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

@Entity
@Getter
@DynamicUpdate
@DynamicInsert
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
Expand All @@ -31,7 +35,7 @@ public class Restaurant extends BaseEntity {
private String address;

@Enumerated(EnumType.STRING)
@Column(nullable = false, length = 10)
@Column(columnDefinition = "VARCHAR(10) DEFAULT 'ACTIVE'")
private RestaurantStatus status;

private LocalDate inactiveDate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class Review extends BaseEntity {
@Column(nullable = false)
private Integer score;

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

@ManyToOne(fetch = FetchType.LAZY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,15 @@ public class MemberFood extends BaseEntity {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "food_id")
private Food food;

public void setMember(Member member){
if(this.member != null)
member.getMemberFoodList().remove(this);
this.member = member;
member.getMemberFoodList().add(this);
}

public void setFood(Food food){
this.food = food;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@
import javalab.umc7th_mission.study.domain.Mission;
import javalab.umc7th_mission.study.domain.common.BaseEntity;
import javalab.umc7th_mission.study.domain.enums.MissionStatus;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import java.time.LocalDate;

@Entity
@Getter
@DynamicUpdate
@DynamicInsert
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
Expand All @@ -18,11 +24,14 @@ public class MemberMission extends BaseEntity {
private Long id;

@Enumerated(EnumType.STRING)
@Column(nullable = false, length = 20)
@Column(columnDefinition = "VARCHAR(20) DEFAULT 'CHALLENGING'")
private MissionStatus status;

@Column(nullable = false)
private Integer bossNumber;
private LocalDate startDate;

@Column(nullable = true)
private LocalDate endDate;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
import javalab.umc7th_mission.study.domain.mapping.MemberMission;
import org.springframework.data.jpa.repository.JpaRepository;

public interface MemberMissionRepository extends JpaRepository<MemberMission, Integer>, MemberMissionRepositoryCustom{

public interface MemberMissionRepository extends JpaRepository<MemberMission, Long>, MemberMissionRepositoryCustom{
MemberMission findMemberMissionByMemberIdAndMissionId(Long memberId, Long missionId);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package javalab.umc7th_mission.study.repository.MemberMissionRepository;

import com.querydsl.core.types.Projections;
import com.querydsl.jpa.impl.JPAQueryFactory;
import ext.javalab.umc7th_mission.study.domain.QMission;
import ext.javalab.umc7th_mission.study.domain.QRegion;
Expand Down Expand Up @@ -53,4 +54,5 @@ public Long countCompletedMemberMissionsByMemberIdAndRegion(Long memberId, Strin
)
.fetchOne();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
import javalab.umc7th_mission.study.domain.Member;
import org.springframework.data.jpa.repository.JpaRepository;

public interface MemberRepository extends JpaRepository<Member, Integer>, MemberRepositoryCustom {
public interface MemberRepository extends JpaRepository<Member, Long>, MemberRepositoryCustom {

}
Loading

0 comments on commit 8042dc4

Please sign in to comment.