mirror of
https://github.com/Cernobor/oko-server.git
synced 2025-02-24 08:27:17 +00:00
refactoring, support for storing feature photos
* errors put into separate package * added table to store feature photos * added API endpoints for serving photos * POST /data extended to accept photos using a multipart/form-data body
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
package errs
|
||||
|
||||
import "fmt"
|
||||
|
||||
type ConstError string
|
||||
|
||||
func (e ConstError) Error() string {
|
||||
return string(e)
|
||||
}
|
||||
|
||||
const (
|
||||
ErrUserNotExists = ConstError("user does not exist")
|
||||
ErrUserAlreadyExists = ConstError("user already exists")
|
||||
ErrPhotoNotExists = ConstError("photo does not exist (for the given feature)")
|
||||
ErrAttemptedSystemUser = ConstError("attempted to associate with system user")
|
||||
ErrUnsupportedImageFormat = ConstError("unsupported image format")
|
||||
ErrUnsupportedImageContentType = ConstError("unsupported image content type")
|
||||
ErrNonUniqueCreatedFeatureIDs = ConstError("created features do not have unique IDs")
|
||||
)
|
||||
|
||||
type EErrPhotoNotProvided *ErrPhotoNotProvided
|
||||
|
||||
type ErrPhotoNotProvided struct {
|
||||
Reference string
|
||||
}
|
||||
|
||||
func NewErrPhotoNotProvided(reference string) *ErrPhotoNotProvided {
|
||||
return &ErrPhotoNotProvided{
|
||||
Reference: reference,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *ErrPhotoNotProvided) Error() string {
|
||||
return fmt.Sprintf("referenced photo %s which was not provided", e.Reference)
|
||||
}
|
||||
|
||||
type ErrFeatureForPhotoNotExists struct {
|
||||
PhotoFeatureReference int64
|
||||
}
|
||||
|
||||
func NewErrFeatureForPhotoNotExists(reference int64) *ErrFeatureForPhotoNotExists {
|
||||
return &ErrFeatureForPhotoNotExists{
|
||||
PhotoFeatureReference: reference,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *ErrFeatureForPhotoNotExists) Error() string {
|
||||
return fmt.Sprintf("photos were referenced for feature with local ID %d which does not exist in posted created features", e.PhotoFeatureReference)
|
||||
}
|
||||
|
||||
type ErrUnsupportedContentType struct {
|
||||
Reference string
|
||||
}
|
||||
|
||||
func NewErrUnsupportedContentType(reference string) *ErrUnsupportedContentType {
|
||||
return &ErrUnsupportedContentType{
|
||||
Reference: reference,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *ErrUnsupportedContentType) Error() string {
|
||||
return fmt.Sprintf("photo %s has an unsupported Content-Type", e.Reference)
|
||||
}
|
||||
Reference in New Issue
Block a user