-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
945d832
commit 4bc5cfd
Showing
8 changed files
with
137 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.asrez.wheremoney.api.entity; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.persistence.*; | ||
|
||
@Data | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Entity | ||
@Table(name = "types") | ||
public class Type { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@JsonProperty(access = JsonProperty.Access.READ_ONLY) | ||
private Long id; | ||
private String name; | ||
@Column(name = "icon_name") | ||
@JsonProperty(value = "icon_name") | ||
private String iconName; | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/asrez/wheremoney/api/repository/TypeRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.asrez.wheremoney.api.repository; | ||
|
||
import com.asrez.wheremoney.api.entity.Type; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface TypeRepository extends JpaRepository<Type, Long> { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/main/java/com/asrez/wheremoney/api/service/TypeService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.asrez.wheremoney.api.service; | ||
|
||
import com.asrez.wheremoney.api.entity.Type; | ||
import com.asrez.wheremoney.api.exception.ApiRequestException; | ||
import com.asrez.wheremoney.api.repository.TypeRepository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.Optional; | ||
|
||
@Service | ||
public class TypeService { | ||
private final TypeRepository typeRepository; | ||
|
||
@Autowired | ||
public TypeService(TypeRepository typeRepository) { | ||
this.typeRepository = typeRepository; | ||
} | ||
|
||
public Type getType(Long id) { | ||
Optional<Type> typeOptional = typeRepository.findById(id); | ||
if (typeOptional.isEmpty()) | ||
throw new ApiRequestException("Type not found!", " TYPE_NOT_FOUND"); | ||
|
||
return typeOptional.get(); | ||
} | ||
} |